Skip to content

Commit

Permalink
Issue #11 - Override tab panel background color
Browse files Browse the repository at this point in the history
This implements an internal color method for use with the browser window. This should hopefully get rid of the white flashes and follows the same method used in bug 1488384, which overrides the background color of the tab panel (anonymous content that is a *child of the `browser` element).
  • Loading branch information
fofajardo committed Jan 29, 2023
1 parent 897bbac commit 4bf20a4
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 6 deletions.
21 changes: 20 additions & 1 deletion src/content/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ var Swarth = {
gBrowser.addProgressListener(Swarth.pageHandler);
gBrowser.addEventListener("pageshow", Swarth.pageHandler.onPageShow, false);
Swarth.observer.register();
Swarth.scm.update(
{
window: window,
method: Swarth.scm.kMethodBrowserOverride,
isTopLevel: true
},
Swarth.prefs.getAll()
);
} else if (getPanelBrowser()) {
getPanelBrowser().addProgressListener(Swarth.pageHandler);
}
Expand Down Expand Up @@ -343,9 +351,20 @@ this.Swarth.observer = {
Swarth.adjustMethodMenuItems();
}

let invalidateSheets = (aData == "invalidate");
Swarth._updateDocShell(
null,
(aData == "invalidate")
invalidateSheets
);

Swarth.scm.update(
{
window: window,
method: Swarth.scm.kMethodBrowserOverride,
isTopLevel: true,
invalidate: invalidateSheets,
},
Swarth.prefs.getAll()
);

break;
Expand Down
22 changes: 17 additions & 5 deletions src/content/modules/ScopeManager.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ var updatedWindows = new WeakSet();

var ScopeManager = {
kConfigVersion: 1,
kMethodBrowserOverride: -2,
kMethodDefault: -1,
kMethodDisabled: 0,
kMethodCSSProcessor: 1,
Expand Down Expand Up @@ -126,6 +127,12 @@ var ScopeManager = {
let processorInstance = null;
let sheetURIs = [];
switch (aMethod) {
case this.kMethodBrowserOverride:
sheetURIs = [
ScopeManagerInternal.getStylesheet(
kSheetBrowserOverrideKey, aOptions, invalidateCache)
];
break;
case this.kMethodCSSProcessor:
aOptions.important_for_toplevel = (aWindow.top === aWindow.self) ? '!important' : '';
sheetURIs = [
Expand Down Expand Up @@ -227,7 +234,8 @@ var ScopeManager = {
}
if (aOptions.enabled && aOptions.color_enabled) {
var scopeEnabled = (aTarget.method != this.kMethodDisabled);
if (aTarget.method == this.kMethodColorInversion && !aTarget.isTopLevel) {
if (aTarget.method == this.kMethodColorInversion &&
!aTarget.isTopLevel) {
scopeEnabled = false;
}
if (scopeEnabled) {
Expand Down Expand Up @@ -302,10 +310,11 @@ XPCOMUtils.defineLazyModuleGetter(
"resource://gre/modules/NetUtil.jsm"
);

const kSheetBaseKey = "base";
const kSheetSimpleKey = "simple";
const kSheetInvertKey = "invert";
const kSheetProcessorKey = "processor";
const kSheetBaseKey = "base";
const kSheetSimpleKey = "simple";
const kSheetInvertKey = "invert";
const kSheetProcessorKey = "processor";
const kSheetBrowserOverrideKey = "browser-override";

const kBaseSheetURI = "chrome://swarth/content/stylesheets/";
const kCharset = "UTF-8";
Expand Down Expand Up @@ -461,6 +470,9 @@ var ScopeManagerInternal = {
case kSheetProcessorKey:
sheetURI = kBaseSheetURI + "stylesheet-processor.css";
break;
case kSheetBrowserOverrideKey:
sheetURI = kBaseSheetURI + "browser-override.css";
break;
default:
return false;
}
Expand Down
3 changes: 3 additions & 0 deletions src/content/stylesheets/browser-override.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
tabpanels {
background: #{default_background_color} !important;
}

0 comments on commit 4bf20a4

Please sign in to comment.