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 |
7 #include "ash/display/window_tree_host_manager.h" | 9 #include "ash/display/window_tree_host_manager.h" |
8 #include "ash/shell.h" | 10 #include "ash/shell.h" |
| 11 #include "base/stl_util.h" |
9 #include "content/public/browser/browser_thread.h" | 12 #include "content/public/browser/browser_thread.h" |
10 #include "ui/display/display.h" | 13 #include "ui/display/display.h" |
11 #include "ui/display/display_layout.h" | |
12 #include "ui/display/manager/display_manager.h" | 14 #include "ui/display/manager/display_manager.h" |
13 #include "ui/display/screen.h" | 15 #include "ui/display/screen.h" |
| 16 #include "ui/events/devices/device_data_manager.h" |
| 17 #include "ui/events/devices/touchscreen_device.h" |
14 | 18 |
15 using content::BrowserThread; | 19 using content::BrowserThread; |
16 | 20 |
17 namespace chromeos { | 21 namespace chromeos { |
18 | 22 |
19 namespace { | 23 namespace { |
20 | 24 |
21 bool TouchSupportAvailable(const display::Display& display) { | 25 bool TouchSupportAvailable(const display::Display& display) { |
22 return display.touch_support() == | 26 return display.touch_support() == |
23 display::Display::TouchSupport::TOUCH_SUPPORT_AVAILABLE; | 27 display::Display::TouchSupport::TOUCH_SUPPORT_AVAILABLE; |
24 } | 28 } |
25 | 29 |
| 30 // TODO(felixe): More context at crbug.com/738885 |
| 31 const uint16_t kDeviceIds[] = {0x0457, 0x266e}; |
| 32 |
26 } // namespace | 33 } // namespace |
27 | 34 |
28 OobeDisplayChooser::OobeDisplayChooser() : weak_ptr_factory_(this) {} | 35 OobeDisplayChooser::OobeDisplayChooser() : weak_ptr_factory_(this) {} |
29 | 36 |
30 OobeDisplayChooser::~OobeDisplayChooser() {} | 37 OobeDisplayChooser::~OobeDisplayChooser() {} |
31 | 38 |
32 void OobeDisplayChooser::TryToPlaceUiOnTouchDisplay() { | 39 void OobeDisplayChooser::TryToPlaceUiOnTouchDisplay() { |
33 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 40 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
34 | 41 |
35 // Don't (potentially) queue a second task to run MoveToTouchDisplay if one | 42 // Don't (potentially) queue a second task to run MoveToTouchDisplay if one |
36 // already is queued. | 43 // already is queued. |
37 if (weak_ptr_factory_.HasWeakPtrs()) | 44 if (weak_ptr_factory_.HasWeakPtrs()) |
38 return; | 45 return; |
39 | 46 |
40 display::Display primary_display = | 47 display::Display primary_display = |
41 display::Screen::GetScreen()->GetPrimaryDisplay(); | 48 display::Screen::GetScreen()->GetPrimaryDisplay(); |
42 | 49 |
43 if (primary_display.is_valid() && !TouchSupportAvailable(primary_display)) { | 50 if (primary_display.is_valid() && !TouchSupportAvailable(primary_display)) { |
44 BrowserThread::PostTask( | 51 BrowserThread::PostTask( |
45 BrowserThread::UI, FROM_HERE, | 52 BrowserThread::UI, FROM_HERE, |
46 base::BindOnce(&OobeDisplayChooser::MoveToTouchDisplay, | 53 base::BindOnce(&OobeDisplayChooser::MoveToTouchDisplay, |
47 weak_ptr_factory_.GetWeakPtr())); | 54 weak_ptr_factory_.GetWeakPtr())); |
48 } | 55 } |
49 } | 56 } |
50 | 57 |
51 void OobeDisplayChooser::MoveToTouchDisplay() { | 58 void OobeDisplayChooser::MoveToTouchDisplay() { |
52 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 59 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
53 | 60 |
54 const display::Displays& displays = | 61 const ui::DeviceDataManager* device_manager = |
55 ash::Shell::Get()->display_manager()->active_only_display_list(); | 62 ui::DeviceDataManager::GetInstance(); |
| 63 for (const ui::TouchscreenDevice& device : |
| 64 device_manager->GetTouchscreenDevices()) { |
| 65 if (!base::ContainsValue(kDeviceIds, device.vendor_id)) |
| 66 continue; |
56 | 67 |
57 if (displays.size() <= 1) | 68 int64_t display_id = |
58 return; | 69 device_manager->GetTargetDisplayForTouchDevice(device.id); |
| 70 if (display_id == display::kInvalidDisplayId) |
| 71 continue; |
59 | 72 |
60 for (const display::Display& display : displays) { | 73 ash::Shell::Get()->window_tree_host_manager()->SetPrimaryDisplayId( |
61 if (TouchSupportAvailable(display)) { | 74 display_id); |
62 ash::Shell::Get()->window_tree_host_manager()->SetPrimaryDisplayId( | 75 break; |
63 display.id()); | |
64 break; | |
65 } | |
66 } | 76 } |
67 } | 77 } |
68 | 78 |
69 } // namespace chromeos | 79 } // namespace chromeos |
OLD | NEW |