diff options
-rw-r--r-- | Ladybird/WebContentView.cpp | 38 | ||||
-rw-r--r-- | Ladybird/WebContentView.h | 5 | ||||
-rw-r--r-- | Userland/Libraries/LibWebView/OutOfProcessWebView.cpp | 10 | ||||
-rw-r--r-- | Userland/Libraries/LibWebView/OutOfProcessWebView.h | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibWebView/ViewImplementation.h | 2 | ||||
-rw-r--r-- | Userland/Utilities/headless-browser.cpp | 2 |
6 files changed, 37 insertions, 22 deletions
diff --git a/Ladybird/WebContentView.cpp b/Ladybird/WebContentView.cpp index 37c0e294a9..312ef22f9f 100644 --- a/Ladybird/WebContentView.cpp +++ b/Ladybird/WebContentView.cpp @@ -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 diff --git a/Ladybird/WebContentView.h b/Ladybird/WebContentView.h index 3d0865f95f..cb04559faf 100644 --- a/Ladybird/WebContentView.h +++ b/Ladybird/WebContentView.h @@ -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(); diff --git a/Userland/Libraries/LibWebView/OutOfProcessWebView.cpp b/Userland/Libraries/LibWebView/OutOfProcessWebView.cpp index a65256f91b..484206e6d9 100644 --- a/Userland/Libraries/LibWebView/OutOfProcessWebView.cpp +++ b/Userland/Libraries/LibWebView/OutOfProcessWebView.cpp @@ -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); diff --git a/Userland/Libraries/LibWebView/OutOfProcessWebView.h b/Userland/Libraries/LibWebView/OutOfProcessWebView.h index 1be13f44a7..8fef61e714 100644 --- a/Userland/Libraries/LibWebView/OutOfProcessWebView.h +++ b/Userland/Libraries/LibWebView/OutOfProcessWebView.h @@ -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&); diff --git a/Userland/Libraries/LibWebView/ViewImplementation.h b/Userland/Libraries/LibWebView/ViewImplementation.h index 75ca656d5b..3af0c8f097 100644 --- a/Userland/Libraries/LibWebView/ViewImplementation.h +++ b/Userland/Libraries/LibWebView/ViewImplementation.h @@ -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; diff --git a/Userland/Utilities/headless-browser.cpp b/Userland/Utilities/headless-browser.cpp index 75a1ffa299..a0ab097a7a 100644 --- a/Userland/Utilities/headless-browser.cpp +++ b/Userland/Utilities/headless-browser.cpp @@ -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; |