Adding a step to the check-in process that ensures the correct account information...
[chromium-blink-merge.git] / ui / keyboard / keyboard_layout_manager.cc
blobd7faf0fa7ab27cf20608019ccb880abe80b4e215
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 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));
29 void KeyboardLayoutManager::OnWindowAddedToLayout(aura::Window* child) {
30 DCHECK(!keyboard_);
31 keyboard_ = child;
32 keyboard_->SetBounds(DefaultKeyboardBoundsFromWindowBounds(
33 controller_->GetContainerWindow()->bounds()));
36 void KeyboardLayoutManager::SetChildBounds(aura::Window* child,
37 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 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();
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 {
59 controller_->NotifyKeyboardBoundsChanging(requested_bounds);
63 } // namespace keyboard