Bug 640587 - Disable the swipe gesture half of the Elantech hack for driver versions < 8. r=jimm
authorCameron McCormack <cam@mcc.id.au>
Thu, 23 Jun 2011 08:48:24 +1200
changeset 71818 1d90c5f569a2a7fbe477cdd41517ba724f2fcbf0
parent 71817 cd95d565c4d9dac1318ca3f1e6e7bc4ff9dd1372
child 71819 37db25250817ccb627a212a730ef6e0911974a1e
push id209
push userbzbarsky@mozilla.com
push dateTue, 05 Jul 2011 17:42:16 +0000
treeherdermozilla-aurora@cc6e30cce8af [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjimm
bugs640587
milestone7.0a1
Bug 640587 - Disable the swipe gesture half of the Elantech hack for driver versions < 8. r=jimm
widget/src/windows/nsWindow.cpp
widget/src/windows/nsWindow.h
--- a/widget/src/windows/nsWindow.cpp
+++ b/widget/src/windows/nsWindow.cpp
@@ -269,18 +269,20 @@ BYTE            nsWindow::sLastMouseButt
 
 // Trim heap on minimize. (initialized, but still true.)
 int             nsWindow::sTrimOnMinimize         = 2;
 
 // Default value for Trackpoint hack (used when the pref is set to -1).
 PRBool          nsWindow::sDefaultTrackPointHack  = PR_FALSE;
 // Default value for general window class (used when the pref is the empty string).
 const char*     nsWindow::sDefaultMainWindowClass = kClassNameGeneral;
-// Whether to enable the Elantech gesture hack.
-PRBool          nsWindow::sUseElantechGestureHacks = PR_FALSE;
+// Whether to enable the Elantech swipe gesture hack.
+PRBool          nsWindow::sUseElantechSwipeHack  = PR_FALSE;
+// Whether to enable the Elantech pinch-to-zoom gesture hack.
+PRBool          nsWindow::sUseElantechPinchHack  = PR_FALSE;
 
 // If we're using D3D9, this will not be allowed during initial 5 seconds.
 bool            nsWindow::sAllowD3D9              = false;
 
 TriStateBool nsWindow::sHasBogusPopupsDropShadowOnMultiMonitor = TRI_UNKNOWN;
 
 #ifdef ACCESSIBILITY
 BOOL            nsWindow::sIsAccessibilityOn      = FALSE;
@@ -6646,17 +6648,17 @@ LRESULT nsWindow::OnKeyDown(const MSG &a
                             nsModifierKeyState &aModKeyState,
                             PRBool *aEventDispatched,
                             nsFakeCharMessage* aFakeCharMessage)
 {
   UINT virtualKeyCode =
     aMsg.wParam != VK_PROCESSKEY ? aMsg.wParam : ::ImmGetVirtualKey(mWnd);
   gKbdLayout.OnKeyDown(virtualKeyCode);
 
-  if (sUseElantechGestureHacks) {
+  if (sUseElantechSwipeHack) {
     PerformElantechSwipeGestureHack(virtualKeyCode, aModKeyState);
   }
 
   // Use only DOMKeyCode for XP processing.
   // Use virtualKeyCode for gKbdLayout and native processing.
   UINT DOMKeyCode = nsIMM32Handler::IsComposingOn(this) ?
                       virtualKeyCode : MapFromNativeToDOM(virtualKeyCode);
 
@@ -6989,19 +6991,21 @@ LRESULT nsWindow::OnKeyDown(const MSG &a
 
 // OnKeyUp
 LRESULT nsWindow::OnKeyUp(const MSG &aMsg,
                           nsModifierKeyState &aModKeyState,
                           PRBool *aEventDispatched)
 {
   UINT virtualKeyCode = aMsg.wParam;
 
-  if (sUseElantechGestureHacks) {
+  if (sUseElantechSwipeHack) {
     PerformElantechSwipeGestureHack(virtualKeyCode, aModKeyState);
-
+  }
+
+  if (sUseElantechPinchHack) {
     // Version 8 of the Elantech touchpad driver sends these messages for
     // zoom gestures:
     //
     //   WM_KEYDOWN    virtual_key = 0xCC        time = 10
     //   WM_KEYDOWN    virtual_key = VK_CONTROL  time = 10
     //   WM_MOUSEWHEEL                           time = ::GetTickCount()
     //   WM_KEYUP      virtual_key = VK_CONTROL  time = 10
     //   WM_KEYUP      virtual_key = 0xCC        time = 10
@@ -7604,17 +7608,17 @@ PRBool nsWindow::HandleScrollingPlugins(
   }
 
   HWND destWnd = ::WindowFromPoint(point);
   // Since we receive scroll events for as long as
   // we are focused, it's entirely possible that there
   // is another app's window or no window under the
   // pointer.
 
-  if (sUseElantechGestureHacks && IsElantechHelperWindow(destWnd)) {
+  if (sUseElantechPinchHack && IsElantechHelperWindow(destWnd)) {
     // The Elantech driver places a window right underneath the cursor
     // when sending a WM_MOUSEWHEEL event to us as part of a pinch-to-zoom
     // gesture.  We detect that here, and search for our window that would
     // be beneath the cursor if that window wasn't there.
     destWnd = FindOurWindowAtPoint(point);
   }
 
   if (!destWnd) {
@@ -8878,18 +8882,18 @@ IsObsoleteSynapticsDriver()
                                    sizeof buf);
   if (!foundKey)
     return PR_FALSE;
 
   int majorVersion = wcstol(buf, NULL, 10);
   return majorVersion < 15;
 }
 
-static PRBool
-IsObsoleteElantechDriver()
+static PRInt32
+GetElantechDriverMajorVersion()
 {
   PRUnichar buf[40];
   // The driver version is found in one of these two registry keys.
   PRBool foundKey = GetRegistryKey(HKEY_CURRENT_USER,
                                    L"Software\\Elantech\\MainOption",
                                    L"DriverVersion",
                                    buf,
                                    sizeof buf);
@@ -8902,43 +8906,44 @@ IsObsoleteElantechDriver()
 
   if (!foundKey)
     return PR_FALSE;
 
   // Assume that the major version number can be found just after a space
   // or at the start of the string.
   for (PRUnichar* p = buf; *p; p++) {
     if (*p >= L'0' && *p <= L'9' && (p == buf || *(p - 1) == L' ')) {
-      int majorVersion = wcstol(p, NULL, 10);
-      // Versions 7 and 8 need the hack.
-      if (majorVersion == 7 || majorVersion == 8)
-        return PR_TRUE;
-    }
-  }
-
-  return PR_FALSE;
+      return wcstol(p, NULL, 10);
+    }
+  }
+
+  return 0;
 }
 
 void nsWindow::InitInputWorkaroundPrefDefaults()
 {
+  PRUint32 elantechDriverVersion = GetElantechDriverMajorVersion();
+
   if (HasRegistryKey(HKEY_CURRENT_USER, L"Software\\Lenovo\\TrackPoint")) {
     sDefaultTrackPointHack = PR_TRUE;
   } else if (HasRegistryKey(HKEY_CURRENT_USER, L"Software\\Lenovo\\UltraNav")) {
     sDefaultTrackPointHack = PR_TRUE;
   } else if (HasRegistryKey(HKEY_CURRENT_USER, L"Software\\Alps\\Apoint\\TrackPoint")) {
     sDefaultTrackPointHack = PR_TRUE;
   } else if ((HasRegistryKey(HKEY_CURRENT_USER, L"Software\\Synaptics\\SynTPEnh\\UltraNavUSB") ||
               HasRegistryKey(HKEY_CURRENT_USER, L"Software\\Synaptics\\SynTPEnh\\UltraNavPS2")) &&
-              IsObsoleteSynapticsDriver()) {
+              elantechDriverVersion != 0 && elantechDriverVersion <= 8) {
     sDefaultTrackPointHack = PR_TRUE;
   }
 
-  sUseElantechGestureHacks =
+  PRBool useElantechGestureHacks =
     GetInputWorkaroundPref("ui.elantech_gesture_hacks.enabled",
-                           IsObsoleteElantechDriver());
+                           elantechDriverVersion != 0);
+  sUseElantechSwipeHack = useElantechGestureHacks && elantechDriverVersion <= 7;
+  sUseElantechPinchHack = useElantechGestureHacks && elantechDriverVersion <= 8;
 }
 
 LPARAM nsWindow::lParamToScreen(LPARAM lParam)
 {
   POINT pt;
   pt.x = GET_X_LPARAM(lParam);
   pt.y = GET_Y_LPARAM(lParam);
   ::ClientToScreen(mWnd, &pt);
--- a/widget/src/windows/nsWindow.h
+++ b/widget/src/windows/nsWindow.h
@@ -521,17 +521,18 @@ protected:
   static imgIContainer* sCursorImgContainer;
   static PRBool         sSwitchKeyboardLayout;
   static PRBool         sJustGotDeactivate;
   static PRBool         sJustGotActivate;
   static PRBool         sIsInMouseCapture;
   static int            sTrimOnMinimize;
   static PRBool         sDefaultTrackPointHack;
   static const char*    sDefaultMainWindowClass;
-  static PRBool         sUseElantechGestureHacks;
+  static PRBool         sUseElantechSwipeHack;
+  static PRBool         sUseElantechPinchHack;
   static bool           sAllowD3D9;
 
   // Always use the helper method to read this property.  See bug 603793.
   static TriStateBool   sHasBogusPopupsDropShadowOnMultiMonitor;
   static bool           HasBogusPopupsDropShadowOnMultiMonitor();
 
   static PRUint32       sOOPPPluginFocusEvent;