mobile/android/components/ColorPicker.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     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/. */
     5 const Ci = Components.interfaces;
     6 const Cu = Components.utils;
     7 const Cc = Components.classes;
     9 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
    10 Cu.import("resource://gre/modules/Services.jsm");
    11 Cu.import("resource://gre/modules/Prompt.jsm");
    13 function ColorPicker() {
    14 }
    16 ColorPicker.prototype = {
    17   _initial: 0,
    18   _domWin: null,
    19   _title: "",
    21   get strings() {
    22     delete this.strings;
    23     return this.strings = Services.strings.createBundle("chrome://browser/locale/browser.properties");
    24   },
    26   init: function(aParent, aTitle, aInitial) {
    27     this._domWin = aParent;
    28     this._initial = aInitial;
    29     this._title = aTitle;
    30   },
    32   open: function(aCallback) {
    33     let p = new Prompt({ title: this._title,
    34                          buttons: [
    35                             this.strings.GetStringFromName("inputWidgetHelper.set"),
    36                             this.strings.GetStringFromName("inputWidgetHelper.cancel")
    37                          ] })
    38                       .addColorPicker({ value: this._initial })
    39                       .show((data) => {
    40       if (data.button == 0)
    41         aCallback.done(data.color0);
    42       else
    43         aCallback.done(this._initial);
    44     });
    45   },
    47   classID: Components.ID("{430b987f-bb9f-46a3-99a5-241749220b29}"),
    48   QueryInterface: XPCOMUtils.generateQI([Ci.nsIColorPicker])
    49 };
    51 this.NSGetFactory = XPCOMUtils.generateNSGetFactory([ColorPicker]);

mercurial