Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(550)

Side by Side Diff: ui/base/touch/touch_device_win.cc

Issue 2737123003: Fix 'pointer', 'any-pointer', 'hover' and 'any-hover' value on detachable/convertible devices. (Closed)
Patch Set: Fix 'pointer', 'any-pointer', 'hover' and 'any-hover' value on detachable/convertible devices. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/win/win_util.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/base/touch/touch_device.h" 5 #include "ui/base/touch/touch_device.h"
6
6 #include "base/logging.h" 7 #include "base/logging.h"
7 #include "base/win/windows_version.h" 8 #include "base/win/win_util.h"
8 #include <windows.h>
9 9
10 namespace ui { 10 namespace ui {
11 11
12 namespace { 12 namespace {
13 13
14 bool IsTouchDevicePresent() { 14 bool IsTouchDevicePresent() {
15 int value = GetSystemMetrics(SM_DIGITIZER); 15 int value = GetSystemMetrics(SM_DIGITIZER);
16 return (value & NID_READY) && 16 return (value & NID_READY) &&
17 ((value & NID_INTEGRATED_TOUCH) || (value & NID_EXTERNAL_TOUCH)); 17 ((value & NID_INTEGRATED_TOUCH) || (value & NID_EXTERNAL_TOUCH));
18 } 18 }
19 19
20 // The following method logic is as follow :
21 // - On versions prior to Windows 8 it will always return POINTER_TYPE_FINE
22 // and/or POINTER_TYPE_COARSE (if the device has a touch screen).
23 // - If the device is a detachable/convertible win8/10 device and the keyboard/
24 // trackpad is detached/flipped it will always return POINTER_TYPE_COARSE.
25 // It does not cover the case where an external mouse/keyboard is connected
26 // while the device is used as a tablet. This is because Windows doesn't provide
27 // us a reliable way to detect keyboard/mouse presence with
28 // GetSystemMetrics(SM_MOUSEPRESENT).
29 // - If the device doesn't have a touch screen it will return POINTER_TYPE_FINE.
30 // In the rare cases (this is Microsoft documentation) where
31 // GetSystemMetrics(SM_MOUSEPRESENT) returns 0 we will return POINTER_TYPE_NONE.
32 // - If the device has a touch screen the available pointer devices are
33 // POINTER_TYPE_FINE and POINTER_TYPE_COARSE.
20 int GetAvailablePointerTypes() { 34 int GetAvailablePointerTypes() {
21 int available_pointer_types = 0; 35 // IsTabletDevice guarantees us that :
36 // - The device has a touch screen.
37 // - It is used as a tablet which means that it has no keyboard connected.
38 // On Windows 10 it means that it is verifying with ConvertibleSlateMode.
39 if (base::win::IsTabletDevice(nullptr))
40 return POINTER_TYPE_COARSE;
41
42 if (GetSystemMetrics(SM_MOUSEPRESENT) == 0)
43 return POINTER_TYPE_NONE;
44
45 int available_pointer_types = POINTER_TYPE_FINE;
22 if (IsTouchDevicePresent()) 46 if (IsTouchDevicePresent())
23 available_pointer_types |= POINTER_TYPE_COARSE; 47 available_pointer_types |= POINTER_TYPE_COARSE;
24 if (GetSystemMetrics(SM_MOUSEPRESENT) != 0 &&
25 GetSystemMetrics(SM_CMOUSEBUTTONS) > 0)
26 available_pointer_types |= POINTER_TYPE_FINE;
27
28 if (available_pointer_types == 0)
29 available_pointer_types = POINTER_TYPE_NONE;
30 48
31 return available_pointer_types; 49 return available_pointer_types;
32 } 50 }
33 51
52 // This method follows the same logic as above but with hover types.
34 int GetAvailableHoverTypes() { 53 int GetAvailableHoverTypes() {
35 int available_hover_types = 0; 54 if (base::win::IsTabletDevice(nullptr))
55 return HOVER_TYPE_ON_DEMAND;
56
57 if (GetSystemMetrics(SM_MOUSEPRESENT) == 0)
58 return HOVER_TYPE_NONE;
59
60 int available_hover_types = HOVER_TYPE_HOVER;
36 if (IsTouchDevicePresent()) 61 if (IsTouchDevicePresent())
37 available_hover_types |= HOVER_TYPE_ON_DEMAND; 62 available_hover_types |= HOVER_TYPE_ON_DEMAND;
38 if (GetSystemMetrics(SM_MOUSEPRESENT) != 0)
39 available_hover_types |= HOVER_TYPE_HOVER;
40
41 if (available_hover_types == 0)
42 available_hover_types = HOVER_TYPE_NONE;
43 63
44 return available_hover_types; 64 return available_hover_types;
45 } 65 }
46 66
47 } // namespace 67 } // namespace
48 68
49 TouchScreensAvailability GetTouchScreensAvailability() { 69 TouchScreensAvailability GetTouchScreensAvailability() {
50 if (!IsTouchDevicePresent()) 70 if (!IsTouchDevicePresent())
51 return TouchScreensAvailability::NONE; 71 return TouchScreensAvailability::NONE;
52 72
(...skipping 23 matching lines...) Expand all
76 return HOVER_TYPE_ON_DEMAND; 96 return HOVER_TYPE_ON_DEMAND;
77 DCHECK_EQ(available_hover_types, HOVER_TYPE_NONE); 97 DCHECK_EQ(available_hover_types, HOVER_TYPE_NONE);
78 return HOVER_TYPE_NONE; 98 return HOVER_TYPE_NONE;
79 } 99 }
80 100
81 std::pair<int, int> GetAvailablePointerAndHoverTypes() { 101 std::pair<int, int> GetAvailablePointerAndHoverTypes() {
82 return std::make_pair(GetAvailablePointerTypes(), GetAvailableHoverTypes()); 102 return std::make_pair(GetAvailablePointerTypes(), GetAvailableHoverTypes());
83 } 103 }
84 104
85 } // namespace ui 105 } // namespace ui
OLDNEW
« no previous file with comments | « base/win/win_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698