1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 06:57:45 +00:00

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:
This commit is contained in:
Sam Atkins 2022-11-02 17:35:53 +00:00 committed by Linus Groh
parent 045aa8530c
commit 3c7bd5a317
27 changed files with 169 additions and 159 deletions

View file

@ -102,12 +102,12 @@ static Gfx::StandardCursor cursor_css_to_gfx(Optional<CSS::Cursor> 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<int>(top_left_of_layout_node.x()),
position.y() - static_cast<int>(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<Painting::PaintableBox*>(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<float>(), 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<float>(), 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<float>(), 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<float>(), 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<float>(), 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<float>(), 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<float>(), 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<float>(), 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<float>(), 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;

View file

@ -14,6 +14,7 @@
#include <LibGfx/Forward.h>
#include <LibWeb/Forward.h>
#include <LibWeb/Page/EditEventHandler.h>
#include <LibWeb/PixelUnits.h>
namespace Web {
@ -22,11 +23,11 @@ public:
explicit EventHandler(Badge<HTML::BrowsingContext>, 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);

View file

@ -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)

View file

@ -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&) { }