diff --git a/Libraries/LibWebView/Settings.cpp b/Libraries/LibWebView/Settings.cpp index c105d545743..0b9875aeee4 100644 --- a/Libraries/LibWebView/Settings.cpp +++ b/Libraries/LibWebView/Settings.cpp @@ -23,6 +23,9 @@ namespace WebView { static constexpr auto new_tab_page_url_key = "newTabPageURL"sv; +static constexpr auto default_zoom_level_factor_key = "defaultZoomLevelFactor"sv; +static constexpr double initial_zoom_level_factor = 1.0; + static constexpr auto languages_key = "languages"sv; static auto default_language = "en"_string; @@ -90,6 +93,9 @@ Settings Settings::create(Badge) settings.m_new_tab_page_url = parsed_new_tab_page_url.release_value(); } + if (auto factor = settings_json.value().get_double_with_precision_loss(default_zoom_level_factor_key); factor.has_value()) + settings.m_default_zoom_level_factor = factor.release_value(); + if (auto languages = settings_json.value().get(languages_key); languages.has_value()) settings.m_languages = parse_json_languages(*languages); @@ -147,6 +153,7 @@ Settings Settings::create(Badge) Settings::Settings(ByteString settings_path) : m_settings_path(move(settings_path)) , m_new_tab_page_url(URL::about_newtab()) + , m_default_zoom_level_factor(initial_zoom_level_factor) , m_languages({ default_language }) { } @@ -155,6 +162,7 @@ JsonValue Settings::serialize_json() const { JsonObject settings; settings.set(new_tab_page_url_key, m_new_tab_page_url.serialize()); + settings.set(default_zoom_level_factor_key, m_default_zoom_level_factor); JsonArray languages; languages.ensure_capacity(m_languages.size()); @@ -239,6 +247,7 @@ JsonValue Settings::serialize_json() const void Settings::restore_defaults() { m_new_tab_page_url = URL::about_newtab(); + m_default_zoom_level_factor = initial_zoom_level_factor; m_languages = { default_language }; m_search_engine.clear(); m_custom_search_engines.clear(); @@ -251,6 +260,7 @@ void Settings::restore_defaults() for (auto& observer : m_observers) { observer.new_tab_page_url_changed(); + observer.default_zoom_level_factor_changed(); observer.languages_changed(); observer.search_engine_changed(); observer.autocomplete_engine_changed(); @@ -269,6 +279,15 @@ void Settings::set_new_tab_page_url(URL::URL new_tab_page_url) observer.new_tab_page_url_changed(); } +void Settings::set_default_zoom_level_factor(double const zoom_level) +{ + m_default_zoom_level_factor = zoom_level; + persist_settings(); + + for (auto& observer : m_observers) + observer.default_zoom_level_factor_changed(); +} + Vector Settings::parse_json_languages(JsonValue const& languages) { if (!languages.is_array()) diff --git a/Libraries/LibWebView/Settings.h b/Libraries/LibWebView/Settings.h index 725d7548050..fa4fecd3de3 100644 --- a/Libraries/LibWebView/Settings.h +++ b/Libraries/LibWebView/Settings.h @@ -36,6 +36,7 @@ public: virtual ~SettingsObserver(); virtual void new_tab_page_url_changed() { } + virtual void default_zoom_level_factor_changed() { } virtual void languages_changed() { } virtual void search_engine_changed() { } virtual void autocomplete_engine_changed() { } @@ -55,6 +56,9 @@ public: URL::URL const& new_tab_page_url() const { return m_new_tab_page_url; } void set_new_tab_page_url(URL::URL); + double default_zoom_level_factor() const { return m_default_zoom_level_factor; } + void set_default_zoom_level_factor(double); + static Vector parse_json_languages(JsonValue const&); Vector const& languages() const { return m_languages; } void set_languages(Vector); @@ -95,6 +99,7 @@ private: ByteString m_settings_path; URL::URL m_new_tab_page_url; + double m_default_zoom_level_factor { 0 }; Vector m_languages; Optional m_search_engine; Vector m_custom_search_engines; diff --git a/Libraries/LibWebView/ViewImplementation.cpp b/Libraries/LibWebView/ViewImplementation.cpp index 3b9586405df..e60b5f755b1 100644 --- a/Libraries/LibWebView/ViewImplementation.cpp +++ b/Libraries/LibWebView/ViewImplementation.cpp @@ -601,6 +601,7 @@ void ViewImplementation::initialize_client(CreateNewClient create_new_client) if (auto const& user_agent_preset = Application::web_content_options().user_agent_preset; user_agent_preset.has_value()) client().async_debug_request(m_client_state.page_index, "spoof-user-agent"sv, *user_agents.get(*user_agent_preset)); + default_zoom_level_factor_changed(); languages_changed(); autoplay_settings_changed(); do_not_track_changed(); @@ -651,6 +652,12 @@ void ViewImplementation::handle_web_content_process_crash(LoadErrorPage load_err } } +void ViewImplementation::default_zoom_level_factor_changed() +{ + auto const default_zoom_level_factor = Application::settings().default_zoom_level_factor(); + set_zoom(default_zoom_level_factor); +} + void ViewImplementation::languages_changed() { auto const& languages = Application::settings().languages(); diff --git a/Libraries/LibWebView/ViewImplementation.h b/Libraries/LibWebView/ViewImplementation.h index 6e899a29184..73a2db2ef56 100644 --- a/Libraries/LibWebView/ViewImplementation.h +++ b/Libraries/LibWebView/ViewImplementation.h @@ -266,6 +266,7 @@ protected: }; void handle_web_content_process_crash(LoadErrorPage = LoadErrorPage::Yes); + virtual void default_zoom_level_factor_changed() override; virtual void languages_changed() override; virtual void autoplay_settings_changed() override; virtual void do_not_track_changed() override; diff --git a/Libraries/LibWebView/WebUI/SettingsUI.cpp b/Libraries/LibWebView/WebUI/SettingsUI.cpp index 95884782619..1b847404c48 100644 --- a/Libraries/LibWebView/WebUI/SettingsUI.cpp +++ b/Libraries/LibWebView/WebUI/SettingsUI.cpp @@ -24,6 +24,9 @@ void SettingsUI::register_interfaces() register_interface("setNewTabPageURL"sv, [this](auto const& data) { set_new_tab_page_url(data); }); + register_interface("setDefaultZoomLevelFactor"sv, [this](auto const& data) { + set_default_zoom_level_factor(data); + }); register_interface("setLanguages"sv, [this](auto const& data) { set_languages(data); }); @@ -93,6 +96,15 @@ void SettingsUI::set_new_tab_page_url(JsonValue const& new_tab_page_url) WebView::Application::settings().set_new_tab_page_url(parsed_new_tab_page_url.release_value()); } +void SettingsUI::set_default_zoom_level_factor(JsonValue const& default_zoom_level_factor) +{ + auto const maybe_factor = default_zoom_level_factor.get_double_with_precision_loss(); + if (!maybe_factor.has_value()) + return; + + WebView::Application::settings().set_default_zoom_level_factor(maybe_factor.value()); +} + void SettingsUI::set_languages(JsonValue const& languages) { auto parsed_languages = Settings::parse_json_languages(languages); diff --git a/Libraries/LibWebView/WebUI/SettingsUI.h b/Libraries/LibWebView/WebUI/SettingsUI.h index acdedcc967b..6a65f8ae838 100644 --- a/Libraries/LibWebView/WebUI/SettingsUI.h +++ b/Libraries/LibWebView/WebUI/SettingsUI.h @@ -21,6 +21,7 @@ private: void restore_default_settings(); void set_new_tab_page_url(JsonValue const&); + void set_default_zoom_level_factor(JsonValue const&); void set_languages(JsonValue const&); void load_available_engines();