Bug 1359855 - Fix support of per tool key shortcuts in toolboxes opened in a window. r=jdescottes

MozReview-Commit-ID: kP07KzpzxI

--HG--
extra : rebase_source : 4135af713a11f1f96f00be92cd88b707627c22cd
This commit is contained in:
Alexandre Poirot 2017-07-13 15:27:37 +02:00
Родитель 80498fc6b9
Коммит fd1ca6efba
3 изменённых файлов: 44 добавлений и 25 удалений

Просмотреть файл

@ -184,6 +184,7 @@ DevToolsStartup.prototype = {
this.handleDebuggerServerFlag(cmdLine, debuggerServerFlag); this.handleDebuggerServerFlag(cmdLine, debuggerServerFlag);
} }
// Only top level Firefox Windows fire a browser-delayed-startup-finished event
let onWindowReady = window => { let onWindowReady = window => {
this.hookWindow(window); this.hookWindow(window);
@ -512,6 +513,15 @@ DevToolsStartup.prototype = {
} }
}, },
// Used by tests and the toolbox to register the same key shortcuts in toolboxes loaded
// in a window window.
get KeyShortcuts() {
return KeyShortcuts;
},
get wrappedJSObject() {
return this;
},
/* eslint-disable max-len */ /* eslint-disable max-len */
helpInfo: " --jsconsole Open the Browser Console.\n" + helpInfo: " --jsconsole Open the Browser Console.\n" +
" --jsdebugger Open the Browser Toolbox.\n" + " --jsdebugger Open the Browser Toolbox.\n" +

Просмотреть файл

@ -5,28 +5,33 @@
"use strict"; "use strict";
var Startup = Cc["@mozilla.org/devtools/startup-clh;1"].getService(Ci.nsISupports)
.wrappedJSObject;
var {Toolbox} = require("devtools/client/framework/toolbox"); var {Toolbox} = require("devtools/client/framework/toolbox");
var toolbox, toolIDs, idIndex, modifiedPrefs = []; var toolbox, toolIDs, toolShortcuts = [], idIndex, modifiedPrefs = [];
function test() { function test() {
addTab("about:blank").then(function () { addTab("about:blank").then(function () {
toolIDs = []; toolIDs = [];
for (let [id, definition] of gDevTools._tools) { for (let [id, definition] of gDevTools._tools) {
if (definition.key) { let shortcut = Startup.KeyShortcuts.filter(s => s.toolId == id)[0];
toolIDs.push(id); if (!shortcut) {
continue;
}
toolIDs.push(id);
toolShortcuts.push(shortcut);
// Enable disabled tools // Enable disabled tools
let pref = definition.visibilityswitch, prefValue; let pref = definition.visibilityswitch, prefValue;
try { try {
prefValue = Services.prefs.getBoolPref(pref); prefValue = Services.prefs.getBoolPref(pref);
} catch (e) { } catch (e) {
continue; continue;
} }
if (!prefValue) { if (!prefValue) {
modifiedPrefs.push(pref); modifiedPrefs.push(pref);
Services.prefs.setBoolPref(pref, true); Services.prefs.setBoolPref(pref, true);
}
} }
} }
let target = TargetFactory.forTab(gBrowser.selectedTab); let target = TargetFactory.forTab(gBrowser.selectedTab);
@ -49,8 +54,9 @@ function testShortcuts(aToolbox, aIndex) {
toolbox.once("select", selectCB); toolbox.once("select", selectCB);
let key = gDevTools._tools.get(toolIDs[aIndex]).key; let shortcut = toolShortcuts[aIndex];
let toolModifiers = gDevTools._tools.get(toolIDs[aIndex]).modifiers; let key = shortcut.shortcut;
let toolModifiers = shortcut.modifiers;
let modifiers = { let modifiers = {
accelKey: toolModifiers.includes("accel"), accelKey: toolModifiers.includes("accel"),
altKey: toolModifiers.includes("alt"), altKey: toolModifiers.includes("alt"),

Просмотреть файл

@ -14,7 +14,7 @@ const HOST_HISTOGRAM = "DEVTOOLS_TOOLBOX_HOST";
const SCREENSIZE_HISTOGRAM = "DEVTOOLS_SCREEN_RESOLUTION_ENUMERATED_PER_USER"; const SCREENSIZE_HISTOGRAM = "DEVTOOLS_SCREEN_RESOLUTION_ENUMERATED_PER_USER";
const HTML_NS = "http://www.w3.org/1999/xhtml"; const HTML_NS = "http://www.w3.org/1999/xhtml";
var {Ci, Cu} = require("chrome"); var {Ci, Cu, Cc} = require("chrome");
var promise = require("promise"); var promise = require("promise");
var defer = require("devtools/shared/defer"); var defer = require("devtools/shared/defer");
var Services = require("Services"); var Services = require("Services");
@ -27,6 +27,8 @@ var Menu = require("devtools/client/framework/menu");
var MenuItem = require("devtools/client/framework/menu-item"); var MenuItem = require("devtools/client/framework/menu-item");
var { DOMHelpers } = require("resource://devtools/client/shared/DOMHelpers.jsm"); var { DOMHelpers } = require("resource://devtools/client/shared/DOMHelpers.jsm");
const { KeyCodes } = require("devtools/client/shared/keycodes"); const { KeyCodes } = require("devtools/client/shared/keycodes");
var Startup = Cc["@mozilla.org/devtools/startup-clh;1"].getService(Ci.nsISupports)
.wrappedJSObject;
const { BrowserLoader } = const { BrowserLoader } =
Cu.import("resource://devtools/client/shared/browser-loader.js", {}); Cu.import("resource://devtools/client/shared/browser-loader.js", {});
@ -857,24 +859,25 @@ Toolbox.prototype = {
let doc = this.win.parent.document; let doc = this.win.parent.document;
for (let [id, toolDefinition] of gDevTools.getToolDefinitionMap()) { for (let item of Startup.KeyShortcuts) {
// Prevent multiple entries for the same tool. // KeyShortcuts contain tool-specific and global key shortcuts,
if (!toolDefinition.key || doc.getElementById("key_" + id)) { // here we only need to copy shortcut specific to each tool.
if (!item.toolId) {
continue; continue;
} }
let { toolId, shortcut, modifiers } = item;
let toolId = id;
let key = doc.createElement("key"); let key = doc.createElement("key");
key.id = "key_" + toolId; key.id = "key_" + toolId;
if (toolDefinition.key.startsWith("VK_")) { if (shortcut.startsWith("VK_")) {
key.setAttribute("keycode", toolDefinition.key); key.setAttribute("keycode", shortcut);
} else { } else {
key.setAttribute("key", toolDefinition.key); key.setAttribute("key", shortcut);
} }
key.setAttribute("modifiers", toolDefinition.modifiers); key.setAttribute("modifiers", modifiers);
// needed. See bug 371900 // needed. See bug 371900
key.setAttribute("oncommand", "void(0);"); key.setAttribute("oncommand", "void(0);");
key.addEventListener("command", () => { key.addEventListener("command", () => {