mirror of
https://github.com/RGBCube/serenity
synced 2025-05-30 22:18:11 +00:00
Browser: Implement zoom :^)
Largely based on the Ladybird implementation in 0cc151b
.
This commit is contained in:
parent
966d808135
commit
36866730ce
3 changed files with 60 additions and 0 deletions
|
@ -180,6 +180,25 @@ void BrowserWindow::build_menus()
|
||||||
view_menu.add_action(WindowActions::the().show_bookmarks_bar_action());
|
view_menu.add_action(WindowActions::the().show_bookmarks_bar_action());
|
||||||
view_menu.add_action(WindowActions::the().vertical_tabs_action());
|
view_menu.add_action(WindowActions::the().vertical_tabs_action());
|
||||||
view_menu.add_separator();
|
view_menu.add_separator();
|
||||||
|
view_menu.add_action(GUI::CommonActions::make_zoom_in_action(
|
||||||
|
[this](auto&) {
|
||||||
|
auto& tab = active_tab();
|
||||||
|
tab.view().zoom_in();
|
||||||
|
},
|
||||||
|
this));
|
||||||
|
view_menu.add_action(GUI::CommonActions::make_zoom_out_action(
|
||||||
|
[this](auto&) {
|
||||||
|
auto& tab = active_tab();
|
||||||
|
tab.view().zoom_out();
|
||||||
|
},
|
||||||
|
this));
|
||||||
|
view_menu.add_action(GUI::CommonActions::make_reset_zoom_action(
|
||||||
|
[this](auto&) {
|
||||||
|
auto& tab = active_tab();
|
||||||
|
tab.view().reset_zoom();
|
||||||
|
},
|
||||||
|
this));
|
||||||
|
view_menu.add_separator();
|
||||||
view_menu.add_action(GUI::CommonActions::make_fullscreen_action(
|
view_menu.add_action(GUI::CommonActions::make_fullscreen_action(
|
||||||
[this](auto&) {
|
[this](auto&) {
|
||||||
auto& tab = active_tab();
|
auto& tab = active_tab();
|
||||||
|
|
|
@ -159,6 +159,35 @@ void OutOfProcessWebView::handle_resize()
|
||||||
request_repaint();
|
request_repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OutOfProcessWebView::zoom_in()
|
||||||
|
{
|
||||||
|
if (m_zoom_level >= ZOOM_MAX_LEVEL)
|
||||||
|
return;
|
||||||
|
m_zoom_level += ZOOM_STEP;
|
||||||
|
update_zoom();
|
||||||
|
}
|
||||||
|
|
||||||
|
void OutOfProcessWebView::zoom_out()
|
||||||
|
{
|
||||||
|
if (m_zoom_level <= ZOOM_MIN_LEVEL)
|
||||||
|
return;
|
||||||
|
m_zoom_level -= ZOOM_STEP;
|
||||||
|
update_zoom();
|
||||||
|
}
|
||||||
|
|
||||||
|
void OutOfProcessWebView::reset_zoom()
|
||||||
|
{
|
||||||
|
m_zoom_level = 1.0f;
|
||||||
|
update_zoom();
|
||||||
|
}
|
||||||
|
|
||||||
|
void OutOfProcessWebView::update_zoom()
|
||||||
|
{
|
||||||
|
client().async_set_device_pixels_per_css_pixel(m_device_pixel_ratio * m_zoom_level);
|
||||||
|
// FIXME: Refactor this into separate update_viewport_rect() + request_repaint() like in Ladybird
|
||||||
|
handle_resize();
|
||||||
|
}
|
||||||
|
|
||||||
void OutOfProcessWebView::keydown_event(GUI::KeyEvent& event)
|
void OutOfProcessWebView::keydown_event(GUI::KeyEvent& event)
|
||||||
{
|
{
|
||||||
enqueue_input_event(event);
|
enqueue_input_event(event);
|
||||||
|
|
|
@ -77,6 +77,10 @@ public:
|
||||||
|
|
||||||
void set_system_visibility_state(bool visible);
|
void set_system_visibility_state(bool visible);
|
||||||
|
|
||||||
|
void zoom_in();
|
||||||
|
void zoom_out();
|
||||||
|
void reset_zoom();
|
||||||
|
|
||||||
Gfx::ShareableBitmap take_screenshot() const;
|
Gfx::ShareableBitmap take_screenshot() const;
|
||||||
Gfx::ShareableBitmap take_document_screenshot();
|
Gfx::ShareableBitmap take_document_screenshot();
|
||||||
|
|
||||||
|
@ -121,6 +125,10 @@ public:
|
||||||
Function<void()> on_forward_button;
|
Function<void()> on_forward_button;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
static constexpr auto ZOOM_MIN_LEVEL = 0.3f;
|
||||||
|
static constexpr auto ZOOM_MAX_LEVEL = 5.0f;
|
||||||
|
static constexpr auto ZOOM_STEP = 0.1f;
|
||||||
|
|
||||||
OutOfProcessWebView();
|
OutOfProcessWebView();
|
||||||
|
|
||||||
// ^Widget
|
// ^Widget
|
||||||
|
@ -197,6 +205,7 @@ private:
|
||||||
|
|
||||||
void request_repaint();
|
void request_repaint();
|
||||||
void handle_resize();
|
void handle_resize();
|
||||||
|
void update_zoom();
|
||||||
|
|
||||||
void create_client();
|
void create_client();
|
||||||
WebContentClient& client();
|
WebContentClient& client();
|
||||||
|
@ -231,6 +240,9 @@ private:
|
||||||
Queue<InputEvent> m_pending_input_events;
|
Queue<InputEvent> m_pending_input_events;
|
||||||
|
|
||||||
bool m_content_scales_to_viewport { false };
|
bool m_content_scales_to_viewport { false };
|
||||||
|
|
||||||
|
float m_zoom_level { 1.0 };
|
||||||
|
float m_device_pixel_ratio { 1.0 };
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue