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

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: 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 {
(...skipping 15 matching lines...) Expand all
26 return TouchScreensAvailability::ENABLED; 26 return TouchScreensAvailability::ENABLED;
27 } 27 }
28 28
29 int MaxTouchPoints() { 29 int MaxTouchPoints() {
30 if (!IsTouchDevicePresent()) 30 if (!IsTouchDevicePresent())
31 return 0; 31 return 0;
32 32
33 return GetSystemMetrics(SM_MAXIMUMTOUCHES); 33 return GetSystemMetrics(SM_MAXIMUMTOUCHES);
34 } 34 }
35 35
36 std::pair<int, int> GetAvailablePointerAndHoverTypes() {
37 return std::make_pair(GetAvailablePointerTypes(), GetAvailableHoverTypes());
38 }
39
36 int GetAvailablePointerTypes() { 40 int GetAvailablePointerTypes() {
37 int available_pointer_types = 0; 41 int available_pointer_types = 0;
38 if (IsTouchDevicePresent()) 42 if (IsTouchDevicePresent())
39 available_pointer_types |= POINTER_TYPE_COARSE; 43 available_pointer_types |= POINTER_TYPE_COARSE;
40 if (GetSystemMetrics(SM_MOUSEPRESENT) != 0 && 44 if (GetSystemMetrics(SM_MOUSEPRESENT) != 0 &&
41 GetSystemMetrics(SM_CMOUSEBUTTONS) > 0) 45 GetSystemMetrics(SM_CMOUSEBUTTONS) > 0)
42 available_pointer_types |= POINTER_TYPE_FINE; 46 available_pointer_types |= POINTER_TYPE_FINE;
43 47
44 if (available_pointer_types == 0) 48 if (available_pointer_types == 0)
45 available_pointer_types = POINTER_TYPE_NONE; 49 available_pointer_types = POINTER_TYPE_NONE;
46 50
47 return available_pointer_types; 51 return available_pointer_types;
48 } 52 }
49 53
50 PointerType GetPrimaryPointerType() { 54 PointerType GetPrimaryPointerType(int available_pointer_types) {
51 int available_pointer_types = GetAvailablePointerTypes();
52 if (available_pointer_types & POINTER_TYPE_FINE) 55 if (available_pointer_types & POINTER_TYPE_FINE)
53 return POINTER_TYPE_FINE; 56 return POINTER_TYPE_FINE;
54 if (available_pointer_types & POINTER_TYPE_COARSE) 57 if (available_pointer_types & POINTER_TYPE_COARSE)
55 return POINTER_TYPE_COARSE; 58 return POINTER_TYPE_COARSE;
56 DCHECK_EQ(available_pointer_types, POINTER_TYPE_NONE); 59 DCHECK_EQ(available_pointer_types, POINTER_TYPE_NONE);
57 return POINTER_TYPE_NONE; 60 return POINTER_TYPE_NONE;
58 } 61 }
59 62
63 PointerType GetPrimaryPointerType() {
64 return GetPrimaryPointerType(GetAvailablePointerTypes());
65 }
66
60 int GetAvailableHoverTypes() { 67 int GetAvailableHoverTypes() {
61 int available_hover_types = 0; 68 int available_hover_types = 0;
62 if (IsTouchDevicePresent()) 69 if (IsTouchDevicePresent())
63 available_hover_types |= HOVER_TYPE_ON_DEMAND; 70 available_hover_types |= HOVER_TYPE_ON_DEMAND;
64 if (GetSystemMetrics(SM_MOUSEPRESENT) != 0) 71 if (GetSystemMetrics(SM_MOUSEPRESENT) != 0)
65 available_hover_types |= HOVER_TYPE_HOVER; 72 available_hover_types |= HOVER_TYPE_HOVER;
66 73
67 if (available_hover_types == 0) 74 if (available_hover_types == 0)
68 available_hover_types = HOVER_TYPE_NONE; 75 available_hover_types = HOVER_TYPE_NONE;
69 76
70 return available_hover_types; 77 return available_hover_types;
71 } 78 }
72 79
73 HoverType GetPrimaryHoverType() { 80 HoverType GetPrimaryHoverType(int available_hover_types) {
74 int available_hover_types = GetAvailableHoverTypes();
75 if (available_hover_types & HOVER_TYPE_HOVER) 81 if (available_hover_types & HOVER_TYPE_HOVER)
76 return HOVER_TYPE_HOVER; 82 return HOVER_TYPE_HOVER;
77 if (available_hover_types & HOVER_TYPE_ON_DEMAND) 83 if (available_hover_types & HOVER_TYPE_ON_DEMAND)
78 return HOVER_TYPE_ON_DEMAND; 84 return HOVER_TYPE_ON_DEMAND;
79 DCHECK_EQ(available_hover_types, HOVER_TYPE_NONE); 85 DCHECK_EQ(available_hover_types, HOVER_TYPE_NONE);
80 return HOVER_TYPE_NONE; 86 return HOVER_TYPE_NONE;
81 } 87 }
82 88
89 HoverType GetPrimaryHoverType() {
90 return GetPrimaryHoverType(GetAvailableHoverTypes());
91 }
92
83 } // namespace ui 93 } // namespace ui
OLDNEW
« ui/base/touch/touch_device.h ('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