 Chromium Code Reviews
 Chromium Code Reviews Issue 2506263002:
  exo: Implement support for zcr_keyboard_configuration_v1 protocol.  (Closed)
    
  
    Issue 2506263002:
  exo: Implement support for zcr_keyboard_configuration_v1 protocol.  (Closed) 
  | 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/shell_surface.h" | 9 #include "components/exo/shell_surface.h" | 
| 9 #include "components/exo/surface.h" | 10 #include "components/exo/surface.h" | 
| 10 #include "ui/aura/client/focus_client.h" | 11 #include "ui/aura/client/focus_client.h" | 
| 11 #include "ui/aura/window.h" | 12 #include "ui/aura/window.h" | 
| 12 #include "ui/base/ime/input_method.h" | 13 #include "ui/base/ime/input_method.h" | 
| 13 #include "ui/events/base_event_utils.h" | 14 #include "ui/events/base_event_utils.h" | 
| 15 #include "ui/events/devices/input_device.h" | |
| 16 #include "ui/events/devices/input_device_manager.h" | |
| 14 #include "ui/events/event.h" | 17 #include "ui/events/event.h" | 
| 15 #include "ui/views/widget/widget.h" | 18 #include "ui/views/widget/widget.h" | 
| 16 | 19 | 
| 17 namespace exo { | 20 namespace exo { | 
| 21 namespace { | |
| 18 | 22 | 
| 19 bool ConsumedByIme(Surface* focus, const ui::KeyEvent* event) { | 23 bool ConsumedByIme(Surface* focus, const ui::KeyEvent* event) { | 
| 20 // Check if IME consumed the event, to avoid it to be doubly processed. | 24 // Check if IME consumed the event, to avoid it to be doubly processed. | 
| 21 // First let us see whether IME is active and is in text input mode. | 25 // First let us see whether IME is active and is in text input mode. | 
| 22 views::Widget* widget = | 26 views::Widget* widget = | 
| 23 focus ? views::Widget::GetTopLevelWidgetForNativeView(focus->window()) | 27 focus ? views::Widget::GetTopLevelWidgetForNativeView(focus->window()) | 
| 24 : nullptr; | 28 : nullptr; | 
| 25 ui::InputMethod* ime = widget ? widget->GetInputMethod() : nullptr; | 29 ui::InputMethod* ime = widget ? widget->GetInputMethod() : nullptr; | 
| 26 if (!ime || ime->GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE) | 30 if (!ime || ime->GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE) | 
| 27 return false; | 31 return false; | 
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 63 if ((event->flags() & kModifierMask) == 0) { | 67 if ((event->flags() & kModifierMask) == 0) { | 
| 64 if (event->key_code() == ui::VKEY_RETURN || | 68 if (event->key_code() == ui::VKEY_RETURN || | 
| 65 event->key_code() == ui::VKEY_BACK) { | 69 event->key_code() == ui::VKEY_BACK) { | 
| 66 return true; | 70 return true; | 
| 67 } | 71 } | 
| 68 } | 72 } | 
| 69 | 73 | 
| 70 return false; | 74 return false; | 
| 71 } | 75 } | 
| 72 | 76 | 
| 77 bool HasEnabledPhysicalKeyboard() { | |
| 
reveman
2016/12/09 00:18:37
IsPhysicalKeyboardEnabled() ?
 
yhanada
2016/12/09 14:54:04
Done.
 | |
| 78 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.
 | |
| 79 | |
| 80 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.
 | |
| 81 // The internal keyboard is enabled if maximize mode is not enabled. | |
| 82 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.
 | |
| 83 | |
| 84 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.
 | |
| 85 DCHECK(manager != nullptr); | |
| 86 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.
 | |
| 87 has_keyboard |= | |
| 88 (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.
 | |
| 89 } | |
| 90 return has_keyboard; | |
| 91 } | |
| 92 | |
| 93 } // namespace | |
| 94 | |
| 73 //////////////////////////////////////////////////////////////////////////////// | 95 //////////////////////////////////////////////////////////////////////////////// | 
| 74 // Keyboard, public: | 96 // Keyboard, public: | 
| 75 | 97 | 
| 76 Keyboard::Keyboard(KeyboardDelegate* delegate) : delegate_(delegate) { | 98 Keyboard::Keyboard(KeyboardDelegate* delegate) : delegate_(delegate) { | 
| 77 auto* helper = WMHelper::GetInstance(); | 99 auto* helper = WMHelper::GetInstance(); | 
| 78 helper->AddPostTargetHandler(this); | 100 helper->AddPostTargetHandler(this); | 
| 79 helper->AddFocusObserver(this); | 101 helper->AddFocusObserver(this); | 
| 102 helper->AddMaximizeModeObserver(this); | |
| 103 helper->AddInputDeviceEventObserver(this); | |
| 80 OnWindowFocused(helper->GetFocusedWindow(), nullptr); | 104 OnWindowFocused(helper->GetFocusedWindow(), nullptr); | 
| 81 } | 105 } | 
| 82 | 106 | 
| 83 Keyboard::~Keyboard() { | 107 Keyboard::~Keyboard() { | 
| 84 delegate_->OnKeyboardDestroying(this); | 108 delegate_->OnKeyboardDestroying(this); | 
| 85 if (focus_) | 109 if (focus_) | 
| 86 focus_->RemoveSurfaceObserver(this); | 110 focus_->RemoveSurfaceObserver(this); | 
| 87 auto* helper = WMHelper::GetInstance(); | 111 auto* helper = WMHelper::GetInstance(); | 
| 88 helper->RemoveFocusObserver(this); | 112 helper->RemoveFocusObserver(this); | 
| 89 helper->RemovePostTargetHandler(this); | 113 helper->RemovePostTargetHandler(this); | 
| 114 helper->RemoveMaximizeModeObserver(this); | |
| 115 helper->RemoveInputDeviceEventObserver(this); | |
| 116 } | |
| 117 | |
| 118 void Keyboard::SetKeyboardDeviceConfigurationDelegate( | |
| 119 KeyboardDeviceConfigurationDelegate* delegate) { | |
| 120 device_configuration_delegate_ = delegate; | |
| 121 if (device_configuration_delegate_) | |
| 
reveman
2016/12/09 00:18:37
Call OnKeyboardDeviceConfigurationChanged() here i
 
yhanada
2016/12/09 14:54:04
Done.
 | |
| 122 device_configuration_delegate_->OnKeyboardTypeChanged( | |
| 123 HasEnabledPhysicalKeyboard()); | |
| 90 } | 124 } | 
| 91 | 125 | 
| 92 //////////////////////////////////////////////////////////////////////////////// | 126 //////////////////////////////////////////////////////////////////////////////// | 
| 93 // ui::EventHandler overrides: | 127 // ui::EventHandler overrides: | 
| 94 | 128 | 
| 95 void Keyboard::OnKeyEvent(ui::KeyEvent* event) { | 129 void Keyboard::OnKeyEvent(ui::KeyEvent* event) { | 
| 96 // These modifiers reflect what Wayland is aware of. For example, | 130 // These modifiers reflect what Wayland is aware of. For example, | 
| 97 // EF_SCROLL_LOCK_ON is missing because Wayland doesn't support scroll lock. | 131 // EF_SCROLL_LOCK_ON is missing because Wayland doesn't support scroll lock. | 
| 98 const int kModifierMask = ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN | | 132 const int kModifierMask = ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN | | 
| 99 ui::EF_ALT_DOWN | ui::EF_COMMAND_DOWN | | 133 ui::EF_ALT_DOWN | ui::EF_COMMAND_DOWN | | 
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 163 //////////////////////////////////////////////////////////////////////////////// | 197 //////////////////////////////////////////////////////////////////////////////// | 
| 164 // SurfaceObserver overrides: | 198 // SurfaceObserver overrides: | 
| 165 | 199 | 
| 166 void Keyboard::OnSurfaceDestroying(Surface* surface) { | 200 void Keyboard::OnSurfaceDestroying(Surface* surface) { | 
| 167 DCHECK(surface == focus_); | 201 DCHECK(surface == focus_); | 
| 168 focus_ = nullptr; | 202 focus_ = nullptr; | 
| 169 surface->RemoveSurfaceObserver(this); | 203 surface->RemoveSurfaceObserver(this); | 
| 170 } | 204 } | 
| 171 | 205 | 
| 172 //////////////////////////////////////////////////////////////////////////////// | 206 //////////////////////////////////////////////////////////////////////////////// | 
| 207 // ui::InputDeviceEventObserver overrides: | |
| 208 | |
| 209 void Keyboard::OnKeyboardDeviceConfigurationChanged() { | |
| 210 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.
 | |
| 211 device_configuration_delegate_->OnKeyboardTypeChanged( | |
| 212 HasEnabledPhysicalKeyboard()); | |
| 213 } | |
| 214 | |
| 215 //////////////////////////////////////////////////////////////////////////////// | |
| 216 // WMHelper::MaximizeModeObserver overrides: | |
| 217 | |
| 218 void Keyboard::OnMaximizeModeStarted() { | |
| 219 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.
 | |
| 220 device_configuration_delegate_->OnKeyboardTypeChanged( | |
| 221 HasEnabledPhysicalKeyboard()); | |
| 222 } | |
| 223 | |
| 224 void Keyboard::OnMaximizeModeEnded() { | |
| 225 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.
 | |
| 226 device_configuration_delegate_->OnKeyboardTypeChanged( | |
| 227 HasEnabledPhysicalKeyboard()); | |
| 228 } | |
| 229 | |
| 230 //////////////////////////////////////////////////////////////////////////////// | |
| 173 // Keyboard, private: | 231 // Keyboard, private: | 
| 174 | 232 | 
| 175 Surface* Keyboard::GetEffectiveFocus(aura::Window* window) const { | 233 Surface* Keyboard::GetEffectiveFocus(aura::Window* window) const { | 
| 176 // Use window surface as effective focus. | 234 // Use window surface as effective focus. | 
| 177 Surface* focus = Surface::AsSurface(window); | 235 Surface* focus = Surface::AsSurface(window); | 
| 178 if (!focus) { | 236 if (!focus) { | 
| 179 // Fallback to main surface. | 237 // Fallback to main surface. | 
| 180 aura::Window* top_level_window = window->GetToplevelWindow(); | 238 aura::Window* top_level_window = window->GetToplevelWindow(); | 
| 181 if (top_level_window) | 239 if (top_level_window) | 
| 182 focus = ShellSurface::GetMainSurface(top_level_window); | 240 focus = ShellSurface::GetMainSurface(top_level_window); | 
| 183 } | 241 } | 
| 184 | 242 | 
| 185 return focus && delegate_->CanAcceptKeyboardEventsForSurface(focus) ? focus | 243 return focus && delegate_->CanAcceptKeyboardEventsForSurface(focus) ? focus | 
| 186 : nullptr; | 244 : nullptr; | 
| 187 } | 245 } | 
| 188 | 246 | 
| 189 } // namespace exo | 247 } // namespace exo | 
| OLD | NEW |