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";
|
|
|
|
|
2013-03-09 21:05:09 -08:00
|
|
|
const SOURCE_URL_DEFAULT_MAX_LENGTH = 64; // chars
|
2012-10-26 10:10:17 -07:00
|
|
|
const SOURCE_SYNTAX_HIGHLIGHT_MAX_FILE_SIZE = 1048576; // 1 MB in bytes
|
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_POPUP_SOURCE_URL_MAX_LENGTH = 32; // chars
|
|
|
|
const STACK_FRAMES_POPUP_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;
|
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 = "*";
|
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.
|
|
|
|
*
|
|
|
|
* @param function aCallback
|
|
|
|
* Called after the view finishes initializing.
|
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
initialize: function(aCallback) {
|
2012-10-26 10:10:17 -07:00
|
|
|
dumpn("Initializing the DebuggerView");
|
2012-11-10 03:14:40 -08:00
|
|
|
|
2012-11-10 03:14:40 -08:00
|
|
|
this._initializePanes();
|
2012-11-10 03:14:40 -08:00
|
|
|
|
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();
|
2013-02-20 15:33:36 -08:00
|
|
|
this.ChromeGlobals.initialize();
|
2012-10-26 10:10:17 -07:00
|
|
|
this.StackFrames.initialize();
|
2013-02-20 15:33:36 -08:00
|
|
|
this.Sources.initialize();
|
2012-11-17 11:41:04 -08:00
|
|
|
this.WatchExpressions.initialize();
|
2012-10-26 10:10:17 -07:00
|
|
|
this.GlobalSearch.initialize();
|
|
|
|
|
2013-06-21 07:33:56 -07:00
|
|
|
this._initializeVariablesView();
|
2012-11-10 03:14:40 -08:00
|
|
|
this._initializeEditor(aCallback);
|
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.
|
|
|
|
*
|
|
|
|
* @param function aCallback
|
|
|
|
* Called after the view finishes destroying.
|
2012-04-08 22:15:47 -07:00
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
destroy: function(aCallback) {
|
2012-10-26 10:10:17 -07:00
|
|
|
dumpn("Destroying the DebuggerView");
|
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();
|
2013-02-20 15:33:36 -08:00
|
|
|
this.ChromeGlobals.destroy();
|
2012-10-26 10:10:17 -07:00
|
|
|
this.StackFrames.destroy();
|
2013-02-20 15:33:36 -08:00
|
|
|
this.Sources.destroy();
|
2012-11-17 11:41:04 -08:00
|
|
|
this.WatchExpressions.destroy();
|
2012-10-26 10:10:17 -07:00
|
|
|
this.GlobalSearch.destroy();
|
|
|
|
|
|
|
|
this._destroyPanes();
|
|
|
|
this._destroyEditor();
|
2012-04-08 22:15:47 -07:00
|
|
|
|
2013-06-21 07:33:56 -07:00
|
|
|
aCallback();
|
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-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-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 });
|
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-02-20 15:33:36 -08:00
|
|
|
Prefs.sourcesWidth = this._sourcesPane.getAttribute("width");
|
|
|
|
Prefs.instrumentsWidth = this._instrumentsPane.getAttribute("width");
|
2012-07-20 01:56:46 -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,
|
|
|
|
eval: DebuggerController.StackFrames.evaluate,
|
|
|
|
lazyEmpty: true
|
|
|
|
});
|
|
|
|
|
|
|
|
// Attach a controller that handles interfacing with the debugger protocol.
|
|
|
|
VariablesViewController.attach(this.Variables, {
|
2013-08-13 09:08:30 -07:00
|
|
|
getObjectClient: aObject => gThreadClient.pauseGrip(aObject)
|
2013-06-21 07:33:56 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
// Relay events from the VariablesView.
|
|
|
|
this.Variables.on("fetched", (aEvent, aType) => {
|
|
|
|
switch (aType) {
|
|
|
|
case "variables":
|
|
|
|
window.dispatchEvent(document, "Debugger:FetchedVariables");
|
|
|
|
break;
|
|
|
|
case "properties":
|
|
|
|
window.dispatchEvent(document, "Debugger:FetchedProperties");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2012-04-08 22:15:47 -07:00
|
|
|
/**
|
|
|
|
* Initializes the SourceEditor 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
|
|
|
|
2012-10-26 10:10:17 -07:00
|
|
|
let placeholder = document.getElementById("editor");
|
2012-04-08 22:15:47 -07:00
|
|
|
let config = {
|
|
|
|
mode: SourceEditor.MODES.JAVASCRIPT,
|
|
|
|
readOnly: true,
|
2012-10-26 10:10:17 -07:00
|
|
|
showLineNumbers: true,
|
2012-04-08 22:15:47 -07:00
|
|
|
showAnnotationRuler: true,
|
2012-10-26 10:10:17 -07:00
|
|
|
showOverviewRuler: true
|
2012-04-08 22:15:47 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
this.editor = new SourceEditor();
|
2013-05-13 00:01:00 -07:00
|
|
|
this.editor.init(placeholder, config, () => {
|
2013-02-20 15:33:36 -08:00
|
|
|
this._loadingText = L10N.getStr("loadingText");
|
2012-08-08 14:36:58 -07:00
|
|
|
this._onEditorLoad();
|
|
|
|
aCallback();
|
2013-05-13 00:01:00 -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.
|
2012-05-31 02:27:22 -07:00
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
_onEditorLoad: function() {
|
2012-10-26 10:10:17 -07:00
|
|
|
dumpn("Finished loading the DebuggerView editor");
|
2012-09-12 03:39:51 -07:00
|
|
|
|
2012-10-26 10:10:17 -07:00
|
|
|
DebuggerController.Breakpoints.initialize();
|
2013-02-20 15:33:36 -08:00
|
|
|
window.dispatchEvent(document, "Debugger:EditorLoaded", this.editor);
|
2012-10-26 10:10:17 -07:00
|
|
|
this.editor.focus();
|
2012-05-31 02:27:22 -07:00
|
|
|
},
|
|
|
|
|
2012-04-08 22:15:47 -07:00
|
|
|
/**
|
2012-10-26 10:10:17 -07:00
|
|
|
* Destroys the SourceEditor instance and also executes any necessary
|
|
|
|
* post-unload operations.
|
2012-04-08 22:15:47 -07:00
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
_destroyEditor: function() {
|
2012-10-26 10:10:17 -07:00
|
|
|
dumpn("Destroying the DebuggerView editor");
|
|
|
|
|
2012-04-08 22:15:47 -07:00
|
|
|
DebuggerController.Breakpoints.destroy();
|
2013-02-20 15:33:36 -08:00
|
|
|
window.dispatchEvent(document, "Debugger:EditorUnloaded", this.editor);
|
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-05-13 00:01:00 -07:00
|
|
|
setEditorMode: function(aUrl, aContentType = "", aTextContent = "") {
|
2013-06-26 13:35:39 -07:00
|
|
|
// Avoid setting the editor mode for very large files.
|
|
|
|
if (aTextContent.length >= SOURCE_SYNTAX_HIGHLIGHT_MAX_FILE_SIZE) {
|
|
|
|
this.editor.setMode(SourceEditor.MODES.TEXT);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-10-26 10:10:17 -07:00
|
|
|
if (aContentType) {
|
|
|
|
if (/javascript/.test(aContentType)) {
|
|
|
|
this.editor.setMode(SourceEditor.MODES.JAVASCRIPT);
|
|
|
|
} else {
|
|
|
|
this.editor.setMode(SourceEditor.MODES.HTML);
|
|
|
|
}
|
2012-11-02 00:31:55 -07:00
|
|
|
} else if (aTextContent.match(/^\s*</)) {
|
|
|
|
// Use HTML mode for files in which the first non whitespace character is
|
|
|
|
// <, regardless of extension.
|
|
|
|
this.editor.setMode(SourceEditor.MODES.HTML);
|
2012-10-26 10:10:17 -07:00
|
|
|
} else {
|
|
|
|
// Use JS mode for files with .js and .jsm extensions.
|
|
|
|
if (/\.jsm?$/.test(SourceUtils.trimUrlQuery(aUrl))) {
|
|
|
|
this.editor.setMode(SourceEditor.MODES.JAVASCRIPT);
|
|
|
|
} else {
|
2012-11-02 00:31:55 -07:00
|
|
|
this.editor.setMode(SourceEditor.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.
|
|
|
|
*
|
|
|
|
* To update the source editor's current caret and debug location based on
|
|
|
|
* a requested url and line, use the DebuggerView.updateEditor method.
|
2012-10-26 10:10:17 -07:00
|
|
|
*
|
|
|
|
* @param object aSource
|
|
|
|
* The source object coming from the active thread.
|
|
|
|
*/
|
2013-02-20 15:33:36 -08:00
|
|
|
set editorSource(aSource) {
|
|
|
|
if (!this._isInitialized || this._isDestroyed || this._editorSource == aSource) {
|
2012-10-26 10:10:17 -07:00
|
|
|
return;
|
|
|
|
}
|
2013-02-28 04:02:00 -08:00
|
|
|
|
2013-02-20 15:33:36 -08:00
|
|
|
dumpn("Setting the DebuggerView editor source: " + aSource.url +
|
2013-06-26 13:35:39 -07:00
|
|
|
", fetched: " + !!aSource._fetched);
|
2013-02-20 15:33:36 -08:00
|
|
|
|
|
|
|
this.editor.setMode(SourceEditor.MODES.TEXT);
|
|
|
|
this.editor.setText(L10N.getStr("loadingText"));
|
|
|
|
this.editor.resetUndo();
|
|
|
|
this._editorSource = aSource;
|
2012-10-26 10:10:17 -07:00
|
|
|
|
2013-06-26 13:35:39 -07:00
|
|
|
DebuggerController.SourceScripts.getTextForSource(aSource).then(([, aText]) => {
|
2013-02-20 15:33:36 -08:00
|
|
|
// Avoid setting an unexpected source. This may happen when fast switching
|
|
|
|
// between sources that haven't been fetched yet.
|
2012-11-15 22:42:52 -08:00
|
|
|
if (this._editorSource != aSource) {
|
2013-02-20 15:33:36 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-06-26 13:35:39 -07:00
|
|
|
this.editor.setText(aText);
|
2013-02-20 15:33:36 -08:00
|
|
|
this.editor.resetUndo();
|
2013-06-26 13:35:39 -07:00
|
|
|
this.setEditorMode(aSource.url, aSource.contentType, aText);
|
2013-02-20 15:33:36 -08:00
|
|
|
|
|
|
|
// Update the editor's current caret and debug locations given by the
|
|
|
|
// currently active frame in the stack, if there's one available.
|
2012-10-26 10:10:17 -07:00
|
|
|
this.updateEditor();
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
// Notify that we've shown a source file.
|
2013-02-20 15:33:36 -08:00
|
|
|
window.dispatchEvent(document, "Debugger:SourceShown", aSource);
|
2013-06-26 13:35:39 -07:00
|
|
|
},
|
|
|
|
([, aError]) => {
|
|
|
|
// Rejected. TODO: Bug 884484.
|
|
|
|
let msg = "Error loading: " + aSource.url + "\n" + aError;
|
|
|
|
dumpn(msg);
|
|
|
|
Cu.reportError(msg);
|
|
|
|
});
|
2012-05-03 10:36:40 -07:00
|
|
|
},
|
|
|
|
|
2013-02-20 15:33:36 -08:00
|
|
|
/**
|
|
|
|
* Gets the currently displayed source text in the editor.
|
|
|
|
*
|
|
|
|
* @return object
|
|
|
|
* The source object coming from the active thread.
|
|
|
|
*/
|
|
|
|
get editorSource() this._editorSource,
|
|
|
|
|
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
|
|
|
|
* a requested url and line. If unspecified, they default to the location
|
|
|
|
* given by the currently active frame in the stack.
|
|
|
|
*
|
|
|
|
* @param string aUrl [optional]
|
|
|
|
* The target source url.
|
|
|
|
* @param number aLine [optional]
|
|
|
|
* The target line number in the source.
|
|
|
|
* @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
|
|
|
* - noSwitch: don't switch to the source if not currently selected
|
|
|
|
* - noCaret: don't set the caret location at the specified line
|
|
|
|
* - noDebug: don't set the debug location at the specified line
|
2012-07-20 01:56:46 -07:00
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
updateEditor: function(aUrl, aLine, aFlags = {}) {
|
2013-02-20 15:33:36 -08:00
|
|
|
if (!this._isInitialized || this._isDestroyed) {
|
2012-10-26 10:10:17 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
// If the location is not specified, default to the location given by
|
|
|
|
// the currently active frame in the stack.
|
|
|
|
if (!aUrl && !aLine) {
|
|
|
|
let cachedFrames = DebuggerController.activeThread.cachedFrames;
|
|
|
|
let currentFrame = DebuggerController.StackFrames.currentFrame;
|
|
|
|
let frame = cachedFrames[currentFrame];
|
|
|
|
if (frame) {
|
|
|
|
let { url, line } = frame.where;
|
|
|
|
this.updateEditor(url, line, { noSwitch: true });
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
dumpn("Updating the DebuggerView editor: " + aUrl + " @ " + aLine +
|
|
|
|
", flags: " + aFlags.toSource());
|
|
|
|
|
|
|
|
// If the currently displayed source is the requested one, update.
|
|
|
|
if (this.Sources.selectedValue == aUrl) {
|
2013-02-20 15:33:36 -08:00
|
|
|
set(aLine);
|
2012-10-26 10:10:17 -07:00
|
|
|
}
|
|
|
|
// If the requested source exists, display it and update.
|
|
|
|
else if (this.Sources.containsValue(aUrl) && !aFlags.noSwitch) {
|
|
|
|
this.Sources.selectedValue = aUrl;
|
2013-02-20 15:33:36 -08:00
|
|
|
set(aLine);
|
2012-10-26 10:10:17 -07:00
|
|
|
}
|
|
|
|
// Dumb request, invalidate the caret position and debug location.
|
|
|
|
else {
|
2013-02-20 15:33:36 -08:00
|
|
|
set(0);
|
2012-10-26 10:10:17 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Updates the source editor's caret position and debug location.
|
|
|
|
// @param number a Line
|
2013-02-20 15:33:36 -08:00
|
|
|
function set(aLine) {
|
|
|
|
let editor = DebuggerView.editor;
|
|
|
|
|
|
|
|
// Handle any additional options for showing the source.
|
|
|
|
if (aFlags.charOffset) {
|
|
|
|
aLine += editor.getLineAtOffset(aFlags.charOffset);
|
|
|
|
}
|
|
|
|
if (aFlags.lineOffset) {
|
|
|
|
aLine += aFlags.lineOffset;
|
|
|
|
}
|
2012-10-26 10:10:17 -07:00
|
|
|
if (!aFlags.noCaret) {
|
2013-03-25 11:02:34 -07:00
|
|
|
editor.setCaretPosition(aLine - 1, aFlags.columnOffset);
|
2012-10-26 10:10:17 -07:00
|
|
|
}
|
|
|
|
if (!aFlags.noDebug) {
|
2013-03-25 11:02:34 -07:00
|
|
|
editor.setDebugLocation(aLine - 1, aFlags.columnOffset);
|
2012-10-26 10:10:17 -07:00
|
|
|
}
|
|
|
|
}
|
2012-07-20 01:56:46 -07:00
|
|
|
},
|
|
|
|
|
2012-05-03 10:36:40 -07:00
|
|
|
/**
|
2012-10-26 10:10:17 -07:00
|
|
|
* Gets the text in the source editor's specified line.
|
|
|
|
*
|
|
|
|
* @param number aLine [optional]
|
|
|
|
* The line to get the text from.
|
|
|
|
* If unspecified, it defaults to the current caret position line.
|
|
|
|
* @return string
|
|
|
|
* The specified line's text.
|
2012-05-03 10:36:40 -07:00
|
|
|
*/
|
2013-06-21 07:33:56 -07:00
|
|
|
getEditorLineText: function(aLine) {
|
2012-10-26 10:10:17 -07:00
|
|
|
let line = aLine || this.editor.getCaretPosition().line;
|
|
|
|
let start = this.editor.getLineStart(line);
|
|
|
|
let end = this.editor.getLineEnd(line);
|
|
|
|
return this.editor.getText(start, end);
|
2012-07-20 01:56:46 -07:00
|
|
|
},
|
|
|
|
|
2013-03-25 11:02:34 -07:00
|
|
|
/**
|
|
|
|
* Gets the text in the source editor's selection bounds.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
* The selected text.
|
|
|
|
*/
|
2013-06-21 07:33:56 -07:00
|
|
|
getEditorSelectionText: function() {
|
2013-03-25 11:02:34 -07:00
|
|
|
let selection = this.editor.getSelection();
|
|
|
|
return this.editor.getText(selection.start, selection.end);
|
|
|
|
},
|
|
|
|
|
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-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
|
2012-10-01 07:55:32 -07:00
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
toggleInstrumentsPane: function(aFlags) {
|
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
|
|
|
}
|
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
|
|
|
|
});
|
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-05-13 00:01:00 -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();
|
2013-02-20 15:33:36 -08:00
|
|
|
this.ChromeGlobals.empty();
|
2012-10-26 10:10:17 -07:00
|
|
|
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();
|
2012-10-01 07:55:32 -07:00
|
|
|
|
2012-10-26 10:10:17 -07:00
|
|
|
if (this.editor) {
|
|
|
|
this.editor.setText("");
|
2012-12-10 06:03:48 -08:00
|
|
|
this.editor.focus();
|
2012-11-15 22:42:52 -08:00
|
|
|
this._editorSource = null;
|
2012-10-26 10:10:17 -07:00
|
|
|
}
|
2012-07-20 01:56:46 -07:00
|
|
|
},
|
|
|
|
|
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,
|
2013-02-20 15:33:36 -08:00
|
|
|
ChromeGlobals: null,
|
2012-10-26 10:10:17 -07:00
|
|
|
StackFrames: null,
|
2013-02-20 15:33:36 -08:00
|
|
|
Sources: null,
|
2012-10-26 10:10:17 -07:00
|
|
|
Variables: null,
|
2013-06-21 07:33:56 -07:00
|
|
|
WatchExpressions: null,
|
2012-10-26 10:10:17 -07:00
|
|
|
_editor: null,
|
2012-11-15 22:42:52 -08:00
|
|
|
_editorSource: null,
|
2013-02-20 15:33:36 -08:00
|
|
|
_loadingText: "",
|
|
|
|
_sourcesPane: null,
|
|
|
|
_instrumentsPane: null,
|
|
|
|
_instrumentsPaneToggleButton: null,
|
|
|
|
_collapsePaneString: "",
|
|
|
|
_expandPaneString: "",
|
2012-10-26 10:10:17 -07:00
|
|
|
_isInitialized: false,
|
2012-10-31 07:02:07 -07:00
|
|
|
_isDestroyed: false
|
2012-04-08 22:15:47 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2013-06-21 07:33:56 -07:00
|
|
|
* A stacked list of items, compatible with WidgetMethods instances, used for
|
2013-02-20 15:33:36 -08:00
|
|
|
* displaying views like the watch expressions, filtering or search results etc.
|
2012-10-26 10:10:17 -07:00
|
|
|
*
|
2013-06-21 07:33:56 -07:00
|
|
|
* You should never need to access these methods directly, use the wrapped
|
|
|
|
* WidgetMethods instead.
|
2013-03-09 21:05:09 -08:00
|
|
|
*
|
2013-06-21 07:33:56 -07:00
|
|
|
* @param nsIDOMNode aNode
|
|
|
|
* The element associated with the widget.
|
2012-04-08 22:15:47 -07:00
|
|
|
*/
|
2013-06-21 07:33:56 -07:00
|
|
|
function ListWidget(aNode) {
|
|
|
|
this._parent = aNode;
|
2012-06-04 05:35:24 -07:00
|
|
|
|
2012-10-26 10:10:17 -07:00
|
|
|
// Create an internal list container.
|
|
|
|
this._list = document.createElement("vbox");
|
|
|
|
this._parent.appendChild(this._list);
|
2013-03-09 21:05:09 -08:00
|
|
|
|
|
|
|
// Delegate some of the associated node's methods to satisfy the interface
|
2013-06-21 07:33:56 -07:00
|
|
|
// required by WidgetMethods instances.
|
2013-06-21 07:33:56 -07:00
|
|
|
ViewHelpers.delegateWidgetAttributeMethods(this, aNode);
|
|
|
|
ViewHelpers.delegateWidgetEventMethods(this, aNode);
|
2012-10-26 10:10:17 -07:00
|
|
|
}
|
2012-06-04 05:35:24 -07:00
|
|
|
|
2013-02-20 15:33:36 -08:00
|
|
|
ListWidget.prototype = {
|
|
|
|
/**
|
|
|
|
* Overrides an item's element type (e.g. "vbox" or "hbox") in this container.
|
|
|
|
* @param string aType
|
|
|
|
*/
|
|
|
|
itemType: "hbox",
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Customization function for creating an item's UI in this container.
|
|
|
|
*
|
|
|
|
* @param nsIDOMNode aElementNode
|
|
|
|
* The element associated with the displayed item.
|
|
|
|
* @param string aLabel
|
|
|
|
* The item's label.
|
|
|
|
* @param string aValue
|
|
|
|
* The item's value.
|
|
|
|
*/
|
|
|
|
itemFactory: null,
|
|
|
|
|
2012-02-07 09:22:30 -08:00
|
|
|
/**
|
2012-10-26 10:10:17 -07:00
|
|
|
* Immediately inserts an item in this container at the specified index.
|
2012-02-07 09:22:30 -08:00
|
|
|
*
|
2012-10-26 10:10:17 -07:00
|
|
|
* @param number aIndex
|
|
|
|
* The position in the container intended for this item.
|
2012-04-08 22:15:47 -07:00
|
|
|
* @param string aLabel
|
2012-10-26 10:10:17 -07:00
|
|
|
* The label displayed in the container.
|
|
|
|
* @param string aValue
|
|
|
|
* The actual internal value of the item.
|
|
|
|
* @param string aDescription [optional]
|
|
|
|
* An optional description of the item.
|
|
|
|
* @param any aAttachment [optional]
|
|
|
|
* Some attached primitive/object.
|
|
|
|
* @return nsIDOMNode
|
|
|
|
* The element associated with the displayed item.
|
2012-04-08 22:15:47 -07:00
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
insertItemAt: function(aIndex, aLabel, aValue, aDescription, aAttachment) {
|
2012-10-26 10:10:17 -07:00
|
|
|
let list = this._list;
|
|
|
|
let childNodes = list.childNodes;
|
|
|
|
|
|
|
|
let element = document.createElement(this.itemType);
|
2013-02-20 15:33:36 -08:00
|
|
|
this.itemFactory(element, aAttachment, aLabel, aValue, aDescription);
|
2012-10-26 10:10:17 -07:00
|
|
|
this._removeEmptyNotice();
|
|
|
|
|
2013-02-20 15:33:36 -08:00
|
|
|
element.classList.add("list-widget-item");
|
2012-10-26 10:10:17 -07:00
|
|
|
return list.insertBefore(element, childNodes[aIndex]);
|
2012-04-08 22:15:47 -07:00
|
|
|
},
|
|
|
|
|
2012-08-02 22:20:33 -07:00
|
|
|
/**
|
2012-10-26 10:10:17 -07:00
|
|
|
* Returns the child node in this container situated at the specified index.
|
2012-08-02 22:20:33 -07:00
|
|
|
*
|
|
|
|
* @param number aIndex
|
2012-10-26 10:10:17 -07:00
|
|
|
* The position in the container intended for this item.
|
|
|
|
* @return nsIDOMNode
|
|
|
|
* The element associated with the displayed item.
|
2012-08-02 22:20:33 -07:00
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
getItemAtIndex: function(aIndex) {
|
2012-10-26 10:10:17 -07:00
|
|
|
return this._list.childNodes[aIndex];
|
2012-08-02 22:20:33 -07:00
|
|
|
},
|
|
|
|
|
2012-04-08 22:15:47 -07:00
|
|
|
/**
|
2012-10-26 10:10:17 -07:00
|
|
|
* Immediately removes the specified child node from this container.
|
2012-04-08 22:15:47 -07:00
|
|
|
*
|
2012-10-26 10:10:17 -07:00
|
|
|
* @param nsIDOMNode aChild
|
|
|
|
* The element associated with the displayed item.
|
2012-02-07 09:22:30 -08:00
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
removeChild: function(aChild) {
|
2012-10-26 10:10:17 -07:00
|
|
|
this._list.removeChild(aChild);
|
|
|
|
|
2013-03-09 21:05:09 -08:00
|
|
|
if (this._selectedItem == aChild) {
|
|
|
|
this._selectedItem = null;
|
|
|
|
}
|
|
|
|
if (!this._list.hasChildNodes()) {
|
2012-10-26 10:10:17 -07:00
|
|
|
this._appendEmptyNotice();
|
2012-04-08 22:15:47 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2012-10-26 10:10:17 -07:00
|
|
|
* Immediately removes all of the child nodes from this container.
|
2012-04-08 22:15:47 -07:00
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
removeAllItems: function() {
|
2012-10-26 10:10:17 -07:00
|
|
|
let parent = this._parent;
|
|
|
|
let list = this._list;
|
|
|
|
|
2013-05-24 11:36:51 -07:00
|
|
|
while (list.hasChildNodes()) {
|
|
|
|
list.firstChild.remove();
|
2012-04-08 22:15:47 -07:00
|
|
|
}
|
2012-10-26 10:10:17 -07:00
|
|
|
parent.scrollTop = 0;
|
|
|
|
parent.scrollLeft = 0;
|
|
|
|
|
|
|
|
this._selectedItem = null;
|
|
|
|
this._appendEmptyNotice();
|
2012-04-08 22:15:47 -07:00
|
|
|
},
|
|
|
|
|
2012-08-18 02:29:47 -07:00
|
|
|
/**
|
2012-10-26 10:10:17 -07:00
|
|
|
* Gets the currently selected child node in this container.
|
|
|
|
* @return nsIDOMNode
|
2012-08-18 02:29:47 -07:00
|
|
|
*/
|
2012-10-26 10:10:17 -07:00
|
|
|
get selectedItem() this._selectedItem,
|
2012-08-18 02:29:47 -07:00
|
|
|
|
2012-04-17 11:16:57 -07:00
|
|
|
/**
|
2012-10-26 10:10:17 -07:00
|
|
|
* Sets the currently selected child node in this container.
|
|
|
|
* @param nsIDOMNode aChild
|
2012-04-17 11:16:57 -07:00
|
|
|
*/
|
2012-10-26 10:10:17 -07:00
|
|
|
set selectedItem(aChild) {
|
|
|
|
let childNodes = this._list.childNodes;
|
|
|
|
|
|
|
|
if (!aChild) {
|
|
|
|
this._selectedItem = null;
|
|
|
|
}
|
|
|
|
for (let node of childNodes) {
|
|
|
|
if (node == aChild) {
|
|
|
|
node.classList.add("selected");
|
|
|
|
this._selectedItem = node;
|
|
|
|
} else {
|
|
|
|
node.classList.remove("selected");
|
|
|
|
}
|
2012-04-17 11:16:57 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-11-17 11:41:04 -08:00
|
|
|
/**
|
|
|
|
* Sets the text displayed permanently in this container's header.
|
|
|
|
* @param string aValue
|
|
|
|
*/
|
|
|
|
set permaText(aValue) {
|
|
|
|
if (this._permaTextNode) {
|
|
|
|
this._permaTextNode.setAttribute("value", aValue);
|
|
|
|
}
|
|
|
|
this._permaTextValue = aValue;
|
|
|
|
this._appendPermaNotice();
|
|
|
|
},
|
|
|
|
|
2012-06-19 08:11:27 -07:00
|
|
|
/**
|
2012-10-26 10:10:17 -07:00
|
|
|
* Sets the text displayed in this container when there are no available items.
|
|
|
|
* @param string aValue
|
2012-06-19 08:11:27 -07:00
|
|
|
*/
|
2012-10-26 10:10:17 -07:00
|
|
|
set emptyText(aValue) {
|
|
|
|
if (this._emptyTextNode) {
|
|
|
|
this._emptyTextNode.setAttribute("value", aValue);
|
2012-08-18 02:29:47 -07:00
|
|
|
}
|
2012-10-26 10:10:17 -07:00
|
|
|
this._emptyTextValue = aValue;
|
2012-11-17 11:41:04 -08:00
|
|
|
this._appendEmptyNotice();
|
2012-06-19 08:11:27 -07:00
|
|
|
},
|
|
|
|
|
2012-11-17 11:41:04 -08:00
|
|
|
/**
|
|
|
|
* Creates and appends a label displayed permanently in this container's header.
|
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
_appendPermaNotice: function() {
|
2012-11-17 11:41:04 -08:00
|
|
|
if (this._permaTextNode || !this._permaTextValue) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let label = document.createElement("label");
|
2013-02-20 15:33:36 -08:00
|
|
|
label.className = "empty list-widget-item";
|
2012-11-17 11:41:04 -08:00
|
|
|
label.setAttribute("value", this._permaTextValue);
|
|
|
|
|
|
|
|
this._parent.insertBefore(label, this._list);
|
|
|
|
this._permaTextNode = label;
|
|
|
|
},
|
|
|
|
|
2012-08-18 02:29:47 -07:00
|
|
|
/**
|
2012-10-26 10:10:17 -07:00
|
|
|
* Creates and appends a label signaling that this container is empty.
|
2012-08-18 02:29:47 -07:00
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
_appendEmptyNotice: function() {
|
2012-11-17 11:41:04 -08:00
|
|
|
if (this._emptyTextNode || !this._emptyTextValue) {
|
2012-10-26 10:10:17 -07:00
|
|
|
return;
|
2012-04-19 03:44:33 -07:00
|
|
|
}
|
2012-08-18 02:29:47 -07:00
|
|
|
|
2012-10-26 10:10:17 -07:00
|
|
|
let label = document.createElement("label");
|
2013-02-20 15:33:36 -08:00
|
|
|
label.className = "empty list-widget-item";
|
2012-10-26 10:10:17 -07:00
|
|
|
label.setAttribute("value", this._emptyTextValue);
|
2012-09-11 12:50:20 -07:00
|
|
|
|
2012-10-26 10:10:17 -07:00
|
|
|
this._parent.appendChild(label);
|
|
|
|
this._emptyTextNode = label;
|
2012-09-12 03:39:29 -07:00
|
|
|
},
|
|
|
|
|
2012-08-18 02:29:47 -07:00
|
|
|
/**
|
2012-10-26 10:10:17 -07:00
|
|
|
* Removes the label signaling that this container is empty.
|
2012-08-18 02:29:47 -07:00
|
|
|
*/
|
2013-05-13 00:01:00 -07:00
|
|
|
_removeEmptyNotice: function() {
|
2012-10-26 10:10:17 -07:00
|
|
|
if (!this._emptyTextNode) {
|
2012-08-18 02:29:47 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-10-26 10:10:17 -07:00
|
|
|
this._parent.removeChild(this._emptyTextNode);
|
|
|
|
this._emptyTextNode = null;
|
2012-04-19 03:44:33 -07:00
|
|
|
},
|
|
|
|
|
2012-10-26 10:10:17 -07:00
|
|
|
_parent: null,
|
|
|
|
_list: null,
|
|
|
|
_selectedItem: null,
|
2012-11-17 11:41:04 -08:00
|
|
|
_permaTextNode: null,
|
|
|
|
_permaTextValue: "",
|
2012-10-26 10:10:17 -07:00
|
|
|
_emptyTextNode: null,
|
|
|
|
_emptyTextValue: ""
|
|
|
|
};
|
|
|
|
|
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");
|
|
|
|
this._panel.className = "results-panel";
|
|
|
|
this._panel.setAttribute("level", "top");
|
|
|
|
this._panel.setAttribute("noautofocus", "true");
|
|
|
|
document.documentElement.appendChild(this._panel);
|
|
|
|
}
|
2013-06-21 07:33:56 -07:00
|
|
|
if (!this.widget) {
|
|
|
|
this.widget = new ListWidget(this._panel);
|
|
|
|
this.widget.itemType = "vbox";
|
|
|
|
this.widget.itemFactory = this._createItemView;
|
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
|
|
|
|
*/
|
|
|
|
get anchor() this._anchor,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the container panel hidden or visible. It's hidden by default.
|
|
|
|
* @param boolean aFlag
|
|
|
|
*/
|
|
|
|
set hidden(aFlag) {
|
|
|
|
if (aFlag) {
|
|
|
|
this._panel.hidePopup();
|
|
|
|
} else {
|
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
|
|
|
this.anchor.focus();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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 nsIDOMNode aElementNode
|
|
|
|
* The element associated with the displayed item.
|
|
|
|
* @param any aAttachment
|
|
|
|
* Some attached primitive/object.
|
|
|
|
* @param string aLabel
|
|
|
|
* The item's label.
|
|
|
|
* @param string aValue
|
|
|
|
* The item's value.
|
|
|
|
* @param string aDescription
|
|
|
|
* An optional description of the item.
|
|
|
|
*/
|
2013-05-24 11:36:51 -07:00
|
|
|
_createItemView: function(aElementNode, aAttachment, aLabel, aValue, aDescription) {
|
2013-03-25 11:02:34 -07:00
|
|
|
let labelsGroup = document.createElement("hbox");
|
2013-06-21 07:33:56 -07:00
|
|
|
|
2013-03-25 11:02:34 -07:00
|
|
|
if (aDescription) {
|
|
|
|
let preLabelNode = document.createElement("label");
|
|
|
|
preLabelNode.className = "plain results-panel-item-pre";
|
|
|
|
preLabelNode.setAttribute("value", aDescription);
|
|
|
|
labelsGroup.appendChild(preLabelNode);
|
|
|
|
}
|
|
|
|
if (aLabel) {
|
|
|
|
let labelNode = document.createElement("label");
|
|
|
|
labelNode.className = "plain results-panel-item-name";
|
|
|
|
labelNode.setAttribute("value", aLabel);
|
|
|
|
labelsGroup.appendChild(labelNode);
|
|
|
|
}
|
|
|
|
|
|
|
|
let valueNode = document.createElement("label");
|
|
|
|
valueNode.className = "plain results-panel-item-details";
|
|
|
|
valueNode.setAttribute("value", aValue);
|
|
|
|
|
|
|
|
aElementNode.className = "light results-panel-item";
|
|
|
|
aElementNode.appendChild(labelsGroup);
|
|
|
|
aElementNode.appendChild(valueNode);
|
|
|
|
},
|
|
|
|
|
|
|
|
_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
|
|
|
});
|