JBR-2630 Typing speed in IDE editor was dropped after switching to 11.0.8

Introduced sun.awt.osx.RobotSafeDelayMillis property to control macOS specific safe delay for Robot methods.
50 ms safe delay was initially hardcoded in 3862142d (JDK-8242174: [macos] The NestedModelessDialogTest test make the macOS unstable) which affected performance tests execution.

(cherry picked from commit 5f691bb788)
(cherry picked from commit cfc90ce2c5)
This commit is contained in:
Elena Sayapina
2020-08-05 23:01:02 +07:00
committed by jbrbot
parent 242c7d6885
commit 95b80a148b
2 changed files with 13 additions and 5 deletions

View File

@@ -34,6 +34,7 @@ import sun.awt.CGraphicsDevice;
final class CRobot implements RobotPeer {
private static final int MOUSE_LOCATION_UNKNOWN = -1;
private static final int DEFAULT_SAFE_DELAY_MILLIS = 50;
private final CGraphicsDevice fDevice;
private int mouseLastX = MOUSE_LOCATION_UNKNOWN;
@@ -50,7 +51,12 @@ final class CRobot implements RobotPeer {
*/
CRobot(CGraphicsDevice d) {
fDevice = d;
initRobot();
int safeDelayMillis = Integer.getInteger(
"sun.awt.osx.RobotSafeDelayMillis", DEFAULT_SAFE_DELAY_MILLIS);
if (safeDelayMillis < 0) {
safeDelayMillis = DEFAULT_SAFE_DELAY_MILLIS;
}
initRobot(safeDelayMillis);
}
/**
@@ -187,7 +193,7 @@ final class CRobot implements RobotPeer {
return c;
}
private native void initRobot();
private native void initRobot(int safeDelayMillis);
private native void mouseEvent(int lastX, int lastY, int buttonsState,
boolean isButtonsDownState,
boolean isMouseMove);

View File

@@ -63,6 +63,7 @@ static NSTimeInterval gsLastClickTime;
static int gsEventNumber;
static int* gsButtonEventNumber;
static NSTimeInterval gNextKeyEventTime;
static NSTimeInterval safeDelay;
static inline CGKeyCode GetCGKeyCode(jint javaKeyCode);
@@ -99,17 +100,17 @@ static inline void autoDelay(BOOL isMove) {
[NSThread sleepForTimeInterval:delay];
}
}
gNextKeyEventTime = [[NSDate date] timeIntervalSinceReferenceDate] + 0.050;
gNextKeyEventTime = [[NSDate date] timeIntervalSinceReferenceDate] + safeDelay;
}
/*
* Class: sun_lwawt_macosx_CRobot
* Method: initRobot
* Signature: (V)V
* Signature: (I)V
*/
JNIEXPORT void JNICALL
Java_sun_lwawt_macosx_CRobot_initRobot
(JNIEnv *env, jobject peer)
(JNIEnv *env, jobject peer, jint safeDelayMillis)
{
// Set things up to let our app act like a synthetic keyboard and mouse.
// Always set all states, in case Apple ever changes default behaviors.
@@ -138,6 +139,7 @@ Java_sun_lwawt_macosx_CRobot_initRobot
gsClickCount = 0;
gsLastClickTime = 0;
gNextKeyEventTime = 0;
safeDelay = (NSTimeInterval)safeDelayMillis/1000;
gsEventNumber = ROBOT_EVENT_NUMBER_START;
gsButtonEventNumber = (int*)SAFE_SIZE_ARRAY_ALLOC(malloc, sizeof(int), gNumberOfButtons);