mirror of
https://github.com/JetBrains/JetBrainsRuntime.git
synced 2025-12-06 09:29:38 +01:00
JBR-2041: Project view tap fix, recovery? constants & logging
(cherry picked from commit 1e904db3b0)
This commit is contained in:
21
src/java.desktop/share/classes/sun/awt/event/TouchEvent.java
Normal file
21
src/java.desktop/share/classes/sun/awt/event/TouchEvent.java
Normal file
@@ -0,0 +1,21 @@
|
||||
package sun.awt.event;
|
||||
|
||||
import java.lang.annotation.Native;
|
||||
|
||||
public class TouchEvent {
|
||||
@Native public static final int TOUCH_BEGIN = 2;
|
||||
@Native public static final int TOUCH_UPDATE = 3;
|
||||
@Native public static final int TOUCH_END = 4;
|
||||
|
||||
/**
|
||||
* The allowable difference between coordinates of touch update events
|
||||
* in pixels
|
||||
*/
|
||||
@Native public static final int CLICK_RADIUS = 10;
|
||||
|
||||
/**
|
||||
* Stop owning touch processing after timeout
|
||||
* in ms
|
||||
*/
|
||||
public static final long NO_UPDATE_TIMEOUT = 1000L;
|
||||
}
|
||||
@@ -68,6 +68,7 @@ class XWindow extends XBaseWindow implements X11ComponentPeer {
|
||||
private static PlatformLogger eventLog = PlatformLogger.getLogger("sun.awt.X11.event.XWindow");
|
||||
private static final PlatformLogger focusLog = PlatformLogger.getLogger("sun.awt.X11.focus.XWindow");
|
||||
private static PlatformLogger keyEventLog = PlatformLogger.getLogger("sun.awt.X11.kye.XWindow");
|
||||
private static PlatformLogger touchEventLog = PlatformLogger.getLogger("sun.awt.event.TouchEvent");
|
||||
/* If a motion comes in while a multi-click is pending,
|
||||
* allow a smudge factor so that moving the mouse by a small
|
||||
* amount does not wipe out the multi-click state variables.
|
||||
@@ -79,14 +80,12 @@ class XWindow extends XBaseWindow implements X11ComponentPeer {
|
||||
static long lastButton = 0;
|
||||
static WeakReference<XWindow> lastWindowRef = null;
|
||||
static int clickCount = 0;
|
||||
|
||||
// all touch scrolls are measured in pixels
|
||||
private static int touchBeginX = 0, touchBeginY = 0;
|
||||
private static int trackingId = 0;
|
||||
private static long lastTouchUpdateTime = 0;
|
||||
private static boolean isTouchScroll = false;
|
||||
private static final int TOUCH_CLICK_RADIUS = 10;
|
||||
// all touch scrolls are measured in pixels
|
||||
private static final int TOUCH_BEGIN = 2;
|
||||
private static final int TOUCH_UPDATE = 3;
|
||||
private static final int TOUCH_END = 4;
|
||||
|
||||
// used to check if we need to re-create surfaceData.
|
||||
int oldWidth = -1;
|
||||
@@ -812,42 +811,61 @@ class XWindow extends XBaseWindow implements X11ComponentPeer {
|
||||
x = localXY.x;
|
||||
y = localXY.y;
|
||||
}
|
||||
|
||||
int button = XConstants.buttons[0];
|
||||
int modifiers = getModifiers(dev.get_mods().get_effective(), button, 0);
|
||||
// turning off shift modifier
|
||||
modifiers &= ~InputEvent.SHIFT_DOWN_MASK;
|
||||
int modifiers = getModifiers(dev.get_mods().get_effective(), MouseEvent.BUTTON1, 0);
|
||||
int scrollModifiers = modifiers & ~InputEvent.SHIFT_DOWN_MASK;
|
||||
|
||||
long jWhen = XToolkit.nowMillisUTC_offset(dev.get_time());
|
||||
|
||||
switch (dev.get_evtype()) {
|
||||
case XConstants.XI_TouchBegin:
|
||||
if (eventLog.isLoggable(PlatformLogger.Level.FINEST)) {
|
||||
touchEventLog.finest("Touch Begin at: " + x + ", " + y);
|
||||
}
|
||||
isTouchScroll = false;
|
||||
touchBeginX = x;
|
||||
touchBeginY = y;
|
||||
sendWheelEventFromTouch(dev, jWhen, modifiers, touchBeginX, touchBeginY, TOUCH_BEGIN, 1);
|
||||
lastTouchUpdateTime = jWhen;
|
||||
sendWheelEventFromTouch(dev, jWhen, scrollModifiers, touchBeginX, touchBeginY, TouchEvent.TOUCH_BEGIN, 1);
|
||||
break;
|
||||
case XConstants.XI_TouchUpdate:
|
||||
if (eventLog.isLoggable(PlatformLogger.Level.FINEST)) {
|
||||
touchEventLog.finest("Touch Update at: " + x + ", " + y);
|
||||
}
|
||||
lastTouchUpdateTime = jWhen;
|
||||
|
||||
if (!isTouchScroll && isInsideTouchClickBoundaries(x, y)) {
|
||||
return;
|
||||
}
|
||||
isTouchScroll = true;
|
||||
|
||||
if (lastY - y != 0) {
|
||||
sendWheelEventFromTouch(dev, jWhen, modifiers, x, y, TOUCH_UPDATE, lastY - y);
|
||||
int deltaY = lastY - y;
|
||||
if (deltaY != 0) {
|
||||
if (eventLog.isLoggable(PlatformLogger.Level.FINEST)) {
|
||||
touchEventLog.finest("Vertical touch scroll, delta: " + deltaY);
|
||||
}
|
||||
sendWheelEventFromTouch(dev, jWhen, scrollModifiers, x, y, TouchEvent.TOUCH_UPDATE, deltaY);
|
||||
}
|
||||
// horizontal scroll
|
||||
if (lastX - x != 0) {
|
||||
modifiers |= InputEvent.SHIFT_DOWN_MASK;
|
||||
sendWheelEventFromTouch(dev, jWhen, modifiers, x, y, TOUCH_UPDATE, lastX - x);
|
||||
|
||||
int deltaX = lastX - x;
|
||||
if (deltaX != 0) {
|
||||
if (eventLog.isLoggable(PlatformLogger.Level.FINEST)) {
|
||||
touchEventLog.finest("Horizontal touch scroll, delta: " + deltaX);
|
||||
}
|
||||
int horizontalScrollMods = scrollModifiers | InputEvent.SHIFT_DOWN_MASK;
|
||||
sendWheelEventFromTouch(dev, jWhen, horizontalScrollMods, x, y, TouchEvent.TOUCH_UPDATE, deltaX);
|
||||
}
|
||||
break;
|
||||
case XConstants.XI_TouchEnd:
|
||||
sendWheelEventFromTouch(dev, jWhen, modifiers, x, y, TOUCH_END, 1);
|
||||
if (eventLog.isLoggable(PlatformLogger.Level.FINEST)) {
|
||||
touchEventLog.finest("Touch End at: " + x + ", " + y);
|
||||
}
|
||||
sendWheelEventFromTouch(dev, jWhen, scrollModifiers, x, y, TouchEvent.TOUCH_END, 1);
|
||||
|
||||
if (!isTouchScroll) {
|
||||
sendMouseEventFromTouch(dev, MouseEvent.MOUSE_PRESSED, jWhen, modifiers, touchBeginX, touchBeginY, button);
|
||||
sendMouseEventFromTouch(dev, MouseEvent.MOUSE_RELEASED, jWhen, modifiers, touchBeginX, touchBeginY, button);
|
||||
sendMouseEventFromTouch(dev, MouseEvent.MOUSE_CLICKED, jWhen, modifiers, touchBeginX, touchBeginY, button);
|
||||
if (eventLog.isLoggable(PlatformLogger.Level.FINEST)) {
|
||||
touchEventLog.finest("Touch Press at: " + x + ", " + y);
|
||||
}
|
||||
sendButtonPressFromTouch(dev, jWhen, modifiers, touchBeginX, touchBeginY);
|
||||
}
|
||||
|
||||
// release touch processing
|
||||
@@ -860,8 +878,8 @@ class XWindow extends XBaseWindow implements X11ComponentPeer {
|
||||
}
|
||||
|
||||
private boolean isInsideTouchClickBoundaries(int x, int y) {
|
||||
return Math.abs(touchBeginX - x) <= TOUCH_CLICK_RADIUS &&
|
||||
Math.abs(touchBeginY - y) <= TOUCH_CLICK_RADIUS;
|
||||
return Math.abs(touchBeginX - x) <= TouchEvent.CLICK_RADIUS &&
|
||||
Math.abs(touchBeginY - y) <= TouchEvent.CLICK_RADIUS;
|
||||
}
|
||||
|
||||
private static boolean isOwningTouch(int fingerId) {
|
||||
@@ -869,7 +887,24 @@ class XWindow extends XBaseWindow implements X11ComponentPeer {
|
||||
}
|
||||
|
||||
private static boolean isTouchReleased() {
|
||||
return trackingId == 0;
|
||||
if (trackingId == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// recovery from situation when TOUCH_END event didn't occurred
|
||||
long msFromLastUpdate = Math.abs(System.currentTimeMillis() - lastTouchUpdateTime);
|
||||
if (msFromLastUpdate >= TouchEvent.NO_UPDATE_TIMEOUT) {
|
||||
touchEventLog.warning("Release touch processing, milliseconds from last update: " + msFromLastUpdate);
|
||||
}
|
||||
return msFromLastUpdate >= TouchEvent.NO_UPDATE_TIMEOUT;
|
||||
}
|
||||
|
||||
private void sendButtonPressFromTouch(XIDeviceEvent dev, long jWhen, int modifiers, int x, int y) {
|
||||
sendMouseEventFromTouch(dev, MouseEvent.MOUSE_MOVED, jWhen, modifiers, x, y, MouseEvent.NOBUTTON, 0);
|
||||
sendMouseEventFromTouch(dev, MouseEvent.MOUSE_DRAGGED, jWhen, modifiers, x, y, MouseEvent.BUTTON1, 0);
|
||||
sendMouseEventFromTouch(dev, MouseEvent.MOUSE_PRESSED, jWhen, modifiers, x, y, MouseEvent.BUTTON1, 1);
|
||||
sendMouseEventFromTouch(dev, MouseEvent.MOUSE_RELEASED, jWhen, modifiers, x, y, MouseEvent.BUTTON1, 1);
|
||||
sendMouseEventFromTouch(dev, MouseEvent.MOUSE_CLICKED, jWhen, modifiers, x, y, MouseEvent.BUTTON1, 1);
|
||||
}
|
||||
|
||||
private void sendWheelEventFromTouch(XIDeviceEvent dev, long jWhen, int modifiers, int x, int y, int type, int delta) {
|
||||
@@ -883,15 +918,14 @@ class XWindow extends XBaseWindow implements X11ComponentPeer {
|
||||
1, delta));
|
||||
}
|
||||
|
||||
private void sendMouseEventFromTouch(XIDeviceEvent dev, int type, long jWhen, int modifiers, int x, int y, int button) {
|
||||
private void sendMouseEventFromTouch(XIDeviceEvent dev, int type, long jWhen, int modifiers, int x, int y, int button, int clickCount) {
|
||||
boolean popupTrigger = button == MouseEvent.BUTTON3;
|
||||
postEventToEventQueue(
|
||||
new MouseEvent(getEventSource(), type, jWhen,
|
||||
modifiers,
|
||||
x, y,
|
||||
modifiers, x, y,
|
||||
scaleDown((int) dev.get_root_x()),
|
||||
scaleDown((int) dev.get_root_y()),
|
||||
1,
|
||||
false, button));
|
||||
clickCount, popupTrigger, button));
|
||||
}
|
||||
|
||||
public void handleMotionNotify(XEvent xev) {
|
||||
|
||||
@@ -63,6 +63,7 @@
|
||||
#include <java_awt_event_InputEvent.h>
|
||||
#include <java_awt_event_ActionEvent.h>
|
||||
#include <java_awt_event_InputMethodEvent.h>
|
||||
#include <sun_awt_event_TouchEvent.h>
|
||||
#include <sun_awt_windows_WInputMethod.h>
|
||||
#include <java_awt_event_MouseEvent.h>
|
||||
#include <java_awt_event_MouseWheelEvent.h>
|
||||
@@ -225,7 +226,7 @@ AwtComponent::AwtComponent()
|
||||
m_mouseButtonClickAllowed = 0;
|
||||
|
||||
m_isTouchScroll = FALSE;
|
||||
m_touchDownPoint = {0, 0};
|
||||
m_touchBeginPoint = {0, 0};
|
||||
m_lastTouchPoint = {0, 0};
|
||||
|
||||
m_callbacksEnabled = FALSE;
|
||||
@@ -2360,8 +2361,8 @@ void AwtComponent::WmTouch(WPARAM wParam, LPARAM lParam) {
|
||||
|
||||
BOOL AwtComponent::IsInsideTouchClickBoundaries(POINT p)
|
||||
{
|
||||
return abs(p.x - m_touchDownPoint.x) <= TOUCH_MOUSE_COORDS_DELTA &&
|
||||
abs(p.y - m_touchDownPoint.y) <= TOUCH_MOUSE_COORDS_DELTA;
|
||||
return abs(p.x - m_touchBeginPoint.x) <= sun_awt_event_TouchEvent_CLICK_RADIUS &&
|
||||
abs(p.y - m_touchBeginPoint.y) <= sun_awt_event_TouchEvent_CLICK_RADIUS;
|
||||
}
|
||||
|
||||
POINT AwtComponent::TouchCoordsToLocal(LONG x, LONG y)
|
||||
@@ -2374,17 +2375,24 @@ POINT AwtComponent::TouchCoordsToLocal(LONG x, LONG y)
|
||||
void AwtComponent::SendMouseWheelEventFromTouch(POINT p, jint modifiers, jint scrollType, jint pixels)
|
||||
{
|
||||
SendMouseWheelEvent(java_awt_event_MouseEvent_MOUSE_WHEEL, ::JVM_CurrentTimeMillis(NULL, 0),
|
||||
p.x, p.y, modifiers, 0, 0, scrollType,
|
||||
/*scrollAmount*/ 1, pixels,
|
||||
p.x, p.y, modifiers, /*clickCount*/ 0, /*popupTrigger*/ JNI_FALSE,
|
||||
scrollType, /*scrollAmount*/ 1, pixels,
|
||||
static_cast<double>(pixels), /*msg*/ nullptr);
|
||||
}
|
||||
|
||||
void AwtComponent::SendMouseEventFromTouch(jint id, POINT p, jint modifiers)
|
||||
void AwtComponent::SendMouseEventFromTouch(jint id, POINT p, jint modifiers, jint clickCount, jint button)
|
||||
{
|
||||
SendMouseEvent(id, ::JVM_CurrentTimeMillis(NULL, 0), p.x, p.y,
|
||||
modifiers, /*clickCount*/ 1, JNI_FALSE,
|
||||
java_awt_event_MouseEvent_BUTTON1,
|
||||
/*msg*/ nullptr, /*causedByTouchEvent*/ TRUE);
|
||||
modifiers, clickCount, /*popupTrigger*/ JNI_FALSE,
|
||||
button, /*msg*/ nullptr, /*causedByTouchEvent*/ TRUE);
|
||||
}
|
||||
|
||||
void AwtComponent::SendButtonPressEventFromTouch(POINT p, jint modifiers)
|
||||
{
|
||||
SendMouseEventFromTouch(java_awt_event_MouseEvent_MOUSE_MOVED, p, modifiers, 0, java_awt_event_MouseEvent_NOBUTTON);
|
||||
SendMouseEventFromTouch(java_awt_event_MouseEvent_MOUSE_PRESSED, p, modifiers, 1, java_awt_event_MouseEvent_BUTTON1);
|
||||
SendMouseEventFromTouch(java_awt_event_MouseEvent_MOUSE_RELEASED, p, modifiers, 1, java_awt_event_MouseEvent_BUTTON1);
|
||||
SendMouseEventFromTouch(java_awt_event_MouseEvent_MOUSE_CLICKED, p, modifiers, 1, java_awt_event_MouseEvent_BUTTON1);
|
||||
}
|
||||
|
||||
void AwtComponent::WmTouchHandler(const TOUCHINPUT& touchInput)
|
||||
@@ -2394,43 +2402,39 @@ void AwtComponent::WmTouchHandler(const TOUCHINPUT& touchInput)
|
||||
return;
|
||||
}
|
||||
|
||||
jint modifiers = GetJavaModifiers();
|
||||
// turn off horizontal
|
||||
modifiers &= ~java_awt_event_InputEvent_SHIFT_DOWN_MASK;
|
||||
const jint modifiers = GetJavaModifiers();
|
||||
const POINT p = TouchCoordsToLocal(touchInput.x, touchInput.y);
|
||||
|
||||
if (touchInput.dwFlags & TOUCHEVENTF_DOWN) {
|
||||
m_touchDownPoint = p;
|
||||
m_lastTouchPoint = p;
|
||||
m_touchBeginPoint = p;
|
||||
m_isTouchScroll = FALSE;
|
||||
SendMouseWheelEventFromTouch(p, modifiers, TOUCH_BEGIN, 1);
|
||||
SendMouseWheelEventFromTouch(p, modifiers, sun_awt_event_TouchEvent_TOUCH_BEGIN, 1);
|
||||
} else if (touchInput.dwFlags & TOUCHEVENTF_MOVE) {
|
||||
if (!m_isTouchScroll && IsInsideTouchClickBoundaries(p)) {
|
||||
return;
|
||||
}
|
||||
m_isTouchScroll = TRUE;
|
||||
|
||||
const int deltaY = ScaleDownY(static_cast<int>(m_lastTouchPoint.y - p.y));
|
||||
if (abs(deltaY) != 0) {
|
||||
SendMouseWheelEventFromTouch(p, modifiers, TOUCH_UPDATE, deltaY);
|
||||
const jint deltaY = ScaleDownY(static_cast<int>(m_lastTouchPoint.y - p.y));
|
||||
if (deltaY != 0) {
|
||||
const jint scrollModifiers = modifiers & ~java_awt_event_InputEvent_SHIFT_DOWN_MASK;
|
||||
SendMouseWheelEventFromTouch(p, scrollModifiers, sun_awt_event_TouchEvent_TOUCH_UPDATE, deltaY);
|
||||
}
|
||||
|
||||
const int deltaX = ScaleDownX(static_cast<int>(m_lastTouchPoint.x - p.x));
|
||||
if (abs(deltaX) != 0) {
|
||||
modifiers |= java_awt_event_InputEvent_SHIFT_DOWN_MASK;
|
||||
SendMouseWheelEventFromTouch(p, modifiers, TOUCH_UPDATE, deltaX);
|
||||
const jint deltaX = ScaleDownX(static_cast<int>(m_lastTouchPoint.x - p.x));
|
||||
if (deltaX != 0) {
|
||||
const jint scrollModifiers = modifiers | java_awt_event_InputEvent_SHIFT_DOWN_MASK;
|
||||
SendMouseWheelEventFromTouch(p, scrollModifiers, sun_awt_event_TouchEvent_TOUCH_UPDATE, deltaX);
|
||||
}
|
||||
|
||||
m_lastTouchPoint = p;
|
||||
} else if (touchInput.dwFlags & TOUCHEVENTF_UP) {
|
||||
SendMouseWheelEventFromTouch(p, modifiers, TOUCH_END, 1);
|
||||
SendMouseWheelEventFromTouch(p, modifiers, sun_awt_event_TouchEvent_TOUCH_END, 1);
|
||||
|
||||
if (!m_isTouchScroll) {
|
||||
SendMouseEventFromTouch(java_awt_event_MouseEvent_MOUSE_PRESSED, p, modifiers);
|
||||
SendMouseEventFromTouch(java_awt_event_MouseEvent_MOUSE_RELEASED, p, modifiers);
|
||||
SendMouseEventFromTouch(java_awt_event_MouseEvent_MOUSE_CLICKED, p, modifiers);
|
||||
SendButtonPressEventFromTouch(p, modifiers);
|
||||
}
|
||||
}
|
||||
|
||||
m_lastTouchPoint = p;
|
||||
}
|
||||
|
||||
/* Double-click variables. */
|
||||
|
||||
@@ -67,14 +67,6 @@ const UINT MAX_ACP_STR_LEN = 7; // ANSI CP identifiers are no longer than this
|
||||
const int ALL_MK_BUTTONS = MK_LBUTTON|MK_MBUTTON|MK_RBUTTON;
|
||||
const int X_BUTTONS = MK_XBUTTON1|MK_XBUTTON2;
|
||||
|
||||
// The allowable difference between coordinates of the WM_TOUCH event and the
|
||||
// corresponding WM_LBUTTONDOWN/WM_LBUTTONUP event letting to associate these
|
||||
// events, when their coordinates are slightly different.
|
||||
const int TOUCH_MOUSE_COORDS_DELTA = 10;
|
||||
const int TOUCH_BEGIN = 2;
|
||||
const int TOUCH_UPDATE = 3;
|
||||
const int TOUCH_END = 4;
|
||||
|
||||
// Whether to check for embedded frame and adjust location
|
||||
#define CHECK_EMBEDDED 0
|
||||
#define DONT_CHECK_EMBEDDED 1
|
||||
@@ -540,7 +532,8 @@ public:
|
||||
BOOL IsInsideTouchClickBoundaries(POINT p);
|
||||
POINT TouchCoordsToLocal(LONG x, LONG y);
|
||||
void SendMouseWheelEventFromTouch(POINT p, jint modifiers, jint scrollType, jint pixels);
|
||||
void SendMouseEventFromTouch(jint id, POINT p, jint modifiers);
|
||||
void SendMouseEventFromTouch(jint id, POINT p, jint modifiers, jint clickCount, jint button);
|
||||
void SendButtonPressEventFromTouch(POINT p, jint modifiers);
|
||||
|
||||
// NB: 64-bit: vkey is wParam of the message, but other API's take
|
||||
// vkey parameters of type UINT, so we do the cast before dispatching.
|
||||
@@ -784,7 +777,7 @@ private:
|
||||
UINT m_mouseButtonClickAllowed;
|
||||
|
||||
BOOL m_isTouchScroll;
|
||||
POINT m_touchDownPoint;
|
||||
POINT m_touchBeginPoint;
|
||||
POINT m_lastTouchPoint;
|
||||
|
||||
BOOL m_bSubclassed;
|
||||
|
||||
Reference in New Issue
Block a user