OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "ui/keyboard/keyboard_controller.h" | 5 #include "ui/keyboard/keyboard_controller.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "ui/aura/layout_manager.h" | 9 #include "ui/aura/layout_manager.h" |
10 #include "ui/aura/window.h" | 10 #include "ui/aura/window.h" |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 | 213 |
214 void KeyboardController::SetOverrideContentUrl(const GURL& url) { | 214 void KeyboardController::SetOverrideContentUrl(const GURL& url) { |
215 proxy_->SetOverrideContentUrl(url); | 215 proxy_->SetOverrideContentUrl(url); |
216 } | 216 } |
217 | 217 |
218 void KeyboardController::OnTextInputStateChanged( | 218 void KeyboardController::OnTextInputStateChanged( |
219 const ui::TextInputClient* client) { | 219 const ui::TextInputClient* client) { |
220 if (!container_.get()) | 220 if (!container_.get()) |
221 return; | 221 return; |
222 | 222 |
223 bool was_showing = keyboard_visible_; | 223 if (IsKeyboardUsabilityExperimentEnabled()) { |
224 bool should_show = was_showing; | 224 OnShowImeIfNeeded(); |
| 225 return; |
| 226 } |
| 227 |
225 ui::TextInputType type = | 228 ui::TextInputType type = |
226 client ? client->GetTextInputType() : ui::TEXT_INPUT_TYPE_NONE; | 229 client ? client->GetTextInputType() : ui::TEXT_INPUT_TYPE_NONE; |
227 if (type == ui::TEXT_INPUT_TYPE_NONE && | 230 if (type == ui::TEXT_INPUT_TYPE_NONE && !lock_keyboard_) { |
228 !IsKeyboardUsabilityExperimentEnabled() && | 231 if (keyboard_visible_) { |
229 !lock_keyboard_) { | |
230 should_show = false; | |
231 } else { | |
232 if (container_->children().empty()) { | |
233 keyboard::MarkKeyboardLoadStarted(); | |
234 aura::Window* keyboard = proxy_->GetKeyboardWindow(); | |
235 keyboard->Show(); | |
236 container_->AddChild(keyboard); | |
237 } | |
238 if (type != ui::TEXT_INPUT_TYPE_NONE) | |
239 proxy_->SetUpdateInputType(type); | |
240 container_->parent()->StackChildAtTop(container_.get()); | |
241 should_show = true; | |
242 } | |
243 | |
244 if (was_showing != should_show) { | |
245 if (should_show) { | |
246 keyboard_visible_ = true; | |
247 | |
248 // If the controller is in the process of hiding the keyboard, do not log | |
249 // the stat here since the keyboard will not actually be shown. | |
250 if (!WillHideKeyboard()) | |
251 keyboard::LogKeyboardControlEvent(keyboard::KEYBOARD_CONTROL_SHOW); | |
252 | |
253 weak_factory_.InvalidateWeakPtrs(); | |
254 if (container_->IsVisible()) | |
255 return; | |
256 | |
257 NotifyKeyboardBoundsChanging(container_->children()[0]->bounds()); | |
258 | |
259 proxy_->ShowKeyboardContainer(container_.get()); | |
260 } else { | |
261 // Set the visibility state here so that any queries for visibility | 232 // Set the visibility state here so that any queries for visibility |
262 // before the timer fires returns the correct future value. | 233 // before the timer fires returns the correct future value. |
263 keyboard_visible_ = false; | 234 keyboard_visible_ = false; |
264 base::MessageLoop::current()->PostDelayedTask( | 235 base::MessageLoop::current()->PostDelayedTask( |
265 FROM_HERE, | 236 FROM_HERE, |
266 base::Bind(&KeyboardController::HideKeyboard, | 237 base::Bind(&KeyboardController::HideKeyboard, |
267 weak_factory_.GetWeakPtr(), HIDE_REASON_AUTOMATIC), | 238 weak_factory_.GetWeakPtr(), HIDE_REASON_AUTOMATIC), |
268 base::TimeDelta::FromMilliseconds(kHideKeyboardDelayMs)); | 239 base::TimeDelta::FromMilliseconds(kHideKeyboardDelayMs)); |
269 } | 240 } |
| 241 } else { |
| 242 // Abort a pending keyboard hide. |
| 243 if (WillHideKeyboard()) { |
| 244 weak_factory_.InvalidateWeakPtrs(); |
| 245 keyboard_visible_ = true; |
| 246 } |
| 247 proxy_->SetUpdateInputType(type); |
| 248 // Do not explicitly show the Virtual keyboard unless it is in the process |
| 249 // of hiding. Instead, the virtual keyboard is shown in response to a user |
| 250 // gesture (mouse or touch) that is received while an element has input |
| 251 // focus. Showing the keyboard requires an explicit call to |
| 252 // OnShowImeIfNeeded. |
270 } | 253 } |
271 // TODO(bryeung): whenever the TextInputClient changes we need to notify the | 254 // TODO(bryeung): whenever the TextInputClient changes we need to notify the |
272 // keyboard (with the TextInputType) so that it can reset it's state (e.g. | 255 // keyboard (with the TextInputType) so that it can reset it's state (e.g. |
273 // abandon compositions in progress) | 256 // abandon compositions in progress) |
274 } | 257 } |
275 | 258 |
276 void KeyboardController::OnInputMethodDestroyed( | 259 void KeyboardController::OnInputMethodDestroyed( |
277 const ui::InputMethod* input_method) { | 260 const ui::InputMethod* input_method) { |
278 DCHECK_EQ(input_method_, input_method); | 261 DCHECK_EQ(input_method_, input_method); |
279 input_method_ = NULL; | 262 input_method_ = NULL; |
280 } | 263 } |
281 | 264 |
| 265 void KeyboardController::OnShowImeIfNeeded() { |
| 266 if (!container_.get()) |
| 267 return; |
| 268 |
| 269 if (container_->children().empty()) { |
| 270 aura::Window* keyboard = proxy_->GetKeyboardWindow(); |
| 271 keyboard->Show(); |
| 272 container_->AddChild(keyboard); |
| 273 } |
| 274 if (keyboard_visible_) |
| 275 return; |
| 276 |
| 277 keyboard_visible_ = true; |
| 278 |
| 279 // If the controller is in the process of hiding the keyboard, do not log |
| 280 // the stat here since the keyboard will not actually be shown. |
| 281 if (!WillHideKeyboard()) |
| 282 keyboard::LogKeyboardControlEvent(keyboard::KEYBOARD_CONTROL_SHOW); |
| 283 |
| 284 weak_factory_.InvalidateWeakPtrs(); |
| 285 if (container_->IsVisible()) |
| 286 return; |
| 287 |
| 288 NotifyKeyboardBoundsChanging(container_->children()[0]->bounds()); |
| 289 |
| 290 proxy_->ShowKeyboardContainer(container_.get()); |
| 291 } |
| 292 |
282 bool KeyboardController::WillHideKeyboard() const { | 293 bool KeyboardController::WillHideKeyboard() const { |
283 return weak_factory_.HasWeakPtrs(); | 294 return weak_factory_.HasWeakPtrs(); |
284 } | 295 } |
285 | 296 |
286 } // namespace keyboard | 297 } // namespace keyboard |
OLD | NEW |