Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(153)

Side by Side Diff: chrome/browser/ui/virtual_keyboard/virtual_keyboard_manager.cc

Issue 10204002: Revert 133467 - Convert the last users of DOMView to WebView. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/views/keyboard_overlay_dialog_view.cc ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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* web_view_; 157 views::WebView* webview_;
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 web_view_(new views::WebView(ProfileManager::GetDefaultProfile()))), 175 webview_(new DOMView(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 web_view_->CreateWebContentsWithSiteInstance( 193 webview_->CreateWebContentsWithSiteInstance(
194 content::SiteInstance::CreateForURL(web_view_->browser_context(), 194 content::SiteInstance::CreateForURL(webview_->browser_context(),
195 keyboard_url_)); 195 keyboard_url_));
196 web_view_->LoadInitialURL(keyboard_url_); 196 webview_->LoadInitialURL(keyboard_url_);
197 SetContentsView(web_view_); 197 SetContentsView(webview_);
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(web_view_->web_contents()); 200 content::WebContentsObserver::Observe(webview_->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
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 web_view_->LoadInitialURL(keyboard_url_); 345 webview_->LoadInitialURL(keyboard_url_);
346 web_view_->SchedulePaint(); 346 webview_->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( 351 extension_dispatcher_.Dispatch(request,
352 request, 352 webview_->web_contents()->GetRenderViewHost());
353 web_view_->web_contents()->GetRenderViewHost());
354 } 353 }
355 354
356 void KeyboardWidget::TextInputTypeChanged(ui::TextInputType type, 355 void KeyboardWidget::TextInputTypeChanged(ui::TextInputType type,
357 views::Widget *widget) { 356 views::Widget *widget) {
358 // Send onTextInputTypeChanged event to keyboard extension. 357 // Send onTextInputTypeChanged event to keyboard extension.
359 ListValue args; 358 ListValue args;
360 switch (type) { 359 switch (type) {
361 case ui::TEXT_INPUT_TYPE_NONE: { 360 case ui::TEXT_INPUT_TYPE_NONE: {
362 args.Append(Value::CreateStringValue("none")); 361 args.Append(Value::CreateStringValue("none"));
363 break; 362 break;
(...skipping 29 matching lines...) Expand all
393 default: { 392 default: {
394 NOTREACHED(); 393 NOTREACHED();
395 args.Append(Value::CreateStringValue("none")); 394 args.Append(Value::CreateStringValue("none"));
396 break; 395 break;
397 } 396 }
398 } 397 }
399 398
400 std::string json_args; 399 std::string json_args;
401 base::JSONWriter::Write(&args, &json_args); 400 base::JSONWriter::Write(&args, &json_args);
402 401
403 Profile* profile = Profile::FromBrowserContext(web_view_->browser_context()); 402 Profile* profile = Profile::FromBrowserContext(webview_->browser_context());
404 profile->GetExtensionEventRouter()->DispatchEventToRenderers( 403 profile->GetExtensionEventRouter()->DispatchEventToRenderers(
405 kOnTextInputTypeChanged, json_args, NULL, GURL()); 404 kOnTextInputTypeChanged, json_args, NULL, GURL());
406 405
407 if (type == ui::TEXT_INPUT_TYPE_NONE) 406 if (type == ui::TEXT_INPUT_TYPE_NONE)
408 Hide(); 407 Hide();
409 else 408 else
410 ShowKeyboardForWidget(widget); 409 ShowKeyboardForWidget(widget);
411 } 410 }
412 411
413 Browser* KeyboardWidget::GetBrowser() { 412 Browser* KeyboardWidget::GetBrowser() {
414 // TODO(sad): Find a better way. Perhaps just return NULL, and fix 413 // TODO(sad): Find a better way. Perhaps just return NULL, and fix
415 // SendKeyboardEventInputFunction::GetTopLevelWidget to somehow interact with 414 // SendKeyboardEventInputFunction::GetTopLevelWidget to somehow interact with
416 // the WM to find the top level widget? 415 // the WM to find the top level widget?
417 return BrowserList::GetLastActive(); 416 return BrowserList::GetLastActive();
418 } 417 }
419 418
420 content::WebContents* KeyboardWidget::GetAssociatedWebContents() const { 419 content::WebContents* KeyboardWidget::GetAssociatedWebContents() const {
421 return web_view_->web_contents(); 420 return webview_->web_contents();
422 } 421 }
423 422
424 #if defined(OS_CHROMEOS) 423 #if defined(OS_CHROMEOS)
425 void KeyboardWidget::VirtualKeyboardChanged( 424 void KeyboardWidget::VirtualKeyboardChanged(
426 chromeos::input_method::InputMethodManager* manager, 425 chromeos::input_method::InputMethodManager* manager,
427 const chromeos::input_method::VirtualKeyboard& virtual_keyboard, 426 const chromeos::input_method::VirtualKeyboard& virtual_keyboard,
428 const std::string& virtual_keyboard_layout) { 427 const std::string& virtual_keyboard_layout) {
429 const GURL& url = virtual_keyboard.GetURLForLayout(virtual_keyboard_layout); 428 const GURL& url = virtual_keyboard.GetURLForLayout(virtual_keyboard_layout);
430 web_view_->LoadInitialURL(url); 429 webview_->LoadInitialURL(url);
431 VLOG(1) << "VirtualKeyboardChanged: Switched to " << url.spec(); 430 VLOG(1) << "VirtualKeyboardChanged: Switched to " << url.spec();
432 } 431 }
433 #endif 432 #endif
434 433
435 #if defined(USE_AURA) 434 #if defined(USE_AURA)
436 void KeyboardWidget::OnRootWindowResized(const aura::RootWindow* root, 435 void KeyboardWidget::OnRootWindowResized(const aura::RootWindow* root,
437 const gfx::Size& old_size) { 436 const gfx::Size& old_size) {
438 ResetBounds(); 437 ResetBounds();
439 } 438 }
440 #endif 439 #endif
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
528 527
529 void VirtualKeyboardManager::OnWidgetClosing(views::Widget* widget) { 528 void VirtualKeyboardManager::OnWidgetClosing(views::Widget* widget) {
530 DCHECK_EQ(keyboard_, widget); 529 DCHECK_EQ(keyboard_, widget);
531 keyboard_ = NULL; 530 keyboard_ = NULL;
532 } 531 }
533 532
534 // static 533 // static
535 VirtualKeyboardManager* VirtualKeyboardManager::GetInstance() { 534 VirtualKeyboardManager* VirtualKeyboardManager::GetInstance() {
536 return Singleton<VirtualKeyboardManager>::get(); 535 return Singleton<VirtualKeyboardManager>::get();
537 } 536 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/keyboard_overlay_dialog_view.cc ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698