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 virtual void OnWindowResized() OVERRIDE { | |
sadrul
2013/04/02 16:10:31
// Overridden from aura::LayoutManager:
bryeung
2013/04/03 14:46:03
Done.
| |
23 gfx::Rect owner_bounds = owner_->bounds(); | |
24 gfx::Rect keyboard_bounds = gfx::Rect( | |
25 owner_bounds.x(), | |
26 owner_bounds.y() + owner_bounds.height() * 0.7, | |
27 owner_bounds.width(), | |
28 owner_bounds.height() * 0.3); | |
29 SetChildBoundsDirect(keyboard_, keyboard_bounds); | |
30 } | |
31 | |
32 virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE { | |
33 CHECK(child == keyboard_); | |
34 } | |
35 | |
36 virtual void OnWillRemoveWindowFromLayout(aura::Window* child) OVERRIDE {} | |
37 | |
38 virtual void OnWindowRemovedFromLayout(aura::Window* child) OVERRIDE {} | |
39 | |
40 virtual void OnChildWindowVisibilityChanged(aura::Window* child, | |
41 bool visible) OVERRIDE {} | |
42 | |
43 virtual void SetChildBounds(aura::Window* child, | |
44 const gfx::Rect& requested_bounds) OVERRIDE { | |
45 // Drop these: the size should only be set in OnWindowResized. | |
46 } | |
47 | |
48 private: | |
49 aura::Window* owner_; | |
50 aura::Window* keyboard_; | |
51 | |
52 DISALLOW_COPY_AND_ASSIGN(KeyboardLayoutManager); | |
53 }; | |
54 | |
55 } // namespace | |
56 | |
57 namespace keyboard { | |
58 | |
59 KeyboardController::KeyboardController( | |
60 KeyboardControllerProxy* proxy) | |
61 : proxy_(proxy) { | |
62 CHECK(proxy); | |
63 } | |
64 | |
65 KeyboardController::~KeyboardController() {} | |
66 | |
67 aura::Window* KeyboardController::GetContainerWindow() { | |
68 if (!container_) { | |
69 container_.reset(new aura::Window(NULL)); | |
70 container_->set_owned_by_parent(false); | |
71 container_->SetName("KeyboardContainer"); | |
72 container_->Init(ui::LAYER_NOT_DRAWN); | |
73 | |
74 aura::Window* keyboard = proxy_->GetKeyboardWindow(); | |
75 | |
76 container_->SetLayoutManager( | |
77 new KeyboardLayoutManager(container_.get(), keyboard)); | |
78 container_->AddChild(keyboard); | |
79 container_->Show(); | |
80 } | |
81 return container_.get(); | |
82 } | |
83 | |
84 } // namespace keyboard | |
OLD | NEW |