tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

ColorPickerDelegate.sys.mjs (1442B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 import { GeckoViewUtils } from "resource://gre/modules/GeckoViewUtils.sys.mjs";
      6 
      7 const lazy = {};
      8 
      9 ChromeUtils.defineESModuleGetters(lazy, {
     10  GeckoViewPrompter: "resource://gre/modules/GeckoViewPrompter.sys.mjs",
     11 });
     12 
     13 const { debug, warn } = GeckoViewUtils.initLogging("ColorPickerDelegate");
     14 
     15 export class ColorPickerDelegate {
     16  // TODO(bug 1805397): Implement default colors
     17  init(aBrowsingContext, aTitle, aInitialColor, aDefaultColors) {
     18    this._browsingContext = aBrowsingContext;
     19    this._prompt = new lazy.GeckoViewPrompter(aBrowsingContext);
     20    this._msg = {
     21      type: "color",
     22      title: aTitle,
     23      value: aInitialColor,
     24      predefinedValues: aDefaultColors,
     25    };
     26  }
     27 
     28  open(aColorPickerShownCallback) {
     29    if (!this._browsingContext.canOpenModalPicker) {
     30      // Color pickers are not allowed to open, so we respond to the callback
     31      // with returnCancel.
     32      aColorPickerShownCallback.done("");
     33      return;
     34    }
     35 
     36    this._prompt.asyncShowPrompt(this._msg, result => {
     37      // OK: result
     38      // Cancel: !result
     39      aColorPickerShownCallback.done((result && result.color) || "");
     40    });
     41  }
     42 }
     43 
     44 ColorPickerDelegate.prototype.QueryInterface = ChromeUtils.generateQI([
     45  "nsIColorPicker",
     46 ]);