| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/renderer_host/render_widget_host_view_mac.h" | 5 #include "chrome/browser/renderer_host/render_widget_host_view_mac.h" |
| 6 | 6 |
| 7 #include "base/histogram.h" | 7 #include "base/histogram.h" |
| 8 #import "base/scoped_nsobject.h" | 8 #import "base/scoped_nsobject.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/sys_string_conversions.h" | 10 #include "base/sys_string_conversions.h" |
| 11 #include "chrome/browser/browser_trial.h" | 11 #include "chrome/browser/browser_trial.h" |
| 12 #import "chrome/browser/cocoa/rwhvm_editcommand_helper.h" | 12 #import "chrome/browser/cocoa/rwhvm_editcommand_helper.h" |
| 13 #include "chrome/browser/plugin_process_host.h" |
| 13 #include "chrome/browser/renderer_host/backing_store.h" | 14 #include "chrome/browser/renderer_host/backing_store.h" |
| 14 #include "chrome/browser/renderer_host/render_process_host.h" | 15 #include "chrome/browser/renderer_host/render_process_host.h" |
| 15 #include "chrome/browser/renderer_host/render_widget_host.h" | 16 #include "chrome/browser/renderer_host/render_widget_host.h" |
| 16 #include "chrome/browser/spellchecker_platform_engine.h" | 17 #include "chrome/browser/spellchecker_platform_engine.h" |
| 17 #include "chrome/common/native_web_keyboard_event.h" | 18 #include "chrome/common/native_web_keyboard_event.h" |
| 18 #include "chrome/common/edit_command.h" | 19 #include "chrome/common/edit_command.h" |
| 20 #include "chrome/common/plugin_messages.h" |
| 19 #include "chrome/common/render_messages.h" | 21 #include "chrome/common/render_messages.h" |
| 20 #include "skia/ext/platform_canvas.h" | 22 #include "skia/ext/platform_canvas.h" |
| 21 #include "third_party/WebKit/WebKit/chromium/public/mac/WebInputEventFactory.h" | 23 #include "third_party/WebKit/WebKit/chromium/public/mac/WebInputEventFactory.h" |
| 22 #include "third_party/WebKit/WebKit/chromium/public/WebInputEvent.h" | 24 #include "third_party/WebKit/WebKit/chromium/public/WebInputEvent.h" |
| 23 #include "webkit/glue/webmenurunner_mac.h" | 25 #include "webkit/glue/webmenurunner_mac.h" |
| 24 | 26 |
| 25 using WebKit::WebInputEvent; | 27 using WebKit::WebInputEvent; |
| 26 using WebKit::WebInputEventFactory; | 28 using WebKit::WebInputEventFactory; |
| 27 using WebKit::WebMouseEvent; | 29 using WebKit::WebMouseEvent; |
| 28 using WebKit::WebMouseWheelEvent; | 30 using WebKit::WebMouseWheelEvent; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 41 - (id)initWithRenderWidgetHostViewMac:(RenderWidgetHostViewMac*)r; | 43 - (id)initWithRenderWidgetHostViewMac:(RenderWidgetHostViewMac*)r; |
| 42 - (void)keyEvent:(NSEvent *)theEvent wasKeyEquivalent:(BOOL)equiv; | 44 - (void)keyEvent:(NSEvent *)theEvent wasKeyEquivalent:(BOOL)equiv; |
| 43 - (void)cancelChildPopups; | 45 - (void)cancelChildPopups; |
| 44 @end | 46 @end |
| 45 | 47 |
| 46 namespace { | 48 namespace { |
| 47 | 49 |
| 48 // Maximum number of characters we allow in a tooltip. | 50 // Maximum number of characters we allow in a tooltip. |
| 49 const size_t kMaxTooltipLength = 1024; | 51 const size_t kMaxTooltipLength = 1024; |
| 50 | 52 |
| 53 class NotifyPluginProcessHostTask : public Task { |
| 54 public: |
| 55 NotifyPluginProcessHostTask(uint32 process_id, uint32 instance_id) |
| 56 : process_id_(process_id), instance_id_(instance_id) { } |
| 57 |
| 58 private: |
| 59 void Run() { |
| 60 for (ChildProcessHost::Iterator iter(ChildProcessInfo::PLUGIN_PROCESS); |
| 61 !iter.Done(); ++iter) { |
| 62 PluginProcessHost* plugin = static_cast<PluginProcessHost*>(*iter); |
| 63 uint32 plugin_pid = plugin->handle(); |
| 64 uint32 instance = (plugin_pid == process_id_) ? instance_id_ : 0; |
| 65 plugin->Send(new PluginProcessMsg_PluginFocusNotify(instance)); |
| 66 } |
| 67 } |
| 68 |
| 69 uint32 process_id_; |
| 70 uint32 instance_id_; |
| 71 }; |
| 72 |
| 51 } | 73 } |
| 52 | 74 |
| 53 // RenderWidgetHostView -------------------------------------------------------- | 75 // RenderWidgetHostView -------------------------------------------------------- |
| 54 | 76 |
| 55 // static | 77 // static |
| 56 RenderWidgetHostView* RenderWidgetHostView::CreateViewForWidget( | 78 RenderWidgetHostView* RenderWidgetHostView::CreateViewForWidget( |
| 57 RenderWidgetHost* widget) { | 79 RenderWidgetHost* widget) { |
| 58 return new RenderWidgetHostViewMac(widget); | 80 return new RenderWidgetHostViewMac(widget); |
| 59 } | 81 } |
| 60 | 82 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 | 149 |
| 128 void RenderWidgetHostViewMac::WasHidden() { | 150 void RenderWidgetHostViewMac::WasHidden() { |
| 129 if (is_hidden_) | 151 if (is_hidden_) |
| 130 return; | 152 return; |
| 131 | 153 |
| 132 // If we receive any more paint messages while we are hidden, we want to | 154 // If we receive any more paint messages while we are hidden, we want to |
| 133 // ignore them so we don't re-allocate the backing store. We will paint | 155 // ignore them so we don't re-allocate the backing store. We will paint |
| 134 // everything again when we become selected again. | 156 // everything again when we become selected again. |
| 135 is_hidden_ = true; | 157 is_hidden_ = true; |
| 136 | 158 |
| 159 // tell any plugins that thought they had the focus that they do not now. |
| 160 ChromeThread::PostTask(ChromeThread::IO, FROM_HERE, |
| 161 new NotifyPluginProcessHostTask(0, 0)); |
| 162 |
| 137 // If we have a renderer, then inform it that we are being hidden so it can | 163 // If we have a renderer, then inform it that we are being hidden so it can |
| 138 // reduce its resource utilization. | 164 // reduce its resource utilization. |
| 139 render_widget_host_->WasHidden(); | 165 render_widget_host_->WasHidden(); |
| 140 } | 166 } |
| 141 | 167 |
| 142 void RenderWidgetHostViewMac::SetSize(const gfx::Size& size) { | 168 void RenderWidgetHostViewMac::SetSize(const gfx::Size& size) { |
| 143 if (is_hidden_) | 169 if (is_hidden_) |
| 144 return; | 170 return; |
| 145 | 171 |
| 146 // TODO(avi): the TabContents object uses this method to size the newly | 172 // TODO(avi): the TabContents object uses this method to size the newly |
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 446 return gfx::Rect(); | 472 return gfx::Rect(); |
| 447 } | 473 } |
| 448 | 474 |
| 449 NSRect bounds = [[cocoa_view_ window] frame]; | 475 NSRect bounds = [[cocoa_view_ window] frame]; |
| 450 return NSRectToRect(bounds, [[cocoa_view_ window] screen]); | 476 return NSRectToRect(bounds, [[cocoa_view_ window] screen]); |
| 451 } | 477 } |
| 452 | 478 |
| 453 void RenderWidgetHostViewMac::SetActive(bool active) { | 479 void RenderWidgetHostViewMac::SetActive(bool active) { |
| 454 if (render_widget_host_) | 480 if (render_widget_host_) |
| 455 render_widget_host_->SetActive(active); | 481 render_widget_host_->SetActive(active); |
| 482 if (!active) |
| 483 // tell any plugins that thought they had the focus that they do not now. |
| 484 ChromeThread::PostTask(ChromeThread::IO, FROM_HERE, |
| 485 new NotifyPluginProcessHostTask(0, 0)); |
| 456 } | 486 } |
| 457 | 487 |
| 458 void RenderWidgetHostViewMac::SetBackground(const SkBitmap& background) { | 488 void RenderWidgetHostViewMac::SetBackground(const SkBitmap& background) { |
| 459 RenderWidgetHostView::SetBackground(background); | 489 RenderWidgetHostView::SetBackground(background); |
| 460 if (render_widget_host_) | 490 if (render_widget_host_) |
| 461 render_widget_host_->Send(new ViewMsg_SetBackground( | 491 render_widget_host_->Send(new ViewMsg_SetBackground( |
| 462 render_widget_host_->routing_id(), background)); | 492 render_widget_host_->routing_id(), background)); |
| 463 } | 493 } |
| 464 | 494 |
| 465 // EditCommandMatcher --------------------------------------------------------- | 495 // EditCommandMatcher --------------------------------------------------------- |
| (...skipping 882 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1348 base::Time::Now().ToDoubleT()); | 1378 base::Time::Now().ToDoubleT()); |
| 1349 renderWidgetHostView_->render_widget_host_->ForwardKeyboardEvent(event); | 1379 renderWidgetHostView_->render_widget_host_->ForwardKeyboardEvent(event); |
| 1350 } else { | 1380 } else { |
| 1351 renderWidgetHostView_->render_widget_host_->ImeConfirmComposition( | 1381 renderWidgetHostView_->render_widget_host_->ImeConfirmComposition( |
| 1352 UTF8ToUTF16([im_text UTF8String])); | 1382 UTF8ToUTF16([im_text UTF8String])); |
| 1353 } | 1383 } |
| 1354 renderWidgetHostView_->im_composing_ = false; | 1384 renderWidgetHostView_->im_composing_ = false; |
| 1355 } | 1385 } |
| 1356 | 1386 |
| 1357 @end | 1387 @end |
| OLD | NEW |