8173876: Fast precise scrolling and DeltaAccumulator fix for macOS Sierra 10.12.2
Reviewed-by: serb, alexsch
This commit is contained in:
parent
6a0c29b77d
commit
46145bdcbf
@ -265,9 +265,8 @@ final class CPlatformResponder {
|
|||||||
|
|
||||||
static class DeltaAccumulator {
|
static class DeltaAccumulator {
|
||||||
|
|
||||||
static final double MIN_THRESHOLD = 0.1;
|
|
||||||
static final double MAX_THRESHOLD = 0.5;
|
|
||||||
double accumulatedDelta;
|
double accumulatedDelta;
|
||||||
|
boolean accumulate;
|
||||||
|
|
||||||
int getRoundedDelta(double delta, int scrollPhase) {
|
int getRoundedDelta(double delta, int scrollPhase) {
|
||||||
|
|
||||||
@ -278,25 +277,23 @@ final class CPlatformResponder {
|
|||||||
roundDelta = delta > 0 ? 1 : -1;
|
roundDelta = delta > 0 ? 1 : -1;
|
||||||
}
|
}
|
||||||
} else { // trackpad
|
} else { // trackpad
|
||||||
boolean begin = scrollPhase == NSEvent.SCROLL_PHASE_BEGAN;
|
if (scrollPhase == NSEvent.SCROLL_PHASE_BEGAN) {
|
||||||
boolean end = scrollPhase == NSEvent.SCROLL_MASK_PHASE_ENDED
|
|
||||||
|| scrollPhase == NSEvent.SCROLL_MASK_PHASE_CANCELLED;
|
|
||||||
|
|
||||||
if (begin) {
|
|
||||||
accumulatedDelta = 0;
|
accumulatedDelta = 0;
|
||||||
|
accumulate = true;
|
||||||
}
|
}
|
||||||
|
else if (scrollPhase == NSEvent.SCROLL_PHASE_MOMENTUM_BEGAN) {
|
||||||
|
accumulate = true;
|
||||||
|
}
|
||||||
|
if (accumulate) {
|
||||||
|
|
||||||
accumulatedDelta += delta;
|
accumulatedDelta += delta;
|
||||||
|
|
||||||
double absAccumulatedDelta = Math.abs(accumulatedDelta);
|
|
||||||
if (absAccumulatedDelta > MAX_THRESHOLD) {
|
|
||||||
roundDelta = (int) Math.round(accumulatedDelta);
|
roundDelta = (int) Math.round(accumulatedDelta);
|
||||||
accumulatedDelta -= roundDelta;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (end) {
|
accumulatedDelta -= roundDelta;
|
||||||
if (roundDelta == 0 && absAccumulatedDelta > MIN_THRESHOLD) {
|
|
||||||
roundDelta = accumulatedDelta > 0 ? 1 : -1;
|
if (scrollPhase == NSEvent.SCROLL_PHASE_ENDED) {
|
||||||
|
accumulate = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,8 +36,8 @@ final class NSEvent {
|
|||||||
static final int SCROLL_PHASE_UNSUPPORTED = 1;
|
static final int SCROLL_PHASE_UNSUPPORTED = 1;
|
||||||
static final int SCROLL_PHASE_BEGAN = 2;
|
static final int SCROLL_PHASE_BEGAN = 2;
|
||||||
static final int SCROLL_PHASE_CONTINUED = 3;
|
static final int SCROLL_PHASE_CONTINUED = 3;
|
||||||
static final int SCROLL_MASK_PHASE_CANCELLED = 4;
|
static final int SCROLL_PHASE_MOMENTUM_BEGAN = 4;
|
||||||
static final int SCROLL_MASK_PHASE_ENDED = 5;
|
static final int SCROLL_PHASE_ENDED = 5;
|
||||||
|
|
||||||
private int type;
|
private int type;
|
||||||
private int modifierFlags;
|
private int modifierFlags;
|
||||||
|
@ -382,6 +382,13 @@ static BOOL shouldUsePressAndHold() {
|
|||||||
clickCount = [event clickCount];
|
clickCount = [event clickCount];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
jdouble deltaX = [event deltaX];
|
||||||
|
jdouble deltaY = [event deltaY];
|
||||||
|
if ([AWTToolkit hasPreciseScrollingDeltas: event]) {
|
||||||
|
deltaX = [event scrollingDeltaX] * 0.1;
|
||||||
|
deltaY = [event scrollingDeltaY] * 0.1;
|
||||||
|
}
|
||||||
|
|
||||||
static JNF_CLASS_CACHE(jc_NSEvent, "sun/lwawt/macosx/NSEvent");
|
static JNF_CLASS_CACHE(jc_NSEvent, "sun/lwawt/macosx/NSEvent");
|
||||||
static JNF_CTOR_CACHE(jctor_NSEvent, jc_NSEvent, "(IIIIIIIIDDI)V");
|
static JNF_CTOR_CACHE(jctor_NSEvent, jc_NSEvent, "(IIIIIIIIDDI)V");
|
||||||
jobject jEvent = JNFNewObject(env, jctor_NSEvent,
|
jobject jEvent = JNFNewObject(env, jctor_NSEvent,
|
||||||
@ -391,8 +398,8 @@ static BOOL shouldUsePressAndHold() {
|
|||||||
[event buttonNumber],
|
[event buttonNumber],
|
||||||
(jint)localPoint.x, (jint)localPoint.y,
|
(jint)localPoint.x, (jint)localPoint.y,
|
||||||
(jint)absP.x, (jint)absP.y,
|
(jint)absP.x, (jint)absP.y,
|
||||||
[event deltaY],
|
deltaY,
|
||||||
[event deltaX],
|
deltaX,
|
||||||
[AWTToolkit scrollStateWithEvent: event]);
|
[AWTToolkit scrollStateWithEvent: event]);
|
||||||
CHECK_NULL(jEvent);
|
CHECK_NULL(jEvent);
|
||||||
|
|
||||||
|
@ -140,6 +140,13 @@ static NSSize ScaledImageSizeForStatusBar(NSSize imageSize, BOOL autosize) {
|
|||||||
|
|
||||||
clickCount = [event clickCount];
|
clickCount = [event clickCount];
|
||||||
|
|
||||||
|
jdouble deltaX = [event deltaX];
|
||||||
|
jdouble deltaY = [event deltaY];
|
||||||
|
if ([AWTToolkit hasPreciseScrollingDeltas: event]) {
|
||||||
|
deltaX = [event scrollingDeltaX] * 0.1;
|
||||||
|
deltaY = [event scrollingDeltaY] * 0.1;
|
||||||
|
}
|
||||||
|
|
||||||
static JNF_CLASS_CACHE(jc_NSEvent, "sun/lwawt/macosx/NSEvent");
|
static JNF_CLASS_CACHE(jc_NSEvent, "sun/lwawt/macosx/NSEvent");
|
||||||
static JNF_CTOR_CACHE(jctor_NSEvent, jc_NSEvent, "(IIIIIIIIDDI)V");
|
static JNF_CTOR_CACHE(jctor_NSEvent, jc_NSEvent, "(IIIIIIIIDDI)V");
|
||||||
jobject jEvent = JNFNewObject(env, jctor_NSEvent,
|
jobject jEvent = JNFNewObject(env, jctor_NSEvent,
|
||||||
@ -149,8 +156,8 @@ static NSSize ScaledImageSizeForStatusBar(NSSize imageSize, BOOL autosize) {
|
|||||||
[event buttonNumber],
|
[event buttonNumber],
|
||||||
(jint)localPoint.x, (jint)localPoint.y,
|
(jint)localPoint.x, (jint)localPoint.y,
|
||||||
(jint)absP.x, (jint)absP.y,
|
(jint)absP.x, (jint)absP.y,
|
||||||
[event deltaY],
|
deltaY,
|
||||||
[event deltaX],
|
deltaX,
|
||||||
[AWTToolkit scrollStateWithEvent: event]);
|
[AWTToolkit scrollStateWithEvent: event]);
|
||||||
CHECK_NULL(jEvent);
|
CHECK_NULL(jEvent);
|
||||||
|
|
||||||
|
@ -42,6 +42,7 @@ extern jint* gButtonDownMasks;
|
|||||||
+ (long) getEventCount;
|
+ (long) getEventCount;
|
||||||
+ (void) eventCountPlusPlus;
|
+ (void) eventCountPlusPlus;
|
||||||
+ (jint) scrollStateWithEvent: (NSEvent*) event;
|
+ (jint) scrollStateWithEvent: (NSEvent*) event;
|
||||||
|
+ (BOOL) hasPreciseScrollingDeltas: (NSEvent*) event;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -47,7 +47,7 @@
|
|||||||
#define SCROLL_PHASE_UNSUPPORTED 1
|
#define SCROLL_PHASE_UNSUPPORTED 1
|
||||||
#define SCROLL_PHASE_BEGAN 2
|
#define SCROLL_PHASE_BEGAN 2
|
||||||
#define SCROLL_PHASE_CONTINUED 3
|
#define SCROLL_PHASE_CONTINUED 3
|
||||||
#define SCROLL_PHASE_CANCELLED 4
|
#define SCROLL_PHASE_MOMENTUM_BEGAN 4
|
||||||
#define SCROLL_PHASE_ENDED 5
|
#define SCROLL_PHASE_ENDED 5
|
||||||
|
|
||||||
int gNumberOfButtons;
|
int gNumberOfButtons;
|
||||||
@ -85,16 +85,33 @@ static long eventCount;
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
NSEventPhase phase = [event phase];
|
if ([event phase]) {
|
||||||
NSEventPhase momentumPhase = [event momentumPhase];
|
// process a phase of manual scrolling
|
||||||
|
switch ([event phase]) {
|
||||||
if (!phase && !momentumPhase) return SCROLL_PHASE_UNSUPPORTED;
|
|
||||||
switch (phase) {
|
|
||||||
case NSEventPhaseBegan: return SCROLL_PHASE_BEGAN;
|
case NSEventPhaseBegan: return SCROLL_PHASE_BEGAN;
|
||||||
case NSEventPhaseCancelled: return SCROLL_PHASE_CANCELLED;
|
case NSEventPhaseCancelled: return SCROLL_PHASE_ENDED;
|
||||||
case NSEventPhaseEnded: return SCROLL_PHASE_ENDED;
|
case NSEventPhaseEnded: return SCROLL_PHASE_ENDED;
|
||||||
default: return SCROLL_PHASE_CONTINUED;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
+ (BOOL) hasPreciseScrollingDeltas: (NSEvent*) event {
|
||||||
|
return [event type] == NSScrollWheel
|
||||||
|
&& [event respondsToSelector:@selector(hasPreciseScrollingDeltas)]
|
||||||
|
&& [event hasPreciseScrollingDeltas];
|
||||||
}
|
}
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ import javax.swing.SwingUtilities;
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* @test
|
* @test
|
||||||
* @bug 8166591
|
* @bug 8166591 8173876
|
||||||
* @key headful
|
* @key headful
|
||||||
* @summary [macos 10.12] Trackpad scrolling of text on OS X 10.12 Sierra
|
* @summary [macos 10.12] Trackpad scrolling of text on OS X 10.12 Sierra
|
||||||
* is very fast (Trackpad, Retina only)
|
* is very fast (Trackpad, Retina only)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user