Skip to content

Truly independent web browser

LibWeb+LibWebCommon+UI: Carry wheel ticks with wheel input events

Aliaksandr Kalenik387af03dd573
diff --git a/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp b/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp
index 4bfc384015a..b15f9f38877 100644
--- a/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp
+++ b/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp
@@ -474,9 +474,9 @@ void EventLoop::process_input_events() const
case Web::MouseEvent::Type::MouseWheel:
if (mouse_event.async_scroll_performed_default_action) {
dbgln_if(COMPOSITOR_DEBUG, "[Compositor] Main thread handling DOM wheel after async default action");
- return page.handle_mousewheel(*root, mouse_event.position, mouse_event.screen_position, mouse_event.button, mouse_event.buttons, mouse_event.modifiers, mouse_event.wheel_delta_x, mouse_event.wheel_delta_y, mouse_event.wheel_delta_precision, mouse_event.scroll_gesture_phase, true, nullptr, &remote_target);
+ return page.handle_mousewheel(*root, mouse_event.position, mouse_event.screen_position, mouse_event.button, mouse_event.buttons, mouse_event.modifiers, mouse_event.wheel_delta_x, mouse_event.wheel_delta_y, mouse_event.wheel_tick_120ths_x, mouse_event.wheel_tick_120ths_y, mouse_event.wheel_delta_precision, mouse_event.scroll_gesture_phase, true, nullptr, &remote_target);
}
- return page.handle_mousewheel(*root, mouse_event.position, mouse_event.screen_position, mouse_event.button, mouse_event.buttons, mouse_event.modifiers, mouse_event.wheel_delta_x, mouse_event.wheel_delta_y, mouse_event.wheel_delta_precision, mouse_event.scroll_gesture_phase, false, nullptr, &remote_target);
+ return page.handle_mousewheel(*root, mouse_event.position, mouse_event.screen_position, mouse_event.button, mouse_event.buttons, mouse_event.modifiers, mouse_event.wheel_delta_x, mouse_event.wheel_delta_y, mouse_event.wheel_tick_120ths_x, mouse_event.wheel_tick_120ths_y, mouse_event.wheel_delta_precision, mouse_event.scroll_gesture_phase, false, nullptr, &remote_target);
}
VERIFY_NOT_REACHED();
},
diff --git a/Libraries/LibWeb/Internals/Internals.cpp b/Libraries/LibWeb/Internals/Internals.cpp
index f471bb5160b..44857e5f06c 100644
--- a/Libraries/LibWeb/Internals/Internals.cpp
+++ b/Libraries/LibWeb/Internals/Internals.cpp
@@ -137,6 +137,14 @@ static Web::ScrollGesturePhase scroll_gesture_phase_from(Bindings::ScrollGesture
VERIFY_NOT_REACHED();
}
+static double wheel_tick_120ths_from(Optional<double> wheel_ticks, double pixel_delta, Web::WheelDeltaPrecision wheel_delta_precision)
+{
+ static constexpr double wheel_tick_120ths_per_tick = 120;
+ if (wheel_ticks.has_value())
+ return *wheel_ticks * wheel_tick_120ths_per_tick;
+ return Web::wheel_tick_120ths_from_pixel_delta(pixel_delta, wheel_delta_precision);
+}
+
GC_DEFINE_ALLOCATOR(Internals);
static GC::Ptr<HTML::LocalNavigable> local_root_of(HTML::Window const& window)
@@ -736,12 +744,14 @@ void Internals::mouse_event_through_ui_process(Bindings::MouseEventThroughUIProc
send_mouse_events_through_ui_process(move(events), promise);
}
-void Internals::wheel_through_ui_process(double x, double y, double delta_x, double delta_y, bool precise, Bindings::ScrollGesturePhase phase, GC::Ref<WebIDL::Promise> promise)
+void Internals::wheel_through_ui_process(double x, double y, double delta_x, double delta_y, bool precise, Bindings::ScrollGesturePhase phase, Bindings::WheelTicks const& ticks, GC::Ref<WebIDL::Promise> promise)
{
auto event = mouse_event_through_ui_process_at(Web::MouseEvent::Type::MouseWheel, x, y);
event.wheel_delta_x = delta_x;
event.wheel_delta_y = delta_y;
event.wheel_delta_precision = wheel_delta_precision_from(precise);
+ event.wheel_tick_120ths_x = wheel_tick_120ths_from(ticks.x, delta_x, event.wheel_delta_precision);
+ event.wheel_tick_120ths_y = wheel_tick_120ths_from(ticks.y, delta_y, event.wheel_delta_precision);
event.scroll_gesture_phase = scroll_gesture_phase_from(phase);
Vector<Web::MouseEvent> events;
events.append(move(event));
@@ -838,7 +848,7 @@ void Internals::click_and_hold(double x, double y, WebIDL::UnsignedShort click_c
page.handle_mousedown(position, position, mouse_button, 0, modifiers, click_count);
}
-void Internals::wheel(GC::Ref<WebIDL::Promise> promise, double x, double y, double delta_x, double delta_y, bool precise, Bindings::ScrollGesturePhase phase)
+void Internals::wheel(GC::Ref<WebIDL::Promise> promise, double x, double y, double delta_x, double delta_y, bool precise, Bindings::ScrollGesturePhase phase, Bindings::WheelTicks const& ticks)
{
auto& page = this->page();
@@ -846,7 +856,9 @@ void Internals::wheel(GC::Ref<WebIDL::Promise> promise, double x, double y, doub
auto scroll_gesture_phase = scroll_gesture_phase_from(phase);
auto position = page.css_to_device_point({ x, y });
Optional<AsyncScrollOperation> async_scroll_operation;
- page.handle_mousewheel(position, position, 0, 0, 0, delta_x, delta_y, wheel_delta_precision, scroll_gesture_phase, false, &async_scroll_operation);
+ auto wheel_tick_120ths_x = wheel_tick_120ths_from(ticks.x, delta_x, wheel_delta_precision);
+ auto wheel_tick_120ths_y = wheel_tick_120ths_from(ticks.y, delta_y, wheel_delta_precision);
+ page.handle_mousewheel(position, position, 0, 0, 0, delta_x, delta_y, wheel_tick_120ths_x, wheel_tick_120ths_y, wheel_delta_precision, scroll_gesture_phase, false, &async_scroll_operation);
if (async_scroll_operation.has_value() && async_scroll_operation->navigable) {
async_scroll_operation->navigable->wait_for_async_scroll_operation(async_scroll_operation->operation_id, promise);
@@ -866,9 +878,9 @@ void Internals::wheel(GC::Ref<WebIDL::Promise> promise, double x, double y, doub
WebIDL::wait_for_all(realm, scroll_promises, [resolve](auto const&) { resolve(); }, [resolve](auto) { resolve(); });
}
-void Internals::wheel(double x, double y, double delta_x, double delta_y, bool precise, Bindings::ScrollGesturePhase phase, GC::Ref<WebIDL::Promise> promise)
+void Internals::wheel(double x, double y, double delta_x, double delta_y, bool precise, Bindings::ScrollGesturePhase phase, Bindings::WheelTicks const& ticks, GC::Ref<WebIDL::Promise> promise)
{
- wheel(promise, x, y, delta_x, delta_y, precise, phase);
+ wheel(promise, x, y, delta_x, delta_y, precise, phase, ticks);
}
static JS::Value wrapped_node_with_unique_id(HTML::Window& window, Optional<UniqueNodeID> node_id)
diff --git a/Libraries/LibWeb/Internals/Internals.h b/Libraries/LibWeb/Internals/Internals.h
index 09b7ef795a9..d9a3dfe8ee8 100644
--- a/Libraries/LibWeb/Internals/Internals.h
+++ b/Libraries/LibWeb/Internals/Internals.h
@@ -96,7 +96,7 @@ public:
void grant_transient_activation();
void click_through_ui_process(double x, double y, 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, 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);
WebIDL::ExceptionOr<void> send_text_editing_command(HTML::HTMLElement&, Utf16String const& command_name, bool extend_selection);
void paste(HTML::HTMLElement& target, Utf16String const& text);
@@ -113,8 +113,8 @@ public:
// High-level mouse conveniences
void click(double x, double y, WebIDL::UnsignedShort click_count, WebIDL::UnsignedShort button, WebIDL::UnsignedShort modifiers);
void click_and_hold(double x, double y, WebIDL::UnsignedShort click_count, WebIDL::UnsignedShort button, WebIDL::UnsignedShort modifiers);
- void wheel(GC::Ref<WebIDL::Promise>, double x, double y, double delta_x, double delta_y, bool precise, Bindings::ScrollGesturePhase);
- void wheel(double x, double y, double delta_x, double delta_y, bool precise, Bindings::ScrollGesturePhase, GC::Ref<WebIDL::Promise>);
+ void wheel(GC::Ref<WebIDL::Promise>, double x, double y, double delta_x, double delta_y, bool precise, Bindings::ScrollGesturePhase, Bindings::WheelTicks const&);
+ void wheel(double x, double y, double delta_x, double delta_y, bool precise, Bindings::ScrollGesturePhase, Bindings::WheelTicks const&, GC::Ref<WebIDL::Promise>);
GC::Ref<JS::Object> compositor_scroll_state(GC::Ptr<DOM::Element> scroller);
void pinch(double x, double y, double scale_delta, WebIDL::UnsignedShort modifiers);
void reset_zoom();
diff --git a/Libraries/LibWeb/Internals/Internals.idl b/Libraries/LibWeb/Internals/Internals.idl
index 400caeaa5a9..aaecdc3ab66 100644
--- a/Libraries/LibWeb/Internals/Internals.idl
+++ b/Libraries/LibWeb/Internals/Internals.idl
@@ -73,7 +73,7 @@ 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 = {});
- [CreatesPromise] Promise<undefined> wheelThroughUIProcess(double x, double y, double deltaX, double deltaY, optional boolean precise = false, optional ScrollGesturePhase scrollGesturePhase = "none");
+ [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);
undefined paste(HTMLElement target, DOMString text);
@@ -90,7 +90,7 @@ interface Internals {
// High-level mouse conveniences
undefined click(double x, double y, optional unsigned short clickCount = 1, optional unsigned short button = 0, optional unsigned short modifiers = 0);
undefined clickAndHold(double x, double y, optional unsigned short clickCount = 1, optional unsigned short button = 0, optional unsigned short modifiers = 0);
- [CreatesPromise] Promise<undefined> wheel(double x, double y, double deltaX, double deltaY, optional boolean precise = false, optional ScrollGesturePhase scrollGesturePhase = "none");
+ [CreatesPromise] Promise<undefined> wheel(double x, double y, double deltaX, double deltaY, optional boolean precise = false, optional ScrollGesturePhase scrollGesturePhase = "none", optional WheelTicks ticks = {});
// The scrolling state the compositor has installed from the frames rendered so far, its wheel routing admission,
// and how far, in CSS pixels, it presents the scroller past the edges of its scroll range. The scroller is the
// viewport if none is given.
@@ -386,6 +386,12 @@ enum SpellingMenuItem { "none", "guess", "ignore", "learn" };
enum ScrollGesturePhase { "none", "ongoing", "momentum", "ended" };
enum MouseEventThroughUIProcessType { "mousedown", "mouseup", "mousemove", "mouseleave" };
+// How many wheel ticks a wheel step amounts to on each axis. By default, they are counted from the pixel delta.
+dictionary WheelTicks {
+ double x;
+ double y;
+};
+
dictionary MouseEventThroughUIProcessOptions {
unsigned short button = 0;
// The buttons held once the event has happened. By default, the button a mousedown presses, and none otherwise.
diff --git a/Libraries/LibWeb/Page/EventHandler.cpp b/Libraries/LibWeb/Page/EventHandler.cpp
index 52b0a738910..4d09770025c 100644
--- a/Libraries/LibWeb/Page/EventHandler.cpp
+++ b/Libraries/LibWeb/Page/EventHandler.cpp
@@ -929,7 +929,7 @@ void EventHandler::record_input_routing(InputRoutingDecision decision, Optional<
});
}
-EventResult EventHandler::handle_mousewheel(CSSPixelPoint visual_viewport_position, CSSPixelPoint screen_position, u32 button, u32 buttons, u32 modifiers, double wheel_delta_x, double wheel_delta_y, Web::WheelDeltaPrecision wheel_delta_precision, Web::ScrollGesturePhase scroll_gesture_phase, bool async_scroll_performed_default_action, Optional<AsyncScrollOperation>* async_scroll_operation, Optional<RemoteInputEventTarget>* remote_target)
+EventResult EventHandler::handle_mousewheel(CSSPixelPoint visual_viewport_position, CSSPixelPoint screen_position, u32 button, u32 buttons, u32 modifiers, double wheel_delta_x, double wheel_delta_y, double wheel_tick_120ths_x, double wheel_tick_120ths_y, Web::WheelDeltaPrecision wheel_delta_precision, Web::ScrollGesturePhase scroll_gesture_phase, bool async_scroll_performed_default_action, Optional<AsyncScrollOperation>* async_scroll_operation, Optional<RemoteInputEventTarget>* remote_target)
{
record_last_known_mouse_position(visual_viewport_position, screen_position, buttons, modifiers);
@@ -1018,8 +1018,10 @@ EventResult EventHandler::handle_mousewheel(CSSPixelPoint visual_viewport_positi
if (!has_committed_root_box())
return EventResult::Dropped;
- if (modifiers & UIEvents::KeyModifier::Mod_Shift)
+ if (modifiers & UIEvents::KeyModifier::Mod_Shift) {
swap(wheel_delta_x, wheel_delta_y);
+ swap(wheel_tick_120ths_x, wheel_tick_120ths_y);
+ }
Optional<Target> hit_test_target;
GC::Ptr<DOM::Node> wheel_event_target_node;
@@ -1217,8 +1219,8 @@ EventResult EventHandler::handle_mousewheel(CSSPixelPoint visual_viewport_positi
// A gesture this navigable latched to a scrolling box of its own is not offered to a nested navigable again.
bool offer_to_nested_navigable = !continues_latched_gesture || m_wheel_scroll_latch->gesture_handed_to_nested_navigable;
if (offer_to_nested_navigable) {
- if (auto result = dispatch_event_to_nested_navigable(*this, *wheel_event_target_layout_node, wheel_event_target_node, visual_viewport_position, remote_target, [screen_position, button, buttons, modifiers, wheel_delta_x, wheel_delta_y, wheel_delta_precision, scroll_gesture_phase, async_scroll_performed_default_action, async_scroll_operation, remote_target](EventHandler& event_handler, CSSPixelPoint position) -> EventResult {
- return event_handler.handle_mousewheel(position, screen_position, button, buttons, modifiers, wheel_delta_x, wheel_delta_y, wheel_delta_precision, scroll_gesture_phase, async_scroll_performed_default_action, async_scroll_operation, remote_target);
+ if (auto result = dispatch_event_to_nested_navigable(*this, *wheel_event_target_layout_node, wheel_event_target_node, visual_viewport_position, remote_target, [screen_position, button, buttons, modifiers, wheel_delta_x, wheel_delta_y, wheel_tick_120ths_x, wheel_tick_120ths_y, wheel_delta_precision, scroll_gesture_phase, async_scroll_performed_default_action, async_scroll_operation, remote_target](EventHandler& event_handler, CSSPixelPoint position) -> EventResult {
+ return event_handler.handle_mousewheel(position, screen_position, button, buttons, modifiers, wheel_delta_x, wheel_delta_y, wheel_tick_120ths_x, wheel_tick_120ths_y, wheel_delta_precision, scroll_gesture_phase, async_scroll_performed_default_action, async_scroll_operation, remote_target);
});
result.has_value()) {
record_input_routing(InputRoutingDecision::HandedToNestedNavigable, {}, wheel_event_target_node);
@@ -1244,7 +1246,7 @@ EventResult EventHandler::handle_mousewheel(CSSPixelPoint visual_viewport_positi
}
auto is_cancelable = async_scroll_performed_default_action ? UIEvents::WheelEventIsCancelable::No : UIEvents::WheelEventIsCancelable::Yes;
- auto dispatch_result = dispatch_wheel_event(read, *wheel_event_target_layout_node, visual_viewport_position, screen_position, button, buttons, modifiers, wheel_delta_x, wheel_delta_y, wheel_delta_precision, is_cancelable == UIEvents::WheelEventIsCancelable::Yes);
+ auto dispatch_result = dispatch_wheel_event(read, *wheel_event_target_layout_node, visual_viewport_position, screen_position, button, buttons, modifiers, wheel_delta_x, wheel_delta_y, wheel_tick_120ths_x, wheel_tick_120ths_y, is_cancelable == UIEvents::WheelEventIsCancelable::Yes);
if (dispatch_result == EventResult::Accepted)
record_input_routing(InputRoutingDecision::DispatchedWheelEvent, {}, wheel_event_target_node);
else if (dispatch_result == EventResult::Cancelled)
@@ -1270,7 +1272,7 @@ EventResult EventHandler::handle_mousewheel(CSSPixelPoint visual_viewport_positi
return handled_event;
}
-EventResult EventHandler::dispatch_wheel_event(Layout::BegunRead const& read, Layout::Node& hit_layout_node, CSSPixelPoint visual_viewport_position, CSSPixelPoint screen_position, u32 button, u32 buttons, u32 modifiers, double wheel_delta_x, double wheel_delta_y, Web::WheelDeltaPrecision wheel_delta_precision, bool is_cancelable)
+EventResult EventHandler::dispatch_wheel_event(Layout::BegunRead const& read, Layout::Node& hit_layout_node, CSSPixelPoint visual_viewport_position, CSSPixelPoint screen_position, u32 button, u32 buttons, u32 modifiers, double wheel_delta_x, double wheel_delta_y, double wheel_tick_120ths_x, double wheel_tick_120ths_y, bool is_cancelable)
{
auto document = m_navigable->active_document();
if (!document || !document->is_fully_active())
@@ -1293,7 +1295,7 @@ EventResult EventHandler::dispatch_wheel_event(Layout::BegunRead const& read, La
auto scroll_offset = document->navigable()->viewport_scroll_offset();
auto offset = compute_mouse_event_offset(visual_viewport_position.translated(scroll_offset), *offset_layout_node);
auto cancelability = is_cancelable ? UIEvents::WheelEventIsCancelable::Yes : UIEvents::WheelEventIsCancelable::No;
- auto event = UIEvents::WheelEvent::create_from_platform_event(HTML::relevant_global_object(*node), m_navigable->active_window_proxy(), UIEvents::EventNames::wheel, screen_position, page_offset, viewport_position, offset, wheel_delta_x, wheel_delta_y, wheel_delta_precision, button, buttons, modifiers, cancelability).release_value_but_fixme_should_propagate_errors();
+ auto event = UIEvents::WheelEvent::create_from_platform_event(HTML::relevant_global_object(*node), m_navigable->active_window_proxy(), UIEvents::EventNames::wheel, screen_position, page_offset, viewport_position, offset, wheel_delta_x, wheel_delta_y, wheel_tick_120ths_x, wheel_tick_120ths_y, button, buttons, modifiers, cancelability).release_value_but_fixme_should_propagate_errors();
return node->dispatch_event(event) ? EventResult::Accepted : EventResult::Cancelled;
}
@@ -1330,7 +1332,7 @@ EventResult EventHandler::dispatch_synthetic_pinch_wheel_event(CSSPixelPoint vis
}
modifiers |= UIEvents::KeyModifier::Mod_Ctrl;
- return dispatch_wheel_event(read, *target_layout_node, visual_viewport_position, screen_position, UIEvents::MouseButton::None, UIEvents::MouseButton::None, modifiers, 0, wheel_delta_y, Web::WheelDeltaPrecision::Precise, true);
+ return dispatch_wheel_event(read, *target_layout_node, visual_viewport_position, screen_position, UIEvents::MouseButton::None, UIEvents::MouseButton::None, modifiers, 0, wheel_delta_y, 0, Web::wheel_tick_120ths_from_pixel_delta(wheel_delta_y, Web::WheelDeltaPrecision::Precise), true);
}
EventResult EventHandler::handle_mouseleave()
diff --git a/Libraries/LibWeb/Page/EventHandler.h b/Libraries/LibWeb/Page/EventHandler.h
index fc1badff550..f2586eaca5c 100644
--- a/Libraries/LibWeb/Page/EventHandler.h
+++ b/Libraries/LibWeb/Page/EventHandler.h
@@ -68,7 +68,7 @@ public:
bool handling_outdated_input() const { return m_handling_outdated_input; }
u64 handling_input_event_id() const { return m_handling_input_event_id; }
EventResult handle_mouseup(CSSPixelPoint, CSSPixelPoint screen_position, unsigned button, unsigned buttons, unsigned modifiers, Optional<RemoteInputEventTarget>* remote_target = nullptr);
- EventResult handle_mousewheel(CSSPixelPoint, CSSPixelPoint screen_position, unsigned button, unsigned buttons, unsigned modifiers, double wheel_delta_x, double wheel_delta_y, Web::WheelDeltaPrecision = Web::WheelDeltaPrecision::Discrete, Web::ScrollGesturePhase = Web::ScrollGesturePhase::None, bool async_scroll_performed_default_action = false, Optional<AsyncScrollOperation>* async_scroll_operation = nullptr, Optional<RemoteInputEventTarget>* remote_target = nullptr);
+ EventResult handle_mousewheel(CSSPixelPoint, CSSPixelPoint screen_position, unsigned button, unsigned buttons, unsigned modifiers, double wheel_delta_x, double wheel_delta_y, double wheel_tick_120ths_x, double wheel_tick_120ths_y, Web::WheelDeltaPrecision = Web::WheelDeltaPrecision::Discrete, Web::ScrollGesturePhase = Web::ScrollGesturePhase::None, bool async_scroll_performed_default_action = false, Optional<AsyncScrollOperation>* async_scroll_operation = nullptr, Optional<RemoteInputEventTarget>* remote_target = nullptr);
EventResult handle_mouseleave();
EventResult handle_mousecancel();
EventResult insert_replacement_text(Utf16String const&);
@@ -193,7 +193,7 @@ private:
void stop_updating_selection();
void update_hover_after_scroll(CSSPixelPoint visual_viewport_position, CSSPixelPoint screen_position, unsigned button, unsigned buttons, unsigned modifiers, GC::Ptr<DOM::Node> hover_target = {});
- EventResult dispatch_wheel_event(Layout::BegunRead const& read, Layout::Node&, CSSPixelPoint visual_viewport_position, CSSPixelPoint screen_position, unsigned button, unsigned buttons, unsigned modifiers, double wheel_delta_x, double wheel_delta_y, Web::WheelDeltaPrecision, bool is_cancelable);
+ EventResult dispatch_wheel_event(Layout::BegunRead const& read, Layout::Node&, CSSPixelPoint visual_viewport_position, CSSPixelPoint screen_position, unsigned button, unsigned buttons, unsigned modifiers, double wheel_delta_x, double wheel_delta_y, double wheel_tick_120ths_x, double wheel_tick_120ths_y, bool is_cancelable);
// Both drop the latch when what it refers to is gone from the document, so that the event is targeted afresh.
Layout::Node* validated_wheel_scroll_latch_target_layout_node(Layout::BegunRead const& read, DOM::Document&);
Layout::Node* validated_latched_wheel_scrolling_box();
diff --git a/Libraries/LibWeb/Page/Page.cpp b/Libraries/LibWeb/Page/Page.cpp
index 73464a1957e..cfaa02193d7 100644
--- a/Libraries/LibWeb/Page/Page.cpp
+++ b/Libraries/LibWeb/Page/Page.cpp
@@ -521,14 +521,14 @@ UniqueNodeID Page::node_id_at_position(DevicePixelPoint position)
return node->unique_id();
}
-EventResult Page::handle_mousewheel(HTML::LocalNavigable& root, DevicePixelPoint position, DevicePixelPoint screen_position, unsigned button, unsigned buttons, unsigned modifiers, double wheel_delta_x, double wheel_delta_y, Web::WheelDeltaPrecision wheel_delta_precision, Web::ScrollGesturePhase scroll_gesture_phase, bool async_scroll_performed_default_action, Optional<AsyncScrollOperation>* async_scroll_operation, Optional<RemoteInputEventTarget>* remote_target)
+EventResult Page::handle_mousewheel(HTML::LocalNavigable& root, DevicePixelPoint position, DevicePixelPoint screen_position, unsigned button, unsigned buttons, unsigned modifiers, double wheel_delta_x, double wheel_delta_y, double wheel_tick_120ths_x, double wheel_tick_120ths_y, Web::WheelDeltaPrecision wheel_delta_precision, Web::ScrollGesturePhase scroll_gesture_phase, bool async_scroll_performed_default_action, Optional<AsyncScrollOperation>* async_scroll_operation, Optional<RemoteInputEventTarget>* remote_target)
{
- return root.event_handler().handle_mousewheel(device_to_css_point(position), device_to_css_point(screen_position), button, buttons, modifiers, wheel_delta_x, wheel_delta_y, wheel_delta_precision, scroll_gesture_phase, async_scroll_performed_default_action, async_scroll_operation, remote_target);
+ return root.event_handler().handle_mousewheel(device_to_css_point(position), device_to_css_point(screen_position), button, buttons, modifiers, wheel_delta_x, wheel_delta_y, wheel_tick_120ths_x, wheel_tick_120ths_y, wheel_delta_precision, scroll_gesture_phase, async_scroll_performed_default_action, async_scroll_operation, remote_target);
}
-EventResult Page::handle_mousewheel(DevicePixelPoint position, DevicePixelPoint screen_position, unsigned button, unsigned buttons, unsigned modifiers, double wheel_delta_x, double wheel_delta_y, Web::WheelDeltaPrecision wheel_delta_precision, Web::ScrollGesturePhase scroll_gesture_phase, bool async_scroll_performed_default_action, Optional<AsyncScrollOperation>* async_scroll_operation)
+EventResult Page::handle_mousewheel(DevicePixelPoint position, DevicePixelPoint screen_position, unsigned button, unsigned buttons, unsigned modifiers, double wheel_delta_x, double wheel_delta_y, double wheel_tick_120ths_x, double wheel_tick_120ths_y, Web::WheelDeltaPrecision wheel_delta_precision, Web::ScrollGesturePhase scroll_gesture_phase, bool async_scroll_performed_default_action, Optional<AsyncScrollOperation>* async_scroll_operation)
{
- return handle_mousewheel(local_traversable(), position, screen_position, button, buttons, modifiers, wheel_delta_x, wheel_delta_y, wheel_delta_precision, scroll_gesture_phase, async_scroll_performed_default_action, async_scroll_operation, nullptr);
+ return handle_mousewheel(local_traversable(), position, screen_position, button, buttons, modifiers, wheel_delta_x, wheel_delta_y, wheel_tick_120ths_x, wheel_tick_120ths_y, wheel_delta_precision, scroll_gesture_phase, async_scroll_performed_default_action, async_scroll_operation, nullptr);
}
EventResult Page::handle_drag_and_drop_event(HTML::LocalNavigable& root, DragEvent::Type type, DevicePixelPoint position, DevicePixelPoint screen_position, unsigned button, unsigned buttons, unsigned modifiers, Vector<HTML::SelectedFile> files)
diff --git a/Libraries/LibWeb/Page/Page.h b/Libraries/LibWeb/Page/Page.h
index fbb5525290b..5bf1a864864 100644
--- a/Libraries/LibWeb/Page/Page.h
+++ b/Libraries/LibWeb/Page/Page.h
@@ -194,7 +194,7 @@ public:
EventResult handle_mousemove(HTML::LocalNavigable& root, DevicePixelPoint, DevicePixelPoint screen_position, unsigned buttons, unsigned modifiers, Optional<RemoteInputEventTarget>* remote_target);
EventResult handle_mouseleave(HTML::LocalNavigable& root);
EventResult handle_mousecancel(HTML::LocalNavigable& root);
- EventResult handle_mousewheel(HTML::LocalNavigable& root, DevicePixelPoint, DevicePixelPoint screen_position, unsigned button, unsigned buttons, unsigned modifiers, double wheel_delta_x, double wheel_delta_y, Web::WheelDeltaPrecision, Web::ScrollGesturePhase, bool async_scroll_performed_default_action, Optional<AsyncScrollOperation>* async_scroll_operation, Optional<RemoteInputEventTarget>* remote_target);
+ EventResult handle_mousewheel(HTML::LocalNavigable& root, DevicePixelPoint, DevicePixelPoint screen_position, unsigned button, unsigned buttons, unsigned modifiers, double wheel_delta_x, double wheel_delta_y, double wheel_tick_120ths_x, double wheel_tick_120ths_y, Web::WheelDeltaPrecision, Web::ScrollGesturePhase, bool async_scroll_performed_default_action, Optional<AsyncScrollOperation>* async_scroll_operation, Optional<RemoteInputEventTarget>* remote_target);
EventResult handle_drag_and_drop_event(HTML::LocalNavigable& root, DragEvent::Type, DevicePixelPoint, DevicePixelPoint screen_position, unsigned button, unsigned buttons, unsigned modifiers, Vector<HTML::SelectedFile> files);
EventResult handle_pinch_event(HTML::LocalNavigable& root, DevicePixelPoint point, unsigned modifiers, double scale);
@@ -208,7 +208,7 @@ public:
bool select_word_for_dictionary_lookup(DevicePixelPoint);
#endif
UniqueNodeID node_id_at_position(DevicePixelPoint);
- EventResult handle_mousewheel(DevicePixelPoint, DevicePixelPoint screen_position, unsigned button, unsigned buttons, unsigned modifiers, double wheel_delta_x, double wheel_delta_y, Web::WheelDeltaPrecision = Web::WheelDeltaPrecision::Discrete, Web::ScrollGesturePhase = Web::ScrollGesturePhase::None, bool async_scroll_performed_default_action = false, Optional<AsyncScrollOperation>* async_scroll_operation = nullptr);
+ EventResult handle_mousewheel(DevicePixelPoint, DevicePixelPoint screen_position, unsigned button, unsigned buttons, unsigned modifiers, double wheel_delta_x, double wheel_delta_y, double wheel_tick_120ths_x, double wheel_tick_120ths_y, Web::WheelDeltaPrecision = Web::WheelDeltaPrecision::Discrete, Web::ScrollGesturePhase = Web::ScrollGesturePhase::None, bool async_scroll_performed_default_action = false, Optional<AsyncScrollOperation>* async_scroll_operation = nullptr);
EventResult handle_drag_and_drop_event(DragEvent::Type, DevicePixelPoint, DevicePixelPoint screen_position, unsigned button, unsigned buttons, unsigned modifiers, Vector<HTML::SelectedFile> files);
EventResult handle_pinch_event(DevicePixelPoint point, unsigned modifiers, double scale);
diff --git a/Libraries/LibWeb/UIEvents/WheelEvent.cpp b/Libraries/LibWeb/UIEvents/WheelEvent.cpp
index 76f09981ee5..99b7d228a25 100644
--- a/Libraries/LibWeb/UIEvents/WheelEvent.cpp
+++ b/Libraries/LibWeb/UIEvents/WheelEvent.cpp
@@ -13,7 +13,6 @@
#include <LibWeb/UIEvents/EventNames.h>
#include <LibWeb/UIEvents/WheelEvent.h>
#include <LibWeb/WebIDL/ExceptionOr.h>
-#include <LibWebCommon/Page/InputEvent.h>
#include <LibWebCommon/UIEvents/KeyCode.h>
namespace Web::UIEvents {
@@ -25,18 +24,9 @@ static WebIDL::Long legacy_wheel_delta_from_delta(double delta)
return AK::clamp_to<WebIDL::Long>(-delta);
}
-// Legacy wheelDelta counts 120 units per wheel notch. Discrete input keeps one unit per pixel, as the UI scrolls a
-// notch by three 40-pixel lines. Precise input has no notches, so it counts one notch per 40-pixel line step.
-// INTEROP: For macOS touchpad scrolling, Blink, WebKit, and Gecko all report 3 units per pixel; Blink and WebKit
-// truncate, Gecko rounds. For the ctrl-wheel events of a pinch, WebKit and Gecko also report 3 units per
-// pixel, while Blink reports 120 units per event.
-static WebIDL::Long legacy_wheel_delta_from_platform_delta(double delta, WheelDeltaPrecision delta_precision)
+static WebIDL::Long legacy_wheel_delta_from_wheel_tick_120ths(double wheel_tick_120ths)
{
- static constexpr double legacy_wheel_delta_units_per_notch = 120;
- static constexpr double precise_delta_pixels_per_notch = 40;
- if (delta_precision == WheelDeltaPrecision::Precise)
- delta *= legacy_wheel_delta_units_per_notch / precise_delta_pixels_per_notch;
- return legacy_wheel_delta_from_delta(AK::trunc(delta));
+ return legacy_wheel_delta_from_delta(AK::trunc(wheel_tick_120ths));
}
WheelEvent::WheelEvent(FlyString const& event_name, WheelEventOptions const& options, double page_x, double page_y, double offset_x, double offset_y, HighResolutionTime::DOMHighResTimeStamp time_stamp)
@@ -99,7 +89,7 @@ GC::Ref<WheelEvent> WheelEvent::create_for_constructor(Utf16String const& event_
return create(Utf16FlyString::from_utf16(event_name.utf16_view()), options, event_init.client_x, event_init.client_y, event_init.client_x, event_init.client_y, time_stamp);
}
-WebIDL::ExceptionOr<GC::Ref<WheelEvent>> WheelEvent::create_from_platform_event(JS::Object const& relevant_global_object, GC::Ptr<HTML::WindowProxy> window_proxy, FlyString const& event_name, CSSPixelPoint screen, CSSPixelPoint page, CSSPixelPoint client, CSSPixelPoint offset, double delta_x, double delta_y, WheelDeltaPrecision delta_precision, unsigned button, unsigned buttons, unsigned modifiers, WheelEventIsCancelable is_cancelable)
+WebIDL::ExceptionOr<GC::Ref<WheelEvent>> WheelEvent::create_from_platform_event(JS::Object const& relevant_global_object, GC::Ptr<HTML::WindowProxy> window_proxy, FlyString const& event_name, CSSPixelPoint screen, CSSPixelPoint page, CSSPixelPoint client, CSSPixelPoint offset, double delta_x, double delta_y, double wheel_tick_120ths_x, double wheel_tick_120ths_y, unsigned button, unsigned buttons, unsigned modifiers, WheelEventIsCancelable is_cancelable)
{
WheelEventOptions event_options;
event_options.ctrl_key = modifiers & Mod_Ctrl;
@@ -115,8 +105,8 @@ WebIDL::ExceptionOr<GC::Ref<WheelEvent>> WheelEvent::create_from_platform_event(
event_options.delta_x = delta_x;
event_options.delta_y = delta_y;
event_options.delta_mode = WheelDeltaMode::DOM_DELTA_PIXEL;
- event_options.wheel_delta_x = legacy_wheel_delta_from_platform_delta(delta_x, delta_precision);
- event_options.wheel_delta_y = legacy_wheel_delta_from_platform_delta(delta_y, delta_precision);
+ event_options.wheel_delta_x = legacy_wheel_delta_from_wheel_tick_120ths(wheel_tick_120ths_x);
+ event_options.wheel_delta_y = legacy_wheel_delta_from_wheel_tick_120ths(wheel_tick_120ths_y);
event_options.view = window_proxy;
auto event = WheelEvent::create(event_name, event_options, page.x().to_double(), page.y().to_double(), offset.x().to_double(), offset.y().to_double(), HighResolutionTime::current_high_resolution_time(relevant_global_object));
event->set_is_trusted(true);
@@ -126,7 +116,7 @@ WebIDL::ExceptionOr<GC::Ref<WheelEvent>> WheelEvent::create_from_platform_event(
return event;
}
-WebIDL::ExceptionOr<GC::Ref<WheelEvent>> WheelEvent::create_from_platform_event(JS::Object const& relevant_global_object, GC::Ptr<HTML::WindowProxy> window_proxy, Utf16FlyString const& event_name, CSSPixelPoint screen, CSSPixelPoint page, CSSPixelPoint client, CSSPixelPoint offset, double delta_x, double delta_y, WheelDeltaPrecision delta_precision, unsigned button, unsigned buttons, unsigned modifiers, WheelEventIsCancelable is_cancelable)
+WebIDL::ExceptionOr<GC::Ref<WheelEvent>> WheelEvent::create_from_platform_event(JS::Object const& relevant_global_object, GC::Ptr<HTML::WindowProxy> window_proxy, Utf16FlyString const& event_name, CSSPixelPoint screen, CSSPixelPoint page, CSSPixelPoint client, CSSPixelPoint offset, double delta_x, double delta_y, double wheel_tick_120ths_x, double wheel_tick_120ths_y, unsigned button, unsigned buttons, unsigned modifiers, WheelEventIsCancelable is_cancelable)
{
WheelEventOptions event_options;
event_options.ctrl_key = modifiers & Mod_Ctrl;
@@ -142,8 +132,8 @@ WebIDL::ExceptionOr<GC::Ref<WheelEvent>> WheelEvent::create_from_platform_event(
event_options.delta_x = delta_x;
event_options.delta_y = delta_y;
event_options.delta_mode = WheelDeltaMode::DOM_DELTA_PIXEL;
- event_options.wheel_delta_x = legacy_wheel_delta_from_platform_delta(delta_x, delta_precision);
- event_options.wheel_delta_y = legacy_wheel_delta_from_platform_delta(delta_y, delta_precision);
+ event_options.wheel_delta_x = legacy_wheel_delta_from_wheel_tick_120ths(wheel_tick_120ths_x);
+ event_options.wheel_delta_y = legacy_wheel_delta_from_wheel_tick_120ths(wheel_tick_120ths_y);
event_options.view = window_proxy;
auto event = WheelEvent::create(event_name, event_options, page.x().to_double(), page.y().to_double(), offset.x().to_double(), offset.y().to_double(), HighResolutionTime::current_high_resolution_time(relevant_global_object));
event->set_is_trusted(true);
diff --git a/Libraries/LibWeb/UIEvents/WheelEvent.h b/Libraries/LibWeb/UIEvents/WheelEvent.h
index 78374a234f8..22c4ad9b667 100644
--- a/Libraries/LibWeb/UIEvents/WheelEvent.h
+++ b/Libraries/LibWeb/UIEvents/WheelEvent.h
@@ -51,8 +51,8 @@ public:
[[nodiscard]] static GC::Ref<WheelEvent> create_for_constructor(FlyString const&, Bindings::WheelEventInit const&, HighResolutionTime::DOMHighResTimeStamp);
[[nodiscard]] static GC::Ref<WheelEvent> create_for_constructor(Utf16String const&, Bindings::WheelEventInit const&, HighResolutionTime::DOMHighResTimeStamp);
- static WebIDL::ExceptionOr<GC::Ref<WheelEvent>> create_from_platform_event(JS::Object const& relevant_global_object, GC::Ptr<HTML::WindowProxy>, FlyString const& event_name, CSSPixelPoint screen, CSSPixelPoint page, CSSPixelPoint client, CSSPixelPoint offset, double delta_x, double delta_y, WheelDeltaPrecision, unsigned button, unsigned buttons, unsigned modifiers, WheelEventIsCancelable = WheelEventIsCancelable::Yes);
- static WebIDL::ExceptionOr<GC::Ref<WheelEvent>> create_from_platform_event(JS::Object const& relevant_global_object, GC::Ptr<HTML::WindowProxy>, Utf16FlyString const& event_name, CSSPixelPoint screen, CSSPixelPoint page, CSSPixelPoint client, CSSPixelPoint offset, double delta_x, double delta_y, WheelDeltaPrecision, unsigned button, unsigned buttons, unsigned modifiers, WheelEventIsCancelable = WheelEventIsCancelable::Yes);
+ static WebIDL::ExceptionOr<GC::Ref<WheelEvent>> create_from_platform_event(JS::Object const& relevant_global_object, GC::Ptr<HTML::WindowProxy>, FlyString const& event_name, CSSPixelPoint screen, CSSPixelPoint page, CSSPixelPoint client, CSSPixelPoint offset, double delta_x, double delta_y, double wheel_tick_120ths_x, double wheel_tick_120ths_y, unsigned button, unsigned buttons, unsigned modifiers, WheelEventIsCancelable = WheelEventIsCancelable::Yes);
+ static WebIDL::ExceptionOr<GC::Ref<WheelEvent>> create_from_platform_event(JS::Object const& relevant_global_object, GC::Ptr<HTML::WindowProxy>, Utf16FlyString const& event_name, CSSPixelPoint screen, CSSPixelPoint page, CSSPixelPoint client, CSSPixelPoint offset, double delta_x, double delta_y, double wheel_tick_120ths_x, double wheel_tick_120ths_y, unsigned button, unsigned buttons, unsigned modifiers, WheelEventIsCancelable = WheelEventIsCancelable::Yes);
virtual ~WheelEvent() override;
diff --git a/Libraries/LibWeb/WebDriver/Actions.cpp b/Libraries/LibWeb/WebDriver/Actions.cpp
index 2394f91ff7e..6a70877fb0a 100644
--- a/Libraries/LibWeb/WebDriver/Actions.cpp
+++ b/Libraries/LibWeb/WebDriver/Actions.cpp
@@ -1390,6 +1390,8 @@ static ErrorOr<void, WebDriver::Error> dispatch_scroll_action(ActionObject::Scro
event.wheel_delta_x = static_cast<double>(action_object.delta_x);
event.wheel_delta_y = static_cast<double>(action_object.delta_y);
event.wheel_delta_precision = Web::WheelDeltaPrecision::Discrete;
+ event.wheel_tick_120ths_x = Web::wheel_tick_120ths_from_pixel_delta(event.wheel_delta_x, event.wheel_delta_precision);
+ event.wheel_tick_120ths_y = Web::wheel_tick_120ths_from_pixel_delta(event.wheel_delta_y, event.wheel_delta_precision);
dispatch_mouse_event(move(event));
// 12. Return success with data null.
diff --git a/Libraries/LibWebCommon/Page/InputEvent.cpp b/Libraries/LibWebCommon/Page/InputEvent.cpp
index 06573016bdb..f97ee8910cb 100644
--- a/Libraries/LibWebCommon/Page/InputEvent.cpp
+++ b/Libraries/LibWebCommon/Page/InputEvent.cpp
@@ -18,7 +18,7 @@ KeyEvent KeyEvent::clone_without_browser_data() const
MouseEvent MouseEvent::clone_without_browser_data() const
{
- return { type, position, screen_position, button, buttons, modifiers, wheel_delta_x, wheel_delta_y, wheel_delta_precision, scroll_gesture_phase, click_count, nullptr, async_scroll_performed_default_action, id, scrollbar_dragged_by_compositor };
+ return { type, position, screen_position, button, buttons, modifiers, wheel_delta_x, wheel_delta_y, wheel_tick_120ths_x, wheel_tick_120ths_y, wheel_delta_precision, scroll_gesture_phase, click_count, nullptr, async_scroll_performed_default_action, id, scrollbar_dragged_by_compositor };
}
}
@@ -85,6 +85,8 @@ ErrorOr<void> IPC::encode(Encoder& encoder, Web::MouseEvent const& event)
TRY(encoder.encode(event.modifiers));
TRY(encoder.encode(event.wheel_delta_x));
TRY(encoder.encode(event.wheel_delta_y));
+ TRY(encoder.encode(event.wheel_tick_120ths_x));
+ TRY(encoder.encode(event.wheel_tick_120ths_y));
TRY(encoder.encode(event.wheel_delta_precision));
TRY(encoder.encode(event.scroll_gesture_phase));
TRY(encoder.encode(event.click_count));
@@ -105,6 +107,8 @@ ErrorOr<Web::MouseEvent> IPC::decode(Decoder& decoder)
auto modifiers = TRY(decoder.decode<Web::UIEvents::KeyModifier>());
auto wheel_delta_x = TRY(decoder.decode<double>());
auto wheel_delta_y = TRY(decoder.decode<double>());
+ auto wheel_tick_120ths_x = TRY(decoder.decode<double>());
+ auto wheel_tick_120ths_y = TRY(decoder.decode<double>());
auto wheel_delta_precision = TRY(decoder.decode<Web::WheelDeltaPrecision>());
auto scroll_gesture_phase = TRY(decoder.decode<Web::ScrollGesturePhase>());
auto click_count = TRY(decoder.decode<int>());
@@ -112,7 +116,7 @@ ErrorOr<Web::MouseEvent> IPC::decode(Decoder& decoder)
auto id = TRY(decoder.decode<u64>());
auto scrollbar_dragged_by_compositor = TRY(decoder.decode<Optional<Web::ScrollbarDraggedByCompositor>>());
- return Web::MouseEvent { type, position, screen_position, button, buttons, modifiers, wheel_delta_x, wheel_delta_y, wheel_delta_precision, scroll_gesture_phase, click_count, nullptr, async_scroll_performed_default_action, id, scrollbar_dragged_by_compositor };
+ return Web::MouseEvent { type, position, screen_position, button, buttons, modifiers, wheel_delta_x, wheel_delta_y, wheel_tick_120ths_x, wheel_tick_120ths_y, wheel_delta_precision, scroll_gesture_phase, click_count, nullptr, async_scroll_performed_default_action, id, scrollbar_dragged_by_compositor };
}
template<>
diff --git a/Libraries/LibWebCommon/Page/InputEvent.h b/Libraries/LibWebCommon/Page/InputEvent.h
index 659602d5488..cad280522b1 100644
--- a/Libraries/LibWebCommon/Page/InputEvent.h
+++ b/Libraries/LibWebCommon/Page/InputEvent.h
@@ -77,6 +77,23 @@ enum class WheelDeltaPrecision : u8 {
Precise,
};
+// Besides its pixel delta, wheel input counts how far the wheel turned in 120ths of a tick, the unit of the legacy
+// wheelDelta. A tick is a wheel notch, or one line on platforms that accelerate the wheel by whole lines. Input that
+// reports only a pixel delta counts its ticks from that: a notch scrolls three 40-pixel lines, and precise input has
+// no notches, so it counts one tick per 40-pixel line step.
+// INTEROP: For macOS touchpad scrolling, Blink, WebKit, and Gecko all report 3 units per pixel; Blink and WebKit
+// truncate, Gecko rounds. For the ctrl-wheel events of a pinch, WebKit and Gecko also report 3 units per
+// pixel, while Blink reports 120 units per event.
+constexpr double wheel_tick_120ths_from_pixel_delta(double pixel_delta, WheelDeltaPrecision precision)
+{
+ constexpr double tick_120ths_per_tick = 120;
+ constexpr double pixels_per_notch = 3 * 40;
+ constexpr double pixels_per_precise_tick = 40;
+ if (precision == WheelDeltaPrecision::Precise)
+ return pixel_delta * (tick_120ths_per_tick / pixels_per_precise_tick);
+ return pixel_delta * (tick_120ths_per_tick / pixels_per_notch);
+}
+
// Input that scrolls with a gesture, such as a touchpad, reports whether the user is still making that gesture,
// whether a flick has handed the scrolling over to momentum, and when it ends.
enum class ScrollGesturePhase : u8 {
@@ -106,6 +123,8 @@ struct WEBCOMMON_API MouseEvent {
Web::UIEvents::KeyModifier modifiers { Web::UIEvents::KeyModifier::Mod_None };
double wheel_delta_x { 0 };
double wheel_delta_y { 0 };
+ double wheel_tick_120ths_x { 0 };
+ double wheel_tick_120ths_y { 0 };
WheelDeltaPrecision wheel_delta_precision { WheelDeltaPrecision::Discrete };
ScrollGesturePhase scroll_gesture_phase { ScrollGesturePhase::None };
int click_count { 0 };
diff --git a/Libraries/LibWebView/ViewImplementation.cpp b/Libraries/LibWebView/ViewImplementation.cpp
index c2f7806e1ea..08fa00065c2 100644
--- a/Libraries/LibWebView/ViewImplementation.cpp
+++ b/Libraries/LibWebView/ViewImplementation.cpp
@@ -722,6 +722,8 @@ void ViewImplementation::enqueue_input_event(Web::InputEvent event)
if (mouse_event && mouse_event->type == Web::MouseEvent::Type::MouseWheel) {
mouse_event->wheel_delta_x /= zoom_level();
mouse_event->wheel_delta_y /= zoom_level();
+ mouse_event->wheel_tick_120ths_x /= zoom_level();
+ mouse_event->wheel_tick_120ths_y /= zoom_level();
}
if (key_event && !key_event->native_editing_binding_resolved && Web::is_keyboard_scroll_key(key_event->key, Web::UIEvents::Mod_None)) {
diff --git a/Services/Compositor/ScrollFlingController.cpp b/Services/Compositor/ScrollFlingController.cpp
index ac78ba8e218..b5e318e706a 100644
--- a/Services/Compositor/ScrollFlingController.cpp
+++ b/Services/Compositor/ScrollFlingController.cpp
@@ -98,6 +98,8 @@ Web::MouseEvent ScrollFlingController::event_of_active_fling(Gfx::FloatPoint del
.modifiers = m_active_fling->modifiers,
.wheel_delta_x = delta.x(),
.wheel_delta_y = delta.y(),
+ .wheel_tick_120ths_x = Web::wheel_tick_120ths_from_pixel_delta(delta.x(), Web::WheelDeltaPrecision::Precise),
+ .wheel_tick_120ths_y = Web::wheel_tick_120ths_from_pixel_delta(delta.y(), Web::WheelDeltaPrecision::Precise),
.wheel_delta_precision = Web::WheelDeltaPrecision::Precise,
.scroll_gesture_phase = phase,
.click_count = 0,
diff --git a/Services/WebContent/ConnectionFromClient.cpp b/Services/WebContent/ConnectionFromClient.cpp
index 3f7d1cb011d..341971f15dd 100644
--- a/Services/WebContent/ConnectionFromClient.cpp
+++ b/Services/WebContent/ConnectionFromClient.cpp
@@ -889,6 +889,8 @@ void ConnectionFromClient::enqueue_mouse_event(Web::PageId page_id, Optional<Web
if (auto const* last_mouse_event = event_to_coalesce()) {
event.wheel_delta_x += last_mouse_event->wheel_delta_x;
event.wheel_delta_y += last_mouse_event->wheel_delta_y;
+ event.wheel_tick_120ths_x += last_mouse_event->wheel_tick_120ths_x;
+ event.wheel_tick_120ths_y += last_mouse_event->wheel_tick_120ths_y;
auto coalesced_event_id = last_mouse_event->id;
m_input_event_queue.tail().event = move(event);
diff --git a/Tests/LibWeb/Text/expected/UIEvents/wheel-event-legacy-deltas-from-wheel-ticks.txt b/Tests/LibWeb/Text/expected/UIEvents/wheel-event-legacy-deltas-from-wheel-ticks.txt
new file mode 100644
index 00000000000..e2f6e1863ec
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/UIEvents/wheel-event-legacy-deltas-from-wheel-ticks.txt
@@ -0,0 +1,4 @@
+notch counted from pixels: deltaX=0.00 deltaY=120.00 wheelDeltaX=0 wheelDeltaY=-120 wheelDelta=-120
+one accelerated line: deltaX=0.00 deltaY=40.00 wheelDeltaX=0 wheelDeltaY=-120 wheelDelta=-120
+accelerated lines down: deltaX=0.00 deltaY=146.00 wheelDeltaX=0 wheelDeltaY=-438 wheelDelta=-438
+accelerated lines left and up: deltaX=-80.00 deltaY=-600.00 wheelDeltaX=240 wheelDeltaY=1800 wheelDelta=1800
diff --git a/Tests/LibWeb/Text/input/UIEvents/wheel-event-legacy-deltas-from-wheel-ticks.html b/Tests/LibWeb/Text/input/UIEvents/wheel-event-legacy-deltas-from-wheel-ticks.html
new file mode 100644
index 00000000000..290481ce8a1
--- /dev/null
+++ b/Tests/LibWeb/Text/input/UIEvents/wheel-event-legacy-deltas-from-wheel-ticks.html
@@ -0,0 +1,30 @@
+<!DOCTYPE html>
+<script src="../include.js"></script>
+<style>
+ body {
+ margin: 0;
+ height: 4000px;
+ }
+</style>
+<script>
+ promiseTest(async () => {
+ let resolveNextWheelEvent = null;
+ window.addEventListener("wheel", event => {
+ if (resolveNextWheelEvent)
+ resolveNextWheelEvent(event);
+ resolveNextWheelEvent = null;
+ });
+
+ async function printLegacyDeltasOfWheelStep(label, deltaX, deltaY, ticks) {
+ const nextWheelEvent = new Promise(resolve => (resolveNextWheelEvent = resolve));
+ internals.wheelThroughUIProcess(50, 50, deltaX, deltaY, false, "none", ticks);
+ const event = await nextWheelEvent;
+ println(`${label}: deltaX=${event.deltaX.toFixed(2)} deltaY=${event.deltaY.toFixed(2)} wheelDeltaX=${event.wheelDeltaX} wheelDeltaY=${event.wheelDeltaY} wheelDelta=${event.wheelDelta}`);
+ }
+
+ await printLegacyDeltasOfWheelStep("notch counted from pixels", 0, 120);
+ await printLegacyDeltasOfWheelStep("one accelerated line", 0, 40, { y: 1 });
+ await printLegacyDeltasOfWheelStep("accelerated lines down", 0, 146, { y: 3.65 });
+ await printLegacyDeltasOfWheelStep("accelerated lines left and up", -80, -600, { x: -2, y: -15 });
+ });
+</script>
diff --git a/Tests/LibWebView/TestCompositorInputRouting.cpp b/Tests/LibWebView/TestCompositorInputRouting.cpp
index 39d8277ebf8..493d8b1775e 100644
--- a/Tests/LibWebView/TestCompositorInputRouting.cpp
+++ b/Tests/LibWebView/TestCompositorInputRouting.cpp
@@ -49,6 +49,7 @@ void scroll_wheel_at(WebView::ViewImplementation& view, Web::DevicePixelPoint po
.position = position,
.screen_position = position,
.wheel_delta_y = wheel_delta_y,
+ .wheel_tick_120ths_y = Web::wheel_tick_120ths_from_pixel_delta(wheel_delta_y, Web::WheelDeltaPrecision::Precise),
.wheel_delta_precision = Web::WheelDeltaPrecision::Precise,
.browser_data = nullptr,
});
diff --git a/UI/Android/src/main/cpp/WebViewImplementationNative.cpp b/UI/Android/src/main/cpp/WebViewImplementationNative.cpp
index 152fec34966..c31d2f50f5d 100644
--- a/UI/Android/src/main/cpp/WebViewImplementationNative.cpp
+++ b/UI/Android/src/main/cpp/WebViewImplementationNative.cpp
@@ -113,6 +113,8 @@ void WebViewImplementationNative::mouse_event(Web::MouseEvent::Type event_type,
Web::UIEvents::KeyModifier::Mod_None,
0,
0,
+ 0,
+ 0,
Web::WheelDeltaPrecision::Discrete,
Web::ScrollGesturePhase::None,
0,
diff --git a/UI/Qt/WebContentView.cpp b/UI/Qt/WebContentView.cpp
index 2de37e43137..dc2e4fae871 100644
--- a/UI/Qt/WebContentView.cpp
+++ b/UI/Qt/WebContentView.cpp
@@ -476,44 +476,54 @@ static Web::UIEvents::KeyModifier get_modifiers_from_qt_key_event(QKeyEvent cons
}
static constexpr double wheel_scroll_line_size = 40;
+static constexpr double wheel_tick_120ths_per_tick = 120;
-static QPointF wheel_delta_from_angle_delta(QPoint angle_delta)
+struct WheelDelta {
+ QPointF delta;
+ QPointF tick_120ths;
+ Web::WheelDeltaPrecision precision { Web::WheelDeltaPrecision::Discrete };
+};
+
+static WheelDelta precise_wheel_delta(QPointF pixel_delta)
{
- static constexpr double wheel_delta_units_per_step = static_cast<double>(QWheelEvent::DefaultDeltasPerStep);
- double delta_x = -static_cast<double>(angle_delta.x()) / wheel_delta_units_per_step;
- double delta_y = static_cast<double>(angle_delta.y()) / wheel_delta_units_per_step;
+ auto precise_tick_120ths = [](double pixel_step) {
+ return Web::wheel_tick_120ths_from_pixel_delta(pixel_step, Web::WheelDeltaPrecision::Precise);
+ };
+ return { pixel_delta, { precise_tick_120ths(pixel_delta.x()), precise_tick_120ths(pixel_delta.y()) }, Web::WheelDeltaPrecision::Precise };
+}
- auto step_x = delta_x * static_cast<double>(QApplication::wheelScrollLines());
- auto step_y = delta_y * static_cast<double>(QApplication::wheelScrollLines());
+// Qt counts a wheel's angle delta in 120ths of a notch, as wheel input counts its ticks.
+static_assert(static_cast<double>(QWheelEvent::DefaultDeltasPerStep) == wheel_tick_120ths_per_tick);
- return { step_x * wheel_scroll_line_size, step_y * wheel_scroll_line_size };
+static WheelDelta wheel_delta_from_angle_delta(QPoint angle_delta)
+{
+ QPointF notch_120ths { -static_cast<double>(angle_delta.x()), static_cast<double>(angle_delta.y()) };
+ auto pixels_per_notch = static_cast<double>(QApplication::wheelScrollLines()) * wheel_scroll_line_size;
+ return { notch_120ths * (pixels_per_notch / wheel_tick_120ths_per_tick), notch_120ths, Web::WheelDeltaPrecision::Discrete };
}
#if defined(AK_OS_MACOS)
// NB: Qt reports every macOS mouse-wheel event as exactly one notch of angle delta, which drops the scroll
// acceleration that macOS applies to fast wheel spins. The accelerated line count survives in the pixel delta,
// which Qt computes by multiplying it with an estimated line height.
+// INTEROP: Blink and WebKit count each accelerated line of a macOS mouse wheel as one wheel tick.
static constexpr double qt_macos_mouse_wheel_pixel_delta_per_line = 20;
-static QPointF mouse_wheel_delta_with_macos_scroll_acceleration(QPointF notch_delta, QPoint qt_pixel_delta)
+static WheelDelta mouse_wheel_delta_with_macos_scroll_acceleration(QPoint angle_delta, QPoint qt_pixel_delta)
{
+ auto notch = wheel_delta_from_angle_delta(angle_delta);
// A slow click is accelerated to only a tenth of a line, so a click scrolls at least one line.
- auto accelerated_step = [](double notch_step, int qt_pixel_step) -> double {
+ auto accelerated_line_count = [](double notch_step, int qt_pixel_step) -> double {
if (notch_step == 0)
return 0;
- auto accelerated_line_count = max(AK::abs(qt_pixel_step) / qt_macos_mouse_wheel_pixel_delta_per_line, 1.0);
- auto step_size = accelerated_line_count * wheel_scroll_line_size;
- return notch_step < 0 ? -step_size : step_size;
+ auto line_count = max(AK::abs(qt_pixel_step) / qt_macos_mouse_wheel_pixel_delta_per_line, 1.0);
+ return notch_step < 0 ? -line_count : line_count;
};
- return { accelerated_step(notch_delta.x(), qt_pixel_delta.x()), accelerated_step(notch_delta.y(), qt_pixel_delta.y()) };
+ QPointF line_counts { accelerated_line_count(notch.tick_120ths.x(), qt_pixel_delta.x()), accelerated_line_count(notch.tick_120ths.y(), qt_pixel_delta.y()) };
+ return { line_counts * wheel_scroll_line_size, line_counts * wheel_tick_120ths_per_tick, Web::WheelDeltaPrecision::Discrete };
}
#endif
-struct WheelDelta {
- QPointF delta;
- Web::WheelDeltaPrecision precision { Web::WheelDeltaPrecision::Discrete };
-};
-
static bool is_running_on_wayland()
{
static bool const is_wayland = QGuiApplication::platformName().startsWith(QStringLiteral("wayland"));
@@ -552,24 +562,24 @@ static WheelDelta wheel_delta_from_qt_event(QWheelEvent const& wheel_event)
{
// NB: A slow touchpad movement can have a pixel delta of zero. It is still precise input, not a wheel step.
if (is_running_on_wayland() && wheel_event_scrolls_continuously(wheel_event))
- return { wayland_touchpad_delta(wheel_event), Web::WheelDeltaPrecision::Precise };
+ return precise_wheel_delta(wayland_touchpad_delta(wheel_event));
auto pixel_delta = -wheel_event.pixelDelta();
// NB: macOS can report a tiny pixel delta for mouse-wheel ticks. Use it only for continuous scrolling so physical
// wheels continue through the line-step conversion below.
if (!pixel_delta.isNull() && wheel_event_scrolls_continuously(wheel_event))
- return { pixel_delta, Web::WheelDeltaPrecision::Precise };
+ return precise_wheel_delta(pixel_delta);
auto angle_delta = -wheel_event.angleDelta();
if (!angle_delta.isNull()) {
- auto wheel_delta = wheel_delta_from_angle_delta(angle_delta);
#if defined(AK_OS_MACOS)
- wheel_delta = mouse_wheel_delta_with_macos_scroll_acceleration(wheel_delta, wheel_event.pixelDelta());
+ return mouse_wheel_delta_with_macos_scroll_acceleration(angle_delta, wheel_event.pixelDelta());
+#else
+ return wheel_delta_from_angle_delta(angle_delta);
#endif
- return { wheel_delta, Web::WheelDeltaPrecision::Discrete };
}
- return { pixel_delta, Web::WheelDeltaPrecision::Precise };
+ return precise_wheel_delta(pixel_delta);
}
static Web::ScrollGesturePhase scroll_gesture_phase_from_qt_event(QWheelEvent const& wheel_event)
@@ -2059,6 +2069,8 @@ void WebContentView::enqueue_native_event(Web::MouseEvent::Type type, QSinglePoi
double wheel_delta_x = 0;
double wheel_delta_y = 0;
+ double wheel_tick_120ths_x = 0;
+ double wheel_tick_120ths_y = 0;
auto wheel_delta_precision = Web::WheelDeltaPrecision::Discrete;
auto scroll_gesture_phase = Web::ScrollGesturePhase::None;
@@ -2067,11 +2079,13 @@ void WebContentView::enqueue_native_event(Web::MouseEvent::Type type, QSinglePoi
auto wheel_delta = wheel_delta_from_qt_event(wheel_event);
wheel_delta_x = wheel_delta.delta.x();
wheel_delta_y = wheel_delta.delta.y();
+ wheel_tick_120ths_x = wheel_delta.tick_120ths.x();
+ wheel_tick_120ths_y = wheel_delta.tick_120ths.y();
wheel_delta_precision = wheel_delta.precision;
scroll_gesture_phase = scroll_gesture_phase_from_qt_event(wheel_event);
}
- enqueue_input_event(Web::MouseEvent { type, position, screen_position.to_type<Web::DevicePixels>(), button, buttons, modifiers, wheel_delta_x, wheel_delta_y, wheel_delta_precision, scroll_gesture_phase, m_click_count, nullptr });
+ enqueue_input_event(Web::MouseEvent { type, position, screen_position.to_type<Web::DevicePixels>(), button, buttons, modifiers, wheel_delta_x, wheel_delta_y, wheel_tick_120ths_x, wheel_tick_120ths_y, wheel_delta_precision, scroll_gesture_phase, m_click_count, nullptr });
}
struct DragData : Web::BrowserInputData {