mobile/android/components/ColorPicker.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/mobile/android/components/ColorPicker.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,51 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +const Ci = Components.interfaces;
     1.9 +const Cu = Components.utils;
    1.10 +const Cc = Components.classes;
    1.11 +
    1.12 +Cu.import("resource://gre/modules/XPCOMUtils.jsm");
    1.13 +Cu.import("resource://gre/modules/Services.jsm");
    1.14 +Cu.import("resource://gre/modules/Prompt.jsm");
    1.15 +
    1.16 +function ColorPicker() {
    1.17 +}
    1.18 +
    1.19 +ColorPicker.prototype = {
    1.20 +  _initial: 0,
    1.21 +  _domWin: null,
    1.22 +  _title: "",
    1.23 +
    1.24 +  get strings() {
    1.25 +    delete this.strings;
    1.26 +    return this.strings = Services.strings.createBundle("chrome://browser/locale/browser.properties");
    1.27 +  },
    1.28 +
    1.29 +  init: function(aParent, aTitle, aInitial) {
    1.30 +    this._domWin = aParent;
    1.31 +    this._initial = aInitial;
    1.32 +    this._title = aTitle;
    1.33 +  },
    1.34 +
    1.35 +  open: function(aCallback) {
    1.36 +    let p = new Prompt({ title: this._title,
    1.37 +                         buttons: [
    1.38 +                            this.strings.GetStringFromName("inputWidgetHelper.set"),
    1.39 +                            this.strings.GetStringFromName("inputWidgetHelper.cancel")
    1.40 +                         ] })
    1.41 +                      .addColorPicker({ value: this._initial })
    1.42 +                      .show((data) => {
    1.43 +      if (data.button == 0)
    1.44 +        aCallback.done(data.color0);
    1.45 +      else
    1.46 +        aCallback.done(this._initial);
    1.47 +    });
    1.48 +  },
    1.49 +
    1.50 +  classID: Components.ID("{430b987f-bb9f-46a3-99a5-241749220b29}"),
    1.51 +  QueryInterface: XPCOMUtils.generateQI([Ci.nsIColorPicker])
    1.52 +};
    1.53 +
    1.54 +this.NSGetFactory = XPCOMUtils.generateNSGetFactory([ColorPicker]);

mercurial