diff options
author | Linus Groh <mail@linusgroh.de> | 2023-01-12 19:49:49 +0000 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2023-01-12 23:39:36 +0100 |
commit | 5d9f4b2ffc43e83df44c715b0c296cafcfaabfe0 (patch) | |
tree | 7b25d74c14d603c03b45443a546d7b53c41ff028 /Userland/Libraries | |
parent | 5411adca223a51edde731903828ae4cb39462880 (diff) | |
download | serenity-5d9f4b2ffc43e83df44c715b0c296cafcfaabfe0.zip |
LibWebView+Ladybird: Move zoom logic to ViewImplementation
Diffstat (limited to 'Userland/Libraries')
4 files changed, 35 insertions, 34 deletions
diff --git a/Userland/Libraries/LibWebView/OutOfProcessWebView.cpp b/Userland/Libraries/LibWebView/OutOfProcessWebView.cpp index 52d9c613ad..39edbd63d1 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 d80fc482dd..e75200fbbe 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<void()> 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<WebContentClient>, Gfx::IntSize content_size) override; virtual void notify_server_did_paint(Badge<WebContentClient>, i32 bitmap_id) override; virtual void notify_server_did_invalidate_content_rect(Badge<WebContentClient>, 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<InputEvent> 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 30278456b2..66d84fdcab 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 48c9e4ce89..34fac89815 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<WebContentClient>, Gfx::IntSize content_size) = 0; virtual void notify_server_did_paint(Badge<WebContentClient>, i32 bitmap_id) = 0; virtual void notify_server_did_invalidate_content_rect(Badge<WebContentClient>, 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 }; }; } |