mirror of
https://github.com/zen-browser/desktop.git
synced 2026-02-04 11:04:39 +00:00
feat: Removed legacy stylesheets config and implement c++ mods backen… (#9131)
This commit is contained in:
@@ -11,9 +11,6 @@
|
||||
// Dont download the multilingual dictionary
|
||||
pref("intl.multilingual.downloadEnabled", false);
|
||||
|
||||
// Theme
|
||||
pref('toolkit.legacyUserProfileCustomizations.stylesheets', true);
|
||||
|
||||
#ifdef XP_WIN
|
||||
#include windows.inc
|
||||
#endif
|
||||
|
||||
@@ -16,8 +16,7 @@
|
||||
border-radius: 100% !important;
|
||||
}
|
||||
|
||||
#back-button,
|
||||
#zen-sidebar-web-panel-back {
|
||||
#back-button {
|
||||
list-style-image: url('back.svg') !important;
|
||||
}
|
||||
|
||||
@@ -25,19 +24,16 @@
|
||||
list-style-image: url('move-tab.svg') !important;
|
||||
}
|
||||
|
||||
#forward-button,
|
||||
#zen-sidebar-web-panel-forward {
|
||||
#forward-button {
|
||||
list-style-image: url('forward.svg') !important;
|
||||
}
|
||||
|
||||
#reload-button,
|
||||
#zen-sidebar-web-panel-reload {
|
||||
#reload-button {
|
||||
list-style-image: url('reload.svg') !important;
|
||||
}
|
||||
|
||||
#stop-button,
|
||||
.close-icon,
|
||||
#zen-sidebar-web-panel-close,
|
||||
#zen-glance-sidebar-close,
|
||||
.zen-theme-picker-custom-list-item-remove {
|
||||
list-style-image: url('close.svg') !important;
|
||||
@@ -281,8 +277,7 @@
|
||||
list-style-image: url('bookmark-star-on-tray.svg') !important;
|
||||
}
|
||||
|
||||
#home-button,
|
||||
#zen-sidebar-web-panel-home {
|
||||
#home-button {
|
||||
list-style-image: url('home.svg') !important;
|
||||
}
|
||||
|
||||
@@ -600,11 +595,6 @@
|
||||
> #reload-button[displaystop]
|
||||
+ #stop-button
|
||||
> .toolbarbutton-animatable-box
|
||||
> .toolbarbutton-animatable-image,
|
||||
#zen-sidebar-web-panel-reload[animate]
|
||||
> #zen-sidebar-web-panel-reload-button[displaystop]
|
||||
+ #zen-sidebar-web-panel-stop-button
|
||||
> .toolbarbutton-animatable-box
|
||||
> .toolbarbutton-animatable-image {
|
||||
background-image: url('reload-to-stop.svg') !important;
|
||||
}
|
||||
@@ -612,10 +602,6 @@
|
||||
#stop-reload-button[animate]
|
||||
> #reload-button
|
||||
> .toolbarbutton-animatable-box
|
||||
> .toolbarbutton-animatable-image,
|
||||
#zen-sidebar-web-panel-reload[animate]
|
||||
> #zen-sidebar-web-panel-reload-button
|
||||
> .toolbarbutton-animatable-box
|
||||
> .toolbarbutton-animatable-image {
|
||||
background-image: url('stop-to-reload.svg') !important;
|
||||
}
|
||||
|
||||
20
src/dom/base/Document-cpp.patch
Normal file
20
src/dom/base/Document-cpp.patch
Normal file
@@ -0,0 +1,20 @@
|
||||
diff --git a/dom/base/Document.cpp b/dom/base/Document.cpp
|
||||
index a16bef739fcde0f14ba7e53e0acfa3aa2ee1dd3a..78b9d112a56b3d909e31eb4351ee9f3b06c4ef92 100644
|
||||
--- a/dom/base/Document.cpp
|
||||
+++ b/dom/base/Document.cpp
|
||||
@@ -3332,6 +3332,15 @@ void Document::FillStyleSetUserAndUASheets() {
|
||||
|
||||
ServoStyleSet& styleSet = EnsureStyleSet();
|
||||
for (StyleSheet* sheet : *sheetService->UserStyleSheets()) {
|
||||
+ // If the url starts with "chrome://" and ends with 'zen-themes.css', then
|
||||
+ // skip it if the document is in a chrome docshell.
|
||||
+ // This is to avoid loading the user chrome stylesheet in the content
|
||||
+ // process, which is not allowed.
|
||||
+ auto spec = sheet->GetSheetURI()->GetSpecOrDefault();
|
||||
+ if (!IsInChromeDocShell() && StringBeginsWith(spec, "file://"_ns) &&
|
||||
+ StringEndsWith(spec, "zen-themes.css"_ns)) {
|
||||
+ continue;
|
||||
+ }
|
||||
styleSet.AppendStyleSheet(*sheet);
|
||||
}
|
||||
|
||||
13
src/layout/base/nsStyleSheetService-h.patch
Normal file
13
src/layout/base/nsStyleSheetService-h.patch
Normal file
@@ -0,0 +1,13 @@
|
||||
diff --git a/layout/base/nsStyleSheetService.h b/layout/base/nsStyleSheetService.h
|
||||
index 8c49b338bf8e6830874ace9a08e8c0713167ee58..53a48129b2b6b2adf15e0fe17da14c3b16577966 100644
|
||||
--- a/layout/base/nsStyleSheetService.h
|
||||
+++ b/layout/base/nsStyleSheetService.h
|
||||
@@ -50,6 +50,8 @@ class nsStyleSheetService final : public nsIStyleSheetService,
|
||||
|
||||
size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
|
||||
|
||||
+ void UpdateZenModStyles(mozilla::StyleSheet* aSheet, nsIURI* aURI, bool aInsert);
|
||||
+
|
||||
static nsStyleSheetService* GetInstance();
|
||||
static nsStyleSheetService* gInstance;
|
||||
|
||||
@@ -1,23 +1,15 @@
|
||||
// This Source Code Form is subject to the terms of the Mozilla Public
|
||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
const lazy = {};
|
||||
|
||||
var { AppConstants } = ChromeUtils.importESModule('resource://gre/modules/AppConstants.sys.mjs');
|
||||
|
||||
ChromeUtils.defineESModuleGetters(lazy, {
|
||||
BrowserWindowTracker: 'resource:///modules/BrowserWindowTracker.sys.mjs',
|
||||
});
|
||||
|
||||
class ZenUIMigration {
|
||||
PREF_NAME = 'zen.migration.version';
|
||||
MIGRATION_VERSION = 5;
|
||||
class nsZenUIMigration {
|
||||
PREF_NAME = 'zen.ui.migration.version';
|
||||
MIGRATION_VERSION = 1;
|
||||
|
||||
init(isNewProfile) {
|
||||
const win = lazy.BrowserWindowTracker.getTopWindow();
|
||||
if (!isNewProfile) {
|
||||
try {
|
||||
this._migrate(win);
|
||||
this._migrate();
|
||||
} catch (e) {
|
||||
console.error('ZenUIMigration: Error during migration', e);
|
||||
}
|
||||
@@ -33,18 +25,11 @@ class ZenUIMigration {
|
||||
Services.prefs.setIntPref(this.PREF_NAME, value);
|
||||
}
|
||||
|
||||
_migrate(win) {
|
||||
if (this._migrationVersion < 1) {
|
||||
this._migrateV1(win);
|
||||
}
|
||||
if (this._migrationVersion < 2) {
|
||||
this._migrateV2(win);
|
||||
}
|
||||
if (this._migrationVersion < 3) {
|
||||
this._migrateV3(win);
|
||||
}
|
||||
if (this._migrationVersion < 4) {
|
||||
this._migrateV4(win);
|
||||
_migrate() {
|
||||
for (let i = 0; i <= this.MIGRATION_VERSION; i++) {
|
||||
if (this._migrationVersion < i) {
|
||||
this[`_migrateV${i}`]?.();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,59 +37,21 @@ class ZenUIMigration {
|
||||
this._migrationVersion = this.MIGRATION_VERSION;
|
||||
}
|
||||
|
||||
_migrateV1(win) {
|
||||
// Introduction of the new URL bar, show a message to the user
|
||||
const notification = win.gNotificationBox.appendNotification(
|
||||
'zen-new-urlbar-notification',
|
||||
{
|
||||
label: { 'l10n-id': 'zen-new-urlbar-notification' },
|
||||
image: 'chrome://browser/skin/notification-icons/persistent-storage-blocked.svg',
|
||||
priority: win.gNotificationBox.PRIORITY_WARNING_HIGH,
|
||||
},
|
||||
[
|
||||
{
|
||||
'l10n-id': 'zen-disable',
|
||||
accessKey: 'D',
|
||||
callback: () => {
|
||||
Services.prefs.setBoolPref('zen.urlbar.replace-newtab', false);
|
||||
},
|
||||
},
|
||||
{
|
||||
link: 'https://docs.zen-browser.app/user-manual/urlbar/',
|
||||
'l10n-id': 'zen-learn-more-text',
|
||||
},
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
_migrateV2(win) {
|
||||
if (Services.prefs.getBoolPref('zen.widget.windows.acrylic', false)) {
|
||||
Services.prefs.setIntPref('widget.windows.mica.toplevel-backdrop', 2);
|
||||
Services.prefs.clearUserPref('zen.widget.windows.acrylic');
|
||||
_migrateV1() {
|
||||
// If there's an userChrome.css or userContent.css existing, we set
|
||||
// 'toolkit.legacyUserProfileCustomizations.stylesheets' back to true
|
||||
// We do this to avoid existing user stylesheets to be ignored
|
||||
const profileDir = Services.dirsvc.get('ProfD', Ci.nsIFile);
|
||||
const userChromeFile = profileDir.clone();
|
||||
userChromeFile.append('chrome');
|
||||
userChromeFile.append('userChrome.css');
|
||||
const userContentFile = profileDir.clone();
|
||||
userContentFile.append('chrome');
|
||||
userContentFile.append('userContent.css');
|
||||
if (userChromeFile.exists() || userContentFile.exists()) {
|
||||
Services.prefs.setBoolPref('toolkit.legacyUserProfileCustomizations.stylesheets', true);
|
||||
}
|
||||
}
|
||||
|
||||
_migrateV3(win) {
|
||||
const kArea = win.CustomizableUI.AREA_TABSTRIP;
|
||||
const widgets = win.CustomizableUI.getWidgetsInArea(kArea);
|
||||
for (const widget of widgets) {
|
||||
const widgetId = widget.id;
|
||||
if (widgetId === 'tabbrowser-tabs') {
|
||||
continue;
|
||||
}
|
||||
win.CustomizableUI.removeWidgetFromArea(widgetId);
|
||||
}
|
||||
}
|
||||
|
||||
_migrateV4(win) {
|
||||
if (AppConstants.platform === 'linux') {
|
||||
return;
|
||||
}
|
||||
Services.prefs.setBoolPref(
|
||||
'browser.tabs.unloadOnLowMemory',
|
||||
Services.prefs.getBoolPref('zen.tab-unloader.enabled', true)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export var gZenUIMigration = new ZenUIMigration();
|
||||
export var gZenUIMigration = new nsZenUIMigration();
|
||||
|
||||
@@ -185,7 +185,15 @@
|
||||
#navigator-toolbox:has(.tabbrowser-tab:active),
|
||||
&[zen-renaming-tab='true'] #navigator-toolbox,
|
||||
#navigator-toolbox:has(
|
||||
*:is([panelopen='true'], [open='true'], #urlbar:focus-within, [breakout-extend='true']):not(#urlbar[zen-floating-urlbar='true']):not(tab):not(.zen-compact-mode-ignore)
|
||||
*:is(
|
||||
[panelopen='true'],
|
||||
[open='true'],
|
||||
#urlbar:focus-within,
|
||||
[breakout-extend='true']
|
||||
)
|
||||
:not(#urlbar[zen-floating-urlbar='true'])
|
||||
:not(tab)
|
||||
:not(.zen-compact-mode-ignore)
|
||||
) {
|
||||
&:not([animate='true']) {
|
||||
--zen-compact-mode-func: linear(
|
||||
@@ -328,8 +336,7 @@
|
||||
}
|
||||
|
||||
& #titlebar,
|
||||
& #zen-appcontent-wrapper,
|
||||
& #zen-sidebar-web-panel-wrapper:has(#zen-sidebar-web-panel:not([pinned='true'])) {
|
||||
& #zen-appcontent-wrapper {
|
||||
margin-top: var(--zen-element-separation) !important;
|
||||
}
|
||||
|
||||
@@ -337,10 +344,6 @@
|
||||
z-index: 3 !important;
|
||||
}
|
||||
|
||||
& #zen-sidebar-web-panel-wrapper:has(#zen-sidebar-web-panel[pinned='true']) {
|
||||
margin-top: calc(var(--zen-element-separation) * 2) !important;
|
||||
}
|
||||
|
||||
& #zen-appcontent-navbar-wrapper {
|
||||
--zen-compact-toolbar-offset: 5px;
|
||||
position: absolute;
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
},
|
||||
});
|
||||
|
||||
class ZenDownloadAnimation extends ZenDOMOperatedFeature {
|
||||
class nsZenDownloadAnimation extends ZenDOMOperatedFeature {
|
||||
async init() {
|
||||
await this.#setupDownloadListeners();
|
||||
}
|
||||
@@ -26,7 +26,7 @@
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(
|
||||
`[${ZenDownloadAnimation.name}] Failed to set up download animation listeners: ${error}`
|
||||
`[${nsZenDownloadAnimation.name}] Failed to set up download animation listeners: ${error}`
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -41,7 +41,7 @@
|
||||
|
||||
if (!gZenUIManager._lastClickPosition) {
|
||||
console.warn(
|
||||
`[${ZenDownloadAnimation.name}] No recent click position available for animation`
|
||||
`[${nsZenDownloadAnimation.name}] No recent click position available for animation`
|
||||
);
|
||||
return;
|
||||
}
|
||||
@@ -61,7 +61,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
class ZenDownloadAnimationElement extends HTMLElement {
|
||||
class nsZenDownloadAnimationElement extends HTMLElement {
|
||||
#boxAnimationElement = null;
|
||||
#boxAnimationTimeoutId = null;
|
||||
#isBoxAnimationRunning = false;
|
||||
@@ -82,14 +82,14 @@
|
||||
);
|
||||
this.shadowRoot.appendChild(link);
|
||||
} catch (error) {
|
||||
console.error(`[${ZenDownloadAnimationElement.name}] Error loading arc styles: ${error}`);
|
||||
console.error(`[${nsZenDownloadAnimationElement.name}] Error loading arc styles: ${error}`);
|
||||
}
|
||||
}
|
||||
|
||||
async initializeAnimation(startPosition) {
|
||||
if (!startPosition) {
|
||||
console.warn(
|
||||
`[${ZenDownloadAnimationElement.name}] No start position provided, skipping animation`
|
||||
`[${nsZenDownloadAnimationElement.name}] No start position provided, skipping animation`
|
||||
);
|
||||
return;
|
||||
}
|
||||
@@ -229,7 +229,7 @@
|
||||
|
||||
this.#cleanArcAnimation(arcAnimationElement);
|
||||
} catch (error) {
|
||||
console.error('[ZenDownloadAnimationElement] Error in animation sequence:', error);
|
||||
console.error('[nsZenDownloadAnimationElement] Error in animation sequence:', error);
|
||||
this.#cleanArcAnimation(arcAnimationElement);
|
||||
}
|
||||
}
|
||||
@@ -309,7 +309,7 @@
|
||||
// If animation is already in progress, don't start a new one
|
||||
if (this.#isBoxAnimationRunning) {
|
||||
console.warn(
|
||||
`[${ZenDownloadAnimationElement.name}] Box animation already running, skipping new request.`
|
||||
`[${nsZenDownloadAnimationElement.name}] Box animation already running, skipping new request.`
|
||||
);
|
||||
return;
|
||||
}
|
||||
@@ -326,7 +326,7 @@
|
||||
const wrapper = document.getElementById('zen-main-app-wrapper');
|
||||
if (!wrapper) {
|
||||
console.warn(
|
||||
`[${ZenDownloadAnimationElement.name}] Cannot start box animation, Wrapper element not found`
|
||||
`[${nsZenDownloadAnimationElement.name}] Cannot start box animation, Wrapper element not found`
|
||||
);
|
||||
return;
|
||||
}
|
||||
@@ -385,7 +385,7 @@
|
||||
);
|
||||
} catch (error) {
|
||||
console.error(
|
||||
`[${ZenDownloadAnimationElement.name}] Error during box entry animation: ${error}`
|
||||
`[${nsZenDownloadAnimationElement.name}] Error during box entry animation: ${error}`
|
||||
);
|
||||
this.#cleanBoxAnimation();
|
||||
} finally {
|
||||
@@ -436,7 +436,7 @@
|
||||
).finished;
|
||||
} catch (error) {
|
||||
console.warn(
|
||||
`[${ZenDownloadAnimationElement.name}] Error during box exit animation: ${error}`
|
||||
`[${nsZenDownloadAnimationElement.name}] Error during box exit animation: ${error}`
|
||||
);
|
||||
} finally {
|
||||
this.#cleanBoxAnimation();
|
||||
@@ -458,7 +458,7 @@
|
||||
this.#boxAnimationElement.remove();
|
||||
} catch (error) {
|
||||
console.error(
|
||||
`[${ZenDownloadAnimationElement.name}] Error removing box animation element: ${error}`,
|
||||
`[${nsZenDownloadAnimationElement.name}] Error removing box animation element: ${error}`,
|
||||
error
|
||||
);
|
||||
}
|
||||
@@ -488,7 +488,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
customElements.define('zen-download-animation', ZenDownloadAnimationElement);
|
||||
customElements.define('zen-download-animation', nsZenDownloadAnimationElement);
|
||||
|
||||
new ZenDownloadAnimation();
|
||||
new nsZenDownloadAnimation();
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
{
|
||||
class ZenGlanceManager extends ZenDOMOperatedFeature {
|
||||
class nsZenGlanceManager extends ZenDOMOperatedFeature {
|
||||
_animating = false;
|
||||
_lazyPref = {};
|
||||
|
||||
@@ -783,7 +783,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
window.gZenGlanceManager = new ZenGlanceManager();
|
||||
window.gZenGlanceManager = new nsZenGlanceManager();
|
||||
|
||||
function registerWindowActors() {
|
||||
gZenActorsManager.addJSWindowActor('ZenGlance', {
|
||||
|
||||
@@ -138,7 +138,7 @@ const VALID_SHORTCUT_GROUPS = [
|
||||
'other',
|
||||
];
|
||||
|
||||
class KeyShortcutModifiers {
|
||||
class nsKeyShortcutModifiers {
|
||||
#control = false;
|
||||
#alt = false;
|
||||
#shift = false;
|
||||
@@ -161,10 +161,10 @@ class KeyShortcutModifiers {
|
||||
|
||||
static parseFromJSON(modifiers) {
|
||||
if (!modifiers) {
|
||||
return new KeyShortcutModifiers(false, false, false, false, false);
|
||||
return new nsKeyShortcutModifiers(false, false, false, false, false);
|
||||
}
|
||||
|
||||
return new KeyShortcutModifiers(
|
||||
return new nsKeyShortcutModifiers(
|
||||
modifiers['control'] == true,
|
||||
modifiers['alt'] == true,
|
||||
modifiers['shift'] == true,
|
||||
@@ -175,10 +175,10 @@ class KeyShortcutModifiers {
|
||||
|
||||
static parseFromXHTMLAttribute(modifiers) {
|
||||
if (!modifiers) {
|
||||
return new KeyShortcutModifiers(false, false, false, false, false);
|
||||
return new nsKeyShortcutModifiers(false, false, false, false, false);
|
||||
}
|
||||
|
||||
return new KeyShortcutModifiers(
|
||||
return new nsKeyShortcutModifiers(
|
||||
modifiers.includes('control'),
|
||||
modifiers.includes('alt'),
|
||||
modifiers.includes('shift'),
|
||||
@@ -189,7 +189,7 @@ class KeyShortcutModifiers {
|
||||
|
||||
// used to avoid any future changes to the object
|
||||
static fromObject({ ctrl = false, alt = false, shift = false, meta = false, accel = false }) {
|
||||
return new KeyShortcutModifiers(ctrl, alt, shift, meta, accel);
|
||||
return new nsKeyShortcutModifiers(ctrl, alt, shift, meta, accel);
|
||||
}
|
||||
|
||||
toUserString() {
|
||||
@@ -290,7 +290,7 @@ class KeyShortcut {
|
||||
#key = '';
|
||||
#keycode = '';
|
||||
#group = FIREFOX_SHORTCUTS_GROUP;
|
||||
#modifiers = new KeyShortcutModifiers(false, false, false, false, false);
|
||||
#modifiers = new nsKeyShortcutModifiers(false, false, false, false, false);
|
||||
#action = '';
|
||||
#l10nId = '';
|
||||
#disabled = false;
|
||||
@@ -357,7 +357,7 @@ class KeyShortcut {
|
||||
json['key'],
|
||||
json['keycode'],
|
||||
json['group'],
|
||||
KeyShortcutModifiers.parseFromJSON(json['modifiers']),
|
||||
nsKeyShortcutModifiers.parseFromJSON(json['modifiers']),
|
||||
json['action'],
|
||||
json['l10nId'],
|
||||
json['disabled'],
|
||||
@@ -376,7 +376,7 @@ class KeyShortcut {
|
||||
KeyShortcut.sanitizeL10nId(key.getAttribute('data-l10n-id')),
|
||||
key.getAttribute('id')
|
||||
),
|
||||
KeyShortcutModifiers.parseFromXHTMLAttribute(key.getAttribute('modifiers')),
|
||||
nsKeyShortcutModifiers.parseFromXHTMLAttribute(key.getAttribute('modifiers')),
|
||||
key.getAttribute('command'),
|
||||
key.getAttribute('data-l10n-id'),
|
||||
key.getAttribute('disabled') == 'true',
|
||||
@@ -504,8 +504,8 @@ class KeyShortcut {
|
||||
}
|
||||
|
||||
setModifiers(modifiers) {
|
||||
if ((!modifiers) instanceof KeyShortcutModifiers) {
|
||||
throw new Error('Only KeyShortcutModifiers allowed');
|
||||
if ((!modifiers) instanceof nsKeyShortcutModifiers) {
|
||||
throw new Error('Only nsKeyShortcutModifiers allowed');
|
||||
}
|
||||
this.#modifiers = modifiers;
|
||||
}
|
||||
@@ -554,7 +554,7 @@ class KeyShortcut {
|
||||
clearKeybind() {
|
||||
this.#key = '';
|
||||
this.#keycode = '';
|
||||
this.#modifiers = new KeyShortcutModifiers(false, false, false, false);
|
||||
this.#modifiers = new nsKeyShortcutModifiers(false, false, false, false);
|
||||
}
|
||||
|
||||
setNewBinding(shortcut) {
|
||||
@@ -571,7 +571,7 @@ class KeyShortcut {
|
||||
}
|
||||
}
|
||||
|
||||
class ZenKeyboardShortcutsLoader {
|
||||
class nsZenKeyboardShortcutsLoader {
|
||||
constructor() {}
|
||||
|
||||
get shortcutsFile() {
|
||||
@@ -623,7 +623,7 @@ class ZenKeyboardShortcutsLoader {
|
||||
'C',
|
||||
'',
|
||||
ZEN_COMPACT_MODE_SHORTCUTS_GROUP,
|
||||
KeyShortcutModifiers.fromObject({ accel: true, alt: true }),
|
||||
nsKeyShortcutModifiers.fromObject({ accel: true, alt: true }),
|
||||
'cmd_zenCompactModeToggle',
|
||||
'zen-compact-mode-shortcut-toggle'
|
||||
)
|
||||
@@ -634,7 +634,7 @@ class ZenKeyboardShortcutsLoader {
|
||||
'S',
|
||||
'',
|
||||
ZEN_COMPACT_MODE_SHORTCUTS_GROUP,
|
||||
KeyShortcutModifiers.fromObject({ accel: true, alt: true }),
|
||||
nsKeyShortcutModifiers.fromObject({ accel: true, alt: true }),
|
||||
'cmd_zenCompactModeShowSidebar',
|
||||
'zen-compact-mode-shortcut-show-sidebar'
|
||||
)
|
||||
@@ -645,7 +645,7 @@ class ZenKeyboardShortcutsLoader {
|
||||
'T',
|
||||
'',
|
||||
ZEN_COMPACT_MODE_SHORTCUTS_GROUP,
|
||||
KeyShortcutModifiers.fromObject({ accel: true, alt: true }),
|
||||
nsKeyShortcutModifiers.fromObject({ accel: true, alt: true }),
|
||||
'cmd_zenCompactModeShowToolbar',
|
||||
'zen-compact-mode-shortcut-show-toolbar'
|
||||
)
|
||||
@@ -659,7 +659,7 @@ class ZenKeyboardShortcutsLoader {
|
||||
'',
|
||||
'',
|
||||
ZEN_WORKSPACE_SHORTCUTS_GROUP,
|
||||
KeyShortcutModifiers.fromObject({}),
|
||||
nsKeyShortcutModifiers.fromObject({}),
|
||||
`cmd_zenWorkspaceSwitch${i}`,
|
||||
`zen-workspace-shortcut-switch-${i}`
|
||||
)
|
||||
@@ -671,7 +671,7 @@ class ZenKeyboardShortcutsLoader {
|
||||
'E',
|
||||
'',
|
||||
ZEN_WORKSPACE_SHORTCUTS_GROUP,
|
||||
KeyShortcutModifiers.fromObject({ accel: true, alt: true }),
|
||||
nsKeyShortcutModifiers.fromObject({ accel: true, alt: true }),
|
||||
'cmd_zenWorkspaceForward',
|
||||
'zen-workspace-shortcut-forward'
|
||||
)
|
||||
@@ -682,7 +682,7 @@ class ZenKeyboardShortcutsLoader {
|
||||
'Q',
|
||||
'',
|
||||
ZEN_WORKSPACE_SHORTCUTS_GROUP,
|
||||
KeyShortcutModifiers.fromObject({ accel: true, alt: true }),
|
||||
nsKeyShortcutModifiers.fromObject({ accel: true, alt: true }),
|
||||
'cmd_zenWorkspaceBackward',
|
||||
'zen-workspace-shortcut-backward'
|
||||
)
|
||||
@@ -695,7 +695,7 @@ class ZenKeyboardShortcutsLoader {
|
||||
'G',
|
||||
'',
|
||||
ZEN_SPLIT_VIEW_SHORTCUTS_GROUP,
|
||||
KeyShortcutModifiers.fromObject({ accel: true, alt: true }),
|
||||
nsKeyShortcutModifiers.fromObject({ accel: true, alt: true }),
|
||||
'cmd_zenSplitViewGrid',
|
||||
'zen-split-view-shortcut-grid'
|
||||
)
|
||||
@@ -706,7 +706,7 @@ class ZenKeyboardShortcutsLoader {
|
||||
'V',
|
||||
'',
|
||||
ZEN_SPLIT_VIEW_SHORTCUTS_GROUP,
|
||||
KeyShortcutModifiers.fromObject({ accel: true, alt: true }),
|
||||
nsKeyShortcutModifiers.fromObject({ accel: true, alt: true }),
|
||||
'cmd_zenSplitViewVertical',
|
||||
'zen-split-view-shortcut-vertical'
|
||||
)
|
||||
@@ -717,7 +717,7 @@ class ZenKeyboardShortcutsLoader {
|
||||
'H',
|
||||
'',
|
||||
ZEN_SPLIT_VIEW_SHORTCUTS_GROUP,
|
||||
KeyShortcutModifiers.fromObject({ accel: true, alt: true }),
|
||||
nsKeyShortcutModifiers.fromObject({ accel: true, alt: true }),
|
||||
'cmd_zenSplitViewHorizontal',
|
||||
'zen-split-view-shortcut-horizontal'
|
||||
)
|
||||
@@ -728,7 +728,7 @@ class ZenKeyboardShortcutsLoader {
|
||||
'U',
|
||||
'',
|
||||
ZEN_SPLIT_VIEW_SHORTCUTS_GROUP,
|
||||
KeyShortcutModifiers.fromObject({ accel: true, alt: true }),
|
||||
nsKeyShortcutModifiers.fromObject({ accel: true, alt: true }),
|
||||
'cmd_zenSplitViewUnsplit',
|
||||
'zen-split-view-shortcut-unsplit'
|
||||
)
|
||||
@@ -763,7 +763,7 @@ class ZenKeyboardShortcutsLoader {
|
||||
}
|
||||
}
|
||||
|
||||
class ZenKeyboardShortcutsVersioner {
|
||||
class nsZenKeyboardShortcutsVersioner {
|
||||
static LATEST_KBS_VERSION = 9;
|
||||
|
||||
constructor() {}
|
||||
@@ -783,11 +783,11 @@ class ZenKeyboardShortcutsVersioner {
|
||||
}
|
||||
|
||||
isVersionUpToDate() {
|
||||
return this.version == ZenKeyboardShortcutsVersioner.LATEST_KBS_VERSION;
|
||||
return this.version == nsZenKeyboardShortcutsVersioner.LATEST_KBS_VERSION;
|
||||
}
|
||||
|
||||
isVersionOutdated() {
|
||||
return this.version < ZenKeyboardShortcutsVersioner.LATEST_KBS_VERSION;
|
||||
return this.version < nsZenKeyboardShortcutsVersioner.LATEST_KBS_VERSION;
|
||||
}
|
||||
|
||||
migrateIfNeeded(data) {
|
||||
@@ -806,10 +806,10 @@ class ZenKeyboardShortcutsVersioner {
|
||||
'Zen CKS: Migrating shortcuts from version',
|
||||
version,
|
||||
'to',
|
||||
ZenKeyboardShortcutsVersioner.LATEST_KBS_VERSION
|
||||
nsZenKeyboardShortcutsVersioner.LATEST_KBS_VERSION
|
||||
);
|
||||
const newData = this.migrate(data, version);
|
||||
this.version = ZenKeyboardShortcutsVersioner.LATEST_KBS_VERSION;
|
||||
this.version = nsZenKeyboardShortcutsVersioner.LATEST_KBS_VERSION;
|
||||
return newData;
|
||||
}
|
||||
|
||||
@@ -819,7 +819,7 @@ class ZenKeyboardShortcutsVersioner {
|
||||
}
|
||||
|
||||
fillDefaultIfNotPresent(data) {
|
||||
for (let shortcut of ZenKeyboardShortcutsLoader.zenGetDefaultShortcuts()) {
|
||||
for (let shortcut of nsZenKeyboardShortcutsLoader.zenGetDefaultShortcuts()) {
|
||||
// If it has an ID and we dont find it in the data, we add it
|
||||
if (shortcut.getID() && !data.find((s) => s.getID() == shortcut.getID())) {
|
||||
data.push(shortcut);
|
||||
@@ -837,7 +837,7 @@ class ZenKeyboardShortcutsVersioner {
|
||||
// Migrate from 0 to 1
|
||||
// Here, we do a complet reset of the shortcuts,
|
||||
// since nothing seems to work properly.
|
||||
data = ZenKeyboardShortcutsLoader.zenGetDefaultShortcuts();
|
||||
data = nsZenKeyboardShortcutsLoader.zenGetDefaultShortcuts();
|
||||
}
|
||||
if (version < 2) {
|
||||
// Migrate from 1 to 2
|
||||
@@ -855,7 +855,7 @@ class ZenKeyboardShortcutsVersioner {
|
||||
'',
|
||||
'',
|
||||
ZEN_OTHER_SHORTCUTS_GROUP,
|
||||
KeyShortcutModifiers.fromObject({}),
|
||||
nsKeyShortcutModifiers.fromObject({}),
|
||||
'cmd_zenPinnedTabReset',
|
||||
'zen-pinned-tab-shortcut-reset'
|
||||
)
|
||||
@@ -867,7 +867,7 @@ class ZenKeyboardShortcutsVersioner {
|
||||
// detection for internal keys was not working properly, so every internal
|
||||
// shortcut was being saved as a user-editable shortcut.
|
||||
// This migration will fix this issue.
|
||||
const defaultShortcuts = ZenKeyboardShortcutsLoader.zenGetDefaultShortcuts();
|
||||
const defaultShortcuts = nsZenKeyboardShortcutsLoader.zenGetDefaultShortcuts();
|
||||
// Get the default shortcut, compare the id and set the internal flag if needed
|
||||
for (let shortcut of data) {
|
||||
for (let defaultShortcut of defaultShortcuts) {
|
||||
@@ -892,7 +892,7 @@ class ZenKeyboardShortcutsVersioner {
|
||||
'B',
|
||||
'',
|
||||
ZEN_OTHER_SHORTCUTS_GROUP,
|
||||
KeyShortcutModifiers.fromObject({ alt: true }),
|
||||
nsKeyShortcutModifiers.fromObject({ alt: true }),
|
||||
'cmd_zenToggleSidebar',
|
||||
'zen-sidebar-shortcut-toggle'
|
||||
)
|
||||
@@ -907,7 +907,7 @@ class ZenKeyboardShortcutsVersioner {
|
||||
'C',
|
||||
'',
|
||||
ZEN_OTHER_SHORTCUTS_GROUP,
|
||||
KeyShortcutModifiers.fromObject({ accel: true, shift: true }),
|
||||
nsKeyShortcutModifiers.fromObject({ accel: true, shift: true }),
|
||||
'cmd_zenCopyCurrentURL',
|
||||
'zen-text-action-copy-url-shortcut'
|
||||
)
|
||||
@@ -919,7 +919,7 @@ class ZenKeyboardShortcutsVersioner {
|
||||
const listener = (event) => {
|
||||
event.stopPropagation();
|
||||
|
||||
const devToolsShortcuts = ZenKeyboardShortcutsLoader.zenGetDefaultDevToolsShortcuts();
|
||||
const devToolsShortcuts = nsZenKeyboardShortcutsLoader.zenGetDefaultDevToolsShortcuts();
|
||||
gZenKeyboardShortcutsManager.updatedDefaultDevtoolsShortcuts(devToolsShortcuts);
|
||||
|
||||
window.removeEventListener('zen-devtools-keyset-added', listener);
|
||||
@@ -939,7 +939,7 @@ class ZenKeyboardShortcutsVersioner {
|
||||
'C',
|
||||
'',
|
||||
ZEN_OTHER_SHORTCUTS_GROUP,
|
||||
KeyShortcutModifiers.fromObject({ accel: true, shift: true, alt: true }),
|
||||
nsKeyShortcutModifiers.fromObject({ accel: true, shift: true, alt: true }),
|
||||
'cmd_zenCopyCurrentURLMarkdown',
|
||||
'zen-text-action-copy-url-markdown-shortcut'
|
||||
)
|
||||
@@ -989,7 +989,7 @@ class ZenKeyboardShortcutsVersioner {
|
||||
}
|
||||
|
||||
var gZenKeyboardShortcutsManager = {
|
||||
loader: new ZenKeyboardShortcutsLoader(),
|
||||
loader: new nsZenKeyboardShortcutsLoader(),
|
||||
_hasToLoadDevtools: false,
|
||||
_inlineCommands: [],
|
||||
|
||||
@@ -1051,7 +1051,7 @@ var gZenKeyboardShortcutsManager = {
|
||||
};
|
||||
|
||||
const loadedShortcuts = await innerLoad();
|
||||
this.versioner = new ZenKeyboardShortcutsVersioner(loadedShortcuts);
|
||||
this.versioner = new nsZenKeyboardShortcutsVersioner(loadedShortcuts);
|
||||
return loadedShortcuts;
|
||||
},
|
||||
|
||||
@@ -1160,7 +1160,7 @@ var gZenKeyboardShortcutsManager = {
|
||||
if (key.getGroup() != 'devTools') {
|
||||
continue;
|
||||
}
|
||||
if (ZenKeyboardShortcutsLoader.IGNORED_DEVTOOLS_SHORTCUTS.includes(key.getID())) {
|
||||
if (nsZenKeyboardShortcutsLoader.IGNORED_DEVTOOLS_SHORTCUTS.includes(key.getID())) {
|
||||
continue;
|
||||
}
|
||||
const originalKey = browser.document.getElementById(key.getID());
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
true
|
||||
);
|
||||
|
||||
class ZenMediaController {
|
||||
class nsZenMediaController {
|
||||
_currentMediaController = null;
|
||||
_currentBrowser = null;
|
||||
_mediaUpdateInterval = null;
|
||||
@@ -684,5 +684,5 @@
|
||||
}
|
||||
}
|
||||
|
||||
window.gZenMediaController = new ZenMediaController();
|
||||
window.gZenMediaController = new nsZenMediaController();
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
{
|
||||
class ZenMods extends ZenPreloadedFeature {
|
||||
class nsZenMods extends ZenPreloadedFeature {
|
||||
// private properties start
|
||||
#kZenStylesheetModHeader = '/* Zen Mods - Generated by ZenMods.';
|
||||
#kZenStylesheetModHeaderBody = `* DO NOT EDIT THIS FILE DIRECTLY!
|
||||
@@ -25,24 +25,13 @@
|
||||
}
|
||||
|
||||
// Stylesheet service
|
||||
#sss = null;
|
||||
#_modsBackend = null;
|
||||
|
||||
get #stylesheetService() {
|
||||
if (!this.#sss) {
|
||||
this.#sss = Cc['@mozilla.org/content/style-sheet-service;1'].getService(
|
||||
Ci.nsIStyleSheetService
|
||||
);
|
||||
get #modsBackend() {
|
||||
if (!this.#_modsBackend) {
|
||||
this.#_modsBackend = Cc['@mozilla.org/zen/mods-backend;1'].getService(Ci.nsIZenModsBackend);
|
||||
}
|
||||
return this.#sss;
|
||||
}
|
||||
|
||||
#ssu = null;
|
||||
|
||||
get #styleSheetUri() {
|
||||
if (!this.#ssu) {
|
||||
this.#ssu = Services.io.newFileURI(new FileUtils.File(this.#styleSheetPath));
|
||||
}
|
||||
return this.#ssu;
|
||||
return this.#_modsBackend;
|
||||
}
|
||||
|
||||
get #styleSheetPath() {
|
||||
@@ -50,15 +39,7 @@
|
||||
}
|
||||
|
||||
async #handleDisableMods() {
|
||||
if (Services.prefs.getBoolPref('zen.themes.disable-all', false)) {
|
||||
console.log('[ZenMods]: Disabling mods module.');
|
||||
|
||||
await this.#removeStylesheet();
|
||||
} else {
|
||||
console.log('[ZenMods]: Enabling mods module.');
|
||||
|
||||
await this.#rebuildModsStylesheet();
|
||||
}
|
||||
await this.#rebuildModsStylesheet();
|
||||
}
|
||||
|
||||
#getStylesheetURIForMod(mod) {
|
||||
@@ -68,60 +49,31 @@
|
||||
}
|
||||
|
||||
async #insertStylesheet() {
|
||||
if (await IOUtils.exists(this.#styleSheetPath)) {
|
||||
await this.#stylesheetService.loadAndRegisterSheet(
|
||||
this.#styleSheetUri,
|
||||
this.#stylesheetService.AGENT_SHEET
|
||||
);
|
||||
}
|
||||
|
||||
if (
|
||||
!this.#stylesheetService.sheetRegistered(
|
||||
this.#styleSheetUri,
|
||||
this.#stylesheetService.AGENT_SHEET
|
||||
)
|
||||
) {
|
||||
console.error(`[ZenMods]: Failed to register stylesheet at ${this.#styleSheetUri.spec}.`);
|
||||
}
|
||||
}
|
||||
|
||||
async #removeStylesheet() {
|
||||
await this.#stylesheetService.unregisterSheet(
|
||||
this.#styleSheetUri,
|
||||
this.#stylesheetService.AGENT_SHEET
|
||||
);
|
||||
const rv = this.#stylesheetService.sheetRegistered(
|
||||
this.#styleSheetUri,
|
||||
this.#stylesheetService.AGENT_SHEET
|
||||
);
|
||||
await IOUtils.remove(this.#styleSheetPath, { ignoreAbsent: true });
|
||||
|
||||
if (rv || (await IOUtils.exists(this.#styleSheetPath))) {
|
||||
console.error(`[ZenMods]: Failed to unregister stylesheet at ${this.#styleSheetUri.spec}.`);
|
||||
}
|
||||
this.#modsBackend.rebuildModsStyles();
|
||||
}
|
||||
|
||||
async #rebuildModsStylesheet() {
|
||||
await this.#removeStylesheet();
|
||||
const shouldBeEnabled = !Services.prefs.getBoolPref('zen.themes.disable-all', false);
|
||||
if (shouldBeEnabled) {
|
||||
const mods = await this.#getEnabledMods();
|
||||
|
||||
const mods = await this.#getEnabledMods();
|
||||
await this.#writeStylesheet(mods);
|
||||
|
||||
await this.#writeStylesheet(mods);
|
||||
const modsWithPreferences = await Promise.all(
|
||||
mods.map(async (mod) => {
|
||||
const preferences = await this.getModPreferences(mod);
|
||||
|
||||
const modsWithPreferences = await Promise.all(
|
||||
mods.map(async (mod) => {
|
||||
const preferences = await this.getModPreferences(mod);
|
||||
return {
|
||||
name: mod.name,
|
||||
enabled: mod.enabled,
|
||||
preferences,
|
||||
};
|
||||
})
|
||||
);
|
||||
|
||||
return {
|
||||
name: mod.name,
|
||||
enabled: mod.enabled,
|
||||
preferences,
|
||||
};
|
||||
})
|
||||
);
|
||||
|
||||
this.#setDefaults(modsWithPreferences);
|
||||
this.#writeToDom(modsWithPreferences);
|
||||
this.#setDefaults(modsWithPreferences);
|
||||
this.#writeToDom(modsWithPreferences);
|
||||
}
|
||||
|
||||
await this.#insertStylesheet();
|
||||
}
|
||||
@@ -336,20 +288,8 @@
|
||||
|
||||
const data = await response.text();
|
||||
|
||||
let content = data;
|
||||
|
||||
if (isStyleSheet) {
|
||||
content = '@-moz-document url-prefix("chrome:") {\n';
|
||||
|
||||
for (const line of data.split('\n')) {
|
||||
content += ` ${line}\n`;
|
||||
}
|
||||
|
||||
content += '}';
|
||||
}
|
||||
|
||||
// convert the data into a Uint8Array
|
||||
const buffer = new TextEncoder().encode(content);
|
||||
const buffer = new TextEncoder().encode(data);
|
||||
await IOUtils.write(path, buffer);
|
||||
|
||||
return; // to exit the loop
|
||||
@@ -715,7 +655,7 @@
|
||||
// public properties end
|
||||
}
|
||||
|
||||
window.gZenMods = new ZenMods();
|
||||
window.gZenMods = new nsZenMods();
|
||||
|
||||
gZenActorsManager.addJSWindowActor('ZenModsMarketplace', {
|
||||
parent: {
|
||||
|
||||
70
src/zen/mods/ZenStyleSheetCache.cpp
Normal file
70
src/zen/mods/ZenStyleSheetCache.cpp
Normal file
@@ -0,0 +1,70 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "ZenStyleSheetCache.h"
|
||||
#include "nsAppDirectoryServiceDefs.h"
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIFile.h"
|
||||
|
||||
#include "mozilla/css/SheetParsingMode.h"
|
||||
#include "mozilla/GlobalStyleSheetCache.h"
|
||||
|
||||
namespace zen {
|
||||
|
||||
using namespace mozilla;
|
||||
NS_IMPL_ISUPPORTS(ZenStyleSheetCache, nsISupports)
|
||||
|
||||
auto ZenStyleSheetCache::InvalidateModsSheet() -> void {
|
||||
mModsSheet = nullptr;
|
||||
}
|
||||
|
||||
auto ZenStyleSheetCache::GetModsSheet() -> StyleSheet* {
|
||||
if (mModsSheet) {
|
||||
// If the mods stylesheet is already loaded, return it.
|
||||
return mModsSheet;
|
||||
}
|
||||
nsCOMPtr<nsIFile> chromeFile;
|
||||
|
||||
NS_GetSpecialDirectory(NS_APP_USER_CHROME_DIR, getter_AddRefs(chromeFile));
|
||||
if (!chromeFile) {
|
||||
// if we don't have a profile yet, that's OK!
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
chromeFile->Append(ZEN_MODS_FILENAME);
|
||||
LoadSheetFile(chromeFile, css::eUserSheetFeatures);
|
||||
return mModsSheet;
|
||||
}
|
||||
|
||||
auto ZenStyleSheetCache::LoadSheetFile(nsIFile* aFile,
|
||||
css::SheetParsingMode aParsingMode)
|
||||
-> void {
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
NS_NewFileURI(getter_AddRefs(uri), aFile);
|
||||
if (!uri) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto loader = new mozilla::css::Loader;
|
||||
auto result = loader->LoadSheetSync(uri, aParsingMode,
|
||||
css::Loader::UseSystemPrincipal::Yes);
|
||||
if (MOZ_UNLIKELY(result.isErr())) {
|
||||
return;
|
||||
}
|
||||
mModsSheet = result.unwrapOr(nullptr);
|
||||
}
|
||||
|
||||
/* static */
|
||||
auto ZenStyleSheetCache::Singleton() -> ZenStyleSheetCache* {
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
if (!gZenModsCache) {
|
||||
gZenModsCache = new ZenStyleSheetCache;
|
||||
}
|
||||
return gZenModsCache;
|
||||
}
|
||||
|
||||
mozilla::StaticRefPtr<ZenStyleSheetCache> ZenStyleSheetCache::gZenModsCache;
|
||||
|
||||
} // namespace: zen
|
||||
57
src/zen/mods/ZenStyleSheetCache.h
Normal file
57
src/zen/mods/ZenStyleSheetCache.h
Normal file
@@ -0,0 +1,57 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#ifndef mozilla_ZenStyleSheetCache_h__
|
||||
#define mozilla_ZenStyleSheetCache_h__
|
||||
|
||||
#include "mozilla/css/Loader.h"
|
||||
#include "mozilla/NotNull.h"
|
||||
#include "mozilla/StaticPtr.h"
|
||||
|
||||
#ifndef ZEN_MODS_FILENAME
|
||||
#define ZEN_MODS_FILENAME u"zen-themes.css"_ns
|
||||
#endif
|
||||
|
||||
namespace zen {
|
||||
|
||||
class ZenStyleSheetCache final : public nsISupports {
|
||||
using StyleSheet = mozilla::StyleSheet;
|
||||
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
/**
|
||||
* @brief Clear up the cache and create a new mods stylesheet.
|
||||
* This is called when we need to recalculate the mods stylesheets.
|
||||
* @returns The mods stylesheet.
|
||||
*/
|
||||
auto InvalidateModsSheet() -> void;
|
||||
|
||||
/**
|
||||
* @brief Get the mods stylesheet.
|
||||
* This is called when we need to get the mods stylesheets.
|
||||
* @returns The mods stylesheet.
|
||||
*/
|
||||
auto GetModsSheet() -> StyleSheet*;
|
||||
|
||||
static auto Singleton() -> ZenStyleSheetCache*;
|
||||
private:
|
||||
ZenStyleSheetCache() = default;
|
||||
~ZenStyleSheetCache() = default;
|
||||
|
||||
/**
|
||||
* @brief Load the stylesheet from the given file.
|
||||
* @param aFile The file to load the stylesheet from.
|
||||
*/
|
||||
auto LoadSheetFile(nsIFile* aFile, mozilla::css::SheetParsingMode aParsingMode)
|
||||
-> void;
|
||||
|
||||
static mozilla::StaticRefPtr<ZenStyleSheetCache> gZenModsCache;
|
||||
|
||||
RefPtr<StyleSheet> mModsSheet;
|
||||
};
|
||||
|
||||
} // namespace zen
|
||||
|
||||
#endif
|
||||
10
src/zen/mods/components.conf
Normal file
10
src/zen/mods/components.conf
Normal file
@@ -0,0 +1,10 @@
|
||||
Classes = [
|
||||
{
|
||||
'cid': '{a0ee4792-b186-4497-936d-53a8989fe836}',
|
||||
'interfaces': ['nsIZenModsBackend'],
|
||||
'contract_ids': ['@mozilla.org/zen/mods-backend;1'],
|
||||
'type': 'zen::nsZenModsBackend',
|
||||
'headers': ['mozilla/nsZenModsBackend.h'],
|
||||
'processes': ProcessSelector.MAIN_PROCESS_ONLY,
|
||||
},
|
||||
]
|
||||
@@ -7,3 +7,31 @@ FINAL_TARGET_FILES.actors += [
|
||||
"actors/ZenModsMarketplaceChild.sys.mjs",
|
||||
"actors/ZenModsMarketplaceParent.sys.mjs",
|
||||
]
|
||||
|
||||
XPIDL_SOURCES += [
|
||||
"nsIZenModsBackend.idl",
|
||||
]
|
||||
|
||||
EXPORTS.mozilla += [
|
||||
"nsZenModsBackend.h",
|
||||
"ZenStyleSheetCache.h",
|
||||
]
|
||||
|
||||
SOURCES += [
|
||||
"nsZenModsBackend.cpp",
|
||||
"ZenStyleSheetCache.cpp",
|
||||
]
|
||||
|
||||
XPCOM_MANIFESTS += [
|
||||
"components.conf",
|
||||
]
|
||||
|
||||
include("/ipc/chromium/chromium-config.mozbuild")
|
||||
|
||||
LOCAL_INCLUDES += [
|
||||
"/dom/base",
|
||||
"/dom/ipc",
|
||||
]
|
||||
|
||||
FINAL_LIBRARY = "xul"
|
||||
XPIDL_MODULE = "zen_mods"
|
||||
|
||||
31
src/zen/mods/nsIZenModsBackend.idl
Normal file
31
src/zen/mods/nsIZenModsBackend.idl
Normal file
@@ -0,0 +1,31 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "nsISupports.idl"
|
||||
#include "nsIURI.idl"
|
||||
|
||||
%{C++
|
||||
#include "mozilla/ServoStyleSet.h"
|
||||
#include "mozilla/dom/Document.h"
|
||||
%}
|
||||
|
||||
/**
|
||||
* @brief Interface for Zen mods backend.
|
||||
*/
|
||||
[scriptable, uuid(a0ee4792-b186-4497-936d-53a8989fe836)]
|
||||
interface nsIZenModsBackend : nsISupports {
|
||||
/*
|
||||
* @brief Remove, clear cache and create a new mods stylesheet.
|
||||
* This is called when we need to recalculate the mods stylesheets.
|
||||
* @returns The mods stylesheet.
|
||||
*/
|
||||
void invalidateModsSheet();
|
||||
/**
|
||||
* @brief Unregister and register the mods stylesheet.
|
||||
* This is called when we need to recalculate the mods stylesheets.
|
||||
* @returns void
|
||||
*/
|
||||
void rebuildModsStyles();
|
||||
};
|
||||
|
||||
105
src/zen/mods/nsZenModsBackend.cpp
Normal file
105
src/zen/mods/nsZenModsBackend.cpp
Normal file
@@ -0,0 +1,105 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "nsZenModsBackend.h"
|
||||
|
||||
#include "nsIXULRuntime.h"
|
||||
#include "nsStyleSheetService.h"
|
||||
|
||||
#include "mozilla/PresShell.h"
|
||||
#include "mozilla/dom/ContentParent.h"
|
||||
|
||||
#include "nsIURI.h"
|
||||
#include "nsIFile.h"
|
||||
|
||||
#include "ZenStyleSheetCache.h"
|
||||
|
||||
namespace zen {
|
||||
|
||||
namespace {
|
||||
/// @brief Helper function to get the singleton instance of ZenStyleSheetCache.
|
||||
/// @return A pointer to the singleton instance of ZenStyleSheetCache.
|
||||
static auto GetZenStyleSheetCache() -> ZenStyleSheetCache* {
|
||||
return ZenStyleSheetCache::Singleton();
|
||||
}
|
||||
}
|
||||
|
||||
// Use the macro to inject all of the definitions for nsISupports.
|
||||
NS_IMPL_ISUPPORTS(nsZenModsBackend, nsIZenModsBackend)
|
||||
|
||||
nsZenModsBackend::nsZenModsBackend() {
|
||||
mozilla::Unused << CheckEnabled();
|
||||
}
|
||||
|
||||
auto nsZenModsBackend::CheckEnabled() -> bool {
|
||||
// Check if the mods backend is enabled based on the preference.
|
||||
nsCOMPtr<nsIXULRuntime> appInfo =
|
||||
do_GetService("@mozilla.org/xre/app-info;1");
|
||||
bool inSafeMode = false;
|
||||
if (appInfo) {
|
||||
appInfo->GetInSafeMode(&inSafeMode);
|
||||
}
|
||||
mEnabled = !inSafeMode &&
|
||||
!mozilla::Preferences::GetBool("zen.themes.disable-all", false);
|
||||
return mEnabled;
|
||||
}
|
||||
|
||||
auto nsZenModsBackend::RebuildModsStyles() -> nsresult {
|
||||
// Invalidate the mods stylesheet cache.
|
||||
GetZenStyleSheetCache()->InvalidateModsSheet();
|
||||
// Rebuild the mods stylesheets.
|
||||
auto modsSheet = GetZenStyleSheetCache()->GetModsSheet();
|
||||
if (!modsSheet) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
// Get the service from @mozilla.org/content/style-sheet-service;1
|
||||
if (auto* sss = nsStyleSheetService::GetInstance()) {
|
||||
// Register the mods stylesheet.
|
||||
sss->UpdateZenModStyles(modsSheet, modsSheet->GetSheetURI(), CheckEnabled());
|
||||
}
|
||||
// Notify that the mods stylesheets have been rebuilt.
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsZenModsBackend::InvalidateModsSheet() {
|
||||
if (!mEnabled) {
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
GetZenStyleSheetCache()->InvalidateModsSheet();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
} // namespace: zen
|
||||
|
||||
void nsStyleSheetService::UpdateZenModStyles(mozilla::StyleSheet* aSheet, nsIURI* aURI, bool aInsert) {
|
||||
auto sheetType = nsStyleSheetService::USER_SHEET;
|
||||
this->UnregisterSheet(aURI, sheetType);
|
||||
if (!aSheet || !aInsert) {
|
||||
return; // Nothing to update.
|
||||
}
|
||||
mSheets[sheetType].AppendElement(aSheet);
|
||||
// Hold on to a copy of the registered PresShells.
|
||||
for (mozilla::PresShell* presShell : mPresShells.Clone()) {
|
||||
// Only allow on chrome documents.
|
||||
auto doc = presShell->GetDocument();
|
||||
if (doc && !doc->IsInChromeDocShell()) {
|
||||
continue;
|
||||
}
|
||||
presShell->NotifyStyleSheetServiceSheetAdded(aSheet, sheetType);
|
||||
}
|
||||
|
||||
if (XRE_IsParentProcess()) {
|
||||
nsTArray<mozilla::dom::ContentParent*> children;
|
||||
mozilla::dom::ContentParent::GetAll(children);
|
||||
|
||||
if (children.IsEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < children.Length(); i++) {
|
||||
mozilla::Unused << children[i]->SendLoadAndRegisterSheet(aURI, sheetType);
|
||||
}
|
||||
}
|
||||
}
|
||||
36
src/zen/mods/nsZenModsBackend.h
Normal file
36
src/zen/mods/nsZenModsBackend.h
Normal file
@@ -0,0 +1,36 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#ifndef mozilla_ZenModsBackend_h__
|
||||
#define mozilla_ZenModsBackend_h__
|
||||
|
||||
#include "nsIZenModsBackend.h"
|
||||
#include "nsIZenCommonUtils.h"
|
||||
|
||||
#include "mozilla/ServoStyleSet.h"
|
||||
#include "mozilla/dom/Document.h"
|
||||
|
||||
namespace zen {
|
||||
|
||||
class nsZenModsBackend final : public nsIZenModsBackend {
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIZENMODSBACKEND
|
||||
|
||||
public:
|
||||
explicit nsZenModsBackend();
|
||||
|
||||
protected:
|
||||
/**
|
||||
* @brief Check for the preference and see if the app is on safe mode.
|
||||
*/
|
||||
auto CheckEnabled() -> bool;
|
||||
|
||||
private:
|
||||
~nsZenModsBackend() = default;
|
||||
bool mEnabled = false;
|
||||
};
|
||||
|
||||
} // namespace zen
|
||||
|
||||
#endif
|
||||
@@ -2,7 +2,7 @@
|
||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
class SplitLeafNode {
|
||||
class nsSplitLeafNode {
|
||||
/**
|
||||
* The percentage of the size of the parent the node takes up, dependent on parent direction this is either
|
||||
* width or height.
|
||||
@@ -14,7 +14,7 @@ class SplitLeafNode {
|
||||
*/
|
||||
positionToRoot; // position relative to root node
|
||||
/**
|
||||
* @type {SplitNode}
|
||||
* @type {nsSplitNode}
|
||||
*/
|
||||
parent;
|
||||
constructor(tab, sizeInParent) {
|
||||
@@ -31,7 +31,7 @@ class SplitLeafNode {
|
||||
}
|
||||
}
|
||||
|
||||
class SplitNode extends SplitLeafNode {
|
||||
class nsSplitNode extends nsSplitLeafNode {
|
||||
/**
|
||||
* @type {string}
|
||||
*/
|
||||
@@ -63,7 +63,7 @@ class SplitNode extends SplitLeafNode {
|
||||
}
|
||||
}
|
||||
|
||||
class ZenViewSplitter extends ZenDOMOperatedFeature {
|
||||
class nsZenViewSplitter extends ZenDOMOperatedFeature {
|
||||
currentView = -1;
|
||||
_data = [];
|
||||
_tabBrowserPanel = null;
|
||||
@@ -441,9 +441,9 @@ class ZenViewSplitter extends ZenDOMOperatedFeature {
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a SplitNode from its tree and the view
|
||||
* @param {SplitNode} toRemove
|
||||
* @return {SplitNode} that has to be updated
|
||||
* Remove a nsSplitNode from its tree and the view
|
||||
* @param {nsSplitNode} toRemove
|
||||
* @return {nsSplitNode} that has to be updated
|
||||
*/
|
||||
removeNode(toRemove) {
|
||||
this._removeNodeSplitters(toRemove, true);
|
||||
@@ -825,7 +825,7 @@ class ZenViewSplitter extends ZenDOMOperatedFeature {
|
||||
nodeSize = node.sizeInParent;
|
||||
} else {
|
||||
nodeSize = 100;
|
||||
newParent = new SplitNode(splitDirection, node.sizeInParent);
|
||||
newParent = new nsSplitNode(splitDirection, node.sizeInParent);
|
||||
if (node.parent) {
|
||||
newParent.parent = node.parent;
|
||||
const nodeIndex = node.parent.children.indexOf(node);
|
||||
@@ -1118,7 +1118,7 @@ class ZenViewSplitter extends ZenDOMOperatedFeature {
|
||||
addTabToSplit(tab, splitNode, prepend = true) {
|
||||
const reduce = splitNode.children.length / (splitNode.children.length + 1);
|
||||
splitNode.children.forEach((c) => (c.sizeInParent *= reduce));
|
||||
splitNode.addChild(new SplitLeafNode(tab, (1 - reduce) * 100), prepend);
|
||||
splitNode.addChild(new nsSplitLeafNode(tab, (1 - reduce) * 100), prepend);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1184,21 +1184,24 @@ class ZenViewSplitter extends ZenDOMOperatedFeature {
|
||||
calculateLayoutTree(tabs, gridType) {
|
||||
let rootNode;
|
||||
if (gridType === 'vsep' || (tabs.length === 2 && gridType === 'grid')) {
|
||||
rootNode = new SplitNode('row');
|
||||
rootNode.children = tabs.map((tab) => new SplitLeafNode(tab, 100 / tabs.length));
|
||||
rootNode = new nsSplitNode('row');
|
||||
rootNode.children = tabs.map((tab) => new nsSplitLeafNode(tab, 100 / tabs.length));
|
||||
} else if (gridType === 'hsep') {
|
||||
rootNode = new SplitNode('column');
|
||||
rootNode.children = tabs.map((tab) => new SplitLeafNode(tab, 100 / tabs.length));
|
||||
rootNode = new nsSplitNode('column');
|
||||
rootNode.children = tabs.map((tab) => new nsSplitLeafNode(tab, 100 / tabs.length));
|
||||
} else if (gridType === 'grid') {
|
||||
rootNode = new SplitNode('row');
|
||||
rootNode = new nsSplitNode('row');
|
||||
const rowWidth = 100 / Math.ceil(tabs.length / 2);
|
||||
for (let i = 0; i < tabs.length - 1; i += 2) {
|
||||
const columnNode = new SplitNode('column', rowWidth, 100);
|
||||
columnNode.children = [new SplitLeafNode(tabs[i], 50), new SplitLeafNode(tabs[i + 1], 50)];
|
||||
const columnNode = new nsSplitNode('column', rowWidth, 100);
|
||||
columnNode.children = [
|
||||
new nsSplitLeafNode(tabs[i], 50),
|
||||
new nsSplitLeafNode(tabs[i + 1], 50),
|
||||
];
|
||||
rootNode.addChild(columnNode);
|
||||
}
|
||||
if (tabs.length % 2 !== 0) {
|
||||
rootNode.addChild(new SplitLeafNode(tabs[tabs.length - 1], rowWidth));
|
||||
rootNode.addChild(new nsSplitLeafNode(tabs[tabs.length - 1], rowWidth));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1260,7 +1263,7 @@ class ZenViewSplitter extends ZenDOMOperatedFeature {
|
||||
/**
|
||||
* Apply grid layout to tabBrowserPanel
|
||||
*
|
||||
* @param {SplitNode} splitNode SplitNode
|
||||
* @param {nsSplitNode} splitNode nsSplitNode
|
||||
*/
|
||||
applyGridLayout(splitNode) {
|
||||
if (!splitNode.positionToRoot) {
|
||||
@@ -1317,7 +1320,7 @@ class ZenViewSplitter extends ZenDOMOperatedFeature {
|
||||
/**
|
||||
*
|
||||
* @param {String} orient
|
||||
* @param {SplitNode} parentNode
|
||||
* @param {nsSplitNode} parentNode
|
||||
* @param {Number} idx
|
||||
*/
|
||||
createSplitter(orient, parentNode, idx) {
|
||||
@@ -1332,7 +1335,7 @@ class ZenViewSplitter extends ZenDOMOperatedFeature {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {SplitNode} parentNode
|
||||
* @param {nsSplitNode} parentNode
|
||||
* @param {number|undefined} splittersNeeded if provided the amount of splitters for node will be adjusted to match
|
||||
*/
|
||||
getSplitters(parentNode, splittersNeeded) {
|
||||
@@ -1365,7 +1368,7 @@ class ZenViewSplitter extends ZenDOMOperatedFeature {
|
||||
|
||||
/**
|
||||
* @param {Tab} tab
|
||||
* @return {SplitNode} splitNode
|
||||
* @return {nsSplitNode} splitNode
|
||||
*/
|
||||
getSplitNodeFromTab(tab) {
|
||||
return this._tabToSplitNode.get(tab);
|
||||
@@ -1703,7 +1706,7 @@ class ZenViewSplitter extends ZenDOMOperatedFeature {
|
||||
if (parentNode.direction !== splitDirection) {
|
||||
this.splitIntoNode(
|
||||
droppedOnSplitNode,
|
||||
new SplitLeafNode(draggedTab, 50),
|
||||
new nsSplitLeafNode(draggedTab, 50),
|
||||
hoverSide,
|
||||
0.5
|
||||
);
|
||||
@@ -1900,4 +1903,4 @@ class ZenViewSplitter extends ZenDOMOperatedFeature {
|
||||
}
|
||||
}
|
||||
|
||||
window.gZenViewSplitter = new ZenViewSplitter();
|
||||
window.gZenViewSplitter = new nsZenViewSplitter();
|
||||
|
||||
@@ -51,7 +51,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
class ZenPinnedTabManager extends ZenDOMOperatedFeature {
|
||||
class nsZenPinnedTabManager extends ZenDOMOperatedFeature {
|
||||
MAX_ESSENTIALS_TABS = 12;
|
||||
|
||||
async init() {
|
||||
@@ -1104,5 +1104,5 @@
|
||||
}
|
||||
}
|
||||
|
||||
window.gZenPinnedTabManager = new ZenPinnedTabManager();
|
||||
window.gZenPinnedTabManager = new nsZenPinnedTabManager();
|
||||
}
|
||||
|
||||
@@ -126,7 +126,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
class ZenWelcomePages {
|
||||
class nsZenWelcomePages {
|
||||
constructor(pages) {
|
||||
this._currentPage = -1;
|
||||
this._pages = pages;
|
||||
@@ -740,7 +740,7 @@
|
||||
delay: getMotion().stagger(0.4),
|
||||
}
|
||||
);
|
||||
new ZenWelcomePages(getWelcomePages());
|
||||
new nsZenWelcomePages(getWelcomePages());
|
||||
});
|
||||
await animate(
|
||||
button,
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
{
|
||||
class ZenWorkspace extends MozXULElement {
|
||||
class nsZenWorkspace extends MozXULElement {
|
||||
static get markup() {
|
||||
return `
|
||||
<vbox class="zen-workspace-tabs-section zen-current-workspace-indicator" flex="1" context="zenWorkspaceMoreActions">
|
||||
@@ -220,5 +220,5 @@
|
||||
}
|
||||
}
|
||||
|
||||
customElements.define('zen-workspace', ZenWorkspace);
|
||||
customElements.define('zen-workspace', nsZenWorkspace);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
class ZenWorkspaceCreation extends MozXULElement {
|
||||
class nsZenWorkspaceCreation extends MozXULElement {
|
||||
#wasInCollapsedMode = false;
|
||||
|
||||
promiseInitialized = new Promise((resolve) => {
|
||||
@@ -336,5 +336,5 @@
|
||||
}
|
||||
}
|
||||
|
||||
customElements.define('zen-workspace-creation', ZenWorkspaceCreation);
|
||||
customElements.define('zen-workspace-creation', nsZenWorkspaceCreation);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
{
|
||||
class ZenWorkspaceIcons extends MozXULElement {
|
||||
class nsZenWorkspaceIcons extends MozXULElement {
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
@@ -181,5 +181,5 @@
|
||||
}
|
||||
}
|
||||
|
||||
customElements.define('zen-workspace-icons', ZenWorkspaceIcons);
|
||||
customElements.define('zen-workspace-icons', nsZenWorkspaceIcons);
|
||||
}
|
||||
|
||||
@@ -124,7 +124,7 @@
|
||||
#PanelUI-zen-gradient-generator-custom-list {
|
||||
margin-top: 15px;
|
||||
|
||||
&:not(:has(.zen-theme-picker-custom-list-item)) {
|
||||
&:empty {
|
||||
display: none;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user