4419271: Provide support for scrolling-mechanisms of non-mouse input-devices
Reviewed-by: alexsch, malenkov
--- a/jdk/src/java.desktop/windows/native/libawt/windows/awt_Component.cpp Tue Dec 06 14:10:33 2016 +0530
+++ b/jdk/src/java.desktop/windows/native/libawt/windows/awt_Component.cpp Tue Dec 06 15:50:22 2016 -0800
@@ -251,7 +251,8 @@
m_bPauseDestroy = FALSE;
m_MessagesProcessing = 0;
- m_wheelRotationAmount = 0;
+ m_wheelRotationAmountX = 0;
+ m_wheelRotationAmountY = 0;
if (!sm_PrimaryDynamicTableBuilt) {
// do it once.
AwtComponent::BuildPrimaryDynamicTable();
@@ -1208,6 +1209,7 @@
WIN_MSG(WM_XBUTTONDOWN)
WIN_MSG(WM_XBUTTONUP)
WIN_MSG(WM_MOUSEWHEEL)
+ WIN_MSG(WM_MOUSEHWHEEL)
WIN_MSG(WM_PARENTNOTIFY)
WIN_MSG(WM_ENTERMENULOOP)
WIN_MSG(WM_EXITMENULOOP)
@@ -1639,6 +1641,7 @@
case WM_XBUTTONUP:
case WM_MOUSEMOVE:
case WM_MOUSEWHEEL:
+ case WM_MOUSEHWHEEL:
case WM_AWT_MOUSEENTER:
case WM_AWT_MOUSEEXIT:
curPos = ::GetMessagePos();
@@ -1708,10 +1711,12 @@
case WM_AWT_MOUSEEXIT:
mr = WmMouseExit(static_cast<UINT>(wParam), myPos.x, myPos.y);
break;
- case WM_MOUSEWHEEL:
+ case WM_MOUSEWHEEL:
+ case WM_MOUSEHWHEEL:
mr = WmMouseWheel(GET_KEYSTATE_WPARAM(wParam),
GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam),
- GET_WHEEL_DELTA_WPARAM(wParam));
+ GET_WHEEL_DELTA_WPARAM(wParam),
+ switchMessage == WM_MOUSEHWHEEL);
break;
}
break;
@@ -2078,13 +2083,15 @@
MsgRouting AwtComponent::WmSetFocus(HWND hWndLostFocus)
{
- m_wheelRotationAmount = 0;
+ m_wheelRotationAmountX = 0;
+ m_wheelRotationAmountY = 0;
return mrDoDefault;
}
MsgRouting AwtComponent::WmKillFocus(HWND hWndGotFocus)
{
- m_wheelRotationAmount = 0;
+ m_wheelRotationAmountX = 0;
+ m_wheelRotationAmountY = 0;
return mrDoDefault;
}
@@ -2461,7 +2468,7 @@
}
MsgRouting AwtComponent::WmMouseWheel(UINT flags, int x, int y,
- int wheelRotation)
+ int wheelRotation, BOOL isHorizontal)
{
// convert coordinates to be Component-relative, not screen relative
// for wheeling when outside the window, this works similar to
@@ -2475,42 +2482,54 @@
// set some defaults
jint scrollType = java_awt_event_MouseWheelEvent_WHEEL_UNIT_SCROLL;
- jint scrollLines = 3;
+ jint scrollUnits = 3;
BOOL result;
- UINT platformLines;
-
- m_wheelRotationAmount += wheelRotation;
+ UINT platformUnits;
+ jint roundedWheelRotation;
+ jdouble preciseWheelRotation;
// AWT interprets wheel rotation differently than win32, so we need to
// decode wheel amount.
- jint roundedWheelRotation = m_wheelRotationAmount / (-1 * WHEEL_DELTA);
- jdouble preciseWheelRotation = (jdouble) wheelRotation / (-1 * WHEEL_DELTA);
+ jint modifiers = GetJavaModifiers();
+ if (isHorizontal) {
+ modifiers |= java_awt_event_InputEvent_SHIFT_DOWN_MASK;
+ m_wheelRotationAmountX += wheelRotation;
+ roundedWheelRotation = m_wheelRotationAmountX / (WHEEL_DELTA);
+ preciseWheelRotation = (jdouble) wheelRotation / (WHEEL_DELTA);
+ result = ::SystemParametersInfo(SPI_GETWHEELSCROLLCHARS, 0,
+ &platformUnits, 0);
+ } else {
+ m_wheelRotationAmountY += wheelRotation;
+ roundedWheelRotation = m_wheelRotationAmountY / (-1 * WHEEL_DELTA);
+ preciseWheelRotation = (jdouble) wheelRotation / (-1 * WHEEL_DELTA);
+ result = ::SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0,
+ &platformUnits, 0);
+ }
MSG msg;
- result = ::SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0,
- &platformLines, 0);
InitMessage(&msg, lastMessage, MAKEWPARAM(flags, wheelRotation),
MAKELPARAM(x, y));
if (result) {
- if (platformLines == WHEEL_PAGESCROLL) {
+ if (platformUnits == WHEEL_PAGESCROLL) {
scrollType = java_awt_event_MouseWheelEvent_WHEEL_BLOCK_SCROLL;
- scrollLines = 1;
+ scrollUnits = 1;
}
else {
scrollType = java_awt_event_MouseWheelEvent_WHEEL_UNIT_SCROLL;
- scrollLines = platformLines;
+ scrollUnits = platformUnits;
}
}
DTRACE_PRINTLN("calling SendMouseWheelEvent");
SendMouseWheelEvent(java_awt_event_MouseEvent_MOUSE_WHEEL, ::JVM_CurrentTimeMillis(NULL, 0),
- eventPt.x, eventPt.y, GetJavaModifiers(), 0, 0, scrollType,
- scrollLines, roundedWheelRotation, preciseWheelRotation, &msg);
-
- m_wheelRotationAmount %= WHEEL_DELTA;
+ eventPt.x, eventPt.y, modifiers, 0, 0, scrollType,
+ scrollUnits, roundedWheelRotation, preciseWheelRotation, &msg);
+
+ m_wheelRotationAmountX %= WHEEL_DELTA;
+ m_wheelRotationAmountY %= WHEEL_DELTA;
// this message could be propagated up to the parent chain
// by the mouse message post processors
return mrConsume;
--- a/jdk/src/java.desktop/windows/native/libawt/windows/awt_Component.h Tue Dec 06 14:10:33 2016 +0530
+++ b/jdk/src/java.desktop/windows/native/libawt/windows/awt_Component.h Tue Dec 06 15:50:22 2016 -0800
@@ -522,7 +522,7 @@
virtual MsgRouting WmMouseMove(UINT flags, int x, int y);
virtual MsgRouting WmMouseExit(UINT flags, int x, int y);
virtual MsgRouting WmMouseWheel(UINT flags, int x, int y,
- int wheelRotation);
+ int wheelRotation, BOOL isHorizontal);
virtual MsgRouting WmNcMouseDown(WPARAM hitTest, int x, int y, int button);
virtual MsgRouting WmNcMouseUp(WPARAM hitTest, int x, int y, int button);
virtual MsgRouting WmWindowPosChanging(LPARAM windowPos);
@@ -824,7 +824,8 @@
int windowMoveLockPosCY;
// 6524352: support finer-resolution
- int m_wheelRotationAmount;
+ int m_wheelRotationAmountX;
+ int m_wheelRotationAmountY;
BOOL deadKeyActive;
--- a/jdk/src/java.desktop/windows/native/libawt/windows/awt_Dialog.cpp Tue Dec 06 14:10:33 2016 +0530
+++ b/jdk/src/java.desktop/windows/native/libawt/windows/awt_Dialog.cpp Tue Dec 06 15:50:22 2016 -0800
@@ -240,6 +240,7 @@
(wParam == WM_RBUTTONDOWN) ||
(wParam == WM_MOUSEACTIVATE) ||
(wParam == WM_MOUSEWHEEL) ||
+ (wParam == WM_MOUSEHWHEEL) ||
(wParam == WM_NCLBUTTONDOWN) ||
(wParam == WM_NCMBUTTONDOWN) ||
(wParam == WM_NCRBUTTONDOWN))
--- a/jdk/src/java.desktop/windows/native/libawt/windows/awt_Toolkit.cpp Tue Dec 06 14:10:33 2016 +0530
+++ b/jdk/src/java.desktop/windows/native/libawt/windows/awt_Toolkit.cpp Tue Dec 06 15:50:22 2016 -0800
@@ -1590,7 +1590,7 @@
* the mouse, not the Component with the input focus.
*/
- if (msg.message == WM_MOUSEWHEEL) {
+ if (msg.message == WM_MOUSEWHEEL || msg.message == WM_MOUSEHWHEEL) {
//i.e. mouse is over client area for this window
DWORD hWndForWheelProcess;
DWORD hWndForWheelThread = ::GetWindowThreadProcessId(hWndForWheel, &hWndForWheelProcess);
--- a/jdk/src/java.desktop/windows/native/libawt/windows/awtmsg.h Tue Dec 06 14:10:33 2016 +0530
+++ b/jdk/src/java.desktop/windows/native/libawt/windows/awtmsg.h Tue Dec 06 15:50:22 2016 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1996, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1996, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -45,6 +45,10 @@
#define WM_MOUSEWHEEL 0x020A
#endif //WM_MOUSEWHEEL
+#ifndef WM_MOUSEHWHEEL
+#define WM_MOUSEHWHEEL 0x020E
+#endif //WM_MOUSEHWHEEL
+
#ifndef WHEEL_DELTA
#define WHEEL_DELTA 120
#endif //WHEEL_DELTA
@@ -54,12 +58,16 @@
#endif //WHEEL_PAGESCROLL
#ifndef SPI_GETWHEELSCROLLLINES
-#define SPI_GETWHEELSCROLLLINES 104
+#define SPI_GETWHEELSCROLLLINES 0x0068
#endif //SPI_GETWHEELSCROLLLINES
+#ifndef SPI_GETWHEELSCROLLCHARS
+#define SPI_GETWHEELSCROLLCHARS 0x006C
+#endif //SPI_GETWHEELSCROLLCHARS
+
#ifndef SM_MOUSEWHEELPRESENT
#define SM_MOUSEWHEELPRESENT 75
-#endif //SPI_GETWHEELSCROLLLINES
+#endif //SM_MOUSEWHEELPRESENT
#ifndef COLOR_HOTLIGHT
#define COLOR_HOTLIGHT 26
--- a/jdk/test/javax/swing/plaf/basic/BasicScrollPaneUI/8166591/TooMuchWheelRotationEventsTest.java Tue Dec 06 14:10:33 2016 +0530
+++ b/jdk/test/javax/swing/plaf/basic/BasicScrollPaneUI/8166591/TooMuchWheelRotationEventsTest.java Tue Dec 06 15:50:22 2016 -0800
@@ -44,20 +44,20 @@
* @key headful
* @summary [macos 10.12] Trackpad scrolling of text on OS X 10.12 Sierra
* is very fast (Trackpad, Retina only)
+ * @requires (os.family == "windows" | os.family == "mac")
* @run main/manual/othervm TooMuchWheelRotationEventsTest
*/
public class TooMuchWheelRotationEventsTest {
private static volatile boolean testResult = false;
private static volatile CountDownLatch countDownLatch;
- private static final String INSTRUCTIONS = "INSTRUCTIONS:\n"
- + "Try to check the issue on Mac OS X 10.12 Sierra with trackpad"
- + " on Retina display.\n"
+ private static final String INSTRUCTIONS = " INSTRUCTIONS:\n"
+ + " Try to check the issue with trackpad\n"
+ "\n"
- + "If the trackpad is not supported, press PASS\n"
+ + " If the trackpad is not supported, press PASS\n"
+ "\n"
- + "Use the trackpad to slightly scroll the JTextArea horizontally and vertically.\n"
- + "If the text area is scrolled too fast press FAIL, else press PASS.";
+ + " Use the trackpad to slightly scroll the JTextArea horizontally and vertically.\n"
+ + " If the text area is scrolled too fast press FAIL, else press PASS.";
public static void main(String args[]) throws Exception {
countDownLatch = new CountDownLatch(1);
@@ -138,6 +138,7 @@
countDownLatch.countDown();
}
});
+ mainFrame.setLocationRelativeTo(null);
mainFrame.setVisible(true);
}