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

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

Issue 2301073002: Optimization: avoid making 4 JNI calls to get touch device attributes. (Closed)
Patch Set: Correct a spelling mistake. Created 4 years, 3 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
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 #include "base/logging.h" 6 #include "base/logging.h"
7 #include "base/win/windows_version.h" 7 #include "base/win/windows_version.h"
8 #include <windows.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 PointerType GetPrimaryPointerType(int available_pointer_types) {
21 if (available_pointer_types & POINTER_TYPE_FINE)
22 return POINTER_TYPE_FINE;
23 if (available_pointer_types & POINTER_TYPE_COARSE)
24 return POINTER_TYPE_COARSE;
25 DCHECK_EQ(available_pointer_types, POINTER_TYPE_NONE);
26 return POINTER_TYPE_NONE;
27 }
28
29 int GetAvailableHoverTypes() {
30 int available_hover_types = 0;
31 if (IsTouchDevicePresent())
32 available_hover_types |= HOVER_TYPE_ON_DEMAND;
33 if (GetSystemMetrics(SM_MOUSEPRESENT) != 0)
34 available_hover_types |= HOVER_TYPE_HOVER;
35
36 if (available_hover_types == 0)
37 available_hover_types = HOVER_TYPE_NONE;
38
39 return available_hover_types;
40 }
41
20 } // namespace 42 } // namespace
21 43
22 TouchScreensAvailability GetTouchScreensAvailability() { 44 TouchScreensAvailability GetTouchScreensAvailability() {
23 if (!IsTouchDevicePresent()) 45 if (!IsTouchDevicePresent())
24 return TouchScreensAvailability::NONE; 46 return TouchScreensAvailability::NONE;
25 47
26 return TouchScreensAvailability::ENABLED; 48 return TouchScreensAvailability::ENABLED;
27 } 49 }
28 50
29 int MaxTouchPoints() { 51 int MaxTouchPoints() {
30 if (!IsTouchDevicePresent()) 52 if (!IsTouchDevicePresent())
31 return 0; 53 return 0;
32 54
33 return GetSystemMetrics(SM_MAXIMUMTOUCHES); 55 return GetSystemMetrics(SM_MAXIMUMTOUCHES);
34 } 56 }
35 57
58 std::pair<int, int> GetAvailablePointerAndHoverTypes() {
59 return std::make_pair(GetAvailablePointerTypes(), GetAvailableHoverTypes());
60 }
61
36 int GetAvailablePointerTypes() { 62 int GetAvailablePointerTypes() {
37 int available_pointer_types = 0; 63 int available_pointer_types = 0;
38 if (IsTouchDevicePresent()) 64 if (IsTouchDevicePresent())
39 available_pointer_types |= POINTER_TYPE_COARSE; 65 available_pointer_types |= POINTER_TYPE_COARSE;
40 if (GetSystemMetrics(SM_MOUSEPRESENT) != 0 && 66 if (GetSystemMetrics(SM_MOUSEPRESENT) != 0 &&
41 GetSystemMetrics(SM_CMOUSEBUTTONS) > 0) 67 GetSystemMetrics(SM_CMOUSEBUTTONS) > 0)
42 available_pointer_types |= POINTER_TYPE_FINE; 68 available_pointer_types |= POINTER_TYPE_FINE;
43 69
44 if (available_pointer_types == 0) 70 if (available_pointer_types == 0)
45 available_pointer_types = POINTER_TYPE_NONE; 71 available_pointer_types = POINTER_TYPE_NONE;
46 72
47 return available_pointer_types; 73 return available_pointer_types;
48 } 74 }
49 75
50 PointerType GetPrimaryPointerType() { 76 HoverType GetPrimaryHoverType(int available_hover_types) {
51 int available_pointer_types = GetAvailablePointerTypes();
52 if (available_pointer_types & POINTER_TYPE_FINE)
53 return POINTER_TYPE_FINE;
54 if (available_pointer_types & POINTER_TYPE_COARSE)
55 return POINTER_TYPE_COARSE;
56 DCHECK_EQ(available_pointer_types, POINTER_TYPE_NONE);
57 return POINTER_TYPE_NONE;
58 }
59
60 int GetAvailableHoverTypes() {
61 int available_hover_types = 0;
62 if (IsTouchDevicePresent())
63 available_hover_types |= HOVER_TYPE_ON_DEMAND;
64 if (GetSystemMetrics(SM_MOUSEPRESENT) != 0)
65 available_hover_types |= HOVER_TYPE_HOVER;
66
67 if (available_hover_types == 0)
68 available_hover_types = HOVER_TYPE_NONE;
69
70 return available_hover_types;
71 }
72
73 HoverType GetPrimaryHoverType() {
74 int available_hover_types = GetAvailableHoverTypes();
75 if (available_hover_types & HOVER_TYPE_HOVER) 77 if (available_hover_types & HOVER_TYPE_HOVER)
76 return HOVER_TYPE_HOVER; 78 return HOVER_TYPE_HOVER;
77 if (available_hover_types & HOVER_TYPE_ON_DEMAND) 79 if (available_hover_types & HOVER_TYPE_ON_DEMAND)
78 return HOVER_TYPE_ON_DEMAND; 80 return HOVER_TYPE_ON_DEMAND;
79 DCHECK_EQ(available_hover_types, HOVER_TYPE_NONE); 81 DCHECK_EQ(available_hover_types, HOVER_TYPE_NONE);
80 return HOVER_TYPE_NONE; 82 return HOVER_TYPE_NONE;
81 } 83 }
82 84
83 } // namespace ui 85 } // namespace ui
OLDNEW
« ui/base/touch/touch_device.cc ('K') | « ui/base/touch/touch_device_linux.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698