OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2013 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. | |
4 | |
5 #include "ui/keyboard/keyboard_controller.h" | |
6 | |
7 #include "ui/aura/layout_manager.h" | |
8 #include "ui/aura/window.h" | |
9 #include "ui/gfx/rect.h" | |
10 #include "ui/keyboard/keyboard_controller_proxy.h" | |
11 | |
12 namespace { | |
13 | |
14 // LayoutManager for the virtual keyboard container. Manages a single window | |
15 // (the virtual keyboard) and keeps it positioned at the bottom of the | |
16 // container window. | |
17 class KeyboardLayoutManager : public aura::LayoutManager { | |
18 public: | |
19 KeyboardLayoutManager(aura::Window* owner, aura::Window* keyboard) | |
20 : owner_(owner), keyboard_(keyboard) {} | |
21 | |
22 // Overridden from aura::LayoutManager | |
23 virtual void OnWindowResized() OVERRIDE { | |
24 gfx::Rect owner_bounds = owner_->bounds(); | |
25 gfx::Rect keyboard_bounds = gfx::Rect( | |
26 owner_bounds.x(), | |
27 owner_bounds.y() + owner_bounds.height() * 0.7, | |
28 owner_bounds.width(), | |
29 owner_bounds.height() * 0.3); | |
30 SetChildBoundsDirect(keyboard_, keyboard_bounds); | |
31 } | |
32 | |
33 virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE { | |
34 CHECK(child == keyboard_); | |
35 } | |
36 | |
37 virtual void OnWillRemoveWindowFromLayout(aura::Window* child) OVERRIDE {} | |
38 | |
39 virtual void OnWindowRemovedFromLayout(aura::Window* child) OVERRIDE {} | |
40 | |
41 virtual void OnChildWindowVisibilityChanged(aura::Window* child, | |
42 bool visible) OVERRIDE {} | |
43 | |
44 virtual void SetChildBounds(aura::Window* child, | |
45 const gfx::Rect& requested_bounds) OVERRIDE { | |
46 // Drop these: the size should only be set in OnWindowResized. | |
47 } | |
48 | |
49 private: | |
50 aura::Window* owner_; | |
51 aura::Window* keyboard_; | |
52 | |
53 DISALLOW_COPY_AND_ASSIGN(KeyboardLayoutManager); | |
54 }; | |
55 | |
56 } // namespace | |
57 | |
58 namespace keyboard { | |
59 | |
60 KeyboardController::KeyboardController( | |
61 KeyboardControllerProxy* proxy) | |
62 : proxy_(proxy), container_(NULL) { | |
sadrul
2013/04/04 22:08:25
2 more spaces.
bryeung
2013/04/05 12:29:38
Done.
| |
63 CHECK(proxy); | |
64 } | |
65 | |
66 KeyboardController::~KeyboardController() {} | |
67 | |
68 aura::Window* KeyboardController::GetContainerWindow() { | |
69 if (!container_) { | |
70 container_ = new aura::Window(NULL); | |
71 container_->SetName("KeyboardContainer"); | |
72 container_->Init(ui::LAYER_NOT_DRAWN); | |
73 | |
74 aura::Window* keyboard = proxy_->GetKeyboardWindow(); | |
75 keyboard->Show(); | |
76 | |
77 container_->SetLayoutManager( | |
78 new KeyboardLayoutManager(container_, keyboard)); | |
79 container_->AddChild(keyboard); | |
80 } | |
81 return container_; | |
82 } | |
83 | |
84 } // namespace keyboard | |
OLD | NEW |