/* vim: set ts=2 sw=2 sts=2 et 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"; var EXPORTED_SYMBOLS = ["SelectChild"]; const {ActorChild} = ChromeUtils.import("resource://gre/modules/ActorChild.jsm"); const {XPCOMUtils} = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm"); ChromeUtils.defineModuleGetter(this, "BrowserUtils", "resource://gre/modules/BrowserUtils.jsm"); ChromeUtils.defineModuleGetter(this, "DeferredTask", "resource://gre/modules/DeferredTask.jsm"); XPCOMUtils.defineLazyGlobalGetters(this, ["InspectorUtils"]); const kStateActive = 0x00000001; // NS_EVENT_STATE_ACTIVE const kStateHover = 0x00000004; // NS_EVENT_STATE_HOVER const SUPPORTED_PROPERTIES = [ "direction", "color", "background-color", "text-shadow", "font-family", "font-weight", "font-size", "font-style", ]; // A process global state for whether or not content thinks // that a while it was open, so // we'll poke a DeferredTask to update the parent sometime // in the very near future. this._updateTimer.arm(); }); this.mut.observe(this.element, {childList: true, subtree: true, attributes: true}); }, uninit() { this.element.openInParentProcess = false; 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 }); this.element.removeEventListener("blur", this, { mozSystemGroup: true }); this.element.removeEventListener("transitionend", this, { mozSystemGroup: true }); this.element = null; this.global = null; this.mut.disconnect(); this._updateTimer.disarm(); this._updateTimer = null; gOpen = false; }, showDropDown() { this.element.openInParentProcess = true; this._setupPseudoClassStyles(); let rect = this._getBoundingContentRect(); let computedStyles = getComputedStyles(this.element); let options = this._buildOptionList(); let defaultStyles = this.element.ownerGlobal.getDefaultComputedStyle(this.element); this.global.sendAsyncMessage("Forms:ShowDropDown", { isOpenedViaTouch: this.isOpenedViaTouch, options, rect, selectedIndex: this.element.selectedIndex, style: supportedStyles(computedStyles), defaultStyle: supportedStyles(defaultStyles), }); this._clearPseudoClassStyles(); gOpen = true; }, _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; InspectorUtils.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. InspectorUtils.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. InspectorUtils.clearPseudoClassLocks(this.element); let lockedDescendants = this._lockedDescendants; for (let child of lockedDescendants) { InspectorUtils.clearPseudoClassLocks(child); } this._lockedDescendants = null; this._pseudoStylesSetup = false; }, _getBoundingContentRect() { return BrowserUtils.getElementBoundingScreenRect(this.element); }, _buildOptionList() { if (!this._pseudoStylesSetup) { throw new Error("pseudo styles must be set up"); } let uniqueStyles = []; let options = buildOptionListForChildren(this.element, uniqueStyles); return { options, uniqueStyles }; }, _update() { // The