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() {
void DisplayChangeObserver::OnKeyboardDeviceConfigurationChanged() {
}
void DisplayChangeObserver::OnMouseDeviceConfigurationChanged() {
}
void DisplayChangeObserver::OnTouchpadDeviceConfigurationChanged() {
}
} // namespace ash
......@@ -50,6 +50,8 @@ class DisplayChangeObserver : public ui::DisplayConfigurator::StateController,
// Overriden from ui::InputDeviceEventObserver:
void OnTouchscreenDeviceConfigurationChanged() override;
void OnKeyboardDeviceConfigurationChanged() override;
void OnMouseDeviceConfigurationChanged() override;
void OnTouchpadDeviceConfigurationChanged() override;
// Overriden from ShellObserver:
void OnAppTerminating() override;
......
......@@ -67,6 +67,12 @@ void VirtualKeyboardController::OnKeyboardDeviceConfigurationChanged() {
UpdateDevices();
}
void VirtualKeyboardController::OnMouseDeviceConfigurationChanged() {
}
void VirtualKeyboardController::OnTouchpadDeviceConfigurationChanged() {
}
void VirtualKeyboardController::ToggleIgnoreExternalKeyboard() {
ignore_external_keyboard_ = !ignore_external_keyboard_;
UpdateKeyboardEnabled();
......
......@@ -28,6 +28,8 @@ class ASH_EXPORT VirtualKeyboardController
// ui::InputDeviceObserver:
void OnTouchscreenDeviceConfigurationChanged() override;
void OnKeyboardDeviceConfigurationChanged() override;
void OnMouseDeviceConfigurationChanged() override;
void OnTouchpadDeviceConfigurationChanged() override;
// Toggles whether the presense of an external keyboard should be ignored
// when determining whether or not to show the on-screen keyboard.
......
......@@ -9,6 +9,7 @@
#include "base/bind_helpers.h"
#include "chrome/browser/chromeos/system/input_device_settings.h"
#include "content/public/browser/browser_thread.h"
#include "ui/events/devices/device_data_manager.h"
#if defined(USE_X11)
#include "chrome/browser/chromeos/events/xinput_hierarchy_changed_event_listener.h"
......@@ -27,6 +28,8 @@ PointerDeviceObserver::~PointerDeviceObserver() {
#if defined(USE_X11)
XInputHierarchyChangedEventListener::GetInstance()
->RemoveObserver(this);
#elif defined(USE_OZONE)
ui::DeviceDataManager::GetInstance()->RemoveObserver(this);
#endif
}
......@@ -34,6 +37,8 @@ void PointerDeviceObserver::Init() {
#if defined(USE_X11)
XInputHierarchyChangedEventListener::GetInstance()
->AddObserver(this);
#elif defined(USE_OZONE)
ui::DeviceDataManager::GetInstance()->AddObserver(this);
#endif
}
......@@ -54,6 +59,14 @@ void PointerDeviceObserver::DeviceHierarchyChanged() {
CheckDevices();
}
void PointerDeviceObserver::OnMouseDeviceConfigurationChanged() {
CheckDevices();
}
void PointerDeviceObserver::OnTouchpadDeviceConfigurationChanged() {
CheckDevices();
}
void PointerDeviceObserver::CheckTouchpadExists() {
InputDeviceSettings::Get()->TouchpadExists(
base::Bind(&PointerDeviceObserver::OnTouchpadExists,
......
......@@ -8,11 +8,13 @@
#include "base/memory/weak_ptr.h"
#include "base/observer_list.h"
#include "chrome/browser/chromeos/device_hierarchy_observer.h"
#include "ui/events/devices/input_device_event_observer.h"
namespace chromeos {
namespace system {
class PointerDeviceObserver : public DeviceHierarchyObserver {
class PointerDeviceObserver : public DeviceHierarchyObserver,
public ui::InputDeviceEventObserver {
public:
PointerDeviceObserver();
~PointerDeviceObserver() override;
......@@ -36,11 +38,17 @@ class PointerDeviceObserver : public DeviceHierarchyObserver {
void RemoveObserver(Observer* observer);
private:
// DeviceHierarchyObserver implementation.
// DeviceHierarchyObserver:
void DeviceHierarchyChanged() override;
void DeviceAdded(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.
void CheckTouchpadExists();
void CheckMouseExists();
......
......@@ -149,6 +149,20 @@ void DeviceDataManager::OnKeyboardDevicesUpdated(
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) {
observers_.AddObserver(observer);
}
......
......@@ -64,6 +64,10 @@ class EVENTS_DEVICES_EXPORT DeviceDataManager
const std::vector<TouchscreenDevice>& devices) override;
void OnKeyboardDevicesUpdated(
const std::vector<KeyboardDevice>& devices) override;
void OnMouseDevicesUpdated(
const std::vector<InputDevice>& devices) override;
void OnTouchpadDevicesUpdated(
const std::vector<InputDevice>& devices) override;
private:
static DeviceDataManager* instance_;
......
......@@ -11,6 +11,7 @@
namespace ui {
struct InputDevice;
struct KeyboardDevice;
struct TouchscreenDevice;
......@@ -20,14 +21,24 @@ class EVENTS_DEVICES_EXPORT DeviceHotplugEventObserver {
virtual ~DeviceHotplugEventObserver() {}
// 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(
const std::vector<TouchscreenDevice>& devices) = 0;
// 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(
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
......
......@@ -16,6 +16,8 @@ class EVENTS_DEVICES_EXPORT InputDeviceEventObserver {
virtual void OnKeyboardDeviceConfigurationChanged() = 0;
virtual void OnTouchscreenDeviceConfigurationChanged() = 0;
virtual void OnMouseDeviceConfigurationChanged() = 0;
virtual void OnTouchpadDeviceConfigurationChanged() = 0;
};
} // namespace ui
......
......@@ -39,6 +39,8 @@ class TestInputDeviceObserver : public InputDeviceEventObserver {
void OnKeyboardDeviceConfigurationChanged() override {
change_notified_ = true;
}
void OnMouseDeviceConfigurationChanged() override {}
void OnTouchpadDeviceConfigurationChanged() override {}
int change_notified() const { return change_notified_; }
void Reset() { change_notified_ = false; }
......
......@@ -254,12 +254,16 @@ void EventFactoryEvdev::DispatchMouseDevicesUpdated(
const std::vector<InputDevice>& devices) {
// There's no list of mice in DeviceDataManager.
input_controller_.set_has_mouse(devices.size() != 0);
DeviceHotplugEventObserver* observer = DeviceDataManager::GetInstance();
observer->OnMouseDevicesUpdated(devices);
}
void EventFactoryEvdev::DispatchTouchpadDevicesUpdated(
const std::vector<InputDevice>& devices) {
// There's no list of touchpads in DeviceDataManager.
input_controller_.set_has_touchpad(devices.size() != 0);
DeviceHotplugEventObserver* observer = DeviceDataManager::GetInstance();
observer->OnTouchpadDevicesUpdated(devices);
}
......
......@@ -340,6 +340,8 @@ void X11HotplugEventHandler::OnHotplugEvent() {
UiCallbacks callbacks;
callbacks.keyboard_callback = base::Bind(&OnKeyboardDevices);
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
// 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