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

Side by Side Diff: ui/keyboard/keyboard_controller.cc

Issue 2445293002: Make the virtual keyboard show up on the display with input focus. (Closed)
Patch Set: rebase & update Created 4 years, 1 month 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
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 <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"
11 #include "base/location.h" 11 #include "base/location.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/single_thread_task_runner.h" 13 #include "base/single_thread_task_runner.h"
14 #include "base/threading/thread_task_runner_handle.h" 14 #include "base/threading/thread_task_runner_handle.h"
15 #include "build/build_config.h" 15 #include "build/build_config.h"
16 #include "ui/aura/window.h" 16 #include "ui/aura/window.h"
17 #include "ui/aura/window_delegate.h" 17 #include "ui/aura/window_delegate.h"
18 #include "ui/aura/window_observer.h" 18 #include "ui/aura/window_observer.h"
19 #include "ui/base/cursor/cursor.h" 19 #include "ui/base/cursor/cursor.h"
20 #include "ui/base/hit_test.h" 20 #include "ui/base/hit_test.h"
21 #include "ui/base/ime/input_method.h" 21 #include "ui/base/ime/input_method.h"
22 #include "ui/base/ime/text_input_client.h" 22 #include "ui/base/ime/text_input_client.h"
23 #include "ui/compositor/layer_animation_observer.h" 23 #include "ui/compositor/layer_animation_observer.h"
24 #include "ui/compositor/scoped_layer_animation_settings.h" 24 #include "ui/compositor/scoped_layer_animation_settings.h"
25 #include "ui/display/display.h"
25 #include "ui/gfx/geometry/rect.h" 26 #include "ui/gfx/geometry/rect.h"
26 #include "ui/gfx/path.h" 27 #include "ui/gfx/path.h"
27 #include "ui/gfx/skia_util.h" 28 #include "ui/gfx/skia_util.h"
28 #include "ui/keyboard/keyboard_controller_observer.h" 29 #include "ui/keyboard/keyboard_controller_observer.h"
29 #include "ui/keyboard/keyboard_layout_manager.h" 30 #include "ui/keyboard/keyboard_layout_manager.h"
30 #include "ui/keyboard/keyboard_ui.h" 31 #include "ui/keyboard/keyboard_ui.h"
31 #include "ui/keyboard/keyboard_util.h" 32 #include "ui/keyboard/keyboard_util.h"
32 33
33 #if defined(OS_CHROMEOS) 34 #if defined(OS_CHROMEOS)
34 #include "base/process/launch.h" 35 #include "base/process/launch.h"
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 } 159 }
159 160
160 void CallbackAnimationObserver::OnLayerAnimationAborted( 161 void CallbackAnimationObserver::OnLayerAnimationAborted(
161 ui::LayerAnimationSequence* seq) { 162 ui::LayerAnimationSequence* seq) {
162 animator_->RemoveObserver(this); 163 animator_->RemoveObserver(this);
163 } 164 }
164 165
165 // static 166 // static
166 KeyboardController* KeyboardController::instance_ = NULL; 167 KeyboardController* KeyboardController::instance_ = NULL;
167 168
168 KeyboardController::KeyboardController(KeyboardUI* ui) 169 KeyboardController::KeyboardController(KeyboardUI* ui,
170 KeyboardLayoutDelegate* delegate)
169 : ui_(ui), 171 : ui_(ui),
172 layout_delegate_(delegate),
170 input_method_(NULL), 173 input_method_(NULL),
171 keyboard_visible_(false), 174 keyboard_visible_(false),
172 show_on_resize_(false), 175 show_on_resize_(false),
173 lock_keyboard_(false), 176 lock_keyboard_(false),
174 keyboard_mode_(FULL_WIDTH), 177 keyboard_mode_(FULL_WIDTH),
175 type_(ui::TEXT_INPUT_TYPE_NONE), 178 type_(ui::TEXT_INPUT_TYPE_NONE),
176 weak_factory_(this) { 179 weak_factory_(this) {
177 CHECK(ui); 180 CHECK(ui);
178 input_method_ = ui_->GetInputMethod(); 181 input_method_ = ui_->GetInputMethod();
179 input_method_->AddObserver(this); 182 input_method_->AddObserver(this);
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 new_bounds.set_y(root_bounds.height() - keyboard_height); 291 new_bounds.set_y(root_bounds.height() - keyboard_height);
289 new_bounds.set_height(keyboard_height); 292 new_bounds.set_height(keyboard_height);
290 GetContainerWindow()->SetBounds(new_bounds); 293 GetContainerWindow()->SetBounds(new_bounds);
291 // No animation added, so call ShowAnimationFinished immediately. 294 // No animation added, so call ShowAnimationFinished immediately.
292 ShowAnimationFinished(); 295 ShowAnimationFinished();
293 } 296 }
294 } 297 }
295 298
296 void KeyboardController::ShowKeyboard(bool lock) { 299 void KeyboardController::ShowKeyboard(bool lock) {
297 set_lock_keyboard(lock); 300 set_lock_keyboard(lock);
298 ShowKeyboardInternal(); 301 ShowKeyboardInternal(display::Display::kInvalidDisplayID);
302 }
303
304 void KeyboardController::ShowKeyboardInSpecificDisplay(int64_t display_id) {
305 set_lock_keyboard(true);
306 ShowKeyboardInternal(display_id);
299 } 307 }
300 308
301 void KeyboardController::OnWindowHierarchyChanged( 309 void KeyboardController::OnWindowHierarchyChanged(
302 const HierarchyChangeParams& params) { 310 const HierarchyChangeParams& params) {
303 if (params.new_parent && params.target == container_.get()) 311 if (params.new_parent && params.target == container_.get())
304 OnTextInputStateChanged(ui_->GetInputMethod()->GetTextInputClient()); 312 OnTextInputStateChanged(ui_->GetInputMethod()->GetTextInputClient());
305 } 313 }
306 314
307 void KeyboardController::OnWindowAddedToRootWindow(aura::Window* window) { 315 void KeyboardController::OnWindowAddedToRootWindow(aura::Window* window) {
308 if (!window->GetRootWindow()->HasObserver(this)) 316 if (!window->GetRootWindow()->HasObserver(this))
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 } 393 }
386 } 394 }
387 395
388 void KeyboardController::OnInputMethodDestroyed( 396 void KeyboardController::OnInputMethodDestroyed(
389 const ui::InputMethod* input_method) { 397 const ui::InputMethod* input_method) {
390 DCHECK_EQ(input_method_, input_method); 398 DCHECK_EQ(input_method_, input_method);
391 input_method_ = NULL; 399 input_method_ = NULL;
392 } 400 }
393 401
394 void KeyboardController::OnShowImeIfNeeded() { 402 void KeyboardController::OnShowImeIfNeeded() {
395 if (IsKeyboardEnabled()) 403 // Calling |ShowKeyboardInternal| may cause the movement of the keyboard to
396 ShowKeyboardInternal(); 404 // another display.
405 if (IsKeyboardEnabled() && !get_lock_keyboard())
406 ShowKeyboardInternal(display::Display::kInvalidDisplayID);
397 } 407 }
398 408
399 void KeyboardController::ShowKeyboardInternal() { 409 void KeyboardController::ShowKeyboardInternal(int64_t display_id) {
400 if (!container_.get()) 410 if (!container_.get())
401 return; 411 return;
402 412
403 if (container_->children().empty()) { 413 if (container_->children().empty()) {
404 keyboard::MarkKeyboardLoadStarted(); 414 keyboard::MarkKeyboardLoadStarted();
405 aura::Window* keyboard = ui_->GetKeyboardWindow(); 415 aura::Window* keyboard = ui_->GetKeyboardWindow();
406 keyboard->Show(); 416 keyboard->Show();
407 container_->AddChild(keyboard); 417 container_->AddChild(keyboard);
408 keyboard->set_owned_by_parent(false); 418 keyboard->set_owned_by_parent(false);
409 } 419 }
410 420
411 ui_->ReloadKeyboardIfNeeded(); 421 ui_->ReloadKeyboardIfNeeded();
412 422
423 if (layout_delegate_ != nullptr) {
424 layout_delegate_->MoveKeyboardToAnotherDisplayIfNeeded(display_id);
425 }
oshima 2016/11/08 17:26:05 nuke {}
yhanada 2016/11/14 22:48:47 Done.
426
413 if (keyboard_visible_) { 427 if (keyboard_visible_) {
414 return; 428 return;
415 } else if (ui_->GetKeyboardWindow()->bounds().height() == 0) { 429 } else if (ui_->GetKeyboardWindow()->bounds().height() == 0) {
416 show_on_resize_ = true; 430 show_on_resize_ = true;
417 return; 431 return;
418 } 432 }
419 433
420 keyboard_visible_ = true; 434 keyboard_visible_ = true;
421 435
422 // If the controller is in the process of hiding the keyboard, do not log 436 // If the controller is in the process of hiding the keyboard, do not log
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 ui_->EnsureCaretInWorkArea(); 499 ui_->EnsureCaretInWorkArea();
486 } 500 }
487 501
488 void KeyboardController::HideAnimationFinished() { 502 void KeyboardController::HideAnimationFinished() {
489 ui_->HideKeyboardContainer(container_.get()); 503 ui_->HideKeyboardContainer(container_.get());
490 for (KeyboardControllerObserver& observer : observer_list_) 504 for (KeyboardControllerObserver& observer : observer_list_)
491 observer.OnKeyboardHidden(); 505 observer.OnKeyboardHidden();
492 } 506 }
493 507
494 } // namespace keyboard 508 } // namespace keyboard
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698