diff --git a/chrome/browser/ui/cocoa/tab_contents/tab_contents_controller.h b/chrome/browser/ui/cocoa/tab_contents/tab_contents_controller.h index a0bf99ca74d588..29b74f597b7945 100644 --- a/chrome/browser/ui/cocoa/tab_contents/tab_contents_controller.h +++ b/chrome/browser/ui/cocoa/tab_contents/tab_contents_controller.h @@ -33,18 +33,14 @@ class WebContents; // and scaling will be avoided whenever possible. @interface TabContentsController : NSViewController { @private - content::WebContents* contents_; // weak - // When |fullscreenObserver_| is not-NULL, TabContentsController monitors for - // and auto-embeds fullscreen widgets as a subview. - scoped_ptr fullscreenObserver_; - // Set to true while TabContentsController is embedding a fullscreen widget - // view as a subview instead of the normal WebContentsView render view. Note: - // This will be false in the case of non-Flash fullscreen. - BOOL isEmbeddingFullscreenWidget_; - // This is used to prevent lazily loading the view during tear-down. This - // functionality is present in the 10.10 SDK as the viewLoaded property of - // NSViewController. - BOOL viewHasLoaded_; + content::WebContents* contents_; // weak + // When |fullscreenObserver_| is not-NULL, TabContentsController monitors for + // and auto-embeds fullscreen widgets as a subview. + scoped_ptr fullscreenObserver_; + // Set to true while TabContentsController is embedding a fullscreen widget + // view as a subview instead of the normal WebContentsView render view. Note: + // This will be false in the case of non-Flash fullscreen. + BOOL isEmbeddingFullscreenWidget_; } @property(readonly, nonatomic) content::WebContents* webContents; diff --git a/chrome/browser/ui/cocoa/tab_contents/tab_contents_controller.mm b/chrome/browser/ui/cocoa/tab_contents/tab_contents_controller.mm index ccd03bade1ea2f..9fe21c96e09cbd 100644 --- a/chrome/browser/ui/cocoa/tab_contents/tab_contents_controller.mm +++ b/chrome/browser/ui/cocoa/tab_contents/tab_contents_controller.mm @@ -78,6 +78,7 @@ @interface TabContentsContainerView : NSView { TabContentsController* delegate_; // weak } +- (NSColor*)computeBackgroundColor; - (void)updateBackgroundColor; @end @@ -101,6 +102,29 @@ - (void)delegateDestroyed { delegate_ = nil; } +- (NSColor*)computeBackgroundColor { + // This view is sometimes flashed into visibility (e.g, when closing + // windows or opening new tabs), so ensure that the flash be the theme + // background color in those cases. + NSColor* backgroundColor = nil; + ThemeService* const theme = + static_cast([[self window] themeProvider]); + if (theme) + backgroundColor = theme->GetNSColor(ThemeProperties::COLOR_NTP_BACKGROUND); + if (!backgroundColor) + backgroundColor = [NSColor whiteColor]; + + // If the page is in fullscreen tab capture mode, change the background color + // to be a dark tint of the new tab page's background color. + if ([delegate_ contentsInFullscreenCaptureMode]) { + const float kDarknessFraction = 0.80f; + return [backgroundColor blendedColorWithFraction:kDarknessFraction + ofColor:[NSColor blackColor]]; + } else { + return backgroundColor; + } +} + // Override auto-resizing logic to query the delegate for the exact frame to // use for the contents view. - (void)resizeSubviewsWithOldSize:(NSSize)oldBoundsSize { @@ -122,33 +146,17 @@ - (void)setNeedsDisplayInRect:(NSRect)rect { } - (void)updateBackgroundColor { - // This view is sometimes flashed into visibility (e.g, when closing - // windows or opening new tabs), so ensure that the flash be the theme - // background color in those cases. - SkColor skBackgroundColor = SK_ColorWHITE; - ThemeService* const theme = - static_cast([[self window] themeProvider]); - if (theme) - skBackgroundColor = theme->GetColor(ThemeProperties::COLOR_NTP_BACKGROUND); - - // Make the web contents use the same background color as the theme. - if ([delegate_ webContents]) - [delegate_ webContents]->SetBackgroundColor(skBackgroundColor); - - // If the page is in fullscreen tab capture mode, change the background color - // to be a dark tint of the new tab page's background color. - if ([delegate_ contentsInFullscreenCaptureMode]) { - const int kBackgroundDivisor = 5; - skBackgroundColor = skBackgroundColor = SkColorSetARGB( - SkColorGetA(skBackgroundColor), - SkColorGetR(skBackgroundColor) / kBackgroundDivisor, - SkColorGetG(skBackgroundColor) / kBackgroundDivisor, - SkColorGetB(skBackgroundColor) / kBackgroundDivisor); - } + // Convert from an NSColor to a CGColorRef. + NSColor* nsBackgroundColor = [self computeBackgroundColor]; + NSColorSpace* nsColorSpace = [nsBackgroundColor colorSpace]; + CGColorSpaceRef cgColorSpace = [nsColorSpace CGColorSpace]; + const NSInteger numberOfComponents = [nsBackgroundColor numberOfComponents]; + CGFloat components[numberOfComponents]; + [nsBackgroundColor getComponents:components]; + base::ScopedCFTypeRef cgBackgroundColor( + CGColorCreate(cgColorSpace, components)); ScopedCAActionDisabler disabler; - base::ScopedCFTypeRef cgBackgroundColor( - gfx::CGColorCreateFromSkColor(skBackgroundColor)); [[self layer] setBackgroundColor:cgBackgroundColor]; } @@ -188,12 +196,10 @@ - (id)initWithContents:(WebContents*)contents { } - (void)dealloc { - if (viewHasLoaded_) { - [static_cast([self view]) delegateDestroyed]; - // Make sure the contents view has been removed from the container view to - // allow objects to be released. - [[self view] removeFromSuperview]; - } + [static_cast([self view]) delegateDestroyed]; + // Make sure the contents view has been removed from the container view to + // allow objects to be released. + [[self view] removeFromSuperview]; [super dealloc]; } @@ -202,7 +208,6 @@ - (void)loadView { [[TabContentsContainerView alloc] initWithDelegate:self]); [view setAutoresizingMask:NSViewHeightSizable|NSViewWidthSizable]; [self setView:view]; - viewHasLoaded_ = YES; } - (void)ensureContentsSizeDoesNotChange { diff --git a/content/browser/renderer_host/render_widget_host_view_mac.h b/content/browser/renderer_host/render_widget_host_view_mac.h index f29fcefcb40dc9..499026922fd9dd 100644 --- a/content/browser/renderer_host/render_widget_host_view_mac.h +++ b/content/browser/renderer_host/render_widget_host_view_mac.h @@ -405,6 +405,9 @@ class CONTENT_EXPORT RenderWidgetHostViewMac ui::TextInputType text_input_type_; bool can_compose_inline_; + // The background CoreAnimation layer which is hosted by |cocoa_view_|. + base::scoped_nsobject background_layer_; + // The state of |delegated_frame_host_| and |browser_compositor_| to // manage being visible, hidden, or occluded. enum BrowserCompositorViewState { diff --git a/content/browser/renderer_host/render_widget_host_view_mac.mm b/content/browser/renderer_host/render_widget_host_view_mac.mm index 549f48a0de4192..22707f03bb7210 100644 --- a/content/browser/renderer_host/render_widget_host_view_mac.mm +++ b/content/browser/renderer_host/render_widget_host_view_mac.mm @@ -564,8 +564,13 @@ float FlipYFromRectToScreen(float y, float rect_height) { cocoa_view_ = [[[RenderWidgetHostViewCocoa alloc] initWithRenderWidgetHostViewMac:this] autorelease]; - base::scoped_nsobject background_layer([[CALayer alloc] init]); - [cocoa_view_ setLayer:background_layer]; + // Paint this view host with |background_color_| when there is no content + // ready to draw. + background_layer_.reset([[CALayer alloc] init]); + // Set the default color to be white. This is the wrong thing to do, but many + // UI components expect this view to be opaque. + [background_layer_ setBackgroundColor:CGColorGetConstantColor(kCGColorWhite)]; + [cocoa_view_ setLayer:background_layer_]; [cocoa_view_ setWantsLayer:YES]; if (IsDelegatedRendererEnabled()) { diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc index 260aeacf2bc839..2e6a5f7556dd83 100644 --- a/content/browser/web_contents/web_contents_impl.cc +++ b/content/browser/web_contents/web_contents_impl.cc @@ -4274,13 +4274,6 @@ bool WebContentsImpl::GetAllowOtherViews() { return view_->GetAllowOtherViews(); } -void WebContentsImpl::SetBackgroundColor(SkColor background_color) { - if (is_being_destroyed_) - return; - if (view_) - view_->SetBackgroundColor(background_color); -} - #endif void WebContentsImpl::OnDialogClosed(int render_process_id, diff --git a/content/browser/web_contents/web_contents_impl.h b/content/browser/web_contents/web_contents_impl.h index 528bb9b66e8324..e5e473eaac0630 100644 --- a/content/browser/web_contents/web_contents_impl.h +++ b/content/browser/web_contents/web_contents_impl.h @@ -364,7 +364,6 @@ class CONTENT_EXPORT WebContentsImpl base::android::ScopedJavaLocalRef GetJavaWebContents() override; virtual WebContentsAndroid* GetWebContentsAndroid(); #elif defined(OS_MACOSX) - void SetBackgroundColor(SkColor background_color) override; void SetAllowOtherViews(bool allow) override; bool GetAllowOtherViews() override; #endif diff --git a/content/browser/web_contents/web_contents_view.h b/content/browser/web_contents/web_contents_view.h index 9cee768da0cd67..439dda4fbcfc7d 100644 --- a/content/browser/web_contents/web_contents_view.h +++ b/content/browser/web_contents/web_contents_view.h @@ -10,7 +10,6 @@ #include "base/basictypes.h" #include "base/strings/string16.h" #include "content/common/content_export.h" -#include "third_party/skia/include/core/SkColor.h" #include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/size.h" #include "ui/gfx/native_widget_types.h" @@ -110,10 +109,6 @@ class WebContentsView { virtual void SetOverscrollControllerEnabled(bool enabled) = 0; #if defined(OS_MACOSX) - // Set the background color which may be flashed if there is not content - // available yet. - virtual void SetBackgroundColor(SkColor background_color) = 0; - // Allowing other views disables optimizations which assume that only a single // WebContents is present. virtual void SetAllowOtherViews(bool allow) = 0; diff --git a/content/browser/web_contents/web_contents_view_guest.cc b/content/browser/web_contents/web_contents_view_guest.cc index 129e24f21449d1..940b4209b1ece3 100644 --- a/content/browser/web_contents/web_contents_view_guest.cc +++ b/content/browser/web_contents/web_contents_view_guest.cc @@ -107,10 +107,6 @@ gfx::Rect WebContentsViewGuest::GetViewBounds() const { } #if defined(OS_MACOSX) -void WebContentsViewGuest::SetBackgroundColor(SkColor background_color) { - platform_view_->SetBackgroundColor(background_color); -} - void WebContentsViewGuest::SetAllowOtherViews(bool allow) { platform_view_->SetAllowOtherViews(allow); } diff --git a/content/browser/web_contents/web_contents_view_guest.h b/content/browser/web_contents/web_contents_view_guest.h index 570a979bbd04cd..f2a10c8681699a 100644 --- a/content/browser/web_contents/web_contents_view_guest.h +++ b/content/browser/web_contents/web_contents_view_guest.h @@ -63,7 +63,6 @@ class WebContentsViewGuest : public WebContentsView, void RenderViewSwappedIn(RenderViewHost* host) override; void SetOverscrollControllerEnabled(bool enabled) override; #if defined(OS_MACOSX) - void SetBackgroundColor(SkColor background_color) override; void SetAllowOtherViews(bool allow) override; bool GetAllowOtherViews() const override; bool IsEventTracking() const override; diff --git a/content/browser/web_contents/web_contents_view_mac.h b/content/browser/web_contents/web_contents_view_mac.h index 5324506486ed2b..d116d7d2a3361b 100644 --- a/content/browser/web_contents/web_contents_view_mac.h +++ b/content/browser/web_contents/web_contents_view_mac.h @@ -78,7 +78,6 @@ class WebContentsViewMac : public WebContentsView, void RestoreFocus() override; DropData* GetDropData() const override; gfx::Rect GetViewBounds() const override; - void SetBackgroundColor(SkColor background_color) override; void SetAllowOtherViews(bool allow) override; bool GetAllowOtherViews() const override; void CreateView(const gfx::Size& initial_size, diff --git a/content/browser/web_contents/web_contents_view_mac.mm b/content/browser/web_contents/web_contents_view_mac.mm index 39269052813a18..9e1f7925e214ce 100644 --- a/content/browser/web_contents/web_contents_view_mac.mm +++ b/content/browser/web_contents/web_contents_view_mac.mm @@ -26,7 +26,6 @@ #include "skia/ext/skia_utils_mac.h" #import "third_party/mozilla/NSPasteboard+Utils.h" #include "ui/base/clipboard/custom_data_helper.h" -#include "ui/base/cocoa/animation_utils.h" #import "ui/base/cocoa/focus_tracker.h" #include "ui/base/dragdrop/cocoa_dnd_util.h" #include "ui/gfx/image/image_skia_util_mac.h" @@ -276,13 +275,6 @@ - (void)viewDidBecomeFirstResponder:(NSNotification*)notification; return gfx::Rect(); } -void WebContentsViewMac::SetBackgroundColor(SkColor background_color) { - ScopedCAActionDisabler disabler; - base::ScopedCFTypeRef cg_background_color( - gfx::CGColorCreateFromSkColor(background_color)); - [[cocoa_view_ layer] setBackgroundColor:cg_background_color]; -} - void WebContentsViewMac::SetAllowOtherViews(bool allow) { if (allow_other_views_ == allow) return; @@ -401,16 +393,6 @@ - (id)initWithWebContentsViewMac:(WebContentsViewMac*)w { self = [super initWithFrame:NSZeroRect]; if (self != nil) { webContentsView_ = w; - - // Initialize the view to have a white background color, since many views - // that host web contents expect this. This may be changed via - // SetBackgroundColor. - base::scoped_nsobject background_layer([[CALayer alloc] init]); - [background_layer - setBackgroundColor:CGColorGetConstantColor(kCGColorWhite)]; - [self setLayer:background_layer]; - [self setWantsLayer:YES]; - dragDest_.reset( [[WebDragDest alloc] initWithWebContentsImpl:[self webContents]]); [self registerDragTypes]; diff --git a/content/public/browser/web_contents.h b/content/public/browser/web_contents.h index 0a79d26e014a48..a28df1cd6ad0fb 100644 --- a/content/public/browser/web_contents.h +++ b/content/public/browser/web_contents.h @@ -650,10 +650,6 @@ class WebContents : public PageNavigator, // Returns true if other views are allowed, false otherwise. virtual bool GetAllowOtherViews() = 0; - - // Set the background color which may be flashed if there is not content - // available yet. - virtual void SetBackgroundColor(SkColor background_color) = 0; #endif // OS_ANDROID private: