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