Bug 1235845 - add the pocket stylesheet to browser windows instead of using the stylesheet service, r=mixedpuppy

--HG--
extra : commitid : DjpsZC9VWBa
extra : rebase_source : 87356b25a5acb338b239a0f5586614f3a2130563
This commit is contained in:
Gijs Kruitbosch 2015-12-31 13:04:08 +00:00
parent f55c95eaa4
commit db544f5e5b
4 changed files with 21 additions and 19 deletions

View File

@ -286,7 +286,6 @@ function pktUIGetter(prop, window) {
var PocketOverlay = {
startup: function(reason) {
this.registerStylesheet();
CreatePocketWidget(reason);
Services.obs.addObserver(this,
"browser-delayed-startup-finished",
@ -298,6 +297,7 @@ var PocketOverlay = {
if (reason == ADDON_ENABLE) {
for (let win of allBrowserWindows()) {
this.setWindowScripts(win);
this.addStyles(win);
this.updateWindow(win);
}
}
@ -312,6 +312,7 @@ var PocketOverlay = {
if (element)
element.remove();
}
this.removeStyles(window);
// remove script getters/objects
delete window.Pocket;
delete window.pktUI;
@ -320,12 +321,12 @@ var PocketOverlay = {
CustomizableUI.destroyWidget("pocket-button");
PocketContextMenu.shutdown();
PocketReader.shutdown();
this.unregisterStylesheet();
},
observe: function(aSubject, aTopic, aData) {
// new browser window, initialize the "overlay"
let window = aSubject;
this.setWindowScripts(window);
this.addStyles(window);
this.updateWindow(window);
},
setWindowScripts: function(window) {
@ -433,25 +434,21 @@ var PocketOverlay = {
}
},
registerStylesheet: function() {
let styleSheetService= Components.classes["@mozilla.org/content/style-sheet-service;1"]
.getService(Components.interfaces.nsIStyleSheetService);
let styleSheetURI = Services.io.newURI("chrome://pocket/skin/pocket.css", null, null);
styleSheetService.loadAndRegisterSheet(styleSheetURI, styleSheetService.AUTHOR_SHEET);
styleSheetURI = Services.io.newURI("chrome://pocket-shared/skin/pocket.css", null, null);
styleSheetService.loadAndRegisterSheet(styleSheetURI, styleSheetService.AUTHOR_SHEET);
addStyles: function(win) {
let xmlPI = win.document.createProcessingInstruction("xml-stylesheet",
"type=\"text/css\" href=\"chrome://pocket/skin/pocket.css\"");
win.document.insertBefore(xmlPI, win.document.documentElement);
},
unregisterStylesheet: function() {
let styleSheetService = Components.classes["@mozilla.org/content/style-sheet-service;1"]
.getService(Components.interfaces.nsIStyleSheetService);
let styleSheetURI = Services.io.newURI("chrome://pocket/skin/pocket.css", null, null);
if (styleSheetService.sheetRegistered(styleSheetURI, styleSheetService.AUTHOR_SHEET)) {
styleSheetService.unregisterSheet(styleSheetURI, styleSheetService.AUTHOR_SHEET);
}
styleSheetURI = Services.io.newURI("chrome://pocket-shared/skin/pocket.css", null, null);
if (styleSheetService.sheetRegistered(styleSheetURI, styleSheetService.AUTHOR_SHEET)) {
styleSheetService.unregisterSheet(styleSheetURI, styleSheetService.AUTHOR_SHEET);
removeStyles: function(win) {
let el = win.document.documentElement.previousSibling;
while (el) {
if (el.nodeType == el.PROCESSING_INSTRUCTION_NODE &&
el.sheet && el.sheet.href == "chrome://pocket/skin/pocket.css") {
el.remove();
break;
}
el = el.previousSibling;
}
}

View File

@ -0,0 +1 @@
@import url("chrome://pocket-shared/skin/pocket.css");

View File

@ -1,3 +1,5 @@
@import url("chrome://pocket-shared/skin/pocket.css");
#pocket-button[cui-areatype="toolbar"][open] {
-moz-image-region: rect(36px, 774px, 54px, 756px);
}

View File

@ -1,3 +1,5 @@
@import url("chrome://pocket-shared/skin/pocket.css");
@media (min-resolution: 1.1dppx) {
#pocket-button[cui-areatype="toolbar"] {
-moz-image-region: rect(0, 1548px, 36px, 1512px);