Chromium Code Reviews| Index: components/exo/keyboard.cc |
| diff --git a/components/exo/keyboard.cc b/components/exo/keyboard.cc |
| index 2ac24547ef0c9b5cd99e797857770784926263b4..3a20053d8ada38d8db1a60d16838874ec8abbaa5 100644 |
| --- a/components/exo/keyboard.cc |
| +++ b/components/exo/keyboard.cc |
| @@ -5,16 +5,20 @@ |
| #include "components/exo/keyboard.h" |
| #include "components/exo/keyboard_delegate.h" |
| +#include "components/exo/keyboard_device_configuration_delegate.h" |
| #include "components/exo/shell_surface.h" |
| #include "components/exo/surface.h" |
| #include "ui/aura/client/focus_client.h" |
| #include "ui/aura/window.h" |
| #include "ui/base/ime/input_method.h" |
| #include "ui/events/base_event_utils.h" |
| +#include "ui/events/devices/input_device.h" |
| +#include "ui/events/devices/input_device_manager.h" |
| #include "ui/events/event.h" |
| #include "ui/views/widget/widget.h" |
| namespace exo { |
| +namespace { |
| bool ConsumedByIme(Surface* focus, const ui::KeyEvent* event) { |
| // Check if IME consumed the event, to avoid it to be doubly processed. |
| @@ -70,6 +74,24 @@ bool ConsumedByIme(Surface* focus, const ui::KeyEvent* event) { |
| return false; |
| } |
| +bool HasEnabledPhysicalKeyboard() { |
|
reveman
2016/12/09 00:18:37
IsPhysicalKeyboardEnabled() ?
yhanada
2016/12/09 14:54:04
Done.
|
| + const auto* helper = WMHelper::GetInstance(); |
|
reveman
2016/12/09 00:18:37
do we need this temporary variable and the dcheck
yhanada
2016/12/09 14:54:04
Done.
|
| + |
| + DCHECK(helper != nullptr); |
|
reveman
2016/12/09 00:18:36
DCHECK(helper) if we need to keep this
yhanada
2016/12/09 14:54:04
Acknowledged.
|
| + // The internal keyboard is enabled if maximize mode is not enabled. |
| + bool has_keyboard = !helper->IsMaximizeModeWindowManagerEnabled(); |
|
reveman
2016/12/09 00:18:37
why not return early here?
if (!WMHelper::GetInst
yhanada
2016/12/09 14:54:04
Done.
|
| + |
| + const auto* manager = ui::InputDeviceManager::GetInstance(); |
|
reveman
2016/12/09 00:18:37
do we need this temporary variable and the dcheck
yhanada
2016/12/09 14:54:04
Done.
|
| + DCHECK(manager != nullptr); |
| + for (const ui::InputDevice& keyboard : manager->GetKeyboardDevices()) { |
|
reveman
2016/12/09 00:18:37
maybe use "auto& keyboard" here
yhanada
2016/12/09 14:54:04
Done.
|
| + has_keyboard |= |
| + (keyboard.type != ui::InputDeviceType::INPUT_DEVICE_INTERNAL); |
|
reveman
2016/12/09 00:18:37
return early here instead:
if (keyboard.type != u
yhanada
2016/12/09 14:54:04
Done.
|
| + } |
| + return has_keyboard; |
| +} |
| + |
| +} // namespace |
| + |
| //////////////////////////////////////////////////////////////////////////////// |
| // Keyboard, public: |
| @@ -77,6 +99,8 @@ Keyboard::Keyboard(KeyboardDelegate* delegate) : delegate_(delegate) { |
| auto* helper = WMHelper::GetInstance(); |
| helper->AddPostTargetHandler(this); |
| helper->AddFocusObserver(this); |
| + helper->AddMaximizeModeObserver(this); |
| + helper->AddInputDeviceEventObserver(this); |
| OnWindowFocused(helper->GetFocusedWindow(), nullptr); |
| } |
| @@ -87,6 +111,16 @@ Keyboard::~Keyboard() { |
| auto* helper = WMHelper::GetInstance(); |
| helper->RemoveFocusObserver(this); |
| helper->RemovePostTargetHandler(this); |
| + helper->RemoveMaximizeModeObserver(this); |
| + helper->RemoveInputDeviceEventObserver(this); |
| +} |
| + |
| +void Keyboard::SetKeyboardDeviceConfigurationDelegate( |
| + KeyboardDeviceConfigurationDelegate* delegate) { |
| + device_configuration_delegate_ = delegate; |
| + if (device_configuration_delegate_) |
|
reveman
2016/12/09 00:18:37
Call OnKeyboardDeviceConfigurationChanged() here i
yhanada
2016/12/09 14:54:04
Done.
|
| + device_configuration_delegate_->OnKeyboardTypeChanged( |
| + HasEnabledPhysicalKeyboard()); |
| } |
| //////////////////////////////////////////////////////////////////////////////// |
| @@ -170,6 +204,30 @@ void Keyboard::OnSurfaceDestroying(Surface* surface) { |
| } |
| //////////////////////////////////////////////////////////////////////////////// |
| +// ui::InputDeviceEventObserver overrides: |
| + |
| +void Keyboard::OnKeyboardDeviceConfigurationChanged() { |
| + if (device_configuration_delegate_) |
|
reveman
2016/12/09 00:18:36
need "{}" for multi line if-statement
yhanada
2016/12/09 14:54:04
Done.
|
| + device_configuration_delegate_->OnKeyboardTypeChanged( |
| + HasEnabledPhysicalKeyboard()); |
| +} |
| + |
| +//////////////////////////////////////////////////////////////////////////////// |
| +// WMHelper::MaximizeModeObserver overrides: |
| + |
| +void Keyboard::OnMaximizeModeStarted() { |
| + if (device_configuration_delegate_) |
|
reveman
2016/12/09 00:18:37
need "{}" for multi line if-statement
yhanada
2016/12/09 14:54:04
Done.
|
| + device_configuration_delegate_->OnKeyboardTypeChanged( |
| + HasEnabledPhysicalKeyboard()); |
| +} |
| + |
| +void Keyboard::OnMaximizeModeEnded() { |
| + if (device_configuration_delegate_) |
|
reveman
2016/12/09 00:18:37
need "{}" for multi line if-statement
yhanada
2016/12/09 14:54:04
Done.
|
| + device_configuration_delegate_->OnKeyboardTypeChanged( |
| + HasEnabledPhysicalKeyboard()); |
| +} |
| + |
| +//////////////////////////////////////////////////////////////////////////////// |
| // Keyboard, private: |
| Surface* Keyboard::GetEffectiveFocus(aura::Window* window) const { |