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";
|
|
|
|
|
|
|
|
const Cc = Components.classes;
|
|
|
|
const Ci = Components.interfaces;
|
|
|
|
const Cu = Components.utils;
|
|
|
|
|
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
|
|
|
|
2014-03-01 05:00:17 +04:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "BrowserUtils",
|
|
|
|
"resource://gre/modules/BrowserUtils.jsm");
|
2016-03-30 12:54:31 +03:00
|
|
|
XPCOMUtils.defineLazyServiceGetter(this, "DOMUtils",
|
|
|
|
"@mozilla.org/inspector/dom-utils;1", "inIDOMUtils");
|
2016-04-16 05:00:36 +03:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "DeferredTask",
|
|
|
|
"resource://gre/modules/DeferredTask.jsm");
|
2016-03-30 12:54:31 +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
|
|
|
|
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;
|
|
|
|
|
2013-08-26 05:34:23 +04:00
|
|
|
this.EXPORTED_SYMBOLS = [
|
|
|
|
"SelectContentHelper"
|
|
|
|
];
|
|
|
|
|
2016-11-12 02:22:34 +03:00
|
|
|
this.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;
|
2013-08-26 05:34:23 +04:00
|
|
|
this.global = aGlobal;
|
2016-08-03 14:45:45 +03:00
|
|
|
this.closedWithEnter = false;
|
2016-10-20 19:45:39 +03:00
|
|
|
this.isOpenedViaTouch = aOptions.isOpenedViaTouch;
|
2017-02-04 08:33:13 +03:00
|
|
|
this._selectBackgroundColor = null;
|
|
|
|
this._selectColor = null;
|
2017-01-31 23:58:27 +03:00
|
|
|
this._uaBackgroundColor = null;
|
|
|
|
this._uaColor = null;
|
2017-02-04 08:33:13 +03:00
|
|
|
this._uaSelectBackgroundColor = null;
|
|
|
|
this._uaSelectColor = null;
|
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);
|
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() {
|
2013-08-26 05:34:23 +04:00
|
|
|
this.global.addMessageListener("Forms:SelectDropDownItem", this);
|
|
|
|
this.global.addMessageListener("Forms:DismissedDropDown", this);
|
2016-03-30 12:54:31 +03:00
|
|
|
this.global.addMessageListener("Forms:MouseOver", this);
|
|
|
|
this.global.addMessageListener("Forms:MouseOut", this);
|
2016-11-17 17:56:43 +03:00
|
|
|
this.global.addMessageListener("Forms:MouseUp", this);
|
2017-04-26 03:19:42 +03:00
|
|
|
this.global.addMessageListener("Forms:SearchFocused", this);
|
|
|
|
this.global.addMessageListener("Forms:BlurDropDown-Pong", this);
|
2017-02-09 19:28:22 +03:00
|
|
|
this.global.addEventListener("pagehide", this, { mozSystemGroup: true });
|
|
|
|
this.global.addEventListener("mozhidedropdown", this, { mozSystemGroup: true });
|
|
|
|
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;
|
2013-08-26 05:34:23 +04:00
|
|
|
this.global.removeMessageListener("Forms:SelectDropDownItem", this);
|
|
|
|
this.global.removeMessageListener("Forms:DismissedDropDown", this);
|
2016-03-30 12:54:31 +03:00
|
|
|
this.global.removeMessageListener("Forms:MouseOver", this);
|
|
|
|
this.global.removeMessageListener("Forms:MouseOut", this);
|
2016-11-17 17:56:43 +03:00
|
|
|
this.global.removeMessageListener("Forms:MouseUp", this);
|
2017-04-26 03:19:42 +03:00
|
|
|
this.global.removeMessageListener("Forms:SearchFocused", this);
|
|
|
|
this.global.removeMessageListener("Forms:BlurDropDown-Pong", this);
|
2017-02-09 19:28:22 +03:00
|
|
|
this.global.removeEventListener("pagehide", this, { mozSystemGroup: true });
|
|
|
|
this.global.removeEventListener("mozhidedropdown", this, { mozSystemGroup: true });
|
|
|
|
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;
|
|
|
|
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);
|
|
|
|
this._selectBackgroundColor = computedStyles.backgroundColor;
|
|
|
|
this._selectColor = computedStyles.color;
|
2017-04-10 23:03:03 +03:00
|
|
|
this._selectTextShadow = computedStyles.textShadow;
|
2013-08-26 05:34:23 +04:00
|
|
|
this.global.sendAsyncMessage("Forms:ShowDropDown", {
|
2017-02-04 08:33:13 +03:00
|
|
|
direction: computedStyles.direction,
|
|
|
|
isOpenedViaTouch: this.isOpenedViaTouch,
|
2013-08-26 05:34:23 +04:00
|
|
|
options: this._buildOptionList(),
|
2017-02-04 08:33:13 +03:00
|
|
|
rect,
|
2015-07-14 05:03:51 +03:00
|
|
|
selectedIndex: this.element.selectedIndex,
|
2017-02-04 08:33:13 +03:00
|
|
|
selectBackgroundColor: this._selectBackgroundColor,
|
|
|
|
selectColor: this._selectColor,
|
2017-04-10 23:03:03 +03:00
|
|
|
selectTextShadow: this._selectTextShadow,
|
2017-01-31 23:58:27 +03:00
|
|
|
uaBackgroundColor: this.uaBackgroundColor,
|
|
|
|
uaColor: this.uaColor,
|
2017-02-04 08:33:13 +03:00
|
|
|
uaSelectBackgroundColor: this.uaSelectBackgroundColor,
|
|
|
|
uaSelectColor: this.uaSelectColor
|
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;
|
|
|
|
DOMUtils.addPseudoClassLock(this.element, ":focus");
|
|
|
|
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.
|
|
|
|
DOMUtils.addPseudoClassLock(child, ":checked", false);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_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.
|
|
|
|
DOMUtils.clearPseudoClassLocks(this.element);
|
|
|
|
let lockedDescendants = this._lockedDescendants;
|
|
|
|
for (let child of lockedDescendants) {
|
|
|
|
DOMUtils.clearPseudoClassLocks(child);
|
|
|
|
}
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
return buildOptionListForChildren(this.element);
|
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);
|
|
|
|
this._selectBackgroundColor = computedStyles.backgroundColor;
|
|
|
|
this._selectColor = computedStyles.color;
|
2017-04-10 23:03:03 +03:00
|
|
|
this._selectTextShadow = computedStyles.textShadow;
|
2016-04-16 05:00:36 +03:00
|
|
|
this.global.sendAsyncMessage("Forms:UpdateDropDown", {
|
|
|
|
options: this._buildOptionList(),
|
|
|
|
selectedIndex: this.element.selectedIndex,
|
2017-02-04 08:33:13 +03:00
|
|
|
selectBackgroundColor: this._selectBackgroundColor,
|
|
|
|
selectColor: this._selectColor,
|
2017-04-10 23:03:03 +03:00
|
|
|
selectTextShadow: this._selectTextShadow,
|
2017-01-31 23:58:27 +03:00
|
|
|
uaBackgroundColor: this.uaBackgroundColor,
|
|
|
|
uaColor: this.uaColor,
|
2017-02-04 08:33:13 +03:00
|
|
|
uaSelectBackgroundColor: this.uaSelectBackgroundColor,
|
|
|
|
uaSelectColor: this.uaSelectColor
|
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-31 23:58:27 +03:00
|
|
|
// Determine user agent background-color and color.
|
|
|
|
// This is used to skip applying the custom color if it matches
|
|
|
|
// the user agent values.
|
|
|
|
_calculateUAColors() {
|
2017-02-04 08:33:13 +03:00
|
|
|
let dummyOption = this.element.ownerDocument.createElement("option");
|
2017-03-13 22:01:25 +03:00
|
|
|
dummyOption.style.setProperty("color", "-moz-comboboxtext", "important");
|
2017-03-21 17:51:40 +03:00
|
|
|
dummyOption.style.setProperty("background-color", "-moz-combobox", "important");
|
2017-02-04 08:33:13 +03:00
|
|
|
let optionCS = this.element.ownerGlobal.getComputedStyle(dummyOption);
|
|
|
|
this._uaBackgroundColor = optionCS.backgroundColor;
|
|
|
|
this._uaColor = optionCS.color;
|
|
|
|
let dummySelect = this.element.ownerDocument.createElement("select");
|
2017-03-13 22:01:25 +03:00
|
|
|
dummySelect.style.setProperty("color", "-moz-fieldtext", "important");
|
2017-03-21 17:51:40 +03:00
|
|
|
dummySelect.style.setProperty("background-color", "-moz-field", "important");
|
2017-02-04 08:33:13 +03:00
|
|
|
let selectCS = this.element.ownerGlobal.getComputedStyle(dummySelect);
|
|
|
|
this._uaSelectBackgroundColor = selectCS.backgroundColor;
|
|
|
|
this._uaSelectColor = selectCS.color;
|
2017-01-31 23:58:27 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
get uaBackgroundColor() {
|
|
|
|
if (!this._uaBackgroundColor) {
|
|
|
|
this._calculateUAColors();
|
|
|
|
}
|
|
|
|
return this._uaBackgroundColor;
|
|
|
|
},
|
|
|
|
|
|
|
|
get uaColor() {
|
|
|
|
if (!this._uaColor) {
|
|
|
|
this._calculateUAColors();
|
|
|
|
}
|
|
|
|
return this._uaColor;
|
|
|
|
},
|
|
|
|
|
2017-02-04 08:33:13 +03:00
|
|
|
get uaSelectBackgroundColor() {
|
|
|
|
if (!this._selectBackgroundColor) {
|
|
|
|
this._calculateUAColors();
|
|
|
|
}
|
|
|
|
return this._uaSelectBackgroundColor;
|
|
|
|
},
|
|
|
|
|
|
|
|
get uaSelectColor() {
|
|
|
|
if (!this._selectBackgroundColor) {
|
|
|
|
this._calculateUAColors();
|
|
|
|
}
|
|
|
|
return this._uaSelectColor;
|
|
|
|
},
|
|
|
|
|
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;
|
2016-08-03 14:45:45 +03:00
|
|
|
this.closedWithEnter = message.data.closedWithEnter;
|
2015-06-26 19:32:25 +03:00
|
|
|
break;
|
2013-12-11 01:46:21 +04:00
|
|
|
|
2015-06-26 19:32:25 +03:00
|
|
|
case "Forms:DismissedDropDown":
|
2016-08-03 14:45:45 +03:00
|
|
|
let selectedOption = this.element.item(this.element.selectedIndex);
|
2017-06-14 08:42:03 +03:00
|
|
|
if (this.initialSelection === selectedOption) {
|
|
|
|
// Clear active document
|
|
|
|
DOMUtils.removeContentState(this.element,
|
|
|
|
kStateActive,
|
|
|
|
/* aClearActiveDocument */ true);
|
|
|
|
} else {
|
2017-01-27 12:51:03 +03:00
|
|
|
let win = this.element.ownerGlobal;
|
2016-08-02 22:09:59 +03:00
|
|
|
// For ordering of events, we're using non-e10s as our guide here,
|
|
|
|
// since the spec isn't exactly clear. In non-e10s, we fire:
|
|
|
|
// mousedown, mouseup, input, change, click if the user clicks
|
|
|
|
// on an element in the dropdown. If the user uses the keyboard
|
|
|
|
// to select an element in the dropdown, we only fire input and
|
|
|
|
// change events.
|
|
|
|
if (!this.closedWithEnter) {
|
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-06-14 08:42:03 +03:00
|
|
|
// Clear active document no matter user selects
|
|
|
|
// via keyboard or mouse
|
|
|
|
DOMUtils.removeContentState(this.element,
|
|
|
|
kStateActive,
|
|
|
|
/* aClearActiveDocument */ true);
|
2016-08-02 22:09:59 +03:00
|
|
|
|
2016-05-13 17:40:24 +03:00
|
|
|
let inputEvent = new win.UIEvent("input", {
|
|
|
|
bubbles: true,
|
|
|
|
});
|
|
|
|
this.element.dispatchEvent(inputEvent);
|
|
|
|
|
|
|
|
let changeEvent = new win.Event("change", {
|
|
|
|
bubbles: true,
|
|
|
|
});
|
|
|
|
this.element.dispatchEvent(changeEvent);
|
|
|
|
|
2016-08-03 14:45:45 +03:00
|
|
|
if (!this.closedWithEnter) {
|
2017-01-19 18:03:56 +03:00
|
|
|
this.dispatchMouseEvent(win, selectedOption, "click");
|
2016-05-25 20:21:23 +03:00
|
|
|
}
|
2013-12-11 01:46:21 +04:00
|
|
|
}
|
2013-08-26 05:34:23 +04:00
|
|
|
|
|
|
|
this.uninit();
|
|
|
|
break;
|
2016-03-30 12:54:31 +03:00
|
|
|
|
|
|
|
case "Forms:MouseOver":
|
|
|
|
DOMUtils.setContentState(this.element, kStateHover);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "Forms:MouseOut":
|
|
|
|
DOMUtils.removeContentState(this.element, kStateHover);
|
|
|
|
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");
|
|
|
|
}
|
2016-11-17 17:56:43 +03:00
|
|
|
DOMUtils.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;
|
|
|
|
}
|
|
|
|
this.global.sendAsyncMessage("Forms:HideDropDown", {});
|
|
|
|
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) {
|
|
|
|
this.global.sendAsyncMessage("Forms:HideDropDown", {});
|
|
|
|
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.
|
|
|
|
this.global.sendAsyncMessage("Forms:BlurDropDown-Ping", {});
|
|
|
|
break;
|
|
|
|
}
|
2016-04-13 20:15:55 +03:00
|
|
|
case "mozhidedropdown":
|
|
|
|
if (this.element === event.target) {
|
|
|
|
this.global.sendAsyncMessage("Forms:HideDropDown", {});
|
|
|
|
this.uninit();
|
|
|
|
}
|
|
|
|
break;
|
2017-04-04 05:52:16 +03:00
|
|
|
case "transitionend":
|
|
|
|
this._update();
|
|
|
|
break;
|
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
|
|
|
}
|
|
|
|
|
2013-08-26 05:34:23 +04:00
|
|
|
function buildOptionListForChildren(node) {
|
|
|
|
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-04-15 23:00:29 +03:00
|
|
|
// We need to do this for every option element as each one can have
|
|
|
|
// an individual style set for direction
|
2016-10-21 22:55:25 +03:00
|
|
|
textDirection: cs.direction,
|
2015-07-14 05:14:31 +03:00
|
|
|
tooltip: child.title,
|
2017-01-31 01:35:14 +03:00
|
|
|
backgroundColor: cs.backgroundColor,
|
|
|
|
color: cs.color,
|
2017-01-17 18:48:17 +03:00
|
|
|
children: tagName == "OPTGROUP" ? buildOptionListForChildren(child) : []
|
2013-08-26 05:34:23 +04:00
|
|
|
};
|
2017-01-31 01:35:14 +03:00
|
|
|
|
2017-04-10 23:03:03 +03:00
|
|
|
if (cs.textShadow != "none") {
|
|
|
|
info.textShadow = cs.textShadow;
|
|
|
|
}
|
|
|
|
|
2013-08-26 05:34:23 +04:00
|
|
|
result.push(info);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|