diff options
25 files changed, 360 insertions, 9 deletions
diff --git a/ash/BUILD.gn b/ash/BUILD.gn index b55fdc9..6a92848 100644 --- a/ash/BUILD.gn +++ b/ash/BUILD.gn @@ -74,6 +74,10 @@ component("ash") { ] } + if (use_ozone) { + deps += [ "//ui/ozone" ] + } + if (is_chromeos) { deps += [ "//device/bluetooth", diff --git a/ash/ash.gyp b/ash/ash.gyp index ba8167d..639fa84 100644 --- a/ash/ash.gyp +++ b/ash/ash.gyp @@ -528,6 +528,8 @@ 'wm/maximize_mode/maximize_mode_window_state.cc', 'wm/maximize_mode/maximize_mode_window_state.h', 'wm/maximize_mode/scoped_disable_internal_mouse_and_keyboard.h', + 'wm/maximize_mode/scoped_disable_internal_mouse_and_keyboard_ozone.cc', + 'wm/maximize_mode/scoped_disable_internal_mouse_and_keyboard_ozone.h', 'wm/maximize_mode/scoped_disable_internal_mouse_and_keyboard_x11.cc', 'wm/maximize_mode/scoped_disable_internal_mouse_and_keyboard_x11.h', 'wm/maximize_mode/workspace_backdrop_delegate.cc', @@ -930,6 +932,11 @@ '../build/linux/system.gyp:xfixes', ], }], + ['use_ozone==1', { + 'dependencies': [ + '../ui/ozone/ozone.gyp:ozone', + ], + }], ['chromeos==1', { 'dependencies': [ '../chromeos/chromeos.gyp:chromeos', diff --git a/ash/wm/maximize_mode/maximize_mode_controller.cc b/ash/wm/maximize_mode/maximize_mode_controller.cc index f391de7..1463a50 100644 --- a/ash/wm/maximize_mode/maximize_mode_controller.cc +++ b/ash/wm/maximize_mode/maximize_mode_controller.cc @@ -24,6 +24,10 @@ #include "ash/wm/maximize_mode/scoped_disable_internal_mouse_and_keyboard_x11.h" #endif +#if defined(USE_OZONE) +#include "ash/wm/maximize_mode/scoped_disable_internal_mouse_and_keyboard_ozone.h" +#endif + #if defined(OS_CHROMEOS) #include "chromeos/dbus/dbus_thread_manager.h" #endif // OS_CHROMEOS @@ -226,6 +230,8 @@ void MaximizeModeController::HandleHingeRotation(const gfx::Vector3dF& base, } #if defined(USE_X11) event_blocker_.reset(new ScopedDisableInternalMouseAndKeyboardX11); +#elif defined(USE_OZONE) + event_blocker_.reset(new ScopedDisableInternalMouseAndKeyboardOzone); #endif } } diff --git a/ash/wm/maximize_mode/scoped_disable_internal_mouse_and_keyboard_ozone.cc b/ash/wm/maximize_mode/scoped_disable_internal_mouse_and_keyboard_ozone.cc new file mode 100644 index 0000000..ddc8452 --- /dev/null +++ b/ash/wm/maximize_mode/scoped_disable_internal_mouse_and_keyboard_ozone.cc @@ -0,0 +1,44 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ash/wm/maximize_mode/scoped_disable_internal_mouse_and_keyboard_ozone.h" + +#include <set> + +#include "ash/shell.h" +#include "ui/aura/client/cursor_client.h" +#include "ui/events/keycodes/dom3/dom_code.h" +#include "ui/ozone/public/input_controller.h" +#include "ui/ozone/public/ozone_platform.h" + +namespace ash { + +ScopedDisableInternalMouseAndKeyboardOzone:: + ScopedDisableInternalMouseAndKeyboardOzone() { + ui::InputController* input_controller = + ui::OzonePlatform::GetInstance()->GetInputController(); + if (input_controller->HasTouchpad()) { + input_controller->DisableInternalTouchpad(); + aura::client::GetCursorClient(Shell::GetInstance()->GetPrimaryRootWindow()) + ->HideCursor(); + } + + // Allow the acccessible keys present on the side of some devices to continue + // working. + scoped_ptr<std::set<ui::DomCode>> excepted_keys(new std::set<ui::DomCode>); + excepted_keys->insert(ui::DomCode::VOLUME_DOWN); + excepted_keys->insert(ui::DomCode::VOLUME_UP); + excepted_keys->insert(ui::DomCode::POWER); + input_controller->DisableInternalKeyboardExceptKeys(excepted_keys.Pass()); +} + +ScopedDisableInternalMouseAndKeyboardOzone:: + ~ScopedDisableInternalMouseAndKeyboardOzone() { + ui::InputController* input_controller = + ui::OzonePlatform::GetInstance()->GetInputController(); + input_controller->EnableInternalTouchpad(); + input_controller->EnableInternalKeyboard(); +} + +} // namespace ash diff --git a/ash/wm/maximize_mode/scoped_disable_internal_mouse_and_keyboard_ozone.h b/ash/wm/maximize_mode/scoped_disable_internal_mouse_and_keyboard_ozone.h new file mode 100644 index 0000000..2376504 --- /dev/null +++ b/ash/wm/maximize_mode/scoped_disable_internal_mouse_and_keyboard_ozone.h @@ -0,0 +1,27 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef ASH_WM_MAXIMIZE_MODE_SCOPED_DISABLE_INTERNAL_MOUSE_AND_KEYBOARD_OZONE_H_ +#define ASH_WM_MAXIMIZE_MODE_SCOPED_DISABLE_INTERNAL_MOUSE_AND_KEYBOARD_OZONE_H_ + +#include "ash/wm/maximize_mode/scoped_disable_internal_mouse_and_keyboard.h" +#include "base/macros.h" + +namespace ash { + +// Disables the internal mouse and keyboard for the duration of the class' +// lifetime. +class ScopedDisableInternalMouseAndKeyboardOzone + : public ScopedDisableInternalMouseAndKeyboard { + public: + ScopedDisableInternalMouseAndKeyboardOzone(); + ~ScopedDisableInternalMouseAndKeyboardOzone() override; + + private: + DISALLOW_COPY_AND_ASSIGN(ScopedDisableInternalMouseAndKeyboardOzone); +}; + +} // namespace ash + +#endif // ASH_WM_MAXIMIZE_MODE_SCOPED_DISABLE_INTERNAL_MOUSE_AND_KEYBOARD_OZONE_H_ diff --git a/ui/events/ozone/evdev/event_converter_evdev.cc b/ui/events/ozone/evdev/event_converter_evdev.cc index 8d98777..fad7bc3 100644 --- a/ui/events/ozone/evdev/event_converter_evdev.cc +++ b/ui/events/ozone/evdev/event_converter_evdev.cc @@ -15,7 +15,7 @@ EventConverterEvdev::EventConverterEvdev(int fd, const base::FilePath& path, int id, InputDeviceType type) - : fd_(fd), path_(path), id_(id), type_(type) { + : fd_(fd), path_(path), id_(id), type_(type), ignore_events_(false) { } EventConverterEvdev::~EventConverterEvdev() { @@ -39,6 +39,10 @@ bool EventConverterEvdev::HasKeyboard() const { return false; } +bool EventConverterEvdev::HasTouchpad() const { + return false; +} + bool EventConverterEvdev::HasTouchscreen() const { return false; } @@ -48,4 +52,13 @@ gfx::Size EventConverterEvdev::GetTouchscreenSize() const { return gfx::Size(); } +void EventConverterEvdev::SetAllowedKeys( + scoped_ptr<std::set<DomCode>> allowed_keys) { + NOTREACHED(); +} + +void EventConverterEvdev::AllowAllKeys() { + NOTREACHED(); +} + } // namespace ui diff --git a/ui/events/ozone/evdev/event_converter_evdev.h b/ui/events/ozone/evdev/event_converter_evdev.h index e67d36d..be155b4 100644 --- a/ui/events/ozone/evdev/event_converter_evdev.h +++ b/ui/events/ozone/evdev/event_converter_evdev.h @@ -5,6 +5,8 @@ #ifndef UI_EVENTS_OZONE_EVDEV_EVENT_CONVERTER_EVDEV_H_ #define UI_EVENTS_OZONE_EVDEV_EVENT_CONVERTER_EVDEV_H_ +#include <set> + #include "base/callback.h" #include "base/files/file_path.h" #include "base/message_loop/message_loop.h" @@ -14,6 +16,7 @@ #include "ui/gfx/geometry/size.h" namespace ui { +enum class DomCode; class EVENTS_OZONE_EVDEV_EXPORT EventConverterEvdev : public base::MessagePumpLibevent::Watcher { @@ -30,22 +33,33 @@ class EVENTS_OZONE_EVDEV_EXPORT EventConverterEvdev InputDeviceType type() const { return type_; } + void set_ignore_events(bool ignore_events) { ignore_events_ = ignore_events; } + // Start reading events. void Start(); // Stop reading events. void Stop(); - // Returns true of the converter is used for a keyboard device. + // Returns true if the converter is used for a keyboard device. virtual bool HasKeyboard() const; - // Returns true of the converter is used for a touchscreen device. + // Returns true if the converter is used for a touchpad device. + virtual bool HasTouchpad() const; + + // Returns true if the converter is used for a touchscreen device. virtual bool HasTouchscreen() const; // Returns the size of the touchscreen device if the converter is used for a // touchscreen device. virtual gfx::Size GetTouchscreenSize() const; + // Sets which keyboard keys should be processed. + virtual void SetAllowedKeys(scoped_ptr<std::set<DomCode>> allowed_keys); + + // Allows all keys to be processed. + virtual void AllowAllKeys(); + protected: // base::MessagePumpLibevent::Watcher: void OnFileCanWriteWithoutBlocking(int fd) override; @@ -62,6 +76,9 @@ class EVENTS_OZONE_EVDEV_EXPORT EventConverterEvdev // Type (internal or external). InputDeviceType type_; + // Whether events from the device should be ignored. + bool ignore_events_; + // Controller for watching the input fd. base::MessagePumpLibevent::FileDescriptorWatcher controller_; diff --git a/ui/events/ozone/evdev/event_converter_evdev_impl.cc b/ui/events/ozone/evdev/event_converter_evdev_impl.cc index 011a6c2..866a4c2 100644 --- a/ui/events/ozone/evdev/event_converter_evdev_impl.cc +++ b/ui/events/ozone/evdev/event_converter_evdev_impl.cc @@ -10,7 +10,7 @@ #include "base/message_loop/message_loop.h" #include "ui/events/event.h" #include "ui/events/keycodes/dom4/keycode_converter.h" -#include "ui/events/keycodes/keyboard_codes.h" +#include "ui/events/ozone/evdev/keyboard_evdev.h" namespace ui { @@ -31,6 +31,7 @@ EventConverterEvdevImpl::EventConverterEvdevImpl( const EventDispatchCallback& callback) : EventConverterEvdev(fd, path, id, type), has_keyboard_(devinfo.HasKeyboard()), + has_touchpad_(devinfo.HasTouchpad()), x_offset_(0), y_offset_(0), cursor_(cursor), @@ -57,6 +58,11 @@ void EventConverterEvdevImpl::OnFileCanReadWithoutBlocking(int fd) { return; } + // TODO(spang): Re-implement this by releasing buttons & temporarily closing + // the device. + if (ignore_events_) + return; + DCHECK_EQ(read_size % sizeof(*inputs), 0u); ProcessEvents(inputs, read_size / sizeof(*inputs)); } @@ -65,6 +71,21 @@ bool EventConverterEvdevImpl::HasKeyboard() const { return has_keyboard_; } +bool EventConverterEvdevImpl::HasTouchpad() const { + return has_touchpad_; +} + +void EventConverterEvdevImpl::SetAllowedKeys( + scoped_ptr<std::set<DomCode>> allowed_keys) { + DCHECK(HasKeyboard()); + allowed_keys_ = allowed_keys.Pass(); +} + +void EventConverterEvdevImpl::AllowAllKeys() { + DCHECK(HasKeyboard()); + allowed_keys_.reset(); +} + void EventConverterEvdevImpl::ProcessEvents(const input_event* inputs, int count) { for (int i = 0; i < count; ++i) { @@ -95,7 +116,10 @@ void EventConverterEvdevImpl::ConvertKeyEvent(const input_event& input) { } // Keyboard processing. - keyboard_->OnKeyChange(input.code, input.value != kKeyReleaseValue); + DomCode key_code = KeycodeConverter::NativeKeycodeToDomCode( + KeyboardEvdev::EvdevCodeToNativeCode(input.code)); + if (!allowed_keys_ || allowed_keys_->count(key_code)) + keyboard_->OnKeyChange(input.code, input.value != kKeyReleaseValue); } void EventConverterEvdevImpl::ConvertMouseMoveEvent(const input_event& input) { diff --git a/ui/events/ozone/evdev/event_converter_evdev_impl.h b/ui/events/ozone/evdev/event_converter_evdev_impl.h index c7e66fe..c9ab9d4 100644 --- a/ui/events/ozone/evdev/event_converter_evdev_impl.h +++ b/ui/events/ozone/evdev/event_converter_evdev_impl.h @@ -5,6 +5,8 @@ #ifndef UI_EVENTS_OZONE_EVDEV_EVENT_CONVERTER_EVDEV_IMPL_H_ #define UI_EVENTS_OZONE_EVDEV_EVENT_CONVERTER_EVDEV_IMPL_H_ +#include <set> + #include "base/files/file_path.h" #include "base/message_loop/message_pump_libevent.h" #include "ui/events/devices/input_device.h" @@ -39,6 +41,9 @@ class EVENTS_OZONE_EVDEV_EXPORT EventConverterEvdevImpl // EventConverterEvdev: void OnFileCanReadWithoutBlocking(int fd) override; bool HasKeyboard() const override; + bool HasTouchpad() const override; + void SetAllowedKeys(scoped_ptr<std::set<DomCode>> allowed_keys) override; + void AllowAllKeys() override; void ProcessEvents(const struct input_event* inputs, int count); @@ -55,6 +60,7 @@ class EVENTS_OZONE_EVDEV_EXPORT EventConverterEvdevImpl // Input modalities for this device. bool has_keyboard_; + bool has_touchpad_; // Save x-axis events of relative devices to be flushed at EV_SYN time. int x_offset_; @@ -65,6 +71,10 @@ class EVENTS_OZONE_EVDEV_EXPORT EventConverterEvdevImpl // Controller for watching the input fd. base::MessagePumpLibevent::FileDescriptorWatcher controller_; + // The keys which should be processed. nullptr if all keys should be + // processed. + scoped_ptr<std::set<DomCode>> allowed_keys_; + // Shared cursor state. CursorDelegateEvdev* cursor_; diff --git a/ui/events/ozone/evdev/event_device_info.cc b/ui/events/ozone/evdev/event_device_info.cc index 2209613..34a1daa 100644 --- a/ui/events/ozone/evdev/event_device_info.cc +++ b/ui/events/ozone/evdev/event_device_info.cc @@ -237,6 +237,10 @@ bool EventDeviceInfo::HasKeyboard() const { return true; } +bool EventDeviceInfo::HasTouchpad() const { + return (HasAbsXY() || HasMTAbsXY()) && !IsMappedToScreen(); +} + const std::vector<int32_t>& EventDeviceInfo::GetMtSlotsForCode(int code) const { int index = code - ABS_MT_SLOT - 1; DCHECK_LE(0, index) << code << " is not a valid multi-touch code"; diff --git a/ui/events/ozone/evdev/event_device_info.h b/ui/events/ozone/evdev/event_device_info.h index a158472..398df5e 100644 --- a/ui/events/ozone/evdev/event_device_info.h +++ b/ui/events/ozone/evdev/event_device_info.h @@ -75,6 +75,9 @@ class EVENTS_OZONE_EVDEV_EXPORT EventDeviceInfo { // Determine whether there's a keyboard on this device. bool HasKeyboard() const; + // Determine whether there's a touchpad on this device. + bool HasTouchpad() const; + private: // Return the slot vector in |slot_values_| for |code|. const std::vector<int32_t>& GetMtSlotsForCode(int code) const; diff --git a/ui/events/ozone/evdev/event_factory_evdev.cc b/ui/events/ozone/evdev/event_factory_evdev.cc index b5a0cb7..ea8766d 100644 --- a/ui/events/ozone/evdev/event_factory_evdev.cc +++ b/ui/events/ozone/evdev/event_factory_evdev.cc @@ -62,9 +62,8 @@ struct OpenInputDeviceParams { #if defined(USE_EVDEV_GESTURES) bool UseGesturesLibraryForDevice(const EventDeviceInfo& devinfo) { - if ((devinfo.HasAbsXY() || devinfo.HasMTAbsXY()) && - !devinfo.IsMappedToScreen()) - return true; // touchpad + if (devinfo.HasTouchpad()) + return true; if (devinfo.HasRelXY()) return true; // mouse @@ -315,6 +314,49 @@ void EventFactoryEvdev::WarpCursorTo(gfx::AcceleratedWidget widget, } } +void EventFactoryEvdev::DisableInternalTouchpad() { + for (const auto& it : converters_) { + EventConverterEvdev* converter = it.second; + if (converter->type() == InputDeviceType::INPUT_DEVICE_INTERNAL && + converter->HasTouchpad()) { + DCHECK(!converter->HasKeyboard()); + converter->set_ignore_events(true); + } + } +} + +void EventFactoryEvdev::EnableInternalTouchpad() { + for (const auto& it : converters_) { + EventConverterEvdev* converter = it.second; + if (converter->type() == InputDeviceType::INPUT_DEVICE_INTERNAL && + converter->HasTouchpad()) { + DCHECK(!converter->HasKeyboard()); + converter->set_ignore_events(false); + } + } +} + +void EventFactoryEvdev::DisableInternalKeyboardExceptKeys( + scoped_ptr<std::set<DomCode>> excepted_keys) { + for (const auto& it : converters_) { + EventConverterEvdev* converter = it.second; + if (converter->type() == InputDeviceType::INPUT_DEVICE_INTERNAL && + converter->HasKeyboard()) { + converter->SetAllowedKeys(excepted_keys.Pass()); + } + } +} + +void EventFactoryEvdev::EnableInternalKeyboard() { + for (const auto& it : converters_) { + EventConverterEvdev* converter = it.second; + if (converter->type() == InputDeviceType::INPUT_DEVICE_INTERNAL && + converter->HasKeyboard()) { + converter->AllowAllKeys(); + } + } +} + void EventFactoryEvdev::NotifyDeviceChange( const EventConverterEvdev& converter) { if (converter.HasTouchscreen()) diff --git a/ui/events/ozone/evdev/event_factory_evdev.h b/ui/events/ozone/evdev/event_factory_evdev.h index 490e327..b893356 100644 --- a/ui/events/ozone/evdev/event_factory_evdev.h +++ b/ui/events/ozone/evdev/event_factory_evdev.h @@ -5,6 +5,7 @@ #ifndef UI_EVENTS_OZONE_EVDEV_EVENT_FACTORY_EVDEV_H_ #define UI_EVENTS_OZONE_EVDEV_EVENT_FACTORY_EVDEV_H_ +#include <set> #include <vector> #include "base/callback.h" @@ -33,6 +34,7 @@ namespace ui { class CursorDelegateEvdev; class DeviceManager; class SystemInputInjector; +enum class DomCode; #if !defined(USE_EVDEV) #error Missing dependency on ui/events/ozone:events_ozone_evdev @@ -59,6 +61,19 @@ class EVENTS_OZONE_EVDEV_EXPORT EventFactoryEvdev : public DeviceEventObserver, void WarpCursorTo(gfx::AcceleratedWidget widget, const gfx::PointF& location); + // Disables the internal touchpad. + void DisableInternalTouchpad(); + + // Enables the internal touchpad. + void EnableInternalTouchpad(); + + // Disables all keys on the internal keyboard except |excepted_keys|. + void DisableInternalKeyboardExceptKeys( + scoped_ptr<std::set<DomCode>> excepted_keys); + + // Enables all keys on the internal keyboard. + void EnableInternalKeyboard(); + scoped_ptr<SystemInputInjector> CreateSystemInputInjector(); InputController* input_controller() { return &input_controller_; } diff --git a/ui/events/ozone/evdev/input_controller_evdev.cc b/ui/events/ozone/evdev/input_controller_evdev.cc index 79559f0..65ca67e 100644 --- a/ui/events/ozone/evdev/input_controller_evdev.cc +++ b/ui/events/ozone/evdev/input_controller_evdev.cc @@ -104,6 +104,23 @@ void InputControllerEvdev::GetAutoRepeatRate(base::TimeDelta* delay, keyboard_->GetAutoRepeatRate(delay, interval); } +void InputControllerEvdev::DisableInternalTouchpad() { + event_factory_->DisableInternalTouchpad(); +} + +void InputControllerEvdev::EnableInternalTouchpad() { + event_factory_->EnableInternalTouchpad(); +} + +void InputControllerEvdev::DisableInternalKeyboardExceptKeys( + scoped_ptr<std::set<DomCode>> excepted_keys) { + event_factory_->DisableInternalKeyboardExceptKeys(excepted_keys.Pass()); +} + +void InputControllerEvdev::EnableInternalKeyboard() { + event_factory_->EnableInternalKeyboard(); +} + void InputControllerEvdev::SetIntPropertyForOneType(const EventDeviceType type, const std::string& name, int value) { diff --git a/ui/events/ozone/evdev/input_controller_evdev.h b/ui/events/ozone/evdev/input_controller_evdev.h index 13b124d..0e151ac 100644 --- a/ui/events/ozone/evdev/input_controller_evdev.h +++ b/ui/events/ozone/evdev/input_controller_evdev.h @@ -55,6 +55,11 @@ class EVENTS_OZONE_EVDEV_EXPORT InputControllerEvdev : public InputController { void SetMouseSensitivity(int value) override; void SetPrimaryButtonRight(bool right) override; void SetTapToClickPaused(bool state) override; + void DisableInternalTouchpad() override; + void EnableInternalTouchpad() override; + void DisableInternalKeyboardExceptKeys( + scoped_ptr<std::set<DomCode>> excepted_keys) override; + void EnableInternalKeyboard() override; private: // Set a property value for all devices of one type. diff --git a/ui/events/ozone/evdev/keyboard_evdev.cc b/ui/events/ozone/evdev/keyboard_evdev.cc index de7d84a..c569bb9 100644 --- a/ui/events/ozone/evdev/keyboard_evdev.cc +++ b/ui/events/ozone/evdev/keyboard_evdev.cc @@ -156,7 +156,7 @@ void KeyboardEvdev::OnRepeatIntervalTimeout() { void KeyboardEvdev::DispatchKey(unsigned int key, bool down, bool repeat) { DomCode dom_code = - KeycodeConverter::NativeKeycodeToDomCode(key + kXkbKeycodeOffset); + KeycodeConverter::NativeKeycodeToDomCode(EvdevCodeToNativeCode(key)); // DomCode constants are not included here because of conflicts with // evdev preprocessor macros. if (!static_cast<int>(dom_code)) @@ -189,4 +189,11 @@ int KeyboardEvdev::NativeCodeToEvdevCode(int native_code) { return native_code - kXkbKeycodeOffset; } +// static +int KeyboardEvdev::EvdevCodeToNativeCode(int evdev_code) { + if (evdev_code == KEY_RESERVED) + return KeycodeConverter::InvalidNativeKeycode(); + return evdev_code + kXkbKeycodeOffset; +} + } // namespace ui diff --git a/ui/events/ozone/evdev/keyboard_evdev.h b/ui/events/ozone/evdev/keyboard_evdev.h index a5fe191..abf2996 100644 --- a/ui/events/ozone/evdev/keyboard_evdev.h +++ b/ui/events/ozone/evdev/keyboard_evdev.h @@ -18,6 +18,7 @@ namespace ui { class EventModifiersEvdev; +enum class DomCode; // Keyboard for evdev. // @@ -35,6 +36,7 @@ class EVENTS_OZONE_EVDEV_EXPORT KeyboardEvdev { ~KeyboardEvdev(); static int NativeCodeToEvdevCode(int native_code); + static int EvdevCodeToNativeCode(int evdev_code); // Handlers for raw key presses & releases. void OnKeyChange(unsigned int code, bool down); diff --git a/ui/events/ozone/evdev/libgestures_glue/event_reader_libevdev_cros.cc b/ui/events/ozone/evdev/libgestures_glue/event_reader_libevdev_cros.cc index aeed791..1bed68b 100644 --- a/ui/events/ozone/evdev/libgestures_glue/event_reader_libevdev_cros.cc +++ b/ui/events/ozone/evdev/libgestures_glue/event_reader_libevdev_cros.cc @@ -33,6 +33,7 @@ EventReaderLibevdevCros::EventReaderLibevdevCros(int fd, scoped_ptr<Delegate> delegate) : EventConverterEvdev(fd, path, id, type), has_keyboard_(devinfo.HasKeyboard()), + has_touchpad_(devinfo.HasTouchpad()), delegate_(delegate.Pass()) { memset(&evdev_, 0, sizeof(evdev_)); evdev_.log = OnLogMessage; @@ -72,11 +73,29 @@ bool EventReaderLibevdevCros::HasKeyboard() const { return has_keyboard_; } +bool EventReaderLibevdevCros::HasTouchpad() const { + return has_touchpad_; +} + +void EventReaderLibevdevCros::SetAllowedKeys( + scoped_ptr<std::set<DomCode>> allowed_keys) { + DCHECK(HasKeyboard()); + delegate_->SetAllowedKeys(allowed_keys.Pass()); +} + +void EventReaderLibevdevCros::AllowAllKeys() { + DCHECK(HasKeyboard()); + delegate_->AllowAllKeys(); +} + // static void EventReaderLibevdevCros::OnSynReport(void* data, EventStateRec* evstate, struct timeval* tv) { EventReaderLibevdevCros* reader = static_cast<EventReaderLibevdevCros*>(data); + if (reader->ignore_events_) + return; + reader->delegate_->OnLibEvdevCrosEvent(&reader->evdev_, evstate, *tv); } diff --git a/ui/events/ozone/evdev/libgestures_glue/event_reader_libevdev_cros.h b/ui/events/ozone/evdev/libgestures_glue/event_reader_libevdev_cros.h index f203cdf..8f775d4 100644 --- a/ui/events/ozone/evdev/libgestures_glue/event_reader_libevdev_cros.h +++ b/ui/events/ozone/evdev/libgestures_glue/event_reader_libevdev_cros.h @@ -34,6 +34,12 @@ class EventReaderLibevdevCros : public EventConverterEvdev { virtual void OnLibEvdevCrosEvent(Evdev* evdev, EventStateRec* state, const timeval& time) = 0; + + // Sets which keyboard keys should be processed. + virtual void SetAllowedKeys(scoped_ptr<std::set<DomCode>> allowed_keys) = 0; + + // Allows all keys to be processed. + virtual void AllowAllKeys() = 0; }; EventReaderLibevdevCros(int fd, @@ -47,6 +53,9 @@ class EventReaderLibevdevCros : public EventConverterEvdev { // EventConverterEvdev: void OnFileCanReadWithoutBlocking(int fd) override; bool HasKeyboard() const override; + bool HasTouchpad() const override; + void SetAllowedKeys(scoped_ptr<std::set<DomCode>> allowed_keys) override; + void AllowAllKeys() override; private: static void OnSynReport(void* data, @@ -56,6 +65,7 @@ class EventReaderLibevdevCros : public EventConverterEvdev { // Input modalities for this device. bool has_keyboard_; + bool has_touchpad_; // Libevdev state. Evdev evdev_; diff --git a/ui/events/ozone/evdev/libgestures_glue/gesture_interpreter_libevdev_cros.cc b/ui/events/ozone/evdev/libgestures_glue/gesture_interpreter_libevdev_cros.cc index b7ca113..dc6fb83 100644 --- a/ui/events/ozone/evdev/libgestures_glue/gesture_interpreter_libevdev_cros.cc +++ b/ui/events/ozone/evdev/libgestures_glue/gesture_interpreter_libevdev_cros.cc @@ -11,6 +11,7 @@ #include "base/strings/stringprintf.h" #include "base/timer/timer.h" #include "ui/events/event.h" +#include "ui/events/keycodes/dom4/keycode_converter.h" #include "ui/events/ozone/evdev/cursor_delegate_evdev.h" #include "ui/events/ozone/evdev/event_device_info.h" #include "ui/events/ozone/evdev/event_device_util.h" @@ -235,6 +236,25 @@ void GestureInterpreterLibevdevCros::OnLibEvdevCrosEvent(Evdev* evdev, GestureInterpreterPushHardwareState(interpreter_, &hwstate); } +void GestureInterpreterLibevdevCros::SetAllowedKeys( + scoped_ptr<std::set<DomCode>> allowed_keys) { + if (!allowed_keys) { + allowed_keys_.reset(); + return; + } + + allowed_keys_.reset(new std::set<int>()); + for (const auto& it : *allowed_keys) { + int evdev_code = KeyboardEvdev::NativeCodeToEvdevCode( + KeycodeConverter::DomCodeToNativeKeycode(it)); + allowed_keys_->insert(evdev_code); + } +} + +void GestureInterpreterLibevdevCros::AllowAllKeys() { + allowed_keys_.reset(); +} + void GestureInterpreterLibevdevCros::OnGestureReady(const Gesture* gesture) { switch (gesture->type) { case kGestureTypeMove: @@ -475,6 +495,9 @@ void GestureInterpreterLibevdevCros::DispatchChangedKeys(Evdev* evdev, if (key >= BTN_DIGI && key < BTN_WHEEL) continue; + if (allowed_keys_ && !allowed_keys_->count(key)) + continue; + // Dispatch key press or release to keyboard. keyboard_->OnKeyChange(key, value); } diff --git a/ui/events/ozone/evdev/libgestures_glue/gesture_interpreter_libevdev_cros.h b/ui/events/ozone/evdev/libgestures_glue/gesture_interpreter_libevdev_cros.h index f532d60..2e29582 100644 --- a/ui/events/ozone/evdev/libgestures_glue/gesture_interpreter_libevdev_cros.h +++ b/ui/events/ozone/evdev/libgestures_glue/gesture_interpreter_libevdev_cros.h @@ -56,6 +56,9 @@ class EVENTS_OZONE_EVDEV_EXPORT GestureInterpreterLibevdevCros void OnLibEvdevCrosEvent(Evdev* evdev, EventStateRec* evstate, const timeval& time) override; + void SetAllowedKeys( + scoped_ptr<std::set<DomCode>> allowed_keys) override; + void AllowAllKeys() override; // Handler for gesture events generated from libgestures. void OnGestureReady(const Gesture* gesture); @@ -89,6 +92,10 @@ class EVENTS_OZONE_EVDEV_EXPORT GestureInterpreterLibevdevCros // and multi-touch mice. bool is_mouse_; + // The evdev codes of the keys which should be processed. nullptr if all keys + // should be processed. + scoped_ptr<std::set<int>> allowed_keys_; + // Shared modifier state. EventModifiersEvdev* modifiers_; diff --git a/ui/events/ozone/evdev/tablet_event_converter_evdev.cc b/ui/events/ozone/evdev/tablet_event_converter_evdev.cc index b6897e8..58dafb9 100644 --- a/ui/events/ozone/evdev/tablet_event_converter_evdev.cc +++ b/ui/events/ozone/evdev/tablet_event_converter_evdev.cc @@ -50,6 +50,9 @@ void TabletEventConverterEvdev::OnFileCanReadWithoutBlocking(int fd) { return; } + if (ignore_events_) + return; + DCHECK_EQ(read_size % sizeof(*inputs), 0u); ProcessEvents(inputs, read_size / sizeof(*inputs)); } diff --git a/ui/events/ozone/evdev/touch_event_converter_evdev.cc b/ui/events/ozone/evdev/touch_event_converter_evdev.cc index c30bba3..caf1baa 100644 --- a/ui/events/ozone/evdev/touch_event_converter_evdev.cc +++ b/ui/events/ozone/evdev/touch_event_converter_evdev.cc @@ -155,6 +155,9 @@ void TouchEventConverterEvdev::OnFileCanReadWithoutBlocking(int fd) { return; } + if (ignore_events_) + return; + for (unsigned i = 0; i < read_size / sizeof(*inputs); i++) { ProcessInputEvent(inputs[i]); } diff --git a/ui/ozone/public/input_controller.cc b/ui/ozone/public/input_controller.cc index f0eb240..1dce350 100644 --- a/ui/ozone/public/input_controller.cc +++ b/ui/ozone/public/input_controller.cc @@ -36,6 +36,11 @@ class StubInputController : public InputController { void SetMouseSensitivity(int value) override; void SetPrimaryButtonRight(bool right) override; void SetTapToClickPaused(bool state) override; + void DisableInternalTouchpad() override; + void EnableInternalTouchpad() override; + void DisableInternalKeyboardExceptKeys( + scoped_ptr<std::set<DomCode>> excepted_keys) override; + void EnableInternalKeyboard() override; private: DISALLOW_COPY_AND_ASSIGN(StubInputController); @@ -119,6 +124,23 @@ void StubInputController::SetTapToClickPaused(bool state) { NOTIMPLEMENTED(); } +void StubInputController::DisableInternalTouchpad() { + NOTIMPLEMENTED(); +} + +void StubInputController::EnableInternalTouchpad() { + NOTIMPLEMENTED(); +} + +void StubInputController::DisableInternalKeyboardExceptKeys( + scoped_ptr<std::set<DomCode>> excepted_keys) { + NOTIMPLEMENTED(); +} + +void StubInputController::EnableInternalKeyboard() { + NOTIMPLEMENTED(); +} + } // namespace scoped_ptr<InputController> CreateStubInputController() { diff --git a/ui/ozone/public/input_controller.h b/ui/ozone/public/input_controller.h index 3ba1c7c..4cb04fd 100644 --- a/ui/ozone/public/input_controller.h +++ b/ui/ozone/public/input_controller.h @@ -5,6 +5,8 @@ #ifndef UI_OZONE_PUBLIC_INPUT_CONTROLLER_H_ #define UI_OZONE_PUBLIC_INPUT_CONTROLLER_H_ +#include <set> + #include "base/macros.h" #include "base/memory/scoped_ptr.h" #include "ui/ozone/ozone_export.h" @@ -15,6 +17,8 @@ class TimeDelta; namespace ui { +enum class DomCode; + // Platform-specific interface for controlling input devices. // // The object provides methods for the preference page to configure input @@ -55,6 +59,19 @@ class OZONE_EXPORT InputController { // experience in some use cases (e.g., typing, watching video). virtual void SetTapToClickPaused(bool state) = 0; + // Disables the internal touchpad. + virtual void DisableInternalTouchpad() = 0; + + // Enables the internal touchpad. + virtual void EnableInternalTouchpad() = 0; + + // Disables all keys on the internal keyboard except |excepted_keys|. + virtual void DisableInternalKeyboardExceptKeys( + scoped_ptr<std::set<DomCode>> excepted_keys) = 0; + + // Enables all keys on the internal keyboard. + virtual void EnableInternalKeyboard() = 0; + private: DISALLOW_COPY_AND_ASSIGN(InputController); }; |