browser/modules/Windows8WindowFrameColor.jsm

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

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 "use strict";
michael@0 6 const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
michael@0 7
michael@0 8 this.EXPORTED_SYMBOLS = ["Windows8WindowFrameColor"];
michael@0 9
michael@0 10 Cu.import("resource://gre/modules/Services.jsm");
michael@0 11 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
michael@0 12 let Registry = Cu.import("resource://gre/modules/WindowsRegistry.jsm").WindowsRegistry;
michael@0 13
michael@0 14 const Windows8WindowFrameColor = {
michael@0 15 _windowFrameColor: null,
michael@0 16
michael@0 17 get: function() {
michael@0 18 if (this._windowFrameColor)
michael@0 19 return this._windowFrameColor;
michael@0 20
michael@0 21 const HKCU = Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER;
michael@0 22 const dwmKey = "Software\\Microsoft\\Windows\\DWM";
michael@0 23 let customizationColor = Registry.readRegKey(HKCU, dwmKey,
michael@0 24 "ColorizationColor");
michael@0 25 // The color returned from the Registry is in decimal form.
michael@0 26 let customizationColorHex = customizationColor.toString(16);
michael@0 27 // Zero-pad the number just to make sure that it is 8 digits.
michael@0 28 customizationColorHex = ("00000000" + customizationColorHex).substr(-8);
michael@0 29 let customizationColorArray = customizationColorHex.match(/../g);
michael@0 30 let [unused, fgR, fgG, fgB] = customizationColorArray.map(function(val) parseInt(val, 16));
michael@0 31 let colorizationColorBalance = Registry.readRegKey(HKCU, dwmKey,
michael@0 32 "ColorizationColorBalance");
michael@0 33 // Window frame base color when Color Intensity is at 0, see bug 1004576.
michael@0 34 let frameBaseColor = 217;
michael@0 35 let alpha = colorizationColorBalance / 100;
michael@0 36
michael@0 37 // Alpha-blend the foreground color with the frame base color.
michael@0 38 let r = Math.round(fgR * alpha + frameBaseColor * (1 - alpha));
michael@0 39 let g = Math.round(fgG * alpha + frameBaseColor * (1 - alpha));
michael@0 40 let b = Math.round(fgB * alpha + frameBaseColor * (1 - alpha));
michael@0 41 return this._windowFrameColor = [r, g, b];
michael@0 42 },
michael@0 43 };

mercurial