Chromium Code Reviews| Index: components/exo/keyboard.cc |
| diff --git a/components/exo/keyboard.cc b/components/exo/keyboard.cc |
| index 2ac24547ef0c9b5cd99e797857770784926263b4..e95fe615d2fd38f02f8adaa52c56388b340b22b9 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,21 @@ bool ConsumedByIme(Surface* focus, const ui::KeyEvent* event) { |
| return false; |
| } |
| +bool IsPhysicalKeyboardEnabled() { |
| + // The internal keyboard is enabled if maximize mode is not enabled. |
| + if (WMHelper::GetInstance()->IsMaximizeModeWindowManagerEnabled()) |
| + return true; |
| + |
| + for (auto& keyboard : |
| + ui::InputDeviceManager::GetInstance()->GetKeyboardDevices()) { |
| + if (keyboard.type != ui::InputDeviceType::INPUT_DEVICE_INTERNAL) |
| + return true; |
| + } |
| + return false; |
| +} |
| + |
| +} // namespace |
| + |
| //////////////////////////////////////////////////////////////////////////////// |
| // Keyboard, public: |
| @@ -77,16 +96,30 @@ 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); |
| } |
| Keyboard::~Keyboard() { |
| delegate_->OnKeyboardDestroying(this); |
| + if (device_configuration_delegate_) |
| + device_configuration_delegate_->OnKeyboardDestroying(this); |
| if (focus_) |
| focus_->RemoveSurfaceObserver(this); |
| auto* helper = WMHelper::GetInstance(); |
| helper->RemoveFocusObserver(this); |
| helper->RemovePostTargetHandler(this); |
| + helper->RemoveMaximizeModeObserver(this); |
| + helper->RemoveInputDeviceEventObserver(this); |
| +} |
| + |
| +void Keyboard::SetDeviceConfigurationDelegate( |
| + KeyboardDeviceConfigurationDelegate* delegate) { |
| + if (device_configuration_delegate_) |
| + device_configuration_delegate_->OnKeyboardDestroying(this); |
|
reveman
2016/12/09 16:15:02
This is surprising and inconsistent with SetStylus
yhanada
2016/12/10 00:09:11
Done.
|
| + device_configuration_delegate_ = delegate; |
| + OnKeyboardDeviceConfigurationChanged(); |
| } |
| //////////////////////////////////////////////////////////////////////////////// |
| @@ -170,6 +203,33 @@ void Keyboard::OnSurfaceDestroying(Surface* surface) { |
| } |
| //////////////////////////////////////////////////////////////////////////////// |
| +// ui::InputDeviceEventObserver overrides: |
| + |
| +void Keyboard::OnKeyboardDeviceConfigurationChanged() { |
| + if (device_configuration_delegate_) { |
| + device_configuration_delegate_->OnKeyboardTypeChanged( |
| + IsPhysicalKeyboardEnabled()); |
| + } |
| +} |
| + |
| +//////////////////////////////////////////////////////////////////////////////// |
| +// WMHelper::MaximizeModeObserver overrides: |
| + |
| +void Keyboard::OnMaximizeModeStarted() { |
| + if (device_configuration_delegate_) { |
|
reveman
2016/12/09 16:15:02
maybe we can just call OnKeyboardDeviceConfigurati
yhanada
2016/12/10 00:09:11
Done.
|
| + device_configuration_delegate_->OnKeyboardTypeChanged( |
| + IsPhysicalKeyboardEnabled()); |
| + } |
| +} |
| + |
| +void Keyboard::OnMaximizeModeEnded() { |
| + if (device_configuration_delegate_) { |
|
reveman
2016/12/09 16:15:02
call OnKeyboardDeviceConfigurationChanged() here?
yhanada
2016/12/10 00:09:11
Done.
|
| + device_configuration_delegate_->OnKeyboardTypeChanged( |
| + IsPhysicalKeyboardEnabled()); |
| + } |
| +} |
| + |
| +//////////////////////////////////////////////////////////////////////////////// |
| // Keyboard, private: |
| Surface* Keyboard::GetEffectiveFocus(aura::Window* window) const { |