Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / athena / virtual_keyboard / virtual_keyboard_manager_impl.cc
blob1de68ee1cb2f0c5e8b70d4bccb1c17ab21cc2a93
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 "athena/virtual_keyboard/public/virtual_keyboard_manager.h"
7 #include "athena/common/container_priorities.h"
8 #include "athena/common/fill_layout_manager.h"
9 #include "athena/screen/public/screen_manager.h"
10 #include "base/bind.h"
11 #include "base/memory/singleton.h"
12 #include "base/values.h"
13 #include "content/public/browser/browser_context.h"
14 #include "ui/aura/client/aura_constants.h"
15 #include "ui/aura/layout_manager.h"
16 #include "ui/aura/window.h"
17 #include "ui/keyboard/keyboard.h"
18 #include "ui/keyboard/keyboard_constants.h"
19 #include "ui/keyboard/keyboard_controller.h"
20 #include "ui/keyboard/keyboard_controller_proxy.h"
21 #include "ui/keyboard/keyboard_util.h"
23 namespace athena {
25 namespace {
27 VirtualKeyboardManager* instance;
29 // A very basic and simple implementation of KeyboardControllerProxy.
30 class BasicKeyboardControllerProxy : public keyboard::KeyboardControllerProxy {
31 public:
32 BasicKeyboardControllerProxy(content::BrowserContext* context,
33 aura::Window* root_window)
34 : browser_context_(context), root_window_(root_window) {}
35 virtual ~BasicKeyboardControllerProxy() {}
37 // keyboard::KeyboardControllerProxy:
38 virtual ui::InputMethod* GetInputMethod() OVERRIDE {
39 ui::InputMethod* input_method =
40 root_window_->GetProperty(aura::client::kRootWindowInputMethodKey);
41 return input_method;
44 virtual void RequestAudioInput(
45 content::WebContents* web_contents,
46 const content::MediaStreamRequest& request,
47 const content::MediaResponseCallback& callback) OVERRIDE {}
49 virtual content::BrowserContext* GetBrowserContext() OVERRIDE {
50 return browser_context_;
53 virtual void SetUpdateInputType(ui::TextInputType type) OVERRIDE {}
55 private:
56 content::BrowserContext* browser_context_;
57 aura::Window* root_window_;
59 DISALLOW_COPY_AND_ASSIGN(BasicKeyboardControllerProxy);
62 class VirtualKeyboardManagerImpl : public VirtualKeyboardManager {
63 public:
64 explicit VirtualKeyboardManagerImpl(content::BrowserContext* browser_context)
65 : browser_context_(browser_context),
66 container_(NULL) {
67 CHECK(!instance);
68 instance = this;
69 Init();
72 virtual ~VirtualKeyboardManagerImpl() {
73 CHECK_EQ(this, instance);
74 instance = NULL;
76 keyboard::KeyboardController::ResetInstance(NULL);
79 private:
80 void Init() {
81 athena::ScreenManager::ContainerParams params("VirtualKeyboardContainer",
82 CP_VIRTUAL_KEYBOARD);
83 container_ = athena::ScreenManager::Get()->CreateContainer(params);
84 container_->SetLayoutManager(new FillLayoutManager(container_));
86 keyboard_controller_.reset(new keyboard::KeyboardController(
87 new BasicKeyboardControllerProxy(browser_context_,
88 container_->GetRootWindow())));
89 keyboard::KeyboardController::ResetInstance(keyboard_controller_.get());
90 aura::Window* kb_container = keyboard_controller_->GetContainerWindow();
91 container_->AddChild(kb_container);
92 kb_container->Show();
95 content::BrowserContext* browser_context_;
96 aura::Window* container_;
97 scoped_ptr<keyboard::KeyboardController> keyboard_controller_;
99 DISALLOW_COPY_AND_ASSIGN(VirtualKeyboardManagerImpl);
102 } // namespace
104 // static
105 VirtualKeyboardManager* VirtualKeyboardManager::Create(
106 content::BrowserContext* browser_context) {
107 CHECK(!instance);
108 keyboard::InitializeKeyboard();
109 keyboard::SetTouchKeyboardEnabled(true);
110 keyboard::InitializeWebUIBindings();
112 new VirtualKeyboardManagerImpl(browser_context);
113 CHECK(instance);
114 return instance;
117 VirtualKeyboardManager* VirtualKeyboardManager::Get() {
118 return instance;
121 void VirtualKeyboardManager::Shutdown() {
122 CHECK(instance);
123 delete instance;
124 CHECK(!instance);
127 } // namespace athena