| 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 #import <Carbon/Carbon.h> | 7 #import <Carbon/Carbon.h> |
| 8 #import <objc/runtime.h> | 8 #import <objc/runtime.h> |
| 9 #include <OpenGL/gl.h> | 9 #include <OpenGL/gl.h> |
| 10 #include <QuartzCore/QuartzCore.h> | 10 #include <QuartzCore/QuartzCore.h> |
| (...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 442 | 442 |
| 443 RenderWidgetHostViewMac::RenderWidgetHostViewMac(RenderWidgetHost* widget, | 443 RenderWidgetHostViewMac::RenderWidgetHostViewMac(RenderWidgetHost* widget, |
| 444 bool is_guest_view_hack) | 444 bool is_guest_view_hack) |
| 445 : render_widget_host_(RenderWidgetHostImpl::From(widget)), | 445 : render_widget_host_(RenderWidgetHostImpl::From(widget)), |
| 446 page_at_minimum_scale_(true), | 446 page_at_minimum_scale_(true), |
| 447 is_loading_(false), | 447 is_loading_(false), |
| 448 allow_pause_for_resize_or_repaint_(true), | 448 allow_pause_for_resize_or_repaint_(true), |
| 449 is_guest_view_hack_(is_guest_view_hack), | 449 is_guest_view_hack_(is_guest_view_hack), |
| 450 fullscreen_parent_host_view_(nullptr), | 450 fullscreen_parent_host_view_(nullptr), |
| 451 needs_flush_input_(false), | 451 needs_flush_input_(false), |
| 452 background_color_(SK_ColorWHITE), |
| 452 weak_factory_(this) { | 453 weak_factory_(this) { |
| 453 // |cocoa_view_| owns us and we will be deleted when |cocoa_view_| | 454 // |cocoa_view_| owns us and we will be deleted when |cocoa_view_| |
| 454 // goes away. Since we autorelease it, our caller must put | 455 // goes away. Since we autorelease it, our caller must put |
| 455 // |GetNativeView()| into the view hierarchy right after calling us. | 456 // |GetNativeView()| into the view hierarchy right after calling us. |
| 456 cocoa_view_ = [[[RenderWidgetHostViewCocoa alloc] | 457 cocoa_view_ = [[[RenderWidgetHostViewCocoa alloc] |
| 457 initWithRenderWidgetHostViewMac:this] autorelease]; | 458 initWithRenderWidgetHostViewMac:this] autorelease]; |
| 458 | 459 |
| 459 // Paint this view host with |background_color_| when there is no content | 460 // Paint this view host with |background_color_| when there is no content |
| 460 // ready to draw. | 461 // ready to draw. |
| 461 background_layer_.reset([[CALayer alloc] init]); | 462 background_layer_.reset([[CALayer alloc] init]); |
| (...skipping 965 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1427 browser_compositor_->DidCreateNewRendererCompositorFrameSink(); | 1428 browser_compositor_->DidCreateNewRendererCompositorFrameSink(); |
| 1428 } | 1429 } |
| 1429 | 1430 |
| 1430 void RenderWidgetHostViewMac::SubmitCompositorFrame( | 1431 void RenderWidgetHostViewMac::SubmitCompositorFrame( |
| 1431 const cc::LocalSurfaceId& local_surface_id, | 1432 const cc::LocalSurfaceId& local_surface_id, |
| 1432 cc::CompositorFrame frame) { | 1433 cc::CompositorFrame frame) { |
| 1433 TRACE_EVENT0("browser", "RenderWidgetHostViewMac::OnSwapCompositorFrame"); | 1434 TRACE_EVENT0("browser", "RenderWidgetHostViewMac::OnSwapCompositorFrame"); |
| 1434 | 1435 |
| 1435 // Override the compositor background color. See RenderWidgetHostViewAura | 1436 // Override the compositor background color. See RenderWidgetHostViewAura |
| 1436 // for more details. | 1437 // for more details. |
| 1437 SetBackgroundColor(frame.metadata.root_background_color); | 1438 UpdateBackgroundColorFromRenderer(frame.metadata.root_background_color); |
| 1438 | 1439 |
| 1439 last_scroll_offset_ = frame.metadata.root_scroll_offset; | 1440 last_scroll_offset_ = frame.metadata.root_scroll_offset; |
| 1440 | 1441 |
| 1441 page_at_minimum_scale_ = | 1442 page_at_minimum_scale_ = |
| 1442 frame.metadata.page_scale_factor == frame.metadata.min_page_scale_factor; | 1443 frame.metadata.page_scale_factor == frame.metadata.min_page_scale_factor; |
| 1443 browser_compositor_->SubmitCompositorFrame(local_surface_id, | 1444 browser_compositor_->SubmitCompositorFrame(local_surface_id, |
| 1444 std::move(frame)); | 1445 std::move(frame)); |
| 1445 UpdateDisplayVSyncParameters(); | 1446 UpdateDisplayVSyncParameters(); |
| 1446 } | 1447 } |
| 1447 | 1448 |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1635 if (!active) | 1636 if (!active) |
| 1636 UnlockMouse(); | 1637 UnlockMouse(); |
| 1637 } | 1638 } |
| 1638 | 1639 |
| 1639 void RenderWidgetHostViewMac::ShowDefinitionForSelection() { | 1640 void RenderWidgetHostViewMac::ShowDefinitionForSelection() { |
| 1640 RenderWidgetHostViewMacDictionaryHelper helper(this); | 1641 RenderWidgetHostViewMacDictionaryHelper helper(this); |
| 1641 helper.ShowDefinitionForSelection(); | 1642 helper.ShowDefinitionForSelection(); |
| 1642 } | 1643 } |
| 1643 | 1644 |
| 1644 void RenderWidgetHostViewMac::SetBackgroundColor(SkColor color) { | 1645 void RenderWidgetHostViewMac::SetBackgroundColor(SkColor color) { |
| 1645 if (color == background_color_) | 1646 // The renderer will feed its color back to us with the first CompositorFrame. |
| 1646 return; | 1647 // We short-cut here to show a sensible color before that happens. |
| 1648 UpdateBackgroundColorFromRenderer(color); |
| 1647 | 1649 |
| 1648 RenderWidgetHostViewBase::SetBackgroundColor(color); | 1650 DCHECK(SkColorGetA(color) == SK_AlphaOPAQUE || |
| 1649 bool opaque = GetBackgroundOpaque(); | 1651 SkColorGetA(color) == SK_AlphaTRANSPARENT); |
| 1650 | 1652 bool opaque = SkColorGetA(color) == SK_AlphaOPAQUE; |
| 1651 if (render_widget_host_) | 1653 if (render_widget_host_) |
| 1652 render_widget_host_->SetBackgroundOpaque(opaque); | 1654 render_widget_host_->SetBackgroundOpaque(opaque); |
| 1655 } |
| 1656 |
| 1657 SkColor RenderWidgetHostViewMac::background_color() const { |
| 1658 return background_color_; |
| 1659 } |
| 1660 |
| 1661 void RenderWidgetHostViewMac::UpdateBackgroundColorFromRenderer(SkColor color) { |
| 1662 if (color == background_color()) |
| 1663 return; |
| 1664 background_color_ = color; |
| 1665 |
| 1666 bool opaque = SkColorGetA(color) == SK_AlphaOPAQUE; |
| 1653 | 1667 |
| 1654 [cocoa_view_ setOpaque:opaque]; | 1668 [cocoa_view_ setOpaque:opaque]; |
| 1655 | 1669 |
| 1656 browser_compositor_->SetHasTransparentBackground(!opaque); | 1670 browser_compositor_->SetHasTransparentBackground(!opaque); |
| 1657 | 1671 |
| 1658 ScopedCAActionDisabler disabler; | 1672 ScopedCAActionDisabler disabler; |
| 1659 base::ScopedCFTypeRef<CGColorRef> cg_color( | 1673 base::ScopedCFTypeRef<CGColorRef> cg_color( |
| 1660 skia::CGColorCreateFromSkColor(color)); | 1674 skia::CGColorCreateFromSkColor(color)); |
| 1661 [background_layer_ setBackgroundColor:cg_color]; | 1675 [background_layer_ setBackgroundColor:cg_color]; |
| 1662 } | 1676 } |
| (...skipping 1844 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3507 | 3521 |
| 3508 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding | 3522 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding |
| 3509 // regions that are not draggable. (See ControlRegionView in | 3523 // regions that are not draggable. (See ControlRegionView in |
| 3510 // native_app_window_cocoa.mm). This requires the render host view to be | 3524 // native_app_window_cocoa.mm). This requires the render host view to be |
| 3511 // draggable by default. | 3525 // draggable by default. |
| 3512 - (BOOL)mouseDownCanMoveWindow { | 3526 - (BOOL)mouseDownCanMoveWindow { |
| 3513 return YES; | 3527 return YES; |
| 3514 } | 3528 } |
| 3515 | 3529 |
| 3516 @end | 3530 @end |
| OLD | NEW |