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

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

Issue 336863002: Moving input device hotplug event processing outside of ui/display (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 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 | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "ash/touch/touchscreen_util.h"
6
7 #include <set>
8
9 #include "ui/events/device_data_manager.h"
10 #include "ui/events/touchscreen_device.h"
11
12 namespace ash {
13
14 void AssociateTouchscreens(std::vector<DisplayInfo>* displays) {
15 std::set<int> no_match_touchscreen;
16 std::vector<ui::TouchscreenDevice> devices =
Daniel Erat 2014/09/11 20:34:00 this function would probably be easier to test if
dnicoara 2014/09/11 21:08:54 Done. You're right, DisplayChangeObserverChromeos
17 ui::DeviceDataManager::GetInstance()->touchscreen_devices();
18
19 int internal_touchscreen = -1;
20 for (size_t i = 0; i < devices.size(); ++i) {
21 if (devices[i].is_internal) {
22 internal_touchscreen = i;
23 break;
24 }
25 }
26
27 DisplayInfo* internal_state = NULL;
28 for (size_t i = 0; i < displays->size(); ++i) {
29 DisplayInfo* state = &(*displays)[i];
30 if (state->id() == gfx::Display::InternalDisplayId() &&
31 !state->GetNativeModeSize().IsEmpty() &&
32 state->touch_support() == gfx::Display::TOUCH_SUPPORT_UNKNOWN) {
33 internal_state = state;
34 break;
35 }
36 }
37
38 if (internal_state && internal_touchscreen >= 0) {
39 internal_state->set_touch_device_id(devices[internal_touchscreen].id);
40 internal_state->set_touch_support(gfx::Display::TOUCH_SUPPORT_AVAILABLE);
41 VLOG(2) << "Found internal touchscreen for internal display "
42 << internal_state->id() << " touch_device_id "
43 << internal_state->touch_device_id() << " size "
44 << devices[internal_touchscreen].size.ToString();
45 }
46
47 for (size_t i = 0; i < devices.size(); ++i) {
48 if (internal_state && internal_state->touch_device_id() == devices[i].id)
49 continue;
50
51 bool found_mapping = false;
52 for (size_t j = 0; j < displays->size(); ++j) {
53 DisplayInfo* state = &(*displays)[j];
54 const gfx::Size native_size = state->GetNativeModeSize();
55 if (state->touch_support() == gfx::Display::TOUCH_SUPPORT_AVAILABLE ||
56 native_size.IsEmpty())
57 continue;
58
59 // Allow 1 pixel difference between screen and touchscreen
60 // resolutions. Because in some cases for monitor resolution
61 // 1024x768 touchscreen's resolution would be 1024x768, but for
62 // some 1023x767. It really depends on touchscreen's firmware
63 // configuration.
64 if (std::abs(native_size.width() - devices[i].size.width()) <= 1 &&
65 std::abs(native_size.height() - devices[i].size.height()) <= 1) {
66 state->set_touch_device_id(devices[i].id);
67 state->set_touch_support(gfx::Display::TOUCH_SUPPORT_AVAILABLE);
68
69 VLOG(2) << "Found touchscreen for display " << state->id()
70 << " touch_device_id " << state->touch_device_id() << " size "
71 << devices[i].size.ToString();
72 found_mapping = true;
73 break;
74 }
75 }
76
77 if (!found_mapping) {
78 no_match_touchscreen.insert(devices[i].id);
79 VLOG(2) << "No matching display for touch_device_id " << devices[i].id
80 << " size " << devices[i].size.ToString();
81 }
82 }
83
84 // Sometimes we can't find a matching screen for the touchscreen, e.g.
85 // due to the touchscreen's reporting range having no correlation with the
86 // screen's resolution. In this case, we arbitrarily assign unmatched
87 // touchscreens to unmatched screens.
88 for (std::set<int>::iterator it = no_match_touchscreen.begin();
89 it != no_match_touchscreen.end();
90 ++it) {
91 for (size_t i = 0; i < displays->size(); ++i) {
92 DisplayInfo* state = &(*displays)[i];
93 if (state->id() != gfx::Display::InternalDisplayId() &&
94 !state->GetNativeModeSize().IsEmpty() &&
95 state->touch_support() == gfx::Display::TOUCH_SUPPORT_UNKNOWN) {
96 state->set_touch_device_id(*it);
97 state->set_touch_support(gfx::Display::TOUCH_SUPPORT_AVAILABLE);
98 VLOG(2) << "Arbitrarily matching touchscreen "
99 << state->touch_device_id() << " to display " << state->id();
100 break;
101 }
102 }
103 }
104 }
105
106 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698