/* 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 Cc = Components.classes; const Ci = Components.interfaces; const Cu = Components.utils; Cu.import("resource://gre/modules/XPCOMUtils.jsm"); XPCOMUtils.defineLazyModuleGetter(this, "BrowserUtils", "resource://gre/modules/BrowserUtils.jsm"); XPCOMUtils.defineLazyServiceGetter(this, "DOMUtils", "@mozilla.org/inspector/dom-utils;1", "inIDOMUtils"); XPCOMUtils.defineLazyModuleGetter(this, "DeferredTask", "resource://gre/modules/DeferredTask.jsm"); const kStateActive = 0x00000001; // NS_EVENT_STATE_ACTIVE const kStateHover = 0x00000004; // NS_EVENT_STATE_HOVER // 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.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; let rect = this._getBoundingContentRect(); DOMUtils.addPseudoClassLock(this.element, ":focus"); let computedStyles = getComputedStyles(this.element); this._selectBackgroundColor = computedStyles.backgroundColor; this._selectColor = computedStyles.color; DOMUtils.clearPseudoClassLocks(this.element); this.global.sendAsyncMessage("Forms:ShowDropDown", { direction: computedStyles.direction, isOpenedViaTouch: this.isOpenedViaTouch, options: this._buildOptionList(), rect, selectedIndex: this.element.selectedIndex, selectBackgroundColor: this._selectBackgroundColor, selectColor: this._selectColor, uaBackgroundColor: this.uaBackgroundColor, uaColor: this.uaColor, uaSelectBackgroundColor: this.uaSelectBackgroundColor, uaSelectColor: this.uaSelectColor }); gOpen = true; }, _getBoundingContentRect() { return BrowserUtils.getElementBoundingScreenRect(this.element); }, _buildOptionList() { DOMUtils.addPseudoClassLock(this.element, ":focus"); let result = buildOptionListForChildren(this.element); DOMUtils.clearPseudoClassLocks(this.element); return result; }, _update() { // The