Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(401)

Side by Side Diff: components/exo/keyboard.cc

Issue 2506263002: exo: Implement support for zcr_keyboard_configuration_v1 protocol. (Closed)
Patch Set: fix initialization Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 IsPhysicalKeyboardEnabled() {
78 // The internal keyboard is enabled if maximize mode is not enabled.
79 if (WMHelper::GetInstance()->IsMaximizeModeWindowManagerEnabled())
80 return true;
81
82 for (auto& keyboard :
83 ui::InputDeviceManager::GetInstance()->GetKeyboardDevices()) {
84 if (keyboard.type != ui::InputDeviceType::INPUT_DEVICE_INTERNAL)
85 return true;
86 }
87 return false;
88 }
89
90 } // namespace
91
73 //////////////////////////////////////////////////////////////////////////////// 92 ////////////////////////////////////////////////////////////////////////////////
74 // Keyboard, public: 93 // Keyboard, public:
75 94
76 Keyboard::Keyboard(KeyboardDelegate* delegate) : delegate_(delegate) { 95 Keyboard::Keyboard(KeyboardDelegate* delegate) : delegate_(delegate) {
77 auto* helper = WMHelper::GetInstance(); 96 auto* helper = WMHelper::GetInstance();
78 helper->AddPostTargetHandler(this); 97 helper->AddPostTargetHandler(this);
79 helper->AddFocusObserver(this); 98 helper->AddFocusObserver(this);
99 helper->AddMaximizeModeObserver(this);
100 helper->AddInputDeviceEventObserver(this);
80 OnWindowFocused(helper->GetFocusedWindow(), nullptr); 101 OnWindowFocused(helper->GetFocusedWindow(), nullptr);
81 } 102 }
82 103
83 Keyboard::~Keyboard() { 104 Keyboard::~Keyboard() {
84 delegate_->OnKeyboardDestroying(this); 105 delegate_->OnKeyboardDestroying(this);
106 if (device_configuration_delegate_)
107 device_configuration_delegate_->OnKeyboardDestroying(this);
85 if (focus_) 108 if (focus_)
86 focus_->RemoveSurfaceObserver(this); 109 focus_->RemoveSurfaceObserver(this);
87 auto* helper = WMHelper::GetInstance(); 110 auto* helper = WMHelper::GetInstance();
88 helper->RemoveFocusObserver(this); 111 helper->RemoveFocusObserver(this);
89 helper->RemovePostTargetHandler(this); 112 helper->RemovePostTargetHandler(this);
113 helper->RemoveMaximizeModeObserver(this);
114 helper->RemoveInputDeviceEventObserver(this);
115 }
116
117 void Keyboard::SetDeviceConfigurationDelegate(
118 KeyboardDeviceConfigurationDelegate* delegate) {
119 if (device_configuration_delegate_)
120 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.
121 device_configuration_delegate_ = delegate;
122 OnKeyboardDeviceConfigurationChanged();
90 } 123 }
91 124
92 //////////////////////////////////////////////////////////////////////////////// 125 ////////////////////////////////////////////////////////////////////////////////
93 // ui::EventHandler overrides: 126 // ui::EventHandler overrides:
94 127
95 void Keyboard::OnKeyEvent(ui::KeyEvent* event) { 128 void Keyboard::OnKeyEvent(ui::KeyEvent* event) {
96 // These modifiers reflect what Wayland is aware of. For example, 129 // These modifiers reflect what Wayland is aware of. For example,
97 // EF_SCROLL_LOCK_ON is missing because Wayland doesn't support scroll lock. 130 // 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 | 131 const int kModifierMask = ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN |
99 ui::EF_ALT_DOWN | ui::EF_COMMAND_DOWN | 132 ui::EF_ALT_DOWN | ui::EF_COMMAND_DOWN |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 //////////////////////////////////////////////////////////////////////////////// 196 ////////////////////////////////////////////////////////////////////////////////
164 // SurfaceObserver overrides: 197 // SurfaceObserver overrides:
165 198
166 void Keyboard::OnSurfaceDestroying(Surface* surface) { 199 void Keyboard::OnSurfaceDestroying(Surface* surface) {
167 DCHECK(surface == focus_); 200 DCHECK(surface == focus_);
168 focus_ = nullptr; 201 focus_ = nullptr;
169 surface->RemoveSurfaceObserver(this); 202 surface->RemoveSurfaceObserver(this);
170 } 203 }
171 204
172 //////////////////////////////////////////////////////////////////////////////// 205 ////////////////////////////////////////////////////////////////////////////////
206 // ui::InputDeviceEventObserver overrides:
207
208 void Keyboard::OnKeyboardDeviceConfigurationChanged() {
209 if (device_configuration_delegate_) {
210 device_configuration_delegate_->OnKeyboardTypeChanged(
211 IsPhysicalKeyboardEnabled());
212 }
213 }
214
215 ////////////////////////////////////////////////////////////////////////////////
216 // WMHelper::MaximizeModeObserver overrides:
217
218 void Keyboard::OnMaximizeModeStarted() {
219 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.
220 device_configuration_delegate_->OnKeyboardTypeChanged(
221 IsPhysicalKeyboardEnabled());
222 }
223 }
224
225 void Keyboard::OnMaximizeModeEnded() {
226 if (device_configuration_delegate_) {
reveman 2016/12/09 16:15:02 call OnKeyboardDeviceConfigurationChanged() here?
yhanada 2016/12/10 00:09:11 Done.
227 device_configuration_delegate_->OnKeyboardTypeChanged(
228 IsPhysicalKeyboardEnabled());
229 }
230 }
231
232 ////////////////////////////////////////////////////////////////////////////////
173 // Keyboard, private: 233 // Keyboard, private:
174 234
175 Surface* Keyboard::GetEffectiveFocus(aura::Window* window) const { 235 Surface* Keyboard::GetEffectiveFocus(aura::Window* window) const {
176 // Use window surface as effective focus. 236 // Use window surface as effective focus.
177 Surface* focus = Surface::AsSurface(window); 237 Surface* focus = Surface::AsSurface(window);
178 if (!focus) { 238 if (!focus) {
179 // Fallback to main surface. 239 // Fallback to main surface.
180 aura::Window* top_level_window = window->GetToplevelWindow(); 240 aura::Window* top_level_window = window->GetToplevelWindow();
181 if (top_level_window) 241 if (top_level_window)
182 focus = ShellSurface::GetMainSurface(top_level_window); 242 focus = ShellSurface::GetMainSurface(top_level_window);
183 } 243 }
184 244
185 return focus && delegate_->CanAcceptKeyboardEventsForSurface(focus) ? focus 245 return focus && delegate_->CanAcceptKeyboardEventsForSurface(focus) ? focus
186 : nullptr; 246 : nullptr;
187 } 247 }
188 248
189 } // namespace exo 249 } // namespace exo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698