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 <set> | 7 #include <set> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 | 168 |
169 KeyboardController::KeyboardController(KeyboardUI* ui, | 169 KeyboardController::KeyboardController(KeyboardUI* ui, |
170 KeyboardLayoutDelegate* delegate) | 170 KeyboardLayoutDelegate* delegate) |
171 : ui_(ui), | 171 : ui_(ui), |
172 layout_delegate_(delegate), | 172 layout_delegate_(delegate), |
173 input_method_(NULL), | 173 input_method_(NULL), |
174 keyboard_visible_(false), | 174 keyboard_visible_(false), |
175 show_on_resize_(false), | 175 show_on_resize_(false), |
176 keyboard_locked_(false), | 176 keyboard_locked_(false), |
177 keyboard_mode_(FULL_WIDTH), | 177 keyboard_mode_(FULL_WIDTH), |
178 type_(ui::TEXT_INPUT_TYPE_NONE), | |
179 weak_factory_(this) { | 178 weak_factory_(this) { |
180 CHECK(ui); | 179 CHECK(ui); |
181 input_method_ = ui_->GetInputMethod(); | 180 input_method_ = ui_->GetInputMethod(); |
182 input_method_->AddObserver(this); | 181 input_method_->AddObserver(this); |
183 ui_->SetController(this); | 182 ui_->SetController(this); |
184 } | 183 } |
185 | 184 |
186 KeyboardController::~KeyboardController() { | 185 KeyboardController::~KeyboardController() { |
187 if (container_) { | 186 if (container_) { |
188 if (container_->GetRootWindow()) | 187 if (container_->GetRootWindow()) |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
358 show_on_resize_ = false; | 357 show_on_resize_ = false; |
359 ui_->ReloadKeyboardIfNeeded(); | 358 ui_->ReloadKeyboardIfNeeded(); |
360 } | 359 } |
361 } | 360 } |
362 | 361 |
363 void KeyboardController::OnTextInputStateChanged( | 362 void KeyboardController::OnTextInputStateChanged( |
364 const ui::TextInputClient* client) { | 363 const ui::TextInputClient* client) { |
365 if (!container_.get()) | 364 if (!container_.get()) |
366 return; | 365 return; |
367 | 366 |
368 type_ = client ? client->GetTextInputType() : ui::TEXT_INPUT_TYPE_NONE; | 367 ui::TextInputType type = |
| 368 client ? client->GetTextInputType() : ui::TEXT_INPUT_TYPE_NONE; |
369 | 369 |
370 if (type_ == ui::TEXT_INPUT_TYPE_NONE && !keyboard_locked_) { | 370 if (type == ui::TEXT_INPUT_TYPE_NONE && !keyboard_locked_) { |
371 if (keyboard_visible_) { | 371 if (keyboard_visible_) { |
372 // Set the visibility state here so that any queries for visibility | 372 // Set the visibility state here so that any queries for visibility |
373 // before the timer fires returns the correct future value. | 373 // before the timer fires returns the correct future value. |
374 keyboard_visible_ = false; | 374 keyboard_visible_ = false; |
375 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 375 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
376 FROM_HERE, | 376 FROM_HERE, |
377 base::Bind(&KeyboardController::HideKeyboard, | 377 base::Bind(&KeyboardController::HideKeyboard, |
378 weak_factory_.GetWeakPtr(), HIDE_REASON_AUTOMATIC), | 378 weak_factory_.GetWeakPtr(), HIDE_REASON_AUTOMATIC), |
379 base::TimeDelta::FromMilliseconds(kHideKeyboardDelayMs)); | 379 base::TimeDelta::FromMilliseconds(kHideKeyboardDelayMs)); |
380 } | 380 } |
381 } else { | 381 } else { |
382 // Abort a pending keyboard hide. | 382 // Abort a pending keyboard hide. |
383 if (WillHideKeyboard()) { | 383 if (WillHideKeyboard()) { |
384 weak_factory_.InvalidateWeakPtrs(); | 384 weak_factory_.InvalidateWeakPtrs(); |
385 keyboard_visible_ = true; | 385 keyboard_visible_ = true; |
386 } | 386 } |
387 ui_->SetUpdateInputType(type_); | 387 ui_->SetUpdateInputType(type); |
388 // Do not explicitly show the Virtual keyboard unless it is in the process | 388 // Do not explicitly show the Virtual keyboard unless it is in the process |
389 // of hiding. Instead, the virtual keyboard is shown in response to a user | 389 // of hiding. Instead, the virtual keyboard is shown in response to a user |
390 // gesture (mouse or touch) that is received while an element has input | 390 // gesture (mouse or touch) that is received while an element has input |
391 // focus. Showing the keyboard requires an explicit call to | 391 // focus. Showing the keyboard requires an explicit call to |
392 // OnShowImeIfNeeded. | 392 // OnShowImeIfNeeded. |
393 } | 393 } |
394 } | 394 } |
395 | 395 |
396 void KeyboardController::OnInputMethodDestroyed( | 396 void KeyboardController::OnInputMethodDestroyed( |
397 const ui::InputMethod* input_method) { | 397 const ui::InputMethod* input_method) { |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
518 int keyboard_height = GetContainerWindow()->bounds().height(); | 518 int keyboard_height = GetContainerWindow()->bounds().height(); |
519 const gfx::Rect& root_bounds = container_->GetRootWindow()->bounds(); | 519 const gfx::Rect& root_bounds = container_->GetRootWindow()->bounds(); |
520 gfx::Rect new_bounds = root_bounds; | 520 gfx::Rect new_bounds = root_bounds; |
521 new_bounds.set_y(root_bounds.height() - keyboard_height); | 521 new_bounds.set_y(root_bounds.height() - keyboard_height); |
522 new_bounds.set_height(keyboard_height); | 522 new_bounds.set_height(keyboard_height); |
523 GetContainerWindow()->SetBounds(new_bounds); | 523 GetContainerWindow()->SetBounds(new_bounds); |
524 } | 524 } |
525 } | 525 } |
526 | 526 |
527 } // namespace keyboard | 527 } // namespace keyboard |
OLD | NEW |