mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 06:37:44 +00:00
Browser: Add reset zoom level button to toolbar
This button shows the current zoom level and when clicked resets the zoom back to 100%. It is only displayed for zoom levels other than 100%.
This commit is contained in:
parent
64da05a96d
commit
b7f9b316ed
4 changed files with 30 additions and 6 deletions
|
@ -84,7 +84,7 @@ BrowserWindow::BrowserWindow(CookieJar& cookie_jar, URL url)
|
||||||
auto& tab = static_cast<Browser::Tab&>(active_widget);
|
auto& tab = static_cast<Browser::Tab&>(active_widget);
|
||||||
set_window_title_for_tab(tab);
|
set_window_title_for_tab(tab);
|
||||||
tab.did_become_active();
|
tab.did_become_active();
|
||||||
update_zoom_menu_text();
|
update_displayed_zoom_level();
|
||||||
};
|
};
|
||||||
|
|
||||||
m_tab_widget->on_middle_click = [](auto& clicked_widget) {
|
m_tab_widget->on_middle_click = [](auto& clicked_widget) {
|
||||||
|
@ -178,21 +178,21 @@ void BrowserWindow::build_menus()
|
||||||
[this](auto&) {
|
[this](auto&) {
|
||||||
auto& tab = active_tab();
|
auto& tab = active_tab();
|
||||||
tab.view().zoom_in();
|
tab.view().zoom_in();
|
||||||
update_zoom_menu_text();
|
update_displayed_zoom_level();
|
||||||
},
|
},
|
||||||
this));
|
this));
|
||||||
m_zoom_menu->add_action(GUI::CommonActions::make_zoom_out_action(
|
m_zoom_menu->add_action(GUI::CommonActions::make_zoom_out_action(
|
||||||
[this](auto&) {
|
[this](auto&) {
|
||||||
auto& tab = active_tab();
|
auto& tab = active_tab();
|
||||||
tab.view().zoom_out();
|
tab.view().zoom_out();
|
||||||
update_zoom_menu_text();
|
update_displayed_zoom_level();
|
||||||
},
|
},
|
||||||
this));
|
this));
|
||||||
m_zoom_menu->add_action(GUI::CommonActions::make_reset_zoom_action(
|
m_zoom_menu->add_action(GUI::CommonActions::make_reset_zoom_action(
|
||||||
[this](auto&) {
|
[this](auto&) {
|
||||||
auto& tab = active_tab();
|
auto& tab = active_tab();
|
||||||
tab.view().reset_zoom();
|
tab.view().reset_zoom();
|
||||||
update_zoom_menu_text();
|
update_displayed_zoom_level();
|
||||||
},
|
},
|
||||||
this));
|
this));
|
||||||
view_menu.add_separator();
|
view_menu.add_separator();
|
||||||
|
@ -796,11 +796,12 @@ ErrorOr<void> BrowserWindow::take_screenshot(ScreenshotType type)
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
void BrowserWindow::update_zoom_menu_text()
|
void BrowserWindow::update_displayed_zoom_level()
|
||||||
{
|
{
|
||||||
VERIFY(m_zoom_menu);
|
VERIFY(m_zoom_menu);
|
||||||
auto zoom_level_text = DeprecatedString::formatted("&Zoom ({}%)", round_to<int>(active_tab().view().zoom_level() * 100));
|
auto zoom_level_text = DeprecatedString::formatted("&Zoom ({}%)", round_to<int>(active_tab().view().zoom_level() * 100));
|
||||||
m_zoom_menu->set_name(zoom_level_text);
|
m_zoom_menu->set_name(zoom_level_text);
|
||||||
|
active_tab().update_reset_zoom_button();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,7 +62,7 @@ private:
|
||||||
|
|
||||||
virtual void event(Core::Event&) override;
|
virtual void event(Core::Event&) override;
|
||||||
|
|
||||||
void update_zoom_menu_text();
|
void update_displayed_zoom_level();
|
||||||
|
|
||||||
enum class ScreenshotType {
|
enum class ScreenshotType {
|
||||||
Visible,
|
Visible,
|
||||||
|
|
|
@ -201,6 +201,15 @@ Tab::Tab(BrowserWindow& window)
|
||||||
},
|
},
|
||||||
this);
|
this);
|
||||||
|
|
||||||
|
m_reset_zoom_button = toolbar.add<GUI::Button>();
|
||||||
|
m_reset_zoom_button->on_click = [&](auto) {
|
||||||
|
view().reset_zoom();
|
||||||
|
update_reset_zoom_button();
|
||||||
|
};
|
||||||
|
m_reset_zoom_button->set_button_style(Gfx::ButtonStyle::Coolbar);
|
||||||
|
m_reset_zoom_button->set_visible(false);
|
||||||
|
m_reset_zoom_button->set_preferred_width(GUI::SpecialDimension::Shrink);
|
||||||
|
|
||||||
m_bookmark_button = toolbar.add<GUI::Button>();
|
m_bookmark_button = toolbar.add<GUI::Button>();
|
||||||
m_bookmark_button->set_action(bookmark_action);
|
m_bookmark_button->set_action(bookmark_action);
|
||||||
m_bookmark_button->set_button_style(Gfx::ButtonStyle::Coolbar);
|
m_bookmark_button->set_button_style(Gfx::ButtonStyle::Coolbar);
|
||||||
|
@ -514,6 +523,17 @@ Tab::Tab(BrowserWindow& window)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Tab::update_reset_zoom_button()
|
||||||
|
{
|
||||||
|
auto zoom_level = view().zoom_level();
|
||||||
|
if (zoom_level != 1.0f) {
|
||||||
|
m_reset_zoom_button->set_text(MUST(String::formatted("{}%", round_to<int>(zoom_level * 100))));
|
||||||
|
m_reset_zoom_button->set_visible(true);
|
||||||
|
} else {
|
||||||
|
m_reset_zoom_button->set_visible(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Optional<URL> Tab::url_from_location_bar(MayAppendTLD may_append_tld)
|
Optional<URL> Tab::url_from_location_bar(MayAppendTLD may_append_tld)
|
||||||
{
|
{
|
||||||
if (m_location_box->text().starts_with('?') && g_search_engine.is_empty()) {
|
if (m_location_box->text().starts_with('?') && g_search_engine.is_empty()) {
|
||||||
|
|
|
@ -90,6 +90,8 @@ public:
|
||||||
void show_storage_inspector();
|
void show_storage_inspector();
|
||||||
void show_history_inspector();
|
void show_history_inspector();
|
||||||
|
|
||||||
|
void update_reset_zoom_button();
|
||||||
|
|
||||||
DeprecatedString const& title() const { return m_title; }
|
DeprecatedString const& title() const { return m_title; }
|
||||||
Gfx::Bitmap const* icon() const { return m_icon; }
|
Gfx::Bitmap const* icon() const { return m_icon; }
|
||||||
|
|
||||||
|
@ -124,6 +126,7 @@ private:
|
||||||
RefPtr<WebView::OutOfProcessWebView> m_web_content_view;
|
RefPtr<WebView::OutOfProcessWebView> m_web_content_view;
|
||||||
|
|
||||||
RefPtr<GUI::UrlBox> m_location_box;
|
RefPtr<GUI::UrlBox> m_location_box;
|
||||||
|
RefPtr<GUI::Button> m_reset_zoom_button;
|
||||||
RefPtr<GUI::Button> m_bookmark_button;
|
RefPtr<GUI::Button> m_bookmark_button;
|
||||||
RefPtr<InspectorWidget> m_dom_inspector_widget;
|
RefPtr<InspectorWidget> m_dom_inspector_widget;
|
||||||
RefPtr<ConsoleWidget> m_console_widget;
|
RefPtr<ConsoleWidget> m_console_widget;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue