2012-02-07 09:22:30 -08:00
|
|
|
/* -*- Mode: javascript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-04-08 22:15:47 -07:00
|
|
|
/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
|
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-02-07 09:22:30 -08:00
|
|
|
"use strict";
|
|
|
|
|
2012-10-26 10:10:17 -07:00
|
|
|
const SOURCE_SYNTAX_HIGHLIGHT_MAX_FILE_SIZE = 1048576; // 1 MB in bytes
|
2013-09-13 06:23:13 -07:00
|
|
|
const SOURCE_URL_DEFAULT_MAX_LENGTH = 64; // chars
|
2013-03-09 21:05:09 -08:00
|
|
|
const STACK_FRAMES_SOURCE_URL_MAX_LENGTH = 15; // chars
|
|
|
|
const STACK_FRAMES_SOURCE_URL_TRIM_SECTION = "center";
|
|
|
|
const STACK_FRAMES_SCROLL_DELAY = 100; // ms
|
2012-10-26 10:10:17 -07:00
|
|
|
const BREAKPOINT_LINE_TOOLTIP_MAX_LENGTH = 1000; // chars
|
2013-02-20 15:33:36 -08:00
|
|
|
const BREAKPOINT_CONDITIONAL_POPUP_POSITION = "before_start";
|
|
|
|
const BREAKPOINT_CONDITIONAL_POPUP_OFFSET_X = 7; // px
|
|
|
|
const BREAKPOINT_CONDITIONAL_POPUP_OFFSET_Y = -3; // px
|
2013-03-25 11:02:34 -07:00
|
|
|
const RESULTS_PANEL_POPUP_POSITION = "before_end";
|
|
|
|
const RESULTS_PANEL_MAX_RESULTS = 10;
|
2013-09-13 06:23:14 -07:00
|
|
|
const FILE_SEARCH_ACTION_MAX_DELAY = 300; // ms
|
2012-10-26 13:28:54 -07:00
|
|
|
const GLOBAL_SEARCH_EXPAND_MAX_RESULTS = 50;
|
2012-12-10 06:03:48 -08:00
|
|
|
const GLOBAL_SEARCH_LINE_MAX_LENGTH = 300; // chars
|
2012-11-21 00:49:45 -08:00
|
|
|
const GLOBAL_SEARCH_ACTION_MAX_DELAY = 1500; // ms
|
2013-03-25 11:02:34 -07:00
|
|
|
const FUNCTION_SEARCH_ACTION_MAX_DELAY = 400; // ms
|
2012-08-18 02:29:47 -07:00
|
|
|
const SEARCH_GLOBAL_FLAG = "!";
|
2013-03-25 11:02:34 -07:00
|
|
|
const SEARCH_FUNCTION_FLAG = "@";
|
2012-08-18 02:29:47 -07:00
|
|
|
const SEARCH_TOKEN_FLAG = "#";
|
2012-11-27 08:19:23 -08:00
|
|
|
const SEARCH_LINE_FLAG = ":";
|
2012-11-03 16:01:05 -07:00
|
|
|
const SEARCH_VARIABLE_FLAG = "*";
|
2014-01-28 02:16:49 -08:00
|
|
|
const SEARCH_AUTOFILL = [SEARCH_GLOBAL_FLAG, SEARCH_FUNCTION_FLAG, SEARCH_TOKEN_FLAG];
|
2014-05-07 06:38:17 -07:00
|
|
|
const EDITOR_VARIABLE_HOVER_DELAY = 750; // ms
|
2014-01-08 06:59:00 -08:00
|
|
|
const EDITOR_VARIABLE_POPUP_POSITION = "topcenter bottomleft";
|
2014-01-09 00:11:54 -08:00
|
|
|
const TOOLBAR_ORDER_POPUP_POSITION = "topcenter bottomleft";
|
2012-05-09 09:05:53 -07:00
|
|
|
|
2012-02-07 09:22:30 -08:00
|
|
|
/**
|
2012-10-26 10:10:17 -07:00
|
|
|
* Object defining the debugger view components.
|
2012-02-07 09:22:30 -08:00
|
|
|
*/
|
|
|
|
let DebuggerView = {
|
2012-10-26 10:10:17 -07:00
|
|
|
/**
|
|
|
|
* Initializes the debugger view.
|
|
|
|
*
|
2013-09-13 06:23:11 -07:00
|
|
|
* @return object
|
|
|
|
* A promise that is resolved when the view finishes initializing.
|
2012-10-26 10:10:17 -07:00
|
|
|
*/
|
2013-09-13 06:23:11 -07:00
|
|
|
initialize: function() {
|
|
|
|
if (this._startup) {
|
|
|
|
return this._startup;
|
|
|
|
}
|
2012-11-10 03:14:40 -08:00
|
|
|
|
2013-09-13 06:23:11 -07:00
|
|
|
let deferred = promise.defer();
|
|
|
|
this._startup = deferred.promise;
|
2012-11-10 03:14:40 -08:00
|
|
|
|
2013-09-13 06:23:11 -07:00
|
|
|
this._initializePanes();
|
2012-10-26 10:10:17 -07:00
|
|
|
this.Toolbar.initialize();
|
|
|
|
this.Options.initialize();
|
|
|
|
this.Filtering.initialize();
|
2012-12-10 06:03:48 -08:00
|
|
|
this.FilteredSources.initialize();
|
2013-03-25 11:02:34 -07:00
|
|
|
this.FilteredFunctions.initialize();
|
2012-10-26 10:10:17 -07:00
|
|
|
this.StackFrames.initialize();
|
2013-12-06 08:33:59 -08:00
|
|
|
this.StackFramesClassicList.initialize();
|
2013-02-20 15:33:36 -08:00
|
|
|
this.Sources.initialize();
|
2013-11-29 06:47:52 -08:00
|
|
|
this.VariableBubble.initialize();
|
2013-12-18 14:17:27 -08:00
|
|
|
this.Tracer.initialize();
|
2012-11-17 11:41:04 -08:00
|
|
|
this.WatchExpressions.initialize();
|
2013-10-04 00:33:08 -07:00
|
|
|
this.EventListeners.initialize();
|
2012-10-26 10:10:17 -07:00
|
|
|
this.GlobalSearch.initialize();
|
2013-06-21 07:33:56 -07:00
|
|
|
this._initializeVariablesView();
|
2013-09-13 06:23:11 -07:00
|
|
|
this._initializeEditor(deferred.resolve);
|
2013-10-22 00:04:46 -07:00
|
|
|
|
2013-10-11 15:09:00 -07:00
|
|
|
document.title = L10N.getStr("DebuggerWindowTitle");
|
2013-09-13 06:23:11 -07:00
|
|
|
|
|
|
|
return deferred.promise;
|
2012-10-26 10:10:17 -07:00
|
|
|
},
|
2012-02-07 09:22:30 -08:00
|
|
|
|
|
|
|
/**
|
2012-10-26 10:10:17 -07:00
|
|
|
* Destroys the debugger view.
|
|
|
|
*
|
2013-09-13 06:23:11 -07:00
|
|
|
* @return object
|
|
|
|
* A promise that is resolved when the view finishes destroying.
|
2012-04-08 22:15:47 -07:00
|
|
|
*/
|
2013-09-13 06:23:11 -07:00
|
|
|
destroy: function() {
|
|
|
|
if (this._shutdown) {
|
|
|
|
return this._shutdown;
|
|
|
|
}
|
|
|
|
|
|
|
|
let deferred = promise.defer();
|
|
|
|
this._shutdown = deferred.promise;
|
2012-11-10 03:14:40 -08:00
|
|
|
|
2012-10-26 10:10:17 -07:00
|
|
|
this.Toolbar.destroy();
|
|
|
|
this.Options.destroy();
|
|
|
|
this.Filtering.destroy();
|
2012-12-10 06:03:48 -08:00
|
|
|
this.FilteredSources.destroy();
|
2013-03-25 11:02:34 -07:00
|
|
|
this.FilteredFunctions.destroy();
|
2012-10-26 10:10:17 -07:00
|
|
|
this.StackFrames.destroy();
|
2013-12-06 08:33:59 -08:00
|
|
|
this.StackFramesClassicList.destroy();
|
2013-02-20 15:33:36 -08:00
|
|
|
this.Sources.destroy();
|
2013-11-29 06:47:52 -08:00
|
|
|
this.VariableBubble.destroy();
|
2013-12-18 14:17:27 -08:00
|
|
|
this.Tracer.destroy();
|
2012-11-17 11:41:04 -08:00
|
|
|
this.WatchExpressions.destroy();
|
2013-10-04 00:33:08 -07:00
|
|
|
this.EventListeners.destroy();
|
2012-10-26 10:10:17 -07:00
|
|
|
this.GlobalSearch.destroy();
|
|
|
|
this._destroyPanes();
|
2013-09-13 06:23:11 -07:00
|
|
|
this._destroyEditor(deferred.resolve);
|
2012-04-08 22:15:47 -07:00
|
|
|
|
2013-09-13 06:23:11 -07:00
|
|
|
return deferred.promise;
|
2012-11-10 03:14:40 -08:00
|
|
|
},
|
|
|
|
|
2012-07-20 01:56:46 -07:00
|
|
|
/**
|
2012-10-26 10:10:17 -07:00
|
|
|
* Initializes the UI for all the displayed panes.
|
2012-07-20 01:56:46 -07:00
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
_initializePanes: function() {
|
2012-10-26 10:10:17 -07:00
|
|
|
dumpn("Initializing the DebuggerView panes");
|
2012-07-20 01:56:46 -07:00
|
|
|
|
2013-10-19 02:26:46 -07:00
|
|
|
this._body = document.getElementById("body");
|
|
|
|
this._editorDeck = document.getElementById("editor-deck");
|
2013-02-20 15:33:36 -08:00
|
|
|
this._sourcesPane = document.getElementById("sources-pane");
|
|
|
|
this._instrumentsPane = document.getElementById("instruments-pane");
|
|
|
|
this._instrumentsPaneToggleButton = document.getElementById("instruments-pane-toggle");
|
2012-09-12 03:39:51 -07:00
|
|
|
|
2013-10-14 13:06:50 -07:00
|
|
|
this.showEditor = this.showEditor.bind(this);
|
|
|
|
this.showBlackBoxMessage = this.showBlackBoxMessage.bind(this);
|
|
|
|
this.showProgressBar = this.showProgressBar.bind(this);
|
|
|
|
this.maybeShowBlackBoxMessage = this.maybeShowBlackBoxMessage.bind(this);
|
|
|
|
|
2013-10-04 00:33:08 -07:00
|
|
|
this._onTabSelect = this._onInstrumentsPaneTabSelect.bind(this);
|
|
|
|
this._instrumentsPane.tabpanels.addEventListener("select", this._onTabSelect);
|
|
|
|
|
2013-02-20 15:33:36 -08:00
|
|
|
this._collapsePaneString = L10N.getStr("collapsePanes");
|
|
|
|
this._expandPaneString = L10N.getStr("expandPanes");
|
|
|
|
|
|
|
|
this._sourcesPane.setAttribute("width", Prefs.sourcesWidth);
|
|
|
|
this._instrumentsPane.setAttribute("width", Prefs.instrumentsWidth);
|
|
|
|
this.toggleInstrumentsPane({ visible: Prefs.panesVisibleOnStartup });
|
2013-10-19 02:26:46 -07:00
|
|
|
|
|
|
|
// Side hosts requires a different arrangement of the debugger widgets.
|
|
|
|
if (gHostType == "side") {
|
|
|
|
this.handleHostChanged(gHostType);
|
|
|
|
}
|
2012-07-20 01:56:46 -07:00
|
|
|
},
|
|
|
|
|
2012-05-31 02:27:22 -07:00
|
|
|
/**
|
2012-10-26 10:10:17 -07:00
|
|
|
* Destroys the UI for all the displayed panes.
|
2012-05-31 02:27:22 -07:00
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
_destroyPanes: function() {
|
2012-10-26 10:10:17 -07:00
|
|
|
dumpn("Destroying the DebuggerView panes");
|
2012-05-31 02:27:22 -07:00
|
|
|
|
2013-10-19 02:26:46 -07:00
|
|
|
if (gHostType != "side") {
|
|
|
|
Prefs.sourcesWidth = this._sourcesPane.getAttribute("width");
|
|
|
|
Prefs.instrumentsWidth = this._instrumentsPane.getAttribute("width");
|
|
|
|
}
|
2013-10-04 00:33:08 -07:00
|
|
|
|
2013-02-20 15:33:36 -08:00
|
|
|
this._sourcesPane = null;
|
|
|
|
this._instrumentsPane = null;
|
|
|
|
this._instrumentsPaneToggleButton = null;
|
2012-05-31 02:27:22 -07:00
|
|
|
},
|
|
|
|
|
2013-06-21 07:33:56 -07:00
|
|
|
/**
|
|
|
|
* Initializes the VariablesView instance and attaches a controller.
|
|
|
|
*/
|
|
|
|
_initializeVariablesView: function() {
|
|
|
|
this.Variables = new VariablesView(document.getElementById("variables"), {
|
|
|
|
searchPlaceholder: L10N.getStr("emptyVariablesFilterText"),
|
|
|
|
emptyText: L10N.getStr("emptyVariablesText"),
|
|
|
|
onlyEnumVisible: Prefs.variablesOnlyEnumVisible,
|
|
|
|
searchEnabled: Prefs.variablesSearchboxVisible,
|
2014-01-06 09:14:21 -08:00
|
|
|
eval: (variable, value) => {
|
|
|
|
let string = variable.evaluationMacro(variable, value);
|
|
|
|
DebuggerController.StackFrames.evaluate(string);
|
|
|
|
},
|
2013-06-21 07:33:56 -07:00
|
|
|
lazyEmpty: true
|
|
|
|
});
|
|
|
|
|
2014-02-01 01:24:44 -08:00
|
|
|
// Attach the current toolbox to the VView so it can link DOMNodes to
|
|
|
|
// the inspector/highlighter
|
|
|
|
this.Variables.toolbox = DebuggerController._toolbox;
|
|
|
|
|
2013-06-21 07:33:56 -07:00
|
|
|
// Attach a controller that handles interfacing with the debugger protocol.
|
|
|
|
VariablesViewController.attach(this.Variables, {
|
2013-09-25 09:03:17 -07:00
|
|
|
getEnvironmentClient: aObject => gThreadClient.environment(aObject),
|
2013-12-18 14:17:27 -08:00
|
|
|
getObjectClient: aObject => {
|
|
|
|
return aObject instanceof DebuggerController.Tracer.WrappedObject
|
|
|
|
? DebuggerController.Tracer.syncGripClient(aObject.object)
|
|
|
|
: gThreadClient.pauseGrip(aObject)
|
|
|
|
}
|
2013-06-21 07:33:56 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
// Relay events from the VariablesView.
|
|
|
|
this.Variables.on("fetched", (aEvent, aType) => {
|
|
|
|
switch (aType) {
|
2014-01-03 13:41:28 -08:00
|
|
|
case "scopes":
|
|
|
|
window.emit(EVENTS.FETCHED_SCOPES);
|
|
|
|
break;
|
2013-06-21 07:33:56 -07:00
|
|
|
case "variables":
|
2013-09-13 06:23:14 -07:00
|
|
|
window.emit(EVENTS.FETCHED_VARIABLES);
|
2013-06-21 07:33:56 -07:00
|
|
|
break;
|
|
|
|
case "properties":
|
2013-09-13 06:23:14 -07:00
|
|
|
window.emit(EVENTS.FETCHED_PROPERTIES);
|
2013-06-21 07:33:56 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2012-04-08 22:15:47 -07:00
|
|
|
/**
|
2013-10-22 13:53:53 -07:00
|
|
|
* Initializes the Editor instance.
|
2012-08-08 14:36:58 -07:00
|
|
|
*
|
|
|
|
* @param function aCallback
|
|
|
|
* Called after the editor finishes initializing.
|
2012-04-08 22:15:47 -07:00
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
_initializeEditor: function(aCallback) {
|
2012-10-26 10:10:17 -07:00
|
|
|
dumpn("Initializing the DebuggerView editor");
|
2012-04-08 22:15:47 -07:00
|
|
|
|
2013-10-22 13:53:53 -07:00
|
|
|
let extraKeys = {};
|
2013-11-28 10:38:42 -08:00
|
|
|
bindKey("_doTokenSearch", "tokenSearchKey");
|
|
|
|
bindKey("_doGlobalSearch", "globalSearchKey", { alt: true });
|
|
|
|
bindKey("_doFunctionSearch", "functionSearchKey");
|
2013-11-07 14:39:31 -08:00
|
|
|
extraKeys[Editor.keyFor("jumpToLine")] = false;
|
|
|
|
|
2013-11-28 10:38:42 -08:00
|
|
|
function bindKey(func, key, modifiers = {}) {
|
|
|
|
let key = document.getElementById(key).getAttribute("key");
|
|
|
|
let shortcut = Editor.accel(key, modifiers);
|
|
|
|
extraKeys[shortcut] = () => DebuggerView.Filtering[func]();
|
|
|
|
}
|
|
|
|
|
2013-10-22 13:53:53 -07:00
|
|
|
this.editor = new Editor({
|
|
|
|
mode: Editor.modes.text,
|
|
|
|
readOnly: true,
|
|
|
|
lineNumbers: true,
|
|
|
|
showAnnotationRuler: true,
|
|
|
|
gutters: [ "breakpoints" ],
|
|
|
|
extraKeys: extraKeys,
|
|
|
|
contextMenu: "sourceEditorContextMenu"
|
|
|
|
});
|
|
|
|
|
|
|
|
this.editor.appendTo(document.getElementById("editor")).then(() => {
|
|
|
|
this.editor.extend(DebuggerEditor);
|
2013-02-20 15:33:36 -08:00
|
|
|
this._loadingText = L10N.getStr("loadingText");
|
2013-09-13 06:23:12 -07:00
|
|
|
this._onEditorLoad(aCallback);
|
2013-05-13 00:01:00 -07:00
|
|
|
});
|
2013-10-22 13:53:53 -07:00
|
|
|
|
2014-05-15 05:51:00 -07:00
|
|
|
this.editor.on("gutterClick", (ev, line, button) => {
|
|
|
|
// A right-click shouldn't do anything but keep track of where
|
|
|
|
// it was clicked.
|
|
|
|
if(button == 2) {
|
|
|
|
this.clickedLine = line;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (this.editor.hasBreakpoint(line)) {
|
|
|
|
this.editor.removeBreakpoint(line);
|
|
|
|
} else {
|
|
|
|
this.editor.addBreakpoint(line);
|
|
|
|
}
|
2013-10-22 13:53:53 -07:00
|
|
|
}
|
|
|
|
});
|
2012-04-08 22:15:47 -07:00
|
|
|
},
|
|
|
|
|
2012-05-31 02:27:22 -07:00
|
|
|
/**
|
2012-10-26 10:10:17 -07:00
|
|
|
* The load event handler for the source editor, also executing any necessary
|
|
|
|
* post-load operations.
|
2013-09-13 06:23:12 -07:00
|
|
|
*
|
|
|
|
* @param function aCallback
|
|
|
|
* Called after the editor finishes loading.
|
2012-05-31 02:27:22 -07:00
|
|
|
*/
|
2013-09-13 06:23:12 -07:00
|
|
|
_onEditorLoad: function(aCallback) {
|
2012-10-26 10:10:17 -07:00
|
|
|
dumpn("Finished loading the DebuggerView editor");
|
2012-09-12 03:39:51 -07:00
|
|
|
|
2013-09-13 06:23:12 -07:00
|
|
|
DebuggerController.Breakpoints.initialize().then(() => {
|
2013-09-13 06:23:14 -07:00
|
|
|
window.emit(EVENTS.EDITOR_LOADED, this.editor);
|
2013-09-13 06:23:12 -07:00
|
|
|
aCallback();
|
|
|
|
});
|
2012-05-31 02:27:22 -07:00
|
|
|
},
|
|
|
|
|
2012-04-08 22:15:47 -07:00
|
|
|
/**
|
2013-10-22 13:53:53 -07:00
|
|
|
* Destroys the Editor instance and also executes any necessary
|
2012-10-26 10:10:17 -07:00
|
|
|
* post-unload operations.
|
2013-09-13 06:23:12 -07:00
|
|
|
*
|
|
|
|
* @param function aCallback
|
|
|
|
* Called after the editor finishes destroying.
|
2012-04-08 22:15:47 -07:00
|
|
|
*/
|
2013-09-13 06:23:12 -07:00
|
|
|
_destroyEditor: function(aCallback) {
|
2012-10-26 10:10:17 -07:00
|
|
|
dumpn("Destroying the DebuggerView editor");
|
|
|
|
|
2013-09-13 06:23:12 -07:00
|
|
|
DebuggerController.Breakpoints.destroy().then(() => {
|
2013-09-13 06:23:14 -07:00
|
|
|
window.emit(EVENTS.EDITOR_UNLOADED, this.editor);
|
2014-03-24 14:30:09 -07:00
|
|
|
this.editor.destroy();
|
|
|
|
this.editor = null;
|
2013-09-13 06:23:12 -07:00
|
|
|
aCallback();
|
|
|
|
});
|
2012-04-08 22:15:47 -07:00
|
|
|
},
|
|
|
|
|
2013-10-14 13:06:50 -07:00
|
|
|
/**
|
|
|
|
* Display the source editor.
|
|
|
|
*/
|
|
|
|
showEditor: function() {
|
|
|
|
this._editorDeck.selectedIndex = 0;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display the black box message.
|
|
|
|
*/
|
|
|
|
showBlackBoxMessage: function() {
|
|
|
|
this._editorDeck.selectedIndex = 1;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display the progress bar.
|
|
|
|
*/
|
|
|
|
showProgressBar: function() {
|
|
|
|
this._editorDeck.selectedIndex = 2;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show or hide the black box message vs. source editor depending on if the
|
|
|
|
* selected source is black boxed or not.
|
|
|
|
*/
|
|
|
|
maybeShowBlackBoxMessage: function() {
|
|
|
|
let { source } = DebuggerView.Sources.selectedItem.attachment;
|
|
|
|
if (gThreadClient.source(source).isBlackBoxed) {
|
|
|
|
this.showBlackBoxMessage();
|
|
|
|
} else {
|
|
|
|
this.showEditor();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2013-09-13 06:23:13 -07:00
|
|
|
/**
|
|
|
|
* Sets the currently displayed text contents in the source editor.
|
|
|
|
* This resets the mode and undo stack.
|
|
|
|
*
|
|
|
|
* @param string aTextContent
|
|
|
|
* The source text content.
|
|
|
|
*/
|
|
|
|
_setEditorText: function(aTextContent = "") {
|
2013-10-22 13:53:53 -07:00
|
|
|
this.editor.setMode(Editor.modes.text);
|
2013-09-13 06:23:13 -07:00
|
|
|
this.editor.setText(aTextContent);
|
2013-11-29 06:47:52 -08:00
|
|
|
this.editor.clearDebugLocation();
|
2013-10-22 13:53:53 -07:00
|
|
|
this.editor.clearHistory();
|
2013-09-13 06:23:13 -07:00
|
|
|
},
|
|
|
|
|
2012-04-08 22:15:47 -07:00
|
|
|
/**
|
2012-10-26 10:10:17 -07:00
|
|
|
* Sets the proper editor mode (JS or HTML) according to the specified
|
2013-02-20 15:33:36 -08:00
|
|
|
* content type, or by determining the type from the url or text content.
|
2012-10-26 10:10:17 -07:00
|
|
|
*
|
|
|
|
* @param string aUrl
|
2013-02-20 15:33:36 -08:00
|
|
|
* The source url.
|
2012-10-26 10:10:17 -07:00
|
|
|
* @param string aContentType [optional]
|
2013-02-20 15:33:36 -08:00
|
|
|
* The source content type.
|
2012-11-02 00:31:55 -07:00
|
|
|
* @param string aTextContent [optional]
|
2013-02-20 15:33:36 -08:00
|
|
|
* The source text content.
|
2012-04-08 22:15:47 -07:00
|
|
|
*/
|
2013-09-13 06:23:13 -07:00
|
|
|
_setEditorMode: function(aUrl, aContentType = "", aTextContent = "") {
|
2013-06-26 13:35:39 -07:00
|
|
|
// Avoid setting the editor mode for very large files.
|
2013-10-22 13:53:53 -07:00
|
|
|
// Is this still necessary? See bug 929225.
|
2013-06-26 13:35:39 -07:00
|
|
|
if (aTextContent.length >= SOURCE_SYNTAX_HIGHLIGHT_MAX_FILE_SIZE) {
|
2013-10-22 13:53:53 -07:00
|
|
|
return void this.editor.setMode(Editor.modes.text);
|
2013-06-26 13:35:39 -07:00
|
|
|
}
|
2013-10-22 13:53:53 -07:00
|
|
|
|
2013-09-22 09:03:15 -07:00
|
|
|
// Use JS mode for files with .js and .jsm extensions.
|
2013-10-22 13:53:53 -07:00
|
|
|
if (SourceUtils.isJavaScript(aUrl, aContentType)) {
|
|
|
|
return void this.editor.setMode(Editor.modes.js);
|
2013-09-22 09:03:15 -07:00
|
|
|
}
|
2013-10-22 13:53:53 -07:00
|
|
|
|
2013-09-22 09:03:15 -07:00
|
|
|
// Use HTML mode for files in which the first non whitespace character is
|
|
|
|
// <, regardless of extension.
|
2013-10-22 13:53:53 -07:00
|
|
|
if (aTextContent.match(/^\s*</)) {
|
|
|
|
return void this.editor.setMode(Editor.modes.html);
|
2012-10-26 10:10:17 -07:00
|
|
|
}
|
2013-10-22 13:53:53 -07:00
|
|
|
|
|
|
|
// Unknown language, use text.
|
|
|
|
this.editor.setMode(Editor.modes.text);
|
2012-10-26 10:10:17 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2013-02-20 15:33:36 -08:00
|
|
|
* Sets the currently displayed source text in the editor.
|
|
|
|
*
|
2013-09-13 06:23:13 -07:00
|
|
|
* You should use DebuggerView.updateEditor instead. It updates the current
|
|
|
|
* caret and debug location based on a requested url and line.
|
2012-10-26 10:10:17 -07:00
|
|
|
*
|
|
|
|
* @param object aSource
|
|
|
|
* The source object coming from the active thread.
|
2013-09-18 17:56:20 -07:00
|
|
|
* @param object aFlags
|
|
|
|
* Additional options for setting the source. Supported options:
|
2014-05-08 19:14:42 -07:00
|
|
|
* - force: boolean forcing all text to be reshown in the editor
|
2013-09-13 06:23:13 -07:00
|
|
|
* @return object
|
|
|
|
* A promise that is resolved after the source text has been set.
|
2012-10-26 10:10:17 -07:00
|
|
|
*/
|
2013-09-18 17:56:20 -07:00
|
|
|
_setEditorSource: function(aSource, aFlags={}) {
|
2013-09-13 06:23:13 -07:00
|
|
|
// Avoid setting the same source text in the editor again.
|
2013-09-18 17:56:20 -07:00
|
|
|
if (this._editorSource.url == aSource.url && !aFlags.force) {
|
2013-09-13 06:23:13 -07:00
|
|
|
return this._editorSource.promise;
|
2012-10-26 10:10:17 -07:00
|
|
|
}
|
2013-09-28 00:41:20 -07:00
|
|
|
let transportType = gClient.localTransport ? "_LOCAL" : "_REMOTE";
|
2013-09-23 13:03:25 -07:00
|
|
|
let histogramId = "DEVTOOLS_DEBUGGER_DISPLAY_SOURCE" + transportType + "_MS";
|
|
|
|
let histogram = Services.telemetry.getHistogramById(histogramId);
|
2013-09-28 00:41:20 -07:00
|
|
|
let startTime = Date.now();
|
2013-02-28 04:02:00 -08:00
|
|
|
|
2013-09-13 06:23:13 -07:00
|
|
|
let deferred = promise.defer();
|
2013-02-20 15:33:36 -08:00
|
|
|
|
2013-09-13 06:23:13 -07:00
|
|
|
this._setEditorText(L10N.getStr("loadingText"));
|
|
|
|
this._editorSource = { url: aSource.url, promise: deferred.promise };
|
2012-10-26 10:10:17 -07:00
|
|
|
|
2014-03-29 10:01:37 -07:00
|
|
|
DebuggerController.SourceScripts.getText(aSource).then(([, aText, aContentType]) => {
|
2013-09-13 06:23:13 -07:00
|
|
|
// Avoid setting an unexpected source. This may happen when switching
|
|
|
|
// very fast between sources that haven't been fetched yet.
|
|
|
|
if (this._editorSource.url != aSource.url) {
|
2013-02-20 15:33:36 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-09-13 06:23:13 -07:00
|
|
|
this._setEditorText(aText);
|
2014-02-11 13:35:11 -08:00
|
|
|
this._setEditorMode(aSource.url, aContentType, aText);
|
2012-10-26 10:10:17 -07:00
|
|
|
|
2013-02-20 15:33:36 -08:00
|
|
|
// Synchronize any other components with the currently displayed source.
|
|
|
|
DebuggerView.Sources.selectedValue = aSource.url;
|
2012-10-26 10:10:17 -07:00
|
|
|
DebuggerController.Breakpoints.updateEditorBreakpoints();
|
|
|
|
|
2013-09-28 00:41:20 -07:00
|
|
|
histogram.add(Date.now() - startTime);
|
2013-09-23 13:03:25 -07:00
|
|
|
|
2013-09-13 06:23:13 -07:00
|
|
|
// Resolve and notify that a source file was shown.
|
2013-09-13 06:23:14 -07:00
|
|
|
window.emit(EVENTS.SOURCE_SHOWN, aSource);
|
2014-02-11 13:35:11 -08:00
|
|
|
deferred.resolve([aSource, aText, aContentType]);
|
2013-06-26 13:35:39 -07:00
|
|
|
},
|
|
|
|
([, aError]) => {
|
2013-09-05 09:10:12 -07:00
|
|
|
let msg = L10N.getStr("errorLoadingText") + DevToolsUtils.safeErrorString(aError);
|
2013-09-13 06:23:13 -07:00
|
|
|
this._setEditorText(msg);
|
2013-06-26 13:35:39 -07:00
|
|
|
Cu.reportError(msg);
|
2013-09-13 06:23:13 -07:00
|
|
|
dumpn(msg);
|
|
|
|
|
|
|
|
// Reject and notify that there was an error showing the source file.
|
2013-09-13 06:23:14 -07:00
|
|
|
window.emit(EVENTS.SOURCE_ERROR_SHOWN, aSource);
|
2013-09-13 06:23:13 -07:00
|
|
|
deferred.reject([aSource, aError]);
|
2013-06-26 13:35:39 -07:00
|
|
|
});
|
2012-05-03 10:36:40 -07:00
|
|
|
|
2013-09-13 06:23:13 -07:00
|
|
|
return deferred.promise;
|
|
|
|
},
|
2013-02-20 15:33:36 -08:00
|
|
|
|
2012-07-20 01:56:46 -07:00
|
|
|
/**
|
2012-10-26 10:10:17 -07:00
|
|
|
* Update the source editor's current caret and debug location based on
|
2013-09-13 06:23:13 -07:00
|
|
|
* a requested url and line.
|
2012-10-26 10:10:17 -07:00
|
|
|
*
|
2013-09-13 06:23:13 -07:00
|
|
|
* @param string aUrl
|
2012-10-26 10:10:17 -07:00
|
|
|
* The target source url.
|
|
|
|
* @param number aLine [optional]
|
2013-09-13 06:23:13 -07:00
|
|
|
* The target line in the source.
|
2012-10-26 10:10:17 -07:00
|
|
|
* @param object aFlags [optional]
|
2013-02-20 15:33:36 -08:00
|
|
|
* Additional options for showing the source. Supported options:
|
|
|
|
* - charOffset: character offset for the caret or debug location
|
|
|
|
* - lineOffset: line offset for the caret or debug location
|
|
|
|
* - columnOffset: column offset for the caret or debug location
|
2012-10-26 10:10:17 -07:00
|
|
|
* - noCaret: don't set the caret location at the specified line
|
|
|
|
* - noDebug: don't set the debug location at the specified line
|
2013-11-29 06:47:52 -08:00
|
|
|
* - align: string specifying whether to align the specified line
|
|
|
|
* at the "top", "center" or "bottom" of the editor
|
2014-05-08 19:14:42 -07:00
|
|
|
* - force: boolean forcing all text to be reshown in the editor
|
2013-09-13 06:23:13 -07:00
|
|
|
* @return object
|
|
|
|
* A promise that is resolved after the source text has been set.
|
2012-07-20 01:56:46 -07:00
|
|
|
*/
|
2013-09-13 06:23:13 -07:00
|
|
|
setEditorLocation: function(aUrl, aLine = 0, aFlags = {}) {
|
|
|
|
// Avoid trying to set a source for a url that isn't known yet.
|
|
|
|
if (!this.Sources.containsValue(aUrl)) {
|
|
|
|
return promise.reject(new Error("Unknown source for the specified URL."));
|
2012-10-26 10:10:17 -07:00
|
|
|
}
|
2013-11-29 06:47:52 -08:00
|
|
|
|
2013-09-13 06:23:13 -07:00
|
|
|
// If the line is not specified, default to the current frame's position,
|
|
|
|
// if available and the frame's url corresponds to the requested url.
|
|
|
|
if (!aLine) {
|
2012-10-26 10:10:17 -07:00
|
|
|
let cachedFrames = DebuggerController.activeThread.cachedFrames;
|
2013-09-13 06:23:13 -07:00
|
|
|
let currentDepth = DebuggerController.StackFrames.currentFrameDepth;
|
|
|
|
let frame = cachedFrames[currentDepth];
|
|
|
|
if (frame && frame.where.url == aUrl) {
|
|
|
|
aLine = frame.where.line;
|
2012-10-26 10:10:17 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-13 06:23:13 -07:00
|
|
|
let sourceItem = this.Sources.getItemByValue(aUrl);
|
2013-09-13 06:23:13 -07:00
|
|
|
let sourceForm = sourceItem.attachment.source;
|
2012-10-26 10:10:17 -07:00
|
|
|
|
2013-09-13 06:23:13 -07:00
|
|
|
// Make sure the requested source client is shown in the editor, then
|
|
|
|
// update the source editor's caret position and debug location.
|
2014-03-29 10:01:37 -07:00
|
|
|
return this._setEditorSource(sourceForm, aFlags).then(([,, aContentType]) => {
|
2014-02-11 13:35:11 -08:00
|
|
|
// Record the contentType learned from fetching
|
|
|
|
sourceForm.contentType = aContentType;
|
2013-09-13 06:23:13 -07:00
|
|
|
// Line numbers in the source editor should start from 1. If invalid
|
|
|
|
// or not specified, then don't do anything.
|
|
|
|
if (aLine < 1) {
|
2014-02-11 13:35:11 -08:00
|
|
|
window.emit(EVENTS.EDITOR_LOCATION_SET);
|
2013-09-13 06:23:13 -07:00
|
|
|
return;
|
|
|
|
}
|
2013-02-20 15:33:36 -08:00
|
|
|
if (aFlags.charOffset) {
|
2013-10-22 13:53:53 -07:00
|
|
|
aLine += this.editor.getPosition(aFlags.charOffset).line;
|
2013-02-20 15:33:36 -08:00
|
|
|
}
|
|
|
|
if (aFlags.lineOffset) {
|
|
|
|
aLine += aFlags.lineOffset;
|
|
|
|
}
|
2012-10-26 10:10:17 -07:00
|
|
|
if (!aFlags.noCaret) {
|
2013-11-29 06:47:52 -08:00
|
|
|
let location = { line: aLine -1, ch: aFlags.columnOffset || 0 };
|
|
|
|
this.editor.setCursor(location, aFlags.align);
|
2012-10-26 10:10:17 -07:00
|
|
|
}
|
|
|
|
if (!aFlags.noDebug) {
|
2013-10-22 13:53:53 -07:00
|
|
|
this.editor.setDebugLocation(aLine - 1);
|
2012-10-26 10:10:17 -07:00
|
|
|
}
|
2014-02-11 13:35:11 -08:00
|
|
|
window.emit(EVENTS.EDITOR_LOCATION_SET);
|
2013-10-22 13:53:53 -07:00
|
|
|
}).then(null, console.error);
|
2012-07-20 01:56:46 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2013-02-20 15:33:36 -08:00
|
|
|
* Gets the visibility state of the instruments pane.
|
2012-10-26 10:10:17 -07:00
|
|
|
* @return boolean
|
|
|
|
*/
|
2013-02-20 15:33:36 -08:00
|
|
|
get instrumentsPaneHidden()
|
2013-03-11 23:50:42 -07:00
|
|
|
this._instrumentsPane.hasAttribute("pane-collapsed"),
|
2012-10-26 10:10:17 -07:00
|
|
|
|
2013-10-04 00:33:08 -07:00
|
|
|
/**
|
|
|
|
* Gets the currently selected tab in the instruments pane.
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
get instrumentsPaneTab()
|
|
|
|
this._instrumentsPane.selectedTab.id,
|
|
|
|
|
2012-10-26 10:10:17 -07:00
|
|
|
/**
|
2013-02-20 15:33:36 -08:00
|
|
|
* Sets the instruments pane hidden or visible.
|
2012-10-01 07:55:32 -07:00
|
|
|
*
|
2013-03-11 23:50:42 -07:00
|
|
|
* @param object aFlags
|
|
|
|
* An object containing some of the following properties:
|
|
|
|
* - visible: true if the pane should be shown, false to hide
|
2012-10-01 07:55:32 -07:00
|
|
|
* - animated: true to display an animation on toggle
|
2013-01-03 23:37:18 -08:00
|
|
|
* - delayed: true to wait a few cycles before toggle
|
2013-02-20 15:33:36 -08:00
|
|
|
* - callback: a function to invoke when the toggle finishes
|
2013-10-04 00:33:08 -07:00
|
|
|
* @param number aTabIndex [optional]
|
|
|
|
* The index of the intended selected tab in the details pane.
|
2012-10-01 07:55:32 -07:00
|
|
|
*/
|
2013-10-04 00:33:08 -07:00
|
|
|
toggleInstrumentsPane: function(aFlags, aTabIndex) {
|
2013-03-11 23:50:42 -07:00
|
|
|
let pane = this._instrumentsPane;
|
|
|
|
let button = this._instrumentsPaneToggleButton;
|
2013-01-03 23:37:18 -08:00
|
|
|
|
2013-03-11 23:50:42 -07:00
|
|
|
ViewHelpers.togglePane(aFlags, pane);
|
2013-01-03 23:37:18 -08:00
|
|
|
|
2013-03-11 23:50:42 -07:00
|
|
|
if (aFlags.visible) {
|
|
|
|
button.removeAttribute("pane-collapsed");
|
|
|
|
button.setAttribute("tooltiptext", this._collapsePaneString);
|
2013-01-03 23:37:18 -08:00
|
|
|
} else {
|
2013-03-11 23:50:42 -07:00
|
|
|
button.setAttribute("pane-collapsed", "");
|
|
|
|
button.setAttribute("tooltiptext", this._expandPaneString);
|
2012-07-20 01:56:46 -07:00
|
|
|
}
|
2013-10-04 00:33:08 -07:00
|
|
|
|
|
|
|
if (aTabIndex !== undefined) {
|
|
|
|
pane.selectedIndex = aTabIndex;
|
|
|
|
}
|
2012-10-26 13:28:54 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2013-02-20 15:33:36 -08:00
|
|
|
* Sets the instruments pane visible after a short period of time.
|
2012-11-15 22:42:52 -08:00
|
|
|
*
|
|
|
|
* @param function aCallback
|
2013-02-20 15:33:36 -08:00
|
|
|
* A function to invoke when the toggle finishes.
|
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
showInstrumentsPane: function(aCallback) {
|
2013-02-20 15:33:36 -08:00
|
|
|
DebuggerView.toggleInstrumentsPane({
|
|
|
|
visible: true,
|
|
|
|
animated: true,
|
|
|
|
delayed: true,
|
|
|
|
callback: aCallback
|
2013-12-19 03:41:46 -08:00
|
|
|
}, 0);
|
2013-10-04 00:33:08 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handles a tab selection event on the instruments pane.
|
|
|
|
*/
|
|
|
|
_onInstrumentsPaneTabSelect: function() {
|
|
|
|
if (this._instrumentsPane.selectedTab.id == "events-tab") {
|
|
|
|
DebuggerController.Breakpoints.DOM.scheduleEventListenersFetch();
|
|
|
|
}
|
2012-10-01 07:55:32 -07:00
|
|
|
},
|
|
|
|
|
2013-10-19 02:26:46 -07:00
|
|
|
/**
|
|
|
|
* Handles a host change event issued by the parent toolbox.
|
|
|
|
*
|
|
|
|
* @param string aType
|
|
|
|
* The host type, either "bottom", "side" or "window".
|
|
|
|
*/
|
|
|
|
handleHostChanged: function(aType) {
|
|
|
|
let newLayout = "";
|
|
|
|
|
|
|
|
if (aType == "side") {
|
|
|
|
newLayout = "vertical";
|
|
|
|
this._enterVerticalLayout();
|
|
|
|
} else {
|
|
|
|
newLayout = "horizontal";
|
|
|
|
this._enterHorizontalLayout();
|
|
|
|
}
|
|
|
|
|
|
|
|
this._hostType = aType;
|
|
|
|
this._body.setAttribute("layout", newLayout);
|
|
|
|
window.emit(EVENTS.LAYOUT_CHANGED, newLayout);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Switches the debugger widgets to a horizontal layout.
|
|
|
|
*/
|
|
|
|
_enterVerticalLayout: function() {
|
|
|
|
let normContainer = document.getElementById("debugger-widgets");
|
|
|
|
let vertContainer = document.getElementById("vertical-layout-panes-container");
|
|
|
|
|
|
|
|
// Move the soruces and instruments panes in a different container.
|
|
|
|
let splitter = document.getElementById("sources-and-instruments-splitter");
|
|
|
|
vertContainer.insertBefore(this._sourcesPane, splitter);
|
|
|
|
vertContainer.appendChild(this._instrumentsPane);
|
|
|
|
|
|
|
|
// Make sure the vertical layout container's height doesn't repeatedly
|
|
|
|
// grow or shrink based on the displayed sources, variables etc.
|
|
|
|
vertContainer.setAttribute("height",
|
|
|
|
vertContainer.getBoundingClientRect().height);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Switches the debugger widgets to a vertical layout.
|
|
|
|
*/
|
|
|
|
_enterHorizontalLayout: function() {
|
|
|
|
let normContainer = document.getElementById("debugger-widgets");
|
|
|
|
let vertContainer = document.getElementById("vertical-layout-panes-container");
|
|
|
|
|
|
|
|
// The sources and instruments pane need to be inserted at their
|
|
|
|
// previous locations in their normal container.
|
|
|
|
let splitter = document.getElementById("sources-and-editor-splitter");
|
|
|
|
normContainer.insertBefore(this._sourcesPane, splitter);
|
|
|
|
normContainer.appendChild(this._instrumentsPane);
|
|
|
|
|
|
|
|
// Revert to the preferred sources and instruments widths, because
|
|
|
|
// they flexed in the vertical layout.
|
|
|
|
this._sourcesPane.setAttribute("width", Prefs.sourcesWidth);
|
|
|
|
this._instrumentsPane.setAttribute("width", Prefs.instrumentsWidth);
|
|
|
|
},
|
|
|
|
|
2012-10-01 07:55:32 -07:00
|
|
|
/**
|
2012-10-26 10:10:17 -07:00
|
|
|
* Handles any initialization on a tab navigation event issued by the client.
|
2012-10-01 07:55:32 -07:00
|
|
|
*/
|
2013-10-19 02:26:46 -07:00
|
|
|
handleTabNavigation: function() {
|
2012-10-26 10:10:17 -07:00
|
|
|
dumpn("Handling tab navigation in the DebuggerView");
|
2012-10-01 07:55:32 -07:00
|
|
|
|
2012-10-26 10:10:17 -07:00
|
|
|
this.Filtering.clearSearch();
|
2013-03-25 11:02:34 -07:00
|
|
|
this.FilteredSources.clearView();
|
|
|
|
this.FilteredFunctions.clearView();
|
2012-10-26 10:10:17 -07:00
|
|
|
this.GlobalSearch.clearView();
|
|
|
|
this.StackFrames.empty();
|
2013-02-20 15:33:36 -08:00
|
|
|
this.Sources.empty();
|
2012-10-26 10:10:17 -07:00
|
|
|
this.Variables.empty();
|
2013-10-04 00:33:08 -07:00
|
|
|
this.EventListeners.empty();
|
2012-10-01 07:55:32 -07:00
|
|
|
|
2012-10-26 10:10:17 -07:00
|
|
|
if (this.editor) {
|
2013-10-22 13:53:53 -07:00
|
|
|
this.editor.setMode(Editor.modes.text);
|
2012-10-26 10:10:17 -07:00
|
|
|
this.editor.setText("");
|
2013-10-22 13:53:53 -07:00
|
|
|
this.editor.clearHistory();
|
2013-09-13 06:23:13 -07:00
|
|
|
this._editorSource = {};
|
2012-10-26 10:10:17 -07:00
|
|
|
}
|
2014-02-06 07:04:13 -08:00
|
|
|
|
|
|
|
this.Sources.emptyText = L10N.getStr("loadingSourcesText");
|
2012-07-20 01:56:46 -07:00
|
|
|
},
|
|
|
|
|
2013-09-13 06:23:11 -07:00
|
|
|
_startup: null,
|
|
|
|
_shutdown: null,
|
2012-10-26 10:10:17 -07:00
|
|
|
Toolbar: null,
|
|
|
|
Options: null,
|
|
|
|
Filtering: null,
|
2013-02-20 15:33:36 -08:00
|
|
|
FilteredSources: null,
|
2013-06-21 07:33:56 -07:00
|
|
|
FilteredFunctions: null,
|
|
|
|
GlobalSearch: null,
|
2012-10-26 10:10:17 -07:00
|
|
|
StackFrames: null,
|
2013-02-20 15:33:36 -08:00
|
|
|
Sources: null,
|
2013-12-18 14:17:27 -08:00
|
|
|
Tracer: null,
|
2012-10-26 10:10:17 -07:00
|
|
|
Variables: null,
|
2013-11-29 06:47:52 -08:00
|
|
|
VariableBubble: null,
|
2013-06-21 07:33:56 -07:00
|
|
|
WatchExpressions: null,
|
2013-10-04 00:33:08 -07:00
|
|
|
EventListeners: null,
|
2013-09-13 06:23:13 -07:00
|
|
|
editor: null,
|
|
|
|
_editorSource: {},
|
2013-02-20 15:33:36 -08:00
|
|
|
_loadingText: "",
|
2013-10-19 02:26:46 -07:00
|
|
|
_body: null,
|
|
|
|
_editorDeck: null,
|
2013-02-20 15:33:36 -08:00
|
|
|
_sourcesPane: null,
|
|
|
|
_instrumentsPane: null,
|
|
|
|
_instrumentsPaneToggleButton: null,
|
|
|
|
_collapsePaneString: "",
|
2013-10-19 02:26:46 -07:00
|
|
|
_expandPaneString: ""
|
2012-04-08 22:15:47 -07:00
|
|
|
};
|
|
|
|
|
2013-03-25 11:02:34 -07:00
|
|
|
/**
|
|
|
|
* A custom items container, used for displaying views like the
|
2013-06-21 07:33:56 -07:00
|
|
|
* FilteredSources, FilteredFunctions etc., inheriting the generic WidgetMethods.
|
2013-03-25 11:02:34 -07:00
|
|
|
*/
|
|
|
|
function ResultsPanelContainer() {
|
|
|
|
}
|
|
|
|
|
2013-06-21 07:33:56 -07:00
|
|
|
ResultsPanelContainer.prototype = Heritage.extend(WidgetMethods, {
|
2013-03-25 11:02:34 -07:00
|
|
|
/**
|
|
|
|
* Sets the anchor node for this container panel.
|
|
|
|
* @param nsIDOMNode aNode
|
|
|
|
*/
|
|
|
|
set anchor(aNode) {
|
|
|
|
this._anchor = aNode;
|
|
|
|
|
|
|
|
// If the anchor node is not null, create a panel to attach to the anchor
|
|
|
|
// when showing the popup.
|
|
|
|
if (aNode) {
|
|
|
|
if (!this._panel) {
|
|
|
|
this._panel = document.createElement("panel");
|
2014-01-07 01:58:07 -08:00
|
|
|
this._panel.id = "results-panel";
|
2013-03-25 11:02:34 -07:00
|
|
|
this._panel.setAttribute("level", "top");
|
|
|
|
this._panel.setAttribute("noautofocus", "true");
|
2013-10-03 14:36:35 -07:00
|
|
|
this._panel.setAttribute("consumeoutsideclicks", "false");
|
2013-03-25 11:02:34 -07:00
|
|
|
document.documentElement.appendChild(this._panel);
|
|
|
|
}
|
2013-06-21 07:33:56 -07:00
|
|
|
if (!this.widget) {
|
2014-01-03 13:42:16 -08:00
|
|
|
this.widget = new SimpleListWidget(this._panel);
|
2014-01-08 00:48:32 -08:00
|
|
|
this.autoFocusOnFirstItem = false;
|
|
|
|
this.autoFocusOnSelection = false;
|
2014-01-03 13:42:16 -08:00
|
|
|
this.maintainSelectionVisible = false;
|
2013-03-25 11:02:34 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// Cleanup the anchor and remove the previously created panel.
|
|
|
|
else {
|
2013-06-21 07:33:56 -07:00
|
|
|
this._panel.remove();
|
|
|
|
this._panel = null;
|
2013-06-21 07:33:56 -07:00
|
|
|
this.widget = null;
|
2013-03-25 11:02:34 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the anchor node for this container panel.
|
|
|
|
* @return nsIDOMNode
|
|
|
|
*/
|
2014-01-03 13:42:16 -08:00
|
|
|
get anchor() {
|
|
|
|
return this._anchor;
|
|
|
|
},
|
2013-03-25 11:02:34 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the container panel hidden or visible. It's hidden by default.
|
|
|
|
* @param boolean aFlag
|
|
|
|
*/
|
|
|
|
set hidden(aFlag) {
|
|
|
|
if (aFlag) {
|
2013-09-13 06:23:13 -07:00
|
|
|
this._panel.hidden = true;
|
2013-03-25 11:02:34 -07:00
|
|
|
this._panel.hidePopup();
|
|
|
|
} else {
|
2013-09-13 06:23:13 -07:00
|
|
|
this._panel.hidden = false;
|
2013-06-21 07:33:56 -07:00
|
|
|
this._panel.openPopup(this._anchor, this.position, this.left, this.top);
|
2013-03-25 11:02:34 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets this container's visibility state.
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
get hidden()
|
|
|
|
this._panel.state == "closed" ||
|
|
|
|
this._panel.state == "hiding",
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes all items from this container and hides it.
|
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
clearView: function() {
|
2013-03-25 11:02:34 -07:00
|
|
|
this.hidden = true;
|
|
|
|
this.empty();
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2013-06-21 07:33:56 -07:00
|
|
|
* Selects the next found item in this container.
|
|
|
|
* Does not change the currently focused node.
|
2013-03-25 11:02:34 -07:00
|
|
|
*/
|
2013-06-21 07:33:56 -07:00
|
|
|
selectNext: function() {
|
2013-03-25 11:02:34 -07:00
|
|
|
let nextIndex = this.selectedIndex + 1;
|
|
|
|
if (nextIndex >= this.itemCount) {
|
|
|
|
nextIndex = 0;
|
|
|
|
}
|
2013-06-21 07:33:56 -07:00
|
|
|
this.selectedItem = this.getItemAtIndex(nextIndex);
|
2013-03-25 11:02:34 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2013-06-21 07:33:56 -07:00
|
|
|
* Selects the previously found item in this container.
|
|
|
|
* Does not change the currently focused node.
|
2013-03-25 11:02:34 -07:00
|
|
|
*/
|
2013-06-21 07:33:56 -07:00
|
|
|
selectPrev: function() {
|
2013-03-25 11:02:34 -07:00
|
|
|
let prevIndex = this.selectedIndex - 1;
|
|
|
|
if (prevIndex < 0) {
|
|
|
|
prevIndex = this.itemCount - 1;
|
|
|
|
}
|
2013-06-21 07:33:56 -07:00
|
|
|
this.selectedItem = this.getItemAtIndex(prevIndex);
|
2013-03-25 11:02:34 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Customization function for creating an item's UI.
|
|
|
|
*
|
|
|
|
* @param string aLabel
|
2014-01-03 13:42:16 -08:00
|
|
|
* The item's label string.
|
|
|
|
* @param string aBeforeLabel
|
|
|
|
* An optional string shown before the label.
|
|
|
|
* @param string aBelowLabel
|
|
|
|
* An optional string shown underneath the label.
|
2013-03-25 11:02:34 -07:00
|
|
|
*/
|
2014-01-03 13:42:16 -08:00
|
|
|
_createItemView: function(aLabel, aBelowLabel, aBeforeLabel) {
|
|
|
|
let container = document.createElement("vbox");
|
|
|
|
container.className = "results-panel-item";
|
|
|
|
|
|
|
|
let firstRowLabels = document.createElement("hbox");
|
|
|
|
let secondRowLabels = document.createElement("hbox");
|
|
|
|
|
|
|
|
if (aBeforeLabel) {
|
|
|
|
let beforeLabelNode = document.createElement("label");
|
|
|
|
beforeLabelNode.className = "plain results-panel-item-label-before";
|
|
|
|
beforeLabelNode.setAttribute("value", aBeforeLabel);
|
|
|
|
firstRowLabels.appendChild(beforeLabelNode);
|
2013-03-25 11:02:34 -07:00
|
|
|
}
|
2014-01-03 13:42:16 -08:00
|
|
|
|
|
|
|
let labelNode = document.createElement("label");
|
|
|
|
labelNode.className = "plain results-panel-item-label";
|
|
|
|
labelNode.setAttribute("value", aLabel);
|
|
|
|
firstRowLabels.appendChild(labelNode);
|
|
|
|
|
|
|
|
if (aBelowLabel) {
|
|
|
|
let belowLabelNode = document.createElement("label");
|
|
|
|
belowLabelNode.className = "plain results-panel-item-label-below";
|
|
|
|
belowLabelNode.setAttribute("value", aBelowLabel);
|
|
|
|
secondRowLabels.appendChild(belowLabelNode);
|
2013-03-25 11:02:34 -07:00
|
|
|
}
|
|
|
|
|
2014-01-03 13:42:16 -08:00
|
|
|
container.appendChild(firstRowLabels);
|
|
|
|
container.appendChild(secondRowLabels);
|
2013-03-25 11:02:34 -07:00
|
|
|
|
2014-01-03 13:42:16 -08:00
|
|
|
return container;
|
2013-03-25 11:02:34 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
_anchor: null,
|
|
|
|
_panel: null,
|
2013-06-21 07:33:56 -07:00
|
|
|
position: RESULTS_PANEL_POPUP_POSITION,
|
|
|
|
left: 0,
|
|
|
|
top: 0
|
2013-03-25 11:02:34 -07:00
|
|
|
});
|