| 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 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 435 | 435 |
| 436 RenderWidgetHostViewMac::RenderWidgetHostViewMac(RenderWidgetHost* widget, | 436 RenderWidgetHostViewMac::RenderWidgetHostViewMac(RenderWidgetHost* widget, |
| 437 bool is_guest_view_hack) | 437 bool is_guest_view_hack) |
| 438 : render_widget_host_(RenderWidgetHostImpl::From(widget)), | 438 : render_widget_host_(RenderWidgetHostImpl::From(widget)), |
| 439 page_at_minimum_scale_(true), | 439 page_at_minimum_scale_(true), |
| 440 is_loading_(false), | 440 is_loading_(false), |
| 441 allow_pause_for_resize_or_repaint_(true), | 441 allow_pause_for_resize_or_repaint_(true), |
| 442 is_guest_view_hack_(is_guest_view_hack), | 442 is_guest_view_hack_(is_guest_view_hack), |
| 443 fullscreen_parent_host_view_(nullptr), | 443 fullscreen_parent_host_view_(nullptr), |
| 444 needs_flush_input_(false), | 444 needs_flush_input_(false), |
| 445 background_color_(SK_ColorWHITE), | |
| 446 weak_factory_(this) { | 445 weak_factory_(this) { |
| 447 // |cocoa_view_| owns us and we will be deleted when |cocoa_view_| | 446 // |cocoa_view_| owns us and we will be deleted when |cocoa_view_| |
| 448 // goes away. Since we autorelease it, our caller must put | 447 // goes away. Since we autorelease it, our caller must put |
| 449 // |GetNativeView()| into the view hierarchy right after calling us. | 448 // |GetNativeView()| into the view hierarchy right after calling us. |
| 450 cocoa_view_ = [[[RenderWidgetHostViewCocoa alloc] | 449 cocoa_view_ = [[[RenderWidgetHostViewCocoa alloc] |
| 451 initWithRenderWidgetHostViewMac:this] autorelease]; | 450 initWithRenderWidgetHostViewMac:this] autorelease]; |
| 452 | 451 |
| 453 // Paint this view host with |background_color_| when there is no content | |
| 454 // ready to draw. | |
| 455 background_layer_.reset([[CALayer alloc] init]); | 452 background_layer_.reset([[CALayer alloc] init]); |
| 456 // Set the default color to be white. This is the wrong thing to do, but many | |
| 457 // UI components expect this view to be opaque. | |
| 458 [background_layer_ setBackgroundColor:CGColorGetConstantColor(kCGColorWhite)]; | |
| 459 [cocoa_view_ setLayer:background_layer_]; | 453 [cocoa_view_ setLayer:background_layer_]; |
| 460 [cocoa_view_ setWantsLayer:YES]; | 454 [cocoa_view_ setWantsLayer:YES]; |
| 461 | 455 |
| 462 cc::FrameSinkId frame_sink_id = | 456 cc::FrameSinkId frame_sink_id = |
| 463 render_widget_host_->AllocateFrameSinkId(is_guest_view_hack_); | 457 render_widget_host_->AllocateFrameSinkId(is_guest_view_hack_); |
| 464 browser_compositor_.reset( | 458 browser_compositor_.reset( |
| 465 new BrowserCompositorMac(this, this, render_widget_host_->is_hidden(), | 459 new BrowserCompositorMac(this, this, render_widget_host_->is_hidden(), |
| 466 [cocoa_view_ window], frame_sink_id)); | 460 [cocoa_view_ window], frame_sink_id)); |
| 467 | 461 |
| 468 display::Screen::GetScreen()->AddObserver(this); | 462 display::Screen::GetScreen()->AddObserver(this); |
| (...skipping 1163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1632 if (!active) | 1626 if (!active) |
| 1633 UnlockMouse(); | 1627 UnlockMouse(); |
| 1634 } | 1628 } |
| 1635 | 1629 |
| 1636 void RenderWidgetHostViewMac::ShowDefinitionForSelection() { | 1630 void RenderWidgetHostViewMac::ShowDefinitionForSelection() { |
| 1637 RenderWidgetHostViewMacDictionaryHelper helper(this); | 1631 RenderWidgetHostViewMacDictionaryHelper helper(this); |
| 1638 helper.ShowDefinitionForSelection(); | 1632 helper.ShowDefinitionForSelection(); |
| 1639 } | 1633 } |
| 1640 | 1634 |
| 1641 void RenderWidgetHostViewMac::SetBackgroundColor(SkColor color) { | 1635 void RenderWidgetHostViewMac::SetBackgroundColor(SkColor color) { |
| 1636 if (color == background_color_) |
| 1637 return; |
| 1638 |
| 1642 // The renderer will feed its color back to us with the first CompositorFrame. | 1639 // The renderer will feed its color back to us with the first CompositorFrame. |
| 1643 // We short-cut here to show a sensible color before that happens. | 1640 // We short-cut here to show a sensible color before that happens. |
| 1644 UpdateBackgroundColorFromRenderer(color); | 1641 UpdateBackgroundColorFromRenderer(color); |
| 1645 | 1642 |
| 1646 DCHECK(SkColorGetA(color) == SK_AlphaOPAQUE || | 1643 DCHECK(SkColorGetA(color) == SK_AlphaOPAQUE || |
| 1647 SkColorGetA(color) == SK_AlphaTRANSPARENT); | 1644 SkColorGetA(color) == SK_AlphaTRANSPARENT); |
| 1648 bool opaque = SkColorGetA(color) == SK_AlphaOPAQUE; | 1645 bool opaque = SkColorGetA(color) == SK_AlphaOPAQUE; |
| 1649 if (render_widget_host_) | 1646 if (render_widget_host_) |
| 1650 render_widget_host_->SetBackgroundOpaque(opaque); | 1647 render_widget_host_->SetBackgroundOpaque(opaque); |
| 1651 } | 1648 } |
| 1652 | 1649 |
| 1653 SkColor RenderWidgetHostViewMac::background_color() const { | 1650 SkColor RenderWidgetHostViewMac::background_color() const { |
| 1654 return background_color_; | 1651 return background_color_; |
| 1655 } | 1652 } |
| 1656 | 1653 |
| 1657 void RenderWidgetHostViewMac::UpdateBackgroundColorFromRenderer(SkColor color) { | 1654 void RenderWidgetHostViewMac::UpdateBackgroundColorFromRenderer(SkColor color) { |
| 1658 if (color == background_color()) | 1655 if (color == background_color_) |
| 1659 return; | 1656 return; |
| 1660 background_color_ = color; | 1657 background_color_ = color; |
| 1661 | 1658 |
| 1662 bool opaque = SkColorGetA(color) == SK_AlphaOPAQUE; | 1659 bool opaque = SkColorGetA(color) == SK_AlphaOPAQUE; |
| 1663 | 1660 |
| 1664 [cocoa_view_ setOpaque:opaque]; | 1661 [cocoa_view_ setOpaque:opaque]; |
| 1665 | 1662 |
| 1666 browser_compositor_->SetHasTransparentBackground(!opaque); | 1663 browser_compositor_->SetHasTransparentBackground(!opaque); |
| 1667 | 1664 |
| 1668 ScopedCAActionDisabler disabler; | 1665 ScopedCAActionDisabler disabler; |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1760 | 1757 |
| 1761 - (id)initWithRenderWidgetHostViewMac:(RenderWidgetHostViewMac*)r { | 1758 - (id)initWithRenderWidgetHostViewMac:(RenderWidgetHostViewMac*)r { |
| 1762 self = [super initWithFrame:NSZeroRect]; | 1759 self = [super initWithFrame:NSZeroRect]; |
| 1763 if (self) { | 1760 if (self) { |
| 1764 self.acceptsTouchEvents = YES; | 1761 self.acceptsTouchEvents = YES; |
| 1765 editCommand_helper_.reset(new RenderWidgetHostViewMacEditCommandHelper); | 1762 editCommand_helper_.reset(new RenderWidgetHostViewMacEditCommandHelper); |
| 1766 editCommand_helper_->AddEditingSelectorsToClass([self class]); | 1763 editCommand_helper_->AddEditingSelectorsToClass([self class]); |
| 1767 | 1764 |
| 1768 renderWidgetHostView_.reset(r); | 1765 renderWidgetHostView_.reset(r); |
| 1769 canBeKeyView_ = YES; | 1766 canBeKeyView_ = YES; |
| 1770 opaque_ = YES; | 1767 opaque_ = NO; |
| 1771 pinchHasReachedZoomThreshold_ = false; | 1768 pinchHasReachedZoomThreshold_ = false; |
| 1772 isStylusEnteringProximity_ = false; | 1769 isStylusEnteringProximity_ = false; |
| 1773 | 1770 |
| 1774 // OpenGL support: | 1771 // OpenGL support: |
| 1775 if ([self respondsToSelector: | 1772 if ([self respondsToSelector: |
| 1776 @selector(setWantsBestResolutionOpenGLSurface:)]) { | 1773 @selector(setWantsBestResolutionOpenGLSurface:)]) { |
| 1777 [self setWantsBestResolutionOpenGLSurface:YES]; | 1774 [self setWantsBestResolutionOpenGLSurface:YES]; |
| 1778 } | 1775 } |
| 1779 [[NSNotificationCenter defaultCenter] | 1776 [[NSNotificationCenter defaultCenter] |
| 1780 addObserver:self | 1777 addObserver:self |
| (...skipping 1736 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3517 | 3514 |
| 3518 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding | 3515 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding |
| 3519 // regions that are not draggable. (See ControlRegionView in | 3516 // regions that are not draggable. (See ControlRegionView in |
| 3520 // native_app_window_cocoa.mm). This requires the render host view to be | 3517 // native_app_window_cocoa.mm). This requires the render host view to be |
| 3521 // draggable by default. | 3518 // draggable by default. |
| 3522 - (BOOL)mouseDownCanMoveWindow { | 3519 - (BOOL)mouseDownCanMoveWindow { |
| 3523 return YES; | 3520 return YES; |
| 3524 } | 3521 } |
| 3525 | 3522 |
| 3526 @end | 3523 @end |
| OLD | NEW |