diff --git a/brightray/browser/mac/bry_inspectable_web_contents_view.h b/brightray/browser/mac/bry_inspectable_web_contents_view.h index 8cf7540b60f9..ea6e3f9a8115 100644 --- a/brightray/browser/mac/bry_inspectable_web_contents_view.h +++ b/brightray/browser/mac/bry_inspectable_web_contents_view.h @@ -5,6 +5,8 @@ #include "base/mac/scoped_nsobject.h" #include "ui/base/cocoa/base_view.h" +@class CAShapeLayer; + namespace brightray { class InspectableWebContentsViewMac; } @@ -19,6 +21,9 @@ using brightray::InspectableWebContentsViewMac; BOOL devtools_visible_; BOOL devtools_docked_; + // Weak reference to the mask of the hosted layer. + CAShapeLayer* layerMask_; + DevToolsContentsResizingStrategy strategy_; } diff --git a/brightray/browser/mac/bry_inspectable_web_contents_view.mm b/brightray/browser/mac/bry_inspectable_web_contents_view.mm index 7fb76539fc07..a7f4134b4fae 100644 --- a/brightray/browser/mac/bry_inspectable_web_contents_view.mm +++ b/brightray/browser/mac/bry_inspectable_web_contents_view.mm @@ -1,14 +1,24 @@ #include "browser/mac/bry_inspectable_web_contents_view.h" +#import + #include "browser/inspectable_web_contents_impl.h" #include "browser/inspectable_web_contents_view_mac.h" #include "content/public/browser/render_widget_host_view.h" -#import "ui/base/cocoa/underlay_opengl_hosting_window.h" +#include "ui/base/cocoa/animation_utils.h" +#include "ui/base/cocoa/underlay_opengl_hosting_window.h" #include "ui/gfx/mac/scoped_ns_disable_screen_updates.h" using namespace brightray; +namespace { + +// The radius of the rounded corners. +const CGFloat kRoundedCornerRadius = 4; + +} // namespace + @implementation BRYInspectableWebContentsView - (instancetype)initWithInspectableWebContentsViewMac:(InspectableWebContentsViewMac*)view { @@ -26,8 +36,14 @@ using namespace brightray; [self addSubview:contentsView]; // See https://code.google.com/p/chromium/issues/detail?id=348490. + ScopedCAActionDisabler disabler; + base::scoped_nsobject layer([[CALayer alloc] init]); + [self setLayer:layer]; [self setWantsLayer:YES]; + // See https://code.google.com/p/chromium/issues/detail?id=396264. + [self updateLayerMask]; + return self; } @@ -35,6 +51,12 @@ using namespace brightray; [self adjustSubviews]; } +// Every time the frame's size changes, the layer mask needs to be updated. +- (void)setFrameSize:(NSSize)newSize { + [super setFrameSize:newSize]; + [self updateLayerMask]; +} + - (IBAction)showDevTools:(id)sender { inspectableWebContentsView_->inspectable_web_contents()->ShowDevTools(); } @@ -152,6 +174,58 @@ using namespace brightray; [contentsView setFrame:[self flipRectToNSRect:new_contents_bounds]]; } +// Creates a path whose bottom two corners are rounded. +// Caller takes ownership of the path. +- (CGPathRef)createRoundedBottomCornersPath:(NSSize)size { + CGMutablePathRef path = CGPathCreateMutable(); + CGFloat width = size.width; + CGFloat height = size.height; + CGFloat cornerRadius = kRoundedCornerRadius; + + // Top left corner. + CGPathMoveToPoint(path, NULL, 0, height); + + // Top right corner. + CGPathAddLineToPoint(path, NULL, width, height); + + // Bottom right corner. + CGPathAddArc(path, + NULL, + width - cornerRadius, + cornerRadius, + cornerRadius, + 0, + -M_PI_2, + true); + + // Bottom left corner. + CGPathAddArc(path, + NULL, + cornerRadius, + cornerRadius, + cornerRadius, + -M_PI_2, + -M_PI, + true); + + // Draw line back to top-left corner. + CGPathAddLineToPoint(path, NULL, 0, height); + CGPathCloseSubpath(path); + return path; +} + +// Updates the path of the layer mask to have make window have round corner. +- (void)updateLayerMask { + if (![self layer].mask) { + layerMask_ = [CAShapeLayer layer]; + [self layer].mask = layerMask_; + } + + CGPathRef path = [self createRoundedBottomCornersPath:self.bounds.size]; + layerMask_.path = path; + CGPathRelease(path); +} + #pragma mark - NSWindowDelegate - (void)windowWillClose:(NSNotification*)notification {