diff --git a/Ladybird/WebContentView.cpp b/Ladybird/WebContentView.cpp index 0c5f9964d3d..9655eed292f 100644 --- a/Ladybird/WebContentView.cpp +++ b/Ladybird/WebContentView.cpp @@ -566,28 +566,6 @@ void WebContentView::set_preferred_color_scheme(Web::CSS::PreferredColorScheme c client().async_set_preferred_color_scheme(color_scheme); } -void WebContentView::zoom_in() -{ - if (m_zoom_level >= ZOOM_MAX_LEVEL) - return; - m_zoom_level += ZOOM_STEP; - update_zoom(); -} - -void WebContentView::zoom_out() -{ - if (m_zoom_level <= ZOOM_MIN_LEVEL) - return; - m_zoom_level -= ZOOM_STEP; - update_zoom(); -} - -void WebContentView::reset_zoom() -{ - m_zoom_level = 1.0f; - update_zoom(); -} - void WebContentView::update_zoom() { client().async_set_device_pixels_per_css_pixel(m_device_pixel_ratio * m_zoom_level); diff --git a/Ladybird/WebContentView.h b/Ladybird/WebContentView.h index 058c31ed778..a5c631d2a13 100644 --- a/Ladybird/WebContentView.h +++ b/Ladybird/WebContentView.h @@ -108,10 +108,6 @@ public: void set_preferred_color_scheme(Web::CSS::PreferredColorScheme); - void zoom_in(); - void zoom_out(); - void reset_zoom(); - DeprecatedString selected_text(); void select_all(); @@ -186,17 +182,13 @@ signals: Gfx::IntRect fullscreen_window(); private: - static constexpr auto ZOOM_MIN_LEVEL = 0.3f; - static constexpr auto ZOOM_MAX_LEVEL = 5.0f; - static constexpr auto ZOOM_STEP = 0.1f; - // ^WebView::ViewImplementation virtual void create_client() override; + virtual void update_zoom() override; void request_repaint(); void update_viewport_rect(); void handle_resize(); - void update_zoom(); void ensure_js_console_widget(); void ensure_inspector_widget(); @@ -207,8 +199,6 @@ private: void close_sub_widgets(); ErrorOr inspect_dom_node(i32 node_id, Optional pseudo_element); - float m_zoom_level { 1.0 }; - float m_device_pixel_ratio { 1.0 }; qreal m_inverse_pixel_scaling_ratio { 1.0 }; bool m_should_show_line_box_borders { false }; diff --git a/Userland/Libraries/LibWebView/OutOfProcessWebView.cpp b/Userland/Libraries/LibWebView/OutOfProcessWebView.cpp index 52d9c613ad1..39edbd63d1c 100644 --- a/Userland/Libraries/LibWebView/OutOfProcessWebView.cpp +++ b/Userland/Libraries/LibWebView/OutOfProcessWebView.cpp @@ -159,28 +159,6 @@ void OutOfProcessWebView::handle_resize() 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); diff --git a/Userland/Libraries/LibWebView/OutOfProcessWebView.h b/Userland/Libraries/LibWebView/OutOfProcessWebView.h index d80fc482dd0..e75200fbbe6 100644 --- a/Userland/Libraries/LibWebView/OutOfProcessWebView.h +++ b/Userland/Libraries/LibWebView/OutOfProcessWebView.h @@ -77,10 +77,6 @@ public: void set_system_visibility_state(bool visible); - void zoom_in(); - void zoom_out(); - void reset_zoom(); - Gfx::ShareableBitmap take_screenshot() const; Gfx::ShareableBitmap take_document_screenshot(); @@ -125,10 +121,6 @@ public: Function on_forward_button; 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(); // ^Widget @@ -153,6 +145,7 @@ private: // ^WebView::ViewImplementation virtual void create_client() override; + virtual void update_zoom() override; virtual void notify_server_did_layout(Badge, Gfx::IntSize content_size) override; virtual void notify_server_did_paint(Badge, i32 bitmap_id) override; virtual void notify_server_did_invalidate_content_rect(Badge, Gfx::IntRect const&) override; @@ -206,7 +199,6 @@ private: void request_repaint(); void handle_resize(); - void update_zoom(); void handle_web_content_process_crash(); @@ -223,9 +215,6 @@ private: Queue m_pending_input_events; bool m_content_scales_to_viewport { false }; - - float m_zoom_level { 1.0 }; - float m_device_pixel_ratio { 1.0 }; }; } diff --git a/Userland/Libraries/LibWebView/ViewImplementation.cpp b/Userland/Libraries/LibWebView/ViewImplementation.cpp index 30278456b2a..66d84fdcab1 100644 --- a/Userland/Libraries/LibWebView/ViewImplementation.cpp +++ b/Userland/Libraries/LibWebView/ViewImplementation.cpp @@ -20,4 +20,26 @@ WebContentClient const& ViewImplementation::client() const return *m_client_state.client; } +void ViewImplementation::zoom_in() +{ + if (m_zoom_level >= ZOOM_MAX_LEVEL) + return; + m_zoom_level += ZOOM_STEP; + update_zoom(); +} + +void ViewImplementation::zoom_out() +{ + if (m_zoom_level <= ZOOM_MIN_LEVEL) + return; + m_zoom_level -= ZOOM_STEP; + update_zoom(); +} + +void ViewImplementation::reset_zoom() +{ + m_zoom_level = 1.0f; + update_zoom(); +} + } diff --git a/Userland/Libraries/LibWebView/ViewImplementation.h b/Userland/Libraries/LibWebView/ViewImplementation.h index 48c9e4ce89e..34fac898158 100644 --- a/Userland/Libraries/LibWebView/ViewImplementation.h +++ b/Userland/Libraries/LibWebView/ViewImplementation.h @@ -19,6 +19,10 @@ class ViewImplementation { public: virtual ~ViewImplementation() { } + void zoom_in(); + void zoom_out(); + void reset_zoom(); + virtual void notify_server_did_layout(Badge, Gfx::IntSize content_size) = 0; virtual void notify_server_did_paint(Badge, i32 bitmap_id) = 0; virtual void notify_server_did_invalidate_content_rect(Badge, Gfx::IntRect const&) = 0; @@ -71,9 +75,14 @@ public: virtual void notify_server_did_finish_handling_input_event(bool event_was_accepted) = 0; protected: + static constexpr auto ZOOM_MIN_LEVEL = 0.3f; + static constexpr auto ZOOM_MAX_LEVEL = 5.0f; + static constexpr auto ZOOM_STEP = 0.1f; + WebContentClient& client(); WebContentClient const& client() const; virtual void create_client() = 0; + virtual void update_zoom() = 0; struct SharedBitmap { i32 id { -1 }; @@ -89,6 +98,9 @@ protected: bool has_usable_bitmap { false }; bool got_repaint_requests_while_painting { false }; } m_client_state; + + float m_zoom_level { 1.0 }; + float m_device_pixel_ratio { 1.0 }; }; }