| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/exo/keyboard.h" | 5 #include "components/exo/keyboard.h" |
| 6 | 6 |
| 7 #include "components/exo/keyboard_delegate.h" | 7 #include "components/exo/keyboard_delegate.h" |
| 8 #include "components/exo/keyboard_device_configuration_delegate.h" | 8 #include "components/exo/keyboard_device_configuration_delegate.h" |
| 9 #include "components/exo/shell_surface.h" | 9 #include "components/exo/shell_surface.h" |
| 10 #include "components/exo/surface.h" | 10 #include "components/exo/surface.h" |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 | 89 |
| 90 } // namespace | 90 } // namespace |
| 91 | 91 |
| 92 //////////////////////////////////////////////////////////////////////////////// | 92 //////////////////////////////////////////////////////////////////////////////// |
| 93 // Keyboard, public: | 93 // Keyboard, public: |
| 94 | 94 |
| 95 Keyboard::Keyboard(KeyboardDelegate* delegate) : delegate_(delegate) { | 95 Keyboard::Keyboard(KeyboardDelegate* delegate) : delegate_(delegate) { |
| 96 auto* helper = WMHelper::GetInstance(); | 96 auto* helper = WMHelper::GetInstance(); |
| 97 helper->AddPostTargetHandler(this); | 97 helper->AddPostTargetHandler(this); |
| 98 helper->AddFocusObserver(this); | 98 helper->AddFocusObserver(this); |
| 99 helper->AddMaximizeModeObserver(this); | 99 helper->AddShellObserver(this); |
| 100 helper->AddInputDeviceEventObserver(this); | 100 helper->AddInputDeviceEventObserver(this); |
| 101 OnWindowFocused(helper->GetFocusedWindow(), nullptr); | 101 OnWindowFocused(helper->GetFocusedWindow(), nullptr); |
| 102 } | 102 } |
| 103 | 103 |
| 104 Keyboard::~Keyboard() { | 104 Keyboard::~Keyboard() { |
| 105 delegate_->OnKeyboardDestroying(this); | 105 delegate_->OnKeyboardDestroying(this); |
| 106 if (device_configuration_delegate_) | 106 if (device_configuration_delegate_) |
| 107 device_configuration_delegate_->OnKeyboardDestroying(this); | 107 device_configuration_delegate_->OnKeyboardDestroying(this); |
| 108 if (focus_) | 108 if (focus_) |
| 109 focus_->RemoveSurfaceObserver(this); | 109 focus_->RemoveSurfaceObserver(this); |
| 110 auto* helper = WMHelper::GetInstance(); | 110 auto* helper = WMHelper::GetInstance(); |
| 111 helper->RemoveFocusObserver(this); | 111 helper->RemoveFocusObserver(this); |
| 112 helper->RemovePostTargetHandler(this); | 112 helper->RemovePostTargetHandler(this); |
| 113 helper->RemoveMaximizeModeObserver(this); | 113 helper->RemoveShellObserver(this); |
| 114 helper->RemoveInputDeviceEventObserver(this); | 114 helper->RemoveInputDeviceEventObserver(this); |
| 115 } | 115 } |
| 116 | 116 |
| 117 bool Keyboard::HasDeviceConfigurationDelegate() const { | 117 bool Keyboard::HasDeviceConfigurationDelegate() const { |
| 118 return !!device_configuration_delegate_; | 118 return !!device_configuration_delegate_; |
| 119 } | 119 } |
| 120 | 120 |
| 121 void Keyboard::SetDeviceConfigurationDelegate( | 121 void Keyboard::SetDeviceConfigurationDelegate( |
| 122 KeyboardDeviceConfigurationDelegate* delegate) { | 122 KeyboardDeviceConfigurationDelegate* delegate) { |
| 123 device_configuration_delegate_ = delegate; | 123 device_configuration_delegate_ = delegate; |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 // ui::InputDeviceEventObserver overrides: | 208 // ui::InputDeviceEventObserver overrides: |
| 209 | 209 |
| 210 void Keyboard::OnKeyboardDeviceConfigurationChanged() { | 210 void Keyboard::OnKeyboardDeviceConfigurationChanged() { |
| 211 if (device_configuration_delegate_) { | 211 if (device_configuration_delegate_) { |
| 212 device_configuration_delegate_->OnKeyboardTypeChanged( | 212 device_configuration_delegate_->OnKeyboardTypeChanged( |
| 213 IsPhysicalKeyboardEnabled()); | 213 IsPhysicalKeyboardEnabled()); |
| 214 } | 214 } |
| 215 } | 215 } |
| 216 | 216 |
| 217 //////////////////////////////////////////////////////////////////////////////// | 217 //////////////////////////////////////////////////////////////////////////////// |
| 218 // WMHelper::MaximizeModeObserver overrides: | 218 // WMHelper::ShellObserver overrides: |
| 219 | 219 |
| 220 void Keyboard::OnMaximizeModeStarted() { | 220 void Keyboard::OnMaximizeModeStarted() { |
| 221 OnKeyboardDeviceConfigurationChanged(); | 221 OnKeyboardDeviceConfigurationChanged(); |
| 222 } | 222 } |
| 223 | 223 |
| 224 void Keyboard::OnMaximizeModeEnded() { | 224 void Keyboard::OnMaximizeModeEnded() { |
| 225 OnKeyboardDeviceConfigurationChanged(); | 225 OnKeyboardDeviceConfigurationChanged(); |
| 226 } | 226 } |
| 227 | 227 |
| 228 //////////////////////////////////////////////////////////////////////////////// | 228 //////////////////////////////////////////////////////////////////////////////// |
| 229 // Keyboard, private: | 229 // Keyboard, private: |
| 230 | 230 |
| 231 Surface* Keyboard::GetEffectiveFocus(aura::Window* window) const { | 231 Surface* Keyboard::GetEffectiveFocus(aura::Window* window) const { |
| 232 // Use window surface as effective focus. | 232 // Use window surface as effective focus. |
| 233 Surface* focus = Surface::AsSurface(window); | 233 Surface* focus = Surface::AsSurface(window); |
| 234 if (!focus) { | 234 if (!focus) { |
| 235 // Fallback to main surface. | 235 // Fallback to main surface. |
| 236 aura::Window* top_level_window = window->GetToplevelWindow(); | 236 aura::Window* top_level_window = window->GetToplevelWindow(); |
| 237 if (top_level_window) | 237 if (top_level_window) |
| 238 focus = ShellSurface::GetMainSurface(top_level_window); | 238 focus = ShellSurface::GetMainSurface(top_level_window); |
| 239 } | 239 } |
| 240 | 240 |
| 241 return focus && delegate_->CanAcceptKeyboardEventsForSurface(focus) ? focus | 241 return focus && delegate_->CanAcceptKeyboardEventsForSurface(focus) ? focus |
| 242 : nullptr; | 242 : nullptr; |
| 243 } | 243 } |
| 244 | 244 |
| 245 } // namespace exo | 245 } // namespace exo |
| OLD | NEW |