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.y() + window_bounds.height() - 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 bool forceShow = child->bounds().height() == 0; | |
Shu Chen
2014/04/22 17:54:57
The naming "forceShow" causes confusion.
If force
bshe
2014/04/23 01:08:53
I have changed the code to make it more readable.
| |
51 SetChildBoundsDirect(child, requested_bounds); | |
52 if (forceShow) { | |
53 controller_->ShowKeyboard(false); | |
54 } else { | |
32 controller_->NotifyKeyboardBoundsChanging(requested_bounds); | 55 controller_->NotifyKeyboardBoundsChanging(requested_bounds); |
33 SetChildBoundsDirect(child, requested_bounds); | |
34 } | 56 } |
35 } | 57 } |
36 | 58 |
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 | 59 } // namespace keyboard |
OLD | NEW |