Truly independent web browser
LibWebView: Offer the color theme on the welcome page
Andreas Klinga1070c5522d9
diff --git a/Base/res/ladybird/about-pages/welcome.html b/Base/res/ladybird/about-pages/welcome.htmlindex 34cfe90c22e..07908bf0d51 100644--- a/Base/res/ladybird/about-pages/welcome.html+++ b/Base/res/ladybird/about-pages/welcome.html@@ -89,6 +89,41 @@ SPDX-License-Identifier: BSD-2-Clause</label></div></section>+ <section aria-labelledby="color-theme-title">+ <h2 id="color-theme-title">Color</h2>+ <div id="color-theme" class="color-swatches" role="radiogroup" aria-labelledby="color-theme-title">+ <label class="color-swatch system-swatch" title="System" style="--swatch: #8e8e93">+ <input type="radio" name="color-theme" value="neutral" aria-label="System" />+ </label>+ <label class="color-swatch" title="Harbor" style="--swatch: #2f6fd6">+ <input type="radio" name="color-theme" value="harbor" aria-label="Harbor" />+ </label>+ <label class="color-swatch" title="Glacier" style="--swatch: #1798b8">+ <input type="radio" name="color-theme" value="glacier" aria-label="Glacier" />+ </label>+ <label class="color-swatch" title="Lagoon" style="--swatch: #12957f">+ <input type="radio" name="color-theme" value="lagoon" aria-label="Lagoon" />+ </label>+ <label class="color-swatch" title="Moss" style="--swatch: #3b8f3e">+ <input type="radio" name="color-theme" value="moss" aria-label="Moss" />+ </label>+ <label class="color-swatch" title="Saffron" style="--swatch: #c99500">+ <input type="radio" name="color-theme" value="saffron" aria-label="Saffron" />+ </label>+ <label class="color-swatch" title="Copper" style="--swatch: #d0631c">+ <input type="radio" name="color-theme" value="copper" aria-label="Copper" />+ </label>+ <label class="color-swatch" title="Cherry" style="--swatch: #d1344b">+ <input type="radio" name="color-theme" value="cherry" aria-label="Cherry" />+ </label>+ <label class="color-swatch" title="Blossom" style="--swatch: #d2459a">+ <input type="radio" name="color-theme" value="blossom" aria-label="Blossom" />+ </label>+ <label class="color-swatch" title="Lavender" style="--swatch: #7563d4">+ <input type="radio" name="color-theme" value="lavender" aria-label="Lavender" />+ </label>+ </div>+ </section><section class="switch-card" aria-labelledby="ad-blocking-title"><div><h2 id="ad-blocking-title">Block ads, trackers and more</h2>diff --git a/Base/res/ladybird/about-pages/welcome.js b/Base/res/ladybird/about-pages/welcome.jsindex 326b63f9886..175a882d3c2 100644--- a/Base/res/ladybird/about-pages/welcome.js+++ b/Base/res/ladybird/about-pages/welcome.js@@ -12,6 +12,7 @@ const searchSuggestions = document.querySelector("#search-suggestions");const searchSuggestionsEnabled = document.querySelector("#search-suggestions-enabled");const searchSuggestionsDescription = document.querySelector("#search-suggestions-description");const tabLayoutInputs = document.querySelectorAll('input[name="tab-layout"]');+const colorThemeInputs = document.querySelectorAll('input[name="color-theme"]');const enableContentBlocking = document.querySelector("#enable-content-blocking");const saveStatus = document.querySelector("#save-status");@@ -101,12 +102,18 @@ function updateTabLayout() {for (const input of tabLayoutInputs) input.checked = input.value === layout;}+function updateColorTheme() {+ const colorTheme = settings.appearance.colorTheme || "neutral";+ for (const input of colorThemeInputs) input.checked = input.value === colorTheme;+}+function initialize() {if (initialized || !settings || !engines || !features) return;initialized = true;document.querySelector("#tab-layout-section").classList.toggle("hidden", !features.verticalTabs);updateTabLayout();+ updateColorTheme();renderSearchEngines();updateSearchSuggestions();@@ -129,6 +136,16 @@ for (const input of tabLayoutInputs) {});}+// Picking a color recolors the window around the page at once.+for (const input of colorThemeInputs) {+ input.addEventListener("change", () => {+ if (!initialized || !input.checked) return;+ // NB: Keep our copy current, as the settings update for this change can arrive after the next one is made.+ settings.appearance = { ...settings.appearance, colorTheme: input.value };+ ladybird.sendMessage("setAppearance", settings.appearance);+ });+}+searchSuggestionsEnabled.addEventListener("change", () => {if (!initialized) return;setSearchEngineSettings(settings.searchEngine.engine, searchSuggestionsEnabled.checked);@@ -171,6 +188,7 @@ document.addEventListener("WebUIMessage", event => {if (initialized) {if (Object.hasOwn(data, "tabs")) updateTabLayout();+ if (Object.hasOwn(data, "appearance")) updateColorTheme();if (Object.hasOwn(data, "searchEngine")) {for (const radio of searchEngines.querySelectorAll("input"))radio.checked = radio.value === settings.searchEngine.engine;diff --git a/Documentation/UI/QuietDesign.md b/Documentation/UI/QuietDesign.mdindex 087d3efa34d..6e5b9f0604d 100644--- a/Documentation/UI/QuietDesign.md+++ b/Documentation/UI/QuietDesign.md@@ -617,7 +617,9 @@ never shows "about:blank".with version, build and platform plus a Copy button. Nothing else.- Welcome (`about:welcome`): the logomark at 56 px (0.85 line, so it doesn't get heavy), the title, then one centered column, in this order: search engine (optional,nothing preselected, engines in a new random order each time, so none is favored by its- place), Layout (all three layouts), content blocking switch, "Start browsing" (enabled as soon as the+ place; shown by name only in a five-column grid, never with logos or letter tiles, which+ would mean shipping other companies' trademarks or contacting their servers before anyone+ has chosen), Layout (all three layouts), Color, content blocking switch, "Start browsing" (enabled as soon as thecurrent settings are loaded; it never waits for a choice).- Error pages: icon, title, one line of detail, buttons, centered like every othersingle-message page ("Report sent"). Security errors may use two lines, because the@@ -632,6 +634,12 @@ never shows "about:blank".named "General" or "Other" collects settings nobody could find.- Appearance, top to bottom: Theme, Color theme, Website appearance, Force dark mode,Layout, Show bookmarks bar, Default page zoom.+- Color theme is a row of round swatches. The first is System (a multicolor wheel, as in+ macOS), selected by default: the browser follows the OS accent until someone picks a+ color. Names live in tooltips and accessible names, never under the swatches. The+ welcome page shows the same row under "Color", right after Layout, and picking a swatch+ there recolors the real window around the page at once; that live change is the point of+ having it on the welcome page.- Layout is three picture cards: Tabs on top, Tabs on the side, Everything in the sidebar.It is called Layout, not Tabs, because the third choice moves the toolbar too. Eachlabel names what is different about it, and each picture draws the address field wherediff --git a/Libraries/LibWebView/WebUI/SettingsUI.cpp b/Libraries/LibWebView/WebUI/SettingsUI.cppindex 5b8d1e515ed..bb341d1309a 100644--- a/Libraries/LibWebView/WebUI/SettingsUI.cpp+++ b/Libraries/LibWebView/WebUI/SettingsUI.cpp@@ -115,6 +115,9 @@ void SettingsUI::register_interfaces()register_interface("setFilterListUpdatesEnabled"sv, [this](auto const& data) {set_filter_list_updates_enabled(data);});+ register_interface("setAppearance"sv, [this](auto const& data) {+ set_appearance(data);+ });if (host() == "welcome"sv) {register_interface("completeFirstRun"sv, [this](auto const& data) {@@ -144,9 +147,6 @@ void SettingsUI::register_interfaces()register_interface("setLanguages"sv, [this](auto const& data) {set_languages(data);});- register_interface("setAppearance"sv, [this](auto const& data) {- set_appearance(data);- });register_interface("resetForceDarkForHost"sv, [this](auto const& data) {reset_force_dark_for_host(data);});