2012-05-21 04:12:37 -07:00
|
|
|
/* 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/. */
|
2012-05-10 10:33:54 -07:00
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
2012-11-30 00:07:59 -08:00
|
|
|
this.EXPORTED_SYMBOLS = [ "DeveloperToolbar", "CommandUtils" ];
|
2012-05-10 10:33:54 -07:00
|
|
|
|
2012-05-17 11:04:33 -07:00
|
|
|
const NS_XHTML = "http://www.w3.org/1999/xhtml";
|
2012-10-04 02:32:36 -07:00
|
|
|
const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
|
2013-05-24 03:26:17 -07:00
|
|
|
const { classes: Cc, interfaces: Ci, utils: Cu } = Components;
|
2012-05-10 10:33:54 -07:00
|
|
|
|
2013-05-24 03:26:17 -07:00
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
|
|
|
Cu.import("resource://gre/modules/Services.jsm");
|
2012-05-10 10:33:54 -07:00
|
|
|
|
2013-09-03 04:20:27 -07:00
|
|
|
const { require, TargetFactory } = Cu.import("resource://gre/modules/devtools/Loader.jsm", {}).devtools;
|
|
|
|
|
2013-05-24 03:26:17 -07:00
|
|
|
const Node = Ci.nsIDOMNode;
|
2012-09-07 06:24:59 -07:00
|
|
|
|
2012-06-24 05:00:47 -07:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "console",
|
2012-07-25 10:34:34 -07:00
|
|
|
"resource://gre/modules/devtools/Console.jsm");
|
2012-05-10 10:33:54 -07:00
|
|
|
|
2013-01-25 08:14:53 -08:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "PluralForm",
|
|
|
|
"resource://gre/modules/PluralForm.jsm");
|
|
|
|
|
2013-05-22 13:32:58 -07:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "EventEmitter",
|
2014-02-25 20:22:05 -08:00
|
|
|
"resource://gre/modules/devtools/event-emitter.js");
|
2013-05-22 13:32:58 -07:00
|
|
|
|
2012-11-30 00:07:59 -08:00
|
|
|
XPCOMUtils.defineLazyGetter(this, "prefBranch", function() {
|
2013-05-24 03:26:17 -07:00
|
|
|
let prefService = Cc["@mozilla.org/preferences-service;1"]
|
|
|
|
.getService(Ci.nsIPrefService);
|
2012-11-30 00:07:59 -08:00
|
|
|
return prefService.getBranch(null)
|
2013-05-24 03:26:17 -07:00
|
|
|
.QueryInterface(Ci.nsIPrefBranch2);
|
2012-11-30 00:07:59 -08:00
|
|
|
});
|
|
|
|
|
2013-01-22 07:55:02 -08:00
|
|
|
XPCOMUtils.defineLazyGetter(this, "toolboxStrings", function () {
|
|
|
|
return Services.strings.createBundle("chrome://browser/locale/devtools/toolbox.properties");
|
|
|
|
});
|
|
|
|
|
2013-09-03 04:20:27 -07:00
|
|
|
const Telemetry = require("devtools/shared/telemetry");
|
2013-05-24 03:26:17 -07:00
|
|
|
|
2014-04-12 23:47:27 -07:00
|
|
|
// This lazy getter is needed to prevent a require loop
|
|
|
|
XPCOMUtils.defineLazyGetter(this, "gcli", () => {
|
2014-06-09 07:16:26 -07:00
|
|
|
try {
|
|
|
|
require("devtools/commandline/commands-index");
|
|
|
|
return require("gcli/index");
|
|
|
|
}
|
|
|
|
catch (ex) {
|
|
|
|
console.error(ex);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
XPCOMUtils.defineLazyGetter(this, "util", () => {
|
|
|
|
return require("gcli/util/util");
|
2014-04-12 23:47:27 -07:00
|
|
|
});
|
2013-03-22 12:55:21 -07:00
|
|
|
|
2013-08-03 03:29:48 -07:00
|
|
|
Object.defineProperty(this, "ConsoleServiceListener", {
|
|
|
|
get: function() {
|
2013-09-03 04:20:27 -07:00
|
|
|
return require("devtools/toolkit/webconsole/utils").ConsoleServiceListener;
|
2013-08-03 03:29:48 -07:00
|
|
|
},
|
|
|
|
configurable: true,
|
|
|
|
enumerable: true
|
|
|
|
});
|
|
|
|
|
2013-09-03 04:20:27 -07:00
|
|
|
const promise = Cu.import('resource://gre/modules/Promise.jsm', {}).Promise;
|
|
|
|
|
2012-11-30 00:07:59 -08:00
|
|
|
/**
|
|
|
|
* A collection of utilities to help working with commands
|
|
|
|
*/
|
2013-03-12 21:51:30 -07:00
|
|
|
let CommandUtils = {
|
2014-04-12 23:47:27 -07:00
|
|
|
/**
|
|
|
|
* Utility to ensure that things are loaded in the correct order
|
|
|
|
*/
|
|
|
|
createRequisition: function(environment) {
|
2014-06-09 07:16:26 -07:00
|
|
|
return gcli.load().then(() => {
|
|
|
|
let Requisition = require("gcli/cli").Requisition
|
|
|
|
return new Requisition({ environment: environment });
|
|
|
|
});
|
2014-04-12 23:47:27 -07:00
|
|
|
},
|
|
|
|
|
2012-11-30 00:07:59 -08:00
|
|
|
/**
|
|
|
|
* Read a toolbarSpec from preferences
|
2013-09-03 04:20:27 -07:00
|
|
|
* @param pref The name of the preference to read
|
2012-11-30 00:07:59 -08:00
|
|
|
*/
|
2013-09-03 04:20:27 -07:00
|
|
|
getCommandbarSpec: function(pref) {
|
|
|
|
let value = prefBranch.getComplexValue(pref, Ci.nsISupportsString).data;
|
2012-11-30 00:07:59 -08:00
|
|
|
return JSON.parse(value);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2014-06-09 07:16:26 -07:00
|
|
|
* A toolbarSpec is an array of strings each of which is a GCLI command.
|
2012-12-18 12:47:39 -08:00
|
|
|
*
|
|
|
|
* Warning: this method uses the unload event of the window that owns the
|
|
|
|
* buttons that are of type checkbox. this means that we don't properly
|
|
|
|
* unregister event handlers until the window is destroyed.
|
2012-11-30 00:07:59 -08:00
|
|
|
*/
|
2013-09-03 04:20:27 -07:00
|
|
|
createButtons: function(toolbarSpec, target, document, requisition) {
|
2014-06-09 07:16:26 -07:00
|
|
|
return util.promiseEach(toolbarSpec, typed => {
|
2012-11-30 00:07:59 -08:00
|
|
|
// Ask GCLI to parse the typed string (doesn't execute it)
|
2014-06-09 07:16:26 -07:00
|
|
|
return requisition.update(typed).then(() => {
|
|
|
|
let button = document.createElement("toolbarbutton");
|
|
|
|
|
|
|
|
// Ignore invalid commands
|
|
|
|
let command = requisition.commandAssignment.value;
|
|
|
|
if (command == null) {
|
|
|
|
throw new Error("No command '" + typed + "'");
|
|
|
|
}
|
2012-11-30 00:07:59 -08:00
|
|
|
if (command.buttonId != null) {
|
|
|
|
button.id = command.buttonId;
|
|
|
|
}
|
|
|
|
if (command.buttonClass != null) {
|
|
|
|
button.className = command.buttonClass;
|
|
|
|
}
|
2012-12-05 08:39:56 -08:00
|
|
|
if (command.tooltipText != null) {
|
|
|
|
button.setAttribute("tooltiptext", command.tooltipText);
|
|
|
|
}
|
|
|
|
else if (command.description != null) {
|
|
|
|
button.setAttribute("tooltiptext", command.description);
|
|
|
|
}
|
2012-11-30 00:07:59 -08:00
|
|
|
|
2014-06-09 07:16:26 -07:00
|
|
|
button.addEventListener("click", () => {
|
|
|
|
requisition.updateExec(typed);
|
2012-11-30 00:07:59 -08:00
|
|
|
}, false);
|
|
|
|
|
|
|
|
// Allow the command button to be toggleable
|
2012-12-18 12:47:39 -08:00
|
|
|
if (command.state) {
|
|
|
|
button.setAttribute("autocheck", false);
|
2014-06-09 07:16:26 -07:00
|
|
|
let onChange = (event, eventTab) => {
|
2012-12-18 12:47:39 -08:00
|
|
|
if (eventTab == target.tab) {
|
|
|
|
if (command.state.isChecked(target)) {
|
|
|
|
button.setAttribute("checked", true);
|
|
|
|
}
|
|
|
|
else if (button.hasAttribute("checked")) {
|
|
|
|
button.removeAttribute("checked");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
command.state.onChange(target, onChange);
|
|
|
|
onChange(null, target.tab);
|
2014-06-09 07:16:26 -07:00
|
|
|
document.defaultView.addEventListener("unload", () => {
|
2012-12-18 12:47:39 -08:00
|
|
|
command.state.offChange(target, onChange);
|
2013-04-27 12:21:42 -07:00
|
|
|
}, false);
|
2012-11-30 00:07:59 -08:00
|
|
|
}
|
|
|
|
|
2014-06-09 07:16:26 -07:00
|
|
|
requisition.clear();
|
2012-11-30 00:07:59 -08:00
|
|
|
|
2014-06-09 07:16:26 -07:00
|
|
|
return button;
|
|
|
|
});
|
|
|
|
});
|
2013-03-12 21:51:30 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A helper function to create the environment object that is passed to
|
|
|
|
* GCLI commands.
|
2013-09-03 04:20:27 -07:00
|
|
|
* @param targetContainer An object containing a 'target' property which
|
|
|
|
* reflects the current debug target
|
2013-03-12 21:51:30 -07:00
|
|
|
*/
|
2013-09-03 04:20:27 -07:00
|
|
|
createEnvironment: function(container, targetProperty='target') {
|
|
|
|
if (container[targetProperty].supports == null) {
|
|
|
|
throw new Error('Missing target');
|
|
|
|
}
|
2013-03-12 21:51:30 -07:00
|
|
|
|
2013-09-03 04:20:27 -07:00
|
|
|
return {
|
|
|
|
get target() {
|
|
|
|
if (container[targetProperty].supports == null) {
|
|
|
|
throw new Error('Removed target');
|
|
|
|
}
|
2013-03-12 21:51:30 -07:00
|
|
|
|
2013-09-03 04:20:27 -07:00
|
|
|
return container[targetProperty];
|
|
|
|
},
|
|
|
|
|
|
|
|
get chromeWindow() {
|
|
|
|
return this.target.tab.ownerDocument.defaultView;
|
|
|
|
},
|
|
|
|
|
|
|
|
get chromeDocument() {
|
|
|
|
return this.chromeWindow.document;
|
|
|
|
},
|
|
|
|
|
|
|
|
get window() {
|
|
|
|
return this.chromeWindow.getBrowser().selectedTab.linkedBrowser.contentWindow;
|
2013-03-12 21:51:30 -07:00
|
|
|
},
|
|
|
|
|
2013-09-03 04:20:27 -07:00
|
|
|
get document() {
|
|
|
|
return this.window.document;
|
|
|
|
}
|
|
|
|
};
|
2013-03-12 21:51:30 -07:00
|
|
|
},
|
2012-11-30 00:07:59 -08:00
|
|
|
};
|
|
|
|
|
2013-03-12 21:51:30 -07:00
|
|
|
this.CommandUtils = CommandUtils;
|
|
|
|
|
2012-08-30 03:03:19 -07:00
|
|
|
/**
|
|
|
|
* Due to a number of panel bugs we need a way to check if we are running on
|
|
|
|
* Linux. See the comments for TooltipPanel and OutputPanel for further details.
|
|
|
|
*
|
|
|
|
* When bug 780102 is fixed all isLinux checks can be removed and we can revert
|
|
|
|
* to using panels.
|
|
|
|
*/
|
2013-09-03 04:20:27 -07:00
|
|
|
XPCOMUtils.defineLazyGetter(this, "isLinux", function() {
|
2013-05-10 06:46:28 -07:00
|
|
|
return OS == "Linux";
|
|
|
|
});
|
|
|
|
|
2013-09-03 04:20:27 -07:00
|
|
|
XPCOMUtils.defineLazyGetter(this, "OS", function() {
|
2013-05-24 03:26:17 -07:00
|
|
|
let os = Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULRuntime).OS;
|
2013-05-10 06:46:28 -07:00
|
|
|
return os;
|
2012-08-30 03:03:19 -07:00
|
|
|
});
|
|
|
|
|
2012-05-10 10:33:54 -07:00
|
|
|
/**
|
|
|
|
* A component to manage the global developer toolbar, which contains a GCLI
|
|
|
|
* and buttons for various developer tools.
|
|
|
|
* @param aChromeWindow The browser window to which this toolbar is attached
|
|
|
|
* @param aToolbarElement See browser.xul:<toolbar id="developer-toolbar">
|
|
|
|
*/
|
2012-10-31 09:13:28 -07:00
|
|
|
this.DeveloperToolbar = function DeveloperToolbar(aChromeWindow, aToolbarElement)
|
2012-05-10 10:33:54 -07:00
|
|
|
{
|
|
|
|
this._chromeWindow = aChromeWindow;
|
|
|
|
|
|
|
|
this._element = aToolbarElement;
|
|
|
|
this._element.hidden = true;
|
|
|
|
this._doc = this._element.ownerDocument;
|
|
|
|
|
2013-05-24 03:26:17 -07:00
|
|
|
this._telemetry = new Telemetry();
|
2012-11-30 00:07:59 -08:00
|
|
|
this._errorsCount = {};
|
2013-01-22 07:55:02 -08:00
|
|
|
this._warningsCount = {};
|
2012-11-30 00:07:59 -08:00
|
|
|
this._errorListeners = {};
|
|
|
|
this._errorCounterButton = this._doc
|
|
|
|
.getElementById("developer-toolbar-toolbox-button");
|
2013-01-22 07:55:02 -08:00
|
|
|
this._errorCounterButton._defaultTooltipText =
|
2013-09-03 04:20:27 -07:00
|
|
|
this._errorCounterButton.getAttribute("tooltiptext");
|
2012-06-24 05:00:47 -07:00
|
|
|
|
2013-05-22 13:32:58 -07:00
|
|
|
EventEmitter.decorate(this);
|
2012-05-10 10:33:54 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Inspector notifications dispatched through the nsIObserverService
|
|
|
|
*/
|
|
|
|
const NOTIFICATIONS = {
|
|
|
|
/** DeveloperToolbar.show() has been called, and we're working on it */
|
|
|
|
LOAD: "developer-toolbar-load",
|
|
|
|
|
|
|
|
/** DeveloperToolbar.show() has completed */
|
|
|
|
SHOW: "developer-toolbar-show",
|
|
|
|
|
|
|
|
/** DeveloperToolbar.hide() has been called */
|
|
|
|
HIDE: "developer-toolbar-hide"
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Attach notification constants to the object prototype so tests etc can
|
|
|
|
* use them without needing to import anything
|
|
|
|
*/
|
|
|
|
DeveloperToolbar.prototype.NOTIFICATIONS = NOTIFICATIONS;
|
|
|
|
|
2014-06-08 14:33:36 -07:00
|
|
|
/**
|
|
|
|
* target is dynamic because the selectedTab changes
|
|
|
|
*/
|
2013-09-03 04:20:27 -07:00
|
|
|
Object.defineProperty(DeveloperToolbar.prototype, "target", {
|
|
|
|
get: function() {
|
|
|
|
return TargetFactory.forTab(this._chromeWindow.getBrowser().selectedTab);
|
|
|
|
},
|
|
|
|
enumerable: true
|
|
|
|
});
|
|
|
|
|
2012-05-10 10:33:54 -07:00
|
|
|
/**
|
|
|
|
* Is the toolbar open?
|
|
|
|
*/
|
|
|
|
Object.defineProperty(DeveloperToolbar.prototype, 'visible', {
|
|
|
|
get: function DT_visible() {
|
|
|
|
return !this._element.hidden;
|
|
|
|
},
|
|
|
|
enumerable: true
|
|
|
|
});
|
|
|
|
|
2012-12-18 12:47:39 -08:00
|
|
|
let _gSequenceId = 0;
|
2012-06-14 04:36:48 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Getter for a unique ID.
|
|
|
|
*/
|
|
|
|
Object.defineProperty(DeveloperToolbar.prototype, 'sequenceId', {
|
|
|
|
get: function DT_visible() {
|
|
|
|
return _gSequenceId++;
|
|
|
|
},
|
|
|
|
enumerable: true
|
|
|
|
});
|
|
|
|
|
2012-05-10 10:33:54 -07:00
|
|
|
/**
|
|
|
|
* Called from browser.xul in response to menu-click or keyboard shortcut to
|
|
|
|
* toggle the toolbar
|
|
|
|
*/
|
2013-09-03 04:20:27 -07:00
|
|
|
DeveloperToolbar.prototype.toggle = function() {
|
2012-05-10 10:33:54 -07:00
|
|
|
if (this.visible) {
|
2013-09-03 04:20:27 -07:00
|
|
|
return this.hide();
|
2012-05-10 10:33:54 -07:00
|
|
|
} else {
|
2013-09-03 04:20:27 -07:00
|
|
|
return this.show(true);
|
2012-05-10 10:33:54 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-07-10 15:04:44 -07:00
|
|
|
/**
|
|
|
|
* Called from browser.xul in response to menu-click or keyboard shortcut to
|
|
|
|
* toggle the toolbar
|
|
|
|
*/
|
2013-09-03 04:20:27 -07:00
|
|
|
DeveloperToolbar.prototype.focus = function() {
|
2012-07-10 15:04:44 -07:00
|
|
|
if (this.visible) {
|
|
|
|
this._input.focus();
|
2013-09-03 04:20:27 -07:00
|
|
|
return promise.resolve();
|
2012-07-10 15:04:44 -07:00
|
|
|
} else {
|
2013-09-03 04:20:27 -07:00
|
|
|
return this.show(true);
|
2012-07-10 15:04:44 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-09-07 06:24:59 -07:00
|
|
|
/**
|
|
|
|
* Called from browser.xul in response to menu-click or keyboard shortcut to
|
|
|
|
* toggle the toolbar
|
|
|
|
*/
|
2013-09-03 04:20:27 -07:00
|
|
|
DeveloperToolbar.prototype.focusToggle = function() {
|
2012-09-07 06:24:59 -07:00
|
|
|
if (this.visible) {
|
|
|
|
// If we have focus then the active element is the HTML input contained
|
|
|
|
// inside the xul input element
|
2012-12-18 12:47:39 -08:00
|
|
|
let active = this._chromeWindow.document.activeElement;
|
|
|
|
let position = this._input.compareDocumentPosition(active);
|
2012-09-07 06:24:59 -07:00
|
|
|
if (position & Node.DOCUMENT_POSITION_CONTAINED_BY) {
|
|
|
|
this.hide();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this._input.focus();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
this.show(true);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-05-10 10:33:54 -07:00
|
|
|
/**
|
|
|
|
* Even if the user has not clicked on 'Got it' in the intro, we only show it
|
|
|
|
* once per session.
|
|
|
|
* Warning this is slightly messed up because this.DeveloperToolbar is not the
|
|
|
|
* same as this.DeveloperToolbar when in browser.js context.
|
|
|
|
*/
|
|
|
|
DeveloperToolbar.introShownThisSession = false;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the developer toolbar
|
|
|
|
*/
|
2013-09-03 04:20:27 -07:00
|
|
|
DeveloperToolbar.prototype.show = function(focus) {
|
|
|
|
if (this._showPromise != null) {
|
|
|
|
return this._showPromise;
|
2012-05-10 10:33:54 -07:00
|
|
|
}
|
|
|
|
|
2013-09-03 04:20:27 -07:00
|
|
|
// hide() is async, so ensure we don't need to wait for hide() to finish
|
|
|
|
var waitPromise = this._hidePromise || promise.resolve();
|
2012-06-15 06:55:33 -07:00
|
|
|
|
2013-09-03 04:20:27 -07:00
|
|
|
this._showPromise = waitPromise.then(() => {
|
|
|
|
Services.prefs.setBoolPref("devtools.toolbar.visible", true);
|
2012-05-10 10:33:54 -07:00
|
|
|
|
2013-09-03 04:20:27 -07:00
|
|
|
this._telemetry.toolOpened("developertoolbar");
|
2012-05-10 10:33:54 -07:00
|
|
|
|
2013-09-03 04:20:27 -07:00
|
|
|
this._notify(NOTIFICATIONS.LOAD);
|
2012-05-10 10:33:54 -07:00
|
|
|
|
2013-09-03 04:20:27 -07:00
|
|
|
this._input = this._doc.querySelector(".gclitoolbar-input-node");
|
2012-05-10 10:33:54 -07:00
|
|
|
|
2013-09-03 04:20:27 -07:00
|
|
|
// Initializing GCLI can only be done when we've got content windows to
|
|
|
|
// write to, so this needs to be done asynchronously.
|
|
|
|
let panelPromises = [
|
|
|
|
TooltipPanel.create(this),
|
|
|
|
OutputPanel.create(this)
|
|
|
|
];
|
|
|
|
return promise.all(panelPromises).then(panels => {
|
|
|
|
[ this.tooltipPanel, this.outputPanel ] = panels;
|
2012-07-04 15:37:25 -07:00
|
|
|
|
2013-09-03 04:20:27 -07:00
|
|
|
this._doc.getElementById("Tools:DevToolbar").setAttribute("checked", "true");
|
2012-05-10 10:33:54 -07:00
|
|
|
|
2014-06-09 07:16:26 -07:00
|
|
|
return gcli.load().then(() => {
|
|
|
|
this.display = gcli.createDisplay({
|
|
|
|
contentDocument: this._chromeWindow.getBrowser().contentDocument,
|
|
|
|
chromeDocument: this._doc,
|
|
|
|
chromeWindow: this._chromeWindow,
|
|
|
|
hintElement: this.tooltipPanel.hintElement,
|
|
|
|
inputElement: this._input,
|
|
|
|
completeElement: this._doc.querySelector(".gclitoolbar-complete-node"),
|
|
|
|
backgroundElement: this._doc.querySelector(".gclitoolbar-stack-node"),
|
|
|
|
outputDocument: this.outputPanel.document,
|
|
|
|
environment: CommandUtils.createEnvironment(this, "target"),
|
|
|
|
tooltipClass: "gcliterm-tooltip",
|
|
|
|
eval: null,
|
|
|
|
scratchpad: null
|
|
|
|
});
|
|
|
|
|
|
|
|
this.display.focusManager.addMonitoredElement(this.outputPanel._frame);
|
|
|
|
this.display.focusManager.addMonitoredElement(this._element);
|
|
|
|
|
|
|
|
this.display.onVisibilityChange.add(this.outputPanel._visibilityChanged,
|
|
|
|
this.outputPanel);
|
|
|
|
this.display.onVisibilityChange.add(this.tooltipPanel._visibilityChanged,
|
|
|
|
this.tooltipPanel);
|
|
|
|
this.display.onOutput.add(this.outputPanel._outputChanged, this.outputPanel);
|
|
|
|
|
|
|
|
let tabbrowser = this._chromeWindow.getBrowser();
|
|
|
|
tabbrowser.tabContainer.addEventListener("TabSelect", this, false);
|
|
|
|
tabbrowser.tabContainer.addEventListener("TabClose", this, false);
|
|
|
|
tabbrowser.addEventListener("load", this, true);
|
|
|
|
tabbrowser.addEventListener("beforeunload", this, true);
|
|
|
|
|
|
|
|
this._initErrorsCount(tabbrowser.selectedTab);
|
|
|
|
this._devtoolsUnloaded = this._devtoolsUnloaded.bind(this);
|
|
|
|
this._devtoolsLoaded = this._devtoolsLoaded.bind(this);
|
|
|
|
Services.obs.addObserver(this._devtoolsUnloaded, "devtools-unloaded", false);
|
|
|
|
Services.obs.addObserver(this._devtoolsLoaded, "devtools-loaded", false);
|
|
|
|
|
|
|
|
this._element.hidden = false;
|
|
|
|
|
|
|
|
if (focus) {
|
|
|
|
this._input.focus();
|
|
|
|
}
|
2013-09-03 04:20:27 -07:00
|
|
|
|
2014-06-09 07:16:26 -07:00
|
|
|
this._notify(NOTIFICATIONS.SHOW);
|
2013-09-03 04:20:27 -07:00
|
|
|
|
2014-06-09 07:16:26 -07:00
|
|
|
if (!DeveloperToolbar.introShownThisSession) {
|
|
|
|
this.display.maybeShowIntro();
|
|
|
|
DeveloperToolbar.introShownThisSession = true;
|
|
|
|
}
|
2013-09-03 04:20:27 -07:00
|
|
|
|
2014-06-09 07:16:26 -07:00
|
|
|
this._showPromise = null;
|
|
|
|
});
|
2013-09-03 04:20:27 -07:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
return this._showPromise;
|
|
|
|
};
|
2012-05-10 10:33:54 -07:00
|
|
|
|
2013-09-03 04:20:27 -07:00
|
|
|
/**
|
|
|
|
* Hide the developer toolbar.
|
|
|
|
*/
|
|
|
|
DeveloperToolbar.prototype.hide = function() {
|
|
|
|
// If we're already in the process of hiding, just use the other promise
|
|
|
|
if (this._hidePromise != null) {
|
|
|
|
return this._hidePromise;
|
2012-05-10 10:33:54 -07:00
|
|
|
}
|
2013-09-03 04:20:27 -07:00
|
|
|
|
|
|
|
// show() is async, so ensure we don't need to wait for show() to finish
|
|
|
|
var waitPromise = this._showPromise || promise.resolve();
|
|
|
|
|
|
|
|
this._hidePromise = waitPromise.then(() => {
|
|
|
|
this._element.hidden = true;
|
|
|
|
|
|
|
|
Services.prefs.setBoolPref("devtools.toolbar.visible", false);
|
|
|
|
|
|
|
|
this._doc.getElementById("Tools:DevToolbar").setAttribute("checked", "false");
|
|
|
|
this.destroy();
|
|
|
|
|
|
|
|
this._telemetry.toolClosed("developertoolbar");
|
|
|
|
this._notify(NOTIFICATIONS.HIDE);
|
|
|
|
|
|
|
|
this._hidePromise = null;
|
|
|
|
});
|
|
|
|
|
|
|
|
return this._hidePromise;
|
2012-05-10 10:33:54 -07:00
|
|
|
};
|
|
|
|
|
2013-08-03 03:29:48 -07:00
|
|
|
/**
|
|
|
|
* The devtools-unloaded event handler.
|
|
|
|
* @private
|
|
|
|
*/
|
2013-09-03 04:20:27 -07:00
|
|
|
DeveloperToolbar.prototype._devtoolsUnloaded = function() {
|
2013-08-03 03:29:48 -07:00
|
|
|
let tabbrowser = this._chromeWindow.getBrowser();
|
|
|
|
Array.prototype.forEach.call(tabbrowser.tabs, this._stopErrorsCount, this);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The devtools-loaded event handler.
|
|
|
|
* @private
|
|
|
|
*/
|
2013-09-03 04:20:27 -07:00
|
|
|
DeveloperToolbar.prototype._devtoolsLoaded = function() {
|
2013-08-03 03:29:48 -07:00
|
|
|
let tabbrowser = this._chromeWindow.getBrowser();
|
|
|
|
this._initErrorsCount(tabbrowser.selectedTab);
|
|
|
|
};
|
|
|
|
|
2012-06-14 04:36:48 -07:00
|
|
|
/**
|
|
|
|
* Initialize the listeners needed for tracking the number of errors for a given
|
|
|
|
* tab.
|
|
|
|
*
|
|
|
|
* @private
|
2013-09-03 04:20:27 -07:00
|
|
|
* @param nsIDOMNode tab the xul:tab for which you want to track the number of
|
2012-06-14 04:36:48 -07:00
|
|
|
* errors.
|
|
|
|
*/
|
2013-09-03 04:20:27 -07:00
|
|
|
DeveloperToolbar.prototype._initErrorsCount = function(tab) {
|
|
|
|
let tabId = tab.linkedPanel;
|
2012-06-14 04:36:48 -07:00
|
|
|
if (tabId in this._errorsCount) {
|
|
|
|
this._updateErrorsCount();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-09-03 04:20:27 -07:00
|
|
|
let window = tab.linkedBrowser.contentWindow;
|
2013-05-28 08:24:31 -07:00
|
|
|
let listener = new ConsoleServiceListener(window, {
|
|
|
|
onConsoleServiceMessage: this._onPageError.bind(this, tabId),
|
2012-10-05 09:15:51 -07:00
|
|
|
});
|
|
|
|
listener.init();
|
2012-06-14 04:36:48 -07:00
|
|
|
|
2012-10-05 09:15:51 -07:00
|
|
|
this._errorListeners[tabId] = listener;
|
2012-06-14 04:36:48 -07:00
|
|
|
this._errorsCount[tabId] = 0;
|
2013-01-22 07:55:02 -08:00
|
|
|
this._warningsCount[tabId] = 0;
|
2012-06-14 04:36:48 -07:00
|
|
|
|
2012-10-05 09:15:51 -07:00
|
|
|
let messages = listener.getCachedMessages();
|
|
|
|
messages.forEach(this._onPageError.bind(this, tabId));
|
2012-06-14 04:36:48 -07:00
|
|
|
|
|
|
|
this._updateErrorsCount();
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Stop the listeners needed for tracking the number of errors for a given
|
|
|
|
* tab.
|
|
|
|
*
|
|
|
|
* @private
|
2013-09-03 04:20:27 -07:00
|
|
|
* @param nsIDOMNode tab the xul:tab for which you want to stop tracking the
|
2012-06-14 04:36:48 -07:00
|
|
|
* number of errors.
|
|
|
|
*/
|
2013-09-03 04:20:27 -07:00
|
|
|
DeveloperToolbar.prototype._stopErrorsCount = function(tab) {
|
|
|
|
let tabId = tab.linkedPanel;
|
2013-01-22 07:55:02 -08:00
|
|
|
if (!(tabId in this._errorsCount) || !(tabId in this._warningsCount)) {
|
2012-06-14 04:36:48 -07:00
|
|
|
this._updateErrorsCount();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-10-05 09:15:51 -07:00
|
|
|
this._errorListeners[tabId].destroy();
|
|
|
|
delete this._errorListeners[tabId];
|
2012-06-14 04:36:48 -07:00
|
|
|
delete this._errorsCount[tabId];
|
2013-01-22 07:55:02 -08:00
|
|
|
delete this._warningsCount[tabId];
|
2012-10-05 09:15:51 -07:00
|
|
|
|
2012-06-14 04:36:48 -07:00
|
|
|
this._updateErrorsCount();
|
|
|
|
};
|
|
|
|
|
2012-05-10 10:33:54 -07:00
|
|
|
/**
|
|
|
|
* Hide the developer toolbar
|
|
|
|
*/
|
2013-09-03 04:20:27 -07:00
|
|
|
DeveloperToolbar.prototype.destroy = function() {
|
|
|
|
if (this._input == null) {
|
|
|
|
return; // Already destroyed
|
2013-01-04 12:31:38 -08:00
|
|
|
}
|
|
|
|
|
2013-03-22 12:55:21 -07:00
|
|
|
let tabbrowser = this._chromeWindow.getBrowser();
|
|
|
|
tabbrowser.tabContainer.removeEventListener("TabSelect", this, false);
|
|
|
|
tabbrowser.tabContainer.removeEventListener("TabClose", this, false);
|
2013-04-20 01:59:00 -07:00
|
|
|
tabbrowser.removeEventListener("load", this, true);
|
2013-03-22 12:55:21 -07:00
|
|
|
tabbrowser.removeEventListener("beforeunload", this, true);
|
2012-06-14 04:36:48 -07:00
|
|
|
|
2013-08-03 03:29:48 -07:00
|
|
|
Services.obs.removeObserver(this._devtoolsUnloaded, "devtools-unloaded");
|
|
|
|
Services.obs.removeObserver(this._devtoolsLoaded, "devtools-loaded");
|
2013-03-22 12:55:21 -07:00
|
|
|
Array.prototype.forEach.call(tabbrowser.tabs, this._stopErrorsCount, this);
|
2012-05-10 10:33:54 -07:00
|
|
|
|
2012-07-04 15:37:25 -07:00
|
|
|
this.display.focusManager.removeMonitoredElement(this.outputPanel._frame);
|
|
|
|
this.display.focusManager.removeMonitoredElement(this._element);
|
|
|
|
|
2012-05-10 10:33:54 -07:00
|
|
|
this.display.onVisibilityChange.remove(this.outputPanel._visibilityChanged, this.outputPanel);
|
|
|
|
this.display.onVisibilityChange.remove(this.tooltipPanel._visibilityChanged, this.tooltipPanel);
|
|
|
|
this.display.onOutput.remove(this.outputPanel._outputChanged, this.outputPanel);
|
|
|
|
this.display.destroy();
|
|
|
|
this.outputPanel.destroy();
|
|
|
|
this.tooltipPanel.destroy();
|
|
|
|
delete this._input;
|
|
|
|
|
|
|
|
// We could "delete this.display" etc if we have hard-to-track-down memory
|
|
|
|
// leaks as a belt-and-braces approach, however this prevents our DOM node
|
|
|
|
// hunter from looking in all the nooks and crannies, so it's better if we
|
|
|
|
// can be leak-free without
|
2012-05-17 11:04:33 -07:00
|
|
|
/*
|
2012-05-10 10:33:54 -07:00
|
|
|
delete this.display;
|
|
|
|
delete this.outputPanel;
|
|
|
|
delete this.tooltipPanel;
|
2012-05-17 11:04:33 -07:00
|
|
|
*/
|
2012-05-10 10:33:54 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Utility for sending notifications
|
2013-09-03 04:20:27 -07:00
|
|
|
* @param topic a NOTIFICATION constant
|
2012-05-10 10:33:54 -07:00
|
|
|
*/
|
2013-09-03 04:20:27 -07:00
|
|
|
DeveloperToolbar.prototype._notify = function(topic) {
|
2012-05-10 10:33:54 -07:00
|
|
|
let data = { toolbar: this };
|
|
|
|
data.wrappedJSObject = data;
|
2013-09-03 04:20:27 -07:00
|
|
|
Services.obs.notifyObservers(data, topic, null);
|
2012-05-10 10:33:54 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update various parts of the UI when the current tab changes
|
|
|
|
*/
|
2013-09-03 04:20:27 -07:00
|
|
|
DeveloperToolbar.prototype.handleEvent = function(ev) {
|
|
|
|
if (ev.type == "TabSelect" || ev.type == "load") {
|
2012-05-10 10:33:54 -07:00
|
|
|
if (this.visible) {
|
|
|
|
this.display.reattach({
|
2013-09-03 04:20:27 -07:00
|
|
|
contentDocument: this._chromeWindow.getBrowser().contentDocument
|
2012-05-10 10:33:54 -07:00
|
|
|
});
|
2012-06-14 04:36:48 -07:00
|
|
|
|
2013-09-03 04:20:27 -07:00
|
|
|
if (ev.type == "TabSelect") {
|
|
|
|
this._initErrorsCount(ev.target);
|
2012-06-14 04:36:48 -07:00
|
|
|
}
|
2012-05-10 10:33:54 -07:00
|
|
|
}
|
|
|
|
}
|
2013-09-03 04:20:27 -07:00
|
|
|
else if (ev.type == "TabClose") {
|
|
|
|
this._stopErrorsCount(ev.target);
|
2012-06-14 04:36:48 -07:00
|
|
|
}
|
2013-09-03 04:20:27 -07:00
|
|
|
else if (ev.type == "beforeunload") {
|
|
|
|
this._onPageBeforeUnload(ev);
|
2012-06-14 04:36:48 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2012-10-05 09:15:51 -07:00
|
|
|
* Count a page error received for the currently selected tab. This
|
|
|
|
* method counts the JavaScript exceptions received and CSS errors/warnings.
|
2012-06-14 04:36:48 -07:00
|
|
|
*
|
|
|
|
* @private
|
2013-09-03 04:20:27 -07:00
|
|
|
* @param string tabId the ID of the tab from where the page error comes.
|
|
|
|
* @param object pageError the page error object received from the
|
2012-10-05 09:15:51 -07:00
|
|
|
* PageErrorListener.
|
2012-06-14 04:36:48 -07:00
|
|
|
*/
|
2013-09-03 04:20:27 -07:00
|
|
|
DeveloperToolbar.prototype._onPageError = function(tabId, pageError) {
|
|
|
|
if (pageError.category == "CSS Parser" ||
|
|
|
|
pageError.category == "CSS Loader") {
|
2013-01-22 07:55:02 -08:00
|
|
|
return;
|
|
|
|
}
|
2013-09-03 04:20:27 -07:00
|
|
|
if ((pageError.flags & pageError.warningFlag) ||
|
|
|
|
(pageError.flags & pageError.strictFlag)) {
|
|
|
|
this._warningsCount[tabId]++;
|
2013-01-22 07:55:02 -08:00
|
|
|
} else {
|
2013-09-03 04:20:27 -07:00
|
|
|
this._errorsCount[tabId]++;
|
2012-06-14 04:36:48 -07:00
|
|
|
}
|
2013-09-03 04:20:27 -07:00
|
|
|
this._updateErrorsCount(tabId);
|
2012-06-14 04:36:48 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The |beforeunload| event handler. This function resets the errors count when
|
|
|
|
* a different page starts loading.
|
|
|
|
*
|
|
|
|
* @private
|
2013-09-03 04:20:27 -07:00
|
|
|
* @param nsIDOMEvent ev the beforeunload DOM event.
|
2012-06-14 04:36:48 -07:00
|
|
|
*/
|
2013-09-03 04:20:27 -07:00
|
|
|
DeveloperToolbar.prototype._onPageBeforeUnload = function(ev) {
|
|
|
|
let window = ev.target.defaultView;
|
2012-06-14 04:36:48 -07:00
|
|
|
if (window.top !== window) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let tabs = this._chromeWindow.getBrowser().tabs;
|
2013-09-03 04:20:27 -07:00
|
|
|
Array.prototype.some.call(tabs, function(tab) {
|
|
|
|
if (tab.linkedBrowser.contentWindow === window) {
|
|
|
|
let tabId = tab.linkedPanel;
|
2013-01-22 07:55:02 -08:00
|
|
|
if (tabId in this._errorsCount || tabId in this._warningsCount) {
|
2012-06-14 04:36:48 -07:00
|
|
|
this._errorsCount[tabId] = 0;
|
2013-01-22 07:55:02 -08:00
|
|
|
this._warningsCount[tabId] = 0;
|
2012-06-14 04:36:48 -07:00
|
|
|
this._updateErrorsCount(tabId);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}, this);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the page errors count displayed in the Web Console button for the
|
|
|
|
* currently selected tab.
|
|
|
|
*
|
|
|
|
* @private
|
2013-09-03 04:20:27 -07:00
|
|
|
* @param string [changedTabId] Optional. The tab ID that had its page errors
|
2012-06-14 04:36:48 -07:00
|
|
|
* count changed. If this is provided and it doesn't match the currently
|
|
|
|
* selected tab, then the button is not updated.
|
|
|
|
*/
|
2013-09-03 04:20:27 -07:00
|
|
|
DeveloperToolbar.prototype._updateErrorsCount = function(changedTabId) {
|
2012-06-14 04:36:48 -07:00
|
|
|
let tabId = this._chromeWindow.getBrowser().selectedTab.linkedPanel;
|
2013-09-03 04:20:27 -07:00
|
|
|
if (changedTabId && tabId != changedTabId) {
|
2012-06-14 04:36:48 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let errors = this._errorsCount[tabId];
|
2013-01-22 07:55:02 -08:00
|
|
|
let warnings = this._warningsCount[tabId];
|
|
|
|
let btn = this._errorCounterButton;
|
2012-06-14 04:36:48 -07:00
|
|
|
if (errors) {
|
2013-01-25 08:14:53 -08:00
|
|
|
let errorsText = toolboxStrings
|
2013-02-15 13:29:44 -08:00
|
|
|
.GetStringFromName("toolboxToggleButton.errors");
|
|
|
|
errorsText = PluralForm.get(errors, errorsText).replace("#1", errors);
|
2013-01-25 08:14:53 -08:00
|
|
|
|
|
|
|
let warningsText = toolboxStrings
|
2013-02-15 13:29:44 -08:00
|
|
|
.GetStringFromName("toolboxToggleButton.warnings");
|
|
|
|
warningsText = PluralForm.get(warnings, warningsText).replace("#1", warnings);
|
2013-01-25 08:14:53 -08:00
|
|
|
|
|
|
|
let tooltiptext = toolboxStrings
|
2013-02-15 13:29:44 -08:00
|
|
|
.formatStringFromName("toolboxToggleButton.tooltip",
|
|
|
|
[errorsText, warningsText], 2);
|
2013-01-25 08:14:53 -08:00
|
|
|
|
2013-01-22 07:55:02 -08:00
|
|
|
btn.setAttribute("error-count", errors);
|
|
|
|
btn.setAttribute("tooltiptext", tooltiptext);
|
2012-07-05 08:02:28 -07:00
|
|
|
} else {
|
2013-01-22 07:55:02 -08:00
|
|
|
btn.removeAttribute("error-count");
|
|
|
|
btn.setAttribute("tooltiptext", btn._defaultTooltipText);
|
2012-06-14 04:36:48 -07:00
|
|
|
}
|
2013-05-22 13:32:58 -07:00
|
|
|
|
|
|
|
this.emit("errors-counter-updated");
|
2012-05-22 00:50:02 -07:00
|
|
|
};
|
2012-05-10 10:33:54 -07:00
|
|
|
|
2012-06-25 08:58:14 -07:00
|
|
|
/**
|
|
|
|
* Reset the errors counter for the given tab.
|
|
|
|
*
|
2013-09-03 04:20:27 -07:00
|
|
|
* @param nsIDOMElement tab The xul:tab for which you want to reset the page
|
2012-06-25 08:58:14 -07:00
|
|
|
* errors counters.
|
|
|
|
*/
|
2013-09-03 04:20:27 -07:00
|
|
|
DeveloperToolbar.prototype.resetErrorsCount = function(tab) {
|
|
|
|
let tabId = tab.linkedPanel;
|
2013-01-22 07:55:02 -08:00
|
|
|
if (tabId in this._errorsCount || tabId in this._warningsCount) {
|
2012-06-25 08:58:14 -07:00
|
|
|
this._errorsCount[tabId] = 0;
|
2013-01-22 07:55:02 -08:00
|
|
|
this._warningsCount[tabId] = 0;
|
2012-06-25 08:58:14 -07:00
|
|
|
this._updateErrorsCount(tabId);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-09-03 04:20:27 -07:00
|
|
|
/**
|
|
|
|
* Creating a OutputPanel is asynchronous
|
|
|
|
*/
|
|
|
|
function OutputPanel() {
|
|
|
|
throw new Error('Use OutputPanel.create()');
|
|
|
|
}
|
|
|
|
|
2012-05-10 10:33:54 -07:00
|
|
|
/**
|
|
|
|
* Panel to handle command line output.
|
2012-08-30 03:03:19 -07:00
|
|
|
*
|
|
|
|
* There is a tooltip bug on Windows and OSX that prevents tooltips from being
|
|
|
|
* positioned properly (bug 786975). There is a Gnome panel bug on Linux that
|
|
|
|
* causes ugly focus issues (https://bugzilla.gnome.org/show_bug.cgi?id=621848).
|
|
|
|
* We now use a tooltip on Linux and a panel on OSX & Windows.
|
|
|
|
*
|
|
|
|
* If a panel has no content and no height it is not shown when openPopup is
|
|
|
|
* called on Windows and OSX (bug 692348) ... this prevents the panel from
|
|
|
|
* appearing the first time it is shown. Setting the panel's height to 1px
|
|
|
|
* before calling openPopup works around this issue as we resize it ourselves
|
|
|
|
* anyway.
|
|
|
|
*
|
2013-09-03 04:20:27 -07:00
|
|
|
* @param devtoolbar The parent DeveloperToolbar object
|
2012-05-10 10:33:54 -07:00
|
|
|
*/
|
2013-09-03 04:20:27 -07:00
|
|
|
OutputPanel.create = function(devtoolbar) {
|
|
|
|
var outputPanel = Object.create(OutputPanel.prototype);
|
|
|
|
return outputPanel._init(devtoolbar);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @private See OutputPanel.create
|
|
|
|
*/
|
|
|
|
OutputPanel.prototype._init = function(devtoolbar) {
|
|
|
|
this._devtoolbar = devtoolbar;
|
2013-03-22 12:55:21 -07:00
|
|
|
this._input = this._devtoolbar._input;
|
|
|
|
this._toolbar = this._devtoolbar._doc.getElementById("developer-toolbar");
|
2012-05-10 10:33:54 -07:00
|
|
|
|
|
|
|
/*
|
2012-08-30 03:03:19 -07:00
|
|
|
<tooltip|panel id="gcli-output"
|
2012-05-10 10:33:54 -07:00
|
|
|
noautofocus="true"
|
|
|
|
noautohide="true"
|
|
|
|
class="gcli-panel">
|
2012-05-22 00:50:02 -07:00
|
|
|
<html:iframe xmlns:html="http://www.w3.org/1999/xhtml"
|
|
|
|
id="gcli-output-frame"
|
2012-08-14 07:51:48 -07:00
|
|
|
src="chrome://browser/content/devtools/commandlineoutput.xhtml"
|
2012-11-01 19:54:13 -07:00
|
|
|
sandbox="allow-same-origin"/>
|
2012-08-30 03:03:19 -07:00
|
|
|
</tooltip|panel>
|
2012-05-10 10:33:54 -07:00
|
|
|
*/
|
2012-08-03 03:05:24 -07:00
|
|
|
|
|
|
|
// TODO: Switch back from tooltip to panel when metacity focus issue is fixed:
|
|
|
|
// https://bugzilla.mozilla.org/show_bug.cgi?id=780102
|
2013-03-22 12:55:21 -07:00
|
|
|
this._panel = this._devtoolbar._doc.createElement(isLinux ? "tooltip" : "panel");
|
2012-08-03 03:05:24 -07:00
|
|
|
|
2012-05-10 10:33:54 -07:00
|
|
|
this._panel.id = "gcli-output";
|
|
|
|
this._panel.classList.add("gcli-panel");
|
2012-08-30 03:03:19 -07:00
|
|
|
|
|
|
|
if (isLinux) {
|
|
|
|
this.canHide = false;
|
|
|
|
this._onpopuphiding = this._onpopuphiding.bind(this);
|
|
|
|
this._panel.addEventListener("popuphiding", this._onpopuphiding, true);
|
|
|
|
} else {
|
|
|
|
this._panel.setAttribute("noautofocus", "true");
|
|
|
|
this._panel.setAttribute("noautohide", "true");
|
|
|
|
|
|
|
|
// Bug 692348: On Windows and OSX if a panel has no content and no height
|
|
|
|
// openPopup fails to display it. Setting the height to 1px alows the panel
|
|
|
|
// to be displayed before has content or a real height i.e. the first time
|
|
|
|
// it is displayed.
|
|
|
|
this._panel.setAttribute("height", "1px");
|
|
|
|
}
|
|
|
|
|
2012-05-22 00:50:02 -07:00
|
|
|
this._toolbar.parentElement.insertBefore(this._panel, this._toolbar);
|
2012-05-10 10:33:54 -07:00
|
|
|
|
2013-03-22 12:55:21 -07:00
|
|
|
this._frame = this._devtoolbar._doc.createElementNS(NS_XHTML, "iframe");
|
2012-05-10 10:33:54 -07:00
|
|
|
this._frame.id = "gcli-output-frame";
|
2012-08-14 07:51:48 -07:00
|
|
|
this._frame.setAttribute("src", "chrome://browser/content/devtools/commandlineoutput.xhtml");
|
2012-11-01 19:54:13 -07:00
|
|
|
this._frame.setAttribute("sandbox", "allow-same-origin");
|
2012-05-10 10:33:54 -07:00
|
|
|
this._panel.appendChild(this._frame);
|
|
|
|
|
|
|
|
this.displayedOutput = undefined;
|
|
|
|
|
2013-05-09 07:15:22 -07:00
|
|
|
this._update = this._update.bind(this);
|
2012-05-10 10:33:54 -07:00
|
|
|
|
2013-09-03 04:20:27 -07:00
|
|
|
// Wire up the element from the iframe, and resolve the promise
|
|
|
|
let deferred = promise.defer();
|
|
|
|
let onload = () => {
|
|
|
|
this._frame.removeEventListener("load", onload, true);
|
2012-05-10 10:33:54 -07:00
|
|
|
|
2013-09-03 04:20:27 -07:00
|
|
|
this.document = this._frame.contentDocument;
|
2012-05-10 10:33:54 -07:00
|
|
|
|
2013-09-03 04:20:27 -07:00
|
|
|
this._div = this.document.getElementById("gcli-output-root");
|
|
|
|
this._div.classList.add('gcli-row-out');
|
|
|
|
this._div.setAttribute('aria-live', 'assertive');
|
2012-05-10 10:33:54 -07:00
|
|
|
|
2013-09-03 04:20:27 -07:00
|
|
|
let styles = this._toolbar.ownerDocument.defaultView
|
|
|
|
.getComputedStyle(this._toolbar);
|
|
|
|
this._div.setAttribute("dir", styles.direction);
|
2012-05-10 10:33:54 -07:00
|
|
|
|
2013-09-03 04:20:27 -07:00
|
|
|
deferred.resolve(this);
|
|
|
|
};
|
|
|
|
this._frame.addEventListener("load", onload, true);
|
2012-06-01 00:24:19 -07:00
|
|
|
|
2013-09-03 04:20:27 -07:00
|
|
|
return deferred.promise;
|
|
|
|
}
|
2012-05-10 10:33:54 -07:00
|
|
|
|
2012-08-03 03:05:24 -07:00
|
|
|
/**
|
|
|
|
* Prevent the popup from hiding if it is not permitted via this.canHide.
|
|
|
|
*/
|
2013-09-03 04:20:27 -07:00
|
|
|
OutputPanel.prototype._onpopuphiding = function(ev) {
|
2012-08-03 03:05:24 -07:00
|
|
|
// TODO: When we switch back from tooltip to panel we can remove this hack:
|
|
|
|
// https://bugzilla.mozilla.org/show_bug.cgi?id=780102
|
2012-08-30 03:03:19 -07:00
|
|
|
if (isLinux && !this.canHide) {
|
2013-09-03 04:20:27 -07:00
|
|
|
ev.preventDefault();
|
2012-08-03 03:05:24 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-05-10 10:33:54 -07:00
|
|
|
/**
|
|
|
|
* Display the OutputPanel.
|
|
|
|
*/
|
2013-09-03 04:20:27 -07:00
|
|
|
OutputPanel.prototype.show = function() {
|
2012-08-30 03:03:19 -07:00
|
|
|
if (isLinux) {
|
|
|
|
this.canHide = false;
|
|
|
|
}
|
2012-08-03 03:05:24 -07:00
|
|
|
|
2012-10-04 02:32:36 -07:00
|
|
|
// We need to reset the iframe size in order for future size calculations to
|
|
|
|
// be correct
|
|
|
|
this._frame.style.minHeight = this._frame.style.maxHeight = 0;
|
|
|
|
this._frame.style.minWidth = 0;
|
|
|
|
|
2012-05-22 00:50:02 -07:00
|
|
|
this._panel.openPopup(this._input, "before_start", 0, 0, false, false, null);
|
2012-05-10 10:33:54 -07:00
|
|
|
this._resize();
|
|
|
|
|
|
|
|
this._input.focus();
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal helper to set the height of the output panel to fit the available
|
|
|
|
* content;
|
|
|
|
*/
|
2013-09-03 04:20:27 -07:00
|
|
|
OutputPanel.prototype._resize = function() {
|
2012-05-22 00:50:02 -07:00
|
|
|
if (this._panel == null || this.document == null || !this._panel.state == "closed") {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2012-10-04 02:32:36 -07:00
|
|
|
// Set max panel width to match any content with a max of the width of the
|
|
|
|
// browser window.
|
|
|
|
let maxWidth = this._panel.ownerDocument.documentElement.clientWidth;
|
|
|
|
|
2013-05-10 06:46:28 -07:00
|
|
|
// Adjust max width according to OS.
|
|
|
|
// We'd like to put this in CSS but we can't:
|
|
|
|
// body { width: calc(min(-5px, max-content)); }
|
|
|
|
// #_panel { max-width: -5px; }
|
|
|
|
switch(OS) {
|
|
|
|
case "Linux":
|
|
|
|
maxWidth -= 5;
|
|
|
|
break;
|
|
|
|
case "Darwin":
|
|
|
|
maxWidth -= 25;
|
|
|
|
break;
|
|
|
|
case "WINNT":
|
|
|
|
maxWidth -= 5;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.document.body.style.width = "-moz-max-content";
|
|
|
|
let style = this._frame.contentWindow.getComputedStyle(this.document.body);
|
|
|
|
let frameWidth = parseInt(style.width, 10);
|
|
|
|
let width = Math.min(maxWidth, frameWidth);
|
|
|
|
this.document.body.style.width = width + "px";
|
2012-10-04 02:32:36 -07:00
|
|
|
|
|
|
|
// Set the width of the iframe.
|
|
|
|
this._frame.style.minWidth = width + "px";
|
2013-05-10 06:46:28 -07:00
|
|
|
this._panel.style.maxWidth = maxWidth + "px";
|
2012-10-04 02:32:36 -07:00
|
|
|
|
|
|
|
// browserAdjustment is used to correct the panel height according to the
|
|
|
|
// browsers borders etc.
|
|
|
|
const browserAdjustment = 15;
|
|
|
|
|
|
|
|
// Set max panel height to match any content with a max of the height of the
|
|
|
|
// browser window.
|
|
|
|
let maxHeight =
|
|
|
|
this._panel.ownerDocument.documentElement.clientHeight - browserAdjustment;
|
|
|
|
let height = Math.min(maxHeight, this.document.documentElement.scrollHeight);
|
|
|
|
|
|
|
|
// Set the height of the iframe. Setting iframe.height does not work.
|
|
|
|
this._frame.style.minHeight = this._frame.style.maxHeight = height + "px";
|
|
|
|
|
|
|
|
// Set the height and width of the panel to match the iframe.
|
|
|
|
this._panel.sizeTo(width, height);
|
|
|
|
|
|
|
|
// Move the panel to the correct position in the case that it has been
|
|
|
|
// positioned incorrectly.
|
|
|
|
let screenX = this._input.boxObject.screenX;
|
|
|
|
let screenY = this._toolbar.boxObject.screenY;
|
|
|
|
this._panel.moveTo(screenX, screenY - height);
|
2012-05-10 10:33:54 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called by GCLI when a command is executed.
|
|
|
|
*/
|
2013-09-03 04:20:27 -07:00
|
|
|
OutputPanel.prototype._outputChanged = function(ev) {
|
|
|
|
if (ev.output.hidden) {
|
2012-05-10 10:33:54 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.remove();
|
|
|
|
|
2013-09-03 04:20:27 -07:00
|
|
|
this.displayedOutput = ev.output;
|
2013-05-09 07:15:22 -07:00
|
|
|
|
|
|
|
if (this.displayedOutput.completed) {
|
|
|
|
this._update();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this.displayedOutput.promise.then(this._update, this._update)
|
|
|
|
.then(null, console.error);
|
|
|
|
}
|
2012-05-10 10:33:54 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when displayed Output says it's changed or from outputChanged, which
|
|
|
|
* happens when there is a new displayed Output.
|
|
|
|
*/
|
2013-09-03 04:20:27 -07:00
|
|
|
OutputPanel.prototype._update = function() {
|
2013-05-09 07:15:22 -07:00
|
|
|
// destroy has been called, bail out
|
|
|
|
if (this._div == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-03-22 12:55:21 -07:00
|
|
|
// Empty this._div
|
|
|
|
while (this._div.hasChildNodes()) {
|
|
|
|
this._div.removeChild(this._div.firstChild);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.displayedOutput.data != null) {
|
2013-09-03 04:20:27 -07:00
|
|
|
let context = this._devtoolbar.display.requisition.conversionContext;
|
2014-05-22 03:04:47 -07:00
|
|
|
this.displayedOutput.convert('dom', context).then(node => {
|
|
|
|
if (node == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-03-22 12:55:21 -07:00
|
|
|
while (this._div.hasChildNodes()) {
|
|
|
|
this._div.removeChild(this._div.firstChild);
|
|
|
|
}
|
|
|
|
|
|
|
|
var links = node.ownerDocument.querySelectorAll('*[href]');
|
|
|
|
for (var i = 0; i < links.length; i++) {
|
|
|
|
links[i].setAttribute('target', '_blank');
|
|
|
|
}
|
|
|
|
|
|
|
|
this._div.appendChild(node);
|
2013-09-03 04:20:27 -07:00
|
|
|
this.show();
|
|
|
|
});
|
2012-05-10 10:33:54 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Detach listeners from the currently displayed Output.
|
|
|
|
*/
|
2013-09-03 04:20:27 -07:00
|
|
|
OutputPanel.prototype.remove = function() {
|
2012-08-30 03:03:19 -07:00
|
|
|
if (isLinux) {
|
|
|
|
this.canHide = true;
|
|
|
|
}
|
2012-08-23 06:48:23 -07:00
|
|
|
|
2012-10-02 08:53:00 -07:00
|
|
|
if (this._panel && this._panel.hidePopup) {
|
2012-08-23 06:48:23 -07:00
|
|
|
this._panel.hidePopup();
|
|
|
|
}
|
2012-05-10 10:33:54 -07:00
|
|
|
|
|
|
|
if (this.displayedOutput) {
|
|
|
|
delete this.displayedOutput;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Detach listeners from the currently displayed Output.
|
|
|
|
*/
|
2013-09-03 04:20:27 -07:00
|
|
|
OutputPanel.prototype.destroy = function() {
|
2012-05-10 10:33:54 -07:00
|
|
|
this.remove();
|
|
|
|
|
2012-08-03 03:05:24 -07:00
|
|
|
this._panel.removeEventListener("popuphiding", this._onpopuphiding, true);
|
|
|
|
|
2012-05-10 10:33:54 -07:00
|
|
|
this._panel.removeChild(this._frame);
|
2012-05-22 00:50:02 -07:00
|
|
|
this._toolbar.parentElement.removeChild(this._panel);
|
2012-05-10 10:33:54 -07:00
|
|
|
|
2013-03-22 12:55:21 -07:00
|
|
|
delete this._devtoolbar;
|
2012-05-10 10:33:54 -07:00
|
|
|
delete this._input;
|
2012-05-22 00:50:02 -07:00
|
|
|
delete this._toolbar;
|
2012-08-03 03:05:24 -07:00
|
|
|
delete this._onpopuphiding;
|
2012-05-10 10:33:54 -07:00
|
|
|
delete this._panel;
|
|
|
|
delete this._frame;
|
|
|
|
delete this._content;
|
|
|
|
delete this._div;
|
|
|
|
delete this.document;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called by GCLI to indicate that we should show or hide one either the
|
|
|
|
* tooltip panel or the output panel.
|
|
|
|
*/
|
2013-09-03 04:20:27 -07:00
|
|
|
OutputPanel.prototype._visibilityChanged = function(ev) {
|
|
|
|
if (ev.outputVisible === true) {
|
2012-05-10 10:33:54 -07:00
|
|
|
// this.show is called by _outputChanged
|
|
|
|
} else {
|
2012-08-30 03:03:19 -07:00
|
|
|
if (isLinux) {
|
|
|
|
this.canHide = true;
|
|
|
|
}
|
2012-05-10 10:33:54 -07:00
|
|
|
this._panel.hidePopup();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-09-03 04:20:27 -07:00
|
|
|
/**
|
|
|
|
* Creating a TooltipPanel is asynchronous
|
|
|
|
*/
|
|
|
|
function TooltipPanel() {
|
|
|
|
throw new Error('Use TooltipPanel.create()');
|
|
|
|
}
|
2012-05-10 10:33:54 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Panel to handle tooltips.
|
2012-08-30 03:03:19 -07:00
|
|
|
*
|
|
|
|
* There is a tooltip bug on Windows and OSX that prevents tooltips from being
|
|
|
|
* positioned properly (bug 786975). There is a Gnome panel bug on Linux that
|
|
|
|
* causes ugly focus issues (https://bugzilla.gnome.org/show_bug.cgi?id=621848).
|
|
|
|
* We now use a tooltip on Linux and a panel on OSX & Windows.
|
|
|
|
*
|
|
|
|
* If a panel has no content and no height it is not shown when openPopup is
|
|
|
|
* called on Windows and OSX (bug 692348) ... this prevents the panel from
|
|
|
|
* appearing the first time it is shown. Setting the panel's height to 1px
|
|
|
|
* before calling openPopup works around this issue as we resize it ourselves
|
|
|
|
* anyway.
|
|
|
|
*
|
2013-09-03 04:20:27 -07:00
|
|
|
* @param devtoolbar The parent DeveloperToolbar object
|
2012-05-10 10:33:54 -07:00
|
|
|
*/
|
2013-09-03 04:20:27 -07:00
|
|
|
TooltipPanel.create = function(devtoolbar) {
|
|
|
|
var tooltipPanel = Object.create(TooltipPanel.prototype);
|
|
|
|
return tooltipPanel._init(devtoolbar);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @private See TooltipPanel.create
|
|
|
|
*/
|
|
|
|
TooltipPanel.prototype._init = function(devtoolbar) {
|
|
|
|
let deferred = promise.defer();
|
|
|
|
|
|
|
|
let chromeDocument = devtoolbar._doc;
|
|
|
|
this._input = devtoolbar._doc.querySelector(".gclitoolbar-input-node");
|
|
|
|
this._toolbar = devtoolbar._doc.querySelector("#developer-toolbar");
|
2012-05-22 00:50:02 -07:00
|
|
|
this._dimensions = { start: 0, end: 0 };
|
2012-05-10 10:33:54 -07:00
|
|
|
|
|
|
|
/*
|
2012-08-30 03:03:19 -07:00
|
|
|
<tooltip|panel id="gcli-tooltip"
|
2012-05-10 10:33:54 -07:00
|
|
|
type="arrow"
|
|
|
|
noautofocus="true"
|
|
|
|
noautohide="true"
|
|
|
|
class="gcli-panel">
|
2012-05-22 00:50:02 -07:00
|
|
|
<html:iframe xmlns:html="http://www.w3.org/1999/xhtml"
|
|
|
|
id="gcli-tooltip-frame"
|
2012-08-14 07:51:48 -07:00
|
|
|
src="chrome://browser/content/devtools/commandlinetooltip.xhtml"
|
2012-11-01 19:54:13 -07:00
|
|
|
flex="1"
|
|
|
|
sandbox="allow-same-origin"/>
|
2012-08-30 03:03:19 -07:00
|
|
|
</tooltip|panel>
|
2012-05-10 10:33:54 -07:00
|
|
|
*/
|
2012-08-03 03:05:24 -07:00
|
|
|
|
|
|
|
// TODO: Switch back from tooltip to panel when metacity focus issue is fixed:
|
|
|
|
// https://bugzilla.mozilla.org/show_bug.cgi?id=780102
|
2013-09-03 04:20:27 -07:00
|
|
|
this._panel = devtoolbar._doc.createElement(isLinux ? "tooltip" : "panel");
|
2012-08-03 03:05:24 -07:00
|
|
|
|
2012-05-10 10:33:54 -07:00
|
|
|
this._panel.id = "gcli-tooltip";
|
|
|
|
this._panel.classList.add("gcli-panel");
|
2012-08-30 03:03:19 -07:00
|
|
|
|
|
|
|
if (isLinux) {
|
|
|
|
this.canHide = false;
|
|
|
|
this._onpopuphiding = this._onpopuphiding.bind(this);
|
|
|
|
this._panel.addEventListener("popuphiding", this._onpopuphiding, true);
|
|
|
|
} else {
|
|
|
|
this._panel.setAttribute("noautofocus", "true");
|
|
|
|
this._panel.setAttribute("noautohide", "true");
|
|
|
|
|
|
|
|
// Bug 692348: On Windows and OSX if a panel has no content and no height
|
|
|
|
// openPopup fails to display it. Setting the height to 1px alows the panel
|
|
|
|
// to be displayed before has content or a real height i.e. the first time
|
|
|
|
// it is displayed.
|
|
|
|
this._panel.setAttribute("height", "1px");
|
|
|
|
}
|
|
|
|
|
2012-05-22 00:50:02 -07:00
|
|
|
this._toolbar.parentElement.insertBefore(this._panel, this._toolbar);
|
2012-05-10 10:33:54 -07:00
|
|
|
|
2013-09-03 04:20:27 -07:00
|
|
|
this._frame = devtoolbar._doc.createElementNS(NS_XHTML, "iframe");
|
2012-05-10 10:33:54 -07:00
|
|
|
this._frame.id = "gcli-tooltip-frame";
|
2012-08-14 07:51:48 -07:00
|
|
|
this._frame.setAttribute("src", "chrome://browser/content/devtools/commandlinetooltip.xhtml");
|
2012-05-10 10:33:54 -07:00
|
|
|
this._frame.setAttribute("flex", "1");
|
2012-11-01 19:54:13 -07:00
|
|
|
this._frame.setAttribute("sandbox", "allow-same-origin");
|
2012-05-10 10:33:54 -07:00
|
|
|
this._panel.appendChild(this._frame);
|
|
|
|
|
2013-09-03 04:20:27 -07:00
|
|
|
/**
|
|
|
|
* Wire up the element from the iframe, and resolve the promise.
|
|
|
|
*/
|
|
|
|
let onload = () => {
|
|
|
|
this._frame.removeEventListener("load", onload, true);
|
2012-05-10 10:33:54 -07:00
|
|
|
|
2013-09-03 04:20:27 -07:00
|
|
|
this.document = this._frame.contentDocument;
|
|
|
|
this.hintElement = this.document.getElementById("gcli-tooltip-root");
|
|
|
|
this._connector = this.document.getElementById("gcli-tooltip-connector");
|
2012-05-10 10:33:54 -07:00
|
|
|
|
2013-09-03 04:20:27 -07:00
|
|
|
let styles = this._toolbar.ownerDocument.defaultView
|
|
|
|
.getComputedStyle(this._toolbar);
|
|
|
|
this.hintElement.setAttribute("dir", styles.direction);
|
2012-06-01 00:24:19 -07:00
|
|
|
|
2013-09-03 04:20:27 -07:00
|
|
|
deferred.resolve(this);
|
|
|
|
};
|
|
|
|
this._frame.addEventListener("load", onload, true);
|
2012-05-10 10:33:54 -07:00
|
|
|
|
2013-09-03 04:20:27 -07:00
|
|
|
return deferred.promise;
|
|
|
|
}
|
2012-05-10 10:33:54 -07:00
|
|
|
|
2012-08-03 03:05:24 -07:00
|
|
|
/**
|
|
|
|
* Prevent the popup from hiding if it is not permitted via this.canHide.
|
|
|
|
*/
|
2013-09-03 04:20:27 -07:00
|
|
|
TooltipPanel.prototype._onpopuphiding = function(ev) {
|
2012-08-03 03:05:24 -07:00
|
|
|
// TODO: When we switch back from tooltip to panel we can remove this hack:
|
|
|
|
// https://bugzilla.mozilla.org/show_bug.cgi?id=780102
|
2012-08-30 03:03:19 -07:00
|
|
|
if (isLinux && !this.canHide) {
|
2013-09-03 04:20:27 -07:00
|
|
|
ev.preventDefault();
|
2012-08-03 03:05:24 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-05-10 10:33:54 -07:00
|
|
|
/**
|
|
|
|
* Display the TooltipPanel.
|
|
|
|
*/
|
2013-09-03 04:20:27 -07:00
|
|
|
TooltipPanel.prototype.show = function(dimensions) {
|
|
|
|
if (!dimensions) {
|
|
|
|
dimensions = { start: 0, end: 0 };
|
2012-05-22 00:50:02 -07:00
|
|
|
}
|
2013-09-03 04:20:27 -07:00
|
|
|
this._dimensions = dimensions;
|
2012-05-22 00:50:02 -07:00
|
|
|
|
|
|
|
// This is nasty, but displaying the panel causes it to re-flow, which can
|
|
|
|
// change the size it should be, so we need to resize the iframe after the
|
|
|
|
// panel has displayed
|
2013-09-03 04:20:27 -07:00
|
|
|
this._panel.ownerDocument.defaultView.setTimeout(() => {
|
2012-05-22 00:50:02 -07:00
|
|
|
this._resize();
|
2013-09-03 04:20:27 -07:00
|
|
|
}, 0);
|
2012-05-10 10:33:54 -07:00
|
|
|
|
2012-08-30 03:03:19 -07:00
|
|
|
if (isLinux) {
|
|
|
|
this.canHide = false;
|
|
|
|
}
|
2012-08-03 03:05:24 -07:00
|
|
|
|
2012-05-22 00:50:02 -07:00
|
|
|
this._resize();
|
2013-09-03 04:20:27 -07:00
|
|
|
this._panel.openPopup(this._input, "before_start", dimensions.start * 10, 0,
|
|
|
|
false, false, null);
|
2012-05-10 10:33:54 -07:00
|
|
|
this._input.focus();
|
|
|
|
};
|
|
|
|
|
2012-05-22 00:50:02 -07:00
|
|
|
/**
|
|
|
|
* One option is to spend lots of time taking an average width of characters
|
|
|
|
* in the current font, dynamically, and weighting for the frequency of use of
|
|
|
|
* various characters, or even to render the given string off screen, and then
|
|
|
|
* measure the width.
|
|
|
|
* Or we could do this...
|
|
|
|
*/
|
|
|
|
const AVE_CHAR_WIDTH = 4.5;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display the TooltipPanel.
|
|
|
|
*/
|
2013-09-03 04:20:27 -07:00
|
|
|
TooltipPanel.prototype._resize = function() {
|
2012-05-22 00:50:02 -07:00
|
|
|
if (this._panel == null || this.document == null || !this._panel.state == "closed") {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
let offset = 10 + Math.floor(this._dimensions.start * AVE_CHAR_WIDTH);
|
2012-07-04 15:39:58 -07:00
|
|
|
this._panel.style.marginLeft = offset + "px";
|
2012-05-22 00:50:02 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
// Bug 744906: UX review - Not sure if we want this code to fatten connector
|
|
|
|
// with param width
|
|
|
|
let width = Math.floor(this._dimensions.end * AVE_CHAR_WIDTH);
|
|
|
|
width = Math.min(width, 100);
|
|
|
|
width = Math.max(width, 10);
|
|
|
|
this._connector.style.width = width + "px";
|
|
|
|
*/
|
|
|
|
|
|
|
|
this._frame.height = this.document.body.scrollHeight;
|
|
|
|
};
|
|
|
|
|
2012-05-10 10:33:54 -07:00
|
|
|
/**
|
|
|
|
* Hide the TooltipPanel.
|
|
|
|
*/
|
2013-09-03 04:20:27 -07:00
|
|
|
TooltipPanel.prototype.remove = function() {
|
2012-08-30 03:03:19 -07:00
|
|
|
if (isLinux) {
|
|
|
|
this.canHide = true;
|
|
|
|
}
|
2012-10-02 08:53:00 -07:00
|
|
|
if (this._panel && this._panel.hidePopup) {
|
|
|
|
this._panel.hidePopup();
|
|
|
|
}
|
2012-05-10 10:33:54 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hide the TooltipPanel.
|
|
|
|
*/
|
2013-09-03 04:20:27 -07:00
|
|
|
TooltipPanel.prototype.destroy = function() {
|
2012-05-10 10:33:54 -07:00
|
|
|
this.remove();
|
|
|
|
|
2012-08-03 03:05:24 -07:00
|
|
|
this._panel.removeEventListener("popuphiding", this._onpopuphiding, true);
|
|
|
|
|
2012-05-10 10:33:54 -07:00
|
|
|
this._panel.removeChild(this._frame);
|
2012-05-22 00:50:02 -07:00
|
|
|
this._toolbar.parentElement.removeChild(this._panel);
|
2012-05-10 10:33:54 -07:00
|
|
|
|
2012-05-22 00:50:02 -07:00
|
|
|
delete this._connector;
|
|
|
|
delete this._dimensions;
|
2012-05-10 10:33:54 -07:00
|
|
|
delete this._input;
|
2012-08-03 03:05:24 -07:00
|
|
|
delete this._onpopuphiding;
|
2012-05-10 10:33:54 -07:00
|
|
|
delete this._panel;
|
|
|
|
delete this._frame;
|
2012-05-22 00:50:02 -07:00
|
|
|
delete this._toolbar;
|
2012-05-10 10:33:54 -07:00
|
|
|
delete this._content;
|
|
|
|
delete this.document;
|
|
|
|
delete this.hintElement;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called by GCLI to indicate that we should show or hide one either the
|
|
|
|
* tooltip panel or the output panel.
|
|
|
|
*/
|
2013-09-03 04:20:27 -07:00
|
|
|
TooltipPanel.prototype._visibilityChanged = function(ev) {
|
|
|
|
if (ev.tooltipVisible === true) {
|
|
|
|
this.show(ev.dimensions);
|
2012-05-10 10:33:54 -07:00
|
|
|
} else {
|
2012-08-30 03:03:19 -07:00
|
|
|
if (isLinux) {
|
|
|
|
this.canHide = true;
|
|
|
|
}
|
2012-05-10 10:33:54 -07:00
|
|
|
this._panel.hidePopup();
|
|
|
|
}
|
|
|
|
};
|