Skip to content
This repository has been archived by the owner on Apr 3, 2020. It is now read-only.

Commit

Permalink
Ozone support for device special cases in keyboard event rewriting.
Browse files Browse the repository at this point in the history
Keyboard event rewriting has some special cases keyed on the device
name (Apple keyboards) or USB VID/PID (Hotrod remote), which had been
handled by special-case device inspection under X11, and not handled
at all under Ozone. This moves the properties to ui::DeviceDataManager
and makes the use in chromeos::EventRewriter platform-independent.

Changed ui::InputDevice::id and ash::DisplayInfo::touch_device_id_ from
'unsigned int' to 'int' in accordance with the coding style guide.

BUG=471753
[email protected],[email protected],[email protected]

Review URL: https://codereview.chromium.org/1073573002

Cr-Commit-Position: refs/heads/master@{#325660}
(cherry picked from commit 711f2fc)

Review URL: https://codereview.chromium.org/1071193002

Cr-Commit-Position: refs/heads/master@{#325042}
(cherry picked from commit a824971)

Review URL: https://codereview.chromium.org/1090863003

Cr-Commit-Position: refs/branch-heads/2357@{#162}
Cr-Branched-From: 59d4494-refs/heads/master@{#323860}
  • Loading branch information
Kevin Schoedel committed Apr 20, 2015
1 parent 175e832 commit b4afab1
Show file tree
Hide file tree
Showing 44 changed files with 487 additions and 365 deletions.
6 changes: 3 additions & 3 deletions ash/display/display_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ class ASH_EXPORT DisplayInfo {
}
gfx::Display::TouchSupport touch_support() const { return touch_support_; }

void set_touch_device_id(unsigned int id) { touch_device_id_ = id; }
unsigned int touch_device_id() const { return touch_device_id_; }
void set_touch_device_id(int id) { touch_device_id_ = id; }
int touch_device_id() const { return touch_device_id_; }

// Gets/Sets the device scale factor of the display.
float device_scale_factor() const { return device_scale_factor_; }
Expand Down Expand Up @@ -236,7 +236,7 @@ class ASH_EXPORT DisplayInfo {

// If the display is also a touch device, it will have a positive
// |touch_device_id_|. Otherwise |touch_device_id_| is 0.
unsigned int touch_device_id_;
int touch_device_id_;

// This specifies the device's pixel density. (For example, a
// display whose DPI is higher than the threshold is considered to have
Expand Down
4 changes: 2 additions & 2 deletions ash/host/ash_window_tree_host_x11_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ TEST_F(AshWindowTreeHostX11Test, DispatchTouchEventToOneRootWindow) {
scoped_ptr<RootWindowEventHandler> handler(
new RootWindowEventHandler(window_tree_host.get()));

std::vector<unsigned int> devices;
std::vector<int> devices;
devices.push_back(0);
ui::SetUpTouchDevicesForTest(devices);
std::vector<ui::Valuator> valuators;
Expand Down Expand Up @@ -155,7 +155,7 @@ TEST_F(AshWindowTreeHostX11Test, DispatchTouchEventToTwoRootWindow) {
scoped_ptr<RootWindowEventHandler> handler2(
new RootWindowEventHandler(window_tree_host2.get()));

std::vector<unsigned int> devices;
std::vector<int> devices;
devices.push_back(0);
ui::SetUpTouchDevicesForTest(devices);
std::vector<ui::Valuator> valuators;
Expand Down
9 changes: 5 additions & 4 deletions ash/test/virtual_keyboard_test_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ void VirtualKeyboardTestHelper::SuppressKeyboard() {
ui::DeviceHotplugEventObserver* manager =
ui::DeviceDataManager::GetInstance();
std::vector<ui::TouchscreenDevice> screens;
screens.push_back(ui::TouchscreenDevice(
1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, gfx::Size(1024, 768), 0));
screens.push_back(
ui::TouchscreenDevice(1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL,
"Touchscreen", gfx::Size(1024, 768), 0));
manager->OnTouchscreenDevicesUpdated(screens);

std::vector<ui::KeyboardDevice> keyboards;
keyboards.push_back(
ui::KeyboardDevice(2, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL));
keyboards.push_back(ui::KeyboardDevice(
2, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "keyboard"));
manager->OnKeyboardDevicesUpdated(keyboards);
}

Expand Down
2 changes: 1 addition & 1 deletion ash/touch/touch_transformer_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ DisplayManager* GetDisplayManager() {
return Shell::GetInstance()->display_manager();
}

ui::TouchscreenDevice FindTouchscreenById(unsigned int id) {
ui::TouchscreenDevice FindTouchscreenById(int id) {
const std::vector<ui::TouchscreenDevice>& touchscreens =
ui::DeviceDataManager::GetInstance()->touchscreen_devices();
for (const auto& touchscreen : touchscreens) {
Expand Down
2 changes: 1 addition & 1 deletion ash/touch/touch_transformer_controller_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ DisplayInfo CreateDisplayInfo(int64 id,
ui::TouchscreenDevice CreateTouchscreenDevice(unsigned int id,
const gfx::Size& size) {
return ui::TouchscreenDevice(id, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL,
size, 0);
std::string(), size, 0);
}

} // namespace
Expand Down
63 changes: 36 additions & 27 deletions ash/touch/touchscreen_util_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -76,74 +76,83 @@ TEST_F(TouchscreenUtilTest, NoTouchscreens) {

TEST_F(TouchscreenUtilTest, OneToOneMapping) {
std::vector<ui::TouchscreenDevice> devices;
devices.push_back(ui::TouchscreenDevice(
1, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, gfx::Size(800, 600), 0));
devices.push_back(ui::TouchscreenDevice(
2, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, gfx::Size(1024, 768), 0));
devices.push_back(
ui::TouchscreenDevice(1, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "",
gfx::Size(800, 600), 0));
devices.push_back(
ui::TouchscreenDevice(2, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "",
gfx::Size(1024, 768), 0));

AssociateTouchscreens(&displays_, devices);

EXPECT_EQ(ui::TouchscreenDevice::kInvalidId, displays_[0].touch_device_id());
EXPECT_EQ(1u, displays_[1].touch_device_id());
EXPECT_EQ(1, displays_[1].touch_device_id());
EXPECT_EQ(ui::TouchscreenDevice::kInvalidId, displays_[2].touch_device_id());
EXPECT_EQ(2u, displays_[3].touch_device_id());
EXPECT_EQ(2, displays_[3].touch_device_id());
}

TEST_F(TouchscreenUtilTest, MapToCorrectDisplaySize) {
std::vector<ui::TouchscreenDevice> devices;
devices.push_back(ui::TouchscreenDevice(
2, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, gfx::Size(1024, 768), 0));
devices.push_back(
ui::TouchscreenDevice(2, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "",
gfx::Size(1024, 768), 0));

AssociateTouchscreens(&displays_, devices);

EXPECT_EQ(ui::TouchscreenDevice::kInvalidId, displays_[0].touch_device_id());
EXPECT_EQ(ui::TouchscreenDevice::kInvalidId, displays_[1].touch_device_id());
EXPECT_EQ(ui::TouchscreenDevice::kInvalidId, displays_[2].touch_device_id());
EXPECT_EQ(2u, displays_[3].touch_device_id());
EXPECT_EQ(2, displays_[3].touch_device_id());
}

TEST_F(TouchscreenUtilTest, MapWhenSizeDiffersByOne) {
std::vector<ui::TouchscreenDevice> devices;
devices.push_back(ui::TouchscreenDevice(
1, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, gfx::Size(801, 600), 0));
devices.push_back(ui::TouchscreenDevice(
2, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, gfx::Size(1023, 768), 0));
devices.push_back(
ui::TouchscreenDevice(1, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "",
gfx::Size(801, 600), 0));
devices.push_back(
ui::TouchscreenDevice(2, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "",
gfx::Size(1023, 768), 0));

AssociateTouchscreens(&displays_, devices);

EXPECT_EQ(ui::TouchscreenDevice::kInvalidId, displays_[0].touch_device_id());
EXPECT_EQ(1u, displays_[1].touch_device_id());
EXPECT_EQ(1, displays_[1].touch_device_id());
EXPECT_EQ(ui::TouchscreenDevice::kInvalidId, displays_[2].touch_device_id());
EXPECT_EQ(2u, displays_[3].touch_device_id());
EXPECT_EQ(2, displays_[3].touch_device_id());
}

TEST_F(TouchscreenUtilTest, MapWhenSizesDoNotMatch) {
std::vector<ui::TouchscreenDevice> devices;
devices.push_back(ui::TouchscreenDevice(
1, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, gfx::Size(1022, 768), 0));
devices.push_back(ui::TouchscreenDevice(
2, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, gfx::Size(802, 600), 0));
devices.push_back(
ui::TouchscreenDevice(1, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "",
gfx::Size(1022, 768), 0));
devices.push_back(
ui::TouchscreenDevice(2, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "",
gfx::Size(802, 600), 0));

AssociateTouchscreens(&displays_, devices);

EXPECT_EQ(ui::TouchscreenDevice::kInvalidId, displays_[0].touch_device_id());
EXPECT_EQ(1u, displays_[1].touch_device_id());
EXPECT_EQ(1, displays_[1].touch_device_id());
EXPECT_EQ(ui::TouchscreenDevice::kInvalidId, displays_[2].touch_device_id());
EXPECT_EQ(2u, displays_[3].touch_device_id());
EXPECT_EQ(2, displays_[3].touch_device_id());
}

TEST_F(TouchscreenUtilTest, MapInternalTouchscreen) {
std::vector<ui::TouchscreenDevice> devices;
devices.push_back(ui::TouchscreenDevice(
1, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, gfx::Size(1920, 1080), 0));
devices.push_back(ui::TouchscreenDevice(
2, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, gfx::Size(9999, 888), 0));
devices.push_back(
ui::TouchscreenDevice(1, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "",
gfx::Size(1920, 1080), 0));
devices.push_back(
ui::TouchscreenDevice(2, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "",
gfx::Size(9999, 888), 0));

AssociateTouchscreens(&displays_, devices);

// Internal touchscreen is always mapped to internal display.
EXPECT_EQ(2u, displays_[0].touch_device_id());
EXPECT_EQ(1u, displays_[1].touch_device_id());
EXPECT_EQ(2, displays_[0].touch_device_id());
EXPECT_EQ(1, displays_[1].touch_device_id());
EXPECT_EQ(ui::TouchscreenDevice::kInvalidId, displays_[2].touch_device_id());
EXPECT_EQ(ui::TouchscreenDevice::kInvalidId, displays_[3].touch_device_id());
}
Expand Down
79 changes: 42 additions & 37 deletions ash/virtual_keyboard_controller_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,8 @@ class VirtualKeyboardControllerTest : public AshTestBase {
// Sets the event blocker on the maximized window controller.
void SetEventBlocker(
scoped_ptr<ScopedDisableInternalMouseAndKeyboard> blocker) {
Shell::GetInstance()
->maximize_mode_controller()
->event_blocker_ = blocker.Pass();
Shell::GetInstance()->maximize_mode_controller()->event_blocker_ =
blocker.Pass();
}

void SetUp() override {
Expand Down Expand Up @@ -84,8 +83,8 @@ class MockEventBlocker : public ScopedDisableInternalMouseAndKeyboard {
MockEventBlocker() {}
~MockEventBlocker() override {
std::vector<ui::KeyboardDevice> keyboards;
keyboards.push_back(
ui::KeyboardDevice(1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL));
keyboards.push_back(ui::KeyboardDevice(
1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "keyboard"));
ui::DeviceHotplugEventObserver* manager =
ui::DeviceDataManager::GetInstance();
manager->OnKeyboardDevicesUpdated(keyboards);
Expand All @@ -102,8 +101,8 @@ TEST_F(VirtualKeyboardControllerTest, RestoreKeyboardDevices) {
Shell::GetInstance()
->maximize_mode_controller()
->EnableMaximizeModeWindowManager(true);
scoped_ptr<ScopedDisableInternalMouseAndKeyboard>
blocker(new MockEventBlocker);
scoped_ptr<ScopedDisableInternalMouseAndKeyboard> blocker(
new MockEventBlocker);
SetEventBlocker(blocker.Pass());
}

Expand Down Expand Up @@ -157,12 +156,13 @@ class VirtualKeyboardControllerAutoTest : public VirtualKeyboardControllerTest,
// present and maximized mode is disabled.
TEST_F(VirtualKeyboardControllerAutoTest, DisabledIfInternalKeyboardPresent) {
std::vector<ui::TouchscreenDevice> screens;
screens.push_back(ui::TouchscreenDevice(
1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, gfx::Size(1024, 768), 0));
screens.push_back(
ui::TouchscreenDevice(1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL,
"Touchscreen", gfx::Size(1024, 768), 0));
UpdateTouchscreenDevices(screens);
std::vector<ui::KeyboardDevice> keyboards;
keyboards.push_back(
ui::KeyboardDevice(1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL));
keyboards.push_back(ui::KeyboardDevice(
1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "keyboard"));
UpdateKeyboardDevices(keyboards);
ASSERT_FALSE(keyboard::IsKeyboardEnabled());
// Remove the internal keyboard. Virtual keyboard should now show.
Expand All @@ -176,8 +176,9 @@ TEST_F(VirtualKeyboardControllerAutoTest, DisabledIfInternalKeyboardPresent) {
TEST_F(VirtualKeyboardControllerAutoTest, DisabledIfNoTouchScreen) {
std::vector<ui::TouchscreenDevice> devices;
// Add a touchscreen. Keyboard should deploy.
devices.push_back(ui::TouchscreenDevice(
1, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, gfx::Size(800, 600), 0));
devices.push_back(
ui::TouchscreenDevice(1, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL,
"Touchscreen", gfx::Size(800, 600), 0));
UpdateTouchscreenDevices(devices);
EXPECT_TRUE(keyboard::IsKeyboardEnabled());
// Remove touchscreen. Keyboard should hide.
Expand All @@ -187,12 +188,13 @@ TEST_F(VirtualKeyboardControllerAutoTest, DisabledIfNoTouchScreen) {

TEST_F(VirtualKeyboardControllerAutoTest, SuppressedIfExternalKeyboardPresent) {
std::vector<ui::TouchscreenDevice> screens;
screens.push_back(ui::TouchscreenDevice(
1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, gfx::Size(1024, 768), 0));
screens.push_back(
ui::TouchscreenDevice(1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL,
"Touchscreen", gfx::Size(1024, 768), 0));
UpdateTouchscreenDevices(screens);
std::vector<ui::KeyboardDevice> keyboards;
keyboards.push_back(
ui::KeyboardDevice(1, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL));
keyboards.push_back(ui::KeyboardDevice(
1, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "keyboard"));
UpdateKeyboardDevices(keyboards);
ASSERT_FALSE(keyboard::IsKeyboardEnabled());
ASSERT_TRUE(notified());
Expand Down Expand Up @@ -225,25 +227,26 @@ TEST_F(VirtualKeyboardControllerAutoTest, SuppressedIfExternalKeyboardPresent) {
// Tests handling multiple keyboards. Catches crbug.com/430252
TEST_F(VirtualKeyboardControllerAutoTest, HandleMultipleKeyboardsPresent) {
std::vector<ui::KeyboardDevice> keyboards;
keyboards.push_back(
ui::KeyboardDevice(1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL));
keyboards.push_back(
ui::KeyboardDevice(2, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL));
keyboards.push_back(
ui::KeyboardDevice(3, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL));
keyboards.push_back(ui::KeyboardDevice(
1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "keyboard"));
keyboards.push_back(ui::KeyboardDevice(
2, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "keyboard"));
keyboards.push_back(ui::KeyboardDevice(
3, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "keyboard"));
UpdateKeyboardDevices(keyboards);
ASSERT_FALSE(keyboard::IsKeyboardEnabled());
}

// Tests maximized mode interaction without disabling the internal keyboard.
TEST_F(VirtualKeyboardControllerAutoTest, EnabledDuringMaximizeMode) {
std::vector<ui::TouchscreenDevice> screens;
screens.push_back(ui::TouchscreenDevice(
1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, gfx::Size(1024, 768), 0));
screens.push_back(
ui::TouchscreenDevice(1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL,
"Touchscreen", gfx::Size(1024, 768), 0));
UpdateTouchscreenDevices(screens);
std::vector<ui::KeyboardDevice> keyboards;
keyboards.push_back(
ui::KeyboardDevice(1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL));
keyboards.push_back(ui::KeyboardDevice(
1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "Keyboard"));
UpdateKeyboardDevices(keyboards);
ASSERT_FALSE(keyboard::IsKeyboardEnabled());
// Toggle maximized mode on.
Expand All @@ -261,14 +264,15 @@ TEST_F(VirtualKeyboardControllerAutoTest, EnabledDuringMaximizeMode) {
// Tests that keyboard gets suppressed in maximized mode.
TEST_F(VirtualKeyboardControllerAutoTest, SuppressedInMaximizedMode) {
std::vector<ui::TouchscreenDevice> screens;
screens.push_back(ui::TouchscreenDevice(
1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, gfx::Size(1024, 768), 0));
screens.push_back(
ui::TouchscreenDevice(1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL,
"Touchscreen", gfx::Size(1024, 768), 0));
UpdateTouchscreenDevices(screens);
std::vector<ui::KeyboardDevice> keyboards;
keyboards.push_back(
ui::KeyboardDevice(1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL));
keyboards.push_back(
ui::KeyboardDevice(2, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL));
keyboards.push_back(ui::KeyboardDevice(
1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "Keyboard"));
keyboards.push_back(ui::KeyboardDevice(
2, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "Keyboard"));
UpdateKeyboardDevices(keyboards);
// Toggle maximized mode on.
Shell::GetInstance()
Expand Down Expand Up @@ -329,12 +333,13 @@ class VirtualKeyboardControllerAlwaysEnabledTest
// keyboard always enabled flag is active.
TEST_F(VirtualKeyboardControllerAlwaysEnabledTest, DoesNotSuppressKeyboard) {
std::vector<ui::TouchscreenDevice> screens;
screens.push_back(ui::TouchscreenDevice(
1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, gfx::Size(1024, 768), 0));
screens.push_back(
ui::TouchscreenDevice(1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL,
"Touchscreen", gfx::Size(1024, 768), 0));
UpdateTouchscreenDevices(screens);
std::vector<ui::KeyboardDevice> keyboards;
keyboards.push_back(
ui::KeyboardDevice(1, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL));
keyboards.push_back(ui::KeyboardDevice(
1, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "keyboard"));
UpdateKeyboardDevices(keyboards);
ASSERT_TRUE(keyboard::IsKeyboardEnabled());
}
Expand Down
Loading

0 comments on commit b4afab1

Please sign in to comment.