Chromium Code Reviews| 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(0, 0, container_bounds.width(), |
| 24 window_bounds.width(), | 24 container_bounds.height())); |
|
sadrul
2015/04/01 06:43:49
gfx::Rect(container_bounds.size())
bshe
2015/04/01 20:41:33
Done.
| |
| 25 height)); | |
| 26 } | 25 } |
| 27 } | 26 } |
| 28 | 27 |
| 29 void KeyboardLayoutManager::OnWindowAddedToLayout(aura::Window* child) { | 28 void KeyboardLayoutManager::OnWindowAddedToLayout(aura::Window* child) { |
| 30 DCHECK(!keyboard_); | 29 DCHECK(!keyboard_); |
| 31 keyboard_ = child; | 30 keyboard_ = child; |
| 32 keyboard_->SetBounds(DefaultKeyboardBoundsFromWindowBounds( | 31 if (controller_->keyboard_mode() == FULL_WIDTH) { |
| 33 controller_->GetContainerWindow()->bounds())); | 32 controller_->GetContainerWindow()->SetBounds( |
| 33 DefaultKeyboardBoundsFromRootBounds( | |
| 34 controller_->GetContainerWindow()->GetRootWindow()->bounds())); | |
| 35 } else if (controller_->keyboard_mode() == FLOATING) { | |
| 36 controller_->GetContainerWindow()->SetBounds(child->bounds()); | |
| 37 SetChildBoundsDirect(keyboard_, gfx::Rect(0, 0, child->bounds().width(), | |
| 38 child->bounds().height())); | |
|
sadrul
2015/04/01 06:43:49
ditto
bshe
2015/04/01 20:41:33
Done.
| |
| 39 } | |
| 34 } | 40 } |
| 35 | 41 |
| 36 void KeyboardLayoutManager::SetChildBounds(aura::Window* child, | 42 void KeyboardLayoutManager::SetChildBounds(aura::Window* child, |
| 37 const gfx::Rect& requested_bounds) { | 43 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_); | 44 DCHECK(child == keyboard_); |
| 43 | 45 |
| 46 // Request to change the bounds of child window (AKA the virtual keyboard | |
| 47 // window) should change the container window first. Then the child window is | |
| 48 // resized and covers the container window. Note the child's bound is only set | |
| 49 // in OnWindowResized. | |
| 50 gfx::Rect old_bounds = controller_->GetContainerWindow()->bounds(); | |
|
sadrul
2015/04/01 06:43:49
const &
bshe
2015/04/01 20:41:33
We actually want gfx::Rect here as we need to chec
| |
| 51 gfx::Rect new_bounds = requested_bounds; | |
| 52 if (controller_->keyboard_mode() == FULL_WIDTH) { | |
| 53 gfx::Rect window_bounds = | |
|
sadrul
2015/04/01 06:43:49
const &
bshe
2015/04/01 20:41:33
Done.
| |
| 54 controller_->GetContainerWindow()->GetRootWindow()->bounds(); | |
| 55 new_bounds.set_y(window_bounds.height() - new_bounds.height()); | |
| 56 new_bounds.set_width(window_bounds.width()); | |
| 57 } | |
| 58 // Keyboard bounds should only be reset when it actually changes. Otherwise | |
| 59 // it interrupts the initial animation of showing the keyboard. Described in | |
| 60 // crbug.com/356753. | |
| 61 if (new_bounds == old_bounds) { | |
| 62 return; | |
| 63 } | |
| 64 | |
| 44 ui::LayerAnimator* animator = | 65 ui::LayerAnimator* animator = |
| 45 controller_->GetContainerWindow()->layer()->GetAnimator(); | 66 controller_->GetContainerWindow()->layer()->GetAnimator(); |
| 46 // Stops previous animation if a window resize is requested during animation. | 67 // Stops previous animation if a window resize is requested during animation. |
| 47 if (animator->is_animating()) | 68 if (animator->is_animating()) |
| 48 animator->StopAnimating(); | 69 animator->StopAnimating(); |
| 49 | 70 |
| 50 gfx::Rect old_bounds = child->bounds(); | 71 controller_->GetContainerWindow()->SetBounds(new_bounds); |
| 51 SetChildBoundsDirect(child, requested_bounds); | 72 SetChildBoundsDirect(keyboard_, gfx::Rect(0, 0, new_bounds.width(), |
| 52 if (old_bounds.height() == 0 && child->bounds().height() != 0 && | 73 new_bounds.height())); |
|
sadrul
2015/04/01 06:43:49
gfx::Rect(new_bounds.size())
bshe
2015/04/01 20:41:33
Done.
| |
| 53 controller_->show_on_resize()) { | 74 |
| 54 // The window height is set to 0 initially or before switch to an IME in a | 75 if (controller_->keyboard_mode() == FULL_WIDTH) { |
| 55 // different extension. Virtual keyboard window may wait for this bounds | 76 if (old_bounds.height() == 0 && child->bounds().height() != 0 && |
| 56 // change to correctly animate in. | 77 controller_->show_on_resize()) { |
| 57 controller_->ShowKeyboard(false); | 78 // The window height is set to 0 initially or before switch to an IME in a |
| 58 } else { | 79 // different extension. Virtual keyboard window may wait for this bounds |
| 59 // We need to send out this notification only if keyboard is visible since | 80 // change to correctly animate in. |
| 60 // keyboard window is resized even if keyboard is hidden. | 81 controller_->ShowKeyboard(false); |
| 61 if (controller_->keyboard_visible()) | 82 } else { |
| 62 controller_->NotifyKeyboardBoundsChanging(requested_bounds); | 83 // We need to send out this notification only if keyboard is visible since |
| 84 // keyboard window is resized even if keyboard is hidden. | |
| 85 if (controller_->keyboard_visible()) | |
| 86 controller_->NotifyKeyboardBoundsChanging(requested_bounds); | |
| 87 } | |
| 88 } else if (controller_->keyboard_mode() == FLOATING) { | |
| 89 controller_->NotifyKeyboardBoundsChanging(gfx::Rect()); | |
| 63 } | 90 } |
| 64 } | 91 } |
| 65 | 92 |
| 66 } // namespace keyboard | 93 } // namespace keyboard |
| OLD | NEW |