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/keyboard/keyboard_controller.h" | 8 #include "ui/keyboard/keyboard_controller.h" |
8 #include "ui/keyboard/keyboard_controller_proxy.h" | 9 #include "ui/keyboard/keyboard_controller_proxy.h" |
9 #include "ui/keyboard/keyboard_util.h" | 10 #include "ui/keyboard/keyboard_util.h" |
10 | 11 |
11 namespace keyboard { | 12 namespace keyboard { |
12 | 13 |
13 // Overridden from aura::LayoutManager | 14 // Overridden from aura::LayoutManager |
14 void KeyboardLayoutManager::OnWindowResized() { | 15 void KeyboardLayoutManager::OnWindowResized() { |
15 if (keyboard_ && !controller_->proxy()->resizing_from_contents()) | 16 if (keyboard_) { |
16 ResizeKeyboardToDefault(keyboard_); | 17 gfx::Rect window_bounds = controller_->GetContainerWindow()->bounds(); |
| 18 // Keep the same height when window resize. It usually get called when |
| 19 // screen rotate. |
| 20 int height = keyboard_->bounds().height(); |
| 21 keyboard_->SetBounds(gfx::Rect( |
| 22 window_bounds.x(), |
| 23 window_bounds.bottom() - height, |
| 24 window_bounds.width(), |
| 25 height)); |
| 26 } |
17 } | 27 } |
18 | 28 |
19 void KeyboardLayoutManager::OnWindowAddedToLayout(aura::Window* child) { | 29 void KeyboardLayoutManager::OnWindowAddedToLayout(aura::Window* child) { |
20 DCHECK(!keyboard_); | 30 DCHECK(!keyboard_); |
21 keyboard_ = child; | 31 keyboard_ = child; |
22 ResizeKeyboardToDefault(keyboard_); | 32 keyboard_->SetBounds(DefaultKeyboardBoundsFromWindowBounds( |
| 33 controller_->GetContainerWindow()->bounds())); |
23 } | 34 } |
24 | 35 |
25 void KeyboardLayoutManager::SetChildBounds(aura::Window* child, | 36 void KeyboardLayoutManager::SetChildBounds(aura::Window* child, |
26 const gfx::Rect& requested_bounds) { | 37 const gfx::Rect& requested_bounds) { |
27 // SetChildBounds can be invoked by resizing from the container or by | 38 // SetChildBounds can be invoked by resizing from the container or by |
28 // resizing from the contents (through window.resizeTo call in JS). | 39 // resizing from the contents (through window.resizeTo call in JS). |
29 // The flag resizing_from_contents() is used to determine the source of the | 40 // The flag resizing_from_contents() is used to determine the source of the |
30 // resize. | 41 // resize. |
31 if (controller_->proxy()->resizing_from_contents()) { | 42 DCHECK(child == keyboard_); |
| 43 |
| 44 ui::LayerAnimator* animator = |
| 45 controller_->GetContainerWindow()->layer()->GetAnimator(); |
| 46 // Stops previous animation if a window resize is requested during animation. |
| 47 if (animator->is_animating()) |
| 48 animator->StopAnimating(); |
| 49 |
| 50 gfx::Rect old_bounds = child->bounds(); |
| 51 SetChildBoundsDirect(child, requested_bounds); |
| 52 if (old_bounds.height() == 0 && child->bounds().height() != 0) { |
| 53 // The window height is set to 0 initially. If the height of |old_bounds| is |
| 54 // 0 and the new bounds is not 0, it probably means window.resizeTo is |
| 55 // called to set the window height. We should try to show keyboard again in |
| 56 // case the show keyboard request is called before the height is set. |
| 57 controller_->ShowKeyboard(false); |
| 58 } else { |
32 controller_->NotifyKeyboardBoundsChanging(requested_bounds); | 59 controller_->NotifyKeyboardBoundsChanging(requested_bounds); |
33 SetChildBoundsDirect(child, requested_bounds); | |
34 } | 60 } |
35 } | 61 } |
36 | 62 |
37 void KeyboardLayoutManager::ResizeKeyboardToDefault(aura::Window* child) { | |
38 gfx::Rect keyboard_bounds = DefaultKeyboardBoundsFromWindowBounds( | |
39 controller_->GetContainerWindow()->bounds()); | |
40 SetChildBoundsDirect(child, keyboard_bounds); | |
41 } | |
42 | |
43 } // namespace keyboard | 63 } // namespace keyboard |
OLD | NEW |