Truly independent web browser
LibWeb: Dispatch WebDriver touch and pen pointer actions
Andreas Kling7235790965a4
diff --git a/Libraries/LibWeb/DOM/Document.cpp b/Libraries/LibWeb/DOM/Document.cppindex 35b883a8424..ad1845cd4c0 100644--- a/Libraries/LibWeb/DOM/Document.cpp+++ b/Libraries/LibWeb/DOM/Document.cpp@@ -3332,16 +3332,24 @@ static void mark_mouse_transition_event_as_trusted_if_needed(Event& event, Optioevent.set_is_trusted(true);}-void Document::set_hovered_node(GC::Ptr<Node> node, Optional<HoverEventData> hover_event_data)+void Document::set_hovered_node(GC::Ptr<Node> node, Optional<HoverEventData> hover_event_data, BoundaryEventTypes types){- Layout::ForcedReadScope read { *this };// The style's hover follows the node the events hover. A hover beside the host may have moved it already, while// the hovered node of the events stayed.CSS::move_style_hover(*this, node);if (m_hovered_node == node)return;- GC::Ptr<Node> old_hovered_node = move(m_hovered_node);+ auto old_hovered_node = m_hovered_node;+ m_hovered_node = node;+ dispatch_boundary_events(old_hovered_node, node, hover_event_data, types);+}++void Document::dispatch_boundary_events(GC::Ptr<Node> old_hovered_node, GC::Ptr<Node> node, Optional<HoverEventData> hover_event_data, BoundaryEventTypes types)+{+ if (old_hovered_node == node)+ return;+ Layout::ForcedReadScope read { *this };// AD-HOC: The boundary event steps in the Pointer Events spec walk the target's inclusive ancestors, which stop at// the shadow root and ignore slot assignment. Chromium and Gecko walk the flat tree instead, so content// assigned to a slot is inside the elements around that slot.@@ -3378,8 +3386,6 @@ void Document::set_hovered_node(GC::Ptr<Node> node, Optional<HoverEventData> hovfor (auto* target = node.ptr(); target && target != common_ancestor; target = target->flat_tree_parent())entered_ancestors.append(make_hover_event_target(*target));- m_hovered_node = node;-auto current_event_time_stamp = [&] {return HighResolutionTime::current_high_resolution_time(relevant_global_object(*this));};@@ -3406,12 +3412,12 @@ void Document::set_hovered_node(GC::Ptr<Node> node, Optional<HoverEventData> hov};// https://w3c.github.io/pointerevents/#the-pointerout-event- if (old_hovered_node && old_hovered_node != m_hovered_node) {+ if (types != BoundaryEventTypes::Mouse && old_hovered_node && old_hovered_node != node) {UIEvents::PointerEventOptions pointer_event_options;pointer_event_options.bubbles = true;pointer_event_options.cancelable = true;pointer_event_options.composed = true;- pointer_event_options.related_target = m_hovered_node;+ pointer_event_options.related_target = node;pointer_event_options.is_primary = true;pointer_event_options.pointer_type = UIEvents::PointerTypes::Mouse;pointer_event_options.view = window_proxy;@@ -3424,12 +3430,12 @@ void Document::set_hovered_node(GC::Ptr<Node> node, Optional<HoverEventData> hov}// https://w3c.github.io/uievents/#mouseout- if (old_hovered_node && old_hovered_node != m_hovered_node) {+ if (types != BoundaryEventTypes::Pointer && old_hovered_node && old_hovered_node != node) {UIEvents::MouseEventOptions mouse_event_options;mouse_event_options.bubbles = true;mouse_event_options.cancelable = true;mouse_event_options.composed = true;- mouse_event_options.related_target = m_hovered_node;+ mouse_event_options.related_target = node;mouse_event_options.view = window_proxy;if (hover_event_data.has_value())populate_mouse_event_options_from_hover_event_data(mouse_event_options, *hover_event_data, window_proxy);@@ -3440,10 +3446,10 @@ void Document::set_hovered_node(GC::Ptr<Node> node, Optional<HoverEventData> hov}// https://w3c.github.io/pointerevents/#the-pointerleave-event- if (!left_ancestors.is_empty()) {+ if (types != BoundaryEventTypes::Mouse && !left_ancestors.is_empty()) {for (auto const& target : left_ancestors) {UIEvents::PointerEventOptions pointer_event_options;- pointer_event_options.related_target = m_hovered_node;+ pointer_event_options.related_target = node;pointer_event_options.is_primary = true;pointer_event_options.pointer_type = UIEvents::PointerTypes::Mouse;pointer_event_options.view = window_proxy;@@ -3457,10 +3463,10 @@ void Document::set_hovered_node(GC::Ptr<Node> node, Optional<HoverEventData> hov}// https://w3c.github.io/uievents/#mouseleave- if (!left_ancestors.is_empty()) {+ if (types != BoundaryEventTypes::Pointer && !left_ancestors.is_empty()) {for (auto const& target : left_ancestors) {UIEvents::MouseEventOptions mouse_event_options;- mouse_event_options.related_target = m_hovered_node;+ mouse_event_options.related_target = node;if (hover_event_data.has_value())populate_mouse_event_options_from_hover_event_data(mouse_event_options, *hover_event_data, window_proxy);auto offset = target.offset;@@ -3471,7 +3477,7 @@ void Document::set_hovered_node(GC::Ptr<Node> node, Optional<HoverEventData> hov}// https://w3c.github.io/pointerevents/#the-pointerover-event- if (m_hovered_node && m_hovered_node != old_hovered_node) {+ if (types != BoundaryEventTypes::Mouse && node && node != old_hovered_node) {UIEvents::PointerEventOptions pointer_event_options;pointer_event_options.bubbles = true;pointer_event_options.cancelable = true;@@ -3485,11 +3491,11 @@ void Document::set_hovered_node(GC::Ptr<Node> node, Optional<HoverEventData> hovauto offset = *hovered_node_offset;auto event = create_pointer_event(UIEvents::EventNames::pointerover, move(pointer_event_options), offset);mark_mouse_transition_event_as_trusted_if_needed(event, hover_event_data);- m_hovered_node->dispatch_event(event);+ node->dispatch_event(event);}// https://w3c.github.io/uievents/#mouseover- if (m_hovered_node && m_hovered_node != old_hovered_node) {+ if (types != BoundaryEventTypes::Pointer && node && node != old_hovered_node) {UIEvents::MouseEventOptions mouse_event_options;mouse_event_options.bubbles = true;mouse_event_options.cancelable = true;@@ -3501,7 +3507,7 @@ void Document::set_hovered_node(GC::Ptr<Node> node, Optional<HoverEventData> hovauto offset = *hovered_node_offset;auto event = create_mouse_event(UIEvents::EventNames::mouseover, mouse_event_options, offset);mark_mouse_transition_event_as_trusted_if_needed(event, hover_event_data);- m_hovered_node->dispatch_event(event);+ node->dispatch_event(event);}// https://w3c.github.io/pointerevents/#the-pointerenter-event@@ -3510,24 +3516,28 @@ void Document::set_hovered_node(GC::Ptr<Node> node, Optional<HoverEventData> hov// Leave events are dispatched in the opposite order.if (!entered_ancestors.is_empty()) {for (auto target : entered_ancestors.in_reverse()) {- UIEvents::PointerEventOptions pointer_event_options;- pointer_event_options.related_target = old_hovered_node;- pointer_event_options.is_primary = true;- pointer_event_options.pointer_type = UIEvents::PointerTypes::Mouse;- pointer_event_options.view = window_proxy;- if (hover_event_data.has_value())- populate_mouse_event_options_from_hover_event_data(pointer_event_options, *hover_event_data, window_proxy);auto offset = target.offset;- auto pointer_event = create_pointer_event(UIEvents::EventNames::pointerenter, move(pointer_event_options), offset);- mark_mouse_transition_event_as_trusted_if_needed(pointer_event, hover_event_data);- target.node->dispatch_event(pointer_event);- UIEvents::MouseEventOptions mouse_event_options;- mouse_event_options.related_target = old_hovered_node;- if (hover_event_data.has_value())- populate_mouse_event_options_from_hover_event_data(mouse_event_options, *hover_event_data, window_proxy);- auto mouse_event = create_mouse_event(UIEvents::EventNames::mouseenter, mouse_event_options, offset);- mark_mouse_transition_event_as_trusted_if_needed(mouse_event, hover_event_data);- target.node->dispatch_event(mouse_event);+ if (types != BoundaryEventTypes::Mouse) {+ UIEvents::PointerEventOptions pointer_event_options;+ pointer_event_options.related_target = old_hovered_node;+ pointer_event_options.is_primary = true;+ pointer_event_options.pointer_type = UIEvents::PointerTypes::Mouse;+ pointer_event_options.view = window_proxy;+ if (hover_event_data.has_value())+ populate_mouse_event_options_from_hover_event_data(pointer_event_options, *hover_event_data, window_proxy);+ auto pointer_event = create_pointer_event(UIEvents::EventNames::pointerenter, move(pointer_event_options), offset);+ mark_mouse_transition_event_as_trusted_if_needed(pointer_event, hover_event_data);+ target.node->dispatch_event(pointer_event);+ }+ if (types != BoundaryEventTypes::Pointer) {+ UIEvents::MouseEventOptions mouse_event_options;+ mouse_event_options.related_target = old_hovered_node;+ if (hover_event_data.has_value())+ populate_mouse_event_options_from_hover_event_data(mouse_event_options, *hover_event_data, window_proxy);+ auto mouse_event = create_mouse_event(UIEvents::EventNames::mouseenter, mouse_event_options, offset);+ mark_mouse_transition_event_as_trusted_if_needed(mouse_event, hover_event_data);+ target.node->dispatch_event(mouse_event);+ }}}}diff --git a/Libraries/LibWeb/DOM/Document.h b/Libraries/LibWeb/DOM/Document.hindex 8003640d531..faac74c4128 100644--- a/Libraries/LibWeb/DOM/Document.h+++ b/Libraries/LibWeb/DOM/Document.h@@ -431,7 +431,13 @@ public:virtual Utf16FlyString node_name() const override { return "#document"_utf16_fly_string; }- void set_hovered_node(GC::Ptr<Node>, Optional<HoverEventData> = {});+ enum class BoundaryEventTypes {+ Pointer,+ Mouse,+ All,+ };+ void set_hovered_node(GC::Ptr<Node>, Optional<HoverEventData> = {}, BoundaryEventTypes = BoundaryEventTypes::All);+ void dispatch_boundary_events(GC::Ptr<Node> old_target, GC::Ptr<Node> target, Optional<HoverEventData>, BoundaryEventTypes);Node* hovered_node() { return m_hovered_node.ptr(); }Node const* hovered_node() const { return m_hovered_node.ptr(); }diff --git a/Libraries/LibWeb/Internals/Internals.cpp b/Libraries/LibWeb/Internals/Internals.cppindex 46df738c6ae..e6f74c59123 100644--- a/Libraries/LibWeb/Internals/Internals.cpp+++ b/Libraries/LibWeb/Internals/Internals.cpp@@ -8,6 +8,7 @@#include <AK/Find.h>#include <AK/HashTable.h>#include <AK/JsonObject.h>+#include <AK/JsonParser.h>#include <AK/NumericLimits.h>#include <AK/Utf16String.h>#include <AK/Utf16StringBuilder.h>@@ -108,6 +109,8 @@#include <LibWeb/ResizeObserver/ResizeObserver.h>#include <LibWeb/Streams/ReadableStream.h>#include <LibWeb/StyleValueRustFFI.h>+#include <LibWeb/WebDriver/Actions.h>+#include <LibWeb/WebDriver/InputState.h>#include <LibWeb/WebIDL/ExceptionOr.h>#include <LibWeb/WebIDL/Promise.h>#include <LibWeb/WebSockets/WebSocket.h>@@ -117,6 +120,7 @@#include <LibWebCommon/Page/DragEvent.h>#include <LibWebCommon/Page/InputEvent.h>#include <LibWebCommon/StorageAPI/StorageEndpoint.h>+#include <LibWebCommon/WebDriver/Response.h>namespace Web::Internals {@@ -175,6 +179,11 @@ void Internals::visit_edges(GC::Cell::Visitor& visitor)void Internals::signal_test_is_done(Utf16String const& text){+ // NB: A listener may finish a test while the UI still owns input from its action sequence.+ if (m_actions_running) {+ m_pending_action_test_result = text;+ return;+ }perform_per_test_cleanup();page().client().page_did_finish_test(text);}@@ -736,6 +745,49 @@ static Web::MouseEvent::Type mouse_event_type_from(Bindings::MouseEventThroughUIVERIFY_NOT_REACHED();}+void Internals::perform_actions(Utf16String const& json, GC::Ref<WebIDL::Promise> promise)+{+ auto& realm = window().principal_realm();+ auto reject = [&](String const& message) {+ WebIDL::reject_promise(realm, promise, JS::PrimitiveString::create(vm(), Utf16String::from_utf8(message)));+ };+ if (m_actions_running) {+ reject("An action sequence is already running"_string);+ return;+ }+ auto value = JsonValue::from_string(json.to_utf8());+ if (value.is_error()) {+ reject("Invalid action JSON"_string);+ return;+ }+ auto& input_state = WebDriver::get_input_state(*window().navigable()->top_level_traversable());+ WebDriver::ActionsOptions options;+ options.is_element_origin = [](JsonValue const&) { return false; };+ auto actions = WebDriver::extract_an_action_sequence(input_state, value.release_value(), options);+ if (actions.is_error()) {+ reject(actions.error().message);+ return;+ }+ let_compositor_take_in_every_rendered_frame(window());+ m_actions_running = true;+ auto executor = WebDriver::dispatch_actions(input_state, actions.release_value(), *window().associated_document().browsing_context(), options,+ GC::create_function(heap(), [this, promise, realm = GC::Ref { realm }](WebDriver::Response response) {+ HTML::TemporaryExecutionContext context { *realm };+ m_actions_running = false;+ m_actions_executor = {};+ if (response.is_error())+ WebIDL::reject_promise(*realm, promise, JS::PrimitiveString::create(realm->vm(), Utf16String::from_utf8(response.error().message)));+ else+ WebIDL::resolve_promise(*realm, promise);+ if (m_pending_action_test_result.has_value()) {+ auto text = m_pending_action_test_result.release_value();+ signal_test_is_done(text);+ }+ }));+ if (m_actions_running)+ m_actions_executor = GC::make_root(executor);+}+void Internals::mouse_event_through_ui_process(Bindings::MouseEventThroughUIProcessType type, double x, double y, Bindings::MouseEventThroughUIProcessOptions const& options, GC::Ref<WebIDL::Promise> promise){auto event = mouse_event_through_ui_process_at(mouse_event_type_from(type), x, y);diff --git a/Libraries/LibWeb/Internals/Internals.h b/Libraries/LibWeb/Internals/Internals.hindex 73e3faf8d32..317e5249fca 100644--- a/Libraries/LibWeb/Internals/Internals.h+++ b/Libraries/LibWeb/Internals/Internals.h@@ -8,6 +8,7 @@#include <LibCompositing/Scrolling/AsyncScrollTree.h>#include <LibCompositing/Scrolling/AsyncScrollingState.h>+#include <LibGC/Root.h>#include <LibWeb/Bindings/Internals.h>#include <LibWeb/DOM/Document.h>#include <LibWeb/Export.h>@@ -99,6 +100,7 @@ public:void send_text_through_ui_process(Utf16String const&);void grant_transient_activation();void click_through_ui_process(double x, double y, GC::Ref<WebIDL::Promise>);+ void perform_actions(Utf16String const&, GC::Ref<WebIDL::Promise>);void mouse_event_through_ui_process(Bindings::MouseEventThroughUIProcessType, double x, double y, Bindings::MouseEventThroughUIProcessOptions const&, GC::Ref<WebIDL::Promise>);void wheel_through_ui_process(double x, double y, double delta_x, double delta_y, bool precise, Bindings::ScrollGesturePhase, Bindings::WheelTicks const&, GC::Ref<WebIDL::Promise>);void send_key(HTML::HTMLElement&, Utf16String const&, WebIDL::UnsignedShort modifiers, WebIDL::UnsignedLong repeat_count);@@ -335,6 +337,9 @@ private:UIEvents::MouseButton button_from_unsigned_short(WebIDL::UnsignedShort button);+ GC::Root<JS::Cell> m_actions_executor;+ bool m_actions_running { false };+ Optional<Utf16String> m_pending_action_test_result;Vector<GC::Ref<InternalGamepad>> m_gamepads;};diff --git a/Libraries/LibWeb/Internals/Internals.idl b/Libraries/LibWeb/Internals/Internals.idlindex db7d1185c17..6e7f6a2d3dd 100644--- a/Libraries/LibWeb/Internals/Internals.idl+++ b/Libraries/LibWeb/Internals/Internals.idl@@ -78,6 +78,8 @@ interface Internals {// and resolve once the UI process reports that the input has been handled.[CreatesPromise] Promise<undefined> clickThroughUIProcess(double x, double y);[CreatesPromise] Promise<undefined> mouseEventThroughUIProcess(MouseEventThroughUIProcessType type, double x, double y, optional MouseEventThroughUIProcessOptions options = {});+ // Performs a WebDriver action sequence, given as the JSON parameters of Perform Actions, through the UI process.+ [CreatesPromise] Promise<undefined> performActions(DOMString actions);[CreatesPromise] Promise<undefined> wheelThroughUIProcess(double x, double y, double deltaX, double deltaY, optional boolean precise = false, optional ScrollGesturePhase scrollGesturePhase = "none", optional WheelTicks ticks = {});undefined sendKey(HTMLElement target, DOMString keyName, optional unsigned short modifiers = 0, optional unsigned long repeatCount = 1);undefined sendTextEditingCommand(HTMLElement target, DOMString commandName, optional boolean extendSelection = false);diff --git a/Libraries/LibWeb/Page/EventHandler.cpp b/Libraries/LibWeb/Page/EventHandler.cppindex 033f40896d2..5216228a7bf 100644--- a/Libraries/LibWeb/Page/EventHandler.cpp+++ b/Libraries/LibWeb/Page/EventHandler.cpp@@ -20,6 +20,7 @@#include <LibUnicode/Segmenter.h>#include <LibWeb/CSS/ComputedValues.h>#include <LibWeb/CSS/StyleComputer.h>+#include <LibWeb/CSS/StyleEngineInput.h>#include <LibWeb/CSS/VisualViewport.h>#include <LibWeb/Clipboard/ClipboardEvent.h>#include <LibWeb/Compositor/NavigablePresenter.h>@@ -4342,6 +4343,7 @@ GC::Ref<UIEvents::PointerEvent> EventHandler::create_pointer_event(PointerState{UIEvents::PointerEventOptions options;options.view = m_navigable->active_window_proxy();+ options.detail = name == UIEvents::EventNames::click ? 1 : 0;options.screen_x = screen_position.x().to_double();options.screen_y = screen_position.y().to_double();options.client_x = coordinates.viewport_position.x().to_double();@@ -4413,7 +4415,7 @@ void EventHandler::update_pointer_hover(Layout::BegunRead const& read, PointerStentered.append(make_target(*node));auto dispatch = [&](BoundaryTarget const& boundary, Utf16FlyString const& name, GC::Ptr<DOM::Node> related_target, bool bubbles) {- auto event = create_pointer_event(pointer, boundary.node, name, boundary.coordinates, screen_position, -1);+ auto event = create_pointer_event(pointer, boundary.node, name, boundary.coordinates, screen_position, pointer.properties.pointer_type == PointerType::Touch && (!pointer.last_position.has_value() || pointer.buttons == 0) ? 0 : -1);event->set_related_target(related_target);event->set_bubbles(bubbles);event->set_cancelable(bubbles);@@ -4430,10 +4432,23 @@ void EventHandler::update_pointer_hover(Layout::BegunRead const& read, PointerStdispatch(boundary, UIEvents::EventNames::pointerenter, previous, false);}+bool EventHandler::has_pointer_capture_in_subtree(i32 pointer_id) const+{+ auto const* state = pointer_state(pointer_id);+ if (!state)+ return false;+ if (state->pending_capture_target || state->capture_target)+ return true;+ auto* container = as_if<HTML::NavigableContainer>(state->nested_target.ptr().ptr());+ if (!container)+ return false;+ auto* child = as_if<HTML::LocalNavigable>(container->content_navigable().ptr());+ return child && child->event_handler().has_pointer_capture_in_subtree(pointer_id);+}+// https://w3c.github.io/pointerevents/#firing-events-using-the-pointerevent-interfaceEventResult EventHandler::handle_pointer_event(Web::MouseEvent const& input, CSSPixelPoint visual_viewport_position, CSSPixelPoint screen_position, Optional<RemoteInputEventTarget>* remote_target){- // FIXME: Add compatibility mouse dispatch and default actions before enabling WebDriver touch and pen input.auto const* properties = input.pointer_data.ptr();VERIFY(properties && properties->pointer_type != PointerType::Mouse);if (input.type == Web::MouseEvent::Type::MouseWheel)@@ -4451,10 +4466,12 @@ EventResult EventHandler::handle_pointer_event(Web::MouseEvent const& input, CSSauto pointer = make_ref_counted<AdditionalPointerState>();pointer->state.properties = *properties;pointer->state.is_primary = true;- for (auto const& entry : m_additional_pointers) {- if (entry.value->state.active && entry.value->state.properties.pointer_type == properties->pointer_type) {- pointer->state.is_primary = false;- break;+ for (auto const& navigable : m_navigable->page().hosted_navigables()) {+ for (auto const& entry : navigable->event_handler().m_additional_pointers) {+ if (entry.key != properties->pointer_id && entry.value->state.active && entry.value->state.properties.pointer_type == properties->pointer_type) {+ pointer->state.is_primary = false;+ break;+ }}}m_additional_pointers.set(properties->pointer_id, move(pointer));@@ -4490,14 +4507,57 @@ EventResult EventHandler::handle_pointer_event(Web::MouseEvent const& input, CSSGC::Ptr<DOM::Node> hit_target = hit.has_value() ? hit->dom_node() : nullptr;auto* layout_node = hit.has_value() ? hit->layout_node(read) : nullptr;- // FIXME: Route captured pointers to their owning navigable before hit testing, including captures in another- // WebContent process.+ // FIXME: Route capture acquired in another navigable outside this local descendant chain, including capture+ // held in another WebContent process, to its owning EventHandler.+ if (auto* container = as_if<HTML::NavigableContainer>(pointer.nested_target.ptr().ptr())) {+ auto* child = as_if<HTML::LocalNavigable>(container->content_navigable().ptr());+ if (child && child->event_handler().has_pointer_capture_in_subtree(properties->pointer_id)) {+ if (auto* container_layout = container->layout_node(read)) {+ auto result = dispatch_event_to_nested_navigable(*this, *container_layout, container, visual_viewport_position, remote_target, [&](EventHandler& handler, CSSPixelPoint position) {+ return handler.handle_pointer_event(input, position, screen_position, remote_target);+ });+ if (result.has_value()) {+ pointer.active = false;+ if (cancelled || (input.type == Web::MouseEvent::Type::MouseUp && pointer.buttons == 0))+ m_additional_pointers.remove(properties->pointer_id);+ return *result;+ }+ }+ }+ }+ GC::Ptr<DOM::Node> nested_target = !pointer.pending_capture_target && layout_node && Painting::is_navigable_container_viewport_paintable(*layout_node) ? hit_target : nullptr;+ if (auto previous_nested_target = pointer.nested_target.ptr(); previous_nested_target && previous_nested_target != nested_target) {+ pointer.nested_target = nullptr;+ if (auto* previous_layout = previous_nested_target->layout_node(read)) {+ (void)dispatch_event_to_nested_navigable(*this, *previous_layout, previous_nested_target, visual_viewport_position, nullptr, [&](EventHandler& child, CSSPixelPoint position) {+ auto const* child_pointer = child.pointer_state(properties->pointer_id);+ if (!child_pointer)+ return EventResult::Handled;+ auto cleanup = input.clone_without_browser_data();+ // NB: The parent has already updated its buttons for this event, but the child may still hold a press.+ cleanup.type = child_pointer->buttons ? Web::MouseEvent::Type::MouseCancel : Web::MouseEvent::Type::MouseLeave;+ return child.handle_pointer_event(cleanup, position, screen_position, nullptr);+ });+ if (m_navigable->active_document() != document)+ return EventResult::Handled;+ document->update_layout(DOM::UpdateLayoutReason::EventHandlerHandleMouseMove);+ if (!has_committed_root_box())+ return EventResult::Dropped;+ viewport_position = document->visual_viewport()->map_to_layout_viewport(visual_viewport_position);+ hit = target_for_mouse_position(visual_viewport_position);+ hit_target = hit.has_value() ? hit->dom_node() : nullptr;+ layout_node = hit.has_value() ? hit->layout_node(read) : nullptr;+ }+ }if (!pointer.pending_capture_target && layout_node) {auto result = dispatch_event_to_nested_navigable(*this, *layout_node, hit_target, visual_viewport_position, remote_target, [&](EventHandler& child, CSSPixelPoint position) {return child.handle_pointer_event(input, position, screen_position, remote_target);});if (result.has_value()) {+ pointer.nested_target = hit_target;pointer.active = false;+ if (cancelled || (input.type == Web::MouseEvent::Type::MouseUp && pointer.buttons == 0))+ m_additional_pointers.remove(properties->pointer_id);return *result;}}@@ -4532,6 +4592,22 @@ EventResult EventHandler::handle_pointer_event(Web::MouseEvent const& input, CSS}update_pointer_hover(read, pointer, target, coordinates, screen_position);if (!target || input.type == Web::MouseEvent::Type::MouseLeave) {+ if (!target && pointer.is_primary && pointer.properties.pointer_type == PointerType::Pen) {+ DOM::HoverEventData hover_data {+ .screen_position = screen_position,+ .page_offset = coordinates.page_offset,+ .viewport_position = coordinates.viewport_position,+ .offset = coordinates.offset,+ .movement = {},+ .buttons = pointer.buttons,+ .modifiers = pointer.modifiers,+ };+ document->dispatch_boundary_events(m_effective_legacy_mouse_pointer_position.ptr(), nullptr, hover_data, DOM::Document::BoundaryEventTypes::Mouse);+ m_effective_legacy_mouse_pointer_position = nullptr;+ CSS::move_style_hover(*document, nullptr);+ if (m_navigable->active_document() != document)+ return EventResult::Handled;+ }if (cancelled || (input.type == Web::MouseEvent::Type::MouseUp && pointer.buttons == 0)) {release_pointer_capture_implicitly(read, pointer);pointer.active = false;@@ -4556,6 +4632,27 @@ EventResult EventHandler::handle_pointer_event(Web::MouseEvent const& input, CSSauto button = input.type == Web::MouseEvent::Type::MouseMove ? i16 { -1 } : UIEvents::mouse_button_to_button_code(input.button);auto movement = name == UIEvents::EventNames::pointermove && previous_position.has_value() ? screen_position - previous_position->screen_position : CSSPixelPoint {};pointer.last_position = PointerEventPosition { coordinates, screen_position };+ if (name == UIEvents::EventNames::pointerdown) {+ pointer.down_target = target;+ if (pointer.properties.pointer_type == PointerType::Touch && is<DOM::Element>(*target))+ pointer.pending_capture_target = as<DOM::Element>(*target);+ }+ if (pointer.is_primary && !cancelled) {+ DOM::HoverEventData hover_data {+ .screen_position = screen_position,+ .page_offset = coordinates.page_offset,+ .viewport_position = coordinates.viewport_position,+ .offset = coordinates.offset,+ .movement = {},+ .buttons = pointer.buttons,+ .modifiers = pointer.modifiers,+ };+ document->dispatch_boundary_events(m_effective_legacy_mouse_pointer_position.ptr(), target, hover_data, DOM::Document::BoundaryEventTypes::Mouse);+ m_effective_legacy_mouse_pointer_position = target;+ CSS::move_style_hover(*document, target);+ if (m_navigable->active_document() != document)+ return EventResult::Handled;+ }auto event = create_pointer_event(pointer, *target, name, coordinates, screen_position, button, movement);if (cancelled)event->set_cancelable(false);@@ -4566,13 +4663,64 @@ EventResult EventHandler::handle_pointer_event(Web::MouseEvent const& input, CSSreturn EventResult::Handled;if (name == UIEvents::EventNames::pointerup || cancelled) {- pointer.prevent_mouse_event = false;+ // https://w3c.github.io/pointerevents/#implicit-release-of-pointer-capturerelease_pointer_capture_implicitly(read, pointer);if (m_navigable->active_document() != document)return EventResult::Handled;document->update_layout(DOM::UpdateLayoutReason::EventHandlerPointerCaptureEvents);auto hover_target = pointer.properties.pointer_type == PointerType::Touch || cancelled ? nullptr : hit_target;update_pointer_hover(read, pointer, hover_target, coordinates, screen_position);+ if (m_navigable->active_document() != document)+ return EventResult::Handled;+ }++ // https://w3c.github.io/pointerevents/#mapping-for-devices-that-support-hover+ // pointercancel, then fire a mouseup event at the window.+ if (cancelled && pointer.is_primary && pointer.properties.pointer_type == PointerType::Pen && !pointer.prevent_mouse_event) {+ auto mouse_event = UIEvents::MouseEvent::create_from_platform_event(HTML::relevant_global_object(*document), m_navigable->active_window_proxy(), UIEvents::EventNames::mouseup,+ screen_position, coordinates.page_offset, coordinates.viewport_position, coordinates.offset, {},+ UIEvents::MouseButton::Primary, 0, pointer.modifiers, 1)+ .release_value_but_fixme_should_propagate_errors();+ document->window()->dispatch_event(mouse_event);+ if (m_navigable->active_document() != document)+ return EventResult::Handled;+ }++ // https://w3c.github.io/pointerevents/#compatibility-mapping-with-mouse-events+ if (pointer.is_primary && !cancelled) {+ if (!pointer.prevent_mouse_event) {+ auto mouse_name = input.type == Web::MouseEvent::Type::MouseDown ? UIEvents::EventNames::mousedown+ : input.type == Web::MouseEvent::Type::MouseUp ? UIEvents::EventNames::mouseup+ : UIEvents::EventNames::mousemove;+ auto mouse_event = UIEvents::MouseEvent::create_from_platform_event(HTML::relevant_global_object(*document), m_navigable->active_window_proxy(), mouse_name,+ screen_position, coordinates.page_offset, coordinates.viewport_position, coordinates.offset, {},+ to_underlying(input.button), pointer.buttons, pointer.modifiers, mouse_name == UIEvents::EventNames::mousemove ? 0 : 1)+ .release_value_but_fixme_should_propagate_errors();+ auto allowed = target->dispatch_event(mouse_event);+ if (m_navigable->active_document() != document)+ return EventResult::Handled;+ if (allowed && mouse_name == UIEvents::EventNames::mousedown) {+ if (auto focus_target = focus_candidate_for_position(read, visual_viewport_position))+ HTML::run_focusing_steps(focus_target, nullptr, HTML::FocusTrigger::Click);+ }+ }+ if (name == UIEvents::EventNames::pointerup && input.button == UIEvents::MouseButton::Primary) {+ auto click_target = capture_target ? target : target_for_click_event(pointer.down_target.ptr().ptr(), *target);+ if (click_target) {+ auto click_coordinates = coordinates;+ if (auto* click_layout = click_target->layout_node(read))+ click_coordinates = compute_mouse_event_coordinates(visual_viewport_position, viewport_position, *click_layout);+ auto click = create_pointer_event(pointer, *click_target, UIEvents::EventNames::click, click_coordinates, screen_position, 0);+ if (click_target->dispatch_event(click))+ run_activation_behavior(*click_target, to_underlying(input.button), pointer.modifiers);+ }+ }+ }+ if (m_navigable->active_document() != document)+ return EventResult::Handled;+ if (name == UIEvents::EventNames::pointerup || cancelled) {+ pointer.down_target = nullptr;+ pointer.prevent_mouse_event = false;if (pointer.properties.pointer_type == PointerType::Touch || cancelled) {pointer.active = false;m_additional_pointers.remove(properties->pointer_id);@@ -4918,7 +5066,7 @@ void EventHandler::track_the_effective_position_of_the_legacy_mouse_pointer(GC::// 2. If T and current effective legacy mouse pointer position are both unset or they are equal, terminate these// steps.- if (m_effective_legacy_mouse_pointer_position == target)+ if (m_effective_legacy_mouse_pointer_position == target && document.hovered_node() == target.ptr())return;// AD-HOC: An event older than a pointer move whose hover the screen showed leaves the pointer where that move went.@@ -4928,8 +5076,12 @@ void EventHandler::track_the_effective_position_of_the_legacy_mouse_pointer(GC::// 3. Dispatch mouseover, mouseout, mouseenter and mouseleave events as per [UIEVENTS] for a mouse moving from the// current effective legacy mouse pointer position to T. Consider an unset value of either current effective// legacy mouse pointer position or T as an out-of-window mouse position.- // FIXME: This is supposed to only fire legacy events. The pointer events should be fired elsewhere.- document.set_hovered_node(target, hover_event_data);+ if (m_effective_legacy_mouse_pointer_position == document.hovered_node()) {+ document.set_hovered_node(target, hover_event_data);+ } else {+ document.set_hovered_node(target, hover_event_data, DOM::Document::BoundaryEventTypes::Pointer);+ document.dispatch_boundary_events(m_effective_legacy_mouse_pointer_position.ptr(), target, hover_event_data, DOM::Document::BoundaryEventTypes::Mouse);+ }// 4. Set effective legacy mouse pointer position to T.m_effective_legacy_mouse_pointer_position = target;diff --git a/Libraries/LibWeb/Page/EventHandler.h b/Libraries/LibWeb/Page/EventHandler.hindex 697a9d41712..c2c5cc162f2 100644--- a/Libraries/LibWeb/Page/EventHandler.h+++ b/Libraries/LibWeb/Page/EventHandler.h@@ -185,6 +185,8 @@ private:// NB: A pointercancel uses the last dispatched position.Optional<PointerEventPosition> last_position;GC::Weak<DOM::Node> hovered_node;+ GC::Weak<DOM::Node> down_target;+ GC::Weak<DOM::Node> nested_target;// https://w3c.github.io/pointerevents/#dfn-pending-pointer-capture-target-overrideGC::Weak<DOM::Element> pending_capture_target;// https://w3c.github.io/pointerevents/#dfn-pointer-capture-target-override@@ -196,6 +198,7 @@ private:};GC::Ref<UIEvents::PointerEvent> create_pointer_event(PointerState const&, DOM::Node const&, Utf16FlyString const&, MouseEventCoordinates const&, CSSPixelPoint screen_position, i16 button, CSSPixelPoint movement = {}) const;void update_pointer_hover(Layout::BegunRead const&, PointerState&, GC::Ptr<DOM::Node>, MouseEventCoordinates const&, CSSPixelPoint screen_position);+ bool has_pointer_capture_in_subtree(i32 pointer_id) const;PointerState const* pointer_state(i32 pointer_id) const;PointerState* pointer_state(i32 pointer_id);diff --git a/Libraries/LibWeb/WebDriver/Actions.cpp b/Libraries/LibWeb/WebDriver/Actions.cppindex ccc76b8e093..04840c306c4 100644--- a/Libraries/LibWeb/WebDriver/Actions.cpp+++ b/Libraries/LibWeb/WebDriver/Actions.cpp@@ -508,8 +508,7 @@ static ErrorOr<ActionObject, WebDriver::Error> process_pointer_action(String id,// 8. If subtype is "pointerCancel" process a pointer cancel action. If doing so results in an error, return that error.else if (subtype == PointerCancel) {- // FIXME: There are no spec steps to "process a pointer cancel action" yet.- return WebDriver::Error::from_code(WebDriver::ErrorCode::UnsupportedOperation, "pointerCancel events not implemented"sv);+ // NB: No additional properties are defined for pointerCancel.}// 9. Return success with data action.@@ -1126,11 +1125,81 @@ static ErrorOr<void, WebDriver::Error> dispatch_key_up_action(ActionObject::KeyFreturn {};}+// NB: Native mouse input keeps the empty payload and avoids allocating per-action pointer data.+static PointerInputData pointer_input_data(ActionObject::PointerFields const& action, PointerInputSource const& source, bool active)+{+ if (source.subtype == PointerInputSource::Subtype::Mouse)+ return {};+ PointerProperties properties;+ properties.pointer_id = source.pointer_id;+ properties.pointer_type = source.subtype == PointerInputSource::Subtype::Touch ? PointerType::Touch : PointerType::Pen;+ properties.width = action.width.value_or(1);+ properties.height = action.height.value_or(1);+ properties.pressure = active ? action.pressure.value_or(0.5) : 0;+ properties.tangential_pressure = action.tangential_pressure.value_or(0);+ properties.tilt_x = action.tilt_x.value_or(0);+ properties.tilt_y = action.tilt_y.value_or(0);+ properties.twist = action.twist.value_or(0);+ properties.altitude_angle = action.altitude_angle.value_or(AK::Pi<double> / 2);+ properties.azimuth_angle = action.azimuth_angle.value_or(0);+ // https://w3c.github.io/pointerevents/#converting-between-tiltx-tilty-and-altitudeangle-azimuthangle+ // NB: Platforms may supply either orientation representation. Preserve explicitly supplied components.+ constexpr auto pi = AK::Pi<double>;+ if (action.altitude_angle.has_value() || action.azimuth_angle.has_value()) {+ auto altitude = properties.altitude_angle;+ auto azimuth = properties.azimuth_angle;+ double tilt_x = 0;+ double tilt_y = 0;+ if (altitude == 0) {+ if (azimuth < pi / 2 || azimuth > 3 * pi / 2)+ tilt_x = 90;+ else if (azimuth > pi / 2 && azimuth < 3 * pi / 2)+ tilt_x = -90;+ if (azimuth > 0 && azimuth < pi)+ tilt_y = 90;+ else if (azimuth > pi && azimuth < 2 * pi)+ tilt_y = -90;+ } else {+ tilt_x = atan(cos(azimuth) / tan(altitude)) * 180 / pi;+ tilt_y = atan(sin(azimuth) / tan(altitude)) * 180 / pi;+ }+ properties.tilt_x = action.tilt_x.value_or(static_cast<i32>(floor(tilt_x + 0.5)));+ properties.tilt_y = action.tilt_y.value_or(static_cast<i32>(floor(tilt_y + 0.5)));+ } else if (action.tilt_x.has_value() || action.tilt_y.has_value()) {+ auto tilt_x = properties.tilt_x;+ auto tilt_y = properties.tilt_y;+ auto radians_x = tilt_x * pi / 180;+ auto radians_y = tilt_y * pi / 180;+ if (tilt_x == 0)+ properties.azimuth_angle = tilt_y > 0 ? pi / 2 : tilt_y < 0 ? 3 * pi / 2+ : 0;+ else if (tilt_y == 0)+ properties.azimuth_angle = tilt_x < 0 ? pi : 0;+ else if (abs(tilt_x) != 90 && abs(tilt_y) != 90) {+ properties.azimuth_angle = atan2(tan(radians_y), tan(radians_x));+ if (properties.azimuth_angle < 0)+ properties.azimuth_angle += 2 * pi;+ }+ if (abs(tilt_x) == 90 || abs(tilt_y) == 90)+ properties.altitude_angle = 0;+ else if (tilt_x == 0)+ properties.altitude_angle = pi / 2 - fabs(radians_y);+ else if (tilt_y == 0)+ properties.altitude_angle = pi / 2 - fabs(radians_x);+ else {+ auto tangent_x = tan(radians_x);+ auto tangent_y = tan(radians_y);+ properties.altitude_angle = atan(1 / sqrt(tangent_x * tangent_x + tangent_y * tangent_y));+ }+ }+ return PointerInputData { properties };+}+// https://w3c.github.io/webdriver/#dfn-dispatch-a-pointerdown-actionstatic ErrorOr<void, WebDriver::Error> dispatch_pointer_down_action(ActionObject::PointerUpDownFields const& action_object, PointerInputSource& source, GlobalKeyState const& global_key_state, HTML::BrowsingContext& browsing_context, DispatchMouseEvent const& dispatch_mouse_event){// 1. Let pointerType be equal to action object's pointerType property.- auto pointer_type = action_object.pointer_type;+ [[maybe_unused]] auto pointer_type = action_object.pointer_type;// 2. Let button be equal to action object's button property.auto button = action_object.button;@@ -1164,24 +1233,16 @@ static ErrorOr<void, WebDriver::Error> dispatch_pointer_down_action(ActionObject// and [POINTER-EVENTS]. set ctrlKey, shiftKey, altKey, and metaKey equal to the corresponding items in global// key state. Type specific properties for the pointer that are not exposed through the webdriver API must be// set to the default value specified for hardware that doesn't support that property.- switch (pointer_type) {- case PointerInputSource::Subtype::Mouse: {- Web::MouseEvent event;- event.type = Web::MouseEvent::Type::MouseDown;- event.position = position;- event.screen_position = position;- event.button = button;- event.buttons = buttons;- event.modifiers = global_key_state.modifiers();- event.click_count = 1;- dispatch_mouse_event(move(event));- break;- }- case PointerInputSource::Subtype::Pen:- return WebDriver::Error::from_code(WebDriver::ErrorCode::UnsupportedOperation, "Pen events not implemented"sv);- case PointerInputSource::Subtype::Touch:- return WebDriver::Error::from_code(WebDriver::ErrorCode::UnsupportedOperation, "Touch events not implemented"sv);- }+ Web::MouseEvent event;+ event.type = Web::MouseEvent::Type::MouseDown;+ event.position = position;+ event.screen_position = position;+ event.button = button;+ event.buttons = buttons;+ event.modifiers = global_key_state.modifiers();+ event.click_count = 1;+ event.pointer_data = pointer_input_data(action_object, source, true);+ dispatch_mouse_event(move(event));// 17. Return success with data null.return {};@@ -1191,7 +1252,7 @@ static ErrorOr<void, WebDriver::Error> dispatch_pointer_down_action(ActionObjectstatic ErrorOr<void, WebDriver::Error> dispatch_pointer_up_action(ActionObject::PointerUpDownFields const& action_object, PointerInputSource& source, GlobalKeyState const& global_key_state, HTML::BrowsingContext& browsing_context, DispatchMouseEvent const& dispatch_mouse_event){// 1. Let pointerType be equal to action object's pointerType property.- auto pointer_type = action_object.pointer_type;+ [[maybe_unused]] auto pointer_type = action_object.pointer_type;// 2. Let button be equal to action object's button property.auto button = action_object.button;@@ -1215,23 +1276,15 @@ static ErrorOr<void, WebDriver::Error> dispatch_pointer_up_action(ActionObject::// and metaKey equal to the corresponding items in global key state. Type specific properties for the pointer// that are not exposed through the webdriver API must be set to the default value specified for hardware that// doesn't support that property.- switch (pointer_type) {- case PointerInputSource::Subtype::Mouse: {- Web::MouseEvent event;- event.type = Web::MouseEvent::Type::MouseUp;- event.position = position;- event.screen_position = position;- event.button = button;- event.buttons = buttons;- event.modifiers = global_key_state.modifiers();- dispatch_mouse_event(move(event));- break;- }- case PointerInputSource::Subtype::Pen:- return WebDriver::Error::from_code(WebDriver::ErrorCode::UnsupportedOperation, "Pen events not implemented"sv);- case PointerInputSource::Subtype::Touch:- return WebDriver::Error::from_code(WebDriver::ErrorCode::UnsupportedOperation, "Touch events not implemented"sv);- }+ Web::MouseEvent event;+ event.type = Web::MouseEvent::Type::MouseUp;+ event.position = position;+ event.screen_position = position;+ event.button = button;+ event.buttons = buttons;+ event.modifiers = global_key_state.modifiers();+ event.pointer_data = pointer_input_data(action_object, source, buttons != UIEvents::MouseButton::None);+ dispatch_mouse_event(move(event));// 8. Return success with data null.return {};@@ -1253,7 +1306,9 @@ static ErrorOr<void, WebDriver::Error> perform_pointer_move(ActionObject::Pointeauto current = source.position;// 8. If x is not equal to current x or y is not equal to current y, run the following steps:- if (current != coordinates) {+ // AD-HOC: Contact geometry and pressure can change without changing the coordinates, so touch and pen moves are+ // dispatched even when the position stays the same.+ if (current != coordinates || source.subtype != PointerInputSource::Subtype::Mouse) {// 1. Let buttons be equal to input state's buttons property.auto buttons = source.pressed;@@ -1269,22 +1324,14 @@ static ErrorOr<void, WebDriver::Error> perform_pointer_move(ActionObject::Pointe// always produce events including at least a pointerMove event.auto position = browsing_context.page().css_to_device_point(coordinates);- switch (action_object.pointer_type) {- case PointerInputSource::Subtype::Mouse: {- Web::MouseEvent event;- event.type = Web::MouseEvent::Type::MouseMove;- event.position = position;- event.screen_position = position;- event.buttons = buttons;- event.modifiers = global_key_state.modifiers();- dispatch_mouse_event(move(event));- break;- }- case PointerInputSource::Subtype::Pen:- return WebDriver::Error::from_code(WebDriver::ErrorCode::UnsupportedOperation, "Pen events not implemented"sv);- case PointerInputSource::Subtype::Touch:- return WebDriver::Error::from_code(WebDriver::ErrorCode::UnsupportedOperation, "Touch events not implemented"sv);- }+ Web::MouseEvent event;+ event.type = Web::MouseEvent::Type::MouseMove;+ event.position = position;+ event.screen_position = position;+ event.buttons = buttons;+ event.modifiers = global_key_state.modifiers();+ event.pointer_data = pointer_input_data(action_object, source, buttons != UIEvents::MouseButton::None);+ dispatch_mouse_event(move(event));// 3. Let input state's x property equal x and y property equal y.source.position = coordinates;@@ -1628,8 +1675,21 @@ static ErrorOr<void, WebDriver::Error> dispatch_tick_actions(InputState& input_scase ActionObject::Subtype::PointerMove:TRY(dispatch_pointer_move_action(action_object.pointer_move_fields(), source->get<PointerInputSource>(), global_key_state, tick_duration, browsing_context, actions_options, dispatch_mouse_event));break;- case ActionObject::Subtype::PointerCancel:- return WebDriver::Error::from_code(WebDriver::ErrorCode::UnsupportedOperation, "Pointer cancel events not implemented"sv);+ case ActionObject::Subtype::PointerCancel: {+ auto& pointer = source->get<PointerInputSource>();+ if (pointer.subtype == PointerInputSource::Subtype::Mouse)+ return WebDriver::Error::from_code(WebDriver::ErrorCode::UnsupportedOperation, "Mouse cancel events not implemented"sv);+ Web::MouseEvent event;+ event.type = Web::MouseEvent::Type::MouseCancel;+ event.position = browsing_context.page().css_to_device_point(pointer.position);+ event.screen_position = event.position;+ ActionObject::PointerFields fields;+ event.pointer_data = pointer_input_data(fields, pointer, false);+ event.modifiers = global_key_state.modifiers();+ pointer.pressed = UIEvents::MouseButton::None;+ dispatch_mouse_event(move(event));+ break;+ }case ActionObject::Subtype::Scroll:TRY(dispatch_scroll_action(action_object.scroll_fields(), global_key_state, tick_duration, browsing_context, actions_options, dispatch_mouse_event));break;diff --git a/Tests/LibWeb/Text/expected/UIEvents/pen-cancellation-and-hover-exit.txt b/Tests/LibWeb/Text/expected/UIEvents/pen-cancellation-and-hover-exit.txtnew file mode 100644index 00000000000..1ff1afb36a6--- /dev/null+++ b/Tests/LibWeb/Text/expected/UIEvents/pen-cancellation-and-hover-exit.txt@@ -0,0 +1,3 @@+pointercancel: target, buttons=0+mouseup: window, buttons=0+leaves: pointer=1, mouse=1, hover=falsediff --git a/Tests/LibWeb/Text/expected/UIEvents/pointer-leaves-local-iframe.txt b/Tests/LibWeb/Text/expected/UIEvents/pointer-leaves-local-iframe.txtnew file mode 100644index 00000000000..b3dbd4be753--- /dev/null+++ b/Tests/LibWeb/Text/expected/UIEvents/pointer-leaves-local-iframe.txt@@ -0,0 +1,8 @@+pointerout: 145,25+pointerleave: 145,25+touch pointerdown: primary=true+touchstart: touches=1+touchcancel: touches=0, changed=1+touch pointerdown: primary=true+touchstart: touches=1+click: touchdiff --git a/Tests/LibWeb/Text/expected/UIEvents/touch-capture-in-local-iframe.txt b/Tests/LibWeb/Text/expected/UIEvents/touch-capture-in-local-iframe.txtnew file mode 100644index 00000000000..7d86e3e755c--- /dev/null+++ b/Tests/LibWeb/Text/expected/UIEvents/touch-capture-in-local-iframe.txt@@ -0,0 +1,5 @@+pointerdown: touch, 20, primary=true, captured=true+gotpointercapture: touch, 20, primary=true, captured=true+pointermove: touch, 180, primary=true, captured=true+pointerup: touch, 180, primary=true, captured=true+lostpointercapture: touch, 180, primary=true, captured=falsediff --git a/Tests/LibWeb/Text/expected/UIEvents/webdriver-actions-early-completion.txt b/Tests/LibWeb/Text/expected/UIEvents/webdriver-actions-early-completion.txtnew file mode 100644index 00000000000..ec8d3d3fd03--- /dev/null+++ b/Tests/LibWeb/Text/expected/UIEvents/webdriver-actions-early-completion.txt@@ -0,0 +1 @@+finished from a pointerdown listenerdiff --git a/Tests/LibWeb/Text/expected/UIEvents/webdriver-touch-and-pen-actions.txt b/Tests/LibWeb/Text/expected/UIEvents/webdriver-touch-and-pen-actions.txtnew file mode 100644index 00000000000..c65d23c05cb--- /dev/null+++ b/Tests/LibWeb/Text/expected/UIEvents/webdriver-touch-and-pen-actions.txt@@ -0,0 +1,18 @@+pointerdown:a:touch:true+mousedown:a:mouse:-+pointerdown:b:touch:false+gotpointercapture:a:touch:true+pointermove:a:touch:true+gotpointercapture:b:touch:false+pointermove:b:touch:false+pointerup:a:touch:true+lostpointercapture:a:touch:true+mouseup:a:mouse:-+click:a:touch:true+pointerup:b:touch:false+lostpointercapture:b:touch:false+properties:12,18,0.75,0.25,30,-20,90,0.5,1.25+pointermove:a:pen:true+pointerdown:a:pen:true+pointerup:a:pen:true+click:a:pen:truediff --git a/Tests/LibWeb/Text/input/UIEvents/pen-cancellation-and-hover-exit.html b/Tests/LibWeb/Text/input/UIEvents/pen-cancellation-and-hover-exit.htmlnew file mode 100644index 00000000000..39a9721ab16--- /dev/null+++ b/Tests/LibWeb/Text/input/UIEvents/pen-cancellation-and-hover-exit.html@@ -0,0 +1,21 @@+<!doctype html>+<style>body{margin:0}#target{width:100px;height:100px}</style>+<div id="target"></div>+<script src="../include.js"></script>+<script>+asyncTest(async done => {+ for (const type of ["pointercancel", "mouseup"])+ window.addEventListener(type, event => println(`${type}: ${event.target===window ? "window" : event.target.id}, buttons=${event.buttons}`));+ await internals.performActions(JSON.stringify({actions:[{type:"pointer",id:"pen",parameters:{pointerType:"pen"},actions:[+ {type:"pointerMove",x:20,y:20},{type:"pointerDown",button:0},{type:"pointerCancel"}+ ]}]}));+ let pointerLeaves=0, mouseLeaves=0;+ target.addEventListener("pointerleave", () => ++pointerLeaves);+ target.addEventListener("mouseleave", () => ++mouseLeaves);+ const pointer = {pointerType:"pen",pointerId:20};+ await internals.mouseEventThroughUIProcess("mousemove",20,20,{pointer});+ await internals.mouseEventThroughUIProcess("mouseleave",20,20,{pointer});+ println(`leaves: pointer=${pointerLeaves}, mouse=${mouseLeaves}, hover=${target.matches(":hover")}`);+ done();+});+</script>diff --git a/Tests/LibWeb/Text/input/UIEvents/pointer-leaves-local-iframe.html b/Tests/LibWeb/Text/input/UIEvents/pointer-leaves-local-iframe.htmlnew file mode 100644index 00000000000..4fffe9c5c3b--- /dev/null+++ b/Tests/LibWeb/Text/input/UIEvents/pointer-leaves-local-iframe.html@@ -0,0 +1,57 @@+<!doctype html>+<meta charset="utf-8" />+<style>+ body {+ margin: 0;+ }+ iframe {+ position: absolute;+ left: 40px;+ top: 30px;+ width: 100px;+ height: 100px;+ border: 0;+ }+ #outside {+ position: absolute;+ left: 180px;+ top: 30px;+ width: 100px;+ height: 100px;+ }+</style>+<iframe srcdoc="<style>body{margin:0}div{width:100px;height:100px}</style><div id='target'></div>"></iframe>+<div id="outside"></div>+<script src="../include.js"></script>+<script>+ asyncTest(async done => {+ const frame = document.querySelector("iframe");+ if (!frame.contentDocument.getElementById("target")) await new Promise(resolve => (frame.onload = resolve));+ const target = frame.contentDocument.getElementById("target");+ for (const type of ["pointerout", "pointerleave"])+ target.addEventListener(type, event => {+ if (event.pointerType === "pen") println(`${type}: ${event.clientX},${event.clientY}`);+ });+ const pen = { pointerType: "pen", pointerId: 20 };+ await internals.mouseEventThroughUIProcess("mousemove", 65, 55, { pointer: pen });+ await internals.mouseEventThroughUIProcess("mousemove", 185, 55, { pointer: pen });+ await internals.mouseEventThroughUIProcess("mousemove", 190, 55, { pointer: pen });++ target.addEventListener("pointerdown", event => {+ target.releasePointerCapture(event.pointerId);+ println(`touch pointerdown: primary=${event.isPrimary}`);+ });+ target.addEventListener("touchstart", event => println(`touchstart: touches=${event.touches.length}`));+ target.addEventListener("touchcancel", event =>+ println(`touchcancel: touches=${event.touches.length}, changed=${event.changedTouches.length}`)+ );+ target.addEventListener("click", event => println(`click: ${event.pointerType}`));+ const first = { pointerType: "touch", pointerId: 21 };+ await internals.mouseEventThroughUIProcess("mousedown", 65, 55, { pointer: first });+ await internals.mouseEventThroughUIProcess("mouseup", 185, 55, { pointer: first });+ const second = { pointerType: "touch", pointerId: 22 };+ await internals.mouseEventThroughUIProcess("mousedown", 65, 55, { pointer: second });+ await internals.mouseEventThroughUIProcess("mouseup", 65, 55, { pointer: second });+ done();+ });+</script>diff --git a/Tests/LibWeb/Text/input/UIEvents/touch-capture-in-local-iframe.html b/Tests/LibWeb/Text/input/UIEvents/touch-capture-in-local-iframe.htmlnew file mode 100644index 00000000000..950eba21be1--- /dev/null+++ b/Tests/LibWeb/Text/input/UIEvents/touch-capture-in-local-iframe.html@@ -0,0 +1,20 @@+<!doctype html>+<meta charset="utf-8">+<style>body { margin:0 } iframe { width:100px; height:100px; border:0 }</style>+<iframe srcdoc="<style>body{margin:0}div{width:100px;height:100px}</style><div id='target'></div>"></iframe>+<script src="../include.js"></script>+<script>+asyncTest(async done => {+ const frame = document.querySelector("iframe");+ if (!frame.contentDocument.getElementById("target"))+ await new Promise(resolve => frame.onload = resolve);+ const target = frame.contentDocument.getElementById("target");+ for (const type of ["pointerdown", "pointermove", "pointerup", "gotpointercapture", "lostpointercapture"])+ target.addEventListener(type, event => println(`${type}: ${event.pointerType}, ${event.clientX}, primary=${event.isPrimary}, captured=${target.hasPointerCapture(event.pointerId)}`));+ await internals.performActions(JSON.stringify({ actions: [{ type:"pointer", id:"touch", parameters:{pointerType:"touch"}, actions:[+ {type:"pointerMove",x:20,y:20}, {type:"pointerDown",button:0},+ {type:"pointerMove",x:180,y:20}, {type:"pointerUp",button:0}+ ] }]}));+ done();+});+</script>diff --git a/Tests/LibWeb/Text/input/UIEvents/webdriver-actions-early-completion.html b/Tests/LibWeb/Text/input/UIEvents/webdriver-actions-early-completion.htmlnew file mode 100644index 00000000000..d6d99820c5a--- /dev/null+++ b/Tests/LibWeb/Text/input/UIEvents/webdriver-actions-early-completion.html@@ -0,0 +1,15 @@+<!doctype html>+<style>body{margin:0}#target{width:100px;height:100px}</style>+<div id="target"></div>+<script src="../include.js"></script>+<script>+asyncTest(async done => {+ target.addEventListener("pointerdown", () => {+ println("finished from a pointerdown listener");+ done();+ });+ await internals.performActions(JSON.stringify({actions:[{type:"pointer",id:"touch",parameters:{pointerType:"touch"},actions:[+ {type:"pointerMove",x:20,y:20},{type:"pointerDown",button:0},{type:"pointerMove",x:30,y:30},{type:"pointerUp",button:0}+ ]}]}));+});+</script>diff --git a/Tests/LibWeb/Text/input/UIEvents/webdriver-touch-and-pen-actions.html b/Tests/LibWeb/Text/input/UIEvents/webdriver-touch-and-pen-actions.htmlnew file mode 100644index 00000000000..c78930b4f19--- /dev/null+++ b/Tests/LibWeb/Text/input/UIEvents/webdriver-touch-and-pen-actions.html@@ -0,0 +1,33 @@+<!doctype html>+<meta charset="utf-8">+<style>body { margin: 0 } #a, #b { position:absolute; width:100px; height:100px; top:0 } #a { left:0 } #b { left:150px }</style>+<div id="a"></div><div id="b"></div>+<script src="../include.js"></script>+<script>+asyncTest(async done => {+ const log = [];+ for (const type of ["pointerdown", "pointermove", "pointerup", "pointercancel", "gotpointercapture", "lostpointercapture", "mousedown", "mouseup", "click"])+ document.addEventListener(type, event => log.push(`${type}:${event.target.id}:${event.pointerType ?? "mouse"}:${event.isPrimary ?? "-"}`));+ const source = (id, pointerType, actions) => ({ type: "pointer", id, parameters: { pointerType }, actions });+ const move = (x, y, extra = {}) => ({ type: "pointerMove", x, y, ...extra });+ const down = { type: "pointerDown", button: 0 };+ const up = { type: "pointerUp", button: 0 };+ await internals.performActions(JSON.stringify({ actions: [+ source("finger1", "touch", [move(20,20), down, move(180,20), up]),+ source("finger2", "touch", [move(180,20), down, move(20,20), up]),+ ] }));+ println(log.join("\n"));+ log.length = 0;+ a.addEventListener("pointerdown", event => {+ if (event.pointerType === "pen") {+ println(`properties:${event.width},${event.height},${event.pressure},${event.tangentialPressure},${event.tiltX},${event.tiltY},${event.twist},${event.altitudeAngle},${event.azimuthAngle}`);+ event.preventDefault();+ }+ });+ await internals.performActions(JSON.stringify({ actions: [source("stylus", "pen", [move(20,20), {+ ...down, width:12, height:18, pressure:0.75, tangentialPressure:0.25, tiltX:30, tiltY:-20, twist:90, altitudeAngle:0.5, azimuthAngle:1.25+ }, up])] }));+ println(log.join("\n"));+ done();+});+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/resources/testdriver-vendor.js b/Tests/LibWeb/Text/input/wpt-import/resources/testdriver-vendor.jsindex 9ef5966b21e..f6e6b0e44b0 100644--- a/Tests/LibWeb/Text/input/wpt-import/resources/testdriver-vendor.js+++ b/Tests/LibWeb/Text/input/wpt-import/resources/testdriver-vendor.js@@ -32,6 +32,16 @@ window.test_driver_internal.delete_all_cookies = function(context) {const pointerStates = new Map();window.test_driver_internal.action_sequence = async function(actions, context) {+ if (actions.some(source => source.type === "pointer" && ["touch", "pen"].includes(source.parameters?.pointerType))) {+ const converted = actions.map(source => ({ ...source, actions: source.actions.map(action => {+ if (!(action.origin instanceof Element))+ return action;+ const center = elementCenter(action.origin);+ return { ...action, origin: "viewport", x: Math.round(center.x + (action.x ?? 0)), y: Math.round(center.y + (action.y ?? 0)) };+ }) }));+ return window.internals.performActions(JSON.stringify({ actions: converted }));+ }+// Modifier key codes from WebDriver specconst SHIFT = "\uE008";const CTRL = "\uE009";