| 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 "content/browser/renderer_host/render_widget_host_view_mac.h" | 5 #include "content/browser/renderer_host/render_widget_host_view_mac.h" |
| 6 | 6 |
| 7 #include <QuartzCore/QuartzCore.h> | 7 #include <QuartzCore/QuartzCore.h> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 /////////////////////////////////////////////////////////////////////////////// | 282 /////////////////////////////////////////////////////////////////////////////// |
| 283 // RenderWidgetHostViewMac, public: | 283 // RenderWidgetHostViewMac, public: |
| 284 | 284 |
| 285 RenderWidgetHostViewMac::RenderWidgetHostViewMac(RenderWidgetHost* widget) | 285 RenderWidgetHostViewMac::RenderWidgetHostViewMac(RenderWidgetHost* widget) |
| 286 : render_widget_host_(RenderWidgetHostImpl::From(widget)), | 286 : render_widget_host_(RenderWidgetHostImpl::From(widget)), |
| 287 about_to_validate_and_paint_(false), | 287 about_to_validate_and_paint_(false), |
| 288 call_set_needs_display_in_rect_pending_(false), | 288 call_set_needs_display_in_rect_pending_(false), |
| 289 last_frame_was_accelerated_(false), | 289 last_frame_was_accelerated_(false), |
| 290 text_input_type_(ui::TEXT_INPUT_TYPE_NONE), | 290 text_input_type_(ui::TEXT_INPUT_TYPE_NONE), |
| 291 can_compose_inline_(true), | 291 can_compose_inline_(true), |
| 292 allow_overlapping_views_(false), |
| 292 is_loading_(false), | 293 is_loading_(false), |
| 293 is_hidden_(false), | 294 is_hidden_(false), |
| 294 weak_factory_(this), | 295 weak_factory_(this), |
| 295 fullscreen_parent_host_view_(NULL) { | 296 fullscreen_parent_host_view_(NULL) { |
| 296 // |cocoa_view_| owns us and we will be deleted when |cocoa_view_| | 297 // |cocoa_view_| owns us and we will be deleted when |cocoa_view_| |
| 297 // goes away. Since we autorelease it, our caller must put | 298 // goes away. Since we autorelease it, our caller must put |
| 298 // |GetNativeView()| into the view hierarchy right after calling us. | 299 // |GetNativeView()| into the view hierarchy right after calling us. |
| 299 cocoa_view_ = [[[RenderWidgetHostViewCocoa alloc] | 300 cocoa_view_ = [[[RenderWidgetHostViewCocoa alloc] |
| 300 initWithRenderWidgetHostViewMac:this] autorelease]; | 301 initWithRenderWidgetHostViewMac:this] autorelease]; |
| 301 render_widget_host_->SetView(this); | 302 render_widget_host_->SetView(this); |
| 302 } | 303 } |
| 303 | 304 |
| 304 RenderWidgetHostViewMac::~RenderWidgetHostViewMac() { | 305 RenderWidgetHostViewMac::~RenderWidgetHostViewMac() { |
| 305 AckPendingSwapBuffers(); | 306 AckPendingSwapBuffers(); |
| 306 UnlockMouse(); | 307 UnlockMouse(); |
| 307 // We are owned by RenderWidgetHostViewCocoa, so if we go away before the | 308 // We are owned by RenderWidgetHostViewCocoa, so if we go away before the |
| 308 // RenderWidgetHost does we need to tell it not to hold a stale pointer to | 309 // RenderWidgetHost does we need to tell it not to hold a stale pointer to |
| 309 // us. | 310 // us. |
| 310 if (render_widget_host_) | 311 if (render_widget_host_) |
| 311 render_widget_host_->SetView(NULL); | 312 render_widget_host_->SetView(NULL); |
| 312 } | 313 } |
| 313 | 314 |
| 314 void RenderWidgetHostViewMac::SetDelegate( | 315 void RenderWidgetHostViewMac::SetDelegate( |
| 315 NSObject<RenderWidgetHostViewMacDelegate>* delegate) { | 316 NSObject<RenderWidgetHostViewMacDelegate>* delegate) { |
| 316 [cocoa_view_ setRWHVDelegate:delegate]; | 317 [cocoa_view_ setRWHVDelegate:delegate]; |
| 317 } | 318 } |
| 318 | 319 |
| 320 void RenderWidgetHostViewMac::SetAllowOverlappingViews(bool overlapping) { |
| 321 allow_overlapping_views_ = overlapping; |
| 322 } |
| 323 |
| 319 /////////////////////////////////////////////////////////////////////////////// | 324 /////////////////////////////////////////////////////////////////////////////// |
| 320 // RenderWidgetHostViewMac, RenderWidgetHostView implementation: | 325 // RenderWidgetHostViewMac, RenderWidgetHostView implementation: |
| 321 | 326 |
| 322 void RenderWidgetHostViewMac::InitAsChild( | 327 void RenderWidgetHostViewMac::InitAsChild( |
| 323 gfx::NativeView parent_view) { | 328 gfx::NativeView parent_view) { |
| 324 } | 329 } |
| 325 | 330 |
| 326 void RenderWidgetHostViewMac::InitAsPopup( | 331 void RenderWidgetHostViewMac::InitAsPopup( |
| 327 RenderWidgetHostView* parent_host_view, | 332 RenderWidgetHostView* parent_host_view, |
| 328 const gfx::Rect& pos) { | 333 const gfx::Rect& pos) { |
| (...skipping 710 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1039 [NSString stringWithFormat:@"window %s delegate %s controller %s", | 1044 [NSString stringWithFormat:@"window %s delegate %s controller %s", |
| 1040 object_getClassName(window), | 1045 object_getClassName(window), |
| 1041 object_getClassName([window delegate]), | 1046 object_getClassName([window delegate]), |
| 1042 object_getClassName([window windowController])]; | 1047 object_getClassName([window windowController])]; |
| 1043 base::mac::SetCrashKeyValue(kCrashKey, value); | 1048 base::mac::SetCrashKeyValue(kCrashKey, value); |
| 1044 } | 1049 } |
| 1045 | 1050 |
| 1046 return true; | 1051 return true; |
| 1047 } | 1052 } |
| 1048 | 1053 |
| 1049 if (!compositing_iosurface_.get()) | 1054 if (!compositing_iosurface_.get()) { |
| 1050 compositing_iosurface_.reset(CompositingIOSurfaceMac::Create()); | 1055 compositing_iosurface_.reset( |
| 1056 CompositingIOSurfaceMac::Create(allow_overlapping_views_)); |
| 1057 } |
| 1051 | 1058 |
| 1052 if (!compositing_iosurface_.get()) | 1059 if (!compositing_iosurface_.get()) |
| 1053 return true; | 1060 return true; |
| 1054 | 1061 |
| 1055 compositing_iosurface_->SetIOSurface(surface_handle, size); | 1062 compositing_iosurface_->SetIOSurface(surface_handle, size); |
| 1056 | 1063 |
| 1057 GotAcceleratedFrame(); | 1064 GotAcceleratedFrame(); |
| 1058 | 1065 |
| 1059 gfx::Size window_size(NSSizeToCGSize([cocoa_view_ frame].size)); | 1066 gfx::Size window_size(NSSizeToCGSize([cocoa_view_ frame].size)); |
| 1060 if (window_size.IsEmpty()) { | 1067 if (window_size.IsEmpty()) { |
| (...skipping 1240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2301 // blit the IOSurface below. | 2308 // blit the IOSurface below. |
| 2302 renderWidgetHostView_->about_to_validate_and_paint_ = true; | 2309 renderWidgetHostView_->about_to_validate_and_paint_ = true; |
| 2303 BackingStoreMac* backingStore = static_cast<BackingStoreMac*>( | 2310 BackingStoreMac* backingStore = static_cast<BackingStoreMac*>( |
| 2304 renderWidgetHostView_->render_widget_host_->GetBackingStore(true)); | 2311 renderWidgetHostView_->render_widget_host_->GetBackingStore(true)); |
| 2305 renderWidgetHostView_->about_to_validate_and_paint_ = false; | 2312 renderWidgetHostView_->about_to_validate_and_paint_ = false; |
| 2306 | 2313 |
| 2307 const gfx::Rect damagedRect([self flipNSRectToRect:dirtyRect]); | 2314 const gfx::Rect damagedRect([self flipNSRectToRect:dirtyRect]); |
| 2308 | 2315 |
| 2309 if (renderWidgetHostView_->last_frame_was_accelerated_ && | 2316 if (renderWidgetHostView_->last_frame_was_accelerated_ && |
| 2310 renderWidgetHostView_->compositing_iosurface_.get()) { | 2317 renderWidgetHostView_->compositing_iosurface_.get()) { |
| 2311 { | 2318 if (renderWidgetHostView_->allow_overlapping_views_) { |
| 2319 // If overlapping views need to be allowed, punch a hole in the window |
| 2320 // to expose the GL underlay. |
| 2312 TRACE_EVENT2("gpu", "NSRectFill clear", "w", damagedRect.width(), | 2321 TRACE_EVENT2("gpu", "NSRectFill clear", "w", damagedRect.width(), |
| 2313 "h", damagedRect.height()); | 2322 "h", damagedRect.height()); |
| 2314 // Draw transparency to expose the GL underlay. NSRectFill is extremely | 2323 // NSRectFill is extremely slow (15ms for a window on a fast MacPro), so |
| 2315 // slow (15ms for a window on a fast MacPro), so this is only done when | 2324 // this is only done when it's a real invalidation from window damage (not |
| 2316 // it's a real invalidation from window damage (not when a BuffersSwapped | 2325 // when a BuffersSwapped was received). Note that even a 1x1 NSRectFill |
| 2317 // was received). Note that even a 1x1 NSRectFill can take many | 2326 // can take many milliseconds sometimes (!) so this is skipped completely |
| 2318 // milliseconds sometimes (!) so this is skipped completely for drawRects | 2327 // for drawRects that are triggered by BuffersSwapped messages. |
| 2319 // that are triggered by BuffersSwapped messages. | |
| 2320 [[NSColor clearColor] set]; | 2328 [[NSColor clearColor] set]; |
| 2321 NSRectFill(dirtyRect); | 2329 NSRectFill(dirtyRect); |
| 2322 } | 2330 } |
| 2323 | 2331 |
| 2324 renderWidgetHostView_->compositing_iosurface_->DrawIOSurface( | 2332 renderWidgetHostView_->compositing_iosurface_->DrawIOSurface( |
| 2325 self, ScaleFactor(self)); | 2333 self, ScaleFactor(self)); |
| 2326 return; | 2334 return; |
| 2327 } | 2335 } |
| 2328 | 2336 |
| 2329 if (backingStore) { | 2337 if (backingStore) { |
| (...skipping 1035 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3365 if (!string) return NO; | 3373 if (!string) return NO; |
| 3366 | 3374 |
| 3367 // If the user is currently using an IME, confirm the IME input, | 3375 // If the user is currently using an IME, confirm the IME input, |
| 3368 // and then insert the text from the service, the same as TextEdit and Safari. | 3376 // and then insert the text from the service, the same as TextEdit and Safari. |
| 3369 [self confirmComposition]; | 3377 [self confirmComposition]; |
| 3370 [self insertText:string]; | 3378 [self insertText:string]; |
| 3371 return YES; | 3379 return YES; |
| 3372 } | 3380 } |
| 3373 | 3381 |
| 3374 @end | 3382 @end |
| OLD | NEW |