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

Side by Side Diff: ash/touch/touchscreen_util.cc

Issue 2477993004: Clean up some nits in ash/touch/touchscreen_util.cc. (Closed)
Patch Set: rebase, auto Created 4 years, 1 month 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 | « no previous file | 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "ash/touch/touchscreen_util.h" 5 #include "ash/touch/touchscreen_util.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 12 matching lines...) Expand all
23 const ui::TouchscreenDevice* device) { 23 const ui::TouchscreenDevice* device) {
24 display->AddInputDevice(device->id); 24 display->AddInputDevice(device->id);
25 display->set_touch_support(display::Display::TOUCH_SUPPORT_AVAILABLE); 25 display->set_touch_support(display::Display::TOUCH_SUPPORT_AVAILABLE);
26 } 26 }
27 27
28 // Returns true if |path| is likely a USB device. 28 // Returns true if |path| is likely a USB device.
29 bool IsDeviceConnectedViaUsb(const base::FilePath& path) { 29 bool IsDeviceConnectedViaUsb(const base::FilePath& path) {
30 std::vector<base::FilePath::StringType> components; 30 std::vector<base::FilePath::StringType> components;
31 path.GetComponents(&components); 31 path.GetComponents(&components);
32 32
33 for (base::FilePath::StringType component : components) { 33 for (const auto& component : components) {
34 if (base::StartsWith(component, "usb", 34 if (base::StartsWith(component, "usb",
35 base::CompareCase::INSENSITIVE_ASCII)) 35 base::CompareCase::INSENSITIVE_ASCII))
36 return true; 36 return true;
37 } 37 }
38 38
39 return false; 39 return false;
40 } 40 }
41 41
42 // Returns the UDL association score between |display| and |device|. A score <= 42 // Returns the UDL association score between |display| and |device|. A score <=
43 // 0 means that there is no association. 43 // 0 means that there is no association.
44 int GetUdlAssociationScore(display::ManagedDisplayInfo* display, 44 int GetUdlAssociationScore(const display::ManagedDisplayInfo* display,
45 const ui::TouchscreenDevice* device) { 45 const ui::TouchscreenDevice* device) {
46 // If the devices are not both connected via USB, then there cannot be a UDL 46 // If the devices are not both connected via USB, then there cannot be a UDL
47 // association score. 47 // association score.
48 if (!IsDeviceConnectedViaUsb(display->sys_path()) || 48 if (!IsDeviceConnectedViaUsb(display->sys_path()) ||
49 !IsDeviceConnectedViaUsb(device->sys_path)) 49 !IsDeviceConnectedViaUsb(device->sys_path))
50 return 0; 50 return 0;
51 51
52 // The association score is simply the number of prefix path components that 52 // The association score is simply the number of prefix path components that
53 // sysfs paths have in common. 53 // sysfs paths have in common.
54 std::vector<base::FilePath::StringType> display_components; 54 std::vector<base::FilePath::StringType> display_components;
55 std::vector<base::FilePath::StringType> device_components; 55 std::vector<base::FilePath::StringType> device_components;
56 display->sys_path().GetComponents(&display_components); 56 display->sys_path().GetComponents(&display_components);
57 device->sys_path.GetComponents(&device_components); 57 device->sys_path.GetComponents(&device_components);
58 58
59 std::size_t largest_idx = 0; 59 std::size_t largest_idx = 0;
60 while (largest_idx < display_components.size() && 60 while (largest_idx < display_components.size() &&
61 largest_idx < device_components.size() && 61 largest_idx < device_components.size() &&
62 display_components[largest_idx] == device_components[largest_idx]) { 62 display_components[largest_idx] == device_components[largest_idx]) {
63 ++largest_idx; 63 ++largest_idx;
64 } 64 }
65 return largest_idx; 65 return largest_idx;
66 } 66 }
67 67
68 // Tries to find a UDL device that best matches |display|. Returns nullptr 68 // Tries to find a UDL device that best matches |display|. Returns nullptr
69 // if one is not found. 69 // if one is not found.
70 const ui::TouchscreenDevice* GuessBestUdlDevice( 70 const ui::TouchscreenDevice* GuessBestUdlDevice(
71 display::ManagedDisplayInfo* display, 71 const display::ManagedDisplayInfo* display,
72 const DeviceList& devices) { 72 const DeviceList& devices) {
73 int best_score = 0; 73 int best_score = 0;
74 const ui::TouchscreenDevice* best_device = nullptr; 74 const ui::TouchscreenDevice* best_device = nullptr;
75 75
76 for (const ui::TouchscreenDevice* device : devices) { 76 for (const ui::TouchscreenDevice* device : devices) {
77 int score = GetUdlAssociationScore(display, device); 77 int score = GetUdlAssociationScore(display, device);
78 if (score > best_score) { 78 if (score > best_score) {
79 best_score = score; 79 best_score = score;
80 best_device = device; 80 best_device = device;
81 } 81 }
(...skipping 21 matching lines...) Expand all
103 devices->erase(std::find(devices->begin(), devices->end(), device)); 103 devices->erase(std::find(devices->begin(), devices->end(), device));
104 104
105 continue; 105 continue;
106 } 106 }
107 107
108 ++display_it; 108 ++display_it;
109 } 109 }
110 } 110 }
111 111
112 // Returns true if |display| is internal. 112 // Returns true if |display| is internal.
113 bool IsInternalDisplay(display::ManagedDisplayInfo* display) { 113 bool IsInternalDisplay(const display::ManagedDisplayInfo* display) {
114 return display::Display::IsInternalDisplayId(display->id()); 114 return display::Display::IsInternalDisplayId(display->id());
115 } 115 }
116 116
117 // Returns true if |device| is internal. 117 // Returns true if |device| is internal.
118 bool IsInternalDevice(const ui::TouchscreenDevice* device) { 118 bool IsInternalDevice(const ui::TouchscreenDevice* device) {
119 return device->type == ui::InputDeviceType::INPUT_DEVICE_INTERNAL; 119 return device->type == ui::InputDeviceType::INPUT_DEVICE_INTERNAL;
120 } 120 }
121 121
122 void AssociateInternalDevices(DisplayInfoList* displays, DeviceList* devices) { 122 void AssociateInternalDevices(DisplayInfoList* displays, DeviceList* devices) {
123 VLOG(2) << "Trying to match internal devices (" << displays->size() 123 VLOG(2) << "Trying to match internal devices (" << displays->size()
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 } 211 }
212 212
213 void AssociateToSingleDisplay(DisplayInfoList* displays, DeviceList* devices) { 213 void AssociateToSingleDisplay(DisplayInfoList* displays, DeviceList* devices) {
214 // If there is only one display left, then we should associate all input 214 // If there is only one display left, then we should associate all input
215 // devices with it. 215 // devices with it.
216 216
217 VLOG(2) << "Trying to match to single display (" << displays->size() 217 VLOG(2) << "Trying to match to single display (" << displays->size()
218 << " displays and " << devices->size() << " devices to match)"; 218 << " displays and " << devices->size() << " devices to match)";
219 219
220 // We only associate to one display. 220 // We only associate to one display.
221 if (displays->size() != 1 || devices->size() == 0) 221 if (displays->size() != 1 || devices->empty())
222 return; 222 return;
223 223
224 display::ManagedDisplayInfo* display = *displays->begin(); 224 display::ManagedDisplayInfo* display = *displays->begin();
225 for (const ui::TouchscreenDevice* device : *devices) { 225 for (const ui::TouchscreenDevice* device : *devices) {
226 VLOG(2) << "=> Matched device " << device->name << " to display " 226 VLOG(2) << "=> Matched device " << device->name << " to display "
227 << display->name(); 227 << display->name();
228 Associate(display, device); 228 Associate(display, device);
229 } 229 }
230 230
231 displays->clear(); 231 displays->clear();
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 AssociateSameSizeDevices(&displays, &devices); 275 AssociateSameSizeDevices(&displays, &devices);
276 AssociateToSingleDisplay(&displays, &devices); 276 AssociateToSingleDisplay(&displays, &devices);
277 277
278 for (const display::ManagedDisplayInfo* display : displays) 278 for (const display::ManagedDisplayInfo* display : displays)
279 LOG(WARNING) << "Unmatched display " << display->name(); 279 LOG(WARNING) << "Unmatched display " << display->name();
280 for (const ui::TouchscreenDevice* device : devices) 280 for (const ui::TouchscreenDevice* device : devices)
281 LOG(WARNING) << "Unmatched device " << device->name; 281 LOG(WARNING) << "Unmatched device " << device->name;
282 } 282 }
283 283
284 } // namespace ash 284 } // namespace ash
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698