From 5e48dd9d4571208cba63afa9173ca259d08fbe9c Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 24 Apr 2018 20:08:14 +0900 Subject: [PATCH] be aware of views::Widget's layer --- atom/browser/native_window_mac.mm | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/atom/browser/native_window_mac.mm b/atom/browser/native_window_mac.mm index bb28bff0676f..60d6b93a87cb 100644 --- a/atom/browser/native_window_mac.mm +++ b/atom/browser/native_window_mac.mm @@ -27,6 +27,7 @@ #include "ui/gfx/skia_util.h" #include "ui/gl/gpu_switching_manager.h" #include "ui/views/background.h" +#include "ui/views/cocoa/bridged_native_widget.h" #include "ui/views/widget/widget.h" // Custom Quit, Minimize and Full Screen button container for frameless @@ -449,8 +450,13 @@ void NativeWindowMac::SetContentView( // Make sure the bottom corner is rounded for non-modal windows: // http://crbug.com/396264. But do not enable it on OS X 10.9 for transparent // window, otherwise a semi-transparent frame would show. - if (!(transparent() && base::mac::IsOS10_9()) && !is_modal()) + if (!(transparent() && base::mac::IsOS10_9()) && !is_modal()) { + base::scoped_nsobject background_layer([[CALayer alloc] init]); + [background_layer + setAutoresizingMask:kCALayerWidthSizable | kCALayerHeightSizable]; + [[window_ contentView] setLayer:background_layer]; [[window_ contentView] setWantsLayer:YES]; + } if (has_frame()) { [content_view_ setFrame:[[window_ contentView] bounds]]; @@ -974,7 +980,17 @@ bool NativeWindowMac::IsKiosk() { } void NativeWindowMac::SetBackgroundColor(SkColor color) { - widget_->GetRootView()->SetBackground(views::CreateSolidBackground(color)); + base::ScopedCFTypeRef cgcolor( + skia::CGColorCreateFromSkColor(color)); + // views::Widget adds a layer for the content view. + auto* bridge = views::NativeWidgetMac::GetBridgeForNativeWindow(window_); + NSView* compositor_superview = + static_cast(bridge)-> + AcceleratedWidgetGetNSView(); + [[compositor_superview layer] setBackgroundColor:cgcolor]; + // When using WebContents as content view, the contentView also has layer. + if ([[window_ contentView] wantsLayer]) + [[[window_ contentView] layer] setBackgroundColor:cgcolor]; } void NativeWindowMac::SetHasShadow(bool has_shadow) {