|
35 | 35 | #include "content/nw/src/nw_package.h" |
36 | 36 | #include "content/nw/src/nw_shell.h" |
37 | 37 | #include "content/public/browser/native_web_keyboard_event.h" |
38 | | -#include "content/public/browser/render_widget_host_view.h" |
| 38 | +#include "content/browser/renderer_host/render_widget_host_view_mac.h" |
39 | 39 | #include "content/public/browser/web_contents.h" |
40 | 40 | #include "extensions/common/draggable_region.h" |
41 | 41 | #include "third_party/skia/include/core/SkRegion.h" |
@@ -282,7 +282,11 @@ - (void)drawCustomFrameRect:(NSRect)rect forView:(NSView*)view { |
282 | 282 | [[NSBezierPath bezierPathWithRoundedRect:[view bounds] |
283 | 283 | xRadius:cornerRadius |
284 | 284 | yRadius:cornerRadius] addClip]; |
285 | | - [[NSColor whiteColor] set]; |
| 285 | + if ([self isOpaque]) |
| 286 | + [[NSColor whiteColor] set]; |
| 287 | + else |
| 288 | + [[NSColor clearColor] set]; |
| 289 | + |
286 | 290 | NSRectFill(rect); |
287 | 291 | } |
288 | 292 |
|
@@ -385,10 +389,13 @@ - (void)drawRect:(NSRect)dirtyRect { |
385 | 389 | defer:NO]; |
386 | 390 | } |
387 | 391 | window_ = shell_window; |
| 392 | + opaque_color_ = [window() backgroundColor]; |
388 | 393 | [shell_window setShell:shell]; |
389 | 394 | [[window() contentView] setWantsLayer:YES]; |
390 | 395 | [window() setDelegate:[[NativeWindowDelegate alloc] initWithShell:shell]]; |
391 | 396 |
|
| 397 | + SetTransparent(transparent_); |
| 398 | + |
392 | 399 | // Disable fullscreen button when 'fullscreen' is specified to false. |
393 | 400 | bool fullscreen; |
394 | 401 | if (!(manifest->GetBoolean(switches::kmFullscreen, &fullscreen) && |
@@ -539,6 +546,26 @@ - (void)drawRect:(NSRect)dirtyRect { |
539 | 546 | return is_fullscreen_; |
540 | 547 | } |
541 | 548 |
|
| 549 | +void NativeWindowCocoa::SetTransparent(bool transparent) { |
| 550 | + |
| 551 | + if (!transparent_ && transparent) { |
| 552 | + opaque_color_ = [window() backgroundColor]; |
| 553 | + } |
| 554 | + |
| 555 | + [window() setHasShadow:transparent ? NO : YES]; |
| 556 | + [window() setOpaque:transparent ? NO : YES]; |
| 557 | + [window() setBackgroundColor:transparent ? [NSColor clearColor] : opaque_color_]; |
| 558 | + |
| 559 | + content::RenderWidgetHostViewMac* rwhv = static_cast<content::RenderWidgetHostViewMac*>(shell_->web_contents()->GetRenderWidgetHostView()); |
| 560 | + |
| 561 | + if (rwhv) { |
| 562 | + rwhv->SetBackgroundOpaque(!transparent); |
| 563 | + [rwhv->background_layer_ setBackgroundColor:CGColorGetConstantColor(transparent ? kCGColorClear : kCGColorWhite)]; |
| 564 | + } |
| 565 | + |
| 566 | + transparent_ = transparent; |
| 567 | + |
| 568 | +} |
542 | 569 | void NativeWindowCocoa::SetNonLionFullscreen(bool fullscreen) { |
543 | 570 | if (fullscreen == is_fullscreen_) |
544 | 571 | return; |
|
0 commit comments