Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8469)

Unified Diff: chrome/browser/ui/cocoa/fast_resize_view.mm

Issue 463263002: Mac: Fix rounded corners on browser windows on retina display. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Replace 10.7+ CGPath function with 10.2+ equivalent function. Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/cocoa/fast_resize_view.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..848d356540a9b42c2e3e8eb3d971dc3c20b18701 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,59 @@
}
}
+- (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;
+}
+
+- (void)updateLayerMask {
+ if (fastResizeMode_ || !roundedBottomCorners_) {
+ [self layer].mask = nil;
+ layerMask_ = nil;
+ return;
+ }
+
+ if (![self layer].mask) {
+ layerMask_ = [CAShapeLayer layer];
+ [self layer].mask = layerMask_;
+ }
+
+ CGPathRef path = [self createRoundedBottomCornersPath:self.bounds.size];
+ layerMask_.path = path;
+ CGPathRelease(path);
+}
+
@end
« no previous file with comments | « chrome/browser/ui/cocoa/fast_resize_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698