--- old/src/java.desktop/macosx/classes/sun/lwawt/macosx/CPlatformResponder.java 2016-09-28 15:30:40.000000000 +0400 +++ new/src/java.desktop/macosx/classes/sun/lwawt/macosx/CPlatformResponder.java 2016-09-28 15:30:40.000000000 +0400 @@ -44,6 +44,9 @@ private final PlatformEventNotifier eventNotifier; private final boolean isNpapiCallback; private int lastKeyPressCode = KeyEvent.VK_UNDEFINED; + private static final double DELTA_THRESHOLD = 0.8; + private double accumulatedDeltaX; + private double accumulatedDeltaY; CPlatformResponder(final PlatformEventNotifier eventNotifier, final boolean isNpapiCallback) { @@ -89,37 +92,65 @@ */ void handleScrollEvent(final int x, final int y, final int absX, final int absY, final int modifierFlags, - final double deltaX, final double deltaY) { + final double deltaX, final double deltaY, + final int scrollMask) { int jmodifiers = NSEvent.nsToJavaModifiers(modifierFlags); final boolean isShift = (jmodifiers & InputEvent.SHIFT_DOWN_MASK) != 0; + int roundDeltaX = (int) Math.round(deltaX); + int roundDeltaY = (int) Math.round(deltaY); + + if ((scrollMask & NSEvent.SCROLL_MASK_TRACKPAD) != 0) { + if ((scrollMask & NSEvent.SCROLL_MASK_PHASE_BEGAN) != 0) { + accumulatedDeltaX = deltaX; + accumulatedDeltaY = deltaY; + } else { + accumulatedDeltaX += deltaX; + accumulatedDeltaY += deltaY; + } + + if (Math.abs(accumulatedDeltaX) > DELTA_THRESHOLD) { + roundDeltaX = (int) Math.round(accumulatedDeltaX); + accumulatedDeltaX -= roundDeltaX; + } + + if (Math.abs(accumulatedDeltaY) > DELTA_THRESHOLD) { + roundDeltaY = (int) Math.round(accumulatedDeltaY); + accumulatedDeltaY -= roundDeltaY; + } + } else { + if (roundDeltaX == 0 && deltaX != 0) { + roundDeltaX = deltaX > 0 ? 1 : -1; + } + + if (roundDeltaY == 0 && deltaY != 0) { + roundDeltaY = deltaY > 0 ? 1 : -1; + } + } + // Vertical scroll. if (!isShift && deltaY != 0.0) { - dispatchScrollEvent(x, y, absX, absY, jmodifiers, deltaY); + dispatchScrollEvent(x, y, absX, absY, jmodifiers, roundDeltaY, deltaY); } // Horizontal scroll or shirt+vertical scroll. final double delta = isShift && deltaY != 0.0 ? deltaY : deltaX; + final int roundDelta = isShift && roundDeltaY != 0.0 ? roundDeltaY : roundDeltaX; if (delta != 0.0) { jmodifiers |= InputEvent.SHIFT_DOWN_MASK; - dispatchScrollEvent(x, y, absX, absY, jmodifiers, delta); + dispatchScrollEvent(x, y, absX, absY, jmodifiers, roundDelta, delta); } } private void dispatchScrollEvent(final int x, final int y, final int absX, final int absY, final int modifiers, - final double delta) { + final int roundDelta, final double delta) { final long when = System.currentTimeMillis(); final int scrollType = MouseWheelEvent.WHEEL_UNIT_SCROLL; final int scrollAmount = 1; - int wheelRotation = (int) delta; - int signum = (int) Math.signum(delta); - if (signum * delta < 1) { - wheelRotation = signum; - } // invert the wheelRotation for the peer eventNotifier.notifyMouseWheelEvent(when, x, y, absX, absY, modifiers, scrollType, scrollAmount, - -wheelRotation, -delta, null); + -roundDelta, -delta, null); } /**