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

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 "base/logging.h"
6 #include "base/win/win_util.h"
5 #include "ui/base/touch/touch_device.h" 7 #include "ui/base/touch/touch_device.h"
grt (UTC plus 2) 2017/03/09 09:39:17 since this is conceptually the .h corresponding to
6 #include "base/logging.h"
7 #include "base/win/windows_version.h"
8 #include <windows.h>
9 8
10 namespace ui { 9 namespace ui {
11 10
12 namespace { 11 namespace {
13 12
14 bool IsTouchDevicePresent() { 13 bool IsTouchDevicePresent() {
15 int value = GetSystemMetrics(SM_DIGITIZER); 14 int value = GetSystemMetrics(SM_DIGITIZER);
16 return (value & NID_READY) && 15 return (value & NID_READY) &&
17 ((value & NID_INTEGRATED_TOUCH) || (value & NID_EXTERNAL_TOUCH)); 16 ((value & NID_INTEGRATED_TOUCH) || (value & NID_EXTERNAL_TOUCH));
18 } 17 }
19 18
19 // The following method logic is as follow :
20 // - On versions prior to Windows 8 it will always return POINTER_TYPE_FINE
21 // and/or POINTER_TYPE_COARSE (if the device has a touch screen).
22 // - If the device is a detachable/convertible win8/10 device and the keyboard/
23 // trackpad is detached/flipped it will always return POINTER_TYPE_COARSE.
24 // It does not cover the case where an external mouse/keyboard is connected
25 // while the device is used as a tablet. This is because Windows doesn't provide
26 // us a reliable way to detect keyboard/mouse presence with
27 // GetSystemMetrics(SM_MOUSEPRESENT).
28 // - If the device doesn't have a touch screen it will return POINTER_TYPE_FINE.
29 // In the rare cases (this is Microsoft documentation) where
30 // GetSystemMetrics(SM_MOUSEPRESENT) returns 0 we will return POINTER_TYPE_NONE.
31 // - If the device has a touch screen the available pointer devices are
32 // POINTER_TYPE_FINE and POINTER_TYPE_COARSE.
20 int GetAvailablePointerTypes() { 33 int GetAvailablePointerTypes() {
21 int available_pointer_types = 0; 34 // IsTabletDevice guarantees us that :
35 // - The device has a touch screen.
36 // - It is used as a tablet which means that it has no keyboard connected.
37 // On Windows 10 it means that it is verifying with ConvertibleSlateMode.
38 if (base::win::IsTabletDevice(nullptr))
39 return POINTER_TYPE_COARSE;
40
41 if (GetSystemMetrics(SM_MOUSEPRESENT) == 0)
42 return POINTER_TYPE_NONE;
43
44 int available_pointer_types = POINTER_TYPE_FINE;
22 if (IsTouchDevicePresent()) 45 if (IsTouchDevicePresent())
23 available_pointer_types |= POINTER_TYPE_COARSE; 46 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 47
31 return available_pointer_types; 48 return available_pointer_types;
32 } 49 }
33 50
51 // This method follows the same logic as above but with hover types.
34 int GetAvailableHoverTypes() { 52 int GetAvailableHoverTypes() {
35 int available_hover_types = 0; 53 if (base::win::IsTabletDevice(nullptr))
54 return HOVER_TYPE_ON_DEMAND;
55
56 if (GetSystemMetrics(SM_MOUSEPRESENT) == 0)
57 return HOVER_TYPE_NONE;
58
59 int available_hover_types = HOVER_TYPE_HOVER;
36 if (IsTouchDevicePresent()) 60 if (IsTouchDevicePresent())
37 available_hover_types |= HOVER_TYPE_ON_DEMAND; 61 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 62
44 return available_hover_types; 63 return available_hover_types;
45 } 64 }
46 65
47 } // namespace 66 } // namespace
48 67
49 TouchScreensAvailability GetTouchScreensAvailability() { 68 TouchScreensAvailability GetTouchScreensAvailability() {
50 if (!IsTouchDevicePresent()) 69 if (!IsTouchDevicePresent())
51 return TouchScreensAvailability::NONE; 70 return TouchScreensAvailability::NONE;
52 71
(...skipping 23 matching lines...) Expand all
76 return HOVER_TYPE_ON_DEMAND; 95 return HOVER_TYPE_ON_DEMAND;
77 DCHECK_EQ(available_hover_types, HOVER_TYPE_NONE); 96 DCHECK_EQ(available_hover_types, HOVER_TYPE_NONE);
78 return HOVER_TYPE_NONE; 97 return HOVER_TYPE_NONE;
79 } 98 }
80 99
81 std::pair<int, int> GetAvailablePointerAndHoverTypes() { 100 std::pair<int, int> GetAvailablePointerAndHoverTypes() {
82 return std::make_pair(GetAvailablePointerTypes(), GetAvailableHoverTypes()); 101 return std::make_pair(GetAvailablePointerTypes(), GetAvailableHoverTypes());
83 } 102 }
84 103
85 } // namespace ui 104 } // 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