mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-22 09:18:55 +00:00
LibWebView: Add defaultZoomLevelFactor setting and necessary plumbing
This commit is contained in:
parent
73266c8498
commit
333164ecf9
Notes:
github-actions[bot]
2025-08-26 10:32:48 +00:00
Author: https://github.com/rmg-x
Commit: 333164ecf9
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5969
Reviewed-by: https://github.com/trflynn89
6 changed files with 45 additions and 0 deletions
|
@ -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<Application>)
|
|||
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<Application>)
|
|||
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<String> Settings::parse_json_languages(JsonValue const& languages)
|
||||
{
|
||||
if (!languages.is_array())
|
||||
|
|
|
@ -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<String> parse_json_languages(JsonValue const&);
|
||||
Vector<String> const& languages() const { return m_languages; }
|
||||
void set_languages(Vector<String>);
|
||||
|
@ -95,6 +99,7 @@ private:
|
|||
ByteString m_settings_path;
|
||||
|
||||
URL::URL m_new_tab_page_url;
|
||||
double m_default_zoom_level_factor { 0 };
|
||||
Vector<String> m_languages;
|
||||
Optional<SearchEngine> m_search_engine;
|
||||
Vector<SearchEngine> m_custom_search_engines;
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue