Index: ui/keyboard/keyboard_controller.cc |
diff --git a/ui/keyboard/keyboard_controller.cc b/ui/keyboard/keyboard_controller.cc |
index 1a3d88db3e12aec8bdfb6879f66ae61e09c4827f..0977f892ed07456cde323c075665755a9841df80 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" |
@@ -19,6 +20,8 @@ |
namespace { |
+const int kHideKeyboardDelayMs = 100; |
+ |
gfx::Rect KeyboardBoundsFromWindowBounds(const gfx::Rect& window_bounds) { |
const float kKeyboardHeightRatio = 0.3f; |
return gfx::Rect( |
@@ -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,15 @@ void KeyboardController::OnInputMethodDestroyed( |
input_method_ = NULL; |
} |
+void KeyboardController::HideKeyboard() { |
+ FOR_EACH_OBSERVER(KeyboardControllerObserver, |
+ observer_list_, |
+ OnKeyboardBoundsChanging(gfx::Rect())); |
+ proxy_->HideKeyboardContainer(container_); |
+} |
+ |
+bool KeyboardController::WillHideKeyboard() const { |
+ return weak_factory_.HasWeakPtrs(); |
+} |
+ |
} // namespace keyboard |