Truly independent web browser
LibWebView: Add a color theme setting
Andreas Klinga4b6ed4e34b5
diff --git a/Base/res/ladybird/about-pages/settings.html b/Base/res/ladybird/about-pages/settings.htmlindex 80e3ab533d5..04c35a09182 100644--- a/Base/res/ladybird/about-pages/settings.html+++ b/Base/res/ladybird/about-pages/settings.html@@ -921,6 +921,46 @@<label><input type="radio" name="interface-theme" value="dark" />Dark</label></div></div>+ <div class="card-group inline-container">+ <span id="color-theme-title">+ Color theme+ <p class="description">The colors of tabs, toolbars, menus and highlights.</p>+ </span>+ <div+ id="color-theme"+ class="color-swatches"+ role="radiogroup"+ aria-labelledby="color-theme-title"+ >+ <label class="color-swatch" title="Neutral" style="--swatch: #8e8e93">+ <input type="radio" name="color-theme" value="neutral" aria-label="Neutral" />+ </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>+ </div>+ </div><div class="card-group inline-container"><span>Website appearancediff --git a/Base/res/ladybird/about-pages/settings/appearance.js b/Base/res/ladybird/about-pages/settings/appearance.jsindex 831a1b44f60..eba869cc555 100644--- a/Base/res/ladybird/about-pages/settings/appearance.js+++ b/Base/res/ladybird/about-pages/settings/appearance.js@@ -3,6 +3,7 @@ const showMenuBarGroup = document.querySelector("#show-menu-bar-group");const showBookmarksBar = document.querySelector("#show-bookmarks-bar");const interfaceTheme = document.querySelector("#interface-theme");const websiteColorScheme = document.querySelector("#website-color-scheme");+const colorTheme = document.querySelector("#color-theme");function segmentedValue(control) {return control.querySelector("input:checked")?.value;@@ -29,6 +30,7 @@ const loadSettings = settings => {showBookmarksBar.value = APPEARANCE.showBookmarksBar || "never";setSegmentedValue(interfaceTheme, APPEARANCE.interfaceTheme || "system");setSegmentedValue(websiteColorScheme, APPEARANCE.websiteColorScheme || "system");+ setSegmentedValue(colorTheme, APPEARANCE.colorTheme || "neutral");};function saveAppearance() {@@ -50,6 +52,11 @@ interfaceTheme.addEventListener("change", () => {saveAppearance();});+colorTheme.addEventListener("change", () => {+ APPEARANCE.colorTheme = segmentedValue(colorTheme);+ saveAppearance();+});+websiteColorScheme.addEventListener("change", () => {APPEARANCE.websiteColorScheme = segmentedValue(websiteColorScheme);saveAppearance();diff --git a/Base/res/ladybird/ladybird.css b/Base/res/ladybird/ladybird.cssindex e0922bd063d..2382ba41d2d 100644--- a/Base/res/ladybird/ladybird.css+++ b/Base/res/ladybird/ladybird.css@@ -512,6 +512,42 @@ input[type="checkbox"][switch]:checked::before {flex-direction: column;}+/* A color theme is chosen from a row of dots in its base colors. The chosen dot is ringed in its own color. */+.color-swatches {+ display: flex;+ flex-wrap: wrap;+ gap: 10px;+}++.color-swatch {+ width: 20px;+ height: 20px;+ margin: 0;+ border-radius: 50%;+ background: var(--swatch);+ box-shadow: inset 0 0 0 1px var(--edge);+ cursor: pointer;+}++.color-swatch:has(input:checked) {+ box-shadow:+ 0 0 0 2px var(--page),+ 0 0 0 4px var(--swatch);+}++.color-swatch:has(input:focus-visible) {+ box-shadow:+ 0 0 0 2px var(--page),+ 0 0 0 4px var(--swatch),+ 0 0 0 7px var(--focus-ring);+}++.color-swatch input {+ position: absolute;+ opacity: 0;+ pointer-events: none;+}+/* A search engine is pictured by a small tile with its initial. */.letter-tile {display: flex;diff --git a/Libraries/LibWebView/Settings.cpp b/Libraries/LibWebView/Settings.cppindex 2383e143e69..3fbd204682e 100644--- a/Libraries/LibWebView/Settings.cpp+++ b/Libraries/LibWebView/Settings.cpp@@ -35,6 +35,7 @@ static constexpr auto SHOW_MENU_BAR_KEY = "showMenuBar"sv;static constexpr auto SHOW_BOOKMARKS_BAR_KEY = "showBookmarksBar"sv;static constexpr auto INTERFACE_THEME_KEY = "interfaceTheme"sv;static constexpr auto WEBSITE_COLOR_SCHEME_KEY = "websiteColorScheme"sv;+static constexpr auto COLOR_THEME_KEY = "colorTheme"sv;static constexpr auto WINDOW_SETTINGS_KEY = "window"sv;static constexpr auto WINDOW_POSITION_KEY = "position"sv;@@ -280,6 +281,28 @@ static constexpr Optional<ThemePreference> theme_preference_from_string(StringVireturn {};}+static constexpr StringView color_theme_to_string(ColorTheme theme)+{+ switch (theme) {+#define __ENUMERATE_COLOR_THEME(name, string) \+ case ColorTheme::name: \+ return string##sv;+ ENUMERATE_COLOR_THEMES(__ENUMERATE_COLOR_THEME)+#undef __ENUMERATE_COLOR_THEME+ }+ VERIFY_NOT_REACHED();+}++static constexpr Optional<ColorTheme> color_theme_from_string(StringView theme)+{+#define __ENUMERATE_COLOR_THEME(name, string) \+ if (theme == string##sv) \+ return ColorTheme::name;+ ENUMERATE_COLOR_THEMES(__ENUMERATE_COLOR_THEME)+#undef __ENUMERATE_COLOR_THEME+ return {};+}+static constexpr StringView vertical_tabs_position_to_string(VerticalTabsPosition position){switch (position) {@@ -616,6 +639,7 @@ JsonValue Settings::serialize_json() constappearance.set(SHOW_BOOKMARKS_BAR_KEY, show_bookmarks_bar_to_string(m_appearance.show_bookmarks_bar));appearance.set(INTERFACE_THEME_KEY, theme_preference_to_string(m_appearance.interface_theme));appearance.set(WEBSITE_COLOR_SCHEME_KEY, theme_preference_to_string(m_appearance.website_color_scheme));+ appearance.set(COLOR_THEME_KEY, color_theme_to_string(m_appearance.color_theme));settings.set(APPEARANCE_KEY, move(appearance));JsonObject zoom_per_host;@@ -899,6 +923,10 @@ Appearance Settings::parse_appearance(JsonValue const& settings)if (auto parsed = theme_preference_from_string(*website_color_scheme); parsed.has_value())appearance.website_color_scheme = *parsed;}+ if (auto color_theme = settings.as_object().get_string(COLOR_THEME_KEY); color_theme.has_value()) {+ if (auto parsed = color_theme_from_string(*color_theme); parsed.has_value())+ appearance.color_theme = *parsed;+ }return appearance;}diff --git a/Libraries/LibWebView/Settings.h b/Libraries/LibWebView/Settings.hindex 2e4bf4772c2..3cb8870d5c2 100644--- a/Libraries/LibWebView/Settings.h+++ b/Libraries/LibWebView/Settings.h@@ -44,11 +44,30 @@ enum class ThemePreference : u8 {Dark,};+// The colors of the browser's own tabs, toolbars and menus. Each theme is made from one or two base colors.+#define ENUMERATE_COLOR_THEMES(X) \+ X(Neutral, "neutral") \+ X(Harbor, "harbor") \+ X(Glacier, "glacier") \+ X(Lagoon, "lagoon") \+ X(Moss, "moss") \+ X(Saffron, "saffron") \+ X(Copper, "copper") \+ X(Cherry, "cherry") \+ X(Blossom, "blossom")++enum class ColorTheme : u8 {+#define __ENUMERATE_COLOR_THEME(name, string) name,+ ENUMERATE_COLOR_THEMES(__ENUMERATE_COLOR_THEME)+#undef __ENUMERATE_COLOR_THEME+};+struct Appearance {bool show_menu_bar { false };ShowBookmarksBar show_bookmarks_bar { ShowBookmarksBar::Never };ThemePreference interface_theme { ThemePreference::System };ThemePreference website_color_scheme { ThemePreference::System };+ ColorTheme color_theme { ColorTheme::Neutral };};struct ContentSettings {