diff options
author | Sergey Malenkov <sergey.malenkov@jetbrains.com> | 2016-10-21 12:51:23 +0300 |
---|---|---|
committer | Sergey Malenkov <sergey.malenkov@jetbrains.com> | 2016-10-21 12:51:23 +0300 |
commit | a423784cc10f07958f460473967efdfd91019cd8 (patch) | |
tree | fcb7567d3b9c9815ee5830dfb0ac2671eeb56431 | |
parent | 536d5e221428b3e09f131f23a134785da2c84aa0 (diff) | |
download | jdk8u_jdk-a423784cc10f07958f460473967efdfd91019cd8.tar.gz |
IDEA-162490 Fix for unexpected jumping on the end of scrollingjb8u112-b481
-rw-r--r-- | src/macosx/classes/sun/lwawt/macosx/CPlatformResponder.java | 20 | ||||
-rw-r--r-- | src/macosx/classes/sun/lwawt/macosx/NSEvent.java | 2 | ||||
-rw-r--r-- | src/macosx/native/sun/awt/LWCToolkit.m | 34 |
3 files changed, 29 insertions, 27 deletions
diff --git a/src/macosx/classes/sun/lwawt/macosx/CPlatformResponder.java b/src/macosx/classes/sun/lwawt/macosx/CPlatformResponder.java index 42fdbb7a4f..185950b4c4 100644 --- a/src/macosx/classes/sun/lwawt/macosx/CPlatformResponder.java +++ b/src/macosx/classes/sun/lwawt/macosx/CPlatformResponder.java @@ -281,8 +281,6 @@ final class CPlatformResponder { static class DeltaAccumulator { - static final double MIN_THRESHOLD = 0.1; - static final double MAX_THRESHOLD = 0.5; double accumulatedDelta; boolean accumulate; @@ -299,27 +297,19 @@ final class CPlatformResponder { accumulatedDelta = 0; accumulate = true; } + else if (scrollPhase == NSEvent.SCROLL_PHASE_MOMENTUM_BEGAN) { + accumulate = true; + } if (accumulate) { accumulatedDelta += delta; - if (accumulatedDelta > MAX_THRESHOLD) { - roundDelta = (int) (0.5 + accumulatedDelta); - } else if (accumulatedDelta < -MAX_THRESHOLD) { - roundDelta = -(int) (0.5 - accumulatedDelta); - } + roundDelta = (int) Math.round(accumulatedDelta); accumulatedDelta -= roundDelta; - if (scrollPhase == NSEvent.SCROLL_PHASE_ENDED || scrollPhase == NSEvent.SCROLL_PHASE_CANCELLED) { + if (scrollPhase == NSEvent.SCROLL_PHASE_ENDED) { accumulate = false; - if (roundDelta == 0) { - if (accumulatedDelta > MIN_THRESHOLD) { - roundDelta = 1; - } else if (accumulatedDelta < -MIN_THRESHOLD) { - roundDelta = -1; - } - } } } } diff --git a/src/macosx/classes/sun/lwawt/macosx/NSEvent.java b/src/macosx/classes/sun/lwawt/macosx/NSEvent.java index b547914a20..3a8508d48c 100644 --- a/src/macosx/classes/sun/lwawt/macosx/NSEvent.java +++ b/src/macosx/classes/sun/lwawt/macosx/NSEvent.java @@ -36,7 +36,7 @@ final class NSEvent { static final int SCROLL_PHASE_UNSUPPORTED = 1; static final int SCROLL_PHASE_BEGAN = 2; static final int SCROLL_PHASE_CONTINUED = 3; - static final int SCROLL_PHASE_CANCELLED = 4; + static final int SCROLL_PHASE_MOMENTUM_BEGAN = 4; static final int SCROLL_PHASE_ENDED = 5; private int type; diff --git a/src/macosx/native/sun/awt/LWCToolkit.m b/src/macosx/native/sun/awt/LWCToolkit.m index 8a80d63469..e730b5cb2b 100644 --- a/src/macosx/native/sun/awt/LWCToolkit.m +++ b/src/macosx/native/sun/awt/LWCToolkit.m @@ -43,7 +43,7 @@ #define SCROLL_PHASE_UNSUPPORTED 1 #define SCROLL_PHASE_BEGAN 2 #define SCROLL_PHASE_CONTINUED 3 -#define SCROLL_PHASE_CANCELLED 4 +#define SCROLL_PHASE_MOMENTUM_BEGAN 4 #define SCROLL_PHASE_ENDED 5 int gNumberOfButtons; @@ -63,17 +63,29 @@ static long eventCount; + (jint) scrollStateWithEvent: (NSEvent*) event { - if ([event type] != NSScrollWheel) return 0; - - NSEventPhase phase = [event phase]; - if (!phase) phase = [event momentumPhase]; - if (!phase) return SCROLL_PHASE_UNSUPPORTED; - switch (phase) { - case NSEventPhaseBegan: return SCROLL_PHASE_BEGAN; - case NSEventPhaseCancelled: return SCROLL_PHASE_CANCELLED; - case NSEventPhaseEnded: return SCROLL_PHASE_ENDED; - default: return SCROLL_PHASE_CONTINUED; + if ([event type] != NSScrollWheel) { + return 0; + } + if ([event phase]) { + // process a phase of manual scrolling + switch ([event phase]) { + case NSEventPhaseBegan: return SCROLL_PHASE_BEGAN; + case NSEventPhaseCancelled: return SCROLL_PHASE_ENDED; + case NSEventPhaseEnded: return SCROLL_PHASE_ENDED; + default: return SCROLL_PHASE_CONTINUED; + } + } + if ([event momentumPhase]) { + // process a phase of automatic scrolling + switch ([event momentumPhase]) { + case NSEventPhaseBegan: return SCROLL_PHASE_MOMENTUM_BEGAN; + case NSEventPhaseCancelled: return SCROLL_PHASE_ENDED; + case NSEventPhaseEnded: return SCROLL_PHASE_ENDED; + default: return SCROLL_PHASE_CONTINUED; + } } + // phase and momentum phase both are not set + return SCROLL_PHASE_UNSUPPORTED; } @end |