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

Side by Side 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: Address reviewer feedback. 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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_ /* && !IsKeyboardUsabilityExperimentEnabled() */) {
sadrul 2014/01/10 19:53:21 Remove the /* comment
kevers 2014/01/13 16:59:10 Done.
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);
sadrul 2014/01/10 19:53:21 Don't you need to show the keyboard window here?
kevers 2014/01/13 16:59:10 Added a comment to clarify. We only wish to show t
270 } 248 }
271 // TODO(bryeung): whenever the TextInputClient changes we need to notify the 249 // 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. 250 // keyboard (with the TextInputType) so that it can reset it's state (e.g.
273 // abandon compositions in progress) 251 // abandon compositions in progress)
274 } 252 }
275 253
276 void KeyboardController::OnInputMethodDestroyed( 254 void KeyboardController::OnInputMethodDestroyed(
277 const ui::InputMethod* input_method) { 255 const ui::InputMethod* input_method) {
278 DCHECK_EQ(input_method_, input_method); 256 DCHECK_EQ(input_method_, input_method);
279 input_method_ = NULL; 257 input_method_ = NULL;
280 } 258 }
281 259
260 void KeyboardController::OnShowImeIfNeeded() {
261 if (!container_.get())
262 return;
263
264 if (container_->children().empty()) {
265 aura::Window* keyboard = proxy_->GetKeyboardWindow();
266 keyboard->Show();
267 container_->AddChild(keyboard);
268 }
269 if (keyboard_visible_)
270 return;
271
272 keyboard_visible_ = true;
273
274 // If the controller is in the process of hiding the keyboard, do not log
275 // the stat here since the keyboard will not actually be shown.
276 if (!WillHideKeyboard())
277 keyboard::LogKeyboardControlEvent(keyboard::KEYBOARD_CONTROL_SHOW);
278
279 weak_factory_.InvalidateWeakPtrs();
280 if (container_->IsVisible())
281 return;
282
283 NotifyKeyboardBoundsChanging(container_->children()[0]->bounds());
284
285 proxy_->ShowKeyboardContainer(container_.get());
286 }
287
282 bool KeyboardController::WillHideKeyboard() const { 288 bool KeyboardController::WillHideKeyboard() const {
283 return weak_factory_.HasWeakPtrs(); 289 return weak_factory_.HasWeakPtrs();
284 } 290 }
285 291
286 } // namespace keyboard 292 } // namespace keyboard
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698