Bug 891556 - Add Ctrl-Shift-C (Cmd-Opt-C) shortcut to toggle highlighting; r=jwalker

This commit is contained in:
Brian Grinstead 2013-08-02 11:28:37 -07:00
parent 37a492acf5
commit 6505f8e6d7
12 changed files with 161 additions and 10 deletions

View File

@ -345,15 +345,24 @@ let gDevToolsBrowser = {
selectToolCommand: function(gBrowser, toolId) {
let target = devtools.TargetFactory.forTab(gBrowser.selectedTab);
let toolbox = gDevTools.getToolbox(target);
let tools = gDevTools.getToolDefinitionMap();
let toolDefinition = tools.get(toolId);
if (toolbox && toolbox.currentToolId == toolId) {
if (toolbox.hostType == devtools.Toolbox.HostType.WINDOW) {
toolbox.fireCustomKey(toolId);
if (toolDefinition.preventClosingOnKey || toolbox.hostType == devtools.Toolbox.HostType.WINDOW) {
toolbox.raise();
} else {
toolbox.destroy();
}
} else {
gDevTools.showToolbox(target, toolId);
gDevTools.showToolbox(target, toolId).then(() => {
let target = devtools.TargetFactory.forTab(gBrowser.selectedTab);
let toolbox = gDevTools.getToolbox(target);
toolbox.fireCustomKey(toolId);
});
}
},

View File

@ -30,6 +30,7 @@ MOCHITEST_BROWSER_FILES = \
browser_toolbox_options_disablejs_iframe.html \
browser_toolbox_highlight.js \
browser_toolbox_raise.js \
browser_keybindings.js \
$(NULL)
include $(topsrcdir)/config/rules.mk

View File

@ -0,0 +1,119 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
// Tests that the keybindings for opening and closing the inspector work as expected
// Can probably make this a shared test that tests all of the tools global keybindings
function test()
{
waitForExplicitFinish();
let doc;
let node;
let inspector;
let keysetMap = { };
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,<html><head><title>Test for the " +
"highlighter keybindings</title></head><body>" +
"<h1>Keybindings!</h1></body></html>";
function buildDevtoolsKeysetMap(keyset) {
[].forEach.call(keyset.querySelectorAll("key"), function(key) {
if (!key.getAttribute("key")) {
return;
}
let modifiers = key.getAttribute("modifiers");
keysetMap[key.id.split("_")[1]] = {
key: key.getAttribute("key"),
modifiers: modifiers,
modifierOpt: {
shiftKey: modifiers.match("shift"),
ctrlKey: modifiers.match("ctrl"),
altKey: modifiers.match("alt"),
metaKey: modifiers.match("meta"),
accelKey: modifiers.match("accel")
},
synthesizeKey: function() {
EventUtils.synthesizeKey(this.key, this.modifierOpt);
}
}
});
}
function setupKeyBindingsTest()
{
for (let win of gDevToolsBrowser._trackedBrowserWindows) {
buildDevtoolsKeysetMap(win.document.getElementById("devtoolsKeyset"));
}
gDevTools.once("toolbox-ready", (e, toolbox) => {
inspectorShouldBeOpenAndHighlighting(toolbox.getCurrentPanel(), toolbox)
});
keysetMap.inspector.synthesizeKey();
}
function inspectorShouldBeOpenAndHighlighting(aInspector, aToolbox)
{
is (aToolbox.currentToolId, "inspector", "Correct tool has been loaded");
is (aInspector.highlighter.locked, true, "Highlighter should be locked");
aInspector.highlighter.once("unlocked", () => {
is (aInspector.highlighter.locked, false, "Highlighter should be unlocked");
keysetMap.inspector.synthesizeKey();
is (aInspector.highlighter.locked, true, "Highlighter should be locked");
keysetMap.inspector.synthesizeKey();
is (aInspector.highlighter.locked, false, "Highlighter should be unlocked");
keysetMap.inspector.synthesizeKey();
is (aInspector.highlighter.locked, true, "Highlighter should be locked");
aToolbox.once("webconsole-ready", (e, panel) => {
webconsoleShouldBeSelected(aToolbox, panel);
});
keysetMap.webconsole.synthesizeKey();
});
}
function webconsoleShouldBeSelected(aToolbox, panel)
{
is (aToolbox.currentToolId, "webconsole");
aToolbox.once("jsdebugger-ready", (e, panel) => {
jsdebuggerShouldBeSelected(aToolbox, panel);
});
keysetMap.jsdebugger.synthesizeKey();
}
function jsdebuggerShouldBeSelected(aToolbox, panel)
{
is (aToolbox.currentToolId, "jsdebugger");
aToolbox.once("netmonitor-ready", (e, panel) => {
netmonitorShouldBeSelected(aToolbox, panel);
});
keysetMap.netmonitor.synthesizeKey();
}
function netmonitorShouldBeSelected(aToolbox, panel)
{
is (aToolbox.currentToolId, "netmonitor");
finishUp();
}
function finishUp() {
doc = node = inspector = keysetMap = null;
gBrowser.removeCurrentTab();
finish();
}
}

View File

@ -264,13 +264,30 @@ Toolbox.prototype = {
key.setAttribute("modifiers", toolDefinition.modifiers);
key.setAttribute("oncommand", "void(0);"); // needed. See bug 371900
key.addEventListener("command", function(toolId) {
this.selectTool(toolId);
this.selectTool(toolId).then(() => {
this.fireCustomKey(toolId);
});
}.bind(this, id), true);
doc.getElementById("toolbox-keyset").appendChild(key);
}
}
},
/**
* Handle any custom key events. Returns true if there was a custom key binding run
* @param {string} toolId
* Which tool to run the command on (skip if not current)
*/
fireCustomKey: function TBOX_fireCustomKey(toolId) {
let tools = gDevTools.getToolDefinitionMap();
let activeToolDefinition = tools.get(toolId);
if (activeToolDefinition.onkey && this.currentToolId === toolId) {
activeToolDefinition.onkey(this.getCurrentPanel());
}
},
/**
* Build the buttons for changing hosts. Called every time
* the host changes.

View File

@ -129,8 +129,6 @@ Highlighter.prototype = {
this.transitionDisabler = null;
this.pageEventsMuter = null;
this.unlockAndFocus();
this.selection.on("new-node", this.highlight);
this.selection.on("new-node", this.updateInfobar);
this.selection.on("pseudoclass", this.updateInfobar);

View File

@ -137,10 +137,6 @@ InspectorPanel.prototype = {
// All the components are initialized. Let's select a node.
this._selection.setNodeFront(defaultSelection);
if (this.highlighter) {
this.highlighter.unlock();
}
this.markup.expandNode(this.selection.nodeFront);
this.emit("ready");

View File

@ -29,6 +29,7 @@ function test()
function runObjectInspectionTest(inspector)
{
inspector.highlighter.once("locked", performTestComparison);
inspector.highlighter.unlock();
inspector.selection.setNode(objectNode, "");
}

View File

@ -50,6 +50,7 @@ function test()
function runTests(inspector)
{
inspector.highlighter.unlock();
executeSoon(function() {
inspector.highlighter.once("highlighting", isTheIframeSelected);
moveMouseOver(iframeNode, 1, 1);

View File

@ -51,6 +51,7 @@ function moveMouseOver(aElement)
function runIframeTests()
{
getActiveInspector().highlighter.unlock();
getActiveInspector().selection.once("new-node", performTestComparisons1);
moveMouseOver(div1)
}

View File

@ -35,6 +35,7 @@ function inspectNode(aInspector)
inspector.highlighter.once("locked", performScrollingTest);
executeSoon(function() {
inspector.highlighter.unlock();
inspector.selection.setNode(div, "");
});
}

View File

@ -97,6 +97,13 @@ Tools.inspector = {
label: l10n("inspector.label", inspectorStrings),
tooltip: l10n("inspector.tooltip", inspectorStrings),
preventClosingOnKey: true,
onkey: function(panel) {
if (panel.highlighter) {
panel.highlighter.toggleLockState();
}
},
isTargetSupported: function(target) {
return !target.isRemote;
},

View File

@ -35,7 +35,7 @@ nodeMenu.tooltiptext=Node operations
# LOCALIZATION NOTE (inspector.*)
# Used for the menuitem in the tool menu
inspector.label=Inspector
inspector.commandkey=I
inspector.commandkey=C
inspector.accesskey=I
# LOCALIZATION NOTE (markupView.more.*)