summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2023-01-12 19:49:49 +0000
committerAndreas Kling <kling@serenityos.org>2023-01-12 23:39:36 +0100
commit5d9f4b2ffc43e83df44c715b0c296cafcfaabfe0 (patch)
tree7b25d74c14d603c03b45443a546d7b53c41ff028
parent5411adca223a51edde731903828ae4cb39462880 (diff)
downloadserenity-5d9f4b2ffc43e83df44c715b0c296cafcfaabfe0.zip
LibWebView+Ladybird: Move zoom logic to ViewImplementation
-rw-r--r--Ladybird/WebContentView.cpp22
-rw-r--r--Ladybird/WebContentView.h12
-rw-r--r--Userland/Libraries/LibWebView/OutOfProcessWebView.cpp22
-rw-r--r--Userland/Libraries/LibWebView/OutOfProcessWebView.h13
-rw-r--r--Userland/Libraries/LibWebView/ViewImplementation.cpp22
-rw-r--r--Userland/Libraries/LibWebView/ViewImplementation.h12
6 files changed, 36 insertions, 67 deletions
diff --git a/Ladybird/WebContentView.cpp b/Ladybird/WebContentView.cpp
index 0c5f9964d3..9655eed292 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 058c31ed77..a5c631d2a1 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<Ladybird::DOMNodeProperties> inspect_dom_node(i32 node_id, Optional<Web::CSS::Selector::PseudoElement> 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 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 };
};
}