Bug 669658 - [highlighter] Improve the keybindings, r=rcampbell

This commit is contained in:
Panos Astithas 2011-10-11 10:11:20 -03:00
parent 2ac4397240
commit f3905307b7
4 changed files with 104 additions and 28 deletions

View File

@ -1,5 +1,5 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=2 et sw=2 tw=80: */
/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
@ -141,6 +141,7 @@ TreePanel.prototype = {
this.treeLoaded = true;
this.treeIFrame.addEventListener("click", this.onTreeClick.bind(this), false);
this.treeIFrame.addEventListener("dblclick", this.onTreeDblClick.bind(this), false);
this.treeIFrame.addEventListener("keypress", this.IUI, false);
delete this.initializingTreePanel;
Services.obs.notifyObservers(null,
this.IUI.INSPECTOR_NOTIFICATIONS.TREEPANELREADY, null);
@ -694,6 +695,7 @@ TreePanel.prototype = {
}
if (this.treeIFrame) {
this.treeIFrame.removeEventListener("keypress", this.IUI, false);
this.treeIFrame.removeEventListener("dblclick", this.onTreeDblClick, false);
this.treeIFrame.removeEventListener("click", this.onTreeClick, false);
let parent = this.treeIFrame.parentNode;

View File

@ -989,6 +989,7 @@ InspectorUI.prototype = {
}
this.stopInspecting();
this.browser.removeEventListener("keypress", this, true);
this.saveToolState(this.winID);
this.toolsDo(function IUI_toolsHide(aTool) {
@ -996,6 +997,9 @@ InspectorUI.prototype = {
}.bind(this));
if (this.highlighter) {
this.highlighter.highlighterContainer.removeEventListener("keypress",
this,
true);
this.highlighter.destroy();
this.highlighter = null;
}
@ -1026,7 +1030,12 @@ InspectorUI.prototype = {
this.treePanel.closeEditor();
this.inspectToolbutton.checked = true;
this.attachPageListeners();
// Attach event listeners to content window and child windows to enable
// highlighting and click to stop inspection.
this.browser.addEventListener("keypress", this, true);
this.highlighter.highlighterContainer.addEventListener("keypress", this, true);
this.highlighter.attachInspectListeners();
this.inspecting = true;
this.toolsDim(true);
this.highlighter.veilContainer.removeAttribute("locked");
@ -1046,7 +1055,12 @@ InspectorUI.prototype = {
}
this.inspectToolbutton.checked = false;
this.detachPageListeners();
// Detach event listeners from content window and child windows to disable
// highlighting. We still want to be notified if the user presses "ESCAPE"
// to unlock the node, so we don't remove the "keypress" event until
// the highlighter is removed.
this.highlighter.detachInspectListeners();
this.inspecting = false;
this.toolsDim(false);
if (this.highlighter.node) {
@ -1166,11 +1180,9 @@ InspectorUI.prototype = {
switch (event.keyCode) {
case this.chromeWin.KeyEvent.DOM_VK_RETURN:
case this.chromeWin.KeyEvent.DOM_VK_ESCAPE:
if (this.inspecting) {
this.stopInspecting();
event.preventDefault();
event.stopPropagation();
}
this.toggleInspection();
event.preventDefault();
event.stopPropagation();
break;
case this.chromeWin.KeyEvent.DOM_VK_LEFT:
let node;
@ -1240,26 +1252,6 @@ InspectorUI.prototype = {
}
},
/**
* Attach event listeners to content window and child windows to enable
* highlighting and click to stop inspection.
*/
attachPageListeners: function IUI_attachPageListeners()
{
this.browser.addEventListener("keypress", this, true);
this.highlighter.attachInspectListeners();
},
/**
* Detach event listeners from content window and child windows
* to disable highlighting.
*/
detachPageListeners: function IUI_detachPageListeners()
{
this.browser.removeEventListener("keypress", this, true);
this.highlighter.detachInspectListeners();
},
/////////////////////////////////////////////////////////////////////////
//// Utility Methods

View File

@ -62,6 +62,7 @@ _BROWSER_FILES = \
browser_inspector_infobar.js \
browser_inspector_bug_690361.js \
browser_inspector_bug_672902_keyboard_shortcuts.js \
browser_inspector_keybindings.js \
$(NULL)
# Disabled due to constant failures

View File

@ -0,0 +1,81 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
function test()
{
waitForExplicitFinish();
let doc;
let node;
gBrowser.selectedTab = gBrowser.addTab();
gBrowser.selectedBrowser.addEventListener("load", function onload() {
gBrowser.selectedBrowser.removeEventListener("load", onload, true);
doc = content.document;
waitForFocus(setupKeyBindingsTest, content);
}, true);
content.location = "data:text/html,<h1>foobar</h1>";
function setupKeyBindingsTest()
{
node = doc.querySelector("h1");
Services.obs.addObserver(highlightNode,
InspectorUI.INSPECTOR_NOTIFICATIONS.OPENED, false);
InspectorUI.toggleInspectorUI();
}
function highlightNode()
{
Services.obs.removeObserver(highlightNode,
InspectorUI.INSPECTOR_NOTIFICATIONS.OPENED);
executeSoon(function() {
Services.obs.addObserver(lockNode,
InspectorUI.INSPECTOR_NOTIFICATIONS.HIGHLIGHTING, false);
InspectorUI.inspectNode(node);
});
}
function lockNode()
{
Services.obs.removeObserver(lockNode,
InspectorUI.INSPECTOR_NOTIFICATIONS.HIGHLIGHTING);
EventUtils.synthesizeKey("VK_ESCAPE", { });
executeSoon(isTheNodeLocked);
}
function isTheNodeLocked()
{
is(InspectorUI.selection, node, "selection matches node");
ok(!InspectorUI.inspecting, "the node is locked");
unlockNode();
}
function unlockNode() {
EventUtils.synthesizeKey("VK_ESCAPE", { });
executeSoon(isTheNodeUnlocked);
}
function isTheNodeUnlocked()
{
ok(InspectorUI.inspecting, "the node is unlocked");
Services.obs.addObserver(finishUp,
InspectorUI.INSPECTOR_NOTIFICATIONS.CLOSED, false);
InspectorUI.closeInspectorUI();
}
function finishUp() {
Services.obs.removeObserver(finishUp,
InspectorUI.INSPECTOR_NOTIFICATIONS.CLOSED);
doc = node = null;
gBrowser.removeCurrentTab();
finish();
}
}