OLD | NEW |
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/types/display_constants.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 Loading... |
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 keyboard_locked_(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); |
180 ui_->SetController(this); | 183 ui_->SetController(this); |
181 } | 184 } |
182 | 185 |
183 KeyboardController::~KeyboardController() { | 186 KeyboardController::~KeyboardController() { |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 keyboard_visible_ = false; | 239 keyboard_visible_ = false; |
237 ToggleTouchEventLogging(true); | 240 ToggleTouchEventLogging(true); |
238 | 241 |
239 keyboard::LogKeyboardControlEvent( | 242 keyboard::LogKeyboardControlEvent( |
240 reason == HIDE_REASON_AUTOMATIC ? | 243 reason == HIDE_REASON_AUTOMATIC ? |
241 keyboard::KEYBOARD_CONTROL_HIDE_AUTO : | 244 keyboard::KEYBOARD_CONTROL_HIDE_AUTO : |
242 keyboard::KEYBOARD_CONTROL_HIDE_USER); | 245 keyboard::KEYBOARD_CONTROL_HIDE_USER); |
243 | 246 |
244 NotifyKeyboardBoundsChanging(gfx::Rect()); | 247 NotifyKeyboardBoundsChanging(gfx::Rect()); |
245 | 248 |
246 set_lock_keyboard(false); | 249 set_keyboard_locked(false); |
247 | 250 |
248 ui::LayerAnimator* container_animator = container_->layer()->GetAnimator(); | 251 ui::LayerAnimator* container_animator = container_->layer()->GetAnimator(); |
249 animation_observer_.reset(new CallbackAnimationObserver( | 252 animation_observer_.reset(new CallbackAnimationObserver( |
250 container_animator, | 253 container_animator, |
251 base::Bind(&KeyboardController::HideAnimationFinished, | 254 base::Bind(&KeyboardController::HideAnimationFinished, |
252 base::Unretained(this)))); | 255 base::Unretained(this)))); |
253 container_animator->AddObserver(animation_observer_.get()); | 256 container_animator->AddObserver(animation_observer_.get()); |
254 | 257 |
255 ui::ScopedLayerAnimationSettings settings(container_animator); | 258 ui::ScopedLayerAnimationSettings settings(container_animator); |
256 settings.SetTweenType(gfx::Tween::FAST_OUT_LINEAR_IN); | 259 settings.SetTweenType(gfx::Tween::FAST_OUT_LINEAR_IN); |
(...skipping 30 matching lines...) Expand all Loading... |
287 gfx::Rect new_bounds = root_bounds; | 290 gfx::Rect new_bounds = root_bounds; |
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_keyboard_locked(lock); |
298 ShowKeyboardInternal(); | 301 ShowKeyboardInternal(display::kInvalidDisplayId); |
| 302 } |
| 303 |
| 304 void KeyboardController::ShowKeyboardInDisplay(int64_t display_id) { |
| 305 set_keyboard_locked(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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 } | 360 } |
353 } | 361 } |
354 | 362 |
355 void KeyboardController::OnTextInputStateChanged( | 363 void KeyboardController::OnTextInputStateChanged( |
356 const ui::TextInputClient* client) { | 364 const ui::TextInputClient* client) { |
357 if (!container_.get()) | 365 if (!container_.get()) |
358 return; | 366 return; |
359 | 367 |
360 type_ = client ? client->GetTextInputType() : ui::TEXT_INPUT_TYPE_NONE; | 368 type_ = client ? client->GetTextInputType() : ui::TEXT_INPUT_TYPE_NONE; |
361 | 369 |
362 if (type_ == ui::TEXT_INPUT_TYPE_NONE && !lock_keyboard_) { | 370 if (type_ == ui::TEXT_INPUT_TYPE_NONE && !keyboard_locked_) { |
363 if (keyboard_visible_) { | 371 if (keyboard_visible_) { |
364 // Set the visibility state here so that any queries for visibility | 372 // Set the visibility state here so that any queries for visibility |
365 // before the timer fires returns the correct future value. | 373 // before the timer fires returns the correct future value. |
366 keyboard_visible_ = false; | 374 keyboard_visible_ = false; |
367 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 375 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
368 FROM_HERE, | 376 FROM_HERE, |
369 base::Bind(&KeyboardController::HideKeyboard, | 377 base::Bind(&KeyboardController::HideKeyboard, |
370 weak_factory_.GetWeakPtr(), HIDE_REASON_AUTOMATIC), | 378 weak_factory_.GetWeakPtr(), HIDE_REASON_AUTOMATIC), |
371 base::TimeDelta::FromMilliseconds(kHideKeyboardDelayMs)); | 379 base::TimeDelta::FromMilliseconds(kHideKeyboardDelayMs)); |
372 } | 380 } |
(...skipping 12 matching lines...) Expand all Loading... |
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 move the keyboard to another display. |
396 ShowKeyboardInternal(); | 404 if (IsKeyboardEnabled() && !keyboard_locked()) |
| 405 ShowKeyboardInternal(display::kInvalidDisplayId); |
397 } | 406 } |
398 | 407 |
399 void KeyboardController::ShowKeyboardInternal() { | 408 void KeyboardController::ShowKeyboardInternal(int64_t display_id) { |
400 if (!container_.get()) | 409 if (!container_.get()) |
401 return; | 410 return; |
402 | 411 |
403 if (container_->children().empty()) { | 412 if (container_->children().empty()) { |
404 keyboard::MarkKeyboardLoadStarted(); | 413 keyboard::MarkKeyboardLoadStarted(); |
405 aura::Window* keyboard = ui_->GetKeyboardWindow(); | 414 aura::Window* keyboard = ui_->GetKeyboardWindow(); |
406 keyboard->Show(); | 415 keyboard->Show(); |
407 container_->AddChild(keyboard); | 416 container_->AddChild(keyboard); |
408 keyboard->set_owned_by_parent(false); | 417 keyboard->set_owned_by_parent(false); |
409 } | 418 } |
410 | 419 |
411 ui_->ReloadKeyboardIfNeeded(); | 420 ui_->ReloadKeyboardIfNeeded(); |
412 | 421 |
| 422 if (layout_delegate_ != nullptr) { |
| 423 if (display_id != display::kInvalidDisplayId) |
| 424 layout_delegate_->MoveKeyboardToDisplay(display_id); |
| 425 else |
| 426 layout_delegate_->MoveKeyboardToTouchableDisplay(); |
| 427 } |
| 428 |
413 if (keyboard_visible_) { | 429 if (keyboard_visible_) { |
414 return; | 430 return; |
415 } else if (ui_->GetKeyboardWindow()->bounds().height() == 0) { | 431 } else if (ui_->GetKeyboardWindow()->bounds().height() == 0) { |
416 show_on_resize_ = true; | 432 show_on_resize_ = true; |
417 return; | 433 return; |
418 } | 434 } |
419 | 435 |
420 keyboard_visible_ = true; | 436 keyboard_visible_ = true; |
421 | 437 |
422 // If the controller is in the process of hiding the keyboard, do not log | 438 // 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 Loading... |
485 ui_->EnsureCaretInWorkArea(); | 501 ui_->EnsureCaretInWorkArea(); |
486 } | 502 } |
487 | 503 |
488 void KeyboardController::HideAnimationFinished() { | 504 void KeyboardController::HideAnimationFinished() { |
489 ui_->HideKeyboardContainer(container_.get()); | 505 ui_->HideKeyboardContainer(container_.get()); |
490 for (KeyboardControllerObserver& observer : observer_list_) | 506 for (KeyboardControllerObserver& observer : observer_list_) |
491 observer.OnKeyboardHidden(); | 507 observer.OnKeyboardHidden(); |
492 } | 508 } |
493 | 509 |
494 } // namespace keyboard | 510 } // namespace keyboard |
OLD | NEW |