Skip to content

Commit 97e7eb3

Browse files
jacobdufault-googleJacob Dufault
authored and
Jacob Dufault
committed
Reland OOBE display chooser commits + add Mash guard
This CL will reland / revert revert 2 commits and add a non-Mash guard for listening to DeviceDataManager. A TODO has been added about using InputDeviceClient in Mash, but it's not super urgent as the reaction to the event is a NOP in Mash further down the call chain. Revert "Revert of Remove confusing keyboard test & focus on input device" commit 8a2f3aa Revert "Revert "Listen to changes to touch input devices"" commit 0cd134a [email protected] (cherry picked from commit d706dfc) Bug: 738885 Change-Id: Ic805ca3966df2969d8444b2c441eac24f75dce62 Reviewed-on: https://chromium-review.googlesource.com/575138 Commit-Queue: Felix Ekblom <[email protected]> Reviewed-by: Mitsuru Oshima <[email protected]> Reviewed-by: Jacob Dufault <[email protected]> Cr-Original-Commit-Position: refs/heads/master@{#488622} Reviewed-on: https://chromium-review.googlesource.com/590352 Cr-Commit-Position: refs/branch-heads/3163@{#84} Cr-Branched-From: ff259ba-refs/heads/master@{#488528}
1 parent 63431ed commit 97e7eb3

File tree

5 files changed

+124
-60
lines changed

5 files changed

+124
-60
lines changed

chrome/browser/chromeos/login/ui/login_display_host_impl.cc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@
9999
#include "ui/compositor/scoped_layer_animation_settings.h"
100100
#include "ui/display/display.h"
101101
#include "ui/display/screen.h"
102+
#include "ui/events/devices/device_data_manager.h"
102103
#include "ui/events/event_handler.h"
103104
#include "ui/events/event_utils.h"
104105
#include "ui/gfx/geometry/rect.h"
@@ -384,6 +385,12 @@ LoginDisplayHostImpl::LoginDisplayHostImpl(const gfx::Rect& wallpaper_bounds)
384385

385386
display::Screen::GetScreen()->AddObserver(this);
386387

388+
// TODO(crbug.com/747267): Add Mash case. Not strictly needed since callee in
389+
// observer method is NOP in Mash, but good for symmetry and to avoid leaking
390+
// implementation details about OobeUI.
391+
if (!ash_util::IsRunningInMash())
392+
ui::DeviceDataManager::GetInstance()->AddObserver(this);
393+
387394
// We need to listen to CLOSE_ALL_BROWSERS_REQUEST but not APP_TERMINATING
388395
// because/ APP_TERMINATING will never be fired as long as this keeps
389396
// ref-count. CLOSE_ALL_BROWSERS_REQUEST is safe here because there will be no
@@ -494,6 +501,12 @@ LoginDisplayHostImpl::~LoginDisplayHostImpl() {
494501
CrasAudioHandler::Get()->RemoveAudioObserver(this);
495502
display::Screen::GetScreen()->RemoveObserver(this);
496503

504+
// TODO(crbug.com/747267): Add Mash case. Not strictly needed since callee in
505+
// observer method is NOP in Mash, but good for symmetry and to avoid leaking
506+
// implementation details about OobeUI.
507+
if (!ash_util::IsRunningInMash())
508+
ui::DeviceDataManager::GetInstance()->RemoveObserver(this);
509+
497510
if (login_view_ && login_window_)
498511
login_window_->RemoveRemovalsObserver(this);
499512

@@ -1017,6 +1030,13 @@ void LoginDisplayHostImpl::OnDisplayMetricsChanged(
10171030
}
10181031
}
10191032

1033+
////////////////////////////////////////////////////////////////////////////////
1034+
// LoginDisplayHostImpl, ui::InputDeviceEventObserver
1035+
void LoginDisplayHostImpl::OnTouchscreenDeviceConfigurationChanged() {
1036+
if (GetOobeUI())
1037+
GetOobeUI()->OnDisplayConfigurationChanged();
1038+
}
1039+
10201040
////////////////////////////////////////////////////////////////////////////////
10211041
// LoginDisplayHostImpl, views::WidgetRemovalsObserver:
10221042
void LoginDisplayHostImpl::OnWillRemoveView(views::Widget* widget,

chrome/browser/chromeos/login/ui/login_display_host_impl.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "content/public/browser/notification_registrar.h"
2929
#include "content/public/browser/web_contents_observer.h"
3030
#include "ui/display/display_observer.h"
31+
#include "ui/events/devices/input_device_event_observer.h"
3132
#include "ui/gfx/geometry/rect.h"
3233
#include "ui/views/widget/widget_removals_observer.h"
3334
#include "ui/wm/public/scoped_drag_drop_disabler.h"
@@ -51,6 +52,7 @@ class LoginDisplayHostImpl : public LoginDisplayHost,
5152
public chromeos::SessionManagerClient::Observer,
5253
public chromeos::CrasAudioHandler::AudioObserver,
5354
public display::DisplayObserver,
55+
public ui::InputDeviceEventObserver,
5456
public views::WidgetRemovalsObserver,
5557
public chrome::MultiUserWindowManager::Observer {
5658
public:
@@ -122,6 +124,9 @@ class LoginDisplayHostImpl : public LoginDisplayHost,
122124
void OnDisplayMetricsChanged(const display::Display& display,
123125
uint32_t changed_metrics) override;
124126

127+
// Overridden from ui::InputDeviceEventObserver
128+
void OnTouchscreenDeviceConfigurationChanged() override;
129+
125130
// Overriden from views::WidgetRemovalsObserver:
126131
void OnWillRemoveView(views::Widget* widget, views::View* view) override;
127132

chrome/browser/ui/webui/chromeos/login/oobe_display_chooser.cc

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,17 @@
44

55
#include "chrome/browser/ui/webui/chromeos/login/oobe_display_chooser.h"
66

7+
#include <stdint.h>
8+
79
#include "ash/display/window_tree_host_manager.h"
810
#include "ash/shell.h"
11+
#include "base/stl_util.h"
912
#include "content/public/browser/browser_thread.h"
1013
#include "ui/display/display.h"
11-
#include "ui/display/display_layout.h"
1214
#include "ui/display/manager/display_manager.h"
1315
#include "ui/display/screen.h"
16+
#include "ui/events/devices/device_data_manager.h"
17+
#include "ui/events/devices/touchscreen_device.h"
1418

1519
using content::BrowserThread;
1620

@@ -23,6 +27,9 @@ bool TouchSupportAvailable(const display::Display& display) {
2327
display::Display::TouchSupport::TOUCH_SUPPORT_AVAILABLE;
2428
}
2529

30+
// TODO(felixe): More context at crbug.com/738885
31+
const uint16_t kDeviceIds[] = {0x0457, 0x266e};
32+
2633
} // namespace
2734

2835
OobeDisplayChooser::OobeDisplayChooser() : weak_ptr_factory_(this) {}
@@ -51,18 +58,21 @@ void OobeDisplayChooser::TryToPlaceUiOnTouchDisplay() {
5158
void OobeDisplayChooser::MoveToTouchDisplay() {
5259
DCHECK_CURRENTLY_ON(BrowserThread::UI);
5360

54-
const display::Displays& displays =
55-
ash::Shell::Get()->display_manager()->active_only_display_list();
56-
57-
if (displays.size() <= 1)
58-
return;
59-
60-
for (const display::Display& display : displays) {
61-
if (TouchSupportAvailable(display)) {
62-
ash::Shell::Get()->window_tree_host_manager()->SetPrimaryDisplayId(
63-
display.id());
64-
break;
65-
}
61+
const ui::DeviceDataManager* device_manager =
62+
ui::DeviceDataManager::GetInstance();
63+
for (const ui::TouchscreenDevice& device :
64+
device_manager->GetTouchscreenDevices()) {
65+
if (!base::ContainsValue(kDeviceIds, device.vendor_id))
66+
continue;
67+
68+
int64_t display_id =
69+
device_manager->GetTargetDisplayForTouchDevice(device.id);
70+
if (display_id == display::kInvalidDisplayId)
71+
continue;
72+
73+
ash::Shell::Get()->window_tree_host_manager()->SetPrimaryDisplayId(
74+
display_id);
75+
break;
6676
}
6777
}
6878

chrome/browser/ui/webui/chromeos/login/oobe_display_chooser_unittest.cc

Lines changed: 69 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "chrome/browser/ui/webui/chromeos/login/oobe_display_chooser.h"
66

77
#include <memory>
8+
#include <vector>
89

910
#include "ash/display/display_configuration_controller.h"
1011
#include "ash/shell.h"
@@ -13,9 +14,12 @@
1314
#include "testing/gtest/include/gtest/gtest.h"
1415
#include "ui/display/display.h"
1516
#include "ui/display/display_observer.h"
17+
#include "ui/display/manager/chromeos/touchscreen_util.h"
1618
#include "ui/display/manager/display_manager.h"
1719
#include "ui/display/screen.h"
1820
#include "ui/display/test/display_manager_test_api.h"
21+
#include "ui/events/devices/device_data_manager.h"
22+
#include "ui/events/devices/touchscreen_device.h"
1923

2024
namespace chromeos {
2125

@@ -25,63 +29,93 @@ class OobeDisplayChooserTest : public ash::AshTestBase {
2529
public:
2630
OobeDisplayChooserTest() : ash::AshTestBase() {}
2731

28-
void SetUp() override {
29-
ash::AshTestBase::SetUp();
30-
display_manager_test_api_.reset(
31-
new display::test::DisplayManagerTestApi(display_manager()));
32+
int64_t GetPrimaryDisplay() {
33+
return display::Screen::GetScreen()->GetPrimaryDisplay().id();
3234
}
3335

34-
void EnableTouch(int64_t id) {
35-
display_manager_test_api_->SetTouchSupport(
36-
id, display::Display::TouchSupport::TOUCH_SUPPORT_AVAILABLE);
37-
}
36+
void UpdateTouchscreenDevices(const ui::TouchscreenDevice& touchscreen) {
37+
std::vector<ui::TouchscreenDevice> devices{touchscreen};
3838

39-
void DisableTouch(int64_t id) {
40-
display_manager_test_api_->SetTouchSupport(
41-
id, display::Display::TouchSupport::TOUCH_SUPPORT_UNAVAILABLE);
42-
}
43-
44-
int64_t GetPrimaryDisplay() {
45-
return display::Screen::GetScreen()->GetPrimaryDisplay().id();
39+
ui::DeviceHotplugEventObserver* manager =
40+
ui::DeviceDataManager::GetInstance();
41+
manager->OnTouchscreenDevicesUpdated(devices);
4642
}
4743

4844
private:
49-
std::unique_ptr<display::test::DisplayManagerTestApi>
50-
display_manager_test_api_;
51-
5245
DISALLOW_COPY_AND_ASSIGN(OobeDisplayChooserTest);
5346
};
5447

48+
const uint16_t kWhitelistedId = 0x266e;
49+
5550
} // namespace
5651

5752
TEST_F(OobeDisplayChooserTest, PreferTouchAsPrimary) {
58-
OobeDisplayChooser display_chooser;
53+
// Setup 2 displays, second one is intended to be a touch display
54+
std::vector<display::ManagedDisplayInfo> display_info;
55+
display_info.push_back(
56+
display::ManagedDisplayInfo::CreateFromSpecWithID("0+0-3000x2000", 1));
57+
display_info.push_back(
58+
display::ManagedDisplayInfo::CreateFromSpecWithID("3000+0-800x600", 2));
59+
display_manager()->OnNativeDisplaysChanged(display_info);
60+
base::RunLoop().RunUntilIdle();
5961

60-
UpdateDisplay("3000x2000,800x600");
61-
display::DisplayIdList ids = display_manager()->GetCurrentDisplayIdList();
62-
DisableTouch(ids[0]);
63-
EnableTouch(ids[1]);
62+
// Make sure the non-touch display is primary
63+
ash::Shell::Get()->window_tree_host_manager()->SetPrimaryDisplayId(1);
6464

65-
EXPECT_EQ(ids[0], GetPrimaryDisplay());
66-
display_chooser.TryToPlaceUiOnTouchDisplay();
65+
// Setup corresponding TouchscreenDevice object
66+
ui::TouchscreenDevice touchscreen =
67+
ui::TouchscreenDevice(1, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL,
68+
"Touchscreen", gfx::Size(800, 600), 1);
69+
touchscreen.vendor_id = kWhitelistedId;
70+
UpdateTouchscreenDevices(touchscreen);
6771
base::RunLoop().RunUntilIdle();
6872

69-
EXPECT_EQ(ids[1], GetPrimaryDisplay());
70-
}
73+
// Associate touchscreen device with display
74+
display_info[1].AddInputDevice(touchscreen.id);
75+
display_info[1].set_touch_support(display::Display::TOUCH_SUPPORT_AVAILABLE);
76+
display_manager()->OnNativeDisplaysChanged(display_info);
77+
base::RunLoop().RunUntilIdle();
7178

72-
TEST_F(OobeDisplayChooserTest, AddingSecondTouchDisplayShouldbeNOP) {
7379
OobeDisplayChooser display_chooser;
80+
EXPECT_EQ(1, GetPrimaryDisplay());
81+
display_chooser.TryToPlaceUiOnTouchDisplay();
82+
base::RunLoop().RunUntilIdle();
83+
EXPECT_EQ(2, GetPrimaryDisplay());
84+
}
7485

75-
UpdateDisplay("3000x2000,800x600");
76-
display::DisplayIdList ids = display_manager()->GetCurrentDisplayIdList();
77-
EnableTouch(ids[0]);
78-
EnableTouch(ids[1]);
86+
TEST_F(OobeDisplayChooserTest, DontSwitchFromTouch) {
87+
// Setup 2 displays, second one is intended to be a touch display
88+
std::vector<display::ManagedDisplayInfo> display_info;
89+
display_info.push_back(
90+
display::ManagedDisplayInfo::CreateFromSpecWithID("0+0-3000x2000", 1));
91+
display_info.push_back(
92+
display::ManagedDisplayInfo::CreateFromSpecWithID("3000+0-800x600", 2));
93+
display_info[0].set_touch_support(display::Display::TOUCH_SUPPORT_AVAILABLE);
94+
display_manager()->OnNativeDisplaysChanged(display_info);
95+
base::RunLoop().RunUntilIdle();
7996

80-
EXPECT_EQ(ids[0], GetPrimaryDisplay());
81-
display_chooser.TryToPlaceUiOnTouchDisplay();
97+
// Make sure the non-touch display is primary
98+
ash::Shell::Get()->window_tree_host_manager()->SetPrimaryDisplayId(1);
99+
100+
// Setup corresponding TouchscreenDevice object
101+
ui::TouchscreenDevice touchscreen =
102+
ui::TouchscreenDevice(1, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL,
103+
"Touchscreen", gfx::Size(800, 600), 1);
104+
touchscreen.vendor_id = kWhitelistedId;
105+
UpdateTouchscreenDevices(touchscreen);
106+
base::RunLoop().RunUntilIdle();
107+
108+
// Associate touchscreen device with display
109+
display_info[1].AddInputDevice(touchscreen.id);
110+
display_info[1].set_touch_support(display::Display::TOUCH_SUPPORT_AVAILABLE);
111+
display_manager()->OnNativeDisplaysChanged(display_info);
82112
base::RunLoop().RunUntilIdle();
83113

84-
EXPECT_EQ(ids[0], GetPrimaryDisplay());
114+
OobeDisplayChooser display_chooser;
115+
EXPECT_EQ(1, GetPrimaryDisplay());
116+
display_chooser.TryToPlaceUiOnTouchDisplay();
117+
base::RunLoop().RunUntilIdle();
118+
EXPECT_EQ(1, GetPrimaryDisplay());
85119
}
86120

87121
} // namespace chromeos

chrome/browser/ui/webui/chromeos/login/oobe_ui.cc

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -226,17 +226,12 @@ std::string GetDisplayType(const GURL& url) {
226226
return path;
227227
}
228228

229-
bool IsKeyboardConnected() {
230-
const std::vector<ui::InputDevice>& keyboards =
231-
ui::InputDeviceManager::GetInstance()->GetKeyboardDevices();
232-
for (const ui::InputDevice& keyboard : keyboards) {
233-
if (keyboard.type == ui::INPUT_DEVICE_INTERNAL ||
234-
keyboard.type == ui::INPUT_DEVICE_EXTERNAL) {
235-
return true;
236-
}
237-
}
238-
239-
return false;
229+
bool IsRemoraRequisitioned() {
230+
policy::DeviceCloudPolicyManagerChromeOS* policy_manager =
231+
g_browser_process->platform_part()
232+
->browser_policy_connector_chromeos()
233+
->GetDeviceCloudPolicyManager();
234+
return policy_manager && policy_manager->IsRemoraRequisition();
240235
}
241236

242237
} // namespace
@@ -376,7 +371,7 @@ OobeUI::OobeUI(content::WebUI* web_ui, const GURL& url)
376371

377372
// TODO(felixe): Display iteration and primary display selection not supported
378373
// in Mash. See http://crbug.com/720917.
379-
if (!ash_util::IsRunningInMash() && !IsKeyboardConnected())
374+
if (!ash_util::IsRunningInMash() && IsRemoraRequisitioned())
380375
oobe_display_chooser_ = base::MakeUnique<OobeDisplayChooser>();
381376
}
382377

0 commit comments

Comments
 (0)