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 | |
Ben Goodger (Google)
2013/04/05 16:01:48
remove nls around this method:
bryeung
2013/04/05 17:22:24
Done.
| |
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(KeyboardControllerProxy* proxy) | |
61 : proxy_(proxy), container_(NULL) { | |
62 CHECK(proxy); | |
63 } | |
64 | |
65 KeyboardController::~KeyboardController() {} | |
66 | |
67 aura::Window* KeyboardController::GetContainerWindow() { | |
68 if (!container_) { | |
69 container_ = new aura::Window(NULL); | |
70 container_->SetName("KeyboardContainer"); | |
71 container_->Init(ui::LAYER_NOT_DRAWN); | |
72 | |
73 aura::Window* keyboard = proxy_->GetKeyboardWindow(); | |
74 keyboard->Show(); | |
75 | |
76 container_->SetLayoutManager( | |
77 new KeyboardLayoutManager(container_, keyboard)); | |
78 container_->AddChild(keyboard); | |
79 } | |
80 return container_; | |
81 } | |
82 | |
83 } // namespace keyboard | |
OLD | NEW |