Index: ui/keyboard/keyboard_controller.cc |
diff --git a/ui/keyboard/keyboard_controller.cc b/ui/keyboard/keyboard_controller.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..b389f0e0185769e5803163e08ba91fc5a2925529 |
--- /dev/null |
+++ b/ui/keyboard/keyboard_controller.cc |
@@ -0,0 +1,84 @@ |
+// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "ui/keyboard/keyboard_controller.h" |
+ |
+#include "ui/aura/layout_manager.h" |
+#include "ui/aura/window.h" |
+#include "ui/gfx/rect.h" |
+#include "ui/keyboard/keyboard_controller_proxy.h" |
+ |
+namespace { |
+ |
+// LayoutManager for the virtual keyboard container. Manages a single window |
+// (the virtual keyboard) and keeps it positioned at the bottom of the |
+// container window. |
+class KeyboardLayoutManager : public aura::LayoutManager { |
+ public: |
+ KeyboardLayoutManager(aura::Window* owner, aura::Window* keyboard) |
+ : owner_(owner), keyboard_(keyboard) {} |
+ |
+ virtual void OnWindowResized() OVERRIDE { |
sadrul
2013/04/02 16:10:31
// Overridden from aura::LayoutManager:
bryeung
2013/04/03 14:46:03
Done.
|
+ gfx::Rect owner_bounds = owner_->bounds(); |
+ gfx::Rect keyboard_bounds = gfx::Rect( |
+ owner_bounds.x(), |
+ owner_bounds.y() + owner_bounds.height() * 0.7, |
+ owner_bounds.width(), |
+ owner_bounds.height() * 0.3); |
+ SetChildBoundsDirect(keyboard_, keyboard_bounds); |
+ } |
+ |
+ virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE { |
+ CHECK(child == keyboard_); |
+ } |
+ |
+ virtual void OnWillRemoveWindowFromLayout(aura::Window* child) OVERRIDE {} |
+ |
+ virtual void OnWindowRemovedFromLayout(aura::Window* child) OVERRIDE {} |
+ |
+ virtual void OnChildWindowVisibilityChanged(aura::Window* child, |
+ bool visible) OVERRIDE {} |
+ |
+ virtual void SetChildBounds(aura::Window* child, |
+ const gfx::Rect& requested_bounds) OVERRIDE { |
+ // Drop these: the size should only be set in OnWindowResized. |
+ } |
+ |
+ private: |
+ aura::Window* owner_; |
+ aura::Window* keyboard_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(KeyboardLayoutManager); |
+}; |
+ |
+} // namespace |
+ |
+namespace keyboard { |
+ |
+KeyboardController::KeyboardController( |
+ KeyboardControllerProxy* proxy) |
+ : proxy_(proxy) { |
+ CHECK(proxy); |
+} |
+ |
+KeyboardController::~KeyboardController() {} |
+ |
+aura::Window* KeyboardController::GetContainerWindow() { |
+ if (!container_) { |
+ container_.reset(new aura::Window(NULL)); |
+ container_->set_owned_by_parent(false); |
+ container_->SetName("KeyboardContainer"); |
+ container_->Init(ui::LAYER_NOT_DRAWN); |
+ |
+ aura::Window* keyboard = proxy_->GetKeyboardWindow(); |
+ |
+ container_->SetLayoutManager( |
+ new KeyboardLayoutManager(container_.get(), keyboard)); |
+ container_->AddChild(keyboard); |
+ container_->Show(); |
+ } |
+ return container_.get(); |
+} |
+ |
+} // namespace keyboard |