Add type annotations to video_player.js.
[chromium-blink-merge.git] / ui / keyboard / keyboard_layout_manager.cc
blobc54f78ceeefebd14b5c6f780d55b4c1903122bb2
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 controller_->show_on_resize()) {
54 // The window height is set to 0 initially or before switch to an IME in a
55 // different extension. Virtual keyboard window may wait for this bounds
56 // change to correctly animate in.
57 controller_->ShowKeyboard(false);
58 } else {
59 // We need to send out this notification only if keyboard is visible since
60 // keyboard window is resized even if keyboard is hidden.
61 if (controller_->keyboard_visible())
62 controller_->NotifyKeyboardBoundsChanging(requested_bounds);
66 } // namespace keyboard