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/. */
6 const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
8 this.EXPORTED_SYMBOLS = ["Windows8WindowFrameColor"];
10 Cu.import("resource://gre/modules/Services.jsm");
11 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
12 let Registry = Cu.import("resource://gre/modules/WindowsRegistry.jsm").WindowsRegistry;
14 const Windows8WindowFrameColor = {
15 _windowFrameColor: null,
18 if (this._windowFrameColor)
19 return this._windowFrameColor;
21 const HKCU = Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER;
22 const dwmKey = "Software\\Microsoft\\Windows\\DWM";
23 let customizationColor = Registry.readRegKey(HKCU, dwmKey,
25 if (!customizationColor) {
26 // Seems to be the default color (hardcoded because of bug 1065998)
27 return [158, 158, 158];
29 // The color returned from the Registry is in decimal form.
30 let customizationColorHex = customizationColor.toString(16);
31 // Zero-pad the number just to make sure that it is 8 digits.
32 customizationColorHex = ("00000000" + customizationColorHex).substr(-8);
33 let customizationColorArray = customizationColorHex.match(/../g);
34 let [unused, fgR, fgG, fgB] = customizationColorArray.map(function(val) parseInt(val, 16));
35 let colorizationColorBalance = Registry.readRegKey(HKCU, dwmKey,
36 "ColorizationColorBalance") || 78;
37 // Window frame base color when Color Intensity is at 0, see bug 1004576.
38 let frameBaseColor = 217;
39 let alpha = colorizationColorBalance / 100;
41 // Alpha-blend the foreground color with the frame base color.
42 let r = Math.round(fgR * alpha + frameBaseColor * (1 - alpha));
43 let g = Math.round(fgG * alpha + frameBaseColor * (1 - alpha));
44 let b = Math.round(fgB * alpha + frameBaseColor * (1 - alpha));
45 return this._windowFrameColor = [r, g, b];