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

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

Issue 2506263002: exo: Implement support for zcr_keyboard_configuration_v1 protocol. (Closed)
Patch Set: add one more TODO 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
« no previous file with comments | « components/exo/keyboard.h ('k') | components/exo/keyboard_delegate.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 device_configuration_delegate_ = delegate;
120 OnKeyboardDeviceConfigurationChanged();
90 } 121 }
91 122
92 //////////////////////////////////////////////////////////////////////////////// 123 ////////////////////////////////////////////////////////////////////////////////
93 // ui::EventHandler overrides: 124 // ui::EventHandler overrides:
94 125
95 void Keyboard::OnKeyEvent(ui::KeyEvent* event) { 126 void Keyboard::OnKeyEvent(ui::KeyEvent* event) {
96 // These modifiers reflect what Wayland is aware of. For example, 127 // These modifiers reflect what Wayland is aware of. For example,
97 // EF_SCROLL_LOCK_ON is missing because Wayland doesn't support scroll lock. 128 // 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 | 129 const int kModifierMask = ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN |
99 ui::EF_ALT_DOWN | ui::EF_COMMAND_DOWN | 130 ui::EF_ALT_DOWN | ui::EF_COMMAND_DOWN |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 //////////////////////////////////////////////////////////////////////////////// 194 ////////////////////////////////////////////////////////////////////////////////
164 // SurfaceObserver overrides: 195 // SurfaceObserver overrides:
165 196
166 void Keyboard::OnSurfaceDestroying(Surface* surface) { 197 void Keyboard::OnSurfaceDestroying(Surface* surface) {
167 DCHECK(surface == focus_); 198 DCHECK(surface == focus_);
168 focus_ = nullptr; 199 focus_ = nullptr;
169 surface->RemoveSurfaceObserver(this); 200 surface->RemoveSurfaceObserver(this);
170 } 201 }
171 202
172 //////////////////////////////////////////////////////////////////////////////// 203 ////////////////////////////////////////////////////////////////////////////////
204 // ui::InputDeviceEventObserver overrides:
205
206 void Keyboard::OnKeyboardDeviceConfigurationChanged() {
207 if (device_configuration_delegate_) {
208 device_configuration_delegate_->OnKeyboardTypeChanged(
209 IsPhysicalKeyboardEnabled());
210 }
211 }
212
213 ////////////////////////////////////////////////////////////////////////////////
214 // WMHelper::MaximizeModeObserver overrides:
215
216 void Keyboard::OnMaximizeModeStarted() {
217 OnKeyboardDeviceConfigurationChanged();
218 }
219
220 void Keyboard::OnMaximizeModeEnded() {
221 OnKeyboardDeviceConfigurationChanged();
222 }
223
224 ////////////////////////////////////////////////////////////////////////////////
173 // Keyboard, private: 225 // Keyboard, private:
174 226
175 Surface* Keyboard::GetEffectiveFocus(aura::Window* window) const { 227 Surface* Keyboard::GetEffectiveFocus(aura::Window* window) const {
176 // Use window surface as effective focus. 228 // Use window surface as effective focus.
177 Surface* focus = Surface::AsSurface(window); 229 Surface* focus = Surface::AsSurface(window);
178 if (!focus) { 230 if (!focus) {
179 // Fallback to main surface. 231 // Fallback to main surface.
180 aura::Window* top_level_window = window->GetToplevelWindow(); 232 aura::Window* top_level_window = window->GetToplevelWindow();
181 if (top_level_window) 233 if (top_level_window)
182 focus = ShellSurface::GetMainSurface(top_level_window); 234 focus = ShellSurface::GetMainSurface(top_level_window);
183 } 235 }
184 236
185 return focus && delegate_->CanAcceptKeyboardEventsForSurface(focus) ? focus 237 return focus && delegate_->CanAcceptKeyboardEventsForSurface(focus) ? focus
186 : nullptr; 238 : nullptr;
187 } 239 }
188 240
189 } // namespace exo 241 } // namespace exo
OLDNEW
« no previous file with comments | « components/exo/keyboard.h ('k') | components/exo/keyboard_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698