mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
LibWebView+Ladybird: Move zoom logic to ViewImplementation
This commit is contained in:
parent
5411adca22
commit
5d9f4b2ffc
Notes:
sideshowbarker
2024-07-17 01:47:25 +09:00
Author: https://github.com/linusg Commit: https://github.com/SerenityOS/serenity/commit/5d9f4b2ffc Pull-request: https://github.com/SerenityOS/serenity/pull/16983
6 changed files with 36 additions and 67 deletions
|
@ -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);
|
||||
|
|
|
@ -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 };
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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 };
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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 };
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue