From 77f144de6798b3c0caadece63ae6fa68e3ed434f Mon Sep 17 00:00:00 2001 From: Pavel Fatin Date: Mon, 30 Jan 2017 22:32:39 +0100 Subject: [PATCH] true smooth scrolling: compatibility with a different encoding of absolute scrolling deltas in JetBrains Runtime --- .../ui/components/MouseWheelEventEx.java | 36 +++++++++---------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/platform/platform-api/src/com/intellij/ui/components/MouseWheelEventEx.java b/platform/platform-api/src/com/intellij/ui/components/MouseWheelEventEx.java index 21d1fc26d9cd..bb4ca4dffd49 100644 --- a/platform/platform-api/src/com/intellij/ui/components/MouseWheelEventEx.java +++ b/platform/platform-api/src/com/intellij/ui/components/MouseWheelEventEx.java @@ -15,39 +15,37 @@ */ package com.intellij.ui.components; -import com.intellij.util.MethodInvocator; +import com.intellij.openapi.util.SystemInfo; import java.awt.event.MouseWheelEvent; /** - * Accessor for absolute scrolling delta in the - * enhanced MouseWheelEvent. - *

- * Should be paired up with our custom JRE (currently has has - * an implementation for Mac OS X). + * Accessor for absolute scrolling delta in enhanced MouseWheelEvent. */ class MouseWheelEventEx { - private static final MethodInvocator ourGetScrollingDeltaMethod = new MethodInvocator(false, MouseWheelEvent.class, "getScrollingDelta"); - /** - * Returns scrolling delta as an absolute value (if available). - *

- * Returns 0.0 when scrolling delta is available only as a number of "clicks" or - * as a fraction of a "click". - *

- * The method returns natural numbers, however, for future extensibility, - * the return type is declared as {@code double}. + * Returns scrolling delta as an absolute value (if available). Requires JetBrains Runtime. *

* Some devices (e.g. high-precision touchpads) may report scrolling deltas * in absolute values rather than in fractions of a "click". This data can be used, * for example, to implement pixel-perfect scrolling (which cannot be * implemented via the {@link MouseWheelEvent#getPreciseWheelRotation} method, as fractions * of scrolling "units" cannot be reliably translated to pixel-precise deltas). + *

+ * JetBrains Runtime currently uses preciseWheelRotation = 0.1 * scrollingDelta + * mapping in Mac OS to encode absolute scrolling deltas as relative ones. + *

+ * That approach is suboptimal, because it: + * 1) produces different dynamics of relative deltas (in Mac OS there's no reliable linear mapping between those values), + * 2) makes handling of true relative deltas impossible (as there's no way to distinguish them from the encoded absolute ones). + *

+ * Ideally, we need to implement a method of distinguishing between the two kinds of scrolling deltas. * - * @param event the event - * @return negative values for scrolling up, positive values for scrolling down (natural numbers) + * @param e the event + * @return negative values for scrolling up, positive values for scrolling down + * 0.0 when absolute deltas are not supported or not available */ - static double getScrollingDelta(MouseWheelEvent event) { - return ourGetScrollingDeltaMethod.isAvailable() ? (double)ourGetScrollingDeltaMethod.invoke(event) : 0.0D; + static double getScrollingDelta(MouseWheelEvent e) { + return SystemInfo.isJetbrainsJvm && SystemInfo.isMac ? 10.0D * e.getPreciseWheelRotation() : 0.0D; } }