Commit d706dfca authored by Felix Ekblom's avatar Felix Ekblom Committed by Commit Bot

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 8a2f3aa1

Revert "Revert "Listen to changes to touch input devices""
  commit 0cd134a5

Bug: 738885
Change-Id: Ic805ca3966df2969d8444b2c441eac24f75dce62
Reviewed-on: https://chromium-review.googlesource.com/575138
Commit-Queue: Felix Ekblom <felixe@chromium.org>
Reviewed-by: default avatarMitsuru Oshima <oshima@chromium.org>
Reviewed-by: default avatarJacob Dufault <jdufault@chromium.org>
Cr-Commit-Position: refs/heads/master@{#488622}
parent 31d7cd09
...@@ -99,6 +99,7 @@ ...@@ -99,6 +99,7 @@
#include "ui/compositor/scoped_layer_animation_settings.h" #include "ui/compositor/scoped_layer_animation_settings.h"
#include "ui/display/display.h" #include "ui/display/display.h"
#include "ui/display/screen.h" #include "ui/display/screen.h"
#include "ui/events/devices/device_data_manager.h"
#include "ui/events/event_handler.h" #include "ui/events/event_handler.h"
#include "ui/events/event_utils.h" #include "ui/events/event_utils.h"
#include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/rect.h"
...@@ -384,6 +385,12 @@ LoginDisplayHostImpl::LoginDisplayHostImpl(const gfx::Rect& wallpaper_bounds) ...@@ -384,6 +385,12 @@ LoginDisplayHostImpl::LoginDisplayHostImpl(const gfx::Rect& wallpaper_bounds)
display::Screen::GetScreen()->AddObserver(this); display::Screen::GetScreen()->AddObserver(this);
// TODO(crbug.com/747267): Add Mash case. Not strictly needed since callee in
// observer method is NOP in Mash, but good for symmetry and to avoid leaking
// implementation details about OobeUI.
if (!ash_util::IsRunningInMash())
ui::DeviceDataManager::GetInstance()->AddObserver(this);
// We need to listen to CLOSE_ALL_BROWSERS_REQUEST but not APP_TERMINATING // We need to listen to CLOSE_ALL_BROWSERS_REQUEST but not APP_TERMINATING
// because/ APP_TERMINATING will never be fired as long as this keeps // because/ APP_TERMINATING will never be fired as long as this keeps
// ref-count. CLOSE_ALL_BROWSERS_REQUEST is safe here because there will be no // ref-count. CLOSE_ALL_BROWSERS_REQUEST is safe here because there will be no
...@@ -494,6 +501,12 @@ LoginDisplayHostImpl::~LoginDisplayHostImpl() { ...@@ -494,6 +501,12 @@ LoginDisplayHostImpl::~LoginDisplayHostImpl() {
CrasAudioHandler::Get()->RemoveAudioObserver(this); CrasAudioHandler::Get()->RemoveAudioObserver(this);
display::Screen::GetScreen()->RemoveObserver(this); display::Screen::GetScreen()->RemoveObserver(this);
// TODO(crbug.com/747267): Add Mash case. Not strictly needed since callee in
// observer method is NOP in Mash, but good for symmetry and to avoid leaking
// implementation details about OobeUI.
if (!ash_util::IsRunningInMash())
ui::DeviceDataManager::GetInstance()->RemoveObserver(this);
if (login_view_ && login_window_) if (login_view_ && login_window_)
login_window_->RemoveRemovalsObserver(this); login_window_->RemoveRemovalsObserver(this);
...@@ -1017,6 +1030,13 @@ void LoginDisplayHostImpl::OnDisplayMetricsChanged( ...@@ -1017,6 +1030,13 @@ void LoginDisplayHostImpl::OnDisplayMetricsChanged(
} }
} }
////////////////////////////////////////////////////////////////////////////////
// LoginDisplayHostImpl, ui::InputDeviceEventObserver
void LoginDisplayHostImpl::OnTouchscreenDeviceConfigurationChanged() {
if (GetOobeUI())
GetOobeUI()->OnDisplayConfigurationChanged();
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// LoginDisplayHostImpl, views::WidgetRemovalsObserver: // LoginDisplayHostImpl, views::WidgetRemovalsObserver:
void LoginDisplayHostImpl::OnWillRemoveView(views::Widget* widget, void LoginDisplayHostImpl::OnWillRemoveView(views::Widget* widget,
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include "content/public/browser/notification_registrar.h" #include "content/public/browser/notification_registrar.h"
#include "content/public/browser/web_contents_observer.h" #include "content/public/browser/web_contents_observer.h"
#include "ui/display/display_observer.h" #include "ui/display/display_observer.h"
#include "ui/events/devices/input_device_event_observer.h"
#include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/rect.h"
#include "ui/views/widget/widget_removals_observer.h" #include "ui/views/widget/widget_removals_observer.h"
#include "ui/wm/public/scoped_drag_drop_disabler.h" #include "ui/wm/public/scoped_drag_drop_disabler.h"
...@@ -51,6 +52,7 @@ class LoginDisplayHostImpl : public LoginDisplayHost, ...@@ -51,6 +52,7 @@ class LoginDisplayHostImpl : public LoginDisplayHost,
public chromeos::SessionManagerClient::Observer, public chromeos::SessionManagerClient::Observer,
public chromeos::CrasAudioHandler::AudioObserver, public chromeos::CrasAudioHandler::AudioObserver,
public display::DisplayObserver, public display::DisplayObserver,
public ui::InputDeviceEventObserver,
public views::WidgetRemovalsObserver, public views::WidgetRemovalsObserver,
public chrome::MultiUserWindowManager::Observer { public chrome::MultiUserWindowManager::Observer {
public: public:
...@@ -122,6 +124,9 @@ class LoginDisplayHostImpl : public LoginDisplayHost, ...@@ -122,6 +124,9 @@ class LoginDisplayHostImpl : public LoginDisplayHost,
void OnDisplayMetricsChanged(const display::Display& display, void OnDisplayMetricsChanged(const display::Display& display,
uint32_t changed_metrics) override; uint32_t changed_metrics) override;
// Overridden from ui::InputDeviceEventObserver
void OnTouchscreenDeviceConfigurationChanged() override;
// Overriden from views::WidgetRemovalsObserver: // Overriden from views::WidgetRemovalsObserver:
void OnWillRemoveView(views::Widget* widget, views::View* view) override; void OnWillRemoveView(views::Widget* widget, views::View* view) override;
......
...@@ -4,13 +4,17 @@ ...@@ -4,13 +4,17 @@
#include "chrome/browser/ui/webui/chromeos/login/oobe_display_chooser.h" #include "chrome/browser/ui/webui/chromeos/login/oobe_display_chooser.h"
#include <stdint.h>
#include "ash/display/window_tree_host_manager.h" #include "ash/display/window_tree_host_manager.h"
#include "ash/shell.h" #include "ash/shell.h"
#include "base/stl_util.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "ui/display/display.h" #include "ui/display/display.h"
#include "ui/display/display_layout.h"
#include "ui/display/manager/display_manager.h" #include "ui/display/manager/display_manager.h"
#include "ui/display/screen.h" #include "ui/display/screen.h"
#include "ui/events/devices/device_data_manager.h"
#include "ui/events/devices/touchscreen_device.h"
using content::BrowserThread; using content::BrowserThread;
...@@ -23,6 +27,9 @@ bool TouchSupportAvailable(const display::Display& display) { ...@@ -23,6 +27,9 @@ bool TouchSupportAvailable(const display::Display& display) {
display::Display::TouchSupport::TOUCH_SUPPORT_AVAILABLE; display::Display::TouchSupport::TOUCH_SUPPORT_AVAILABLE;
} }
// TODO(felixe): More context at crbug.com/738885
const uint16_t kDeviceIds[] = {0x0457, 0x266e};
} // namespace } // namespace
OobeDisplayChooser::OobeDisplayChooser() : weak_ptr_factory_(this) {} OobeDisplayChooser::OobeDisplayChooser() : weak_ptr_factory_(this) {}
...@@ -51,18 +58,21 @@ void OobeDisplayChooser::TryToPlaceUiOnTouchDisplay() { ...@@ -51,18 +58,21 @@ void OobeDisplayChooser::TryToPlaceUiOnTouchDisplay() {
void OobeDisplayChooser::MoveToTouchDisplay() { void OobeDisplayChooser::MoveToTouchDisplay() {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
const display::Displays& displays = const ui::DeviceDataManager* device_manager =
ash::Shell::Get()->display_manager()->active_only_display_list(); ui::DeviceDataManager::GetInstance();
for (const ui::TouchscreenDevice& device :
if (displays.size() <= 1) device_manager->GetTouchscreenDevices()) {
return; if (!base::ContainsValue(kDeviceIds, device.vendor_id))
continue;
for (const display::Display& display : displays) {
if (TouchSupportAvailable(display)) { int64_t display_id =
ash::Shell::Get()->window_tree_host_manager()->SetPrimaryDisplayId( device_manager->GetTargetDisplayForTouchDevice(device.id);
display.id()); if (display_id == display::kInvalidDisplayId)
break; continue;
}
ash::Shell::Get()->window_tree_host_manager()->SetPrimaryDisplayId(
display_id);
break;
} }
} }
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "chrome/browser/ui/webui/chromeos/login/oobe_display_chooser.h" #include "chrome/browser/ui/webui/chromeos/login/oobe_display_chooser.h"
#include <memory> #include <memory>
#include <vector>
#include "ash/display/display_configuration_controller.h" #include "ash/display/display_configuration_controller.h"
#include "ash/shell.h" #include "ash/shell.h"
...@@ -13,9 +14,12 @@ ...@@ -13,9 +14,12 @@
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "ui/display/display.h" #include "ui/display/display.h"
#include "ui/display/display_observer.h" #include "ui/display/display_observer.h"
#include "ui/display/manager/chromeos/touchscreen_util.h"
#include "ui/display/manager/display_manager.h" #include "ui/display/manager/display_manager.h"
#include "ui/display/screen.h" #include "ui/display/screen.h"
#include "ui/display/test/display_manager_test_api.h" #include "ui/display/test/display_manager_test_api.h"
#include "ui/events/devices/device_data_manager.h"
#include "ui/events/devices/touchscreen_device.h"
namespace chromeos { namespace chromeos {
...@@ -25,63 +29,93 @@ class OobeDisplayChooserTest : public ash::AshTestBase { ...@@ -25,63 +29,93 @@ class OobeDisplayChooserTest : public ash::AshTestBase {
public: public:
OobeDisplayChooserTest() : ash::AshTestBase() {} OobeDisplayChooserTest() : ash::AshTestBase() {}
void SetUp() override { int64_t GetPrimaryDisplay() {
ash::AshTestBase::SetUp(); return display::Screen::GetScreen()->GetPrimaryDisplay().id();
display_manager_test_api_.reset(
new display::test::DisplayManagerTestApi(display_manager()));
} }
void EnableTouch(int64_t id) { void UpdateTouchscreenDevices(const ui::TouchscreenDevice& touchscreen) {
display_manager_test_api_->SetTouchSupport( std::vector<ui::TouchscreenDevice> devices{touchscreen};
id, display::Display::TouchSupport::TOUCH_SUPPORT_AVAILABLE);
}
void DisableTouch(int64_t id) { ui::DeviceHotplugEventObserver* manager =
display_manager_test_api_->SetTouchSupport( ui::DeviceDataManager::GetInstance();
id, display::Display::TouchSupport::TOUCH_SUPPORT_UNAVAILABLE); manager->OnTouchscreenDevicesUpdated(devices);
}
int64_t GetPrimaryDisplay() {
return display::Screen::GetScreen()->GetPrimaryDisplay().id();
} }
private: private:
std::unique_ptr<display::test::DisplayManagerTestApi>
display_manager_test_api_;
DISALLOW_COPY_AND_ASSIGN(OobeDisplayChooserTest); DISALLOW_COPY_AND_ASSIGN(OobeDisplayChooserTest);
}; };
const uint16_t kWhitelistedId = 0x266e;
} // namespace } // namespace
TEST_F(OobeDisplayChooserTest, PreferTouchAsPrimary) { TEST_F(OobeDisplayChooserTest, PreferTouchAsPrimary) {
OobeDisplayChooser display_chooser; // Setup 2 displays, second one is intended to be a touch display
std::vector<display::ManagedDisplayInfo> display_info;
display_info.push_back(
display::ManagedDisplayInfo::CreateFromSpecWithID("0+0-3000x2000", 1));
display_info.push_back(
display::ManagedDisplayInfo::CreateFromSpecWithID("3000+0-800x600", 2));
display_manager()->OnNativeDisplaysChanged(display_info);
base::RunLoop().RunUntilIdle();
UpdateDisplay("3000x2000,800x600"); // Make sure the non-touch display is primary
display::DisplayIdList ids = display_manager()->GetCurrentDisplayIdList(); ash::Shell::Get()->window_tree_host_manager()->SetPrimaryDisplayId(1);
DisableTouch(ids[0]);
EnableTouch(ids[1]);
EXPECT_EQ(ids[0], GetPrimaryDisplay()); // Setup corresponding TouchscreenDevice object
display_chooser.TryToPlaceUiOnTouchDisplay(); ui::TouchscreenDevice touchscreen =
ui::TouchscreenDevice(1, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL,
"Touchscreen", gfx::Size(800, 600), 1);
touchscreen.vendor_id = kWhitelistedId;
UpdateTouchscreenDevices(touchscreen);
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
EXPECT_EQ(ids[1], GetPrimaryDisplay()); // Associate touchscreen device with display
} display_info[1].AddInputDevice(touchscreen.id);
display_info[1].set_touch_support(display::Display::TOUCH_SUPPORT_AVAILABLE);
display_manager()->OnNativeDisplaysChanged(display_info);
base::RunLoop().RunUntilIdle();
TEST_F(OobeDisplayChooserTest, AddingSecondTouchDisplayShouldbeNOP) {
OobeDisplayChooser display_chooser; OobeDisplayChooser display_chooser;
EXPECT_EQ(1, GetPrimaryDisplay());
display_chooser.TryToPlaceUiOnTouchDisplay();
base::RunLoop().RunUntilIdle();
EXPECT_EQ(2, GetPrimaryDisplay());
}
UpdateDisplay("3000x2000,800x600"); TEST_F(OobeDisplayChooserTest, DontSwitchFromTouch) {
display::DisplayIdList ids = display_manager()->GetCurrentDisplayIdList(); // Setup 2 displays, second one is intended to be a touch display
EnableTouch(ids[0]); std::vector<display::ManagedDisplayInfo> display_info;
EnableTouch(ids[1]); display_info.push_back(
display::ManagedDisplayInfo::CreateFromSpecWithID("0+0-3000x2000", 1));
display_info.push_back(
display::ManagedDisplayInfo::CreateFromSpecWithID("3000+0-800x600", 2));
display_info[0].set_touch_support(display::Display::TOUCH_SUPPORT_AVAILABLE);
display_manager()->OnNativeDisplaysChanged(display_info);
base::RunLoop().RunUntilIdle();
EXPECT_EQ(ids[0], GetPrimaryDisplay()); // Make sure the non-touch display is primary
display_chooser.TryToPlaceUiOnTouchDisplay(); ash::Shell::Get()->window_tree_host_manager()->SetPrimaryDisplayId(1);
// Setup corresponding TouchscreenDevice object
ui::TouchscreenDevice touchscreen =
ui::TouchscreenDevice(1, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL,
"Touchscreen", gfx::Size(800, 600), 1);
touchscreen.vendor_id = kWhitelistedId;
UpdateTouchscreenDevices(touchscreen);
base::RunLoop().RunUntilIdle();
// Associate touchscreen device with display
display_info[1].AddInputDevice(touchscreen.id);
display_info[1].set_touch_support(display::Display::TOUCH_SUPPORT_AVAILABLE);
display_manager()->OnNativeDisplaysChanged(display_info);
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
EXPECT_EQ(ids[0], GetPrimaryDisplay()); OobeDisplayChooser display_chooser;
EXPECT_EQ(1, GetPrimaryDisplay());
display_chooser.TryToPlaceUiOnTouchDisplay();
base::RunLoop().RunUntilIdle();
EXPECT_EQ(1, GetPrimaryDisplay());
} }
} // namespace chromeos } // namespace chromeos
...@@ -226,17 +226,12 @@ std::string GetDisplayType(const GURL& url) { ...@@ -226,17 +226,12 @@ std::string GetDisplayType(const GURL& url) {
return path; return path;
} }
bool IsKeyboardConnected() { bool IsRemoraRequisitioned() {
const std::vector<ui::InputDevice>& keyboards = policy::DeviceCloudPolicyManagerChromeOS* policy_manager =
ui::InputDeviceManager::GetInstance()->GetKeyboardDevices(); g_browser_process->platform_part()
for (const ui::InputDevice& keyboard : keyboards) { ->browser_policy_connector_chromeos()
if (keyboard.type == ui::INPUT_DEVICE_INTERNAL || ->GetDeviceCloudPolicyManager();
keyboard.type == ui::INPUT_DEVICE_EXTERNAL) { return policy_manager && policy_manager->IsRemoraRequisition();
return true;
}
}
return false;
} }
} // namespace } // namespace
...@@ -376,7 +371,7 @@ OobeUI::OobeUI(content::WebUI* web_ui, const GURL& url) ...@@ -376,7 +371,7 @@ OobeUI::OobeUI(content::WebUI* web_ui, const GURL& url)
// TODO(felixe): Display iteration and primary display selection not supported // TODO(felixe): Display iteration and primary display selection not supported
// in Mash. See http://crbug.com/720917. // in Mash. See http://crbug.com/720917.
if (!ash_util::IsRunningInMash() && !IsKeyboardConnected()) if (!ash_util::IsRunningInMash() && IsRemoraRequisitioned())
oobe_display_chooser_ = base::MakeUnique<OobeDisplayChooser>(); oobe_display_chooser_ = base::MakeUnique<OobeDisplayChooser>();
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment