From 732b2a4624afdebedbc094262f7bb02a424153e4 Mon Sep 17 00:00:00 2001 From: Alex Kontos Date: Tue, 5 Aug 2025 16:54:47 +0100 Subject: [PATCH] refactor: about:preferences * feat: Waterfox custom CSS on non-default themes by default * feat: Table of Contents to preferences * feat: DoOH checkbox to privacy preferences * feat panel and menu transparency options * feat: Look & Feel about:preferences item --- browser/components/preferences/main.js | 32 +- .../components/preferences/content/general.js | 142 +- .../content/preferences-general.xhtml | 16 +- .../content/preferences-other.xhtml | 10 +- .../content/preferences-theme.xhtml | 854 ++++++----- .../components/preferences/content/privacy.js | 33 +- .../components/preferences/content/theme.js | 493 +++--- .../components/preferences/content/tocbot.css | 104 ++ .../components/preferences/content/tocbot.js | 1363 +++++++++++++++++ .../preferences/images/autoblur_tab.gif | Bin 305702 -> 0 bytes .../preferences/images/autoblur_tab.png | Bin 0 -> 9828 bytes .../preferences/images/autohide_back.gif | Bin 58315 -> 0 bytes .../preferences/images/autohide_back.png | Bin 0 -> 1852 bytes .../images/autohide_bookmarksbar.gif | Bin 252796 -> 0 bytes .../preferences/images/autohide_forward.gif | Bin 54294 -> 0 bytes .../preferences/images/autohide_forward.png | Bin 0 -> 3565 bytes .../preferences/images/autohide_navbar.gif | Bin 346974 -> 0 bytes .../images/autohide_pageaction.gif | Bin 56583 -> 0 bytes .../preferences/images/autohide_sidebar.gif | Bin 2979093 -> 0 bytes .../preferences/images/autohide_sidebar.png | Bin 0 -> 16906 bytes .../preferences/images/autohide_tab.gif | Bin 206276 -> 0 bytes .../preferences/images/autohide_tab.png | Bin 0 -> 7459 bytes .../preferences/images/autohide_tabbar.gif | Bin 373023 -> 0 bytes .../preferences/images/bookmarkbar_icon.png | Bin 6772 -> 2893 bytes .../preferences/images/bookmarkbar_label.png | Bin 10588 -> 5653 bytes .../preferences/images/close_button_hover.png | Bin 3667 -> 12363 bytes .../preferences/images/disabled_menu.png | Bin 94009 -> 24771 bytes .../images/disabled_menu_hidden.png | Bin 6667 -> 0 bytes .../images/disabled_menu_shown.png | Bin 12741 -> 0 bytes .../preferences/images/drag_space.png | Bin 31151 -> 8958 bytes .../images/full_panel_separator.png | Bin 11840 -> 5049 bytes .../preferences/images/hide_iconbox.png | Bin 40881 -> 8567 bytes .../preferences/images/hide_tabicon.png | Bin 14550 -> 0 bytes .../preferences/images/mac_icons.png | Bin 97985 -> 26358 bytes .../preferences/images/media_player.png | Bin 547579 -> 0 bytes .../preferences/images/monospace_font.png | Bin 63903 -> 13266 bytes .../preferences/images/monospace_theme.png | Bin 177073 -> 16187 bytes .../preferences/images/navbar_center.png | Bin 4346 -> 6749 bytes .../preferences/images/navbar_text.png | Bin 4183 -> 0 bytes .../preferences/images/no_drag_space.png | Bin 30971 -> 0 bytes .../preferences/images/no_panel_separator.png | Bin 11702 -> 4890 bytes .../preferences/images/panel_animate.gif | Bin 302447 -> 0 bytes .../preferences/images/panel_no_animate.gif | Bin 124385 -> 0 bytes .../preferences/images/panel_separator.png | Bin 11836 -> 5095 bytes .../preferences/images/show_tabicon.png | Bin 15571 -> 0 bytes .../preferences/images/sidebar_animate.gif | Bin 2146154 -> 0 bytes .../preferences/images/sidebar_header.png | Bin 23679 -> 0 bytes .../preferences/images/sidebar_no_animate.gif | Bin 1094330 -> 0 bytes .../preferences/images/sidebar_no_header.png | Bin 21643 -> 8088 bytes .../preferences/images/smooth_button.png | Bin 7359 -> 0 bytes .../preferences/images/smooth_field.png | Bin 4855 -> 0 bytes .../preferences/images/smooth_panel.png | Bin 42947 -> 0 bytes .../preferences/images/smooth_popup.png | Bin 6639 -> 0 bytes .../preferences/images/square_button.png | Bin 7096 -> 2568 bytes .../images/square_button_compare.png | Bin 49871 -> 0 bytes .../preferences/images/square_field.png | Bin 4580 -> 2619 bytes .../preferences/images/square_panel.png | Bin 42271 -> 14263 bytes .../preferences/images/square_popup.png | Bin 6413 -> 2764 bytes .../preferences/images/tab_center.png | Bin 15369 -> 8713 bytes .../preferences/images/tab_contextline.png | Bin 0 -> 8389 bytes .../preferences/images/tab_label.png | Bin 14664 -> 8733 bytes .../preferences/images/tab_normal.png | Bin 14874 -> 0 bytes .../preferences/images/tab_square.png | Bin 29071 -> 9598 bytes .../preferences/images/urlbar_iconbox.png | Bin 4183 -> 0 bytes .../preferences/images/urlbar_no_iconbox.png | Bin 2636 -> 0 bytes .../browser/components/preferences/jar.mn | 2 + waterfox/browser/themes/waterfox/general.css | 42 +- 67 files changed, 2425 insertions(+), 666 deletions(-) create mode 100644 waterfox/browser/components/preferences/content/tocbot.css create mode 100644 waterfox/browser/components/preferences/content/tocbot.js delete mode 100644 waterfox/browser/components/preferences/images/autoblur_tab.gif create mode 100644 waterfox/browser/components/preferences/images/autoblur_tab.png delete mode 100644 waterfox/browser/components/preferences/images/autohide_back.gif create mode 100644 waterfox/browser/components/preferences/images/autohide_back.png delete mode 100644 waterfox/browser/components/preferences/images/autohide_bookmarksbar.gif delete mode 100644 waterfox/browser/components/preferences/images/autohide_forward.gif create mode 100644 waterfox/browser/components/preferences/images/autohide_forward.png delete mode 100644 waterfox/browser/components/preferences/images/autohide_navbar.gif delete mode 100644 waterfox/browser/components/preferences/images/autohide_pageaction.gif delete mode 100644 waterfox/browser/components/preferences/images/autohide_sidebar.gif create mode 100644 waterfox/browser/components/preferences/images/autohide_sidebar.png delete mode 100644 waterfox/browser/components/preferences/images/autohide_tab.gif create mode 100644 waterfox/browser/components/preferences/images/autohide_tab.png delete mode 100644 waterfox/browser/components/preferences/images/autohide_tabbar.gif delete mode 100644 waterfox/browser/components/preferences/images/disabled_menu_hidden.png delete mode 100644 waterfox/browser/components/preferences/images/disabled_menu_shown.png delete mode 100644 waterfox/browser/components/preferences/images/hide_tabicon.png delete mode 100644 waterfox/browser/components/preferences/images/media_player.png delete mode 100644 waterfox/browser/components/preferences/images/navbar_text.png delete mode 100644 waterfox/browser/components/preferences/images/no_drag_space.png delete mode 100644 waterfox/browser/components/preferences/images/panel_animate.gif delete mode 100644 waterfox/browser/components/preferences/images/panel_no_animate.gif delete mode 100644 waterfox/browser/components/preferences/images/show_tabicon.png delete mode 100644 waterfox/browser/components/preferences/images/sidebar_animate.gif delete mode 100644 waterfox/browser/components/preferences/images/sidebar_header.png delete mode 100644 waterfox/browser/components/preferences/images/sidebar_no_animate.gif delete mode 100644 waterfox/browser/components/preferences/images/smooth_button.png delete mode 100644 waterfox/browser/components/preferences/images/smooth_field.png delete mode 100644 waterfox/browser/components/preferences/images/smooth_panel.png delete mode 100644 waterfox/browser/components/preferences/images/smooth_popup.png delete mode 100644 waterfox/browser/components/preferences/images/square_button_compare.png create mode 100644 waterfox/browser/components/preferences/images/tab_contextline.png delete mode 100644 waterfox/browser/components/preferences/images/tab_normal.png delete mode 100644 waterfox/browser/components/preferences/images/urlbar_iconbox.png delete mode 100644 waterfox/browser/components/preferences/images/urlbar_no_iconbox.png diff --git a/browser/components/preferences/main.js b/browser/components/preferences/main.js index bec54fd56f46..cf62774eb99f 100644 --- a/browser/components/preferences/main.js +++ b/browser/components/preferences/main.js @@ -190,7 +190,6 @@ Preferences.addAll([ // WATERFOX // Enable auto update checking { id: "app.update.enabled", type: "bool" }, - ]); if (AppConstants.HAVE_SHELL_SERVICE) { @@ -2630,11 +2629,19 @@ var gMainPane = { let radiogroup = document.getElementById("updateRadioGroup"); radiogroup.disabled = true; - let enabled = await UpdateUtils.getAppUpdateAutoEnabled(); + let autoPref = await UpdateUtils.getAppUpdateAutoEnabled(); // WATERFOX // If user sets app.update.enabled to false, set value to disabled, else use enabled - let manualUpdates = Services.prefs.getBoolPref(PREF_UPDATE_ENABLED, true); - radiogroup.value = !manualUpdates ? "disabled" : enabled; + var enabledPref = Preferences.get("app.update.enabled"); + + if (!enabledPref.value) { + // Don't care for autoPref.value in this case. + radiogroup.value = "disabled"; // 3. Never check for updates. + } else if (autoPref.value) { + radiogroup.value = "true"; //1. Automatically install updates + } else { + radiogroup.value = "false"; // 2. Check, but let me choose + } radiogroup.disabled = false; this.maybeDisableBackgroundUpdateControls(); @@ -2657,14 +2664,15 @@ var gMainPane = { ); radiogroup.disabled = true; try { - await UpdateUtils.setAppUpdateAutoEnabled(updateAutoValue); - await _disableTimeOverPromise; - // WATERFOX - // Ensure enabled pref is updated based on radiogroup value + // We need to set this pref first so that the auto pref observer + // has access to the correct enabled pref value. Services.prefs.setBoolPref( PREF_UPDATE_ENABLED, radiogroup.value != "disabled" ); + await UpdateUtils.setAppUpdateAutoEnabled(updateAutoValue); + await _disableTimeOverPromise; + radiogroup.disabled = false; } catch (error) { console.error(error); @@ -2880,16 +2888,14 @@ var gMainPane = { throw new Error("Invalid preference value for app.update.auto"); } // WATERFOX - // Going from Auto to Disable needs to be correctly reflected here - // At this point app.update.enabled has not yet been set, so we - // want to set disabled if it is going from true->false and is - // currently true let manualUpdates = Services.prefs.getBoolPref( "app.update.enabled", true ); + // Only if enabledPref and autoPref are false should we select + // disabled, otherwise we just use the value of autoPref. document.getElementById("updateRadioGroup").value = - manualUpdates && !(aData === "true") ? "disabled" : aData; + !manualUpdates && !(aData === "true") ? "disabled" : aData; this.maybeDisableBackgroundUpdateControls(); } else if (aTopic == BACKGROUND_UPDATE_CHANGED_TOPIC) { if (!AppConstants.MOZ_UPDATE_AGENT) { diff --git a/waterfox/browser/components/preferences/content/general.js b/waterfox/browser/components/preferences/content/general.js index dd463ca3d21d..36fbf9819276 100644 --- a/waterfox/browser/components/preferences/content/general.js +++ b/waterfox/browser/components/preferences/content/general.js @@ -1,11 +1,4 @@ -/* 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/. */ - -/* eslint-env mozilla/browser-window */ -"use strict"; - -const gMainPaneOverlay = { +const _gMainPaneOverlay = { init() { // Initialize prefs window.Preferences.addAll(this.preferences); @@ -60,6 +53,9 @@ const gMainPaneOverlay = { // Scripts { id: "javascript.enabled", type: "bool" }, + + // DoOH + { id: "network.trr.use_ohttp", type: "bool" }, ]; }, @@ -72,15 +68,115 @@ const gMainPaneOverlay = { // Select the correct radio button based on current pref value this.showRelevantElements(); this.setDynamicThemeGroupValue(); - this.setEventListener("dynamicThemeGroup", "command", event => { + this.setEventListener("dynamicThemeGroup", "command", (event) => { this.updateDynamicThemePref(event.target.value); }); + if (document.readyState === "complete") { + this.tocGenerate(); + } else { + document.addEventListener("readystatechange", () => { + if (document.readyState === "complete") { + this.tocGenerate(); + } + }); + } document.initialized = true; } + this.setEventListener("enableObliviousDns", "click", () => { + const value = document.getElementById("enableObliviousDns").checked ? 2 : 0; + Services.prefs.setIntPref("network.trr.mode", value); + }); }, + tocGenerate() { + const contentSelector = "#mainPrefPane"; + const headingSelector = + "#mainPrefPane > hbox:not([hidden]) > h1, #mainPrefPane > groupbox:not([hidden]) > h2, #mainPrefPane > groupbox:not([hidden]) label:not([hidden]) > h2"; + const headerTarget = headingSelector.replaceAll(":not([hidden])", ""); + const specialCharRegex = /[!@#$%^&*():]/gi; + const createHeadingId = () => { + const content = document.querySelector(contentSelector); + const headings = content?.querySelectorAll(headerTarget); + const headingMap = {}; + + let count = 0; + /** + * @param {Element} heading + * @returns {string} + */ + const getHeadingId = (heading) => { + const id = heading.id; + if (id) { + return id; + } + + if (heading instanceof HTMLElement) { + const i18nId = heading.dataset.l10nId; + if (i18nId) { + return i18nId; + } + } + + return ( + heading.textContent + ?.trim() + .toLowerCase() + .split(" ") + .join("-") + .replace(specialCharRegex, "") ?? `${count++}` + ); + }; + /** + * @param {string} headingText + * @param {number} count + * @returns {string} + */ + const createId = (headingText, count) => + `${headingText}${count > 0 ? `-${count}` : ""}`; + if (headings) { + for (const heading of headings) { + const id = getHeadingId(heading); + headingMap[id] = !Number.isNaN(headingMap[id]) ? ++headingMap[id] : 0; + heading.id = createId(id, headingMap[id]); + } + } + }; + + createHeadingId(); + tocbot.init({ + tocSelector: ".toc", + contentSelector, + headingSelector, + scrollContainer: ".main-content", + headingsOffset: 100, // 90 + margins + hasInnerContainers: false, + + /** + * @param {MouseEvent} e + */ + onClick(e) { + e.preventDefault(); + + /** @type {HTMLLinkElement} */ + const link = e.target; + const targetSelector = link?.getAttribute("href"); + if (targetSelector) { + const target = document.querySelector(targetSelector); + if (target) { + target.scrollIntoView({ behavior: "smooth", block: "start" }); + } + } + }, + }); + const tocRefresh = () => { + createHeadingId(); + tocbot.refresh(); + }; + window.addEventListener("hashchange", tocRefresh); + }, + showRelevantElements() { - let idsGeneral = [ + const idsGeneral = [ "dynamicThemeGroup", "restartGroup", "statusBarGroup", @@ -88,25 +184,25 @@ const gMainPaneOverlay = { "geolocationGroup", ]; - let idsPrivacy = ["webrtc", "refheader"]; - let win = Services.wm.getMostRecentWindow("navigator:browser"); - let uri = win.gBrowser.currentURI.spec; + const idsPrivacy = ["webrtc", "refheader", "dohBox"]; + const win = Services.wm.getMostRecentWindow("navigator:browser"); + const uri = win.gBrowser.currentURI.spec; if ( - (uri == "about:preferences" || uri == "about:preferences#general") && - document.visibilityState == "visible" + (uri === "about:preferences" || uri === "about:preferences#general") && + document.visibilityState === "visible" ) { - for (let id of idsGeneral) { - let el = document.getElementById(id); + for (const id of idsGeneral) { + const el = document.getElementById(id); if (el) { el.removeAttribute("hidden"); } } } else if ( - uri == "about:preferences#privacy" && - document.visibilityState == "visible" + uri === "about:preferences#privacy" && + document.visibilityState === "visible" ) { - for (let id of idsPrivacy) { - let el = document.getElementById(id); + for (const id of idsPrivacy) { + const el = document.getElementById(id); if (el) { el.removeAttribute("hidden"); } @@ -117,11 +213,11 @@ const gMainPaneOverlay = { setEventListener(aId, aEventType, aCallback) { document .getElementById(aId) - ?.addEventListener(aEventType, aCallback.bind(gMainPaneOverlay)); + ?.addEventListener(aEventType, aCallback.bind(_gMainPaneOverlay)); }, async setDynamicThemeGroupValue() { - let radiogroup = document.getElementById("dynamicThemeRadioGroup"); + const radiogroup = document.getElementById("dynamicThemeRadioGroup"); radiogroup.disabled = true; radiogroup.value = Services.prefs.getIntPref("ui.systemUsesDarkTheme", -1); diff --git a/waterfox/browser/components/preferences/content/preferences-general.xhtml b/waterfox/browser/components/preferences/content/preferences-general.xhtml index 351f13e3de80..bbb719480ef6 100644 --- a/waterfox/browser/components/preferences/content/preferences-general.xhtml +++ b/waterfox/browser/components/preferences/content/preferences-general.xhtml @@ -3,23 +3,21 @@ + - - + + @@ -124,6 +122,8 @@ #endif + + diff --git a/waterfox/browser/components/preferences/content/preferences-other.xhtml b/waterfox/browser/components/preferences/content/preferences-other.xhtml index 9cf16212423a..7088c2e3ca30 100644 --- a/waterfox/browser/components/preferences/content/preferences-other.xhtml +++ b/waterfox/browser/components/preferences/content/preferences-other.xhtml @@ -19,7 +19,7 @@ /* eslint-env mozilla/browser-window */ /* globals gPrivacyPaneOverlay */ Services.scriptloader.loadSubScript("chrome://browser/content/overlays/privacy.js", this); - gPrivacyPaneOverlay.init(); + _gPrivacyPaneOverlay.init(); @@ -67,5 +67,13 @@ preference="javascript.enabled" flex="1" /> + + + + + + + diff --git a/waterfox/browser/components/preferences/content/preferences-theme.xhtml b/waterfox/browser/components/preferences/content/preferences-theme.xhtml index 18d944bdf955..eb54a2882903 100644 --- a/waterfox/browser/components/preferences/content/preferences-theme.xhtml +++ b/waterfox/browser/components/preferences/content/preferences-theme.xhtml @@ -2,11 +2,11 @@