mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 05:17:34 +00:00
Browser: Add "Color scheme" setting
This allows the user to override whether to use a dark or light theme in supporting websites.
This commit is contained in:
parent
84414da546
commit
2c901ae2be
2 changed files with 27 additions and 0 deletions
|
@ -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&) {
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue