| 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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 if (event->key_code() == ui::VKEY_RETURN || | 68 if (event->key_code() == ui::VKEY_RETURN || |
| 69 event->key_code() == ui::VKEY_BACK) { | 69 event->key_code() == ui::VKEY_BACK) { |
| 70 return true; | 70 return true; |
| 71 } | 71 } |
| 72 } | 72 } |
| 73 | 73 |
| 74 return false; | 74 return false; |
| 75 } | 75 } |
| 76 | 76 |
| 77 bool IsPhysicalKeyboardEnabled() { | 77 bool IsPhysicalKeyboardEnabled() { |
| 78 // The internal keyboard is enabled if maximize mode is not enabled. | 78 // The internal keyboard is enabled if tablet mode is not enabled. |
| 79 if (!WMHelper::GetInstance()->IsMaximizeModeWindowManagerEnabled()) | 79 if (!WMHelper::GetInstance()->IsTabletModeWindowManagerEnabled()) |
| 80 return true; | 80 return true; |
| 81 | 81 |
| 82 for (auto& keyboard : | 82 for (auto& keyboard : |
| 83 ui::InputDeviceManager::GetInstance()->GetKeyboardDevices()) { | 83 ui::InputDeviceManager::GetInstance()->GetKeyboardDevices()) { |
| 84 if (keyboard.type != ui::InputDeviceType::INPUT_DEVICE_INTERNAL) | 84 if (keyboard.type != ui::InputDeviceType::INPUT_DEVICE_INTERNAL) |
| 85 return true; | 85 return true; |
| 86 } | 86 } |
| 87 return false; | 87 return false; |
| 88 } | 88 } |
| 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->AddTabletModeObserver(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->RemoveTabletModeObserver(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::TabletModeObserver overrides: |
| 219 | 219 |
| 220 void Keyboard::OnMaximizeModeStarted() { | 220 void Keyboard::OnTabletModeStarted() { |
| 221 OnKeyboardDeviceConfigurationChanged(); | 221 OnKeyboardDeviceConfigurationChanged(); |
| 222 } | 222 } |
| 223 | 223 |
| 224 void Keyboard::OnMaximizeModeEnding() {} | 224 void Keyboard::OnTabletModeEnding() {} |
| 225 | 225 |
| 226 void Keyboard::OnMaximizeModeEnded() { | 226 void Keyboard::OnTabletModeEnded() { |
| 227 OnKeyboardDeviceConfigurationChanged(); | 227 OnKeyboardDeviceConfigurationChanged(); |
| 228 } | 228 } |
| 229 | 229 |
| 230 //////////////////////////////////////////////////////////////////////////////// | 230 //////////////////////////////////////////////////////////////////////////////// |
| 231 // Keyboard, private: | 231 // Keyboard, private: |
| 232 | 232 |
| 233 Surface* Keyboard::GetEffectiveFocus(aura::Window* window) const { | 233 Surface* Keyboard::GetEffectiveFocus(aura::Window* window) const { |
| 234 // Use window surface as effective focus. | 234 // Use window surface as effective focus. |
| 235 Surface* focus = Surface::AsSurface(window); | 235 Surface* focus = Surface::AsSurface(window); |
| 236 if (!focus) { | 236 if (!focus) { |
| 237 // Fallback to main surface. | 237 // Fallback to main surface. |
| 238 aura::Window* top_level_window = window->GetToplevelWindow(); | 238 aura::Window* top_level_window = window->GetToplevelWindow(); |
| 239 if (top_level_window) | 239 if (top_level_window) |
| 240 focus = ShellSurface::GetMainSurface(top_level_window); | 240 focus = ShellSurface::GetMainSurface(top_level_window); |
| 241 } | 241 } |
| 242 | 242 |
| 243 return focus && delegate_->CanAcceptKeyboardEventsForSurface(focus) ? focus | 243 return focus && delegate_->CanAcceptKeyboardEventsForSurface(focus) ? focus |
| 244 : nullptr; | 244 : nullptr; |
| 245 } | 245 } |
| 246 | 246 |
| 247 } // namespace exo | 247 } // namespace exo |
| OLD | NEW |