Chromium Code Reviews| Index: chrome/browser/ui/cocoa/fast_resize_view.mm |
| diff --git a/chrome/browser/ui/cocoa/fast_resize_view.mm b/chrome/browser/ui/cocoa/fast_resize_view.mm |
| index f4ea8d380b6d794b0f556f4fe3ba0a594f532af4..67d460f496f6154fa529bfe1005d3fd02f97b79c 100644 |
| --- a/chrome/browser/ui/cocoa/fast_resize_view.mm |
| +++ b/chrome/browser/ui/cocoa/fast_resize_view.mm |
| @@ -12,11 +12,26 @@ |
| #include "ui/base/cocoa/animation_utils.h" |
| #include "ui/base/ui_base_switches.h" |
| +namespace { |
| + |
| +// The radius of the rounded corners. |
| +const CGFloat kRoundedCornerRadius = 4; |
| + |
| +} // namespace |
| + |
| @interface FastResizeView (PrivateMethods) |
| // Lays out this views subviews. If fast resize mode is on, does not resize any |
| // subviews and instead pegs them to the top left. If fast resize mode is off, |
| // sets the subviews' frame to be equal to this view's bounds. |
| - (void)layoutSubviews; |
| + |
| +// Creates a path whose bottom two corners are rounded. |
| +// Caller takes ownership of the path. |
| +- (CGPathRef)createRoundedBottomCornersPath:(NSSize)size; |
| + |
| +// Updates the path of the layer mask to reflect the current value of |
| +// roundedBottomCorners_ and fastResizeMode_. |
| +- (void)updateLayerMask; |
| @end |
| @implementation FastResizeView |
| @@ -30,6 +45,9 @@ |
| [layer setBackgroundColor:CGColorGetConstantColor(kCGColorWhite)]; |
| [self setLayer:layer]; |
| [self setWantsLayer:YES]; |
| + |
| + roundedBottomCorners_ = YES; |
| + [self updateLayerMask]; |
| } |
| } |
| return self; |
| @@ -44,6 +62,7 @@ |
| return; |
| fastResizeMode_ = fastResizeMode; |
| + [self updateLayerMask]; |
| // Force a relayout when coming out of fast resize mode. |
| if (!fastResizeMode_) |
| @@ -52,6 +71,14 @@ |
| [self setNeedsDisplay:YES]; |
| } |
| +- (void)setRoundedBottomCorners:(BOOL)roundedBottomCorners { |
| + if (roundedBottomCorners == roundedBottomCorners_) |
| + return; |
| + |
| + roundedBottomCorners_ = roundedBottomCorners; |
| + [self updateLayerMask]; |
| +} |
| + |
| - (void)resizeSubviewsWithOldSize:(NSSize)oldSize { |
| [self layoutSubviews]; |
| } |
| @@ -67,6 +94,12 @@ |
| NSRectFill(dirtyRect); |
| } |
| +// Every time the frame's size changes, the layer mask needs to be updated. |
| +- (void)setFrameSize:(NSSize)newSize { |
| + [super setFrameSize:newSize]; |
| + [self updateLayerMask]; |
| +} |
| + |
| @end |
| @implementation FastResizeView (PrivateMethods) |
| @@ -93,4 +126,48 @@ |
| } |
| } |
| +- (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. |
| + CGPathAddRelativeArc( |
| + path, NULL, width - cornerRadius, cornerRadius, cornerRadius, 0, -M_PI_2); |
| + |
| + // Bottom left corner. |
| + CGPathAddRelativeArc( |
| + path, NULL, cornerRadius, cornerRadius, cornerRadius, -M_PI_2, -M_PI_2); |
| + |
| + // Draw line back to top-left corner. |
| + CGPathAddLineToPoint(path, NULL, 0, height); |
| + CGPathCloseSubpath(path); |
| + return path; |
| +} |
| + |
| +- (void)updateLayerMask { |
| + if (fastResizeMode_ || !roundedBottomCorners_) { |
| + [self layer].mask = nil; |
| + layerMask_ = nil; |
| + return; |
| + } |
| + |
| + if (![self layer].mask) { |
| + CAShapeLayer* maskLayer = [CAShapeLayer layer]; |
| + [self layer].mask = maskLayer; |
| + layerMask_ = maskLayer; |
|
Andre
2014/08/12 23:06:16
optional nit: can do away with maskLayer local var
erikchen
2014/08/12 23:09:25
Done.
|
| + } |
| + |
| + CGPathRef path = [self createRoundedBottomCornersPath:self.bounds.size]; |
| + layerMask_.path = path; |
| + CGPathRelease(path); |
| +} |
| + |
| @end |