diff --git a/browser/devtools/commandline/BuiltinCommands.jsm b/browser/devtools/commandline/BuiltinCommands.jsm index 7638c3fdda5..0aaf7619b76 100644 --- a/browser/devtools/commandline/BuiltinCommands.jsm +++ b/browser/devtools/commandline/BuiltinCommands.jsm @@ -1747,7 +1747,8 @@ XPCOMUtils.defineLazyModuleGetter(this, "AppCacheUtils", width = window.innerWidth; height = window.innerHeight; } else { - let rect = LayoutHelpers.getRect(node, window); + let lh = new LayoutHelpers(window); + let rect = lh.getRect(node, window); top = rect.top; left = rect.left; width = rect.width; diff --git a/browser/devtools/debugger/debugger-controller.js b/browser/devtools/debugger/debugger-controller.js index 734f4efebcc..6d0067eb3ee 100644 --- a/browser/devtools/debugger/debugger-controller.js +++ b/browser/devtools/debugger/debugger-controller.js @@ -19,7 +19,6 @@ Cu.import("resource://gre/modules/XPCOMUtils.jsm"); Cu.import("resource://gre/modules/devtools/dbg-client.jsm"); let promise = Cu.import("resource://gre/modules/commonjs/sdk/core/promise.js").Promise; Cu.import("resource:///modules/source-editor.jsm"); -Cu.import("resource://gre/modules/devtools/LayoutHelpers.jsm"); Cu.import("resource:///modules/devtools/BreadcrumbsWidget.jsm"); Cu.import("resource:///modules/devtools/SideMenuWidget.jsm"); Cu.import("resource:///modules/devtools/VariablesView.jsm"); @@ -40,6 +39,13 @@ Object.defineProperty(this, "NetworkHelper", { enumerable: true }); +Object.defineProperty(this, "DevtoolsHelpers", { + get: function() { + return devtools.require("devtools/shared/helpers"); + }, + configurable: true, + enumerable: true +}); /** * Object defining the debugger controller components. diff --git a/browser/devtools/debugger/debugger-toolbar.js b/browser/devtools/debugger/debugger-toolbar.js index 076c2cdab19..e08aa4bb5ad 100644 --- a/browser/devtools/debugger/debugger-toolbar.js +++ b/browser/devtools/debugger/debugger-toolbar.js @@ -38,10 +38,10 @@ ToolbarView.prototype = { this._stepOutButton = document.getElementById("step-out"); this._chromeGlobals = document.getElementById("chrome-globals"); - let resumeKey = LayoutHelpers.prettyKey(document.getElementById("resumeKey"), true); - let stepOverKey = LayoutHelpers.prettyKey(document.getElementById("stepOverKey"), true); - let stepInKey = LayoutHelpers.prettyKey(document.getElementById("stepInKey"), true); - let stepOutKey = LayoutHelpers.prettyKey(document.getElementById("stepOutKey"), true); + let resumeKey = DevtoolsHelpers.prettyKey(document.getElementById("resumeKey"), true); + let stepOverKey = DevtoolsHelpers.prettyKey(document.getElementById("stepOverKey"), true); + let stepInKey = DevtoolsHelpers.prettyKey(document.getElementById("stepInKey"), true); + let stepOutKey = DevtoolsHelpers.prettyKey(document.getElementById("stepOutKey"), true); this._resumeTooltip = L10N.getFormatStr("resumeButtonTooltip", resumeKey); this._pauseTooltip = L10N.getFormatStr("pauseButtonTooltip", resumeKey); this._stepOverTooltip = L10N.getFormatStr("stepOverTooltip", stepOverKey); @@ -729,12 +729,12 @@ FilterView.prototype = { this._variableOperatorButton = document.getElementById("variable-operator-button"); this._variableOperatorLabel = document.getElementById("variable-operator-label"); - this._fileSearchKey = LayoutHelpers.prettyKey(document.getElementById("fileSearchKey"), true); - this._globalSearchKey = LayoutHelpers.prettyKey(document.getElementById("globalSearchKey"), true); - this._filteredFunctionsKey = LayoutHelpers.prettyKey(document.getElementById("functionSearchKey"), true); - this._tokenSearchKey = LayoutHelpers.prettyKey(document.getElementById("tokenSearchKey"), true); - this._lineSearchKey = LayoutHelpers.prettyKey(document.getElementById("lineSearchKey"), true); - this._variableSearchKey = LayoutHelpers.prettyKey(document.getElementById("variableSearchKey"), true); + this._fileSearchKey = DevtoolsHelpers.prettyKey(document.getElementById("fileSearchKey"), true); + this._globalSearchKey = DevtoolsHelpers.prettyKey(document.getElementById("globalSearchKey"), true); + this._filteredFunctionsKey = DevtoolsHelpers.prettyKey(document.getElementById("functionSearchKey"), true); + this._tokenSearchKey = DevtoolsHelpers.prettyKey(document.getElementById("tokenSearchKey"), true); + this._lineSearchKey = DevtoolsHelpers.prettyKey(document.getElementById("lineSearchKey"), true); + this._variableSearchKey = DevtoolsHelpers.prettyKey(document.getElementById("variableSearchKey"), true); this._searchbox.addEventListener("click", this._onClick, false); this._searchbox.addEventListener("select", this._onSearch, false); diff --git a/browser/devtools/debugger/test/browser_dbg_pause-resume.js b/browser/devtools/debugger/test/browser_dbg_pause-resume.js index 1f886cd17d2..537a39dcd42 100644 --- a/browser/devtools/debugger/test/browser_dbg_pause-resume.js +++ b/browser/devtools/debugger/test/browser_dbg_pause-resume.js @@ -8,7 +8,7 @@ var gPane = null; var gTab = null; var gDebugger = null; var gView = null; -var gLH = null; +var gDH = null; var gL10N = null; function test() { @@ -17,7 +17,7 @@ function test() { gPane = aPane; gDebugger = gPane.panelWin; gView = gDebugger.DebuggerView; - gLH = gDebugger.LayoutHelpers; + gDH = gDebugger.DevtoolsHelpers; gL10N = gDebugger.L10N; testPause(); @@ -31,7 +31,7 @@ function testPause() { let button = gDebugger.document.getElementById("resume"); is(button.getAttribute("tooltiptext"), gL10N.getFormatStr("pauseButtonTooltip", - gLH.prettyKey(gDebugger.document.getElementById("resumeKey"))), + gDH.prettyKey(gDebugger.document.getElementById("resumeKey"))), "Button tooltip should be pause when running."); gDebugger.DebuggerController.activeThread.addOneTimeListener("paused", function() { @@ -45,7 +45,7 @@ function testPause() { is(button.getAttribute("tooltiptext"), gL10N.getFormatStr("resumeButtonTooltip", - gLH.prettyKey(gDebugger.document.getElementById("resumeKey"))), + gDH.prettyKey(gDebugger.document.getElementById("resumeKey"))), "Button tooltip should be resume when paused."); is(frames.querySelectorAll(".dbg-stackframe").length, 0, @@ -70,7 +70,7 @@ function testResume() { let button = gDebugger.document.getElementById("resume"); is(button.getAttribute("tooltiptext"), gL10N.getFormatStr("pauseButtonTooltip", - gLH.prettyKey(gDebugger.document.getElementById("resumeKey"))), + gDH.prettyKey(gDebugger.document.getElementById("resumeKey"))), "Button tooltip should be pause when running."); closeDebuggerAndFinish(); @@ -88,6 +88,6 @@ registerCleanupFunction(function() { gTab = null; gDebugger = null; gView = null; - gLH = null; + gDH = null; gL10N = null; }); diff --git a/browser/devtools/inspector/breadcrumbs.js b/browser/devtools/inspector/breadcrumbs.js index 37c608f1b52..25910863027 100644 --- a/browser/devtools/inspector/breadcrumbs.js +++ b/browser/devtools/inspector/breadcrumbs.js @@ -11,7 +11,6 @@ const ENSURE_SELECTION_VISIBLE_DELAY = 50; // ms Cu.import("resource://gre/modules/XPCOMUtils.jsm"); Cu.import("resource:///modules/devtools/DOMHelpers.jsm"); -Cu.import("resource://gre/modules/devtools/LayoutHelpers.jsm"); Cu.import("resource://gre/modules/Services.jsm"); let promise = require("sdk/core/promise"); diff --git a/browser/devtools/inspector/highlighter.js b/browser/devtools/inspector/highlighter.js index 5d796b508b6..279c0ab63be 100644 --- a/browser/devtools/inspector/highlighter.js +++ b/browser/devtools/inspector/highlighter.js @@ -93,6 +93,7 @@ function LocalHighlighter(aTarget, aInspector, aToolbox) this.chromeDoc = this.tab.ownerDocument; this.chromeWin = this.chromeDoc.defaultView; this.inspector = aInspector + this.layoutHelpers = new LayoutHelpers(this.browser.contentWindow); EventEmitter.decorate(this); @@ -225,7 +226,7 @@ LocalHighlighter.prototype = { this.invalidateSize(); if (!this._highlighting && this.selection.reason != "highlighter") { - LayoutHelpers.scrollIntoViewIfNeeded(this.selection.node); + this.layoutHelpers.scrollIntoViewIfNeeded(this.selection.node); } } else { this.disabled = true; @@ -255,7 +256,7 @@ LocalHighlighter.prototype = { } let clientRect = this.selection.node.getBoundingClientRect(); - let rect = LayoutHelpers.getDirtyRect(this.selection.node); + let rect = this.layoutHelpers.getDirtyRect(this.selection.node); this.highlightRectangle(rect); this.moveInfobar(); @@ -461,7 +462,7 @@ LocalHighlighter.prototype = { texthbox.addEventListener("mousedown", function(aEvent) { // On click, show the node: if (this.selection.isElementNode()) { - LayoutHelpers.scrollIntoViewIfNeeded(this.selection.node); + this.layoutHelpers.scrollIntoViewIfNeeded(this.selection.node); } }.bind(this), true); @@ -514,7 +515,7 @@ LocalHighlighter.prototype = { return; // same rectangle } - let aRectScaled = LayoutHelpers.getZoomedRect(this.win, aRect); + let aRectScaled = this.layoutHelpers.getZoomedRect(this.win, aRect); if (aRectScaled.left >= 0 && aRectScaled.top >= 0 && aRectScaled.width > 0 && aRectScaled.height > 0) { @@ -809,7 +810,7 @@ LocalHighlighter.prototype = { // This should never happen, but just in case, we don't let the // highlighter highlight browser nodes. if (doc && doc != this.chromeDoc) { - let element = LayoutHelpers.getElementFromPoint(aEvent.target.ownerDocument, + let element = this.layoutHelpers.getElementFromPoint(aEvent.target.ownerDocument, aEvent.clientX, aEvent.clientY); if (element && element != this.selection.node) { this.selection.setNode(element, "highlighter"); diff --git a/browser/devtools/inspector/test/browser_inspector_bug_817558_delete_node.js b/browser/devtools/inspector/test/browser_inspector_bug_817558_delete_node.js index 41076fe8c83..746df998f08 100644 --- a/browser/devtools/inspector/test/browser_inspector_bug_817558_delete_node.js +++ b/browser/devtools/inspector/test/browser_inspector_bug_817558_delete_node.js @@ -33,7 +33,8 @@ function test() let tmp = {}; Cu.import("resource://gre/modules/devtools/LayoutHelpers.jsm", tmp); - ok(!tmp.LayoutHelpers.isNodeConnected(node), "Node considered as disconnected."); + let lh = new tmp.LayoutHelpers(window.content); + ok(!lh.isNodeConnected(node), "Node considered as disconnected."); // Wait for the inspector to process the mutation inspector.once("inspector-updated", () => { diff --git a/browser/devtools/inspector/test/browser_inspector_destroyselection.js b/browser/devtools/inspector/test/browser_inspector_destroyselection.js index ea75f4d4629..f0eaabe02d0 100644 --- a/browser/devtools/inspector/test/browser_inspector_destroyselection.js +++ b/browser/devtools/inspector/test/browser_inspector_destroyselection.js @@ -33,7 +33,8 @@ function test() let tmp = {}; Cu.import("resource://gre/modules/devtools/LayoutHelpers.jsm", tmp); - ok(!tmp.LayoutHelpers.isNodeConnected(node), "Node considered as disconnected."); + let lh = new tmp.LayoutHelpers(window.content); + ok(!lh.isNodeConnected(node), "Node considered as disconnected."); ok(!inspector.selection.isConnected(), "Selection considered as disconnected"); finishUp(); diff --git a/browser/devtools/inspector/test/head.js b/browser/devtools/inspector/test/head.js index 5b7a5653505..aa0541b131f 100644 --- a/browser/devtools/inspector/test/head.js +++ b/browser/devtools/inspector/test/head.js @@ -77,7 +77,8 @@ function getHighlitNode() // Get midpoint of diagonal line. let midpoint = midPoint(a, b); - return LayoutHelpers.getElementFromPoint(h.win.document, midpoint.x, + let lh = new LayoutHelpers(window.content); + return lh.getElementFromPoint(h.win.document, midpoint.x, midpoint.y); } diff --git a/browser/devtools/layoutview/view.js b/browser/devtools/layoutview/view.js index 6f80d708d47..c2b86cd0ff8 100644 --- a/browser/devtools/layoutview/view.js +++ b/browser/devtools/layoutview/view.js @@ -8,7 +8,6 @@ const Cu = Components.utils; Cu.import("resource://gre/modules/Services.jsm"); -Cu.import("resource://gre/modules/devtools/LayoutHelpers.jsm"); Cu.import("resource://gre/modules/devtools/Loader.jsm"); Cu.import("resource://gre/modules/devtools/Console.jsm"); diff --git a/browser/devtools/markupview/markup-view.js b/browser/devtools/markupview/markup-view.js index 94f10c78aa1..3bc496072b9 100644 --- a/browser/devtools/markupview/markup-view.js +++ b/browser/devtools/markupview/markup-view.js @@ -53,6 +53,8 @@ function MarkupView(aInspector, aFrame, aControllerWindow) this.doc = this._frame.contentDocument; this._elt = this.doc.querySelector("#root"); + this.layoutHelpers = new LayoutHelpers(this.doc.defaultView); + try { this.maxChildren = Services.prefs.getIntPref("devtools.markup.pagesize"); } catch(ex) { @@ -406,7 +408,7 @@ MarkupView.prototype = { return this._ensureVisible(aNode); }).then(() => { // Why is this not working? - LayoutHelpers.scrollIntoViewIfNeeded(this._containers.get(aNode).editor.elt, centered); + this.layoutHelpers.scrollIntoViewIfNeeded(this._containers.get(aNode).editor.elt, centered); }); }, @@ -1231,7 +1233,7 @@ ElementEditor.prototype = { // Double quotes need to be handled specially to prevent DOMParser failing. // name="v"a"l"u"e" when editing -> name='v"a"l"u"e"' // name="v'a"l'u"e" when editing -> name="v'a"l'u"e" - let editValueDisplayed = aAttr.value; + let editValueDisplayed = aAttr.value || ""; let hasDoubleQuote = editValueDisplayed.contains('"'); let hasSingleQuote = editValueDisplayed.contains("'"); let initial = aAttr.name + '="' + editValueDisplayed + '"'; diff --git a/browser/devtools/scratchpad/scratchpad.js b/browser/devtools/scratchpad/scratchpad.js index de3c2c821b6..76cf6d74c6c 100644 --- a/browser/devtools/scratchpad/scratchpad.js +++ b/browser/devtools/scratchpad/scratchpad.js @@ -19,6 +19,7 @@ let require = Components.utils.import("resource://gre/modules/devtools/Loader.js let { Cc, Ci, Cu } = require("chrome"); let promise = require("sdk/core/promise"); let Telemetry = require("devtools/shared/telemetry"); +let DevtoolsHelpers = require("devtools/shared/helpers"); let TargetFactory = require("devtools/framework/target").TargetFactory; const escodegen = require("escodegen/escodegen"); @@ -26,7 +27,6 @@ Cu.import("resource://gre/modules/XPCOMUtils.jsm"); Cu.import("resource://gre/modules/Services.jsm"); Cu.import("resource://gre/modules/NetUtil.jsm"); Cu.import("resource:///modules/source-editor.jsm"); -Cu.import("resource://gre/modules/devtools/LayoutHelpers.jsm"); Cu.import("resource:///modules/devtools/scratchpad-manager.jsm"); Cu.import("resource://gre/modules/jsdebugger.jsm"); Cu.import("resource:///modules/devtools/gDevTools.jsm"); @@ -1284,9 +1284,9 @@ var Scratchpad = { let initialText = this.strings.formatStringFromName( "scratchpadIntro1", - [LayoutHelpers.prettyKey(document.getElementById("sp-key-run")), - LayoutHelpers.prettyKey(document.getElementById("sp-key-inspect")), - LayoutHelpers.prettyKey(document.getElementById("sp-key-display"))], + [DevtoolsHelpers.prettyKey(document.getElementById("sp-key-run")), + DevtoolsHelpers.prettyKey(document.getElementById("sp-key-inspect")), + DevtoolsHelpers.prettyKey(document.getElementById("sp-key-display"))], 3); let args = window.arguments; diff --git a/browser/devtools/shared/test/browser_layoutHelpers.js b/browser/devtools/shared/test/browser_layoutHelpers.js index 6f421474ded..a626d0a6040 100644 --- a/browser/devtools/shared/test/browser_layoutHelpers.js +++ b/browser/devtools/shared/test/browser_layoutHelpers.js @@ -25,52 +25,54 @@ function test() { } function runTest(win, some) { + let lh = new LayoutHelpers(win); + some.style.top = win.innerHeight + 'px'; some.style.left = win.innerWidth + 'px'; // The tests start with a black 2x2 pixels square below bottom right. // Do not resize the window during the tests. win.scroll(win.innerWidth / 2, win.innerHeight + 2); // Above the viewport. - LayoutHelpers.scrollIntoViewIfNeeded(some); + lh.scrollIntoViewIfNeeded(some); is(win.scrollY, Math.floor(win.innerHeight / 2) + 1, 'Element completely hidden above should appear centered.'); win.scroll(win.innerWidth / 2, win.innerHeight + 1); // On the top edge. - LayoutHelpers.scrollIntoViewIfNeeded(some); + lh.scrollIntoViewIfNeeded(some); is(win.scrollY, win.innerHeight, 'Element partially visible above should appear above.'); win.scroll(win.innerWidth / 2, 0); // Just below the viewport. - LayoutHelpers.scrollIntoViewIfNeeded(some); + lh.scrollIntoViewIfNeeded(some); is(win.scrollY, Math.floor(win.innerHeight / 2) + 1, 'Element completely hidden below should appear centered.'); win.scroll(win.innerWidth / 2, 1); // On the bottom edge. - LayoutHelpers.scrollIntoViewIfNeeded(some); + lh.scrollIntoViewIfNeeded(some); is(win.scrollY, 2, 'Element partially visible below should appear below.'); win.scroll(win.innerWidth / 2, win.innerHeight + 2); // Above the viewport. - LayoutHelpers.scrollIntoViewIfNeeded(some, false); + lh.scrollIntoViewIfNeeded(some, false); is(win.scrollY, win.innerHeight, 'Element completely hidden above should appear above ' + 'if parameter is false.'); win.scroll(win.innerWidth / 2, win.innerHeight + 1); // On the top edge. - LayoutHelpers.scrollIntoViewIfNeeded(some, false); + lh.scrollIntoViewIfNeeded(some, false); is(win.scrollY, win.innerHeight, 'Element partially visible above should appear above ' + 'if parameter is false.'); win.scroll(win.innerWidth / 2, 0); // Below the viewport. - LayoutHelpers.scrollIntoViewIfNeeded(some, false); + lh.scrollIntoViewIfNeeded(some, false); is(win.scrollY, 2, 'Element completely hidden below should appear below ' + 'if parameter is false.'); win.scroll(win.innerWidth / 2, 1); // On the bottom edge. - LayoutHelpers.scrollIntoViewIfNeeded(some, false); + lh.scrollIntoViewIfNeeded(some, false); is(win.scrollY, 2, 'Element partially visible below should appear below ' + 'if parameter is false.'); @@ -86,7 +88,7 @@ function runTest(win, some) { fwin.addEventListener('load', function frameLoad() { let some = fwin.document.getElementById('some'); - LayoutHelpers.scrollIntoViewIfNeeded(some); + lh.scrollIntoViewIfNeeded(some); is(win.scrollX, Math.floor(win.innerWidth / 2) + 20, 'Scrolling from an iframe should center the iframe vertically.'); is(win.scrollY, Math.floor(win.innerHeight / 2) + 20, diff --git a/browser/devtools/tilt/test/browser_tilt_utils05.js b/browser/devtools/tilt/test/browser_tilt_utils05.js index 0f09d198e94..139b4aa3c2d 100644 --- a/browser/devtools/tilt/test/browser_tilt_utils05.js +++ b/browser/devtools/tilt/test/browser_tilt_utils05.js @@ -55,10 +55,11 @@ function test() { iframe.contentWindow.innerHeight, "The content window height wasn't calculated correctly."); - let nodeCoordinates = LayoutHelpers.getRect( + let lh = new LayoutHelpers(gBrowser.contentWindow); + let nodeCoordinates = lh.getRect( iframe.contentDocument.getElementById("test-div"), iframe.contentWindow); - let frameOffset = LayoutHelpers.getIframeContentOffset(iframe); + let frameOffset = lh.getIframeContentOffset(iframe); let frameRect = iframe.getBoundingClientRect(); is(nodeCoordinates.top, frameRect.top + frameOffset[0] + 98, diff --git a/browser/devtools/tilt/test/browser_tilt_utils07.js b/browser/devtools/tilt/test/browser_tilt_utils07.js index 0c07300a896..ab97cc698ef 100644 --- a/browser/devtools/tilt/test/browser_tilt_utils07.js +++ b/browser/devtools/tilt/test/browser_tilt_utils07.js @@ -104,10 +104,11 @@ function test() { iframe.contentWindow.innerHeight, "The content window height wasn't calculated correctly."); - let nodeCoordinates = LayoutHelpers.getRect( + let lh = new LayoutHelpers(gBrowser.contentWindow); + let nodeCoordinates = lh.getRect( iframe.contentDocument.getElementById("test-div"), iframe.contentWindow); - let frameOffset = LayoutHelpers.getIframeContentOffset(iframe); + let frameOffset = lh.getIframeContentOffset(iframe); let frameRect = iframe.getBoundingClientRect(); is(nodeCoordinates.top, frameRect.top + frameOffset[0], diff --git a/browser/devtools/tilt/tilt-utils.js b/browser/devtools/tilt/tilt-utils.js index 40f3613b6e0..17e14644f95 100644 --- a/browser/devtools/tilt/tilt-utils.js +++ b/browser/devtools/tilt/tilt-utils.js @@ -405,8 +405,9 @@ TiltUtils.DOM = { */ getNodePosition: function TUD_getNodePosition(aContentWindow, aNode, aParentPosition) { + let lh = new LayoutHelpers(aContentWindow); // get the x, y, width and height coordinates of the node - let coord = LayoutHelpers.getRect(aNode, aContentWindow); + let coord = lh.getRect(aNode, aContentWindow); if (!coord) { return null; }