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

Unified Diff: ui/keyboard/keyboard_controller.cc

Issue 29943002: Limit display of the virtual keyboard to state changes triggered from a user gesture. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix unit tests for input methods on Windows. Created 6 years, 11 months 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 side-by-side diff with in-line comments
Download patch
Index: ui/keyboard/keyboard_controller.cc
diff --git a/ui/keyboard/keyboard_controller.cc b/ui/keyboard/keyboard_controller.cc
index ca8e54fcc4af7d903c842c95e7e273516de48d62..bbc0d9553c48af879bf95f4135229f386fe6ad2f 100644
--- a/ui/keyboard/keyboard_controller.cc
+++ b/ui/keyboard/keyboard_controller.cc
@@ -220,44 +220,15 @@ void KeyboardController::OnTextInputStateChanged(
if (!container_.get())
return;
- bool was_showing = keyboard_visible_;
- bool should_show = was_showing;
- ui::TextInputType type =
- client ? client->GetTextInputType() : ui::TEXT_INPUT_TYPE_NONE;
- if (type == ui::TEXT_INPUT_TYPE_NONE &&
- !IsKeyboardUsabilityExperimentEnabled() &&
- !lock_keyboard_) {
- should_show = false;
- } else {
- if (container_->children().empty()) {
- keyboard::MarkKeyboardLoadStarted();
- aura::Window* keyboard = proxy_->GetKeyboardWindow();
- keyboard->Show();
- container_->AddChild(keyboard);
- }
- if (type != ui::TEXT_INPUT_TYPE_NONE)
- proxy_->SetUpdateInputType(type);
- container_->parent()->StackChildAtTop(container_.get());
- should_show = true;
+ if (IsKeyboardUsabilityExperimentEnabled()) {
+ OnShowImeIfNeeded();
+ return;
}
- if (was_showing != should_show) {
- if (should_show) {
- keyboard_visible_ = true;
-
- // If the controller is in the process of hiding the keyboard, do not log
- // the stat here since the keyboard will not actually be shown.
- if (!WillHideKeyboard())
- keyboard::LogKeyboardControlEvent(keyboard::KEYBOARD_CONTROL_SHOW);
-
- weak_factory_.InvalidateWeakPtrs();
- if (container_->IsVisible())
- return;
-
- NotifyKeyboardBoundsChanging(container_->children()[0]->bounds());
-
- proxy_->ShowKeyboardContainer(container_.get());
- } else {
+ ui::TextInputType type =
+ client ? client->GetTextInputType() : ui::TEXT_INPUT_TYPE_NONE;
+ if (type == ui::TEXT_INPUT_TYPE_NONE && !lock_keyboard_) {
+ if (keyboard_visible_ /* && !IsKeyboardUsabilityExperimentEnabled() */) {
// Set the visibility state here so that any queries for visibility
// before the timer fires returns the correct future value.
keyboard_visible_ = false;
@@ -267,6 +238,13 @@ void KeyboardController::OnTextInputStateChanged(
weak_factory_.GetWeakPtr(), HIDE_REASON_AUTOMATIC),
base::TimeDelta::FromMilliseconds(kHideKeyboardDelayMs));
}
+ } else {
+ // Abort a pending keyboard hide.
+ if (WillHideKeyboard()) {
+ weak_factory_.InvalidateWeakPtrs();
+ keyboard_visible_ = true;
+ }
+ proxy_->SetUpdateInputType(type);
}
// 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.
@@ -279,6 +257,37 @@ void KeyboardController::OnInputMethodDestroyed(
input_method_ = NULL;
}
+void KeyboardController::OnShowImeIfNeeded() {
+ if (!container_.get())
+ return;
+
+ if (container_->children().empty()) {
+ aura::Window* keyboard = proxy_->GetKeyboardWindow();
+ keyboard->Show();
+ container_->AddChild(keyboard);
+ container_->layout_manager()->OnWindowResized();
Shu Chen 2014/01/09 04:21:17 unnecessary call to OnWindowResized(), because now
kevers 2014/01/09 15:29:09 Done.
+ }
+ if (keyboard_visible_)
+ return;
+
+ keyboard_visible_ = true;
+
+ // If the controller is in the process of hiding the keyboard, do not log
+ // the stat here since the keyboard will not actually be shown.
+ if (!WillHideKeyboard())
+ keyboard::LogKeyboardControlEvent(keyboard::KEYBOARD_CONTROL_SHOW);
+
+ weak_factory_.InvalidateWeakPtrs();
+ if (container_->IsVisible())
+ return;
+
+ FOR_EACH_OBSERVER(
+ KeyboardControllerObserver,
+ observer_list_,
+ OnKeyboardBoundsChanging(container_->children()[0]->bounds()));
Shu Chen 2014/01/09 04:21:17 Why not use this? NotifyKeyboardBoundsChanging(con
kevers 2014/01/09 15:29:09 Done.
+ proxy_->ShowKeyboardContainer(container_.get());
+}
+
bool KeyboardController::WillHideKeyboard() const {
return weak_factory_.HasWeakPtrs();
}

Powered by Google App Engine
This is Rietveld 408576698