Bug 1566215 - Part 4: Use message manager to send layout debugger commands to content. r=dbaron

Differential Revision: https://phabricator.services.mozilla.com/D38414

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Cameron McCormack 2019-07-22 04:48:37 +00:00
Родитель 3c7a36d829
Коммит 383e501763
3 изменённых файлов: 31 добавлений и 11 удалений

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

@ -0,0 +1,19 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// Frame script that runs in the layout debugger's <browser>.
var gDebuggingTools;
const NS_LAYOUT_DEBUGGINGTOOLS_CONTRACTID =
"@mozilla.org/layout-debug/layout-debuggingtools;1";
gDebuggingTools = Cc[NS_LAYOUT_DEBUGGINGTOOLS_CONTRACTID].createInstance(
Ci.nsILayoutDebuggingTools
);
gDebuggingTools.init(content);
addMessageListener("LayoutDebug:Call", function(msg) {
gDebuggingTools[msg.data.name](msg.data.arg);
});

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

@ -11,8 +11,7 @@ const { Preferences } = ChromeUtils.import(
);
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
const NS_LAYOUT_DEBUGGINGTOOLS_CONTRACTID =
"@mozilla.org/layout-debug/layout-debuggingtools;1";
const HELPER_URL = "chrome://layoutdebug/content/layoutdebug-helper.js";
const FEATURES = {
paintFlashing: "nglayout.debug.paint_flashing",
@ -40,14 +39,11 @@ class Debugger {
this._flags = new Map();
this._visualDebugging = false;
this._visualEventDebugging = false;
this._tools = Cc[NS_LAYOUT_DEBUGGINGTOOLS_CONTRACTID].createInstance(
Ci.nsILayoutDebuggingTools
);
for (let [name, pref] of Object.entries(FEATURES)) {
this._flags.set(name, !!Preferences.get(pref, false));
}
this._tools.init(gBrowser.contentWindow);
gBrowser.messageManager.loadFrameScript(HELPER_URL, false);
}
get visualDebugging() {
@ -57,7 +53,7 @@ class Debugger {
set visualDebugging(v) {
v = !!v;
this._visualDebugging = v;
this._tools.setVisualDebugging(v);
this._sendMessage("setVisualDebugging", v);
}
get visualEventDebugging() {
@ -67,7 +63,11 @@ class Debugger {
set visualEventDebugging(v) {
v = !!v;
this._visualEventDebugging = v;
this._tools.setVisualEventDebugging(v);
this._sendMessage("setVisualEventDebugging", v);
}
_sendMessage(name, arg) {
gBrowser.messageManager.sendAsyncMessage("LayoutDebug:Call", { name, arg });
}
}
@ -82,16 +82,16 @@ for (let [name, pref] of Object.entries(FEATURES)) {
this._flags.set(name, v);
// XXX PresShell should watch for this pref change itself.
if (name == "reflowCounts") {
this._tools.setReflowCounts(v);
this._sendMessage("setReflowCounts", v);
}
this._tools.forceRefresh();
this._sendMessage("forceRefresh");
},
});
}
for (let name of COMMANDS) {
Debugger.prototype[name] = function() {
this._tools[name]();
this._sendMessage(name);
};
}

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

@ -7,4 +7,5 @@ layoutdebug.jar:
% locale layoutdebug en-US %locale/en-US/layoutdebug/
content/layoutdebug/layoutdebug.xul (content/layoutdebug.xul)
content/layoutdebug/layoutdebug.js (content/layoutdebug.js)
content/layoutdebug/layoutdebug-helper.js (content/layoutdebug-helper.js)
locale/en-US/layoutdebug/layoutdebug.dtd (locale/en-US/layoutdebug.dtd)