From 3c7bd5a317515ac572610eba2919c82dcd320a1e Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Wed, 2 Nov 2022 17:35:53 +0000 Subject: [PATCH] LibWeb+WebContent+headless-browser: Use CSSPixels for PageClient events ...and also for hit testing, which is involved in most of them. Much of this is temporary conversions and other awkwardness, which should resolve itself as the rest of LibWeb is converted to these new types. Hopefully. :thousandyakstare: --- Userland/Libraries/LibWeb/DOM/Element.cpp | 2 +- .../Libraries/LibWeb/HTML/BrowsingContext.cpp | 12 +++---- .../Libraries/LibWeb/HTML/BrowsingContext.h | 4 +-- Userland/Libraries/LibWeb/Layout/Label.cpp | 18 +++++----- Userland/Libraries/LibWeb/Layout/Label.h | 8 ++--- .../Libraries/LibWeb/Page/EventHandler.cpp | 34 +++++++++---------- Userland/Libraries/LibWeb/Page/EventHandler.h | 11 +++--- Userland/Libraries/LibWeb/Page/Page.cpp | 20 +++++------ Userland/Libraries/LibWeb/Page/Page.h | 24 ++++++------- .../LibWeb/Painting/LabelablePaintable.cpp | 10 +++--- .../LibWeb/Painting/LabelablePaintable.h | 6 ++-- .../Libraries/LibWeb/Painting/Paintable.cpp | 10 +++--- .../Libraries/LibWeb/Painting/Paintable.h | 10 +++--- .../LibWeb/Painting/PaintableBox.cpp | 14 ++++---- .../Libraries/LibWeb/Painting/PaintableBox.h | 6 ++-- .../LibWeb/Painting/StackingContext.cpp | 21 +++++++----- .../LibWeb/Painting/StackingContext.h | 2 +- .../LibWeb/Painting/TextPaintable.cpp | 6 ++-- .../Libraries/LibWeb/Painting/TextPaintable.h | 6 ++-- .../Libraries/LibWeb/UIEvents/MouseEvent.cpp | 10 +++--- .../Libraries/LibWeb/UIEvents/MouseEvent.h | 3 +- .../Libraries/LibWeb/UIEvents/WheelEvent.cpp | 10 +++--- .../Libraries/LibWeb/UIEvents/WheelEvent.h | 2 +- .../WebContent/ConnectionFromClient.cpp | 10 +++--- Userland/Services/WebContent/PageHost.cpp | 34 +++++++++++-------- Userland/Services/WebContent/PageHost.h | 16 ++++----- Userland/Utilities/headless-browser.cpp | 19 +++++------ 27 files changed, 169 insertions(+), 159 deletions(-) diff --git a/Userland/Libraries/LibWeb/DOM/Element.cpp b/Userland/Libraries/LibWeb/DOM/Element.cpp index f79fa7065c..e7071bb7ec 100644 --- a/Userland/Libraries/LibWeb/DOM/Element.cpp +++ b/Userland/Libraries/LibWeb/DOM/Element.cpp @@ -1210,7 +1210,7 @@ static void scroll_an_element_into_view(DOM::Element& element, Bindings::ScrollB if (!layout_node) return; - page->client().page_did_request_scroll_into_view(verify_cast(*layout_node).paint_box()->absolute_padding_box_rect().to_rounded()); + page->client().page_did_request_scroll_into_view(verify_cast(*layout_node).paint_box()->absolute_padding_box_rect().to_type()); } // https://w3c.github.io/csswg-drafts/cssom-view-1/#dom-element-scrollintoview diff --git a/Userland/Libraries/LibWeb/HTML/BrowsingContext.cpp b/Userland/Libraries/LibWeb/HTML/BrowsingContext.cpp index 4c34c88913..67e136af2a 100644 --- a/Userland/Libraries/LibWeb/HTML/BrowsingContext.cpp +++ b/Userland/Libraries/LibWeb/HTML/BrowsingContext.cpp @@ -375,7 +375,7 @@ void BrowsingContext::set_needs_display(Gfx::IntRect const& rect) if (is_top_level()) { if (m_page) - m_page->client().page_did_invalidate(to_top_level_rect(rect)); + m_page->client().page_did_invalidate(to_top_level_rect(rect.to_type())); return; } @@ -389,7 +389,7 @@ void BrowsingContext::scroll_to(Gfx::IntPoint position) active_document()->force_layout(); if (m_page) - m_page->client().page_did_request_scroll_to(position); + m_page->client().page_did_request_scroll_to(position.to_type()); } void BrowsingContext::scroll_to_anchor(DeprecatedString const& fragment) @@ -427,17 +427,17 @@ void BrowsingContext::scroll_to_anchor(DeprecatedString const& fragment) } if (m_page) - m_page->client().page_did_request_scroll_into_view(enclosing_int_rect(float_rect)); + m_page->client().page_did_request_scroll_into_view(float_rect.to_type()); } -Gfx::IntRect BrowsingContext::to_top_level_rect(Gfx::IntRect const& a_rect) +CSSPixelRect BrowsingContext::to_top_level_rect(CSSPixelRect const& a_rect) { auto rect = a_rect; rect.set_location(to_top_level_position(a_rect.location())); return rect; } -Gfx::IntPoint BrowsingContext::to_top_level_position(Gfx::IntPoint a_position) +CSSPixelPoint BrowsingContext::to_top_level_position(CSSPixelPoint a_position) { auto position = a_position; for (auto ancestor = parent(); ancestor; ancestor = ancestor->parent()) { @@ -447,7 +447,7 @@ Gfx::IntPoint BrowsingContext::to_top_level_position(Gfx::IntPoint a_position) return {}; if (!ancestor->container()->layout_node()) return {}; - position.translate_by(ancestor->container()->layout_node()->box_type_agnostic_position().to_type()); + position.translate_by(ancestor->container()->layout_node()->box_type_agnostic_position().to_type()); } return position; } diff --git a/Userland/Libraries/LibWeb/HTML/BrowsingContext.h b/Userland/Libraries/LibWeb/HTML/BrowsingContext.h index f6de079b7d..af6ccec47c 100644 --- a/Userland/Libraries/LibWeb/HTML/BrowsingContext.h +++ b/Userland/Libraries/LibWeb/HTML/BrowsingContext.h @@ -183,8 +183,8 @@ public: HTML::BrowsingContextContainer* container() { return m_container; } HTML::BrowsingContextContainer const* container() const { return m_container; } - Gfx::IntPoint to_top_level_position(Gfx::IntPoint); - Gfx::IntRect to_top_level_rect(Gfx::IntRect const&); + CSSPixelPoint to_top_level_position(CSSPixelPoint); + CSSPixelRect to_top_level_rect(CSSPixelRect const&); DOM::Position const& cursor_position() const { return m_cursor_position; } void set_cursor_position(DOM::Position); diff --git a/Userland/Libraries/LibWeb/Layout/Label.cpp b/Userland/Libraries/LibWeb/Layout/Label.cpp index 8c484c09e0..cdf0d7ac17 100644 --- a/Userland/Libraries/LibWeb/Layout/Label.cpp +++ b/Userland/Libraries/LibWeb/Layout/Label.cpp @@ -22,7 +22,7 @@ Label::Label(DOM::Document& document, HTML::HTMLLabelElement* element, NonnullRe Label::~Label() = default; -void Label::handle_mousedown_on_label(Badge, Gfx::IntPoint, unsigned button) +void Label::handle_mousedown_on_label(Badge, CSSPixelPoint, unsigned button) { if (button != GUI::MouseButton::Primary) return; @@ -33,14 +33,14 @@ void Label::handle_mousedown_on_label(Badge, Gfx::IntPo m_tracking_mouse = true; } -void Label::handle_mouseup_on_label(Badge, Gfx::IntPoint position, unsigned button) +void Label::handle_mouseup_on_label(Badge, CSSPixelPoint position, unsigned button) { if (!m_tracking_mouse || button != GUI::MouseButton::Primary) return; if (auto* control = labeled_control(); control) { - bool is_inside_control = enclosing_int_rect(control->paint_box()->absolute_rect()).contains(position); - bool is_inside_label = enclosing_int_rect(paint_box()->absolute_rect()).contains(position); + bool is_inside_control = enclosing_int_rect(control->paint_box()->absolute_rect()).to_type().contains(position); + bool is_inside_label = enclosing_int_rect(paint_box()->absolute_rect()).to_type().contains(position); if (is_inside_control || is_inside_label) control->paintable()->handle_associated_label_mouseup({}); @@ -49,23 +49,23 @@ void Label::handle_mouseup_on_label(Badge, Gfx::IntPoin m_tracking_mouse = false; } -void Label::handle_mousemove_on_label(Badge, Gfx::IntPoint position, unsigned) +void Label::handle_mousemove_on_label(Badge, CSSPixelPoint position, unsigned) { if (!m_tracking_mouse) return; if (auto* control = labeled_control(); control) { - bool is_inside_control = enclosing_int_rect(control->paint_box()->absolute_rect()).contains(position); - bool is_inside_label = enclosing_int_rect(paint_box()->absolute_rect()).contains(position); + bool is_inside_control = enclosing_int_rect(control->paint_box()->absolute_rect()).to_type().contains(position); + bool is_inside_label = enclosing_int_rect(paint_box()->absolute_rect()).to_type().contains(position); control->paintable()->handle_associated_label_mousemove({}, is_inside_control || is_inside_label); } } -bool Label::is_inside_associated_label(LabelableNode const& control, Gfx::IntPoint position) +bool Label::is_inside_associated_label(LabelableNode const& control, CSSPixelPoint position) { if (auto* label = label_for_control_node(control); label) - return enclosing_int_rect(label->paint_box()->absolute_rect()).contains(position); + return enclosing_int_rect(label->paint_box()->absolute_rect()).to_type().contains(position); return false; } diff --git a/Userland/Libraries/LibWeb/Layout/Label.h b/Userland/Libraries/LibWeb/Layout/Label.h index 89806c00c2..3009b5b331 100644 --- a/Userland/Libraries/LibWeb/Layout/Label.h +++ b/Userland/Libraries/LibWeb/Layout/Label.h @@ -18,15 +18,15 @@ public: Label(DOM::Document&, HTML::HTMLLabelElement*, NonnullRefPtr); virtual ~Label() override; - static bool is_inside_associated_label(LabelableNode const&, Gfx::IntPoint); + static bool is_inside_associated_label(LabelableNode const&, CSSPixelPoint); static bool is_associated_label_hovered(LabelableNode const&); const HTML::HTMLLabelElement& dom_node() const { return static_cast(*BlockContainer::dom_node()); } HTML::HTMLLabelElement& dom_node() { return static_cast(*BlockContainer::dom_node()); } - void handle_mousedown_on_label(Badge, Gfx::IntPoint, unsigned button); - void handle_mouseup_on_label(Badge, Gfx::IntPoint, unsigned button); - void handle_mousemove_on_label(Badge, Gfx::IntPoint, unsigned button); + void handle_mousedown_on_label(Badge, CSSPixelPoint, unsigned button); + void handle_mouseup_on_label(Badge, CSSPixelPoint, unsigned button); + void handle_mousemove_on_label(Badge, CSSPixelPoint, unsigned button); LabelableNode* labeled_control(); diff --git a/Userland/Libraries/LibWeb/Page/EventHandler.cpp b/Userland/Libraries/LibWeb/Page/EventHandler.cpp index e4d86e0a78..b2e46c4338 100644 --- a/Userland/Libraries/LibWeb/Page/EventHandler.cpp +++ b/Userland/Libraries/LibWeb/Page/EventHandler.cpp @@ -102,12 +102,12 @@ static Gfx::StandardCursor cursor_css_to_gfx(Optional cursor) } } -static Gfx::IntPoint compute_mouse_event_offset(Gfx::IntPoint position, Layout::Node const& layout_node) +static CSSPixelPoint compute_mouse_event_offset(CSSPixelPoint position, Layout::Node const& layout_node) { auto top_left_of_layout_node = layout_node.box_type_agnostic_position(); return { - position.x() - static_cast(top_left_of_layout_node.x()), - position.y() - static_cast(top_left_of_layout_node.y()) + position.x() - top_left_of_layout_node.x(), + position.y() - top_left_of_layout_node.y() }; } @@ -147,7 +147,7 @@ Painting::PaintableBox const* EventHandler::paint_root() const return const_cast(m_browsing_context.active_document()->paint_box()); } -bool EventHandler::handle_mousewheel(Gfx::IntPoint position, unsigned button, unsigned buttons, unsigned int modifiers, int wheel_delta_x, int wheel_delta_y) +bool EventHandler::handle_mousewheel(CSSPixelPoint position, unsigned button, unsigned buttons, unsigned int modifiers, int wheel_delta_x, int wheel_delta_y) { if (m_browsing_context.active_document()) m_browsing_context.active_document()->update_layout(); @@ -164,7 +164,7 @@ bool EventHandler::handle_mousewheel(Gfx::IntPoint position, unsigned button, un if (m_mouse_event_tracking_layout_node) { paintable = m_mouse_event_tracking_layout_node->paintable(); } else { - if (auto result = paint_root()->hit_test(position.to_type(), Painting::HitTestType::Exact); result.has_value()) + if (auto result = paint_root()->hit_test(position, Painting::HitTestType::Exact); result.has_value()) paintable = result->paintable; } @@ -198,7 +198,7 @@ bool EventHandler::handle_mousewheel(Gfx::IntPoint position, unsigned button, un return handled_event; } -bool EventHandler::handle_mouseup(Gfx::IntPoint position, unsigned button, unsigned buttons, unsigned modifiers) +bool EventHandler::handle_mouseup(CSSPixelPoint position, unsigned button, unsigned buttons, unsigned modifiers) { if (m_browsing_context.active_document()) m_browsing_context.active_document()->update_layout(); @@ -212,7 +212,7 @@ bool EventHandler::handle_mouseup(Gfx::IntPoint position, unsigned button, unsig if (m_mouse_event_tracking_layout_node) { paintable = m_mouse_event_tracking_layout_node->paintable(); } else { - if (auto result = paint_root()->hit_test(position.to_type(), Painting::HitTestType::Exact); result.has_value()) + if (auto result = paint_root()->hit_test(position, Painting::HitTestType::Exact); result.has_value()) paintable = result->paintable; } @@ -223,7 +223,7 @@ bool EventHandler::handle_mouseup(Gfx::IntPoint position, unsigned button, unsig // Things may have changed as a consequence of Layout::Node::handle_mouseup(). Hit test again. if (!paint_root()) return true; - if (auto result = paint_root()->hit_test(position.to_type(), Painting::HitTestType::Exact); result.has_value()) + if (auto result = paint_root()->hit_test(position, Painting::HitTestType::Exact); result.has_value()) paintable = result->paintable; } @@ -313,7 +313,7 @@ after_node_use: return handled_event; } -bool EventHandler::handle_mousedown(Gfx::IntPoint position, unsigned button, unsigned buttons, unsigned modifiers) +bool EventHandler::handle_mousedown(CSSPixelPoint position, unsigned button, unsigned buttons, unsigned modifiers) { if (m_browsing_context.active_document()) m_browsing_context.active_document()->update_layout(); @@ -329,7 +329,7 @@ bool EventHandler::handle_mousedown(Gfx::IntPoint position, unsigned button, uns if (m_mouse_event_tracking_layout_node) { paintable = m_mouse_event_tracking_layout_node->paintable(); } else { - auto result = paint_root()->hit_test(position.to_type(), Painting::HitTestType::Exact); + auto result = paint_root()->hit_test(position, Painting::HitTestType::Exact); if (!result.has_value()) return false; paintable = result->paintable; @@ -376,7 +376,7 @@ bool EventHandler::handle_mousedown(Gfx::IntPoint position, unsigned button, uns return true; if (button == GUI::MouseButton::Primary) { - if (auto result = paint_root()->hit_test(position.to_type(), Painting::HitTestType::TextCursor); result.has_value()) { + if (auto result = paint_root()->hit_test(position, Painting::HitTestType::TextCursor); result.has_value()) { auto paintable = result->paintable; if (paintable->dom_node()) { // See if we want to focus something. @@ -404,7 +404,7 @@ bool EventHandler::handle_mousedown(Gfx::IntPoint position, unsigned button, uns return true; } -bool EventHandler::handle_mousemove(Gfx::IntPoint position, unsigned buttons, unsigned modifiers) +bool EventHandler::handle_mousemove(CSSPixelPoint position, unsigned buttons, unsigned modifiers) { if (m_browsing_context.active_document()) m_browsing_context.active_document()->update_layout(); @@ -423,7 +423,7 @@ bool EventHandler::handle_mousemove(Gfx::IntPoint position, unsigned buttons, un if (m_mouse_event_tracking_layout_node) { paintable = m_mouse_event_tracking_layout_node->paintable(); } else { - if (auto result = paint_root()->hit_test(position.to_type(), Painting::HitTestType::Exact); result.has_value()) { + if (auto result = paint_root()->hit_test(position, Painting::HitTestType::Exact); result.has_value()) { paintable = result->paintable; start_index = result->index_in_node; } @@ -486,7 +486,7 @@ bool EventHandler::handle_mousemove(Gfx::IntPoint position, unsigned buttons, un return true; } if (m_in_mouse_selection) { - auto hit = paint_root()->hit_test(position.to_type(), Painting::HitTestType::TextCursor); + auto hit = paint_root()->hit_test(position, Painting::HitTestType::TextCursor); if (start_index.has_value() && hit.has_value() && hit->dom_node()) { m_browsing_context.set_cursor_position(DOM::Position(*hit->dom_node(), *start_index)); layout_root()->set_selection_end({ hit->paintable->layout_node(), hit->index_in_node }); @@ -516,7 +516,7 @@ bool EventHandler::handle_mousemove(Gfx::IntPoint position, unsigned buttons, un return true; } -bool EventHandler::handle_doubleclick(Gfx::IntPoint position, unsigned button, unsigned buttons, unsigned modifiers) +bool EventHandler::handle_doubleclick(CSSPixelPoint position, unsigned button, unsigned buttons, unsigned modifiers) { if (m_browsing_context.active_document()) m_browsing_context.active_document()->update_layout(); @@ -528,7 +528,7 @@ bool EventHandler::handle_doubleclick(Gfx::IntPoint position, unsigned button, u if (m_mouse_event_tracking_layout_node) { paintable = m_mouse_event_tracking_layout_node->paintable(); } else { - auto result = paint_root()->hit_test(position.to_type(), Painting::HitTestType::Exact); + auto result = paint_root()->hit_test(position, Painting::HitTestType::Exact); if (!result.has_value()) return false; paintable = result->paintable; @@ -568,7 +568,7 @@ bool EventHandler::handle_doubleclick(Gfx::IntPoint position, unsigned button, u return true; if (button == GUI::MouseButton::Primary) { - if (auto result = paint_root()->hit_test(position.to_type(), Painting::HitTestType::TextCursor); result.has_value()) { + if (auto result = paint_root()->hit_test(position, Painting::HitTestType::TextCursor); result.has_value()) { auto hit_paintable = result->paintable; if (!hit_paintable->dom_node()) return true; diff --git a/Userland/Libraries/LibWeb/Page/EventHandler.h b/Userland/Libraries/LibWeb/Page/EventHandler.h index 71832e5ea3..ee1de0cbda 100644 --- a/Userland/Libraries/LibWeb/Page/EventHandler.h +++ b/Userland/Libraries/LibWeb/Page/EventHandler.h @@ -14,6 +14,7 @@ #include #include #include +#include namespace Web { @@ -22,11 +23,11 @@ public: explicit EventHandler(Badge, HTML::BrowsingContext&); ~EventHandler(); - bool handle_mouseup(Gfx::IntPoint, unsigned button, unsigned buttons, unsigned modifiers); - bool handle_mousedown(Gfx::IntPoint, unsigned button, unsigned buttons, unsigned modifiers); - bool handle_mousemove(Gfx::IntPoint, unsigned buttons, unsigned modifiers); - bool handle_mousewheel(Gfx::IntPoint, unsigned button, unsigned buttons, unsigned modifiers, int wheel_delta_x, int wheel_delta_y); - bool handle_doubleclick(Gfx::IntPoint, unsigned button, unsigned buttons, unsigned modifiers); + bool handle_mouseup(CSSPixelPoint, unsigned button, unsigned buttons, unsigned modifiers); + bool handle_mousedown(CSSPixelPoint, unsigned button, unsigned buttons, unsigned modifiers); + bool handle_mousemove(CSSPixelPoint, unsigned buttons, unsigned modifiers); + bool handle_mousewheel(CSSPixelPoint, unsigned button, unsigned buttons, unsigned modifiers, int wheel_delta_x, int wheel_delta_y); + bool handle_doubleclick(CSSPixelPoint, unsigned button, unsigned buttons, unsigned modifiers); bool handle_keydown(KeyCode, unsigned modifiers, u32 code_point); bool handle_keyup(KeyCode, unsigned modifiers, u32 code_point); diff --git a/Userland/Libraries/LibWeb/Page/Page.cpp b/Userland/Libraries/LibWeb/Page/Page.cpp index b38956699b..150fa3593a 100644 --- a/Userland/Libraries/LibWeb/Page/Page.cpp +++ b/Userland/Libraries/LibWeb/Page/Page.cpp @@ -122,29 +122,29 @@ DevicePixelRect Page::rounded_device_rect(CSSPixelRect rect) const }; } -bool Page::handle_mousewheel(Gfx::IntPoint position, unsigned button, unsigned buttons, unsigned modifiers, int wheel_delta_x, int wheel_delta_y) +bool Page::handle_mousewheel(DevicePixelPoint position, unsigned button, unsigned buttons, unsigned modifiers, int wheel_delta_x, int wheel_delta_y) { - return top_level_browsing_context().event_handler().handle_mousewheel(position, button, buttons, modifiers, wheel_delta_x, wheel_delta_y); + return top_level_browsing_context().event_handler().handle_mousewheel(device_to_css_point(position), button, buttons, modifiers, wheel_delta_x, wheel_delta_y); } -bool Page::handle_mouseup(Gfx::IntPoint position, unsigned button, unsigned buttons, unsigned modifiers) +bool Page::handle_mouseup(DevicePixelPoint position, unsigned button, unsigned buttons, unsigned modifiers) { - return top_level_browsing_context().event_handler().handle_mouseup(position, button, buttons, modifiers); + return top_level_browsing_context().event_handler().handle_mouseup(device_to_css_point(position), button, buttons, modifiers); } -bool Page::handle_mousedown(Gfx::IntPoint position, unsigned button, unsigned buttons, unsigned modifiers) +bool Page::handle_mousedown(DevicePixelPoint position, unsigned button, unsigned buttons, unsigned modifiers) { - return top_level_browsing_context().event_handler().handle_mousedown(position, button, buttons, modifiers); + return top_level_browsing_context().event_handler().handle_mousedown(device_to_css_point(position), button, buttons, modifiers); } -bool Page::handle_mousemove(Gfx::IntPoint position, unsigned buttons, unsigned modifiers) +bool Page::handle_mousemove(DevicePixelPoint position, unsigned buttons, unsigned modifiers) { - return top_level_browsing_context().event_handler().handle_mousemove(position, buttons, modifiers); + return top_level_browsing_context().event_handler().handle_mousemove(device_to_css_point(position), buttons, modifiers); } -bool Page::handle_doubleclick(Gfx::IntPoint position, unsigned button, unsigned buttons, unsigned modifiers) +bool Page::handle_doubleclick(DevicePixelPoint position, unsigned button, unsigned buttons, unsigned modifiers) { - return top_level_browsing_context().event_handler().handle_doubleclick(position, button, buttons, modifiers); + return top_level_browsing_context().event_handler().handle_doubleclick(device_to_css_point(position), button, buttons, modifiers); } bool Page::handle_keydown(KeyCode key, unsigned modifiers, u32 code_point) diff --git a/Userland/Libraries/LibWeb/Page/Page.h b/Userland/Libraries/LibWeb/Page/Page.h index dde45bf915..d958775373 100644 --- a/Userland/Libraries/LibWeb/Page/Page.h +++ b/Userland/Libraries/LibWeb/Page/Page.h @@ -62,11 +62,11 @@ public: DevicePixelRect enclosing_device_rect(CSSPixelRect) const; DevicePixelRect rounded_device_rect(CSSPixelRect) const; - bool handle_mouseup(Gfx::IntPoint, unsigned button, unsigned buttons, unsigned modifiers); - bool handle_mousedown(Gfx::IntPoint, unsigned button, unsigned buttons, unsigned modifiers); - bool handle_mousemove(Gfx::IntPoint, unsigned buttons, unsigned modifiers); - bool handle_mousewheel(Gfx::IntPoint, unsigned button, unsigned buttons, unsigned modifiers, int wheel_delta_x, int wheel_delta_y); - bool handle_doubleclick(Gfx::IntPoint, unsigned button, unsigned buttons, unsigned modifiers); + bool handle_mouseup(DevicePixelPoint, unsigned button, unsigned buttons, unsigned modifiers); + bool handle_mousedown(DevicePixelPoint, unsigned button, unsigned buttons, unsigned modifiers); + bool handle_mousemove(DevicePixelPoint, unsigned buttons, unsigned modifiers); + bool handle_mousewheel(DevicePixelPoint, unsigned button, unsigned buttons, unsigned modifiers, int wheel_delta_x, int wheel_delta_y); + bool handle_doubleclick(DevicePixelPoint, unsigned button, unsigned buttons, unsigned modifiers); bool handle_keydown(KeyCode, unsigned modifiers, u32 code_point); bool handle_keyup(KeyCode, unsigned modifiers, u32 code_point); @@ -166,21 +166,21 @@ public: virtual void page_did_finish_loading(const AK::URL&) { } virtual void page_did_change_selection() { } virtual void page_did_request_cursor_change(Gfx::StandardCursor) { } - virtual void page_did_request_context_menu(Gfx::IntPoint) { } - virtual void page_did_request_link_context_menu(Gfx::IntPoint, const AK::URL&, [[maybe_unused]] DeprecatedString const& target, [[maybe_unused]] unsigned modifiers) { } - virtual void page_did_request_image_context_menu(Gfx::IntPoint, const AK::URL&, [[maybe_unused]] DeprecatedString const& target, [[maybe_unused]] unsigned modifiers, Gfx::Bitmap const*) { } + virtual void page_did_request_context_menu(CSSPixelPoint) { } + virtual void page_did_request_link_context_menu(CSSPixelPoint, AK::URL const&, [[maybe_unused]] DeprecatedString const& target, [[maybe_unused]] unsigned modifiers) { } + virtual void page_did_request_image_context_menu(CSSPixelPoint, AK::URL const&, [[maybe_unused]] DeprecatedString const& target, [[maybe_unused]] unsigned modifiers, Gfx::Bitmap const*) { } virtual void page_did_click_link(const AK::URL&, [[maybe_unused]] DeprecatedString const& target, [[maybe_unused]] unsigned modifiers) { } virtual void page_did_middle_click_link(const AK::URL&, [[maybe_unused]] DeprecatedString const& target, [[maybe_unused]] unsigned modifiers) { } - virtual void page_did_enter_tooltip_area(Gfx::IntPoint, DeprecatedString const&) { } + virtual void page_did_enter_tooltip_area(CSSPixelPoint, DeprecatedString const&) { } virtual void page_did_leave_tooltip_area() { } virtual void page_did_hover_link(const AK::URL&) { } virtual void page_did_unhover_link() { } - virtual void page_did_invalidate(Gfx::IntRect const&) { } + virtual void page_did_invalidate(CSSPixelRect const&) { } virtual void page_did_change_favicon(Gfx::Bitmap const&) { } virtual void page_did_layout() { } virtual void page_did_request_scroll(i32, i32) { } - virtual void page_did_request_scroll_to(Gfx::IntPoint) { } - virtual void page_did_request_scroll_into_view(Gfx::IntRect const&) { } + virtual void page_did_request_scroll_to(CSSPixelPoint) { } + virtual void page_did_request_scroll_into_view(CSSPixelRect const&) { } virtual void page_did_request_alert(DeprecatedString const&) { } virtual void page_did_request_confirm(DeprecatedString const&) { } virtual void page_did_request_prompt(DeprecatedString const&, DeprecatedString const&) { } diff --git a/Userland/Libraries/LibWeb/Painting/LabelablePaintable.cpp b/Userland/Libraries/LibWeb/Painting/LabelablePaintable.cpp index 358956e780..ebedfdf967 100644 --- a/Userland/Libraries/LibWeb/Painting/LabelablePaintable.cpp +++ b/Userland/Libraries/LibWeb/Painting/LabelablePaintable.cpp @@ -35,7 +35,7 @@ Layout::FormAssociatedLabelableNode& LabelablePaintable::layout_box() return static_cast(PaintableBox::layout_box()); } -LabelablePaintable::DispatchEventOfSameName LabelablePaintable::handle_mousedown(Badge, Gfx::IntPoint, unsigned button, unsigned) +LabelablePaintable::DispatchEventOfSameName LabelablePaintable::handle_mousedown(Badge, CSSPixelPoint, unsigned button, unsigned) { if (button != GUI::MouseButton::Primary || !layout_box().dom_node().enabled()) return DispatchEventOfSameName::No; @@ -46,12 +46,12 @@ LabelablePaintable::DispatchEventOfSameName LabelablePaintable::handle_mousedown return DispatchEventOfSameName::Yes; } -LabelablePaintable::DispatchEventOfSameName LabelablePaintable::handle_mouseup(Badge, Gfx::IntPoint position, unsigned button, unsigned) +LabelablePaintable::DispatchEventOfSameName LabelablePaintable::handle_mouseup(Badge, CSSPixelPoint position, unsigned button, unsigned) { if (!m_tracking_mouse || button != GUI::MouseButton::Primary || !layout_box().dom_node().enabled()) return DispatchEventOfSameName::No; - bool is_inside_node_or_label = enclosing_int_rect(absolute_rect()).contains(position); + bool is_inside_node_or_label = absolute_rect().to_type().contains(position); if (!is_inside_node_or_label) is_inside_node_or_label = Layout::Label::is_inside_associated_label(layout_box(), position); @@ -61,12 +61,12 @@ LabelablePaintable::DispatchEventOfSameName LabelablePaintable::handle_mouseup(B return DispatchEventOfSameName::Yes; } -LabelablePaintable::DispatchEventOfSameName LabelablePaintable::handle_mousemove(Badge, Gfx::IntPoint position, unsigned, unsigned) +LabelablePaintable::DispatchEventOfSameName LabelablePaintable::handle_mousemove(Badge, CSSPixelPoint position, unsigned, unsigned) { if (!m_tracking_mouse || !layout_box().dom_node().enabled()) return DispatchEventOfSameName::No; - bool is_inside_node_or_label = enclosing_int_rect(absolute_rect()).contains(position); + bool is_inside_node_or_label = absolute_rect().to_type().contains(position); if (!is_inside_node_or_label) is_inside_node_or_label = Layout::Label::is_inside_associated_label(layout_box(), position); diff --git a/Userland/Libraries/LibWeb/Painting/LabelablePaintable.h b/Userland/Libraries/LibWeb/Painting/LabelablePaintable.h index 7f256f628f..c64555c127 100644 --- a/Userland/Libraries/LibWeb/Painting/LabelablePaintable.h +++ b/Userland/Libraries/LibWeb/Painting/LabelablePaintable.h @@ -21,9 +21,9 @@ public: Layout::FormAssociatedLabelableNode& layout_box(); virtual bool wants_mouse_events() const override { return true; } - virtual DispatchEventOfSameName handle_mousedown(Badge, Gfx::IntPoint, unsigned button, unsigned modifiers) override; - virtual DispatchEventOfSameName handle_mouseup(Badge, Gfx::IntPoint, unsigned button, unsigned modifiers) override; - virtual DispatchEventOfSameName handle_mousemove(Badge, Gfx::IntPoint, unsigned buttons, unsigned modifiers) override; + virtual DispatchEventOfSameName handle_mousedown(Badge, CSSPixelPoint, unsigned button, unsigned modifiers) override; + virtual DispatchEventOfSameName handle_mouseup(Badge, CSSPixelPoint, unsigned button, unsigned modifiers) override; + virtual DispatchEventOfSameName handle_mousemove(Badge, CSSPixelPoint, unsigned buttons, unsigned modifiers) override; void handle_associated_label_mousedown(Badge); void handle_associated_label_mouseup(Badge); diff --git a/Userland/Libraries/LibWeb/Painting/Paintable.cpp b/Userland/Libraries/LibWeb/Painting/Paintable.cpp index 1fcc14fd27..37154bc3d2 100644 --- a/Userland/Libraries/LibWeb/Painting/Paintable.cpp +++ b/Userland/Libraries/LibWeb/Painting/Paintable.cpp @@ -10,22 +10,22 @@ namespace Web::Painting { -Paintable::DispatchEventOfSameName Paintable::handle_mousedown(Badge, Gfx::IntPoint, unsigned, unsigned) +Paintable::DispatchEventOfSameName Paintable::handle_mousedown(Badge, CSSPixelPoint, unsigned, unsigned) { return DispatchEventOfSameName::Yes; } -Paintable::DispatchEventOfSameName Paintable::handle_mouseup(Badge, Gfx::IntPoint, unsigned, unsigned) +Paintable::DispatchEventOfSameName Paintable::handle_mouseup(Badge, CSSPixelPoint, unsigned, unsigned) { return DispatchEventOfSameName::Yes; } -Paintable::DispatchEventOfSameName Paintable::handle_mousemove(Badge, Gfx::IntPoint, unsigned, unsigned) +Paintable::DispatchEventOfSameName Paintable::handle_mousemove(Badge, CSSPixelPoint, unsigned, unsigned) { return DispatchEventOfSameName::Yes; } -bool Paintable::handle_mousewheel(Badge, Gfx::IntPoint, unsigned, unsigned, int wheel_delta_x, int wheel_delta_y) +bool Paintable::handle_mousewheel(Badge, CSSPixelPoint, unsigned, unsigned, int wheel_delta_x, int wheel_delta_y) { if (auto* containing_block = this->containing_block()) { if (!containing_block->is_scrollable()) @@ -41,7 +41,7 @@ bool Paintable::handle_mousewheel(Badge, Gfx::IntPoint, unsigned, return false; } -Optional Paintable::hit_test(Gfx::FloatPoint, HitTestType) const +Optional Paintable::hit_test(CSSPixelPoint, HitTestType) const { return {}; } diff --git a/Userland/Libraries/LibWeb/Painting/Paintable.h b/Userland/Libraries/LibWeb/Painting/Paintable.h index a868ff9ab3..e791aa6c63 100644 --- a/Userland/Libraries/LibWeb/Painting/Paintable.h +++ b/Userland/Libraries/LibWeb/Painting/Paintable.h @@ -89,7 +89,7 @@ public: virtual void before_children_paint(PaintContext&, PaintPhase) const { } virtual void after_children_paint(PaintContext&, PaintPhase) const { } - virtual Optional hit_test(Gfx::FloatPoint, HitTestType) const; + virtual Optional hit_test(CSSPixelPoint, HitTestType) const; virtual bool wants_mouse_events() const { return false; } @@ -100,12 +100,12 @@ public: // When these methods return true, the DOM event with the same name will be // dispatch at the mouse_event_target if it returns a valid DOM::Node, or // the layout node's associated DOM node if it doesn't. - virtual DispatchEventOfSameName handle_mousedown(Badge, Gfx::IntPoint, unsigned button, unsigned modifiers); - virtual DispatchEventOfSameName handle_mouseup(Badge, Gfx::IntPoint, unsigned button, unsigned modifiers); - virtual DispatchEventOfSameName handle_mousemove(Badge, Gfx::IntPoint, unsigned buttons, unsigned modifiers); + virtual DispatchEventOfSameName handle_mousedown(Badge, CSSPixelPoint, unsigned button, unsigned modifiers); + virtual DispatchEventOfSameName handle_mouseup(Badge, CSSPixelPoint, unsigned button, unsigned modifiers); + virtual DispatchEventOfSameName handle_mousemove(Badge, CSSPixelPoint, unsigned buttons, unsigned modifiers); virtual DOM::Node* mouse_event_target() const { return nullptr; } - virtual bool handle_mousewheel(Badge, Gfx::IntPoint, unsigned buttons, unsigned modifiers, int wheel_delta_x, int wheel_delta_y); + virtual bool handle_mousewheel(Badge, CSSPixelPoint, unsigned buttons, unsigned modifiers, int wheel_delta_x, int wheel_delta_y); Layout::Node const& layout_node() const { return m_layout_node; } Layout::Node& layout_node() { return const_cast(m_layout_node); } diff --git a/Userland/Libraries/LibWeb/Painting/PaintableBox.cpp b/Userland/Libraries/LibWeb/Painting/PaintableBox.cpp index c9703d417e..6634269b68 100644 --- a/Userland/Libraries/LibWeb/Painting/PaintableBox.cpp +++ b/Userland/Libraries/LibWeb/Painting/PaintableBox.cpp @@ -630,7 +630,7 @@ void PaintableWithLines::paint(PaintContext& context, PaintPhase phase) const } } -bool PaintableWithLines::handle_mousewheel(Badge, Gfx::IntPoint, unsigned, unsigned, int wheel_delta_x, int wheel_delta_y) +bool PaintableWithLines::handle_mousewheel(Badge, CSSPixelPoint, unsigned, unsigned, int wheel_delta_x, int wheel_delta_y) { if (!layout_box().is_scrollable()) return false; @@ -655,7 +655,7 @@ void PaintableBox::set_stacking_context(NonnullOwnPtr stacking_ m_stacking_context = move(stacking_context); } -Optional PaintableBox::hit_test(Gfx::FloatPoint position, HitTestType type) const +Optional PaintableBox::hit_test(CSSPixelPoint position, HitTestType type) const { if (!is_visible()) return {}; @@ -665,7 +665,7 @@ Optional PaintableBox::hit_test(Gfx::FloatPoint position, HitTest return stacking_context()->hit_test(position, type); } - if (!absolute_border_box_rect().contains(position.x(), position.y())) + if (!absolute_border_box_rect().contains(position.x().value(), position.y().value())) return {}; for (auto* child = first_child(); child; child = child->next_sibling()) { @@ -679,7 +679,7 @@ Optional PaintableBox::hit_test(Gfx::FloatPoint position, HitTest return HitTestResult { *this }; } -Optional PaintableWithLines::hit_test(Gfx::FloatPoint position, HitTestType type) const +Optional PaintableWithLines::hit_test(CSSPixelPoint position, HitTestType type) const { if (!layout_box().children_are_inline()) return PaintableBox::hit_test(position, type); @@ -693,11 +693,11 @@ Optional PaintableWithLines::hit_test(Gfx::FloatPoint position, H dbgln("FIXME: PaintableWithLines::hit_test(): Missing containing block on {}", fragment.layout_node().debug_description()); continue; } - auto fragment_absolute_rect = fragment.absolute_rect(); + auto fragment_absolute_rect = fragment.absolute_rect().to_type(); if (fragment_absolute_rect.contains(position)) { if (is(fragment.layout_node()) && fragment.layout_node().paintable()) return fragment.layout_node().paintable()->hit_test(position, type); - return HitTestResult { *fragment.layout_node().paintable(), fragment.text_index_at(position.x()) }; + return HitTestResult { *fragment.layout_node().paintable(), fragment.text_index_at(position.x().value()) }; } if (fragment_absolute_rect.top() <= position.y()) last_good_candidate = HitTestResult { *fragment.layout_node().paintable(), fragment.length() + 1 }; @@ -706,7 +706,7 @@ Optional PaintableWithLines::hit_test(Gfx::FloatPoint position, H if (type == HitTestType::TextCursor && last_good_candidate.has_value()) return last_good_candidate; - if (is_visible() && absolute_border_box_rect().contains(position.x(), position.y())) + if (is_visible() && absolute_border_box_rect().contains(position.x().value(), position.y().value())) return HitTestResult { *this }; return {}; } diff --git a/Userland/Libraries/LibWeb/Painting/PaintableBox.h b/Userland/Libraries/LibWeb/Painting/PaintableBox.h index a954f00a85..a509c1d886 100644 --- a/Userland/Libraries/LibWeb/Painting/PaintableBox.h +++ b/Userland/Libraries/LibWeb/Painting/PaintableBox.h @@ -115,7 +115,7 @@ public: virtual void before_children_paint(PaintContext&, PaintPhase) const override; virtual void after_children_paint(PaintContext&, PaintPhase) const override; - virtual Optional hit_test(Gfx::FloatPoint, HitTestType) const override; + virtual Optional hit_test(CSSPixelPoint, HitTestType) const override; void invalidate_stacking_context(); @@ -188,9 +188,9 @@ public: virtual void paint(PaintContext&, PaintPhase) const override; virtual bool wants_mouse_events() const override { return false; } - virtual bool handle_mousewheel(Badge, Gfx::IntPoint, unsigned buttons, unsigned modifiers, int wheel_delta_x, int wheel_delta_y) override; + virtual bool handle_mousewheel(Badge, CSSPixelPoint, unsigned buttons, unsigned modifiers, int wheel_delta_x, int wheel_delta_y) override; - virtual Optional hit_test(Gfx::FloatPoint, HitTestType) const override; + virtual Optional hit_test(CSSPixelPoint, HitTestType) const override; protected: PaintableWithLines(Layout::BlockContainer const&); diff --git a/Userland/Libraries/LibWeb/Painting/StackingContext.cpp b/Userland/Libraries/LibWeb/Painting/StackingContext.cpp index cfcc141be3..cfdff679f7 100644 --- a/Userland/Libraries/LibWeb/Painting/StackingContext.cpp +++ b/Userland/Libraries/LibWeb/Painting/StackingContext.cpp @@ -439,17 +439,22 @@ static TraversalDecision for_each_in_subtree_of_type_within_same_stacking_contex return TraversalDecision::Continue; } -Optional StackingContext::hit_test(Gfx::FloatPoint position, HitTestType type) const +Optional StackingContext::hit_test(CSSPixelPoint position, HitTestType type) const { if (!m_box.is_visible()) return {}; - auto transform_origin = this->transform_origin(); - auto transformed_position = affine_transform_matrix().inverse().value_or({}).map(position - transform_origin) + transform_origin; + auto transform_origin = this->transform_origin().to_type(); + // NOTE: This CSSPixels -> Float -> CSSPixels conversion is because we can't AffineTransform::map() a CSSPixelPoint. + Gfx::FloatPoint offset_position { + position.x().value() - transform_origin.x().value(), + position.y().value() - transform_origin.y().value() + }; + auto transformed_position = affine_transform_matrix().inverse().value_or({}).map(offset_position).to_type() + transform_origin; // FIXME: Support more overflow variations. if (paintable().computed_values().overflow_x() == CSS::Overflow::Hidden && paintable().computed_values().overflow_y() == CSS::Overflow::Hidden) { - if (!paintable().absolute_border_box_rect().contains(transformed_position.x(), transformed_position.y())) + if (!paintable().absolute_border_box_rect().contains(transformed_position.x().value(), transformed_position.y().value())) return {}; } @@ -473,7 +478,7 @@ Optional StackingContext::hit_test(Gfx::FloatPoint position, HitT for_each_in_subtree_of_type_within_same_stacking_context_in_reverse(paintable(), [&](PaintableBox const& paint_box) { // FIXME: Support more overflow variations. if (paint_box.computed_values().overflow_x() == CSS::Overflow::Hidden && paint_box.computed_values().overflow_y() == CSS::Overflow::Hidden) { - if (!paint_box.absolute_border_box_rect().contains(transformed_position.x(), transformed_position.y())) + if (!paint_box.absolute_border_box_rect().contains(transformed_position.x().value(), transformed_position.y().value())) return TraversalDecision::SkipChildrenAndContinue; } @@ -521,7 +526,7 @@ Optional StackingContext::hit_test(Gfx::FloatPoint position, HitT for_each_in_subtree_of_type_within_same_stacking_context_in_reverse(paintable(), [&](auto const& paint_box) { // FIXME: Support more overflow variations. if (paint_box.computed_values().overflow_x() == CSS::Overflow::Hidden && paint_box.computed_values().overflow_y() == CSS::Overflow::Hidden) { - if (!paint_box.absolute_border_box_rect().contains(transformed_position.x(), transformed_position.y())) + if (!paint_box.absolute_border_box_rect().contains(transformed_position.x().value(), transformed_position.y().value())) return TraversalDecision::SkipChildrenAndContinue; } @@ -542,7 +547,7 @@ Optional StackingContext::hit_test(Gfx::FloatPoint position, HitT for_each_in_subtree_of_type_within_same_stacking_context_in_reverse(paintable(), [&](auto const& paint_box) { // FIXME: Support more overflow variations. if (paint_box.computed_values().overflow_x() == CSS::Overflow::Hidden && paint_box.computed_values().overflow_y() == CSS::Overflow::Hidden) { - if (!paint_box.absolute_border_box_rect().contains(transformed_position.x(), transformed_position.y())) + if (!paint_box.absolute_border_box_rect().contains(transformed_position.x().value(), transformed_position.y().value())) return TraversalDecision::SkipChildrenAndContinue; } @@ -571,7 +576,7 @@ Optional StackingContext::hit_test(Gfx::FloatPoint position, HitT } // 1. the background and borders of the element forming the stacking context. - if (paintable().absolute_border_box_rect().contains(transformed_position)) { + if (paintable().absolute_border_box_rect().contains(transformed_position.x().value(), transformed_position.y().value())) { return HitTestResult { .paintable = paintable(), }; diff --git a/Userland/Libraries/LibWeb/Painting/StackingContext.h b/Userland/Libraries/LibWeb/Painting/StackingContext.h index 72aba5dce6..7391ec03e8 100644 --- a/Userland/Libraries/LibWeb/Painting/StackingContext.h +++ b/Userland/Libraries/LibWeb/Painting/StackingContext.h @@ -32,7 +32,7 @@ public: void paint_descendants(PaintContext&, Layout::Node const&, StackingContextPaintPhase) const; void paint(PaintContext&) const; - Optional hit_test(Gfx::FloatPoint, HitTestType) const; + Optional hit_test(CSSPixelPoint, HitTestType) const; Gfx::FloatMatrix4x4 const& transform_matrix() const { return m_transform; } Gfx::AffineTransform affine_transform_matrix() const; diff --git a/Userland/Libraries/LibWeb/Painting/TextPaintable.cpp b/Userland/Libraries/LibWeb/Painting/TextPaintable.cpp index 726382f6da..b7e6a146c2 100644 --- a/Userland/Libraries/LibWeb/Painting/TextPaintable.cpp +++ b/Userland/Libraries/LibWeb/Painting/TextPaintable.cpp @@ -36,7 +36,7 @@ DOM::Node* TextPaintable::mouse_event_target() const return nullptr; } -TextPaintable::DispatchEventOfSameName TextPaintable::handle_mousedown(Badge, Gfx::IntPoint position, unsigned button, unsigned) +TextPaintable::DispatchEventOfSameName TextPaintable::handle_mousedown(Badge, CSSPixelPoint position, unsigned button, unsigned) { auto* label = layout_node().first_ancestor_of_type(); if (!label) @@ -46,7 +46,7 @@ TextPaintable::DispatchEventOfSameName TextPaintable::handle_mousedown(Badge, Gfx::IntPoint position, unsigned button, unsigned) +TextPaintable::DispatchEventOfSameName TextPaintable::handle_mouseup(Badge, CSSPixelPoint position, unsigned button, unsigned) { auto* label = layout_node().first_ancestor_of_type(); if (!label) @@ -57,7 +57,7 @@ TextPaintable::DispatchEventOfSameName TextPaintable::handle_mouseup(Badge, Gfx::IntPoint position, unsigned button, unsigned) +TextPaintable::DispatchEventOfSameName TextPaintable::handle_mousemove(Badge, CSSPixelPoint position, unsigned button, unsigned) { auto* label = layout_node().first_ancestor_of_type(); if (!label) diff --git a/Userland/Libraries/LibWeb/Painting/TextPaintable.h b/Userland/Libraries/LibWeb/Painting/TextPaintable.h index fb0cd302d7..dd99ea2e7a 100644 --- a/Userland/Libraries/LibWeb/Painting/TextPaintable.h +++ b/Userland/Libraries/LibWeb/Painting/TextPaintable.h @@ -18,9 +18,9 @@ public: virtual bool wants_mouse_events() const override; virtual DOM::Node* mouse_event_target() const override; - virtual DispatchEventOfSameName handle_mousedown(Badge, Gfx::IntPoint, unsigned button, unsigned modifiers) override; - virtual DispatchEventOfSameName handle_mouseup(Badge, Gfx::IntPoint, unsigned button, unsigned modifiers) override; - virtual DispatchEventOfSameName handle_mousemove(Badge, Gfx::IntPoint, unsigned button, unsigned modifiers) override; + virtual DispatchEventOfSameName handle_mousedown(Badge, CSSPixelPoint, unsigned button, unsigned modifiers) override; + virtual DispatchEventOfSameName handle_mouseup(Badge, CSSPixelPoint, unsigned button, unsigned modifiers) override; + virtual DispatchEventOfSameName handle_mousemove(Badge, CSSPixelPoint, unsigned button, unsigned modifiers) override; private: explicit TextPaintable(Layout::TextNode const&); diff --git a/Userland/Libraries/LibWeb/UIEvents/MouseEvent.cpp b/Userland/Libraries/LibWeb/UIEvents/MouseEvent.cpp index 8ccfe84a9e..8dee161cf6 100644 --- a/Userland/Libraries/LibWeb/UIEvents/MouseEvent.cpp +++ b/Userland/Libraries/LibWeb/UIEvents/MouseEvent.cpp @@ -52,13 +52,13 @@ MouseEvent* MouseEvent::create(JS::Realm& realm, FlyString const& event_name, Mo return realm.heap().allocate(realm, realm, event_name, event_init); } -MouseEvent* MouseEvent::create_from_platform_event(JS::Realm& realm, FlyString const& event_name, double offset_x, double offset_y, double client_x, double client_y, unsigned buttons, unsigned mouse_button) +MouseEvent* MouseEvent::create_from_platform_event(JS::Realm& realm, FlyString const& event_name, CSSPixels offset_x, CSSPixels offset_y, CSSPixels client_x, CSSPixels client_y, unsigned buttons, unsigned mouse_button) { MouseEventInit event_init {}; - event_init.offset_x = offset_x; - event_init.offset_y = offset_y; - event_init.client_x = client_x; - event_init.client_y = client_y; + event_init.offset_x = static_cast(offset_x.value()); + event_init.offset_y = static_cast(offset_y.value()); + event_init.client_x = static_cast(client_x.value()); + event_init.client_y = static_cast(client_y.value()); event_init.button = determine_button(mouse_button); event_init.buttons = buttons; return MouseEvent::create(realm, event_name, event_init); diff --git a/Userland/Libraries/LibWeb/UIEvents/MouseEvent.h b/Userland/Libraries/LibWeb/UIEvents/MouseEvent.h index a1c3675c3a..3511fc6766 100644 --- a/Userland/Libraries/LibWeb/UIEvents/MouseEvent.h +++ b/Userland/Libraries/LibWeb/UIEvents/MouseEvent.h @@ -7,6 +7,7 @@ #pragma once #include +#include #include #include @@ -27,7 +28,7 @@ class MouseEvent : public UIEvent { public: static MouseEvent* create(JS::Realm&, FlyString const& event_name, MouseEventInit const& event_init = {}); - static MouseEvent* create_from_platform_event(JS::Realm&, FlyString const& event_name, double offset_x, double offset_y, double client_x, double client_y, unsigned buttons, unsigned mouse_button = 1); + static MouseEvent* create_from_platform_event(JS::Realm&, FlyString const& event_name, CSSPixels offset_x, CSSPixels offset_y, CSSPixels client_x, CSSPixels client_y, unsigned buttons, unsigned mouse_button = 1); virtual ~MouseEvent() override; diff --git a/Userland/Libraries/LibWeb/UIEvents/WheelEvent.cpp b/Userland/Libraries/LibWeb/UIEvents/WheelEvent.cpp index 06c84d467d..c6584f1966 100644 --- a/Userland/Libraries/LibWeb/UIEvents/WheelEvent.cpp +++ b/Userland/Libraries/LibWeb/UIEvents/WheelEvent.cpp @@ -28,13 +28,13 @@ WheelEvent* WheelEvent::create(JS::Realm& realm, FlyString const& event_name, Wh return realm.heap().allocate(realm, realm, event_name, event_init); } -WheelEvent* WheelEvent::create_from_platform_event(JS::Realm& realm, FlyString const& event_name, double offset_x, double offset_y, double client_x, double client_y, double delta_x, double delta_y, unsigned buttons, unsigned button) +WheelEvent* WheelEvent::create_from_platform_event(JS::Realm& realm, FlyString const& event_name, CSSPixels offset_x, CSSPixels offset_y, CSSPixels client_x, CSSPixels client_y, double delta_x, double delta_y, unsigned buttons, unsigned button) { WheelEventInit event_init {}; - event_init.offset_x = offset_x; - event_init.offset_y = offset_y; - event_init.client_x = client_x; - event_init.client_y = client_y; + event_init.offset_x = static_cast(offset_x.value()); + event_init.offset_y = static_cast(offset_y.value()); + event_init.client_x = static_cast(client_x.value()); + event_init.client_y = static_cast(client_y.value()); event_init.button = button; event_init.buttons = buttons; event_init.delta_x = delta_x; diff --git a/Userland/Libraries/LibWeb/UIEvents/WheelEvent.h b/Userland/Libraries/LibWeb/UIEvents/WheelEvent.h index 7f7408fc7e..47ab277af5 100644 --- a/Userland/Libraries/LibWeb/UIEvents/WheelEvent.h +++ b/Userland/Libraries/LibWeb/UIEvents/WheelEvent.h @@ -30,7 +30,7 @@ class WheelEvent final : public MouseEvent { public: static WheelEvent* create(JS::Realm&, FlyString const& event_name, WheelEventInit const& event_init = {}); - static WheelEvent* create_from_platform_event(JS::Realm&, FlyString const& event_name, double offset_x, double offset_y, double client_x, double client_y, double delta_x, double delta_y, unsigned buttons, unsigned button); + static WheelEvent* create_from_platform_event(JS::Realm&, FlyString const& event_name, CSSPixels offset_x, CSSPixels offset_y, CSSPixels client_x, CSSPixels client_y, double delta_x, double delta_y, unsigned buttons, unsigned button); virtual ~WheelEvent() override; diff --git a/Userland/Services/WebContent/ConnectionFromClient.cpp b/Userland/Services/WebContent/ConnectionFromClient.cpp index bc56decb02..0e1f7bf59d 100644 --- a/Userland/Services/WebContent/ConnectionFromClient.cpp +++ b/Userland/Services/WebContent/ConnectionFromClient.cpp @@ -157,27 +157,27 @@ void ConnectionFromClient::flush_pending_paint_requests() void ConnectionFromClient::mouse_down(Gfx::IntPoint position, unsigned int button, unsigned int buttons, unsigned int modifiers) { - report_finished_handling_input_event(page().handle_mousedown(position, button, buttons, modifiers)); + report_finished_handling_input_event(page().handle_mousedown(position.to_type(), button, buttons, modifiers)); } void ConnectionFromClient::mouse_move(Gfx::IntPoint position, [[maybe_unused]] unsigned int button, unsigned int buttons, unsigned int modifiers) { - report_finished_handling_input_event(page().handle_mousemove(position, buttons, modifiers)); + report_finished_handling_input_event(page().handle_mousemove(position.to_type(), buttons, modifiers)); } void ConnectionFromClient::mouse_up(Gfx::IntPoint position, unsigned int button, unsigned int buttons, unsigned int modifiers) { - report_finished_handling_input_event(page().handle_mouseup(position, button, buttons, modifiers)); + report_finished_handling_input_event(page().handle_mouseup(position.to_type(), button, buttons, modifiers)); } void ConnectionFromClient::mouse_wheel(Gfx::IntPoint position, unsigned int button, unsigned int buttons, unsigned int modifiers, i32 wheel_delta_x, i32 wheel_delta_y) { - report_finished_handling_input_event(page().handle_mousewheel(position, button, buttons, modifiers, wheel_delta_x, wheel_delta_y)); + report_finished_handling_input_event(page().handle_mousewheel(position.to_type(), button, buttons, modifiers, wheel_delta_x, wheel_delta_y)); } void ConnectionFromClient::doubleclick(Gfx::IntPoint position, unsigned int button, unsigned int buttons, unsigned int modifiers) { - report_finished_handling_input_event(page().handle_doubleclick(position, button, buttons, modifiers)); + report_finished_handling_input_event(page().handle_doubleclick(position.to_type(), button, buttons, modifiers)); } void ConnectionFromClient::key_down(i32 key, unsigned int modifiers, u32 code_point) diff --git a/Userland/Services/WebContent/PageHost.cpp b/Userland/Services/WebContent/PageHost.cpp index 7275b7d111..71e4ffc5a3 100644 --- a/Userland/Services/WebContent/PageHost.cpp +++ b/Userland/Services/WebContent/PageHost.cpp @@ -26,7 +26,7 @@ PageHost::PageHost(ConnectionFromClient& client) { setup_palette(); m_invalidation_coalescing_timer = Web::Platform::Timer::create_single_shot(0, [this] { - m_client.async_did_invalidate_content_rect(m_invalidation_rect); + m_client.async_did_invalidate_content_rect({ m_invalidation_rect.x().value(), m_invalidation_rect.y().value(), m_invalidation_rect.width().value(), m_invalidation_rect.height().value() }); m_invalidation_rect = {}; }); } @@ -130,9 +130,9 @@ void PageHost::set_viewport_rect(Gfx::IntRect const& rect) page().top_level_browsing_context().set_viewport_rect(rect); } -void PageHost::page_did_invalidate(Gfx::IntRect const& content_rect) +void PageHost::page_did_invalidate(Web::CSSPixelRect const& content_rect) { - m_invalidation_rect = m_invalidation_rect.united(content_rect); + m_invalidation_rect = m_invalidation_rect.united(page().enclosing_device_rect(content_rect)); if (!m_invalidation_coalescing_timer->is_active()) m_invalidation_coalescing_timer->start(); } @@ -213,19 +213,23 @@ void PageHost::page_did_request_scroll(i32 x_delta, i32 y_delta) m_client.async_did_request_scroll(x_delta, y_delta); } -void PageHost::page_did_request_scroll_to(Gfx::IntPoint scroll_position) +void PageHost::page_did_request_scroll_to(Web::CSSPixelPoint scroll_position) { - m_client.async_did_request_scroll_to(scroll_position); + m_client.async_did_request_scroll_to({ scroll_position.x().value(), scroll_position.y().value() }); } -void PageHost::page_did_request_scroll_into_view(Gfx::IntRect const& rect) +void PageHost::page_did_request_scroll_into_view(Web::CSSPixelRect const& rect) { - m_client.async_did_request_scroll_into_view(rect); + auto device_pixel_rect = page().enclosing_device_rect(rect); + m_client.async_did_request_scroll_into_view({ device_pixel_rect.x().value(), + device_pixel_rect.y().value(), + device_pixel_rect.width().value(), + device_pixel_rect.height().value() }); } -void PageHost::page_did_enter_tooltip_area(Gfx::IntPoint content_position, DeprecatedString const& title) +void PageHost::page_did_enter_tooltip_area(Web::CSSPixelPoint content_position, DeprecatedString const& title) { - m_client.async_did_enter_tooltip_area(content_position, title); + m_client.async_did_enter_tooltip_area({ content_position.x().value(), content_position.y().value() }, title); } void PageHost::page_did_leave_tooltip_area() @@ -268,14 +272,14 @@ void PageHost::page_did_finish_loading(const URL& url) m_client.async_did_finish_loading(url); } -void PageHost::page_did_request_context_menu(Gfx::IntPoint content_position) +void PageHost::page_did_request_context_menu(Web::CSSPixelPoint content_position) { - m_client.async_did_request_context_menu(content_position); + m_client.async_did_request_context_menu(page().css_to_device_point(content_position).to_type()); } -void PageHost::page_did_request_link_context_menu(Gfx::IntPoint content_position, const URL& url, DeprecatedString const& target, unsigned modifiers) +void PageHost::page_did_request_link_context_menu(Web::CSSPixelPoint content_position, URL const& url, DeprecatedString const& target, unsigned modifiers) { - m_client.async_did_request_link_context_menu(content_position, url, target, modifiers); + m_client.async_did_request_link_context_menu(page().css_to_device_point(content_position).to_type(), url, target, modifiers); } void PageHost::page_did_request_alert(DeprecatedString const& message) @@ -328,10 +332,10 @@ void PageHost::page_did_change_favicon(Gfx::Bitmap const& favicon) m_client.async_did_change_favicon(favicon.to_shareable_bitmap()); } -void PageHost::page_did_request_image_context_menu(Gfx::IntPoint content_position, const URL& url, DeprecatedString const& target, unsigned modifiers, Gfx::Bitmap const* bitmap_pointer) +void PageHost::page_did_request_image_context_menu(Web::CSSPixelPoint content_position, URL const& url, DeprecatedString const& target, unsigned modifiers, Gfx::Bitmap const* bitmap_pointer) { auto bitmap = bitmap_pointer ? bitmap_pointer->to_shareable_bitmap() : Gfx::ShareableBitmap(); - m_client.async_did_request_image_context_menu(content_position, url, target, modifiers, bitmap); + m_client.async_did_request_image_context_menu({ content_position.x().value(), content_position.y().value() }, url, target, modifiers, bitmap); } Vector PageHost::page_did_request_all_cookies(URL const& url) diff --git a/Userland/Services/WebContent/PageHost.h b/Userland/Services/WebContent/PageHost.h index 94c8749b4a..fb0054226d 100644 --- a/Userland/Services/WebContent/PageHost.h +++ b/Userland/Services/WebContent/PageHost.h @@ -55,7 +55,7 @@ private: virtual Web::DevicePixelRect screen_rect() const override { return m_screen_rect; } virtual float device_pixels_per_css_pixel() const override { return m_screen_display_scale; } virtual Web::CSS::PreferredColorScheme preferred_color_scheme() const override { return m_preferred_color_scheme; } - virtual void page_did_invalidate(Gfx::IntRect const&) override; + virtual void page_did_invalidate(Web::CSSPixelRect const&) override; virtual void page_did_change_selection() override; virtual void page_did_request_cursor_change(Gfx::StandardCursor) override; virtual void page_did_layout() override; @@ -70,16 +70,16 @@ private: virtual Gfx::IntRect page_did_request_minimize_window() override; virtual Gfx::IntRect page_did_request_fullscreen_window() override; virtual void page_did_request_scroll(i32, i32) override; - virtual void page_did_request_scroll_to(Gfx::IntPoint) override; - virtual void page_did_request_scroll_into_view(Gfx::IntRect const&) override; - virtual void page_did_enter_tooltip_area(Gfx::IntPoint, DeprecatedString const&) override; + virtual void page_did_request_scroll_to(Web::CSSPixelPoint) override; + virtual void page_did_request_scroll_into_view(Web::CSSPixelRect const&) override; + virtual void page_did_enter_tooltip_area(Web::CSSPixelPoint, DeprecatedString const&) override; virtual void page_did_leave_tooltip_area() override; virtual void page_did_hover_link(const URL&) override; virtual void page_did_unhover_link() override; virtual void page_did_click_link(const URL&, DeprecatedString const& target, unsigned modifiers) override; virtual void page_did_middle_click_link(const URL&, DeprecatedString const& target, unsigned modifiers) override; - virtual void page_did_request_context_menu(Gfx::IntPoint) override; - virtual void page_did_request_link_context_menu(Gfx::IntPoint, const URL&, DeprecatedString const& target, unsigned modifiers) override; + virtual void page_did_request_context_menu(Web::CSSPixelPoint) override; + virtual void page_did_request_link_context_menu(Web::CSSPixelPoint, URL const&, DeprecatedString const& target, unsigned modifiers) override; virtual void page_did_start_loading(const URL&, bool) override; virtual void page_did_create_main_document() override; virtual void page_did_finish_loading(const URL&) override; @@ -90,7 +90,7 @@ private: virtual void page_did_request_accept_dialog() override; virtual void page_did_request_dismiss_dialog() override; virtual void page_did_change_favicon(Gfx::Bitmap const&) override; - virtual void page_did_request_image_context_menu(Gfx::IntPoint, const URL&, DeprecatedString const& target, unsigned modifiers, Gfx::Bitmap const*) override; + virtual void page_did_request_image_context_menu(Web::CSSPixelPoint, const URL&, DeprecatedString const& target, unsigned modifiers, Gfx::Bitmap const*) override; virtual Vector page_did_request_all_cookies(URL const&) override; virtual Optional page_did_request_named_cookie(URL const&, DeprecatedString const&) override; virtual DeprecatedString page_did_request_cookie(const URL&, Web::Cookie::Source) override; @@ -115,7 +115,7 @@ private: bool m_has_focus { false }; RefPtr m_invalidation_coalescing_timer; - Gfx::IntRect m_invalidation_rect; + Web::DevicePixelRect m_invalidation_rect; Web::CSS::PreferredColorScheme m_preferred_color_scheme { Web::CSS::PreferredColorScheme::Auto }; RefPtr m_webdriver; diff --git a/Userland/Utilities/headless-browser.cpp b/Userland/Utilities/headless-browser.cpp index 598af2bd89..de7e0569be 100644 --- a/Userland/Utilities/headless-browser.cpp +++ b/Userland/Utilities/headless-browser.cpp @@ -76,21 +76,20 @@ public: virtual void paint(Web::DevicePixelRect const& content_rect, Gfx::Bitmap& target) override { Gfx::Painter painter(target); - Gfx::IntRect int_content_rect { content_rect.x().value(), content_rect.y().value(), content_rect.width().value(), content_rect.height().value() }; if (auto* document = page().top_level_browsing_context().active_document()) document->update_layout(); - painter.fill_rect({ {}, int_content_rect.size() }, palette().base()); + painter.fill_rect({ {}, content_rect.size().to_type() }, palette().base()); auto* layout_root = this->layout_root(); if (!layout_root) { return; } - Web::PaintContext context(painter, palette(), int_content_rect.top_left()); + Web::PaintContext context(painter, palette(), content_rect.top_left().to_type()); context.set_should_show_line_box_borders(false); - context.set_viewport_rect(int_content_rect); + context.set_viewport_rect(content_rect.to_type()); context.set_has_focus(true); layout_root->paint_all_phases(context); } @@ -177,15 +176,15 @@ public: { } - virtual void page_did_request_context_menu(Gfx::IntPoint) override + virtual void page_did_request_context_menu(Web::CSSPixelPoint) override { } - virtual void page_did_request_link_context_menu(Gfx::IntPoint, AK::URL const&, DeprecatedString const&, unsigned) override + virtual void page_did_request_link_context_menu(Web::CSSPixelPoint, AK::URL const&, DeprecatedString const&, unsigned) override { } - virtual void page_did_request_image_context_menu(Gfx::IntPoint, AK::URL const&, DeprecatedString const&, unsigned, Gfx::Bitmap const*) override + virtual void page_did_request_image_context_menu(Web::CSSPixelPoint, AK::URL const&, DeprecatedString const&, unsigned, Gfx::Bitmap const*) override { } @@ -197,7 +196,7 @@ public: { } - virtual void page_did_enter_tooltip_area(Gfx::IntPoint, DeprecatedString const&) override + virtual void page_did_enter_tooltip_area(Web::CSSPixelPoint, DeprecatedString const&) override { } @@ -213,7 +212,7 @@ public: { } - virtual void page_did_invalidate(Gfx::IntRect const&) override + virtual void page_did_invalidate(Web::CSSPixelRect const&) override { } @@ -225,7 +224,7 @@ public: { } - virtual void page_did_request_scroll_into_view(Gfx::IntRect const&) override + virtual void page_did_request_scroll_into_view(Web::CSSPixelRect const&) override { }