1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 05:57:44 +00:00

Browser+Ladybird+LibWebView: Virtualize computing content/widget points

This will allow moving some copy-pasted functionality from web view
implementations to the base LibWebView class.
This commit is contained in:
Timothy Flynn 2023-05-17 10:12:13 -04:00 committed by Andreas Kling
parent 31d7565cf3
commit 2d51b8c286
6 changed files with 37 additions and 22 deletions

View file

@ -274,7 +274,7 @@ void WebContentView::mouseMoveEvent(QMouseEvent* event)
Gfx::IntPoint position(event->position().x() / m_inverse_pixel_scaling_ratio, event->position().y() / m_inverse_pixel_scaling_ratio);
auto buttons = get_buttons_from_qt_event(*event);
auto modifiers = get_modifiers_from_qt_mouse_event(*event);
client().async_mouse_move(to_content(position), 0, buttons, modifiers);
client().async_mouse_move(to_content_position(position), 0, buttons, modifiers);
}
void WebContentView::mousePressEvent(QMouseEvent* event)
@ -289,7 +289,7 @@ void WebContentView::mousePressEvent(QMouseEvent* event)
}
auto modifiers = get_modifiers_from_qt_mouse_event(*event);
auto buttons = get_buttons_from_qt_event(*event);
client().async_mouse_down(to_content(position), button, buttons, modifiers);
client().async_mouse_down(to_content_position(position), button, buttons, modifiers);
}
void WebContentView::mouseReleaseEvent(QMouseEvent* event)
@ -311,7 +311,7 @@ void WebContentView::mouseReleaseEvent(QMouseEvent* event)
}
auto modifiers = get_modifiers_from_qt_mouse_event(*event);
auto buttons = get_buttons_from_qt_event(*event);
client().async_mouse_up(to_content(position), button, buttons, modifiers);
client().async_mouse_up(to_content_position(position), button, buttons, modifiers);
}
void WebContentView::mouseDoubleClickEvent(QMouseEvent* event)
@ -326,7 +326,7 @@ void WebContentView::mouseDoubleClickEvent(QMouseEvent* event)
}
auto modifiers = get_modifiers_from_qt_mouse_event(*event);
auto buttons = get_buttons_from_qt_event(*event);
client().async_doubleclick(to_content(position), button, buttons, modifiers);
client().async_doubleclick(to_content_position(position), button, buttons, modifiers);
}
void WebContentView::dragEnterEvent(QDragEnterEvent* event)
@ -395,16 +395,6 @@ void WebContentView::focusOutEvent(QFocusEvent*)
client().async_set_has_focus(false);
}
Gfx::IntPoint WebContentView::to_content(Gfx::IntPoint viewport_position) const
{
return viewport_position.translated(max(0, horizontalScrollBar()->value()), max(0, verticalScrollBar()->value()));
}
Gfx::IntPoint WebContentView::to_widget(Gfx::IntPoint content_position) const
{
return content_position.translated(-(max(0, horizontalScrollBar()->value())), -(max(0, verticalScrollBar()->value())));
}
void WebContentView::paintEvent(QPaintEvent*)
{
QPainter painter(viewport());
@ -757,7 +747,7 @@ void WebContentView::notify_server_did_request_scroll_into_view(Badge<WebContent
void WebContentView::notify_server_did_enter_tooltip_area(Badge<WebContentClient>, Gfx::IntPoint content_position, DeprecatedString const& tooltip)
{
auto widget_position = to_widget(content_position);
auto widget_position = to_widget_position(content_position);
QToolTip::showText(
mapToGlobal(QPoint(widget_position.x(), widget_position.y())),
qstring_from_ak_deprecated_string(tooltip),
@ -830,25 +820,25 @@ void WebContentView::notify_server_did_request_refresh(Badge<WebContentClient>)
void WebContentView::notify_server_did_request_context_menu(Badge<WebContentClient>, Gfx::IntPoint content_position)
{
if (on_context_menu_request)
on_context_menu_request(to_widget(content_position));
on_context_menu_request(to_widget_position(content_position));
}
void WebContentView::notify_server_did_request_link_context_menu(Badge<WebContentClient>, Gfx::IntPoint content_position, AK::URL const& url, DeprecatedString const&, unsigned)
{
if (on_link_context_menu_request)
on_link_context_menu_request(url, to_widget(content_position));
on_link_context_menu_request(url, to_widget_position(content_position));
}
void WebContentView::notify_server_did_request_image_context_menu(Badge<WebContentClient>, Gfx::IntPoint content_position, AK::URL const& url, DeprecatedString const&, unsigned, Gfx::ShareableBitmap const& bitmap)
{
if (on_image_context_menu_request)
on_image_context_menu_request(url, to_widget(content_position), bitmap);
on_image_context_menu_request(url, to_widget_position(content_position), bitmap);
}
void WebContentView::notify_server_did_request_video_context_menu(Badge<WebContentClient>, Gfx::IntPoint content_position, AK::URL const& url, DeprecatedString const&, unsigned, bool is_playing, bool has_user_agent_controls, bool is_looping)
{
if (on_video_context_menu_request)
on_video_context_menu_request(url, to_widget(content_position), is_playing, has_user_agent_controls, is_looping);
on_video_context_menu_request(url, to_widget_position(content_position), is_playing, has_user_agent_controls, is_looping);
}
void WebContentView::notify_server_did_request_alert(Badge<WebContentClient>, String const& message)
@ -1046,6 +1036,16 @@ Gfx::IntRect WebContentView::viewport_rect() const
return m_viewport_rect;
}
Gfx::IntPoint WebContentView::to_content_position(Gfx::IntPoint widget_position) const
{
return widget_position.translated(max(0, horizontalScrollBar()->value()), max(0, verticalScrollBar()->value()));
}
Gfx::IntPoint WebContentView::to_widget_position(Gfx::IntPoint content_position) const
{
return content_position.translated(-(max(0, horizontalScrollBar()->value())), -(max(0, verticalScrollBar()->value())));
}
bool WebContentView::event(QEvent* event)
{
// NOTE: We have to implement event() manually as Qt's focus navigation mechanism

View file

@ -107,9 +107,6 @@ public:
void set_window_size(Gfx::IntSize);
void set_window_position(Gfx::IntPoint);
Gfx::IntPoint to_content(Gfx::IntPoint) const;
Gfx::IntPoint to_widget(Gfx::IntPoint) const;
enum class PaletteMode {
Default,
Dark,
@ -198,6 +195,8 @@ private:
virtual void create_client(WebView::EnableCallgrindProfiling = WebView::EnableCallgrindProfiling::No) override;
virtual void update_zoom() override;
virtual Gfx::IntRect viewport_rect() const override;
virtual Gfx::IntPoint to_content_position(Gfx::IntPoint widget_position) const override;
virtual Gfx::IntPoint to_widget_position(Gfx::IntPoint content_position) const override;
void update_viewport_rect();

View file

@ -90,6 +90,16 @@ Gfx::IntRect OutOfProcessWebView::viewport_rect() const
return visible_content_rect();
}
Gfx::IntPoint OutOfProcessWebView::to_content_position(Gfx::IntPoint widget_position) const
{
return GUI::AbstractScrollableWidget::to_content_position(widget_position);
}
Gfx::IntPoint OutOfProcessWebView::to_widget_position(Gfx::IntPoint content_position) const
{
return GUI::AbstractScrollableWidget::to_widget_position(content_position);
}
void OutOfProcessWebView::update_zoom()
{
client().async_set_device_pixels_per_css_pixel(m_device_pixel_ratio * m_zoom_level);

View file

@ -179,6 +179,8 @@ private:
virtual void notify_server_did_finish_handling_input_event(bool event_was_accepted) override;
virtual Gfx::IntRect viewport_rect() const override;
virtual Gfx::IntPoint to_content_position(Gfx::IntPoint widget_position) const override;
virtual Gfx::IntPoint to_widget_position(Gfx::IntPoint content_position) const override;
using InputEvent = Variant<GUI::KeyEvent, GUI::MouseEvent>;
void enqueue_input_event(InputEvent const&);

View file

@ -136,6 +136,8 @@ public:
virtual void notify_server_did_finish_handling_input_event(bool event_was_accepted) = 0;
virtual Gfx::IntRect viewport_rect() const = 0;
virtual Gfx::IntPoint to_content_position(Gfx::IntPoint widget_position) const = 0;
virtual Gfx::IntPoint to_widget_position(Gfx::IntPoint content_position) const = 0;
protected:
static constexpr auto ZOOM_MIN_LEVEL = 0.3f;

View file

@ -158,6 +158,8 @@ private:
void create_client(WebView::EnableCallgrindProfiling) override { }
virtual Gfx::IntRect viewport_rect() const override { return m_viewport_rect; }
virtual Gfx::IntPoint to_content_position(Gfx::IntPoint widget_position) const override { return widget_position; }
virtual Gfx::IntPoint to_widget_position(Gfx::IntPoint content_position) const override { return content_position; }
private:
Gfx::IntRect m_viewport_rect;