| Index: ui/keyboard/keyboard_controller.cc
|
| diff --git a/ui/keyboard/keyboard_controller.cc b/ui/keyboard/keyboard_controller.cc
|
| index 1a3d88db3e12aec8bdfb6879f66ae61e09c4827f..09ed815c03ec416b9737fa0e45b52170eeb09fe9 100644
|
| --- a/ui/keyboard/keyboard_controller.cc
|
| +++ b/ui/keyboard/keyboard_controller.cc
|
| @@ -4,6 +4,7 @@
|
|
|
| #include "ui/keyboard/keyboard_controller.h"
|
|
|
| +#include "base/bind.h"
|
| #include "ui/aura/layout_manager.h"
|
| #include "ui/aura/window.h"
|
| #include "ui/aura/window_delegate.h"
|
| @@ -78,6 +79,8 @@ class KeyboardWindowDelegate : public aura::WindowDelegate {
|
|
|
| namespace keyboard {
|
|
|
| +const int kHideKeyboardDelayMs = 100;
|
| +
|
| // LayoutManager for the virtual keyboard container. Manages a single window
|
| // (the virtual keyboard) and keeps it positioned at the bottom of the
|
| // owner window.
|
| @@ -118,7 +121,9 @@ class KeyboardLayoutManager : public aura::LayoutManager {
|
| KeyboardController::KeyboardController(KeyboardControllerProxy* proxy)
|
| : proxy_(proxy),
|
| container_(NULL),
|
| - input_method_(NULL) {
|
| + input_method_(NULL),
|
| + keyboard_visible_(false),
|
| + weak_factory_(this) {
|
| CHECK(proxy);
|
| input_method_ = proxy_->GetInputMethod();
|
| input_method_->AddObserver(this);
|
| @@ -166,7 +171,7 @@ void KeyboardController::OnTextInputStateChanged(
|
| if (!container_)
|
| return;
|
|
|
| - bool was_showing = container_->IsVisible();
|
| + bool was_showing = keyboard_visible_;
|
| bool should_show = was_showing;
|
| if (!client || client->GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE) {
|
| should_show = false;
|
| @@ -182,20 +187,26 @@ void KeyboardController::OnTextInputStateChanged(
|
| }
|
|
|
| if (was_showing != should_show) {
|
| - gfx::Rect new_bounds(
|
| - should_show ? container_->children()[0]->bounds() : gfx::Rect());
|
| -
|
| - FOR_EACH_OBSERVER(
|
| - KeyboardControllerObserver,
|
| - observer_list_,
|
| - OnKeyboardBoundsChanging(new_bounds));
|
| -
|
| - if (should_show)
|
| + if (should_show) {
|
| + keyboard_visible_ = true;
|
| + weak_factory_.InvalidateWeakPtrs();
|
| + if (container_->IsVisible())
|
| + return;
|
| +
|
| + FOR_EACH_OBSERVER(
|
| + KeyboardControllerObserver,
|
| + observer_list_,
|
| + OnKeyboardBoundsChanging(container_->children()[0]->bounds()));
|
| proxy_->ShowKeyboardContainer(container_);
|
| - else
|
| - proxy_->HideKeyboardContainer(container_);
|
| + } else {
|
| + keyboard_visible_ = false;
|
| + base::MessageLoop::current()->PostDelayedTask(
|
| + FROM_HERE,
|
| + base::Bind(&KeyboardController::HideKeyboard,
|
| + weak_factory_.GetWeakPtr()),
|
| + base::TimeDelta::FromMilliseconds(kHideKeyboardDelayMs));
|
| + }
|
| }
|
| -
|
| // TODO(bryeung): whenever the TextInputClient changes we need to notify the
|
| // keyboard (with the TextInputType) so that it can reset it's state (e.g.
|
| // abandon compositions in progress)
|
| @@ -207,4 +218,11 @@ void KeyboardController::OnInputMethodDestroyed(
|
| input_method_ = NULL;
|
| }
|
|
|
| +void KeyboardController::HideKeyboard() {
|
| + FOR_EACH_OBSERVER(KeyboardControllerObserver,
|
| + observer_list_,
|
| + OnKeyboardBoundsChanging(gfx::Rect()));
|
| + proxy_->HideKeyboardContainer(container_);
|
| +}
|
| +
|
| } // namespace keyboard
|
|
|