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 <QuartzCore/CAOpenGLLayer.h> |
| 6 |
5 #include "chrome/browser/renderer_host/render_widget_host_view_mac.h" | 7 #include "chrome/browser/renderer_host/render_widget_host_view_mac.h" |
6 | 8 |
7 #import "base/chrome_application_mac.h" | 9 #import "base/chrome_application_mac.h" |
8 #include "base/histogram.h" | 10 #include "base/histogram.h" |
9 #import "base/scoped_nsobject.h" | 11 #import "base/scoped_nsobject.h" |
10 #include "base/string_util.h" | 12 #include "base/string_util.h" |
11 #include "base/sys_string_conversions.h" | 13 #include "base/sys_string_conversions.h" |
12 #include "chrome/browser/browser_trial.h" | 14 #include "chrome/browser/browser_trial.h" |
13 #import "chrome/browser/cocoa/rwhvm_editcommand_helper.h" | 15 #import "chrome/browser/cocoa/rwhvm_editcommand_helper.h" |
14 #include "chrome/browser/plugin_process_host.h" | 16 #include "chrome/browser/plugin_process_host.h" |
15 #include "chrome/browser/renderer_host/backing_store_mac.h" | 17 #include "chrome/browser/renderer_host/backing_store_mac.h" |
16 #include "chrome/browser/renderer_host/render_process_host.h" | 18 #include "chrome/browser/renderer_host/render_process_host.h" |
17 #include "chrome/browser/renderer_host/render_widget_host.h" | 19 #include "chrome/browser/renderer_host/render_widget_host.h" |
18 #include "chrome/browser/spellchecker_platform_engine.h" | 20 #include "chrome/browser/spellchecker_platform_engine.h" |
19 #include "chrome/common/native_web_keyboard_event.h" | 21 #include "chrome/common/native_web_keyboard_event.h" |
20 #include "chrome/common/edit_command.h" | 22 #include "chrome/common/edit_command.h" |
21 #include "chrome/common/plugin_messages.h" | 23 #include "chrome/common/plugin_messages.h" |
22 #include "chrome/common/render_messages.h" | 24 #include "chrome/common/render_messages.h" |
| 25 #include "chrome/common/io_surface_support_mac.h" |
23 #include "skia/ext/platform_canvas.h" | 26 #include "skia/ext/platform_canvas.h" |
24 #include "third_party/WebKit/WebKit/chromium/public/mac/WebInputEventFactory.h" | 27 #include "third_party/WebKit/WebKit/chromium/public/mac/WebInputEventFactory.h" |
25 #include "third_party/WebKit/WebKit/chromium/public/WebInputEvent.h" | 28 #include "third_party/WebKit/WebKit/chromium/public/WebInputEvent.h" |
26 #include "webkit/glue/webmenurunner_mac.h" | 29 #include "webkit/glue/webmenurunner_mac.h" |
27 | 30 |
28 using WebKit::WebInputEvent; | 31 using WebKit::WebInputEvent; |
29 using WebKit::WebInputEventFactory; | 32 using WebKit::WebInputEventFactory; |
30 using WebKit::WebMouseEvent; | 33 using WebKit::WebMouseEvent; |
31 using WebKit::WebMouseWheelEvent; | 34 using WebKit::WebMouseWheelEvent; |
32 | 35 |
(...skipping 13 matching lines...) Expand all Loading... |
46 - (void)cancelChildPopups; | 49 - (void)cancelChildPopups; |
47 @end | 50 @end |
48 | 51 |
49 namespace { | 52 namespace { |
50 | 53 |
51 // Maximum number of characters we allow in a tooltip. | 54 // Maximum number of characters we allow in a tooltip. |
52 const size_t kMaxTooltipLength = 1024; | 55 const size_t kMaxTooltipLength = 1024; |
53 | 56 |
54 } | 57 } |
55 | 58 |
| 59 // GPUPluginLayer -------------------------------------------------------------- |
| 60 |
| 61 // This subclass of CAOpenGLLayer hosts the output of the GPU plugins |
| 62 // on the page. |
| 63 |
| 64 @interface GPUPluginLayer : CAOpenGLLayer { |
| 65 RenderWidgetHostViewMac* renderWidgetHostView_; // weak |
| 66 } |
| 67 |
| 68 - (id)initWithRenderWidgetHostViewMac:(RenderWidgetHostViewMac*)r; |
| 69 @end |
| 70 |
| 71 @implementation GPUPluginLayer |
| 72 - (id)initWithRenderWidgetHostViewMac:(RenderWidgetHostViewMac*)r { |
| 73 self = [super init]; |
| 74 if (self != nil) { |
| 75 renderWidgetHostView_ = r; |
| 76 } |
| 77 return self; |
| 78 } |
| 79 |
| 80 -(void)drawInCGLContext:(CGLContextObj)glContext |
| 81 pixelFormat:(CGLPixelFormatObj)pixelFormat |
| 82 forLayerTime:(CFTimeInterval)timeInterval |
| 83 displayTime:(const CVTimeStamp *)timeStamp { |
| 84 renderWidgetHostView_->DrawGPUPluginInstances(glContext); |
| 85 } |
| 86 @end |
| 87 |
56 // RenderWidgetHostView -------------------------------------------------------- | 88 // RenderWidgetHostView -------------------------------------------------------- |
57 | 89 |
58 // static | 90 // static |
59 RenderWidgetHostView* RenderWidgetHostView::CreateViewForWidget( | 91 RenderWidgetHostView* RenderWidgetHostView::CreateViewForWidget( |
60 RenderWidgetHost* widget) { | 92 RenderWidgetHost* widget) { |
61 return new RenderWidgetHostViewMac(widget); | 93 return new RenderWidgetHostViewMac(widget); |
62 } | 94 } |
63 | 95 |
64 /////////////////////////////////////////////////////////////////////////////// | 96 /////////////////////////////////////////////////////////////////////////////// |
65 // RenderWidgetHostViewMac, public: | 97 // RenderWidgetHostViewMac, public: |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 rect.set_height(size.height()); | 199 rect.set_height(size.height()); |
168 [cocoa_view_ setFrame:[(BaseView*)[cocoa_view_ superview] RectToNSRect:rect]]; | 200 [cocoa_view_ setFrame:[(BaseView*)[cocoa_view_ superview] RectToNSRect:rect]]; |
169 } | 201 } |
170 | 202 |
171 gfx::NativeView RenderWidgetHostViewMac::GetNativeView() { | 203 gfx::NativeView RenderWidgetHostViewMac::GetNativeView() { |
172 return native_view(); | 204 return native_view(); |
173 } | 205 } |
174 | 206 |
175 void RenderWidgetHostViewMac::MovePluginWindows( | 207 void RenderWidgetHostViewMac::MovePluginWindows( |
176 const std::vector<webkit_glue::WebPluginGeometry>& moves) { | 208 const std::vector<webkit_glue::WebPluginGeometry>& moves) { |
| 209 // The only case we need to notice plugin window moves is the case |
| 210 // of the GPU plugin. As soon as the GPU plugin becomes the GPU |
| 211 // process all of this code will go away. |
| 212 if (moves.size() > 0) { |
| 213 for (std::vector<webkit_glue::WebPluginGeometry>::const_iterator iter = |
| 214 moves.begin(); |
| 215 iter != moves.end(); |
| 216 ++iter) { |
| 217 webkit_glue::WebPluginGeometry geom = *iter; |
| 218 // Ignore bogus moves which claim to move the plugin to (0, 0) |
| 219 // with width and height (0, 0) |
| 220 if (geom.window_rect.x() != 0 || |
| 221 geom.window_rect.y() != 0 || |
| 222 geom.window_rect.width() != 0 || |
| 223 geom.window_rect.height() != 0) { |
| 224 plugin_container_manager_.MovePluginContainer(geom); |
| 225 } |
| 226 } |
| 227 } |
| 228 |
177 // All plugin stuff is TBD. TODO(avi,awalker): fill in | 229 // All plugin stuff is TBD. TODO(avi,awalker): fill in |
178 // http://crbug.com/8192 | 230 // http://crbug.com/8192 |
179 } | 231 } |
180 | 232 |
181 void RenderWidgetHostViewMac::Focus() { | 233 void RenderWidgetHostViewMac::Focus() { |
182 [[cocoa_view_ window] makeFirstResponder:cocoa_view_]; | 234 [[cocoa_view_ window] makeFirstResponder:cocoa_view_]; |
183 } | 235 } |
184 | 236 |
185 void RenderWidgetHostViewMac::Blur() { | 237 void RenderWidgetHostViewMac::Blur() { |
186 [[cocoa_view_ window] makeFirstResponder:nil]; | 238 [[cocoa_view_ window] makeFirstResponder:nil]; |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
433 | 485 |
434 void RenderWidgetHostViewMac::KillSelf() { | 486 void RenderWidgetHostViewMac::KillSelf() { |
435 if (shutdown_factory_.empty()) { | 487 if (shutdown_factory_.empty()) { |
436 [cocoa_view_ setHidden:YES]; | 488 [cocoa_view_ setHidden:YES]; |
437 MessageLoop::current()->PostTask(FROM_HERE, | 489 MessageLoop::current()->PostTask(FROM_HERE, |
438 shutdown_factory_.NewRunnableMethod( | 490 shutdown_factory_.NewRunnableMethod( |
439 &RenderWidgetHostViewMac::ShutdownHost)); | 491 &RenderWidgetHostViewMac::ShutdownHost)); |
440 } | 492 } |
441 } | 493 } |
442 | 494 |
| 495 gfx::PluginWindowHandle |
| 496 RenderWidgetHostViewMac::AllocateFakePluginWindowHandle() { |
| 497 // We currently only support the GPU plugin on 10.6 and later. |
| 498 if (!IOSurfaceSupport::Initialize()) |
| 499 return 0; |
| 500 |
| 501 // If we don't already have a GPUPluginLayer allocated for our view, |
| 502 // set one up now. |
| 503 if (gpu_plugin_layer_.get() == nil) { |
| 504 RenderWidgetHostViewCocoa* our_view = native_view(); |
| 505 // Try to get AppKit to allocate the layer |
| 506 [our_view setWantsLayer:YES]; |
| 507 CALayer* root_layer = [our_view layer]; |
| 508 if (root_layer == nil) { |
| 509 root_layer = [CALayer layer]; |
| 510 [our_view setLayer:root_layer]; |
| 511 } |
| 512 |
| 513 GPUPluginLayer* gpu_layer = |
| 514 [[GPUPluginLayer alloc] initWithRenderWidgetHostViewMac:this]; |
| 515 |
| 516 // Make our layer resize to fit the superlayer |
| 517 gpu_layer.autoresizingMask = kCALayerWidthSizable | kCALayerHeightSizable; |
| 518 // Set up its initial size |
| 519 [gpu_layer setFrame:NSRectToCGRect([our_view bounds])]; |
| 520 |
| 521 [root_layer addSublayer:gpu_layer]; |
| 522 gpu_plugin_layer_.reset(gpu_layer); |
| 523 } |
| 524 |
| 525 return plugin_container_manager_.AllocateFakePluginWindowHandle(); |
| 526 } |
| 527 |
| 528 void RenderWidgetHostViewMac::DestroyFakePluginWindowHandle( |
| 529 gfx::PluginWindowHandle window) { |
| 530 plugin_container_manager_.DestroyFakePluginWindowHandle(window); |
| 531 } |
| 532 |
| 533 void RenderWidgetHostViewMac::GPUPluginSetIOSurface( |
| 534 gfx::PluginWindowHandle window, |
| 535 int32 width, |
| 536 int32 height, |
| 537 uint64 io_surface_identifier) { |
| 538 plugin_container_manager_.SetSizeAndBackingStore(window, |
| 539 width, |
| 540 height, |
| 541 io_surface_identifier); |
| 542 } |
| 543 |
| 544 void RenderWidgetHostViewMac::GPUPluginBuffersSwapped( |
| 545 gfx::PluginWindowHandle window) { |
| 546 [gpu_plugin_layer_.get() setNeedsDisplay]; |
| 547 } |
| 548 |
| 549 void RenderWidgetHostViewMac::DrawGPUPluginInstances(CGLContextObj context) { |
| 550 CGLSetCurrentContext(context); |
| 551 gfx::Rect rect = GetWindowRect(); |
| 552 glMatrixMode(GL_PROJECTION); |
| 553 glLoadIdentity(); |
| 554 // Note that we place the origin at the upper left corner with +y |
| 555 // going down |
| 556 glOrtho(0, rect.width(), rect.height(), 0, -1, 1); |
| 557 glMatrixMode(GL_MODELVIEW); |
| 558 glLoadIdentity(); |
| 559 plugin_container_manager_.Draw(context); |
| 560 } |
| 561 |
443 void RenderWidgetHostViewMac::ShutdownHost() { | 562 void RenderWidgetHostViewMac::ShutdownHost() { |
444 shutdown_factory_.RevokeAll(); | 563 shutdown_factory_.RevokeAll(); |
445 render_widget_host_->Shutdown(); | 564 render_widget_host_->Shutdown(); |
446 // Do not touch any members at this point, |this| has been deleted. | 565 // Do not touch any members at this point, |this| has been deleted. |
447 } | 566 } |
448 | 567 |
449 namespace { | 568 namespace { |
450 | 569 |
451 // Adjusts an NSRect in screen coordinates to have an origin in the upper left, | 570 // Adjusts an NSRect in screen coordinates to have an origin in the upper left, |
452 // and stuffs it into a gfx::Rect. This is likely incorrect for a multiple- | 571 // and stuffs it into a gfx::Rect. This is likely incorrect for a multiple- |
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
863 // Reset tab_switch_paint_time_ to 0 so future tab selections are | 982 // Reset tab_switch_paint_time_ to 0 so future tab selections are |
864 // recorded. | 983 // recorded. |
865 renderWidgetHostView_->tab_switch_paint_time_ = base::TimeTicks(); | 984 renderWidgetHostView_->tab_switch_paint_time_ = base::TimeTicks(); |
866 } | 985 } |
867 } else { | 986 } else { |
868 [[NSColor whiteColor] set]; | 987 [[NSColor whiteColor] set]; |
869 NSRectFill(dirtyRect); | 988 NSRectFill(dirtyRect); |
870 if (renderWidgetHostView_->whiteout_start_time_.is_null()) | 989 if (renderWidgetHostView_->whiteout_start_time_.is_null()) |
871 renderWidgetHostView_->whiteout_start_time_ = base::TimeTicks::Now(); | 990 renderWidgetHostView_->whiteout_start_time_ = base::TimeTicks::Now(); |
872 } | 991 } |
| 992 |
| 993 // This helps keep the GPU plugins' output in better sync with the |
| 994 // window as it resizes. |
| 995 [renderWidgetHostView_->gpu_plugin_layer_.get() setNeedsDisplay]; |
873 } | 996 } |
874 | 997 |
875 - (BOOL)canBecomeKeyView { | 998 - (BOOL)canBecomeKeyView { |
876 if (!renderWidgetHostView_->render_widget_host_) | 999 if (!renderWidgetHostView_->render_widget_host_) |
877 return NO; | 1000 return NO; |
878 | 1001 |
879 return canBeKeyView_; | 1002 return canBeKeyView_; |
880 } | 1003 } |
881 | 1004 |
882 - (BOOL)acceptsFirstResponder { | 1005 - (BOOL)acceptsFirstResponder { |
(...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1389 event.skip_in_browser = true; | 1512 event.skip_in_browser = true; |
1390 renderWidgetHostView_->render_widget_host_->ForwardKeyboardEvent(event); | 1513 renderWidgetHostView_->render_widget_host_->ForwardKeyboardEvent(event); |
1391 } else { | 1514 } else { |
1392 renderWidgetHostView_->render_widget_host_->ImeConfirmComposition( | 1515 renderWidgetHostView_->render_widget_host_->ImeConfirmComposition( |
1393 UTF8ToUTF16([im_text UTF8String])); | 1516 UTF8ToUTF16([im_text UTF8String])); |
1394 } | 1517 } |
1395 renderWidgetHostView_->im_composing_ = false; | 1518 renderWidgetHostView_->im_composing_ = false; |
1396 } | 1519 } |
1397 | 1520 |
1398 @end | 1521 @end |
OLD | NEW |