diff --git a/dom/events/EventStateManager.cpp b/dom/events/EventStateManager.cpp index 085ae90ee9dd..653a38acd177 100644 --- a/dom/events/EventStateManager.cpp +++ b/dom/events/EventStateManager.cpp @@ -2373,18 +2373,9 @@ void EventStateManager::DispatchLegacyMouseScrollEvents( // Ignore mouse wheel transaction for computing legacy mouse wheel // events' delta value. - nsIFrame* scrollFrame = ComputeScrollTargetAndMayAdjustWheelEvent( - aTargetFrame, aEvent, COMPUTE_LEGACY_MOUSE_SCROLL_EVENT_TARGET); - - nsIScrollableFrame* scrollTarget = do_QueryFrame(scrollFrame); - nsPresContext* pc = - scrollFrame ? scrollFrame->PresContext() : aTargetFrame->PresContext(); - // DOM event's delta vales are computed from CSS pixels. - nsSize scrollAmount = GetScrollAmount(pc, aEvent, scrollTarget); - nsIntSize scrollAmountInCSSPixels( - nsPresContext::AppUnitsToIntCSSPixels(scrollAmount.width), - nsPresContext::AppUnitsToIntCSSPixels(scrollAmount.height)); + auto scrollAmountInCSSPixels = + CSSIntSize::FromAppUnits(aEvent->mScrollAmount); // XXX We don't deal with fractional amount in legacy event, though the // default action handler (DoScrollText()) deals with it. @@ -5937,6 +5928,15 @@ void EventStateManager::DeltaAccumulator::InitLineOrPageDelta( mHandlingDeltaMode = aEvent->mDeltaMode; mIsNoLineOrPageDeltaDevice = aEvent->mIsNoLineOrPageDelta; + { + nsIFrame* frame = aESM->ComputeScrollTarget( + aTargetFrame, aEvent, COMPUTE_LEGACY_MOUSE_SCROLL_EVENT_TARGET); + nsPresContext* pc = + frame ? frame->PresContext() : aTargetFrame->PresContext(); + nsIScrollableFrame* scrollTarget = do_QueryFrame(frame); + aEvent->mScrollAmount = aESM->GetScrollAmount(pc, aEvent, scrollTarget); + } + // If it's handling neither a device that does not provide line or page deltas // nor delta values multiplied by prefs, we must not modify lineOrPageDelta // values. @@ -5969,15 +5969,8 @@ void EventStateManager::DeltaAccumulator::InitLineOrPageDelta( // eMouseScrollEventClass (DOMMouseScroll) but not be used for scrolling // of default action. The transaction should be used only for the default // action. - nsIFrame* frame = aESM->ComputeScrollTarget( - aTargetFrame, aEvent, COMPUTE_LEGACY_MOUSE_SCROLL_EVENT_TARGET); - nsPresContext* pc = - frame ? frame->PresContext() : aTargetFrame->PresContext(); - nsIScrollableFrame* scrollTarget = do_QueryFrame(frame); - nsSize scrollAmount = aESM->GetScrollAmount(pc, aEvent, scrollTarget); - nsIntSize scrollAmountInCSSPixels( - nsPresContext::AppUnitsToIntCSSPixels(scrollAmount.width), - nsPresContext::AppUnitsToIntCSSPixels(scrollAmount.height)); + auto scrollAmountInCSSPixels = + CSSIntSize::FromAppUnits(aEvent->mScrollAmount); aEvent->mLineOrPageDeltaX = RoundDown(mX) / scrollAmountInCSSPixels.width; aEvent->mLineOrPageDeltaY = RoundDown(mY) / scrollAmountInCSSPixels.height; diff --git a/dom/events/WheelEvent.cpp b/dom/events/WheelEvent.cpp index 01aeb5a2f5aa..6e7ca4914ba2 100644 --- a/dom/events/WheelEvent.cpp +++ b/dom/events/WheelEvent.cpp @@ -61,7 +61,8 @@ void WheelEvent::InitWheelEvent( } double WheelEvent::ToWebExposedDelta(const WidgetWheelEvent& aWidgetEvent, - double aDelta, CallerType aCallerType) { + double aDelta, nscoord aLineOrPageAmount, + CallerType aCallerType) { if (aCallerType != CallerType::System) { if (mDeltaModeCheckingState == DeltaModeCheckingState::Unknown) { mDeltaModeCheckingState = DeltaModeCheckingState::Unchecked; @@ -69,9 +70,7 @@ double WheelEvent::ToWebExposedDelta(const WidgetWheelEvent& aWidgetEvent, if (mDeltaModeCheckingState == DeltaModeCheckingState::Unchecked && aWidgetEvent.mDeltaMode == WheelEvent_Binding::DOM_DELTA_LINE && StaticPrefs::dom_event_wheel_deltaMode_lines_disabled()) { - // TODO(emilio, bug 1675949): Consider not using a fixed multiplier here? - return aDelta * - StaticPrefs::dom_event_wheel_deltaMode_lines_to_pixel_scale(); + return aDelta * CSSPixel::FromAppUnits(aLineOrPageAmount); } } if (!mAppUnitsPerDevPixel) { @@ -82,17 +81,21 @@ double WheelEvent::ToWebExposedDelta(const WidgetWheelEvent& aWidgetEvent, double WheelEvent::DeltaX(CallerType aCallerType) { WidgetWheelEvent* ev = mEvent->AsWheelEvent(); - return ToWebExposedDelta(*ev, ev->mDeltaX, aCallerType); + return ToWebExposedDelta(*ev, ev->mDeltaX, ev->mScrollAmount.width, + aCallerType); } double WheelEvent::DeltaY(CallerType aCallerType) { WidgetWheelEvent* ev = mEvent->AsWheelEvent(); - return ToWebExposedDelta(*ev, ev->mDeltaY, aCallerType); + return ToWebExposedDelta(*ev, ev->mDeltaY, ev->mScrollAmount.height, + aCallerType); } double WheelEvent::DeltaZ(CallerType aCallerType) { WidgetWheelEvent* ev = mEvent->AsWheelEvent(); - return ToWebExposedDelta(*ev, ev->mDeltaZ, aCallerType); + // XXX Unclear what scroll amount we should use for deltaZ... + auto amount = std::max(ev->mScrollAmount.width, ev->mScrollAmount.height); + return ToWebExposedDelta(*ev, ev->mDeltaZ, amount, aCallerType); } uint32_t WheelEvent::DeltaMode(CallerType aCallerType) { diff --git a/dom/events/WheelEvent.h b/dom/events/WheelEvent.h index a1da439091e4..194579e3e4d9 100644 --- a/dom/events/WheelEvent.h +++ b/dom/events/WheelEvent.h @@ -49,7 +49,8 @@ class WheelEvent : public MouseEvent { protected: ~WheelEvent() = default; - double ToWebExposedDelta(const WidgetWheelEvent&, double aDelta, CallerType); + double ToWebExposedDelta(const WidgetWheelEvent&, double aDelta, + nscoord aLineOrPageAmount, CallerType); private: int32_t mAppUnitsPerDevPixel; diff --git a/dom/events/test/test_continuous_wheel_events.html b/dom/events/test/test_continuous_wheel_events.html index 25ee5f17a227..eaca750d2478 100644 --- a/dom/events/test/test_continuous_wheel_events.html +++ b/dom/events/test/test_continuous_wheel_events.html @@ -2503,9 +2503,9 @@ function* testContinuousTrustedEvents() wheel: { expected: true, preventDefault: false, skipDeltaModeCheck: true, - deltaX: SpecialPowers.getIntPref("dom.event.wheel-deltaMode-lines-to-pixel-scale"), - deltaY: SpecialPowers.getIntPref("dom.event.wheel-deltaMode-lines-to-pixel-scale"), - deltaZ: SpecialPowers.getIntPref("dom.event.wheel-deltaMode-lines-to-pixel-scale"), + deltaX: gHorizontalLine, + deltaY: gLineHeight, + deltaZ: Math.max(gHorizontalLine, gLineHeight), }, DOMMouseScroll: { horizontal: { expected: true, preventDefault: false, detail: 1 }, diff --git a/modules/libpref/init/StaticPrefList.yaml b/modules/libpref/init/StaticPrefList.yaml index 21566ad59c83..53a15bef49be 100644 --- a/modules/libpref/init/StaticPrefList.yaml +++ b/modules/libpref/init/StaticPrefList.yaml @@ -1780,15 +1780,6 @@ value: false mirror: always -# When dom.event.wheel-deltaMode-lines.disabled is true, this is the lines to -# pixels multiplier that gets used. -# -# The value here is taken from PIXELS_PER_LINE_SCALE from pdf.js. -- name: dom.event.wheel-deltaMode-lines-to-pixel-scale - type: uint32_t - value: 30 - mirror: always - #if defined(XP_MACOSX) # Whether to disable treating ctrl click as right click - name: dom.event.treat_ctrl_click_as_right_click.disabled diff --git a/widget/MouseEvents.h b/widget/MouseEvents.h index 3b07cce48013..7c488d8f0b87 100644 --- a/widget/MouseEvents.h +++ b/widget/MouseEvents.h @@ -513,6 +513,12 @@ class WidgetWheelEvent : public WidgetMouseEventBase { double mDeltaY; double mDeltaZ; + // The amount of scrolling per line or page, without accounting for mouse + // wheel transactions etc. + // + // Computed by EventStateManager::DeltaAccumulator::InitLineOrPageDelta. + nsSize mScrollAmount; + // overflowed delta values for scroll, these values are set by // EventStateManger. If the default action of the wheel event isn't scroll, // these values are always zero. Otherwise, remaining delta values which are @@ -609,6 +615,7 @@ class WidgetWheelEvent : public WidgetMouseEventBase { mDeltaY = aEvent.mDeltaY; mDeltaZ = aEvent.mDeltaZ; mDeltaMode = aEvent.mDeltaMode; + mScrollAmount = aEvent.mScrollAmount; mCustomizedByUserPrefs = aEvent.mCustomizedByUserPrefs; mMayHaveMomentum = aEvent.mMayHaveMomentum; mIsMomentum = aEvent.mIsMomentum;