зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1347182 - Add support for setting the background color of all toolbars using a WebExtension theme. r=jaws
Original patch by :mikedeboer. MozReview-Commit-ID: IbTBCjt6oJp --HG-- extra : rebase_source : 09752d1deded2f8189fd2abedcd0f65bd2625ed3
This commit is contained in:
Родитель
ca4b09e233
Коммит
c1a9f6ec56
|
@ -62,6 +62,9 @@ class Theme {
|
||||||
Services.obs.notifyObservers(null,
|
Services.obs.notifyObservers(null,
|
||||||
"lightweight-theme-styling-update",
|
"lightweight-theme-styling-update",
|
||||||
JSON.stringify(this.lwtStyles));
|
JSON.stringify(this.lwtStyles));
|
||||||
|
} else {
|
||||||
|
this.logger.warn("Your theme doesn't include one of the following required " +
|
||||||
|
"properties: 'headerURL', 'accentcolor' or 'textcolor'");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,6 +95,9 @@ class Theme {
|
||||||
case "tab_text":
|
case "tab_text":
|
||||||
this.lwtStyles.textcolor = cssColor;
|
this.lwtStyles.textcolor = cssColor;
|
||||||
break;
|
break;
|
||||||
|
case "toolbar":
|
||||||
|
this.lwtStyles.toolbarColor = cssColor;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,6 +64,10 @@
|
||||||
"textcolor": {
|
"textcolor": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"optional": true
|
"optional": true
|
||||||
|
},
|
||||||
|
"toolbar": {
|
||||||
|
"type": "string",
|
||||||
|
"optional": true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"additionalProperties": { "$ref": "UnrecognizedProperty" }
|
"additionalProperties": { "$ref": "UnrecognizedProperty" }
|
||||||
|
|
|
@ -2,9 +2,10 @@
|
||||||
support-files =
|
support-files =
|
||||||
head.js
|
head.js
|
||||||
|
|
||||||
|
[browser_ext_management_themes.js]
|
||||||
[browser_ext_themes_chromeparity.js]
|
[browser_ext_themes_chromeparity.js]
|
||||||
[browser_ext_themes_dynamic_updates.js]
|
[browser_ext_themes_dynamic_updates.js]
|
||||||
[browser_ext_themes_lwtsupport.js]
|
[browser_ext_themes_lwtsupport.js]
|
||||||
[browser_ext_themes_multiple_backgrounds.js]
|
[browser_ext_themes_multiple_backgrounds.js]
|
||||||
[browser_ext_themes_persistence.js]
|
[browser_ext_themes_persistence.js]
|
||||||
[browser_ext_management_themes.js]
|
[browser_ext_themes_toolbars.js]
|
||||||
|
|
|
@ -0,0 +1,48 @@
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
// This test checks whether applied WebExtension themes that attempt to change
|
||||||
|
// the background color of toolbars are applied properly.
|
||||||
|
|
||||||
|
add_task(async function setup() {
|
||||||
|
await SpecialPowers.pushPrefEnv({
|
||||||
|
set: [["extensions.webextensions.themes.enabled", true]],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
add_task(async function test_support_toolbar_property() {
|
||||||
|
const TOOLBAR_COLOR = "#ff00ff";
|
||||||
|
let extension = ExtensionTestUtils.loadExtension({
|
||||||
|
manifest: {
|
||||||
|
"theme": {
|
||||||
|
"images": {
|
||||||
|
"headerURL": "image1.png",
|
||||||
|
},
|
||||||
|
"colors": {
|
||||||
|
"accentcolor": ACCENT_COLOR,
|
||||||
|
"textcolor": TEXT_COLOR,
|
||||||
|
"toolbar": TOOLBAR_COLOR,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
files: {
|
||||||
|
"image1.png": BACKGROUND,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
await extension.startup();
|
||||||
|
|
||||||
|
let toolbox = document.querySelector("#navigator-toolbox");
|
||||||
|
let toolbars = [...toolbox.querySelectorAll("toolbar:not(#TabsToolbar)")].filter(toolbar => {
|
||||||
|
let bounds = toolbar.getBoundingClientRect();
|
||||||
|
return bounds.width > 0 && bounds.height > 0;
|
||||||
|
});
|
||||||
|
|
||||||
|
info(`Checking toolbar background colors for ${toolbars.length} toolbars.`);
|
||||||
|
for (let toolbar of toolbars) {
|
||||||
|
info(`Testing ${toolbar.id}`);
|
||||||
|
Assert.equal(window.getComputedStyle(toolbar).backgroundColor,
|
||||||
|
"rgb(" + hexToRGB(TOOLBAR_COLOR).join(", ") + ")", "Toolbar color should be set.");
|
||||||
|
}
|
||||||
|
|
||||||
|
await extension.unload();
|
||||||
|
});
|
|
@ -13,6 +13,12 @@ Cu.import("resource://gre/modules/AppConstants.jsm");
|
||||||
XPCOMUtils.defineLazyModuleGetter(this, "LightweightThemeImageOptimizer",
|
XPCOMUtils.defineLazyModuleGetter(this, "LightweightThemeImageOptimizer",
|
||||||
"resource://gre/modules/addons/LightweightThemeImageOptimizer.jsm");
|
"resource://gre/modules/addons/LightweightThemeImageOptimizer.jsm");
|
||||||
|
|
||||||
|
const kCSSVarsMap = new Map([
|
||||||
|
["--lwt-background-alignment", "backgroundsAlignment"],
|
||||||
|
["--lwt-background-tiling", "backgroundsTiling"],
|
||||||
|
["--toolbar-bgcolor", "toolbarColor"]
|
||||||
|
]);
|
||||||
|
|
||||||
this.LightweightThemeConsumer =
|
this.LightweightThemeConsumer =
|
||||||
function LightweightThemeConsumer(aDocument) {
|
function LightweightThemeConsumer(aDocument) {
|
||||||
this._doc = aDocument;
|
this._doc = aDocument;
|
||||||
|
@ -135,8 +141,7 @@ LightweightThemeConsumer.prototype = {
|
||||||
_setImage(root, active, "--lwt-header-image", aData.headerURL);
|
_setImage(root, active, "--lwt-header-image", aData.headerURL);
|
||||||
_setImage(root, active, "--lwt-footer-image", aData.footerURL);
|
_setImage(root, active, "--lwt-footer-image", aData.footerURL);
|
||||||
_setImage(root, active, "--lwt-additional-images", aData.additionalBackgrounds);
|
_setImage(root, active, "--lwt-additional-images", aData.additionalBackgrounds);
|
||||||
_setProperty(root, active, "--lwt-background-alignment", aData.backgroundsAlignment);
|
_setProperties(root, active, aData);
|
||||||
_setProperty(root, active, "--lwt-background-tiling", aData.backgroundsTiling);
|
|
||||||
|
|
||||||
if (active && aData.footerURL)
|
if (active && aData.footerURL)
|
||||||
root.setAttribute("lwthemefooter", "true");
|
root.setAttribute("lwthemefooter", "true");
|
||||||
|
@ -184,6 +189,12 @@ function _setProperty(root, active, variableName, value) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function _setProperties(root, active, vars) {
|
||||||
|
for (let [cssVarName, varsKey] of kCSSVarsMap) {
|
||||||
|
_setProperty(root, active, cssVarName, vars[varsKey]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function _parseRGB(aColorString) {
|
function _parseRGB(aColorString) {
|
||||||
var rgb = aColorString.match(/^rgba?\((\d+), (\d+), (\d+)/);
|
var rgb = aColorString.match(/^rgba?\((\d+), (\d+), (\d+)/);
|
||||||
rgb.shift();
|
rgb.shift();
|
||||||
|
|
Загрузка…
Ссылка в новой задаче