< prev index next >

src/java.desktop/macosx/classes/sun/lwawt/macosx/CPlatformResponder.java

Print this page

        

*** 42,51 **** --- 42,54 ---- final class CPlatformResponder { 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) { this.eventNotifier = eventNotifier; this.isNpapiCallback = isNpapiCallback;
*** 87,127 **** /** * Handles scroll events. */ void handleScrollEvent(final int x, final int y, final int absX, final int absY, final int modifierFlags, ! final double deltaX, final double deltaY) { int jmodifiers = NSEvent.nsToJavaModifiers(modifierFlags); final boolean isShift = (jmodifiers & InputEvent.SHIFT_DOWN_MASK) != 0; // Vertical scroll. if (!isShift && deltaY != 0.0) { ! dispatchScrollEvent(x, y, absX, absY, jmodifiers, deltaY); } // Horizontal scroll or shirt+vertical scroll. final double delta = isShift && deltaY != 0.0 ? deltaY : deltaX; if (delta != 0.0) { jmodifiers |= InputEvent.SHIFT_DOWN_MASK; ! dispatchScrollEvent(x, y, absX, absY, jmodifiers, delta); } } private void dispatchScrollEvent(final int x, final int y, final int absX, final int absY, final int modifiers, ! 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); } /** * Handles key events. */ --- 90,158 ---- /** * Handles scroll events. */ void handleScrollEvent(final int x, final int y, final int absX, final int absY, final int modifierFlags, ! 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, 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, roundDelta, delta); } } private void dispatchScrollEvent(final int x, final int y, final int absX, final int absY, final int modifiers, ! final int roundDelta, final double delta) { final long when = System.currentTimeMillis(); final int scrollType = MouseWheelEvent.WHEEL_UNIT_SCROLL; final int scrollAmount = 1; // invert the wheelRotation for the peer eventNotifier.notifyMouseWheelEvent(when, x, y, absX, absY, modifiers, scrollType, scrollAmount, ! -roundDelta, -delta, null); } /** * Handles key events. */
< prev index next >