OLD | NEW |
---|---|
(Empty) | |
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. | |
4 | |
5 #include "athena/virtual_keyboard/public/virtual_keyboard_manager.h" | |
6 | |
7 #include "athena/screen/public/screen_manager.h" | |
8 #include "athena/virtual_keyboard/vk_webui_controller.h" | |
9 #include "base/bind.h" | |
10 #include "base/memory/singleton.h" | |
11 #include "base/values.h" | |
12 #include "content/public/browser/browser_context.h" | |
13 #include "ui/aura/client/aura_constants.h" | |
14 #include "ui/aura/layout_manager.h" | |
15 #include "ui/aura/window.h" | |
16 #include "ui/keyboard/keyboard.h" | |
17 #include "ui/keyboard/keyboard_constants.h" | |
18 #include "ui/keyboard/keyboard_controller.h" | |
19 #include "ui/keyboard/keyboard_controller_proxy.h" | |
20 #include "ui/keyboard/keyboard_util.h" | |
21 | |
22 namespace athena { | |
23 | |
24 namespace { | |
25 | |
26 VirtualKeyboardManager* instance; | |
27 | |
28 class FillLayoutManager : public aura::LayoutManager { | |
oshima
2014/06/18 20:14:35
can you move the FillLaout from screen/screen_mana
sadrul
2014/06/18 20:57:53
Done.
| |
29 public: | |
30 explicit FillLayoutManager(aura::Window* container) : container_(container) { | |
31 DCHECK(container_); | |
32 } | |
33 | |
34 // aura::LayoutManager: | |
35 virtual void OnWindowResized() OVERRIDE { | |
36 gfx::Rect full_bounds = gfx::Rect(container_->bounds().size()); | |
37 for (aura::Window::Windows::const_iterator iter = | |
38 container_->children().begin(); | |
39 iter != container_->children().end(); | |
40 ++iter) { | |
41 SetChildBoundsDirect(*iter, full_bounds); | |
42 } | |
43 } | |
44 virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE { | |
45 SetChildBoundsDirect(child, (gfx::Rect(container_->bounds().size()))); | |
46 } | |
47 virtual void OnWillRemoveWindowFromLayout(aura::Window* child) OVERRIDE {} | |
48 virtual void OnWindowRemovedFromLayout(aura::Window* child) OVERRIDE {} | |
49 virtual void OnChildWindowVisibilityChanged(aura::Window* child, | |
50 bool visible) OVERRIDE {} | |
51 virtual void SetChildBounds(aura::Window* child, | |
52 const gfx::Rect& requested_bounds) OVERRIDE { | |
53 // Ignore SetBounds request. | |
54 } | |
55 | |
56 private: | |
57 aura::Window* container_; | |
58 | |
59 DISALLOW_COPY_AND_ASSIGN(FillLayoutManager); | |
60 }; | |
61 | |
62 // A very basic and simple implementation of KeyboardControllerProxy. | |
63 class BasicKeyboardControllerProxy : public keyboard::KeyboardControllerProxy { | |
64 public: | |
65 BasicKeyboardControllerProxy(content::BrowserContext* context, | |
66 aura::Window* root_window) | |
67 : browser_context_(context), root_window_(root_window) {} | |
68 virtual ~BasicKeyboardControllerProxy() {} | |
69 | |
70 // keyboard::KeyboardControllerProxy: | |
71 virtual ui::InputMethod* GetInputMethod() OVERRIDE { | |
72 ui::InputMethod* input_method = | |
73 root_window_->GetProperty(aura::client::kRootWindowInputMethodKey); | |
74 return input_method; | |
75 } | |
76 | |
77 virtual void RequestAudioInput( | |
78 content::WebContents* web_contents, | |
79 const content::MediaStreamRequest& request, | |
80 const content::MediaResponseCallback& callback) OVERRIDE {} | |
81 | |
82 virtual content::BrowserContext* GetBrowserContext() OVERRIDE { | |
83 return browser_context_; | |
84 } | |
85 | |
86 private: | |
87 content::BrowserContext* browser_context_; | |
88 aura::Window* root_window_; | |
89 | |
90 DISALLOW_COPY_AND_ASSIGN(BasicKeyboardControllerProxy); | |
91 }; | |
92 | |
93 class VirtualKeyboardManagerImpl : public VirtualKeyboardManager { | |
94 public: | |
95 VirtualKeyboardManagerImpl(aura::Window* window, | |
96 content::BrowserContext* browser_context) | |
97 : browser_context_(browser_context), | |
98 root_window_(window), | |
99 container_(NULL) { | |
100 CHECK(!instance); | |
101 instance = this; | |
102 Init(); | |
103 } | |
104 | |
105 virtual ~VirtualKeyboardManagerImpl() { | |
106 CHECK_EQ(this, instance); | |
107 instance = NULL; | |
oshima
2014/06/18 20:14:35
don't you have to do any cleanup where?
sadrul
2014/06/18 20:57:52
What kind of cleanup do you think could be useful
oshima
2014/06/18 21:11:15
Don't you have to do
keyboard::KeyboardController
sadrul
2014/06/18 21:19:10
Yes, good catch! Done. Thanks
| |
108 } | |
109 | |
110 private: | |
111 void Init() { | |
112 container_ = athena::ScreenManager::Get()->CreateContainer( | |
113 "VirtualKeyboardContainer"); | |
114 container_->SetLayoutManager(new FillLayoutManager(container_)); | |
115 keyboard::SetOverrideContentUrl(GURL(keyboard::kKeyboardURL)); | |
116 | |
117 keyboard_controller_.reset(new keyboard::KeyboardController( | |
118 new BasicKeyboardControllerProxy(browser_context_, root_window_))); | |
oshima
2014/06/18 20:14:35
can you simply use container_->GetRootWindow() ins
sadrul
2014/06/18 20:57:52
Done.
| |
119 keyboard::KeyboardController::ResetInstance(keyboard_controller_.get()); | |
120 aura::Window* kb_container = keyboard_controller_->GetContainerWindow(); | |
121 container_->AddChild(kb_container); | |
122 kb_container->Show(); | |
123 | |
124 content::WebUIControllerFactory::RegisterFactory( | |
125 VKWebUIControllerFactory::GetInstance()); | |
126 } | |
127 | |
128 content::BrowserContext* browser_context_; | |
129 aura::Window* root_window_; | |
130 aura::Window* container_; | |
131 scoped_ptr<keyboard::KeyboardController> keyboard_controller_; | |
132 | |
133 DISALLOW_COPY_AND_ASSIGN(VirtualKeyboardManagerImpl); | |
134 }; | |
135 | |
136 } // namespace | |
137 | |
138 // static | |
139 VirtualKeyboardManager* VirtualKeyboardManager::Create( | |
140 aura::Window* root, | |
141 content::BrowserContext* browser_context) { | |
142 CHECK(!instance); | |
143 keyboard::InitializeKeyboard(); | |
144 new VirtualKeyboardManagerImpl(root, browser_context); | |
145 CHECK(instance); | |
146 return instance; | |
147 } | |
148 | |
149 VirtualKeyboardManager* VirtualKeyboardManager::Get() { | |
150 return instance; | |
151 } | |
152 | |
153 void VirtualKeyboardManager::Shutdown() { | |
154 CHECK(instance); | |
155 delete instance; | |
156 CHECK(!instance); | |
157 } | |
158 | |
159 } // namespace athena | |
OLD | NEW |