Supervised user whitelists: Cleanup
[chromium-blink-merge.git] / ui / keyboard / keyboard_layout_manager.cc
blob6eee390dabf8734f7682f3839cb272cebf239809
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
3 // found in the LICENSE file.
5 #include "ui/keyboard/keyboard_layout_manager.h"
7 #include "ui/compositor/layer_animator.h"
8 #include "ui/keyboard/keyboard_controller.h"
9 #include "ui/keyboard/keyboard_controller_proxy.h"
10 #include "ui/keyboard/keyboard_util.h"
12 namespace keyboard {
14 // Overridden from aura::LayoutManager
15 void KeyboardLayoutManager::OnWindowResized() {
16 if (keyboard_) {
17 // Container window is the top level window of the virtual keyboard window.
18 // To support window.moveTo for the virtual keyboard window, as it actually
19 // moves the top level window, the container window should be set to the
20 // desired bounds before changing the bounds of the virtual keyboard window.
21 gfx::Rect container_bounds = controller_->GetContainerWindow()->bounds();
22 // Always align container window and keyboard window.
23 SetChildBoundsDirect(keyboard_, gfx::Rect(container_bounds.size()));
27 void KeyboardLayoutManager::OnWindowAddedToLayout(aura::Window* child) {
28 DCHECK(!keyboard_);
29 keyboard_ = child;
30 if (controller_->keyboard_mode() == FULL_WIDTH) {
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()));
38 void KeyboardLayoutManager::SetChildBounds(aura::Window* child,
39 const gfx::Rect& requested_bounds) {
40 DCHECK(child == keyboard_);
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());
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;
61 ui::LayerAnimator* animator =
62 controller_->GetContainerWindow()->layer()->GetAnimator();
63 // Stops previous animation if a window resize is requested during animation.
64 if (animator->is_animating())
65 animator->StopAnimating();
67 controller_->GetContainerWindow()->SetBounds(new_bounds);
68 SetChildBoundsDirect(keyboard_, gfx::Rect(new_bounds.size()));
70 if (controller_->keyboard_mode() == FULL_WIDTH) {
71 if (old_bounds.height() == 0 && child->bounds().height() != 0 &&
72 controller_->show_on_resize()) {
73 // The window height is set to 0 initially or before switch to an IME in a
74 // different extension. Virtual keyboard window may wait for this bounds
75 // change to correctly animate in.
76 controller_->ShowKeyboard(false);
77 } else {
78 // We need to send out this notification only if keyboard is visible since
79 // keyboard window is resized even if keyboard is hidden.
80 if (controller_->keyboard_visible())
81 controller_->NotifyKeyboardBoundsChanging(requested_bounds);
83 } else if (controller_->keyboard_mode() == FLOATING) {
84 controller_->NotifyKeyboardBoundsChanging(gfx::Rect());
88 } // namespace keyboard