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_util.h" | 9 #include "ui/keyboard/keyboard_util.h" |
10 | 10 |
11 namespace keyboard { | 11 namespace keyboard { |
12 | 12 |
13 // Overridden from aura::LayoutManager | 13 // Overridden from aura::LayoutManager |
14 void KeyboardLayoutManager::OnWindowResized() { | 14 void KeyboardLayoutManager::OnWindowResized() { |
15 if (keyboard_) { | 15 if (keyboard_) { |
16 // Container window is the top level window of the virtual keyboard window. | 16 // Container window is the top level window of the virtual keyboard window. |
17 // To support window.moveTo for the virtual keyboard window, as it actually | 17 // To support window.moveTo for the virtual keyboard window, as it actually |
18 // moves the top level window, the container window should be set to the | 18 // moves the top level window, the container window should be set to the |
19 // desired bounds before changing the bounds of the virtual keyboard window. | 19 // desired bounds before changing the bounds of the virtual keyboard window. |
20 gfx::Rect container_bounds = controller_->GetContainerWindow()->bounds(); | 20 gfx::Rect container_bounds = controller_->GetContainerWindow()->bounds(); |
21 // Always align container window and keyboard window. | 21 // Always align container window and keyboard window. |
22 SetChildBoundsDirect(keyboard_, gfx::Rect(container_bounds.size())); | 22 if (controller_->keyboard_mode() == FULL_WIDTH) { |
23 SetChildBounds(keyboard_, gfx::Rect(container_bounds.size())); | |
bshe
2016/06/28 12:14:16
Would it possible for you to try rotate the screen
| |
24 } else { | |
25 SetChildBoundsDirect(keyboard_, gfx::Rect(container_bounds.size())); | |
26 } | |
23 } | 27 } |
24 } | 28 } |
25 | 29 |
26 void KeyboardLayoutManager::OnWindowAddedToLayout(aura::Window* child) { | 30 void KeyboardLayoutManager::OnWindowAddedToLayout(aura::Window* child) { |
27 DCHECK(!keyboard_); | 31 DCHECK(!keyboard_); |
28 keyboard_ = child; | 32 keyboard_ = child; |
29 if (controller_->keyboard_mode() == FULL_WIDTH) { | 33 if (controller_->keyboard_mode() == FULL_WIDTH) { |
30 controller_->GetContainerWindow()->SetBounds(gfx::Rect()); | 34 controller_->GetContainerWindow()->SetBounds(gfx::Rect()); |
31 } else if (controller_->keyboard_mode() == FLOATING) { | 35 } else if (controller_->keyboard_mode() == FLOATING) { |
32 controller_->GetContainerWindow()->SetBounds(child->bounds()); | 36 controller_->GetContainerWindow()->SetBounds(child->bounds()); |
33 SetChildBoundsDirect(keyboard_, gfx::Rect(child->bounds().size())); | 37 SetChildBoundsDirect(keyboard_, gfx::Rect(child->bounds().size())); |
34 } | 38 } |
35 } | 39 } |
36 | 40 |
37 void KeyboardLayoutManager::SetChildBounds(aura::Window* child, | 41 void KeyboardLayoutManager::SetChildBounds(aura::Window* child, |
38 const gfx::Rect& requested_bounds) { | 42 const gfx::Rect& requested_bounds) { |
39 DCHECK(child == keyboard_); | 43 DCHECK(child == keyboard_); |
40 | 44 |
41 // Request to change the bounds of child window (AKA the virtual keyboard | 45 // Request to change the bounds of child window (AKA the virtual keyboard |
42 // window) should change the container window first. Then the child window is | 46 // window) should change the container window first. Then the child window is |
43 // resized and covers the container window. Note the child's bound is only set | 47 // resized and covers the container window. Note the child's bound is only set |
44 // in OnWindowResized. | 48 // in OnWindowResized. |
45 gfx::Rect old_bounds = controller_->GetContainerWindow()->bounds(); | |
46 gfx::Rect new_bounds = requested_bounds; | 49 gfx::Rect new_bounds = requested_bounds; |
47 if (controller_->keyboard_mode() == FULL_WIDTH) { | 50 if (controller_->keyboard_mode() == FULL_WIDTH) { |
48 const gfx::Rect& window_bounds = | 51 const gfx::Rect& window_bounds = |
49 controller_->GetContainerWindow()->GetRootWindow()->bounds(); | 52 controller_->GetContainerWindow()->GetRootWindow()->bounds(); |
50 new_bounds.set_y(window_bounds.height() - new_bounds.height()); | 53 new_bounds.set_y(window_bounds.height() - new_bounds.height()); |
51 // If shelf is positioned on the left side of screen, x is not 0. In | 54 // If shelf is positioned on the left side of screen, x is not 0. In |
52 // FULL_WIDTH mode, the virtual keyboard should always align with the left | 55 // FULL_WIDTH mode, the virtual keyboard should always align with the left |
53 // edge of the screen. So manually set x to 0 here. | 56 // edge of the screen. So manually set x to 0 here. |
54 new_bounds.set_x(0); | 57 new_bounds.set_x(0); |
55 new_bounds.set_width(window_bounds.width()); | 58 new_bounds.set_width(window_bounds.width()); |
56 } | 59 } |
57 // Keyboard bounds should only be reset when it actually changes. Otherwise | 60 // Keyboard bounds should only be reset when it actually changes. Otherwise |
58 // it interrupts the initial animation of showing the keyboard. Described in | 61 // it interrupts the initial animation of showing the keyboard. Described in |
59 // crbug.com/356753. | 62 // crbug.com/356753. |
60 if (new_bounds == old_bounds) { | 63 gfx::Rect old_bounds = keyboard_->GetTargetBounds(); |
64 aura::Window::ConvertRectToTarget(keyboard_, | |
65 keyboard_->GetRootWindow(), | |
66 &old_bounds); | |
67 if (new_bounds == old_bounds) | |
61 return; | 68 return; |
62 } | |
63 | 69 |
64 ui::LayerAnimator* animator = | 70 ui::LayerAnimator* animator = |
65 controller_->GetContainerWindow()->layer()->GetAnimator(); | 71 controller_->GetContainerWindow()->layer()->GetAnimator(); |
66 // Stops previous animation if a window resize is requested during animation. | 72 // Stops previous animation if a window resize is requested during animation. |
67 if (animator->is_animating()) | 73 if (animator->is_animating()) |
68 animator->StopAnimating(); | 74 animator->StopAnimating(); |
69 | 75 |
70 controller_->GetContainerWindow()->SetBounds(new_bounds); | 76 controller_->GetContainerWindow()->SetBounds(new_bounds); |
71 SetChildBoundsDirect(keyboard_, gfx::Rect(new_bounds.size())); | 77 SetChildBoundsDirect(keyboard_, gfx::Rect(new_bounds.size())); |
72 | 78 |
73 if (old_bounds.height() == 0 && child->bounds().height() != 0 && | 79 if (old_bounds.height() == 0 && child->bounds().height() != 0 && |
74 controller_->show_on_resize()) { | 80 controller_->show_on_resize()) { |
75 // The window height is set to 0 initially or before switch to an IME in a | 81 // The window height is set to 0 initially or before switch to an IME in a |
76 // different extension. Virtual keyboard window may wait for this bounds | 82 // different extension. Virtual keyboard window may wait for this bounds |
77 // change to correctly animate in. | 83 // change to correctly animate in. |
78 controller_->ShowKeyboard(false); | 84 controller_->ShowKeyboard(false); |
79 } else { | 85 } else { |
80 if (controller_->keyboard_mode() == FULL_WIDTH) { | 86 if (controller_->keyboard_mode() == FULL_WIDTH) { |
81 // We need to send out this notification only if keyboard is visible since | 87 // We need to send out this notification only if keyboard is visible since |
82 // keyboard window is resized even if keyboard is hidden. | 88 // keyboard window is resized even if keyboard is hidden. |
83 if (controller_->keyboard_visible()) | 89 if (controller_->keyboard_visible()) |
84 controller_->NotifyKeyboardBoundsChanging(requested_bounds); | 90 controller_->NotifyKeyboardBoundsChanging(requested_bounds); |
85 } else if (controller_->keyboard_mode() == FLOATING) { | 91 } else if (controller_->keyboard_mode() == FLOATING) { |
86 controller_->NotifyKeyboardBoundsChanging(gfx::Rect()); | 92 controller_->NotifyKeyboardBoundsChanging(gfx::Rect()); |
87 } | 93 } |
88 } | 94 } |
89 } | 95 } |
90 | 96 |
91 } // namespace keyboard | 97 } // namespace keyboard |
OLD | NEW |