OLD | NEW |
---|---|
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 "chrome/browser/ui/webui/chromeos/login/oobe_display_chooser.h" | 5 #include "chrome/browser/ui/webui/chromeos/login/oobe_display_chooser.h" |
6 | 6 |
7 #include <stdint.h> | |
8 #include <algorithm> | |
oshima
2017/07/07 14:22:10
is this necessary?
Felix Ekblom
2017/07/07 19:04:30
Removed.
| |
9 | |
7 #include "ash/display/window_tree_host_manager.h" | 10 #include "ash/display/window_tree_host_manager.h" |
8 #include "ash/shell.h" | 11 #include "ash/shell.h" |
12 #include "base/stl_util.h" | |
9 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" |
10 #include "ui/display/display.h" | 14 #include "ui/display/display.h" |
11 #include "ui/display/display_layout.h" | |
12 #include "ui/display/manager/display_manager.h" | 15 #include "ui/display/manager/display_manager.h" |
13 #include "ui/display/screen.h" | 16 #include "ui/display/screen.h" |
17 #include "ui/events/devices/device_data_manager.h" | |
18 #include "ui/events/devices/touchscreen_device.h" | |
14 | 19 |
15 using content::BrowserThread; | 20 using content::BrowserThread; |
16 | 21 |
17 namespace chromeos { | 22 namespace chromeos { |
18 | 23 |
19 namespace { | 24 namespace { |
20 | 25 |
21 bool TouchSupportAvailable(const display::Display& display) { | 26 bool TouchSupportAvailable(const display::Display& display) { |
22 return display.touch_support() == | 27 return display.touch_support() == |
23 display::Display::TouchSupport::TOUCH_SUPPORT_AVAILABLE; | 28 display::Display::TouchSupport::TOUCH_SUPPORT_AVAILABLE; |
24 } | 29 } |
25 | 30 |
31 // TODO(felixe): More context at crbug.com/738885 | |
32 const uint16_t kDeviceIds[] = {0x0457, 0x266e}; | |
33 | |
26 } // namespace | 34 } // namespace |
27 | 35 |
28 OobeDisplayChooser::OobeDisplayChooser() : weak_ptr_factory_(this) {} | 36 OobeDisplayChooser::OobeDisplayChooser() : weak_ptr_factory_(this) {} |
29 | 37 |
30 OobeDisplayChooser::~OobeDisplayChooser() {} | 38 OobeDisplayChooser::~OobeDisplayChooser() {} |
31 | 39 |
32 void OobeDisplayChooser::TryToPlaceUiOnTouchDisplay() { | 40 void OobeDisplayChooser::TryToPlaceUiOnTouchDisplay() { |
33 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 41 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
34 | 42 |
35 // Don't (potentially) queue a second task to run MoveToTouchDisplay if one | 43 // Don't (potentially) queue a second task to run MoveToTouchDisplay if one |
36 // already is queued. | 44 // already is queued. |
37 if (weak_ptr_factory_.HasWeakPtrs()) | 45 if (weak_ptr_factory_.HasWeakPtrs()) |
38 return; | 46 return; |
39 | 47 |
40 display::Display primary_display = | 48 display::Display primary_display = |
41 display::Screen::GetScreen()->GetPrimaryDisplay(); | 49 display::Screen::GetScreen()->GetPrimaryDisplay(); |
42 | 50 |
43 if (primary_display.is_valid() && !TouchSupportAvailable(primary_display)) { | 51 if (primary_display.is_valid() && !TouchSupportAvailable(primary_display)) { |
44 BrowserThread::PostTask( | 52 BrowserThread::PostTask( |
45 BrowserThread::UI, FROM_HERE, | 53 BrowserThread::UI, FROM_HERE, |
46 base::BindOnce(&OobeDisplayChooser::MoveToTouchDisplay, | 54 base::BindOnce(&OobeDisplayChooser::MoveToTouchDisplay, |
47 weak_ptr_factory_.GetWeakPtr())); | 55 weak_ptr_factory_.GetWeakPtr())); |
48 } | 56 } |
49 } | 57 } |
50 | 58 |
51 void OobeDisplayChooser::MoveToTouchDisplay() { | 59 void OobeDisplayChooser::MoveToTouchDisplay() { |
52 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 60 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
53 | 61 |
54 const display::Displays& displays = | 62 if (!ui::DeviceDataManager::HasInstance()) |
oshima
2017/07/06 20:53:36
can this happen?
Felix Ekblom
2017/07/07 08:41:01
In theory, yes, since GetInstance() does not creat
oshima
2017/07/07 14:22:10
If it should not happen, then remove check and fix
Felix Ekblom
2017/07/07 19:04:30
Very good point. Done.
| |
55 ash::Shell::Get()->display_manager()->active_only_display_list(); | |
56 | |
57 if (displays.size() <= 1) | |
58 return; | 63 return; |
59 | 64 |
60 for (const display::Display& display : displays) { | 65 const ui::DeviceDataManager* device_manager = |
61 if (TouchSupportAvailable(display)) { | 66 ui::DeviceDataManager::GetInstance(); |
62 ash::Shell::Get()->window_tree_host_manager()->SetPrimaryDisplayId( | 67 for (const ui::TouchscreenDevice& device : |
63 display.id()); | 68 device_manager->GetTouchscreenDevices()) { |
64 break; | 69 if (!base::ContainsValue(kDeviceIds, device.vendor_id)) |
65 } | 70 continue; |
71 | |
72 int64_t display_id = | |
73 device_manager->GetTargetDisplayForTouchDevice(device.id); | |
74 if (display_id == display::kInvalidDisplayId) | |
75 continue; | |
76 | |
77 ash::Shell::Get()->window_tree_host_manager()->SetPrimaryDisplayId( | |
78 display_id); | |
79 break; | |
66 } | 80 } |
67 } | 81 } |
68 | 82 |
69 } // namespace chromeos | 83 } // namespace chromeos |
OLD | NEW |