1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 06:27: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

@ -35,7 +35,7 @@ Layout::FormAssociatedLabelableNode& LabelablePaintable::layout_box()
return static_cast<Layout::FormAssociatedLabelableNode&>(PaintableBox::layout_box());
}
LabelablePaintable::DispatchEventOfSameName LabelablePaintable::handle_mousedown(Badge<EventHandler>, Gfx::IntPoint, unsigned button, unsigned)
LabelablePaintable::DispatchEventOfSameName LabelablePaintable::handle_mousedown(Badge<EventHandler>, 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<EventHandler>, Gfx::IntPoint position, unsigned button, unsigned)
LabelablePaintable::DispatchEventOfSameName LabelablePaintable::handle_mouseup(Badge<EventHandler>, 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<CSSPixels>().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<EventHandler>, Gfx::IntPoint position, unsigned, unsigned)
LabelablePaintable::DispatchEventOfSameName LabelablePaintable::handle_mousemove(Badge<EventHandler>, 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<CSSPixels>().contains(position);
if (!is_inside_node_or_label)
is_inside_node_or_label = Layout::Label::is_inside_associated_label(layout_box(), position);

View file

@ -21,9 +21,9 @@ public:
Layout::FormAssociatedLabelableNode& layout_box();
virtual bool wants_mouse_events() const override { return true; }
virtual DispatchEventOfSameName handle_mousedown(Badge<EventHandler>, Gfx::IntPoint, unsigned button, unsigned modifiers) override;
virtual DispatchEventOfSameName handle_mouseup(Badge<EventHandler>, Gfx::IntPoint, unsigned button, unsigned modifiers) override;
virtual DispatchEventOfSameName handle_mousemove(Badge<EventHandler>, Gfx::IntPoint, unsigned buttons, unsigned modifiers) override;
virtual DispatchEventOfSameName handle_mousedown(Badge<EventHandler>, CSSPixelPoint, unsigned button, unsigned modifiers) override;
virtual DispatchEventOfSameName handle_mouseup(Badge<EventHandler>, CSSPixelPoint, unsigned button, unsigned modifiers) override;
virtual DispatchEventOfSameName handle_mousemove(Badge<EventHandler>, CSSPixelPoint, unsigned buttons, unsigned modifiers) override;
void handle_associated_label_mousedown(Badge<Layout::Label>);
void handle_associated_label_mouseup(Badge<Layout::Label>);

View file

@ -10,22 +10,22 @@
namespace Web::Painting {
Paintable::DispatchEventOfSameName Paintable::handle_mousedown(Badge<EventHandler>, Gfx::IntPoint, unsigned, unsigned)
Paintable::DispatchEventOfSameName Paintable::handle_mousedown(Badge<EventHandler>, CSSPixelPoint, unsigned, unsigned)
{
return DispatchEventOfSameName::Yes;
}
Paintable::DispatchEventOfSameName Paintable::handle_mouseup(Badge<EventHandler>, Gfx::IntPoint, unsigned, unsigned)
Paintable::DispatchEventOfSameName Paintable::handle_mouseup(Badge<EventHandler>, CSSPixelPoint, unsigned, unsigned)
{
return DispatchEventOfSameName::Yes;
}
Paintable::DispatchEventOfSameName Paintable::handle_mousemove(Badge<EventHandler>, Gfx::IntPoint, unsigned, unsigned)
Paintable::DispatchEventOfSameName Paintable::handle_mousemove(Badge<EventHandler>, CSSPixelPoint, unsigned, unsigned)
{
return DispatchEventOfSameName::Yes;
}
bool Paintable::handle_mousewheel(Badge<EventHandler>, Gfx::IntPoint, unsigned, unsigned, int wheel_delta_x, int wheel_delta_y)
bool Paintable::handle_mousewheel(Badge<EventHandler>, 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<EventHandler>, Gfx::IntPoint, unsigned,
return false;
}
Optional<HitTestResult> Paintable::hit_test(Gfx::FloatPoint, HitTestType) const
Optional<HitTestResult> Paintable::hit_test(CSSPixelPoint, HitTestType) const
{
return {};
}

View file

@ -89,7 +89,7 @@ public:
virtual void before_children_paint(PaintContext&, PaintPhase) const { }
virtual void after_children_paint(PaintContext&, PaintPhase) const { }
virtual Optional<HitTestResult> hit_test(Gfx::FloatPoint, HitTestType) const;
virtual Optional<HitTestResult> 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<EventHandler>, Gfx::IntPoint, unsigned button, unsigned modifiers);
virtual DispatchEventOfSameName handle_mouseup(Badge<EventHandler>, Gfx::IntPoint, unsigned button, unsigned modifiers);
virtual DispatchEventOfSameName handle_mousemove(Badge<EventHandler>, Gfx::IntPoint, unsigned buttons, unsigned modifiers);
virtual DispatchEventOfSameName handle_mousedown(Badge<EventHandler>, CSSPixelPoint, unsigned button, unsigned modifiers);
virtual DispatchEventOfSameName handle_mouseup(Badge<EventHandler>, CSSPixelPoint, unsigned button, unsigned modifiers);
virtual DispatchEventOfSameName handle_mousemove(Badge<EventHandler>, CSSPixelPoint, unsigned buttons, unsigned modifiers);
virtual DOM::Node* mouse_event_target() const { return nullptr; }
virtual bool handle_mousewheel(Badge<EventHandler>, Gfx::IntPoint, unsigned buttons, unsigned modifiers, int wheel_delta_x, int wheel_delta_y);
virtual bool handle_mousewheel(Badge<EventHandler>, 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<Layout::Node&>(m_layout_node); }

View file

@ -630,7 +630,7 @@ void PaintableWithLines::paint(PaintContext& context, PaintPhase phase) const
}
}
bool PaintableWithLines::handle_mousewheel(Badge<EventHandler>, Gfx::IntPoint, unsigned, unsigned, int wheel_delta_x, int wheel_delta_y)
bool PaintableWithLines::handle_mousewheel(Badge<EventHandler>, 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<StackingContext> stacking_
m_stacking_context = move(stacking_context);
}
Optional<HitTestResult> PaintableBox::hit_test(Gfx::FloatPoint position, HitTestType type) const
Optional<HitTestResult> PaintableBox::hit_test(CSSPixelPoint position, HitTestType type) const
{
if (!is_visible())
return {};
@ -665,7 +665,7 @@ Optional<HitTestResult> 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<HitTestResult> PaintableBox::hit_test(Gfx::FloatPoint position, HitTest
return HitTestResult { *this };
}
Optional<HitTestResult> PaintableWithLines::hit_test(Gfx::FloatPoint position, HitTestType type) const
Optional<HitTestResult> 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<HitTestResult> 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<CSSPixels>();
if (fragment_absolute_rect.contains(position)) {
if (is<Layout::BlockContainer>(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<HitTestResult> 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 {};
}

View file

@ -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<HitTestResult> hit_test(Gfx::FloatPoint, HitTestType) const override;
virtual Optional<HitTestResult> 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<EventHandler>, Gfx::IntPoint, unsigned buttons, unsigned modifiers, int wheel_delta_x, int wheel_delta_y) override;
virtual bool handle_mousewheel(Badge<EventHandler>, CSSPixelPoint, unsigned buttons, unsigned modifiers, int wheel_delta_x, int wheel_delta_y) override;
virtual Optional<HitTestResult> hit_test(Gfx::FloatPoint, HitTestType) const override;
virtual Optional<HitTestResult> hit_test(CSSPixelPoint, HitTestType) const override;
protected:
PaintableWithLines(Layout::BlockContainer const&);

View file

@ -439,17 +439,22 @@ static TraversalDecision for_each_in_subtree_of_type_within_same_stacking_contex
return TraversalDecision::Continue;
}
Optional<HitTestResult> StackingContext::hit_test(Gfx::FloatPoint position, HitTestType type) const
Optional<HitTestResult> 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<CSSPixels>();
// 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<CSSPixels>() + 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<HitTestResult> StackingContext::hit_test(Gfx::FloatPoint position, HitT
for_each_in_subtree_of_type_within_same_stacking_context_in_reverse<PaintableBox>(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<HitTestResult> StackingContext::hit_test(Gfx::FloatPoint position, HitT
for_each_in_subtree_of_type_within_same_stacking_context_in_reverse<PaintableBox>(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<HitTestResult> StackingContext::hit_test(Gfx::FloatPoint position, HitT
for_each_in_subtree_of_type_within_same_stacking_context_in_reverse<PaintableBox>(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<HitTestResult> 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(),
};

View file

@ -32,7 +32,7 @@ public:
void paint_descendants(PaintContext&, Layout::Node const&, StackingContextPaintPhase) const;
void paint(PaintContext&) const;
Optional<HitTestResult> hit_test(Gfx::FloatPoint, HitTestType) const;
Optional<HitTestResult> hit_test(CSSPixelPoint, HitTestType) const;
Gfx::FloatMatrix4x4 const& transform_matrix() const { return m_transform; }
Gfx::AffineTransform affine_transform_matrix() const;

View file

@ -36,7 +36,7 @@ DOM::Node* TextPaintable::mouse_event_target() const
return nullptr;
}
TextPaintable::DispatchEventOfSameName TextPaintable::handle_mousedown(Badge<EventHandler>, Gfx::IntPoint position, unsigned button, unsigned)
TextPaintable::DispatchEventOfSameName TextPaintable::handle_mousedown(Badge<EventHandler>, CSSPixelPoint position, unsigned button, unsigned)
{
auto* label = layout_node().first_ancestor_of_type<Layout::Label>();
if (!label)
@ -46,7 +46,7 @@ TextPaintable::DispatchEventOfSameName TextPaintable::handle_mousedown(Badge<Eve
return DispatchEventOfSameName::Yes;
}
TextPaintable::DispatchEventOfSameName TextPaintable::handle_mouseup(Badge<EventHandler>, Gfx::IntPoint position, unsigned button, unsigned)
TextPaintable::DispatchEventOfSameName TextPaintable::handle_mouseup(Badge<EventHandler>, CSSPixelPoint position, unsigned button, unsigned)
{
auto* label = layout_node().first_ancestor_of_type<Layout::Label>();
if (!label)
@ -57,7 +57,7 @@ TextPaintable::DispatchEventOfSameName TextPaintable::handle_mouseup(Badge<Event
return DispatchEventOfSameName::Yes;
}
TextPaintable::DispatchEventOfSameName TextPaintable::handle_mousemove(Badge<EventHandler>, Gfx::IntPoint position, unsigned button, unsigned)
TextPaintable::DispatchEventOfSameName TextPaintable::handle_mousemove(Badge<EventHandler>, CSSPixelPoint position, unsigned button, unsigned)
{
auto* label = layout_node().first_ancestor_of_type<Layout::Label>();
if (!label)

View file

@ -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<EventHandler>, Gfx::IntPoint, unsigned button, unsigned modifiers) override;
virtual DispatchEventOfSameName handle_mouseup(Badge<EventHandler>, Gfx::IntPoint, unsigned button, unsigned modifiers) override;
virtual DispatchEventOfSameName handle_mousemove(Badge<EventHandler>, Gfx::IntPoint, unsigned button, unsigned modifiers) override;
virtual DispatchEventOfSameName handle_mousedown(Badge<EventHandler>, CSSPixelPoint, unsigned button, unsigned modifiers) override;
virtual DispatchEventOfSameName handle_mouseup(Badge<EventHandler>, CSSPixelPoint, unsigned button, unsigned modifiers) override;
virtual DispatchEventOfSameName handle_mousemove(Badge<EventHandler>, CSSPixelPoint, unsigned button, unsigned modifiers) override;
private:
explicit TextPaintable(Layout::TextNode const&);