Files
palemoon27/devtools/client/shared/widgets/FastListWidget.js
roytam1 9092bd273c import changes from `dev' branch of rmottola/Arctic-Fox:
- bug 1162519 - use winrm for mach clobber on Windows. r=gps (707dfeb728)
- No bug: Make ./mach clobber work on windows without winrm.exe. r=me (bb55cb7a1d)
- Bug 1176642 - Import proper mozinfo package; r=me (f5baa80864)
- Bug 1216171 - Fix MozbuildObject.bindir to import the correct mozinfo, r=jmaher (58df60341e)
- Bug 1216575 - [mozbuild] Remove if statement that sets bindir to resource dir on osx, r=spohl (079d7483c8)
- Bug 1190474 - Allow test-specific timeouts to be specified in cppunittest.ini, r=chmanchester (86d5ffa97c)
- Bug 1181867 - move -runtime flag to runtests.py so it gets set in automation; r=jland,ahalberstadt (939efb386c)
- Bug 1185761 - [mochitest] Allow boolean values to --keep-open for overriding the default, r=ted (b7d1c99778)
- Bug 1156425 - Allow Android test jobs to run for up to 75 minutes; r=ryanvm (9930c4f8e9)
- Bug 1171303 - Set pref extensions.autoupdate.enabled to false to avoid testOfflinePage failures; r=mfinkle (400ed217a5)
- Bug 1179981 - A new test harness for robocop; r=jmaher (9c6b066733)
- Bug 999450 - Add find-test-chunk command in mach to discover the chunk for a mochitest on a platform. r=chmanchester (b9e5b64fc6)
- Bug 1140441 - Add substring matching option to |mach mach-debug-commands|, r=gps (4ad5b5362e)
- Bug 1090276 - Support mach cppunittest on Android; r=dminor (a5dc185c03)
- Bug 1181261 - Merge configs from testing/config/mozharness into mozharness proper, r=chmanchester (9d2a45b3de)
- Bug 1217144: Allow for cppunittest to be run locally on OSX. r=erahm (f470637d77)
- Bug 1205144 - Remove 'REMOVED' commands from output of mach-commands and mach-debug-commands. r=gps DONTBUILD (19a8e3b0bf)
- Bug 1203627 - Change search order for finding android emulator; r=ahal (ca1b0eb350)
- Bug 1199377 - Fetch host-utils for Android tests when needed; r=jmaher (c276a035af)
- Bug 1211407 - Make |mach mochitest| use the adb under `out/host/*/bin` if no --adbpath specified. r=ahal (e8acae4e41)
- Bug 1122590 - Make |mach mochitest| properly detect devtools tests (and other subsuites), r=chmanchester, DONTBUILD, a=NPOTB (5034e6aac6)
- Bug 938994 - Move build/mobile/robocop into mobile/android/tests/browser/robocop. r=gbrown (f386204b05)
- Bug 1208002: Optimize creation of RegExpMatch result for 'str.match', r=bhackett (b8dccae77a)
- Bug 1214548 - GenerateLcovInfo: Check that getOrCreateScript does not OOM. r=bhackett (9bbd59a94e)
- Bug 1155937 - Fix comment in IonBuilder::getPropTryInnerize. r=bz (a8a05ec18f)
- Bug 1213146 - IonMonkey: MIPS: Modify the last two args of Assembler::bind to generic type. r=arai (54123a5c20)
- Bug 1220505 - IonMonkey: MIPS64: Fix workaround for Loongson3 in Assembler::bind. r=huangwenjun06 (fff27fcfeb)
- Bug 1220939 - IonMonkey: MIPS: Check oom() before using editSrc() and Label::use(). r=jolesen (a2a25baf45)
- Bug 1205167 - IonMonkey: MIPS64: Fix typo in Assembler-mips64. r=nbp (b339f0475b)
- Bug 1217873 - IonMonkey: MIPS: Move BailoutStack to architecture dependent. r=arai f=nbp (cd6a703e71)
- Bug 1217873 - IonMonkey: MIPS: Move visitOutOfLineBailout to architecture dependent. r=arai f=nbp (4fc456d837)
- Bug 1217873 - IonMonkey: MIPS64: Simplify BailoutStack for MIPS64. r=lth (baafdfefeb)
- Bug 1090957 - IonMonkey: MIPS64: Implement atomics in MacroAssembler. r=lth (64df89560f)
- Bug 1219157 - IonMonkey: MIPS64: Delete CodeOffsetLabel::fixup(). r=jolesen (20a4bb8de4)
- Bug 1219125 - IonMonkey: MIPS64: Fix profiler/test-bug1026485.js failure in debug mode. r=arai (701dca2337)
- Bug 1213532 - IonMonkey: MIPS32: Fix call FloatRegistersMIPSShared::GetName recursive. r=arai (96cb12e849)
- Bug 1213532 - IonMonkey: MIPS32: Rename BaseFloatRegisters to FloatRegistersMIPSShared. r=arai (d0bbaaad17)
- Bug 1066642 - IonMonkey: MIPS32: Do not allocate odd FP registers on Loongson CPU-s. r=arai (fe0e2e6f0a)
- Bug 1215420 - IonMonkey: MIPS32: Fix FloatRegister::encoding. r=nbp (03534b7eb6)
- Bug 1129813 - special-case "while" and "for" line notes; r=jimb (000e7e8bea)
- Bug 1139235 - don't set line for literal case expressions; r=fitzgen (b317b4c427)
- Bug 1220766 - Don't assume ListIterator's next slot contains an int32 r=shu (65b563b78b)
- Bug 1224222 - Guard against setters on Array.prototype in self-hosted Module code. r=jonco (5ac5b48c5b)
- Bug 1219044 - Take account of the fact that module import bindings may be null if we have hit OOM r=terrence (27b1e057ad)
- Bug 1219408 - Throw error if module loader attempts to evaluate an uninstantiated module r=shu (b89af38208)
- clean up double definition (92c2e6c4d2)
- remove, since 1170372 has long since landed and no trace can be found in FF/TFF (e417a4dc58)
- Bug 1215430 - Inline the guts of the shared method implementing |new RegExp(...)| and |RegExp.prototype.compile| into each separate method, for clarity. r=efaust (5be0d360f2)
- Bug 1215430 - Refactor RegExp code to be more spec-like in its ordering of things, and eliminate the confusing statefulness of RegExpObjectBuilder. r=efaust (fe24ae119d)
- Bug 1209001 - Add test code for OOM handling in parseModule() r=terrence (c36cc5e5c1)
- Bug 978802 - Crash in argumentsOptimizationFailed() if we run out of memory r=jandem (de1bb00bd7)
- Bug 1212128 - Annotate oomInGetJumpLabelForBranch with allow-oom. (rs=terrence) (72304c3b03)
- Bug 1212469 - Make oomTest() into a shell function r=nbp (6c19395033)
- various cleanups (d12627b23f)
- fix some paths (501a27989a)
- Bug 1216260 - Replace mozMatchesSelector with matches in add-on SDK. r=matteo (7457c563b6)
- Bug 1217072 - Remove for-each from addon-sdk/. r=mossop (fa2e52f56e)
- Bug 1216269 - Fix tab-firefox.js typo in tab attach method. r=zer0 (a59f126ec8)
- var-let (d81c53a0ce)
- Bug 1139100 - Apply proper checking for command existence; r=ahal (5d0f1fc75d)
- Bug 1176620 - Refactor how mach command metadata is stored; r=ahal (aa6dc7c786)
- Bug 1176620 - Pass fewer arguments into MethodHandler; r=ahal (fa64eef7ab)
- Bug 1176620 - Eliminate MethodHandler; r=ahal (04130c8e62)
- Bug 1177476 - Fix require_conditions regression in mach, r=gps (30c6400900)
- Bug 1208320 - Allow FileFinder to find dot files; r=glandium (639f2695a0)
- Bug 1210329 - Remove support for line endings munging in the preprocessor. r=gps (cbb01fa96e)
- Bug 1211957 - Add the repackage step at the end of a faster build on Mac. r=gps (48fb11101a)
- Bug 1210687 - Use install manifests for jar.mn files in FasterMake backend. r=gps (cb0b4e2c92)
- Bug 1215238 - Mention the included filepath in pre-processed js sources with #includes. r=glandium (3b3590e287)
- Bug 1209839 - Remove the -E option to the preprocessor. r=gps (63c60f15cd)
- Bug 1215526 - part 3 - make preprocessor.preprocessor report all included files; r=glandium (c4949756ff)
- bit of Bug 1207708 - Part 2 (2a87bac13f)
- fix path (f0ef6214c9)
- some var fixes (35b7ffd9bd)
- Bug 1211810 - Add a way to lock the highlighter on animated nodes from animation-inspector; r=tromey (3cffa92e36)
- more small fixes (14fc9f69f7)
- Bug 1193341 - Detect presence of password fields in any subframe, flagging those on insecure connections. r=MattN (00e2b06413)
- Bug 433238 - Tests for the password manager contextual menu password fill. r=MattN (0b00e327a7)
- Bug 1216668 - Move Parser.jsm to devtools/shared so the webconsole server can use it;r=jryans (bc5e601477)
- Bug 1216668 - Implement console autocomplete for inline arrays and multiline strings;r=fitzgen (b48d94286f)
- various fixes +  Bug 1214231 - Provide an option to generate census tree nodes in a worker when taking a census. r=fitzgen (9907a0539e)
- Bug 1214070 - Add support for diffing census reports to HeapAnalysesWorker; r=jsantell (358ba68ceb)
- Bug 1210954 - Move devtools variables into a single variables.css file;r=jryans;r=jsantell (625329de81)
- fix dupes (ca0a717f35)
- Bug 1209641 - Remove dropdown layout and use sidebars layout. r=jryans (4d52ff6162)
- Bug 1070719 - Autosave project files before running. r=jryans (88ad0d6eba)
- Bug 1205305 - Fix a race condition in browser_dbg_server-conditional-bp-02.js;r=jlong (bb4e3f529c)
- some more var (7a7adf9d0b)
- Bug 1210430 - Use Promise.jsm to make beta doorhanger work again;r=jsantell (5adf7f7854)
- more bits of Fix the World (9788076141)
- Bug 1213137 - Initial react app for memory tool with its snapshot list view. r=jlong (5620d7fae2)
- more World Fix (9828047c75)
- Bug 1203159 - Add resource:// mapping in all DevTools directories. r=glandium,ochameau (9cac2329e8)
- Bug 1203159 - Update each product's DevTools inclusion. r=glandium (0190045250)
- Bug 1203159 - Rewrite DevTools resource URLs. r=ochameau (57eca13fa9)
- Bug 1203159 - Update shim install locations. r=glandium,ochameau (e43672127a)
- Bug 1203159 - Update install location for external libs. r=ochameau (ff1c49723f)
- Bug 1203159 - Clean up various incorrect paths. r=ochameau (cb8a046eb3)
- fix dupes again (644bd27257)
- ported Bug 1217687 - Revert back to including /devtools via toolkit. r=glandium (c30aa568c7)
- Bug 1217687 - Appease the mozbuild reading test. r=me (3a5e862df3)
2022-12-22 10:25:14 +08:00

251 lines
6.9 KiB
JavaScript

/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
const EventEmitter = require("devtools/shared/event-emitter");
const { Cu, Ci } = require("chrome");
const { ViewHelpers } = Cu.import("resource://devtools/client/shared/widgets/ViewHelpers.jsm", {});
/**
* A list menu widget that attempts to be very fast.
*
* Note: this widget should be used in tandem with the WidgetMethods in
* ViewHelpers.jsm.
*
* @param nsIDOMNode aNode
* The element associated with the widget.
*/
const FastListWidget = module.exports = function FastListWidget(aNode) {
this.document = aNode.ownerDocument;
this.window = this.document.defaultView;
this._parent = aNode;
this._fragment = this.document.createDocumentFragment();
// This is a prototype element that each item added to the list clones.
this._templateElement = this.document.createElement("hbox");
// Create an internal scrollbox container.
this._list = this.document.createElement("scrollbox");
this._list.className = "fast-list-widget-container theme-body";
this._list.setAttribute("flex", "1");
this._list.setAttribute("orient", "vertical");
this._list.setAttribute("tabindex", "0");
this._list.addEventListener("keypress", e => this.emit("keyPress", e), false);
this._list.addEventListener("mousedown", e => this.emit("mousePress", e), false);
this._parent.appendChild(this._list);
this._orderedMenuElementsArray = [];
this._itemsByElement = new Map();
// This widget emits events that can be handled in a MenuContainer.
EventEmitter.decorate(this);
// Delegate some of the associated node's methods to satisfy the interface
// required by MenuContainer instances.
ViewHelpers.delegateWidgetAttributeMethods(this, aNode);
ViewHelpers.delegateWidgetEventMethods(this, aNode);
}
FastListWidget.prototype = {
/**
* Inserts an item in this container at the specified index, optionally
* grouping by name.
*
* @param number aIndex
* The position in the container intended for this item.
* @param nsIDOMNode aContents
* The node to be displayed in the container.
* @param Object aAttachment [optional]
* Extra data for the user.
* @return nsIDOMNode
* The element associated with the displayed item.
*/
insertItemAt: function(aIndex, aContents, aAttachment={}) {
let element = this._templateElement.cloneNode();
element.appendChild(aContents);
if (aIndex >= 0) {
throw new Error("FastListWidget only supports appending items.");
}
this._fragment.appendChild(element);
this._orderedMenuElementsArray.push(element);
this._itemsByElement.set(element, this);
return element;
},
/**
* This is a non-standard widget implementation method. When appending items,
* they are queued in a document fragment. This method appends the document
* fragment to the dom.
*/
flush: function() {
this._list.appendChild(this._fragment);
},
/**
* Removes all of the child nodes from this container.
*/
removeAllItems: function() {
let parent = this._parent;
let list = this._list;
while (list.hasChildNodes()) {
list.firstChild.remove();
}
this._selectedItem = null;
this._orderedMenuElementsArray.length = 0;
this._itemsByElement.clear();
},
/**
* Remove the given item.
*/
removeChild: function(child) {
throw new Error("Not yet implemented");
},
/**
* Gets the currently selected child node in this container.
* @return nsIDOMNode
*/
get selectedItem() {
return this._selectedItem;
},
/**
* Sets the currently selected child node in this container.
* @param nsIDOMNode child
*/
set selectedItem(child) {
let menuArray = this._orderedMenuElementsArray;
if (!child) {
this._selectedItem = null;
}
for (let node of menuArray) {
if (node == child) {
node.classList.add("selected");
this._selectedItem = node;
} else {
node.classList.remove("selected");
}
}
this.ensureElementIsVisible(this.selectedItem);
},
/**
* Returns the child node in this container situated at the specified index.
*
* @param number index
* The position in the container intended for this item.
* @return nsIDOMNode
* The element associated with the displayed item.
*/
getItemAtIndex: function(index) {
return this._orderedMenuElementsArray[index];
},
/**
* Adds a new attribute or changes an existing attribute on this container.
*
* @param string name
* The name of the attribute.
* @param string value
* The desired attribute value.
*/
setAttribute: function(name, value) {
this._parent.setAttribute(name, value);
if (name == "emptyText") {
this._textWhenEmpty = value;
}
},
/**
* Removes an attribute on this container.
*
* @param string name
* The name of the attribute.
*/
removeAttribute: function(name) {
this._parent.removeAttribute(name);
if (name == "emptyText") {
this._removeEmptyText();
}
},
/**
* Ensures the specified element is visible.
*
* @param nsIDOMNode element
* The element to make visible.
*/
ensureElementIsVisible: function(element) {
if (!element) {
return;
}
// Ensure the element is visible but not scrolled horizontally.
let boxObject = this._list.boxObject;
boxObject.ensureElementIsVisible(element);
boxObject.scrollBy(-this._list.clientWidth, 0);
},
/**
* Sets the text displayed in this container when empty.
* @param string aValue
*/
set _textWhenEmpty(aValue) {
if (this._emptyTextNode) {
this._emptyTextNode.setAttribute("value", aValue);
}
this._emptyTextValue = aValue;
this._showEmptyText();
},
/**
* Creates and appends a label signaling that this container is empty.
*/
_showEmptyText: function() {
if (this._emptyTextNode || !this._emptyTextValue) {
return;
}
let label = this.document.createElement("label");
label.className = "plain fast-list-widget-empty-text";
label.setAttribute("value", this._emptyTextValue);
this._parent.insertBefore(label, this._list);
this._emptyTextNode = label;
},
/**
* Removes the label signaling that this container is empty.
*/
_removeEmptyText: function() {
if (!this._emptyTextNode) {
return;
}
this._parent.removeChild(this._emptyTextNode);
this._emptyTextNode = null;
},
window: null,
document: null,
_parent: null,
_list: null,
_selectedItem: null,
_orderedMenuElementsArray: null,
_itemsByElement: null,
_emptyTextNode: null,
_emptyTextValue: ""
};