OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/virtual_keyboard/virtual_keyboard_manager.h" | 5 #include "chrome/browser/ui/virtual_keyboard/virtual_keyboard_manager.h" |
6 | 6 |
7 #include "base/json/json_writer.h" | 7 #include "base/json/json_writer.h" |
8 #include "base/values.h" | 8 #include "base/values.h" |
9 #include "chrome/browser/extensions/extension_event_router.h" | 9 #include "chrome/browser/extensions/extension_event_router.h" |
10 #include "chrome/browser/extensions/extension_function_dispatcher.h" | 10 #include "chrome/browser/extensions/extension_function_dispatcher.h" |
11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
12 #include "chrome/browser/profiles/profile_manager.h" | 12 #include "chrome/browser/profiles/profile_manager.h" |
13 #include "chrome/browser/tabs/tab_strip_model.h" | 13 #include "chrome/browser/tabs/tab_strip_model.h" |
14 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
15 #include "chrome/browser/ui/browser_window.h" | 15 #include "chrome/browser/ui/browser_window.h" |
16 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 16 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
17 #include "chrome/browser/ui/views/dom_view.h" | 17 #include "chrome/browser/ui/views/dom_view.h" |
18 #include "chrome/browser/ui/views/frame/browser_view.h" | 18 #include "chrome/browser/ui/views/frame/browser_view.h" |
19 #include "chrome/common/chrome_notification_types.h" | 19 #include "chrome/common/chrome_notification_types.h" |
20 #include "chrome/common/extensions/extension_messages.h" | 20 #include "chrome/common/extensions/extension_messages.h" |
21 #include "chrome/common/url_constants.h" | 21 #include "chrome/common/url_constants.h" |
22 #include "content/public/browser/notification_service.h" | 22 #include "content/public/browser/notification_service.h" |
23 #include "content/public/browser/site_instance.h" | 23 #include "content/public/browser/site_instance.h" |
| 24 #include "content/public/browser/web_contents.h" |
24 #include "content/public/browser/web_contents_observer.h" | 25 #include "content/public/browser/web_contents_observer.h" |
25 #include "ui/base/animation/animation_delegate.h" | 26 #include "ui/base/animation/animation_delegate.h" |
26 #include "ui/base/animation/slide_animation.h" | 27 #include "ui/base/animation/slide_animation.h" |
27 #include "ui/base/ime/text_input_type.h" | 28 #include "ui/base/ime/text_input_type.h" |
28 #include "ui/gfx/compositor/layer.h" | 29 #include "ui/gfx/compositor/layer.h" |
29 #include "ui/gfx/interpolated_transform.h" | |
30 #include "ui/gfx/screen.h" | 30 #include "ui/gfx/screen.h" |
31 #include "ui/views/ime/text_input_type_tracker.h" | 31 #include "ui/views/ime/text_input_type_tracker.h" |
32 #include "ui/views/widget/widget.h" | 32 #include "ui/views/widget/widget.h" |
33 | 33 |
34 #if defined(OS_CHROMEOS) | 34 #if defined(OS_CHROMEOS) |
35 #include "chrome/browser/chromeos/input_method/input_method_manager.h" | 35 #include "chrome/browser/chromeos/input_method/input_method_manager.h" |
36 #include "chrome/browser/chromeos/input_method/virtual_keyboard_selector.h" | 36 #include "chrome/browser/chromeos/input_method/virtual_keyboard_selector.h" |
37 #endif | 37 #endif |
38 | 38 |
39 #if defined(USE_AURA) | 39 #if defined(USE_AURA) |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 void Hide() OVERRIDE; | 93 void Hide() OVERRIDE; |
94 | 94 |
95 private: | 95 private: |
96 // Sets the target widget, adds/removes Widget::Observer, reparents etc. | 96 // Sets the target widget, adds/removes Widget::Observer, reparents etc. |
97 void SetTarget(Widget* target); | 97 void SetTarget(Widget* target); |
98 | 98 |
99 // Returns the widget of the active browser, or NULL if there is no such | 99 // Returns the widget of the active browser, or NULL if there is no such |
100 // widget. | 100 // widget. |
101 views::Widget* GetBrowserWidget(); | 101 views::Widget* GetBrowserWidget(); |
102 | 102 |
103 // Update layer opacity and transform with values in animation_. | 103 // Update layer opacity and bounds with values in animation_. |
104 void UpdateForAnimation(); | 104 void UpdateForAnimation(); |
105 | 105 |
106 // Overridden from views::Widget. | 106 // Overridden from views::Widget. |
107 virtual bool OnKeyEvent(const views::KeyEvent& event) OVERRIDE; | 107 virtual bool OnKeyEvent(const views::KeyEvent& event) OVERRIDE; |
108 | 108 |
109 // Overridden from ui::AnimationDelegate. | 109 // Overridden from ui::AnimationDelegate. |
110 virtual void AnimationProgressed(const ui::Animation* animation) OVERRIDE; | 110 virtual void AnimationProgressed(const ui::Animation* animation) OVERRIDE; |
111 virtual void AnimationEnded(const ui::Animation* animation) OVERRIDE; | 111 virtual void AnimationEnded(const ui::Animation* animation) OVERRIDE; |
112 | 112 |
113 // Overridden from content::WebContentsObserver. | 113 // Overridden from content::WebContentsObserver. |
(...skipping 28 matching lines...) Expand all Loading... |
142 const content::NotificationDetails& details) OVERRIDE; | 142 const content::NotificationDetails& details) OVERRIDE; |
143 | 143 |
144 // Overridden from views::Widget::Observer. | 144 // Overridden from views::Widget::Observer. |
145 virtual void OnWidgetClosing(Widget* widget) OVERRIDE; | 145 virtual void OnWidgetClosing(Widget* widget) OVERRIDE; |
146 virtual void OnWidgetVisibilityChanged(Widget* widget, bool visible) OVERRIDE; | 146 virtual void OnWidgetVisibilityChanged(Widget* widget, bool visible) OVERRIDE; |
147 virtual void OnWidgetActivationChanged(Widget* widget, bool active) OVERRIDE; | 147 virtual void OnWidgetActivationChanged(Widget* widget, bool active) OVERRIDE; |
148 | 148 |
149 // The animation. | 149 // The animation. |
150 scoped_ptr<ui::SlideAnimation> animation_; | 150 scoped_ptr<ui::SlideAnimation> animation_; |
151 | 151 |
152 // Interpolated transform used during animation. | |
153 scoped_ptr<ui::InterpolatedTransform> transform_; | |
154 | |
155 GURL keyboard_url_; | 152 GURL keyboard_url_; |
156 | 153 |
157 // The DOM view to host the keyboard. | 154 // The DOM view to host the keyboard. |
158 DOMView* dom_view_; | 155 DOMView* dom_view_; |
159 | 156 |
160 ExtensionFunctionDispatcher extension_dispatcher_; | 157 ExtensionFunctionDispatcher extension_dispatcher_; |
161 | 158 |
162 // The widget the events from the keyboard should be directed to. | 159 // The widget the events from the keyboard should be directed to. |
163 views::Widget* target_; | 160 views::Widget* target_; |
164 | 161 |
(...skipping 21 matching lines...) Expand all Loading... |
186 params.bounds = GetKeyboardPosition(keyboard_height_); | 183 params.bounds = GetKeyboardPosition(keyboard_height_); |
187 Init(params); | 184 Init(params); |
188 #if defined(USE_AURA) | 185 #if defined(USE_AURA) |
189 ash::Shell::GetInstance()->GetContainer( | 186 ash::Shell::GetInstance()->GetContainer( |
190 ash::internal::kShellWindowId_MenuAndTooltipContainer)-> | 187 ash::internal::kShellWindowId_MenuAndTooltipContainer)-> |
191 AddChild(GetNativeView()); | 188 AddChild(GetNativeView()); |
192 #endif | 189 #endif |
193 | 190 |
194 // Setup the DOM view to host the keyboard. | 191 // Setup the DOM view to host the keyboard. |
195 Profile* profile = ProfileManager::GetDefaultProfile(); | 192 Profile* profile = ProfileManager::GetDefaultProfile(); |
196 dom_view_->Init(profile, SiteInstance::CreateForURL(profile, keyboard_url_)); | 193 dom_view_->Init(profile, |
| 194 content::SiteInstance::CreateForURL(profile, keyboard_url_)); |
197 dom_view_->LoadURL(keyboard_url_); | 195 dom_view_->LoadURL(keyboard_url_); |
198 dom_view_->SetVisible(true); | 196 dom_view_->SetVisible(true); |
199 SetContentsView(dom_view_); | 197 SetContentsView(dom_view_); |
200 | 198 |
201 // Setup observer so the events from the keyboard can be handled. | 199 // Setup observer so the events from the keyboard can be handled. |
202 content::WebContentsObserver::Observe( | 200 content::WebContentsObserver::Observe( |
203 dom_view_->dom_contents()->web_contents()); | 201 dom_view_->dom_contents()->web_contents()); |
204 | 202 |
205 // Initialize the animation. | 203 // Initialize the animation. |
206 animation_.reset(new ui::SlideAnimation(this)); | 204 animation_.reset(new ui::SlideAnimation(this)); |
(...skipping 14 matching lines...) Expand all Loading... |
221 content::NOTIFICATION_APP_TERMINATING, | 219 content::NOTIFICATION_APP_TERMINATING, |
222 content::NotificationService::AllSources()); | 220 content::NotificationService::AllSources()); |
223 | 221 |
224 #if defined(OS_CHROMEOS) | 222 #if defined(OS_CHROMEOS) |
225 chromeos::input_method::InputMethodManager* manager = | 223 chromeos::input_method::InputMethodManager* manager = |
226 chromeos::input_method::InputMethodManager::GetInstance(); | 224 chromeos::input_method::InputMethodManager::GetInstance(); |
227 manager->AddVirtualKeyboardObserver(this); | 225 manager->AddVirtualKeyboardObserver(this); |
228 #endif | 226 #endif |
229 | 227 |
230 #if defined(USE_AURA) | 228 #if defined(USE_AURA) |
231 aura::RootWindow::GetInstance()->AddObserver(this); | 229 aura::RootWindow::GetInstance()->AddRootWindowObserver(this); |
232 #endif | 230 #endif |
233 } | 231 } |
234 | 232 |
235 KeyboardWidget::~KeyboardWidget() { | 233 KeyboardWidget::~KeyboardWidget() { |
236 if (target_) | 234 if (target_) |
237 target_->RemoveObserver(this); | 235 target_->RemoveObserver(this); |
238 views::TextInputTypeTracker::GetInstance()->RemoveTextInputTypeObserver(this); | 236 views::TextInputTypeTracker::GetInstance()->RemoveTextInputTypeObserver(this); |
239 #if defined(OS_CHROMEOS) | 237 #if defined(OS_CHROMEOS) |
240 chromeos::input_method::InputMethodManager* manager = | 238 chromeos::input_method::InputMethodManager* manager = |
241 chromeos::input_method::InputMethodManager::GetInstance(); | 239 chromeos::input_method::InputMethodManager::GetInstance(); |
242 manager->RemoveVirtualKeyboardObserver(this); | 240 manager->RemoveVirtualKeyboardObserver(this); |
243 #endif | 241 #endif |
244 | 242 |
245 #if defined(USE_AURA) | 243 #if defined(USE_AURA) |
246 aura::RootWindow::GetInstance()->RemoveObserver(this); | 244 aura::RootWindow::GetInstance()->RemoveRootWindowObserver(this); |
247 #endif | 245 #endif |
248 // TODO(sad): Do anything else? | 246 // TODO(sad): Do anything else? |
249 } | 247 } |
250 | 248 |
251 void KeyboardWidget::ShowKeyboardForWidget(views::Widget* widget) { | 249 void KeyboardWidget::ShowKeyboardForWidget(views::Widget* widget) { |
252 if (target_ == widget && IsVisible() && !animation_->is_animating()) | 250 if (target_ == widget && IsVisible() && !animation_->is_animating()) |
253 return; | 251 return; |
254 SetTarget(widget); | 252 SetTarget(widget); |
255 | 253 |
256 transform_.reset(new ui::InterpolatedTranslation( | |
257 gfx::Point(0, keyboard_height_), gfx::Point())); | |
258 | |
259 UpdateForAnimation(); | 254 UpdateForAnimation(); |
260 animation_->Show(); | 255 animation_->Show(); |
261 | 256 |
262 Show(); | 257 Show(); |
263 | 258 |
264 bool visible = true; | 259 bool visible = true; |
265 content::NotificationService::current()->Notify( | 260 content::NotificationService::current()->Notify( |
266 chrome::NOTIFICATION_KEYBOARD_VISIBILITY_CHANGED, | 261 chrome::NOTIFICATION_KEYBOARD_VISIBILITY_CHANGED, |
267 content::Source<KeyboardWidget>(this), | 262 content::Source<KeyboardWidget>(this), |
268 content::Details<bool>(&visible)); | 263 content::Details<bool>(&visible)); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 return NULL; | 300 return NULL; |
306 return view->GetWidget(); | 301 return view->GetWidget(); |
307 } | 302 } |
308 | 303 |
309 bool KeyboardWidget::OnKeyEvent(const views::KeyEvent& event) { | 304 bool KeyboardWidget::OnKeyEvent(const views::KeyEvent& event) { |
310 return target_ ? target_->OnKeyEvent(event) : false; | 305 return target_ ? target_->OnKeyEvent(event) : false; |
311 } | 306 } |
312 | 307 |
313 void KeyboardWidget::UpdateForAnimation() { | 308 void KeyboardWidget::UpdateForAnimation() { |
314 float t = static_cast<float>(animation_->GetCurrentValue()); | 309 float t = static_cast<float>(animation_->GetCurrentValue()); |
315 GetRootView()->SetTransform(transform_->Interpolate(t)); | 310 gfx::Rect bounds = GetKeyboardPosition(keyboard_height_); |
| 311 bounds.Offset(0, keyboard_height_*(1 - t)); |
| 312 SetBounds(bounds); |
316 if (GetRootView()->layer()) | 313 if (GetRootView()->layer()) |
317 GetRootView()->layer()->SetOpacity(t * t); | 314 GetRootView()->layer()->SetOpacity(t * t); |
318 } | 315 } |
319 | 316 |
320 void KeyboardWidget::AnimationProgressed(const ui::Animation* animation) { | 317 void KeyboardWidget::AnimationProgressed(const ui::Animation* animation) { |
321 UpdateForAnimation(); | 318 UpdateForAnimation(); |
322 } | 319 } |
323 | 320 |
324 void KeyboardWidget::AnimationEnded(const ui::Animation* animation) { | 321 void KeyboardWidget::AnimationEnded(const ui::Animation* animation) { |
325 gfx::Rect keyboard_rect; | 322 gfx::Rect keyboard_rect; |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
533 | 530 |
534 void VirtualKeyboardManager::OnWidgetClosing(views::Widget* widget) { | 531 void VirtualKeyboardManager::OnWidgetClosing(views::Widget* widget) { |
535 DCHECK_EQ(keyboard_, widget); | 532 DCHECK_EQ(keyboard_, widget); |
536 keyboard_ = NULL; | 533 keyboard_ = NULL; |
537 } | 534 } |
538 | 535 |
539 // static | 536 // static |
540 VirtualKeyboardManager* VirtualKeyboardManager::GetInstance() { | 537 VirtualKeyboardManager* VirtualKeyboardManager::GetInstance() { |
541 return Singleton<VirtualKeyboardManager>::get(); | 538 return Singleton<VirtualKeyboardManager>::get(); |
542 } | 539 } |
OLD | NEW |