mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-26 09:30:24 +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
Notes:
sideshowbarker
2024-07-17 03:51:15 +09:00
Author: https://github.com/MacDue Commit: https://github.com/SerenityOS/serenity/commit/b7f9b316ed Pull-request: https://github.com/SerenityOS/serenity/pull/18080
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);
|
||||
set_window_title_for_tab(tab);
|
||||
tab.did_become_active();
|
||||
update_zoom_menu_text();
|
||||
update_displayed_zoom_level();
|
||||
};
|
||||
|
||||
m_tab_widget->on_middle_click = [](auto& clicked_widget) {
|
||||
|
@ -178,21 +178,21 @@ void BrowserWindow::build_menus()
|
|||
[this](auto&) {
|
||||
auto& tab = active_tab();
|
||||
tab.view().zoom_in();
|
||||
update_zoom_menu_text();
|
||||
update_displayed_zoom_level();
|
||||
},
|
||||
this));
|
||||
m_zoom_menu->add_action(GUI::CommonActions::make_zoom_out_action(
|
||||
[this](auto&) {
|
||||
auto& tab = active_tab();
|
||||
tab.view().zoom_out();
|
||||
update_zoom_menu_text();
|
||||
update_displayed_zoom_level();
|
||||
},
|
||||
this));
|
||||
m_zoom_menu->add_action(GUI::CommonActions::make_reset_zoom_action(
|
||||
[this](auto&) {
|
||||
auto& tab = active_tab();
|
||||
tab.view().reset_zoom();
|
||||
update_zoom_menu_text();
|
||||
update_displayed_zoom_level();
|
||||
},
|
||||
this));
|
||||
view_menu.add_separator();
|
||||
|
@ -796,11 +796,12 @@ ErrorOr<void> BrowserWindow::take_screenshot(ScreenshotType type)
|
|||
return {};
|
||||
}
|
||||
|
||||
void BrowserWindow::update_zoom_menu_text()
|
||||
void BrowserWindow::update_displayed_zoom_level()
|
||||
{
|
||||
VERIFY(m_zoom_menu);
|
||||
auto zoom_level_text = DeprecatedString::formatted("&Zoom ({}%)", round_to<int>(active_tab().view().zoom_level() * 100));
|
||||
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;
|
||||
|
||||
void update_zoom_menu_text();
|
||||
void update_displayed_zoom_level();
|
||||
|
||||
enum class ScreenshotType {
|
||||
Visible,
|
||||
|
|
|
@ -201,6 +201,15 @@ Tab::Tab(BrowserWindow& window)
|
|||
},
|
||||
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->set_action(bookmark_action);
|
||||
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)
|
||||
{
|
||||
if (m_location_box->text().starts_with('?') && g_search_engine.is_empty()) {
|
||||
|
|
|
@ -90,6 +90,8 @@ public:
|
|||
void show_storage_inspector();
|
||||
void show_history_inspector();
|
||||
|
||||
void update_reset_zoom_button();
|
||||
|
||||
DeprecatedString const& title() const { return m_title; }
|
||||
Gfx::Bitmap const* icon() const { return m_icon; }
|
||||
|
||||
|
@ -124,6 +126,7 @@ private:
|
|||
RefPtr<WebView::OutOfProcessWebView> m_web_content_view;
|
||||
|
||||
RefPtr<GUI::UrlBox> m_location_box;
|
||||
RefPtr<GUI::Button> m_reset_zoom_button;
|
||||
RefPtr<GUI::Button> m_bookmark_button;
|
||||
RefPtr<InspectorWidget> m_dom_inspector_widget;
|
||||
RefPtr<ConsoleWidget> m_console_widget;
|
||||
|
|
Loading…
Reference in a new issue