LibWeb: Use paintable to represent event tracking node
The use of layout nodes likely predated the paintable tree, but now there is no point in introducing another level of indirection.
This commit is contained in:
parent
ad59fb7cf0
commit
31e5b5f5de
Notes:
sideshowbarker
2024-07-17 21:16:31 +09:00
Author: https://github.com/kalenikaliaksandr Commit: https://github.com/SerenityOS/serenity/commit/31e5b5f5de Pull-request: https://github.com/SerenityOS/serenity/pull/22749 Reviewed-by: https://github.com/awesomekling
6 changed files with 24 additions and 14 deletions
|
@ -297,6 +297,8 @@ void BrowsingContext::visit_edges(Cell::Visitor& visitor)
|
|||
visitor.visit(m_last_child);
|
||||
visitor.visit(m_next_sibling);
|
||||
visitor.visit(m_previous_sibling);
|
||||
|
||||
m_event_handler.visit_edges(visitor);
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/document-sequences.html#bc-traversable
|
||||
|
|
|
@ -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
|
||||
|
@ -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())
|
||||
|
@ -893,4 +893,9 @@ Optional<EventHandler::Target> EventHandler::target_for_mouse_position(CSSPixelP
|
|||
return {};
|
||||
}
|
||||
|
||||
void EventHandler::visit_edges(JS::Cell::Visitor& visitor) const
|
||||
{
|
||||
visitor.visit(m_mouse_event_tracking_paintable);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#include <Kernel/API/KeyCode.h>
|
||||
#include <LibGUI/Forward.h>
|
||||
#include <LibGfx/Forward.h>
|
||||
#include <LibJS/Heap/Cell.h>
|
||||
#include <LibJS/Heap/GCPtr.h>
|
||||
#include <LibWeb/Forward.h>
|
||||
#include <LibWeb/Page/EditEventHandler.h>
|
||||
|
@ -33,10 +34,12 @@ public:
|
|||
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); }
|
||||
|
||||
void visit_edges(JS::Cell::Visitor& visitor) const;
|
||||
|
||||
private:
|
||||
bool focus_next_element();
|
||||
bool focus_previous_element();
|
||||
|
@ -59,7 +62,7 @@ private:
|
|||
|
||||
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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue