2018-07-30 07:59:16 +03:00
|
|
|
/* vim: set ts=2 sw=2 sts=2 et tw=80: */
|
2013-08-28 05:09:44 +04: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/. */
|
2013-08-26 05:34:23 +04:00
|
|
|
"use strict";
|
|
|
|
|
2018-07-30 07:59:16 +03:00
|
|
|
var EXPORTED_SYMBOLS = ["SelectChild"];
|
|
|
|
|
2019-06-13 20:29:19 +03:00
|
|
|
const {ActorChild} = ChromeUtils.import("resource://gre/modules/ActorChild.jsm");
|
2019-01-17 21:18:31 +03:00
|
|
|
const {XPCOMUtils} = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
|
2013-08-26 05:34:23 +04:00
|
|
|
|
2018-01-30 02:20:18 +03:00
|
|
|
ChromeUtils.defineModuleGetter(this, "BrowserUtils",
|
|
|
|
"resource://gre/modules/BrowserUtils.jsm");
|
|
|
|
ChromeUtils.defineModuleGetter(this, "DeferredTask",
|
|
|
|
"resource://gre/modules/DeferredTask.jsm");
|
2016-03-30 12:54:31 +03:00
|
|
|
|
2018-05-26 03:02:29 +03:00
|
|
|
XPCOMUtils.defineLazyGlobalGetters(this, ["InspectorUtils"]);
|
2018-01-11 07:38:01 +03:00
|
|
|
|
2016-07-25 16:09:11 +03:00
|
|
|
const kStateActive = 0x00000001; // NS_EVENT_STATE_ACTIVE
|
2016-03-30 12:54:31 +03:00
|
|
|
const kStateHover = 0x00000004; // NS_EVENT_STATE_HOVER
|
2014-03-01 05:00:17 +04:00
|
|
|
|
2017-07-31 05:06:29 +03:00
|
|
|
const SUPPORTED_PROPERTIES = [
|
2019-02-28 04:44:52 +03:00
|
|
|
"direction",
|
2017-07-31 05:06:29 +03:00
|
|
|
"color",
|
|
|
|
"background-color",
|
|
|
|
"text-shadow",
|
2019-02-28 04:44:52 +03:00
|
|
|
"font-family",
|
|
|
|
"font-weight",
|
|
|
|
"font-size",
|
|
|
|
"font-style",
|
2017-07-31 05:06:29 +03:00
|
|
|
];
|
|
|
|
|
2016-05-13 17:40:24 +03:00
|
|
|
// A process global state for whether or not content thinks
|
|
|
|
// that a <select> dropdown is open or not. This is managed
|
|
|
|
// entirely within this module, and is read-only accessible
|
|
|
|
// via SelectContentHelper.open.
|
|
|
|
var gOpen = false;
|
|
|
|
|
2019-06-13 20:29:19 +03:00
|
|
|
var SelectContentHelper = function(aElement, aOptions, aGlobal) {
|
2013-08-26 05:34:23 +04:00
|
|
|
this.element = aElement;
|
2015-06-26 19:32:25 +03:00
|
|
|
this.initialSelection = aElement[aElement.selectedIndex] || null;
|
2019-06-13 20:29:19 +03:00
|
|
|
this.global = aGlobal;
|
2017-10-18 09:36:49 +03:00
|
|
|
this.closedWithClickOn = false;
|
2016-10-20 19:45:39 +03:00
|
|
|
this.isOpenedViaTouch = aOptions.isOpenedViaTouch;
|
2017-04-26 03:19:42 +03:00
|
|
|
this._closeAfterBlur = true;
|
2017-05-25 01:25:39 +03:00
|
|
|
this._pseudoStylesSetup = false;
|
|
|
|
this._lockedDescendants = null;
|
2013-08-26 05:34:23 +04:00
|
|
|
this.init();
|
|
|
|
this.showDropDown();
|
2016-04-16 05:00:36 +03:00
|
|
|
this._updateTimer = new DeferredTask(this._update.bind(this), 0);
|
2017-10-15 21:50:30 +03:00
|
|
|
};
|
2013-08-26 05:34:23 +04:00
|
|
|
|
2016-05-13 17:40:24 +03:00
|
|
|
Object.defineProperty(SelectContentHelper, "open", {
|
2016-12-30 02:34:54 +03:00
|
|
|
get() {
|
2016-05-13 17:40:24 +03:00
|
|
|
return gOpen;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2013-08-26 05:34:23 +04:00
|
|
|
this.SelectContentHelper.prototype = {
|
2016-12-30 02:34:54 +03:00
|
|
|
init() {
|
2019-06-13 20:29:19 +03:00
|
|
|
this.global.addMessageListener("Forms:SelectDropDownItem", this);
|
|
|
|
this.global.addMessageListener("Forms:DismissedDropDown", this);
|
|
|
|
this.global.addMessageListener("Forms:MouseOver", this);
|
|
|
|
this.global.addMessageListener("Forms:MouseOut", this);
|
|
|
|
this.global.addMessageListener("Forms:MouseUp", this);
|
|
|
|
this.global.addMessageListener("Forms:SearchFocused", this);
|
|
|
|
this.global.addMessageListener("Forms:BlurDropDown-Pong", this);
|
|
|
|
this.global.addEventListener("pagehide", this, { mozSystemGroup: true });
|
|
|
|
this.global.addEventListener("mozhidedropdown", this, { mozSystemGroup: true });
|
2017-02-09 19:28:22 +03:00
|
|
|
this.element.addEventListener("blur", this, { mozSystemGroup: true });
|
2017-04-04 05:52:16 +03:00
|
|
|
this.element.addEventListener("transitionend", this, { mozSystemGroup: true });
|
2017-01-27 12:51:03 +03:00
|
|
|
let MutationObserver = this.element.ownerGlobal.MutationObserver;
|
2016-04-16 05:00:36 +03:00
|
|
|
this.mut = new MutationObserver(mutations => {
|
|
|
|
// Something changed the <select> while it was open, so
|
|
|
|
// we'll poke a DeferredTask to update the parent sometime
|
|
|
|
// in the very near future.
|
|
|
|
this._updateTimer.arm();
|
|
|
|
});
|
2017-03-29 19:47:13 +03:00
|
|
|
this.mut.observe(this.element, {childList: true, subtree: true, attributes: true});
|
2013-08-26 05:34:23 +04:00
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
uninit() {
|
2016-08-03 14:45:46 +03:00
|
|
|
this.element.openInParentProcess = false;
|
2019-06-13 20:29:19 +03:00
|
|
|
this.global.removeMessageListener("Forms:SelectDropDownItem", this);
|
|
|
|
this.global.removeMessageListener("Forms:DismissedDropDown", this);
|
|
|
|
this.global.removeMessageListener("Forms:MouseOver", this);
|
|
|
|
this.global.removeMessageListener("Forms:MouseOut", this);
|
|
|
|
this.global.removeMessageListener("Forms:MouseUp", this);
|
|
|
|
this.global.removeMessageListener("Forms:SearchFocused", this);
|
|
|
|
this.global.removeMessageListener("Forms:BlurDropDown-Pong", this);
|
|
|
|
this.global.removeEventListener("pagehide", this, { mozSystemGroup: true });
|
|
|
|
this.global.removeEventListener("mozhidedropdown", this, { mozSystemGroup: true });
|
2017-02-09 19:28:22 +03:00
|
|
|
this.element.removeEventListener("blur", this, { mozSystemGroup: true });
|
2017-04-04 05:52:16 +03:00
|
|
|
this.element.removeEventListener("transitionend", this, { mozSystemGroup: true });
|
2013-08-26 05:34:23 +04:00
|
|
|
this.element = null;
|
2019-06-13 20:29:19 +03:00
|
|
|
this.global = null;
|
2016-04-16 05:00:36 +03:00
|
|
|
this.mut.disconnect();
|
|
|
|
this._updateTimer.disarm();
|
|
|
|
this._updateTimer = null;
|
2016-05-13 17:40:24 +03:00
|
|
|
gOpen = false;
|
2013-08-26 05:34:23 +04:00
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
showDropDown() {
|
2016-08-03 14:45:46 +03:00
|
|
|
this.element.openInParentProcess = true;
|
2017-05-25 01:25:39 +03:00
|
|
|
this._setupPseudoClassStyles();
|
2013-08-26 05:34:23 +04:00
|
|
|
let rect = this._getBoundingContentRect();
|
2017-02-04 08:33:13 +03:00
|
|
|
let computedStyles = getComputedStyles(this.element);
|
2018-12-07 01:22:45 +03:00
|
|
|
let options = this._buildOptionList();
|
|
|
|
let defaultStyles = this.element.ownerGlobal.getDefaultComputedStyle(this.element);
|
2019-06-13 20:29:19 +03:00
|
|
|
this.global.sendAsyncMessage("Forms:ShowDropDown", {
|
2017-02-04 08:33:13 +03:00
|
|
|
isOpenedViaTouch: this.isOpenedViaTouch,
|
2018-12-07 01:22:45 +03:00
|
|
|
options,
|
2017-02-04 08:33:13 +03:00
|
|
|
rect,
|
2015-07-14 05:03:51 +03:00
|
|
|
selectedIndex: this.element.selectedIndex,
|
2019-02-28 04:44:52 +03:00
|
|
|
style: supportedStyles(computedStyles),
|
|
|
|
defaultStyle: supportedStyles(defaultStyles),
|
2013-08-26 05:34:23 +04:00
|
|
|
});
|
2017-05-25 01:25:39 +03:00
|
|
|
this._clearPseudoClassStyles();
|
2016-05-13 17:40:24 +03:00
|
|
|
gOpen = true;
|
2013-08-26 05:34:23 +04:00
|
|
|
},
|
|
|
|
|
2017-05-25 01:25:39 +03:00
|
|
|
_setupPseudoClassStyles() {
|
|
|
|
if (this._pseudoStylesSetup) {
|
|
|
|
throw new Error("pseudo styles must not be set up yet");
|
|
|
|
}
|
|
|
|
// Do all of the things that change style at once, before we read
|
|
|
|
// any styles.
|
|
|
|
this._pseudoStylesSetup = true;
|
2018-01-11 07:38:01 +03:00
|
|
|
InspectorUtils.addPseudoClassLock(this.element, ":focus");
|
2017-05-25 01:25:39 +03:00
|
|
|
let lockedDescendants = this._lockedDescendants = this.element.querySelectorAll(":checked");
|
|
|
|
for (let child of lockedDescendants) {
|
|
|
|
// Selected options have the :checked pseudo-class, which
|
|
|
|
// we want to disable before calculating the computed
|
|
|
|
// styles since the user agent styles alter the styling
|
|
|
|
// based on :checked.
|
2018-01-11 07:38:01 +03:00
|
|
|
InspectorUtils.addPseudoClassLock(child, ":checked", false);
|
2017-05-25 01:25:39 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_clearPseudoClassStyles() {
|
|
|
|
if (!this._pseudoStylesSetup) {
|
|
|
|
throw new Error("pseudo styles must be set up already");
|
|
|
|
}
|
|
|
|
// Undo all of the things that change style at once, after we're
|
|
|
|
// done reading styles.
|
2018-01-11 07:38:01 +03:00
|
|
|
InspectorUtils.clearPseudoClassLocks(this.element);
|
2017-05-25 01:25:39 +03:00
|
|
|
let lockedDescendants = this._lockedDescendants;
|
|
|
|
for (let child of lockedDescendants) {
|
2018-01-11 07:38:01 +03:00
|
|
|
InspectorUtils.clearPseudoClassLocks(child);
|
2017-05-25 01:25:39 +03:00
|
|
|
}
|
|
|
|
this._lockedDescendants = null;
|
|
|
|
this._pseudoStylesSetup = false;
|
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
_getBoundingContentRect() {
|
2014-03-01 05:00:17 +04:00
|
|
|
return BrowserUtils.getElementBoundingScreenRect(this.element);
|
2013-08-26 05:34:23 +04:00
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
_buildOptionList() {
|
2017-05-25 01:25:39 +03:00
|
|
|
if (!this._pseudoStylesSetup) {
|
|
|
|
throw new Error("pseudo styles must be set up");
|
|
|
|
}
|
2019-02-28 04:44:52 +03:00
|
|
|
let uniqueStyles = [];
|
|
|
|
let options = buildOptionListForChildren(this.element, uniqueStyles);
|
|
|
|
return { options, uniqueStyles };
|
2013-08-26 05:34:23 +04:00
|
|
|
},
|
|
|
|
|
2016-04-16 05:00:36 +03:00
|
|
|
_update() {
|
|
|
|
// The <select> was updated while the dropdown was open.
|
|
|
|
// Let's send up a new list of options.
|
2017-03-23 20:34:21 +03:00
|
|
|
// Technically we might not need to set this pseudo-class
|
|
|
|
// during _update() since the element should organically
|
|
|
|
// have :focus, though it is here for belt-and-suspenders.
|
2017-05-25 01:25:39 +03:00
|
|
|
this._setupPseudoClassStyles();
|
2017-03-23 20:34:21 +03:00
|
|
|
let computedStyles = getComputedStyles(this.element);
|
2018-12-07 01:22:45 +03:00
|
|
|
let defaultStyles = this.element.ownerGlobal.getDefaultComputedStyle(this.element);
|
2019-06-13 20:29:19 +03:00
|
|
|
this.global.sendAsyncMessage("Forms:UpdateDropDown", {
|
2016-04-16 05:00:36 +03:00
|
|
|
options: this._buildOptionList(),
|
|
|
|
selectedIndex: this.element.selectedIndex,
|
2019-02-28 04:44:52 +03:00
|
|
|
style: supportedStyles(computedStyles),
|
|
|
|
defaultStyle: supportedStyles(defaultStyles),
|
2016-04-16 05:00:36 +03:00
|
|
|
});
|
2017-05-25 01:25:39 +03:00
|
|
|
this._clearPseudoClassStyles();
|
2016-04-16 05:00:36 +03:00
|
|
|
},
|
|
|
|
|
2017-01-19 18:03:56 +03:00
|
|
|
dispatchMouseEvent(win, target, eventName) {
|
|
|
|
let mouseEvent = new win.MouseEvent(eventName, {
|
|
|
|
view: win,
|
|
|
|
bubbles: true,
|
|
|
|
cancelable: true,
|
|
|
|
});
|
|
|
|
target.dispatchEvent(mouseEvent);
|
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
receiveMessage(message) {
|
2013-08-26 05:34:23 +04:00
|
|
|
switch (message.name) {
|
|
|
|
case "Forms:SelectDropDownItem":
|
2015-06-26 19:32:25 +03:00
|
|
|
this.element.selectedIndex = message.data.value;
|
2017-10-18 09:36:49 +03:00
|
|
|
this.closedWithClickOn = !message.data.closedWithEnter;
|
2015-06-26 19:32:25 +03:00
|
|
|
break;
|
2013-12-11 01:46:21 +04:00
|
|
|
|
2017-10-05 11:12:47 +03:00
|
|
|
case "Forms:DismissedDropDown": {
|
2017-01-27 12:51:03 +03:00
|
|
|
let win = this.element.ownerGlobal;
|
2017-10-05 11:12:47 +03:00
|
|
|
let selectedOption = this.element.item(this.element.selectedIndex);
|
|
|
|
|
2016-08-02 22:09:59 +03:00
|
|
|
// For ordering of events, we're using non-e10s as our guide here,
|
2017-10-18 09:36:49 +03:00
|
|
|
// since the spec isn't exactly clear. In non-e10s:
|
|
|
|
// - If the user clicks on an element in the dropdown, we fire
|
|
|
|
// mousedown, mouseup, input, change, and click events.
|
|
|
|
// - If the user uses the keyboard to select an element in the
|
|
|
|
// dropdown, we only fire input and change events.
|
|
|
|
// - If the user pressed ESC key or clicks outside the dropdown,
|
|
|
|
// we fire nothing as the selected option is unchanged.
|
|
|
|
if (this.closedWithClickOn) {
|
2017-01-19 18:03:56 +03:00
|
|
|
this.dispatchMouseEvent(win, selectedOption, "mousedown");
|
|
|
|
this.dispatchMouseEvent(win, selectedOption, "mouseup");
|
2016-08-02 22:09:59 +03:00
|
|
|
}
|
2017-10-05 11:12:47 +03:00
|
|
|
|
|
|
|
// Clear active document no matter user selects via keyboard or mouse
|
2018-01-11 07:38:01 +03:00
|
|
|
InspectorUtils.removeContentState(this.element, kStateActive,
|
|
|
|
/* aClearActiveDocument */ true);
|
2016-08-02 22:09:59 +03:00
|
|
|
|
2017-10-05 11:12:47 +03:00
|
|
|
// Fire input and change events when selected option changes
|
|
|
|
if (this.initialSelection !== selectedOption) {
|
2018-11-20 17:35:38 +03:00
|
|
|
let inputEvent = new win.Event("input", {
|
2017-10-05 11:12:47 +03:00
|
|
|
bubbles: true,
|
|
|
|
});
|
|
|
|
this.element.dispatchEvent(inputEvent);
|
|
|
|
|
|
|
|
let changeEvent = new win.Event("change", {
|
|
|
|
bubbles: true,
|
|
|
|
});
|
|
|
|
this.element.dispatchEvent(changeEvent);
|
|
|
|
}
|
2016-05-13 17:40:24 +03:00
|
|
|
|
2017-10-05 11:12:47 +03:00
|
|
|
// Fire click event
|
2017-10-18 09:36:49 +03:00
|
|
|
if (this.closedWithClickOn) {
|
2017-01-19 18:03:56 +03:00
|
|
|
this.dispatchMouseEvent(win, selectedOption, "click");
|
2016-05-25 20:21:23 +03:00
|
|
|
}
|
2013-08-26 05:34:23 +04:00
|
|
|
|
2017-10-05 11:12:47 +03:00
|
|
|
this.uninit();
|
|
|
|
break;
|
|
|
|
}
|
2016-03-30 12:54:31 +03:00
|
|
|
|
|
|
|
case "Forms:MouseOver":
|
2018-01-11 07:38:01 +03:00
|
|
|
InspectorUtils.setContentState(this.element, kStateHover);
|
2016-03-30 12:54:31 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case "Forms:MouseOut":
|
2018-01-11 07:38:01 +03:00
|
|
|
InspectorUtils.removeContentState(this.element, kStateHover);
|
2016-03-30 12:54:31 +03:00
|
|
|
break;
|
|
|
|
|
2016-11-17 17:56:43 +03:00
|
|
|
case "Forms:MouseUp":
|
2017-01-27 12:51:03 +03:00
|
|
|
let win = this.element.ownerGlobal;
|
2017-01-19 18:03:56 +03:00
|
|
|
if (message.data.onAnchor) {
|
|
|
|
this.dispatchMouseEvent(win, this.element, "mouseup");
|
|
|
|
}
|
2018-01-11 07:38:01 +03:00
|
|
|
InspectorUtils.removeContentState(this.element, kStateActive);
|
2017-01-19 18:03:56 +03:00
|
|
|
if (message.data.onAnchor) {
|
|
|
|
this.dispatchMouseEvent(win, this.element, "click");
|
|
|
|
}
|
2016-11-17 17:56:43 +03:00
|
|
|
break;
|
2017-04-26 03:19:42 +03:00
|
|
|
|
|
|
|
case "Forms:SearchFocused":
|
|
|
|
this._closeAfterBlur = false;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "Forms:BlurDropDown-Pong":
|
|
|
|
if (!this._closeAfterBlur || !gOpen) {
|
|
|
|
return;
|
|
|
|
}
|
2019-06-13 20:29:19 +03:00
|
|
|
this.global.sendAsyncMessage("Forms:HideDropDown", {});
|
2017-04-26 03:19:42 +03:00
|
|
|
this.uninit();
|
|
|
|
break;
|
2013-08-26 05:34:23 +04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
handleEvent(event) {
|
2013-08-26 05:34:23 +04:00
|
|
|
switch (event.type) {
|
|
|
|
case "pagehide":
|
2016-03-18 10:12:46 +03:00
|
|
|
if (this.element.ownerDocument === event.target) {
|
2019-06-13 20:29:19 +03:00
|
|
|
this.global.sendAsyncMessage("Forms:HideDropDown", {});
|
2016-03-18 10:12:46 +03:00
|
|
|
this.uninit();
|
|
|
|
}
|
2013-08-26 05:34:23 +04:00
|
|
|
break;
|
2017-04-26 03:19:42 +03:00
|
|
|
case "blur": {
|
|
|
|
if (this.element !== event.target) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
this._closeAfterBlur = true;
|
|
|
|
// Send a ping-pong message to make sure that we wait for
|
|
|
|
// enough cycles to pass from the potential focusing of the
|
|
|
|
// search box to disable closing-after-blur.
|
2019-06-13 20:29:19 +03:00
|
|
|
this.global.sendAsyncMessage("Forms:BlurDropDown-Ping", {});
|
2017-04-26 03:19:42 +03:00
|
|
|
break;
|
|
|
|
}
|
2016-04-13 20:15:55 +03:00
|
|
|
case "mozhidedropdown":
|
|
|
|
if (this.element === event.target) {
|
2019-06-13 20:29:19 +03:00
|
|
|
this.global.sendAsyncMessage("Forms:HideDropDown", {});
|
2016-04-13 20:15:55 +03:00
|
|
|
this.uninit();
|
|
|
|
}
|
|
|
|
break;
|
2017-04-04 05:52:16 +03:00
|
|
|
case "transitionend":
|
2018-02-01 22:45:22 +03:00
|
|
|
if (SUPPORTED_PROPERTIES.includes(event.propertyName)) {
|
2017-07-31 05:06:29 +03:00
|
|
|
this._updateTimer.arm();
|
|
|
|
}
|
2017-04-04 05:52:16 +03:00
|
|
|
break;
|
2013-08-26 05:34:23 +04:00
|
|
|
}
|
2018-08-31 08:59:17 +03:00
|
|
|
},
|
2017-10-15 21:50:30 +03:00
|
|
|
};
|
2013-08-26 05:34:23 +04:00
|
|
|
|
2016-10-21 22:55:25 +03:00
|
|
|
function getComputedStyles(element) {
|
2017-01-27 12:51:03 +03:00
|
|
|
return element.ownerGlobal.getComputedStyle(element);
|
2015-07-14 05:03:51 +03:00
|
|
|
}
|
|
|
|
|
2019-02-28 04:44:52 +03:00
|
|
|
function supportedStyles(cs) {
|
|
|
|
let styles = {};
|
|
|
|
for (let property of SUPPORTED_PROPERTIES) {
|
|
|
|
styles[property] = cs.getPropertyValue(property);
|
|
|
|
}
|
|
|
|
return styles;
|
|
|
|
}
|
|
|
|
|
|
|
|
function supportedStylesEqual(styles, otherStyles) {
|
|
|
|
for (let property of SUPPORTED_PROPERTIES) {
|
|
|
|
if (styles[property] !== otherStyles[property]) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function uniqueStylesIndex(cs, uniqueStyles) {
|
|
|
|
let styles = supportedStyles(cs);
|
|
|
|
for (let i = uniqueStyles.length; i--; ) {
|
|
|
|
if (supportedStylesEqual(uniqueStyles[i], styles)) {
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
uniqueStyles.push(styles);
|
|
|
|
return uniqueStyles.length - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
function buildOptionListForChildren(node, uniqueStyles) {
|
2013-08-26 05:34:23 +04:00
|
|
|
let result = [];
|
2015-04-15 23:00:29 +03:00
|
|
|
|
2015-03-17 02:29:51 +03:00
|
|
|
for (let child of node.children) {
|
|
|
|
let tagName = child.tagName.toUpperCase();
|
2015-04-15 23:00:29 +03:00
|
|
|
|
2017-01-17 18:48:17 +03:00
|
|
|
if (tagName == "OPTION" || tagName == "OPTGROUP") {
|
2016-01-27 02:12:17 +03:00
|
|
|
if (child.hidden) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2014-11-05 10:21:05 +03:00
|
|
|
let textContent =
|
2017-01-17 18:48:17 +03:00
|
|
|
tagName == "OPTGROUP" ? child.getAttribute("label")
|
2015-08-21 20:30:04 +03:00
|
|
|
: child.text;
|
|
|
|
if (textContent == null) {
|
|
|
|
textContent = "";
|
2014-11-05 10:21:05 +03:00
|
|
|
}
|
|
|
|
|
2016-10-21 22:55:25 +03:00
|
|
|
let cs = getComputedStyles(child);
|
2013-08-26 05:34:23 +04:00
|
|
|
let info = {
|
2016-03-18 20:38:40 +03:00
|
|
|
index: child.index,
|
2016-12-30 02:34:54 +03:00
|
|
|
tagName,
|
|
|
|
textContent,
|
2015-06-05 15:33:29 +03:00
|
|
|
disabled: child.disabled,
|
2016-10-21 22:55:25 +03:00
|
|
|
display: cs.display,
|
2015-07-14 05:14:31 +03:00
|
|
|
tooltip: child.title,
|
2019-02-28 04:44:52 +03:00
|
|
|
children: tagName == "OPTGROUP"
|
|
|
|
? buildOptionListForChildren(child, uniqueStyles)
|
|
|
|
: [],
|
|
|
|
// Most options have the same style. In order to reduce the size of the
|
|
|
|
// IPC message, coalesce them in uniqueStyles.
|
|
|
|
styleIndex: uniqueStylesIndex(cs, uniqueStyles),
|
2013-08-26 05:34:23 +04:00
|
|
|
};
|
2017-01-31 01:35:14 +03:00
|
|
|
|
2013-08-26 05:34:23 +04:00
|
|
|
result.push(info);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
2018-07-30 07:59:16 +03:00
|
|
|
|
2019-06-13 20:29:19 +03:00
|
|
|
class SelectChild extends ActorChild {
|
2018-07-30 07:59:16 +03:00
|
|
|
handleEvent(event) {
|
|
|
|
if (SelectContentHelper.open) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (event.type) {
|
2019-06-13 20:29:19 +03:00
|
|
|
case "mozshowdropdown":
|
|
|
|
new SelectContentHelper(event.target, {isOpenedViaTouch: false}, this.mm);
|
|
|
|
break;
|
2018-07-30 07:59:16 +03:00
|
|
|
|
2019-06-13 20:29:19 +03:00
|
|
|
case "mozshowdropdown-sourcetouch":
|
|
|
|
new SelectContentHelper(event.target, {isOpenedViaTouch: true}, this.mm);
|
|
|
|
break;
|
2018-07-30 07:59:16 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|