LibWeb: Add stub implementation for handling doubleclicks

This commit is contained in:
Karol Kosek 2022-06-14 19:38:00 +02:00 committed by Sam Atkins
parent 565f68f8bb
commit 0e04532623
Notes: sideshowbarker 2024-07-17 10:04:07 +09:00
2 changed files with 59 additions and 0 deletions
Userland/Libraries/LibWeb/Page

View file

@ -491,6 +491,64 @@ bool EventHandler::handle_mousemove(Gfx::IntPoint const& position, unsigned butt
return true;
}
bool EventHandler::handle_doubleclick(Gfx::IntPoint const& position, unsigned button, unsigned modifiers)
{
if (m_browsing_context.active_document())
m_browsing_context.active_document()->update_layout();
if (!paint_root())
return false;
// TODO: Allow selecting element behind if one on top has pointer-events set to none.
RefPtr<Painting::Paintable> paintable;
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);
if (!result.has_value())
return false;
paintable = result->paintable;
}
auto pointer_events = paintable->computed_values().pointer_events();
// FIXME: Handle other values for pointer-events.
if (pointer_events == CSS::PointerEvents::None)
return false;
RefPtr<DOM::Node> node = paintable->mouse_event_target();
if (!node)
node = paintable->dom_node();
if (paintable->wants_mouse_events()) {
// FIXME: Handle double clicks.
}
if (!node)
return false;
if (is<HTML::HTMLIFrameElement>(*node)) {
if (auto* nested_browsing_context = static_cast<HTML::HTMLIFrameElement&>(*node).nested_browsing_context())
return nested_browsing_context->event_handler().handle_doubleclick(position.translated(compute_mouse_event_offset({}, paintable->layout_node())), button, modifiers);
return false;
}
// Search for the first parent of the hit target that's an element.
// "The topmost event target MUST be the element highest in the rendering order which is capable of being an event target." (https://www.w3.org/TR/uievents/#topmost-event-target)
auto* layout_node = &paintable->layout_node();
while (layout_node && node && !node->is_element() && layout_node->parent()) {
layout_node = layout_node->parent();
node = layout_node->dom_node();
}
if (!node || !layout_node)
return false;
// FIXME: Dispatch 'dblclick' events.
// FIXME: Select word
return true;
}
bool EventHandler::focus_next_element()
{
if (!m_browsing_context.active_document())

View file

@ -26,6 +26,7 @@ public:
bool handle_mousedown(Gfx::IntPoint const&, unsigned button, unsigned modifiers);
bool handle_mousemove(Gfx::IntPoint const&, unsigned buttons, unsigned modifiers);
bool handle_mousewheel(Gfx::IntPoint const&, unsigned buttons, unsigned modifiers, int wheel_delta_x, int wheel_delta_y);
bool handle_doubleclick(Gfx::IntPoint const&, unsigned buttons, unsigned modifiers);
bool handle_keydown(KeyCode, unsigned modifiers, u32 code_point);
bool handle_keyup(KeyCode, unsigned modifiers, u32 code_point);