Commit b726eb10 authored by pkotwicz's avatar pkotwicz Committed by Commit bot

Make PointerDeviceObserver work under Ozone

This CL:
- Makes PointerDeviceObserver get notified when a mouse or touchpad is
  plugged in or removed by making PointerDeviceObserver an
  InputDeviceEventObserver on ozone only.
- Adds InputDeviceEventObserver::OnMouseDeviceConfigurationChanged() and
       InputDeviceEventObserver::OnTouchpadDeviceConfigurationChanged().
- Adds the plumbing from EventFactoryEvdev to notify
  InputDeviceEventObservers when a mouse or touchpad is plugged in or
  removed.

In a later CL I will make PointerDeviceObserver an InputDeviceEventObserver on
X11 and add the X11 plumbing

BUG=450899
TEST=Manual, see bug

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

Cr-Commit-Position: refs/heads/master@{#314400}
parent 13cc94a3
...@@ -280,4 +280,10 @@ void DisplayChangeObserver::OnTouchscreenDeviceConfigurationChanged() { ...@@ -280,4 +280,10 @@ void DisplayChangeObserver::OnTouchscreenDeviceConfigurationChanged() {
void DisplayChangeObserver::OnKeyboardDeviceConfigurationChanged() { void DisplayChangeObserver::OnKeyboardDeviceConfigurationChanged() {
} }
void DisplayChangeObserver::OnMouseDeviceConfigurationChanged() {
}
void DisplayChangeObserver::OnTouchpadDeviceConfigurationChanged() {
}
} // namespace ash } // namespace ash
...@@ -50,6 +50,8 @@ class DisplayChangeObserver : public ui::DisplayConfigurator::StateController, ...@@ -50,6 +50,8 @@ class DisplayChangeObserver : public ui::DisplayConfigurator::StateController,
// Overriden from ui::InputDeviceEventObserver: // Overriden from ui::InputDeviceEventObserver:
void OnTouchscreenDeviceConfigurationChanged() override; void OnTouchscreenDeviceConfigurationChanged() override;
void OnKeyboardDeviceConfigurationChanged() override; void OnKeyboardDeviceConfigurationChanged() override;
void OnMouseDeviceConfigurationChanged() override;
void OnTouchpadDeviceConfigurationChanged() override;
// Overriden from ShellObserver: // Overriden from ShellObserver:
void OnAppTerminating() override; void OnAppTerminating() override;
......
...@@ -67,6 +67,12 @@ void VirtualKeyboardController::OnKeyboardDeviceConfigurationChanged() { ...@@ -67,6 +67,12 @@ void VirtualKeyboardController::OnKeyboardDeviceConfigurationChanged() {
UpdateDevices(); UpdateDevices();
} }
void VirtualKeyboardController::OnMouseDeviceConfigurationChanged() {
}
void VirtualKeyboardController::OnTouchpadDeviceConfigurationChanged() {
}
void VirtualKeyboardController::ToggleIgnoreExternalKeyboard() { void VirtualKeyboardController::ToggleIgnoreExternalKeyboard() {
ignore_external_keyboard_ = !ignore_external_keyboard_; ignore_external_keyboard_ = !ignore_external_keyboard_;
UpdateKeyboardEnabled(); UpdateKeyboardEnabled();
......
...@@ -28,6 +28,8 @@ class ASH_EXPORT VirtualKeyboardController ...@@ -28,6 +28,8 @@ class ASH_EXPORT VirtualKeyboardController
// ui::InputDeviceObserver: // ui::InputDeviceObserver:
void OnTouchscreenDeviceConfigurationChanged() override; void OnTouchscreenDeviceConfigurationChanged() override;
void OnKeyboardDeviceConfigurationChanged() override; void OnKeyboardDeviceConfigurationChanged() override;
void OnMouseDeviceConfigurationChanged() override;
void OnTouchpadDeviceConfigurationChanged() override;
// Toggles whether the presense of an external keyboard should be ignored // Toggles whether the presense of an external keyboard should be ignored
// when determining whether or not to show the on-screen keyboard. // when determining whether or not to show the on-screen keyboard.
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "base/bind_helpers.h" #include "base/bind_helpers.h"
#include "chrome/browser/chromeos/system/input_device_settings.h" #include "chrome/browser/chromeos/system/input_device_settings.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "ui/events/devices/device_data_manager.h"
#if defined(USE_X11) #if defined(USE_X11)
#include "chrome/browser/chromeos/events/xinput_hierarchy_changed_event_listener.h" #include "chrome/browser/chromeos/events/xinput_hierarchy_changed_event_listener.h"
...@@ -27,6 +28,8 @@ PointerDeviceObserver::~PointerDeviceObserver() { ...@@ -27,6 +28,8 @@ PointerDeviceObserver::~PointerDeviceObserver() {
#if defined(USE_X11) #if defined(USE_X11)
XInputHierarchyChangedEventListener::GetInstance() XInputHierarchyChangedEventListener::GetInstance()
->RemoveObserver(this); ->RemoveObserver(this);
#elif defined(USE_OZONE)
ui::DeviceDataManager::GetInstance()->RemoveObserver(this);
#endif #endif
} }
...@@ -34,6 +37,8 @@ void PointerDeviceObserver::Init() { ...@@ -34,6 +37,8 @@ void PointerDeviceObserver::Init() {
#if defined(USE_X11) #if defined(USE_X11)
XInputHierarchyChangedEventListener::GetInstance() XInputHierarchyChangedEventListener::GetInstance()
->AddObserver(this); ->AddObserver(this);
#elif defined(USE_OZONE)
ui::DeviceDataManager::GetInstance()->AddObserver(this);
#endif #endif
} }
...@@ -54,6 +59,14 @@ void PointerDeviceObserver::DeviceHierarchyChanged() { ...@@ -54,6 +59,14 @@ void PointerDeviceObserver::DeviceHierarchyChanged() {
CheckDevices(); CheckDevices();
} }
void PointerDeviceObserver::OnMouseDeviceConfigurationChanged() {
CheckDevices();
}
void PointerDeviceObserver::OnTouchpadDeviceConfigurationChanged() {
CheckDevices();
}
void PointerDeviceObserver::CheckTouchpadExists() { void PointerDeviceObserver::CheckTouchpadExists() {
InputDeviceSettings::Get()->TouchpadExists( InputDeviceSettings::Get()->TouchpadExists(
base::Bind(&PointerDeviceObserver::OnTouchpadExists, base::Bind(&PointerDeviceObserver::OnTouchpadExists,
......
...@@ -8,11 +8,13 @@ ...@@ -8,11 +8,13 @@
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/observer_list.h" #include "base/observer_list.h"
#include "chrome/browser/chromeos/device_hierarchy_observer.h" #include "chrome/browser/chromeos/device_hierarchy_observer.h"
#include "ui/events/devices/input_device_event_observer.h"
namespace chromeos { namespace chromeos {
namespace system { namespace system {
class PointerDeviceObserver : public DeviceHierarchyObserver { class PointerDeviceObserver : public DeviceHierarchyObserver,
public ui::InputDeviceEventObserver {
public: public:
PointerDeviceObserver(); PointerDeviceObserver();
~PointerDeviceObserver() override; ~PointerDeviceObserver() override;
...@@ -36,11 +38,17 @@ class PointerDeviceObserver : public DeviceHierarchyObserver { ...@@ -36,11 +38,17 @@ class PointerDeviceObserver : public DeviceHierarchyObserver {
void RemoveObserver(Observer* observer); void RemoveObserver(Observer* observer);
private: private:
// DeviceHierarchyObserver implementation. // DeviceHierarchyObserver:
void DeviceHierarchyChanged() override; void DeviceHierarchyChanged() override;
void DeviceAdded(int device_id) override {} void DeviceAdded(int device_id) override {}
void DeviceRemoved(int device_id) override {} void DeviceRemoved(int device_id) override {}
// InputDeviceEventObserver:
void OnTouchscreenDeviceConfigurationChanged() override {}
void OnKeyboardDeviceConfigurationChanged() override {}
void OnMouseDeviceConfigurationChanged() override;
void OnTouchpadDeviceConfigurationChanged() override;
// Check for pointer devices. // Check for pointer devices.
void CheckTouchpadExists(); void CheckTouchpadExists();
void CheckMouseExists(); void CheckMouseExists();
......
...@@ -149,6 +149,20 @@ void DeviceDataManager::OnKeyboardDevicesUpdated( ...@@ -149,6 +149,20 @@ void DeviceDataManager::OnKeyboardDevicesUpdated(
OnKeyboardDeviceConfigurationChanged()); OnKeyboardDeviceConfigurationChanged());
} }
void DeviceDataManager::OnMouseDevicesUpdated(
const std::vector<InputDevice>& devices) {
FOR_EACH_OBSERVER(InputDeviceEventObserver,
observers_,
OnMouseDeviceConfigurationChanged());
}
void DeviceDataManager::OnTouchpadDevicesUpdated(
const std::vector<InputDevice>& devices) {
FOR_EACH_OBSERVER(InputDeviceEventObserver,
observers_,
OnTouchpadDeviceConfigurationChanged());
}
void DeviceDataManager::AddObserver(InputDeviceEventObserver* observer) { void DeviceDataManager::AddObserver(InputDeviceEventObserver* observer) {
observers_.AddObserver(observer); observers_.AddObserver(observer);
} }
......
...@@ -64,6 +64,10 @@ class EVENTS_DEVICES_EXPORT DeviceDataManager ...@@ -64,6 +64,10 @@ class EVENTS_DEVICES_EXPORT DeviceDataManager
const std::vector<TouchscreenDevice>& devices) override; const std::vector<TouchscreenDevice>& devices) override;
void OnKeyboardDevicesUpdated( void OnKeyboardDevicesUpdated(
const std::vector<KeyboardDevice>& devices) override; const std::vector<KeyboardDevice>& devices) override;
void OnMouseDevicesUpdated(
const std::vector<InputDevice>& devices) override;
void OnTouchpadDevicesUpdated(
const std::vector<InputDevice>& devices) override;
private: private:
static DeviceDataManager* instance_; static DeviceDataManager* instance_;
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
namespace ui { namespace ui {
struct InputDevice;
struct KeyboardDevice; struct KeyboardDevice;
struct TouchscreenDevice; struct TouchscreenDevice;
...@@ -20,14 +21,24 @@ class EVENTS_DEVICES_EXPORT DeviceHotplugEventObserver { ...@@ -20,14 +21,24 @@ class EVENTS_DEVICES_EXPORT DeviceHotplugEventObserver {
virtual ~DeviceHotplugEventObserver() {} virtual ~DeviceHotplugEventObserver() {}
// On a hotplug event this is called with the list of available touchscreen // On a hotplug event this is called with the list of available touchscreen
// devices. The set of touchscreen devices may not necessarily have changed. // devices. The set of touchscreen devices may not have changed.
virtual void OnTouchscreenDevicesUpdated( virtual void OnTouchscreenDevicesUpdated(
const std::vector<TouchscreenDevice>& devices) = 0; const std::vector<TouchscreenDevice>& devices) = 0;
// On a hotplug event this is called with the list of available keyboard // On a hotplug event this is called with the list of available keyboard
// devices. The set of keyboard devices may not necessarily have changed. // devices. The set of keyboard devices may not have changed.
virtual void OnKeyboardDevicesUpdated( virtual void OnKeyboardDevicesUpdated(
const std::vector<KeyboardDevice>& devices) = 0; const std::vector<KeyboardDevice>& devices) = 0;
// On a hotplug event this is called with the list of available mice. The set
// of mice may not have changed.
virtual void OnMouseDevicesUpdated(
const std::vector<InputDevice>& devices) = 0;
// On a hotplug event this is called with the list of available touchpads. The
// set of touchpads may not have changed.
virtual void OnTouchpadDevicesUpdated(
const std::vector<InputDevice>& devices) = 0;
}; };
} // namespace ui } // namespace ui
......
...@@ -16,6 +16,8 @@ class EVENTS_DEVICES_EXPORT InputDeviceEventObserver { ...@@ -16,6 +16,8 @@ class EVENTS_DEVICES_EXPORT InputDeviceEventObserver {
virtual void OnKeyboardDeviceConfigurationChanged() = 0; virtual void OnKeyboardDeviceConfigurationChanged() = 0;
virtual void OnTouchscreenDeviceConfigurationChanged() = 0; virtual void OnTouchscreenDeviceConfigurationChanged() = 0;
virtual void OnMouseDeviceConfigurationChanged() = 0;
virtual void OnTouchpadDeviceConfigurationChanged() = 0;
}; };
} // namespace ui } // namespace ui
......
...@@ -39,6 +39,8 @@ class TestInputDeviceObserver : public InputDeviceEventObserver { ...@@ -39,6 +39,8 @@ class TestInputDeviceObserver : public InputDeviceEventObserver {
void OnKeyboardDeviceConfigurationChanged() override { void OnKeyboardDeviceConfigurationChanged() override {
change_notified_ = true; change_notified_ = true;
} }
void OnMouseDeviceConfigurationChanged() override {}
void OnTouchpadDeviceConfigurationChanged() override {}
int change_notified() const { return change_notified_; } int change_notified() const { return change_notified_; }
void Reset() { change_notified_ = false; } void Reset() { change_notified_ = false; }
......
...@@ -254,12 +254,16 @@ void EventFactoryEvdev::DispatchMouseDevicesUpdated( ...@@ -254,12 +254,16 @@ void EventFactoryEvdev::DispatchMouseDevicesUpdated(
const std::vector<InputDevice>& devices) { const std::vector<InputDevice>& devices) {
// There's no list of mice in DeviceDataManager. // There's no list of mice in DeviceDataManager.
input_controller_.set_has_mouse(devices.size() != 0); input_controller_.set_has_mouse(devices.size() != 0);
DeviceHotplugEventObserver* observer = DeviceDataManager::GetInstance();
observer->OnMouseDevicesUpdated(devices);
} }
void EventFactoryEvdev::DispatchTouchpadDevicesUpdated( void EventFactoryEvdev::DispatchTouchpadDevicesUpdated(
const std::vector<InputDevice>& devices) { const std::vector<InputDevice>& devices) {
// There's no list of touchpads in DeviceDataManager. // There's no list of touchpads in DeviceDataManager.
input_controller_.set_has_touchpad(devices.size() != 0); input_controller_.set_has_touchpad(devices.size() != 0);
DeviceHotplugEventObserver* observer = DeviceDataManager::GetInstance();
observer->OnTouchpadDevicesUpdated(devices);
} }
......
...@@ -340,6 +340,8 @@ void X11HotplugEventHandler::OnHotplugEvent() { ...@@ -340,6 +340,8 @@ void X11HotplugEventHandler::OnHotplugEvent() {
UiCallbacks callbacks; UiCallbacks callbacks;
callbacks.keyboard_callback = base::Bind(&OnKeyboardDevices); callbacks.keyboard_callback = base::Bind(&OnKeyboardDevices);
callbacks.touchscreen_callback = base::Bind(&OnTouchscreenDevices); callbacks.touchscreen_callback = base::Bind(&OnTouchscreenDevices);
// TODO(pkotwicz): Compute the lists of mice and touchpads and send the new
// lists to DeviceHotplugEventObserver.
// Parsing the device information may block, so delegate the operation to a // Parsing the device information may block, so delegate the operation to a
// worker thread. Once the device information is extracted the parsed devices // worker thread. Once the device information is extracted the parsed devices
......
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