summaryrefslogtreecommitdiff
path: root/Userland/Applications/Browser
diff options
context:
space:
mode:
authorSam Atkins <atkinssj@serenityos.org>2021-10-23 17:35:14 +0100
committerLinus Groh <mail@linusgroh.de>2021-10-31 18:39:13 +0100
commit2c901ae2beeb3520e1d65ae1561dbd017ef4bd2f (patch)
tree1b7a1d3f01756304c446875f62d1391329d8d673 /Userland/Applications/Browser
parent84414da546fc3449944b513f31aaa6811663d643 (diff)
downloadserenity-2c901ae2beeb3520e1d65ae1561dbd017ef4bd2f.zip
Browser: Add "Color scheme" setting
This allows the user to override whether to use a dark or light theme in supporting websites.
Diffstat (limited to 'Userland/Applications/Browser')
-rw-r--r--Userland/Applications/Browser/BrowserWindow.cpp26
-rw-r--r--Userland/Applications/Browser/BrowserWindow.h1
2 files changed, 27 insertions, 0 deletions
diff --git a/Userland/Applications/Browser/BrowserWindow.cpp b/Userland/Applications/Browser/BrowserWindow.cpp
index 824ee735c3..32f8ea12ea 100644
--- a/Userland/Applications/Browser/BrowserWindow.cpp
+++ b/Userland/Applications/Browser/BrowserWindow.cpp
@@ -1,6 +1,7 @@
/*
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2021, Jakob-Niklas See <git@nwex.de>
+ * Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@@ -29,6 +30,7 @@
#include <LibGUI/ToolbarContainer.h>
#include <LibGUI/Widget.h>
#include <LibJS/Interpreter.h>
+#include <LibWeb/CSS/PreferredColorScheme.h>
#include <LibWeb/Dump.h>
#include <LibWeb/Layout/InitialContainingBlock.h>
#include <LibWeb/Loader/ResourceLoader.h>
@@ -298,6 +300,30 @@ void BrowserWindow::build_menus()
custom_search_engine_action->set_status_tip(g_search_engine);
}
+ auto& color_scheme_menu = settings_menu.add_submenu("&Color Scheme");
+ color_scheme_menu.set_icon(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/color-chooser.png"));
+ {
+ auto current_setting = Web::CSS::preferred_color_scheme_from_string(Config::read_string("Browser", "Preferences", "ColorScheme", "auto"));
+ m_color_scheme_actions.set_exclusive(true);
+
+ auto add_color_scheme_action = [&](auto& name, Web::CSS::PreferredColorScheme preference_value) {
+ auto action = GUI::Action::create_checkable(
+ name, [=, this](auto&) {
+ Config::write_string("Browser", "Preferences", "ColorScheme", Web::CSS::preferred_color_scheme_to_string(preference_value));
+ active_tab().m_web_content_view->set_preferred_color_scheme(preference_value);
+ },
+ this);
+ if (current_setting == preference_value)
+ action->set_checked(true);
+ color_scheme_menu.add_action(action);
+ m_color_scheme_actions.add_action(action);
+ };
+
+ add_color_scheme_action("Follow system theme", Web::CSS::PreferredColorScheme::Auto);
+ add_color_scheme_action("Light", Web::CSS::PreferredColorScheme::Light);
+ add_color_scheme_action("Dark", Web::CSS::PreferredColorScheme::Dark);
+ }
+
auto& debug_menu = add_menu("&Debug");
debug_menu.add_action(GUI::Action::create(
"Dump &DOM Tree", [this](auto&) {
diff --git a/Userland/Applications/Browser/BrowserWindow.h b/Userland/Applications/Browser/BrowserWindow.h
index 79716b9143..baacc1585a 100644
--- a/Userland/Applications/Browser/BrowserWindow.h
+++ b/Userland/Applications/Browser/BrowserWindow.h
@@ -60,6 +60,7 @@ private:
GUI::ActionGroup m_user_agent_spoof_actions;
GUI::ActionGroup m_search_engine_actions;
+ GUI::ActionGroup m_color_scheme_actions;
RefPtr<GUI::Action> m_disable_user_agent_spoofing;
RefPtr<GUI::Action> m_disable_search_engine_action;
RefPtr<GUI::Action> m_change_homepage_action;