Files
sousa-gecko/toolkit/actors/ColorPickerChild.sys.mjs
T
Emilio Cobos Álvarez e833a1757b Bug 2033243 - Replace ownerGlobal with documentGlobal, and stop exposing ownerGlobal to JS. r=firefox-desktop-core-reviewers ,webidl,joschmidt,perftest-reviewers,sparky,smaug,mossop ,webidl,joschmidt,perftest-reviewers,sparky,smaug,mossop
Bug 2033191 made sure we only call ownerGlobal on nodes.

As per the discussion in dev-platform, the front-end ~always wants
.documentGlobal. This removes ownerGlobal from the bindings. Following
patch will rename internal GetOwnerGlobal in gecko to GetRelevantGlobal
as per the HTML spec terminology.

Differential Revision: https://phabricator.services.mozilla.com/D297183
2026-05-02 22:04:13 +00:00

60 lines
1.6 KiB
JavaScript

/* 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/. */
import { InputPickerChildCommon } from "./InputPickerChildCommon.sys.mjs";
export class ColorPickerChild extends InputPickerChildCommon {
initialValue = null;
constructor() {
super("ColorPicker");
}
/**
* Cleanup function called when picker is closed.
*
* @param {HTMLInputElement} inputElement
*/
closeImpl(inputElement) {
inputElement.setOpenState(false);
if (this.initialValue !== inputElement.value) {
inputElement.dispatchEvent(
new inputElement.documentGlobal.Event("change")
);
}
}
/**
* Element updater function called when the picker value is changed.
*
* @param {ReceiveMessageArgument} aMessage
* @param {HTMLInputElement} inputElement
*/
pickerValueChangedImpl(aMessage, inputElement) {
if (!aMessage.data) {
inputElement.setUserInput(this.initialValue);
return;
}
const { rgb } = aMessage.data;
inputElement.setUserInputColor({
component1: rgb[0],
component2: rgb[1],
component3: rgb[2],
alpha: rgb[3],
});
}
/**
* Picker initialization function called when opening the picker
*
* @param {HTMLInputElement} inputElement
* @returns An argument object to pass to the picker panel, or undefined to stop.
*/
openPickerImpl(inputElement) {
this.initialValue = inputElement.value;
return { value: inputElement.getColor() };
}
}