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"
27 VirtualKeyboardManager
* instance
;
29 // A very basic and simple implementation of KeyboardControllerProxy.
30 class BasicKeyboardControllerProxy
: public keyboard::KeyboardControllerProxy
{
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
);
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
{}
56 content::BrowserContext
* browser_context_
;
57 aura::Window
* root_window_
;
59 DISALLOW_COPY_AND_ASSIGN(BasicKeyboardControllerProxy
);
62 class VirtualKeyboardManagerImpl
: public VirtualKeyboardManager
{
64 explicit VirtualKeyboardManagerImpl(content::BrowserContext
* browser_context
)
65 : browser_context_(browser_context
),
72 virtual ~VirtualKeyboardManagerImpl() {
73 CHECK_EQ(this, instance
);
76 keyboard::KeyboardController::ResetInstance(NULL
);
81 athena::ScreenManager::ContainerParams
params("VirtualKeyboardContainer",
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
);
95 content::BrowserContext
* browser_context_
;
96 aura::Window
* container_
;
97 scoped_ptr
<keyboard::KeyboardController
> keyboard_controller_
;
99 DISALLOW_COPY_AND_ASSIGN(VirtualKeyboardManagerImpl
);
105 VirtualKeyboardManager
* VirtualKeyboardManager::Create(
106 content::BrowserContext
* browser_context
) {
108 keyboard::InitializeKeyboard();
109 keyboard::SetTouchKeyboardEnabled(true);
110 keyboard::InitializeWebUIBindings();
112 new VirtualKeyboardManagerImpl(browser_context
);
117 VirtualKeyboardManager
* VirtualKeyboardManager::Get() {
121 void VirtualKeyboardManager::Shutdown() {
127 } // namespace athena