| 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" |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 virtual void OnWidgetClosing(Widget* widget) OVERRIDE; | 147 virtual void OnWidgetClosing(Widget* widget) OVERRIDE; |
| 148 virtual void OnWidgetVisibilityChanged(Widget* widget, bool visible) OVERRIDE; | 148 virtual void OnWidgetVisibilityChanged(Widget* widget, bool visible) OVERRIDE; |
| 149 virtual void OnWidgetActivationChanged(Widget* widget, bool active) OVERRIDE; | 149 virtual void OnWidgetActivationChanged(Widget* widget, bool active) OVERRIDE; |
| 150 | 150 |
| 151 // The animation. | 151 // The animation. |
| 152 scoped_ptr<ui::SlideAnimation> animation_; | 152 scoped_ptr<ui::SlideAnimation> animation_; |
| 153 | 153 |
| 154 GURL keyboard_url_; | 154 GURL keyboard_url_; |
| 155 | 155 |
| 156 // The WebView to host the keyboard. | 156 // The WebView to host the keyboard. |
| 157 views::WebView* webview_; | 157 views::WebView* web_view_; |
| 158 | 158 |
| 159 ExtensionFunctionDispatcher extension_dispatcher_; | 159 ExtensionFunctionDispatcher extension_dispatcher_; |
| 160 | 160 |
| 161 // The widget the events from the keyboard should be directed to. | 161 // The widget the events from the keyboard should be directed to. |
| 162 views::Widget* target_; | 162 views::Widget* target_; |
| 163 | 163 |
| 164 // Height of the keyboard. | 164 // Height of the keyboard. |
| 165 int keyboard_height_; | 165 int keyboard_height_; |
| 166 | 166 |
| 167 content::NotificationRegistrar registrar_; | 167 content::NotificationRegistrar registrar_; |
| 168 | 168 |
| 169 DISALLOW_COPY_AND_ASSIGN(KeyboardWidget); | 169 DISALLOW_COPY_AND_ASSIGN(KeyboardWidget); |
| 170 }; | 170 }; |
| 171 | 171 |
| 172 KeyboardWidget::KeyboardWidget() | 172 KeyboardWidget::KeyboardWidget() |
| 173 : views::Widget::Widget(), | 173 : views::Widget::Widget(), |
| 174 keyboard_url_(chrome::kChromeUIKeyboardURL), | 174 keyboard_url_(chrome::kChromeUIKeyboardURL), |
| 175 webview_(new DOMView(ProfileManager::GetDefaultProfile()))), | 175 web_view_(new views::WebView(ProfileManager::GetDefaultProfile()))), |
| 176 ALLOW_THIS_IN_INITIALIZER_LIST( | 176 ALLOW_THIS_IN_INITIALIZER_LIST( |
| 177 extension_dispatcher_(ProfileManager::GetDefaultProfile(), this)), | 177 extension_dispatcher_(ProfileManager::GetDefaultProfile(), this)), |
| 178 target_(NULL), | 178 target_(NULL), |
| 179 keyboard_height_(kDefaultKeyboardHeight) { | 179 keyboard_height_(kDefaultKeyboardHeight) { |
| 180 | 180 |
| 181 // Initialize the widget first. | 181 // Initialize the widget first. |
| 182 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); | 182 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); |
| 183 params.keep_on_top = true; | 183 params.keep_on_top = true; |
| 184 params.transparent = true; | 184 params.transparent = true; |
| 185 params.bounds = GetKeyboardPosition(keyboard_height_); | 185 params.bounds = GetKeyboardPosition(keyboard_height_); |
| 186 #if defined(USE_AURA) | 186 #if defined(USE_AURA) |
| 187 params.parent = ash::Shell::GetInstance()->GetContainer( | 187 params.parent = ash::Shell::GetInstance()->GetContainer( |
| 188 ash::internal::kShellWindowId_MenuContainer); | 188 ash::internal::kShellWindowId_MenuContainer); |
| 189 #endif | 189 #endif |
| 190 Init(params); | 190 Init(params); |
| 191 | 191 |
| 192 // Setup the DOM view to host the keyboard. | 192 // Setup the DOM view to host the keyboard. |
| 193 webview_->CreateWebContentsWithSiteInstance( | 193 web_view_->CreateWebContentsWithSiteInstance( |
| 194 content::SiteInstance::CreateForURL(webview_->browser_context(), | 194 content::SiteInstance::CreateForURL(web_view_->browser_context(), |
| 195 keyboard_url_)); | 195 keyboard_url_)); |
| 196 webview_->LoadInitialURL(keyboard_url_); | 196 web_view_->LoadInitialURL(keyboard_url_); |
| 197 SetContentsView(webview_); | 197 SetContentsView(web_view_); |
| 198 | 198 |
| 199 // Setup observer so the events from the keyboard can be handled. | 199 // Setup observer so the events from the keyboard can be handled. |
| 200 content::WebContentsObserver::Observe(webview_->web_contents()); | 200 content::WebContentsObserver::Observe(web_view_->web_contents()); |
| 201 | 201 |
| 202 // Initialize the animation. | 202 // Initialize the animation. |
| 203 animation_.reset(new ui::SlideAnimation(this)); | 203 animation_.reset(new ui::SlideAnimation(this)); |
| 204 animation_->SetTweenType(ui::Tween::LINEAR); | 204 animation_->SetTweenType(ui::Tween::LINEAR); |
| 205 animation_->SetSlideDuration(kKeyboardSlideDuration); | 205 animation_->SetSlideDuration(kKeyboardSlideDuration); |
| 206 | 206 |
| 207 views::TextInputTypeTracker::GetInstance()->AddTextInputTypeObserver(this); | 207 views::TextInputTypeTracker::GetInstance()->AddTextInputTypeObserver(this); |
| 208 registrar_.Add(this, | 208 registrar_.Add(this, |
| 209 chrome::NOTIFICATION_FOCUSED_EDITABLE_NODE_TOUCHED, | 209 chrome::NOTIFICATION_FOCUSED_EDITABLE_NODE_TOUCHED, |
| 210 content::NotificationService::AllSources()); | 210 content::NotificationService::AllSources()); |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 IPC_BEGIN_MESSAGE_MAP(KeyboardWidget, message) | 335 IPC_BEGIN_MESSAGE_MAP(KeyboardWidget, message) |
| 336 IPC_MESSAGE_HANDLER(ExtensionHostMsg_Request, OnRequest) | 336 IPC_MESSAGE_HANDLER(ExtensionHostMsg_Request, OnRequest) |
| 337 IPC_MESSAGE_UNHANDLED(handled = false) | 337 IPC_MESSAGE_UNHANDLED(handled = false) |
| 338 IPC_END_MESSAGE_MAP() | 338 IPC_END_MESSAGE_MAP() |
| 339 return handled; | 339 return handled; |
| 340 } | 340 } |
| 341 | 341 |
| 342 void KeyboardWidget::RenderViewGone(base::TerminationStatus status) { | 342 void KeyboardWidget::RenderViewGone(base::TerminationStatus status) { |
| 343 if (status != base::TERMINATION_STATUS_NORMAL_TERMINATION) { | 343 if (status != base::TERMINATION_STATUS_NORMAL_TERMINATION) { |
| 344 // Reload the keyboard if it crashes. | 344 // Reload the keyboard if it crashes. |
| 345 webview_->LoadInitialURL(keyboard_url_); | 345 web_view_->LoadInitialURL(keyboard_url_); |
| 346 webview_->SchedulePaint(); | 346 web_view_->SchedulePaint(); |
| 347 } | 347 } |
| 348 } | 348 } |
| 349 | 349 |
| 350 void KeyboardWidget::OnRequest(const ExtensionHostMsg_Request_Params& request) { | 350 void KeyboardWidget::OnRequest(const ExtensionHostMsg_Request_Params& request) { |
| 351 extension_dispatcher_.Dispatch(request, | 351 extension_dispatcher_.Dispatch( |
| 352 webview_->web_contents()->GetRenderViewHost()); | 352 request, |
| 353 web_view_->web_contents()->GetRenderViewHost()); |
| 353 } | 354 } |
| 354 | 355 |
| 355 void KeyboardWidget::TextInputTypeChanged(ui::TextInputType type, | 356 void KeyboardWidget::TextInputTypeChanged(ui::TextInputType type, |
| 356 views::Widget *widget) { | 357 views::Widget *widget) { |
| 357 // Send onTextInputTypeChanged event to keyboard extension. | 358 // Send onTextInputTypeChanged event to keyboard extension. |
| 358 ListValue args; | 359 ListValue args; |
| 359 switch (type) { | 360 switch (type) { |
| 360 case ui::TEXT_INPUT_TYPE_NONE: { | 361 case ui::TEXT_INPUT_TYPE_NONE: { |
| 361 args.Append(Value::CreateStringValue("none")); | 362 args.Append(Value::CreateStringValue("none")); |
| 362 break; | 363 break; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 392 default: { | 393 default: { |
| 393 NOTREACHED(); | 394 NOTREACHED(); |
| 394 args.Append(Value::CreateStringValue("none")); | 395 args.Append(Value::CreateStringValue("none")); |
| 395 break; | 396 break; |
| 396 } | 397 } |
| 397 } | 398 } |
| 398 | 399 |
| 399 std::string json_args; | 400 std::string json_args; |
| 400 base::JSONWriter::Write(&args, &json_args); | 401 base::JSONWriter::Write(&args, &json_args); |
| 401 | 402 |
| 402 Profile* profile = Profile::FromBrowserContext(webview_->browser_context()); | 403 Profile* profile = Profile::FromBrowserContext(web_view_->browser_context()); |
| 403 profile->GetExtensionEventRouter()->DispatchEventToRenderers( | 404 profile->GetExtensionEventRouter()->DispatchEventToRenderers( |
| 404 kOnTextInputTypeChanged, json_args, NULL, GURL()); | 405 kOnTextInputTypeChanged, json_args, NULL, GURL()); |
| 405 | 406 |
| 406 if (type == ui::TEXT_INPUT_TYPE_NONE) | 407 if (type == ui::TEXT_INPUT_TYPE_NONE) |
| 407 Hide(); | 408 Hide(); |
| 408 else | 409 else |
| 409 ShowKeyboardForWidget(widget); | 410 ShowKeyboardForWidget(widget); |
| 410 } | 411 } |
| 411 | 412 |
| 412 Browser* KeyboardWidget::GetBrowser() { | 413 Browser* KeyboardWidget::GetBrowser() { |
| 413 // TODO(sad): Find a better way. Perhaps just return NULL, and fix | 414 // TODO(sad): Find a better way. Perhaps just return NULL, and fix |
| 414 // SendKeyboardEventInputFunction::GetTopLevelWidget to somehow interact with | 415 // SendKeyboardEventInputFunction::GetTopLevelWidget to somehow interact with |
| 415 // the WM to find the top level widget? | 416 // the WM to find the top level widget? |
| 416 return BrowserList::GetLastActive(); | 417 return BrowserList::GetLastActive(); |
| 417 } | 418 } |
| 418 | 419 |
| 419 content::WebContents* KeyboardWidget::GetAssociatedWebContents() const { | 420 content::WebContents* KeyboardWidget::GetAssociatedWebContents() const { |
| 420 return webview_->web_contents(); | 421 return web_view_->web_contents(); |
| 421 } | 422 } |
| 422 | 423 |
| 423 #if defined(OS_CHROMEOS) | 424 #if defined(OS_CHROMEOS) |
| 424 void KeyboardWidget::VirtualKeyboardChanged( | 425 void KeyboardWidget::VirtualKeyboardChanged( |
| 425 chromeos::input_method::InputMethodManager* manager, | 426 chromeos::input_method::InputMethodManager* manager, |
| 426 const chromeos::input_method::VirtualKeyboard& virtual_keyboard, | 427 const chromeos::input_method::VirtualKeyboard& virtual_keyboard, |
| 427 const std::string& virtual_keyboard_layout) { | 428 const std::string& virtual_keyboard_layout) { |
| 428 const GURL& url = virtual_keyboard.GetURLForLayout(virtual_keyboard_layout); | 429 const GURL& url = virtual_keyboard.GetURLForLayout(virtual_keyboard_layout); |
| 429 webview_->LoadInitialURL(url); | 430 web_view_->LoadInitialURL(url); |
| 430 VLOG(1) << "VirtualKeyboardChanged: Switched to " << url.spec(); | 431 VLOG(1) << "VirtualKeyboardChanged: Switched to " << url.spec(); |
| 431 } | 432 } |
| 432 #endif | 433 #endif |
| 433 | 434 |
| 434 #if defined(USE_AURA) | 435 #if defined(USE_AURA) |
| 435 void KeyboardWidget::OnRootWindowResized(const aura::RootWindow* root, | 436 void KeyboardWidget::OnRootWindowResized(const aura::RootWindow* root, |
| 436 const gfx::Size& old_size) { | 437 const gfx::Size& old_size) { |
| 437 ResetBounds(); | 438 ResetBounds(); |
| 438 } | 439 } |
| 439 #endif | 440 #endif |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 527 | 528 |
| 528 void VirtualKeyboardManager::OnWidgetClosing(views::Widget* widget) { | 529 void VirtualKeyboardManager::OnWidgetClosing(views::Widget* widget) { |
| 529 DCHECK_EQ(keyboard_, widget); | 530 DCHECK_EQ(keyboard_, widget); |
| 530 keyboard_ = NULL; | 531 keyboard_ = NULL; |
| 531 } | 532 } |
| 532 | 533 |
| 533 // static | 534 // static |
| 534 VirtualKeyboardManager* VirtualKeyboardManager::GetInstance() { | 535 VirtualKeyboardManager* VirtualKeyboardManager::GetInstance() { |
| 535 return Singleton<VirtualKeyboardManager>::get(); | 536 return Singleton<VirtualKeyboardManager>::get(); |
| 536 } | 537 } |
| OLD | NEW |