OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_layout_manager.h" | 5 #include "ui/keyboard/keyboard_layout_manager.h" |
6 | 6 |
7 #include "ui/compositor/layer_animator.h" | 7 #include "ui/compositor/layer_animator.h" |
8 #include "ui/keyboard/keyboard_controller.h" | 8 #include "ui/keyboard/keyboard_controller.h" |
9 #include "ui/keyboard/keyboard_controller_proxy.h" | 9 #include "ui/keyboard/keyboard_controller_proxy.h" |
10 #include "ui/keyboard/keyboard_util.h" | 10 #include "ui/keyboard/keyboard_util.h" |
11 | 11 |
12 namespace keyboard { | 12 namespace keyboard { |
13 | 13 |
14 // Overridden from aura::LayoutManager | 14 // Overridden from aura::LayoutManager |
15 void KeyboardLayoutManager::OnWindowResized() { | 15 void KeyboardLayoutManager::OnWindowResized() { |
16 if (keyboard_) { | 16 if (keyboard_) { |
17 gfx::Rect window_bounds = controller_->GetContainerWindow()->bounds(); | 17 // Container window is the top level window of the virtual keyboard window. |
18 // Keep the same height when window resize. It usually get called when | 18 // To support window.moveTo for the virtual keyboard window, as it actually |
19 // screen rotate. | 19 // moves the top level window, the container window should be set to the |
20 int height = keyboard_->bounds().height(); | 20 // desired bounds before changing the bounds of the virtual keyboard window. |
21 keyboard_->SetBounds(gfx::Rect( | 21 gfx::Rect container_bounds = controller_->GetContainerWindow()->bounds(); |
22 window_bounds.x(), | 22 // Always align container window and keyboard window. |
23 window_bounds.bottom() - height, | 23 SetChildBoundsDirect(keyboard_, gfx::Rect(container_bounds.size())); |
24 window_bounds.width(), | |
25 height)); | |
26 } | 24 } |
27 } | 25 } |
28 | 26 |
29 void KeyboardLayoutManager::OnWindowAddedToLayout(aura::Window* child) { | 27 void KeyboardLayoutManager::OnWindowAddedToLayout(aura::Window* child) { |
30 DCHECK(!keyboard_); | 28 DCHECK(!keyboard_); |
31 keyboard_ = child; | 29 keyboard_ = child; |
32 keyboard_->SetBounds(DefaultKeyboardBoundsFromWindowBounds( | 30 if (controller_->keyboard_mode() == FULL_WIDTH) { |
33 controller_->GetContainerWindow()->bounds())); | 31 controller_->GetContainerWindow()->SetBounds(gfx::Rect()); |
| 32 } else if (controller_->keyboard_mode() == FLOATING) { |
| 33 controller_->GetContainerWindow()->SetBounds(child->bounds()); |
| 34 SetChildBoundsDirect(keyboard_, gfx::Rect(child->bounds().size())); |
| 35 } |
34 } | 36 } |
35 | 37 |
36 void KeyboardLayoutManager::SetChildBounds(aura::Window* child, | 38 void KeyboardLayoutManager::SetChildBounds(aura::Window* child, |
37 const gfx::Rect& requested_bounds) { | 39 const gfx::Rect& requested_bounds) { |
38 // SetChildBounds can be invoked by resizing from the container or by | |
39 // resizing from the contents (through window.resizeTo call in JS). | |
40 // The flag resizing_from_contents() is used to determine the source of the | |
41 // resize. | |
42 DCHECK(child == keyboard_); | 40 DCHECK(child == keyboard_); |
43 | 41 |
| 42 // Request to change the bounds of child window (AKA the virtual keyboard |
| 43 // window) should change the container window first. Then the child window is |
| 44 // resized and covers the container window. Note the child's bound is only set |
| 45 // in OnWindowResized. |
| 46 gfx::Rect old_bounds = controller_->GetContainerWindow()->bounds(); |
| 47 gfx::Rect new_bounds = requested_bounds; |
| 48 if (controller_->keyboard_mode() == FULL_WIDTH) { |
| 49 const gfx::Rect& window_bounds = |
| 50 controller_->GetContainerWindow()->GetRootWindow()->bounds(); |
| 51 new_bounds.set_y(window_bounds.height() - new_bounds.height()); |
| 52 new_bounds.set_width(window_bounds.width()); |
| 53 } |
| 54 // Keyboard bounds should only be reset when it actually changes. Otherwise |
| 55 // it interrupts the initial animation of showing the keyboard. Described in |
| 56 // crbug.com/356753. |
| 57 if (new_bounds == old_bounds) { |
| 58 return; |
| 59 } |
| 60 |
44 ui::LayerAnimator* animator = | 61 ui::LayerAnimator* animator = |
45 controller_->GetContainerWindow()->layer()->GetAnimator(); | 62 controller_->GetContainerWindow()->layer()->GetAnimator(); |
46 // Stops previous animation if a window resize is requested during animation. | 63 // Stops previous animation if a window resize is requested during animation. |
47 if (animator->is_animating()) | 64 if (animator->is_animating()) |
48 animator->StopAnimating(); | 65 animator->StopAnimating(); |
49 | 66 |
50 gfx::Rect old_bounds = child->bounds(); | 67 controller_->GetContainerWindow()->SetBounds(new_bounds); |
51 SetChildBoundsDirect(child, requested_bounds); | 68 SetChildBoundsDirect(keyboard_, gfx::Rect(new_bounds.size())); |
52 if (old_bounds.height() == 0 && child->bounds().height() != 0 && | 69 |
53 controller_->show_on_resize()) { | 70 if (controller_->keyboard_mode() == FULL_WIDTH) { |
54 // The window height is set to 0 initially or before switch to an IME in a | 71 if (old_bounds.height() == 0 && child->bounds().height() != 0 && |
55 // different extension. Virtual keyboard window may wait for this bounds | 72 controller_->show_on_resize()) { |
56 // change to correctly animate in. | 73 // The window height is set to 0 initially or before switch to an IME in a |
57 controller_->ShowKeyboard(false); | 74 // different extension. Virtual keyboard window may wait for this bounds |
58 } else { | 75 // change to correctly animate in. |
59 // We need to send out this notification only if keyboard is visible since | 76 controller_->ShowKeyboard(false); |
60 // keyboard window is resized even if keyboard is hidden. | 77 } else { |
61 if (controller_->keyboard_visible()) | 78 // We need to send out this notification only if keyboard is visible since |
62 controller_->NotifyKeyboardBoundsChanging(requested_bounds); | 79 // keyboard window is resized even if keyboard is hidden. |
| 80 if (controller_->keyboard_visible()) |
| 81 controller_->NotifyKeyboardBoundsChanging(requested_bounds); |
| 82 } |
| 83 } else if (controller_->keyboard_mode() == FLOATING) { |
| 84 controller_->NotifyKeyboardBoundsChanging(gfx::Rect()); |
63 } | 85 } |
64 } | 86 } |
65 | 87 |
66 } // namespace keyboard | 88 } // namespace keyboard |
OLD | NEW |