Bug 1278625 - move XPCOMUtils use out of Tooltip.js; r?jdescottes
MozReview-Commit-ID: 77xkkxl4mqN
--- a/devtools/client/debugger/views/variable-bubble-view.js
+++ b/devtools/client/debugger/views/variable-bubble-view.js
@@ -4,16 +4,18 @@
* 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/. */
/* import-globals-from ../debugger-controller.js */
/* import-globals-from ../debugger-view.js */
/* import-globals-from ../utils.js */
/* globals document, window */
"use strict";
+const {setTooltipVariableContent} = require("devtools/client/shared/widgets/tooltip/VariableContentHelper");
+
/**
* Functions handling the variables bubble UI.
*/
function VariableBubbleView(DebuggerController, DebuggerView) {
dumpn("VariableBubbleView was instantiated");
this.StackFrames = DebuggerController.StackFrames;
this.Parser = DebuggerController.Parser;
@@ -193,17 +195,17 @@ VariableBubbleView.prototype = {
label: L10N.getStr("addWatchExpressionButton"),
className: "dbg-expression-button",
command: () => {
this.DebuggerView.VariableBubble.hideContents();
this.DebuggerView.WatchExpressions.addExpression(evalPrefix, true);
}
}]);
} else {
- this._tooltip.setVariableContent(objectActor, {
+ setTooltipVariableContent(this._tooltip, objectActor, {
searchPlaceholder: L10N.getStr("emptyPropertiesFilterText"),
searchEnabled: Prefs.variablesSearchboxVisible,
eval: (variable, value) => {
let string = variable.evaluationMacro(variable, value);
this.StackFrames.evaluate(string);
this.DebuggerView.VariableBubble.hideContents();
}
}, {
--- a/devtools/client/shared/widgets/Tooltip.js
+++ b/devtools/client/shared/widgets/Tooltip.js
@@ -9,31 +9,25 @@ const defer = require("devtools/shared/d
const {Spectrum} = require("devtools/client/shared/widgets/Spectrum");
const {CubicBezierWidget} =
require("devtools/client/shared/widgets/CubicBezierWidget");
const {CSSFilterEditorWidget} = require("devtools/client/shared/widgets/FilterWidget");
const {TooltipToggle} = require("devtools/client/shared/widgets/tooltip/TooltipToggle");
const EventEmitter = require("devtools/shared/event-emitter");
const {colorUtils} = require("devtools/shared/css-color");
const Heritage = require("sdk/core/heritage");
-const {XPCOMUtils} = require("resource://gre/modules/XPCOMUtils.jsm");
const {HTMLTooltip} = require("devtools/client/shared/widgets/HTMLTooltip");
const {KeyShortcuts} = require("devtools/client/shared/key-shortcuts");
const {Task} = require("devtools/shared/task");
loader.lazyRequireGetter(this, "beautify", "devtools/shared/jsbeautify/beautify");
loader.lazyRequireGetter(this, "setNamedTimeout", "devtools/client/shared/widgets/view-helpers", true);
loader.lazyRequireGetter(this, "clearNamedTimeout", "devtools/client/shared/widgets/view-helpers", true);
loader.lazyRequireGetter(this, "setNamedTimeout", "devtools/client/shared/widgets/view-helpers", true);
-XPCOMUtils.defineLazyModuleGetter(this, "VariablesView",
- "resource://devtools/client/shared/widgets/VariablesView.jsm");
-XPCOMUtils.defineLazyModuleGetter(this, "VariablesViewController",
- "resource://devtools/client/shared/widgets/VariablesViewController.jsm");
-
const XHTML_NS = "http://www.w3.org/1999/xhtml";
const ESCAPE_KEYCODE = Ci.nsIDOMKeyEvent.DOM_VK_ESCAPE;
const POPUP_EVENTS = ["shown", "hidden", "showing", "hiding"];
/**
* Tooltip widget.
*
* This widget is intended at any tool that may need to show rich content in the
@@ -422,88 +416,16 @@ Tooltip.prototype = {
hbox.appendChild(vbox);
this.content = hbox;
} else {
this.content = vbox;
}
},
/**
- * Fill the tooltip with a variables view, inspecting an object via its
- * corresponding object actor, as specified in the remote debugging protocol.
- *
- * @param {object} objectActor
- * The value grip for the object actor.
- * @param {object} viewOptions [optional]
- * Options for the variables view visualization.
- * @param {object} controllerOptions [optional]
- * Options for the variables view controller.
- * @param {object} relayEvents [optional]
- * A collection of events to listen on the variables view widget.
- * For example, { fetched: () => ... }
- * @param {boolean} reuseCachedWidget [optional]
- * Pass false to instantiate a brand new widget for this variable.
- * Otherwise, if a variable was previously inspected, its widget
- * will be reused.
- * @param {Toolbox} toolbox [optional]
- * Pass the instance of the current toolbox if you want the variables
- * view widget to allow highlighting and selection of DOM nodes
- */
- setVariableContent: function (objectActor,
- viewOptions = {},
- controllerOptions = {},
- relayEvents = {},
- extraButtons = [],
- toolbox = null) {
- let vbox = this.doc.createElement("vbox");
- vbox.className = "devtools-tooltip-variables-view-box";
- vbox.setAttribute("flex", "1");
-
- let innerbox = this.doc.createElement("vbox");
- innerbox.className = "devtools-tooltip-variables-view-innerbox";
- innerbox.setAttribute("flex", "1");
- vbox.appendChild(innerbox);
-
- for (let { label, className, command } of extraButtons) {
- let button = this.doc.createElement("button");
- button.className = className;
- button.setAttribute("label", label);
- button.addEventListener("command", command);
- vbox.appendChild(button);
- }
-
- let widget = new VariablesView(innerbox, viewOptions);
-
- // If a toolbox was provided, link it to the vview
- if (toolbox) {
- widget.toolbox = toolbox;
- }
-
- // Analyzing state history isn't useful with transient object inspectors.
- widget.commitHierarchy = () => {};
-
- for (let e in relayEvents) {
- widget.on(e, relayEvents[e]);
- }
- VariablesViewController.attach(widget, controllerOptions);
-
- // Some of the view options are allowed to change between uses.
- widget.searchPlaceholder = viewOptions.searchPlaceholder;
- widget.searchEnabled = viewOptions.searchEnabled;
-
- // Use the object actor's grip to display it as a variable in the widget.
- // The controller options are allowed to change between uses.
- widget.controller.setSingleVariable(
- { objectActor: objectActor }, controllerOptions);
-
- this.content = vbox;
- this.panel.setAttribute("clamped-dimensions", "");
- },
-
- /**
* Load a document into an iframe, and set the iframe
* to be the tooltip's content.
*
* Used by tooltips that want to load their interface
* into an iframe from a URL.
*
* @param {string} width
* Width of the iframe.
new file mode 100644
--- /dev/null
+++ b/devtools/client/shared/widgets/tooltip/VariableContentHelper.js
@@ -0,0 +1,89 @@
+/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
+/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
+/* 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/. */
+
+"use strict";
+
+const {XPCOMUtils} = require("resource://gre/modules/XPCOMUtils.jsm");
+
+XPCOMUtils.defineLazyModuleGetter(this, "VariablesView",
+ "resource://devtools/client/shared/widgets/VariablesView.jsm");
+XPCOMUtils.defineLazyModuleGetter(this, "VariablesViewController",
+ "resource://devtools/client/shared/widgets/VariablesViewController.jsm");
+
+/**
+ * Fill the tooltip with a variables view, inspecting an object via its
+ * corresponding object actor, as specified in the remote debugging protocol.
+ *
+ * @param {Tooltip} tooltip
+ * The tooltip to use
+ * @param {object} objectActor
+ * The value grip for the object actor.
+ * @param {object} viewOptions [optional]
+ * Options for the variables view visualization.
+ * @param {object} controllerOptions [optional]
+ * Options for the variables view controller.
+ * @param {object} relayEvents [optional]
+ * A collection of events to listen on the variables view widget.
+ * For example, { fetched: () => ... }
+ * @param {array} extraButtons [optional]
+ * An array of extra buttons to add. Each element of the array
+ * should be of the form {label, className, command}.
+ * @param {Toolbox} toolbox [optional]
+ * Pass the instance of the current toolbox if you want the variables
+ * view widget to allow highlighting and selection of DOM nodes
+ */
+
+function setTooltipVariableContent(tooltip, objectActor,
+ viewOptions = {}, controllerOptions = {},
+ relayEvents = {}, extraButtons = [],
+ toolbox = null) {
+ let doc = tooltip.doc;
+ let vbox = doc.createElement("vbox");
+ vbox.className = "devtools-tooltip-variables-view-box";
+ vbox.setAttribute("flex", "1");
+
+ let innerbox = doc.createElement("vbox");
+ innerbox.className = "devtools-tooltip-variables-view-innerbox";
+ innerbox.setAttribute("flex", "1");
+ vbox.appendChild(innerbox);
+
+ for (let { label, className, command } of extraButtons) {
+ let button = doc.createElement("button");
+ button.className = className;
+ button.setAttribute("label", label);
+ button.addEventListener("command", command);
+ vbox.appendChild(button);
+ }
+
+ let widget = new VariablesView(innerbox, viewOptions);
+
+ // If a toolbox was provided, link it to the vview
+ if (toolbox) {
+ widget.toolbox = toolbox;
+ }
+
+ // Analyzing state history isn't useful with transient object inspectors.
+ widget.commitHierarchy = () => {};
+
+ for (let e in relayEvents) {
+ widget.on(e, relayEvents[e]);
+ }
+ VariablesViewController.attach(widget, controllerOptions);
+
+ // Some of the view options are allowed to change between uses.
+ widget.searchPlaceholder = viewOptions.searchPlaceholder;
+ widget.searchEnabled = viewOptions.searchEnabled;
+
+ // Use the object actor's grip to display it as a variable in the widget.
+ // The controller options are allowed to change between uses.
+ widget.controller.setSingleVariable(
+ { objectActor: objectActor }, controllerOptions);
+
+ tooltip.content = vbox;
+ tooltip.panel.setAttribute("clamped-dimensions", "");
+}
+
+exports.setTooltipVariableContent = setTooltipVariableContent;
--- a/devtools/client/shared/widgets/tooltip/moz.build
+++ b/devtools/client/shared/widgets/tooltip/moz.build
@@ -4,9 +4,10 @@
# 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/.
DevToolsModules(
'CssDocsTooltip.js',
'EventTooltipHelper.js',
'ImageTooltipHelper.js',
'TooltipToggle.js',
+ 'VariableContentHelper.js',
)