Skip to content

Commit

Permalink
LibWeb: Use paintable to represent event tracking node
Browse files Browse the repository at this point in the history
The use of layout nodes likely predated the paintable tree, but now
there is no point in introducing another level of indirection.
  • Loading branch information
kalenikaliaksandr committed Jan 14, 2024
1 parent 48a3a02 commit 4274bd8
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 14 deletions.
12 changes: 6 additions & 6 deletions Userland/Libraries/LibWeb/Page/EventHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -836,9 +836,9 @@ bool EventHandler::handle_keyup(KeyCode key, u32 modifiers, u32 code_point)
return fire_keyboard_event(UIEvents::EventNames::keyup, m_browsing_context, key, modifiers, code_point);
}

void EventHandler::set_mouse_event_tracking_layout_node(Layout::Node* layout_node)
void EventHandler::set_mouse_event_tracking_paintable(Painting::Paintable* paintable)
{
m_mouse_event_tracking_layout_node = layout_node;
m_mouse_event_tracking_paintable = paintable;
}

CSSPixelPoint EventHandler::compute_mouse_event_client_offset(CSSPixelPoint event_page_position) const
Expand Down Expand Up @@ -880,11 +880,11 @@ CSSPixelPoint EventHandler::compute_mouse_event_movement(CSSPixelPoint screen_po

Optional<EventHandler::Target> EventHandler::target_for_mouse_position(CSSPixelPoint position)
{
if (m_mouse_event_tracking_layout_node) {
if (m_mouse_event_tracking_layout_node->paintable()->wants_mouse_events())
return Target { m_mouse_event_tracking_layout_node->paintable(), {} };
if (m_mouse_event_tracking_paintable) {
if (m_mouse_event_tracking_paintable->wants_mouse_events())
return Target { m_mouse_event_tracking_paintable, {} };

m_mouse_event_tracking_layout_node = nullptr;
m_mouse_event_tracking_paintable = nullptr;
}

if (auto result = paint_root()->hit_test(position, Painting::HitTestType::Exact); result.has_value())
Expand Down
4 changes: 2 additions & 2 deletions Userland/Libraries/LibWeb/Page/EventHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class EventHandler {
bool handle_keydown(KeyCode, unsigned modifiers, u32 code_point);
bool handle_keyup(KeyCode, unsigned modifiers, u32 code_point);

void set_mouse_event_tracking_layout_node(Layout::Node*);
void set_mouse_event_tracking_paintable(Painting::Paintable*);

void set_edit_event_handler(NonnullOwnPtr<EditEventHandler> value) { m_edit_event_handler = move(value); }

Expand All @@ -59,7 +59,7 @@ class EventHandler {

bool m_in_mouse_selection { false };

WeakPtr<Layout::Node> m_mouse_event_tracking_layout_node;
JS::GCPtr<Painting::Paintable> m_mouse_event_tracking_paintable;

NonnullOwnPtr<EditEventHandler> m_edit_event_handler;

Expand Down
4 changes: 2 additions & 2 deletions Userland/Libraries/LibWeb/Painting/LabelablePaintable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ LabelablePaintable::DispatchEventOfSameName LabelablePaintable::handle_mousedown

set_being_pressed(true);
m_tracking_mouse = true;
browsing_context().event_handler().set_mouse_event_tracking_layout_node(&layout_box());
browsing_context().event_handler().set_mouse_event_tracking_paintable(this);
return DispatchEventOfSameName::Yes;
}

Expand All @@ -57,7 +57,7 @@ LabelablePaintable::DispatchEventOfSameName LabelablePaintable::handle_mouseup(B

set_being_pressed(false);
m_tracking_mouse = false;
browsing_context().event_handler().set_mouse_event_tracking_layout_node(nullptr);
browsing_context().event_handler().set_mouse_event_tracking_paintable(nullptr);
return DispatchEventOfSameName::Yes;
}

Expand Down
4 changes: 2 additions & 2 deletions Userland/Libraries/LibWeb/Painting/MediaPaintable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ MediaPaintable::DispatchEventOfSameName MediaPaintable::handle_mousedown(Badge<E
}

if (media_element.layout_mouse_tracking_component({}).has_value())
const_cast<HTML::BrowsingContext&>(browsing_context()).event_handler().set_mouse_event_tracking_layout_node(&layout_node());
const_cast<HTML::BrowsingContext&>(browsing_context()).event_handler().set_mouse_event_tracking_paintable(this);

return DispatchEventOfSameName::Yes;
}
Expand All @@ -306,7 +306,7 @@ MediaPaintable::DispatchEventOfSameName MediaPaintable::handle_mouseup(Badge<Eve
break;
}

const_cast<HTML::BrowsingContext&>(browsing_context()).event_handler().set_mouse_event_tracking_layout_node(nullptr);
const_cast<HTML::BrowsingContext&>(browsing_context()).event_handler().set_mouse_event_tracking_paintable(nullptr);
media_element.set_layout_mouse_tracking_component({}, {});

return DispatchEventOfSameName::Yes;
Expand Down
4 changes: 2 additions & 2 deletions Userland/Libraries/LibWeb/Painting/TextPaintable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ TextPaintable::DispatchEventOfSameName TextPaintable::handle_mousedown(Badge<Eve
if (!label)
return DispatchEventOfSameName::No;
const_cast<Layout::Label*>(label)->handle_mousedown_on_label({}, position, button);
const_cast<HTML::BrowsingContext&>(browsing_context()).event_handler().set_mouse_event_tracking_layout_node(&const_cast<Layout::TextNode&>(layout_node()));
const_cast<HTML::BrowsingContext&>(browsing_context()).event_handler().set_mouse_event_tracking_paintable(this);
return DispatchEventOfSameName::Yes;
}

Expand All @@ -53,7 +53,7 @@ TextPaintable::DispatchEventOfSameName TextPaintable::handle_mouseup(Badge<Event
return DispatchEventOfSameName::No;

const_cast<Layout::Label*>(label)->handle_mouseup_on_label({}, position, button);
const_cast<HTML::BrowsingContext&>(browsing_context()).event_handler().set_mouse_event_tracking_layout_node(nullptr);
const_cast<HTML::BrowsingContext&>(browsing_context()).event_handler().set_mouse_event_tracking_paintable(nullptr);
return DispatchEventOfSameName::Yes;
}

Expand Down

0 comments on commit 4274bd8

Please sign in to comment.