Bug 1511901 - Fix device name comparison in TouchDeviceNeedsPanGestureConversion(). r=cmartin
authorBotond Ballo <botond@mozilla.com>
Mon, 30 Sep 2019 19:43:35 +0000
changeset 495727 42727308025767aa9f53eaf149b13b154f537bc8
parent 495726 df723e7120dc878f3cec9cf8c6eda070ba16d115
child 495728 ac1436cdbaed91ac6169272767b1a2107032fc85
push id114140
push userdvarga@mozilla.com
push dateWed, 02 Oct 2019 18:04:51 +0000
treeherdermozilla-inbound@32eb0ea893f3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscmartin
bugs1511901
milestone71.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1511901 - Fix device name comparison in TouchDeviceNeedsPanGestureConversion(). r=cmartin Differential Revision: https://phabricator.services.mozilla.com/D45113
widget/windows/nsWindow.cpp
--- a/widget/windows/nsWindow.cpp
+++ b/widget/windows/nsWindow.cpp
@@ -6719,17 +6719,24 @@ bool TouchDeviceNeedsPanGestureConversio
   // The second call actually populates the string.
   UINT result = GetRawInputDeviceInfoA(source, RIDI_DEVICENAME, &deviceName[0],
                                        &dataSize);
   if (result == UINT_MAX) {
     return false;
   }
   // The affected device name is "\\?\VIRTUAL_DIGITIZER", but each backslash
   // needs to be escaped with another one.
-  if (deviceName != "\\\\?\\VIRTUAL_DIGITIZER") {
+  std::string expectedDeviceName = "\\\\?\\VIRTUAL_DIGITIZER";
+  // For some reason, the dataSize returned by the first call is double the
+  // actual length of the device name (as if it were returning the size of a
+  // wide-character string in bytes) even though we are using the narrow
+  // version of the API. For the comparison against the expected device name
+  // to pass, we truncate the buffer to be no longer tha the expected device
+  // name.
+  if (deviceName.substr(0, expectedDeviceName.length()) != expectedDeviceName) {
     return false;
   }
 
   RID_DEVICE_INFO deviceInfo;
   deviceInfo.cbSize = sizeof(deviceInfo);
   dataSize = sizeof(deviceInfo);
   result =
       GetRawInputDeviceInfoA(source, RIDI_DEVICEINFO, &deviceInfo, &dataSize);