Chromium Code Reviews| Index: chrome/browser/ui/cocoa/gradient_button_cell.mm |
| diff --git a/chrome/browser/ui/cocoa/gradient_button_cell.mm b/chrome/browser/ui/cocoa/gradient_button_cell.mm |
| index 4827cef0a613467092a3308d79a75041ec3da203..9964455d3b201f053eac3e32f55c7d7e352a8f28 100644 |
| --- a/chrome/browser/ui/cocoa/gradient_button_cell.mm |
| +++ b/chrome/browser/ui/cocoa/gradient_button_cell.mm |
| @@ -490,6 +490,13 @@ static const NSTimeInterval kAnimationHideDuration = 0.4; |
| [innerPath stroke]; |
| } |
| +- (CGFloat)insetInView:(NSView*)controlView { |
| + if (!controlView) |
|
Elly Fong-Jones
2017/05/03 17:03:14
can that happen?
lgrey
2017/05/03 21:32:48
I think this was vestigial from a class method cal
|
| + return [[NSScreen mainScreen] convertRectToBacking:NSMakeRect(0, 0, 1, 1)] |
| + .size.width; |
| + return [controlView cr_lineWidth]; |
| +} |
| + |
| // TODO(viettrungluu): clean this up. |
| // (Private) |
| - (void)getDrawParamsForFrame:(NSRect)cellFrame |
| @@ -497,22 +504,22 @@ static const NSTimeInterval kAnimationHideDuration = 0.4; |
| innerFrame:(NSRect*)returnInnerFrame |
| innerPath:(NSBezierPath**)returnInnerPath |
| clipPath:(NSBezierPath**)returnClipPath { |
| - const CGFloat kLineWidth = [controlView cr_lineWidth]; |
| - const CGFloat kHalfLineWidth = kLineWidth / 2.0; |
| + const CGFloat lineWidth = [self insetInView:controlView]; |
| + const CGFloat halfLineWidth = lineWidth / 2.0; |
| NSRect drawFrame = NSZeroRect; |
| NSRect innerFrame = NSZeroRect; |
| CGFloat cornerRadius = 2; |
| if (![self isMaterialDesignButtonType]) { |
| - drawFrame = NSInsetRect(cellFrame, 1.5 * kLineWidth, 1.5 * kLineWidth); |
| - innerFrame = NSInsetRect(cellFrame, kLineWidth, kLineWidth); |
| + drawFrame = NSInsetRect(cellFrame, 1.5 * lineWidth, 1.5 * lineWidth); |
| + innerFrame = NSInsetRect(cellFrame, lineWidth, lineWidth); |
| cornerRadius = 3; |
| } else { |
| drawFrame = cellFrame; |
| // Hover and click paths are always 20pt tall, regardless of the button's |
| // height. |
| drawFrame.size.height = 20; |
| - innerFrame = NSInsetRect(drawFrame, kLineWidth, kLineWidth); |
| + innerFrame = NSInsetRect(drawFrame, lineWidth, lineWidth); |
| } |
| ButtonType type = [[(NSControl*)controlView cell] tag]; |
| @@ -550,16 +557,16 @@ static const NSTimeInterval kAnimationHideDuration = 0.4; |
| xRadius:cornerRadius |
| yRadius:cornerRadius]; |
| } |
| - [*returnInnerPath setLineWidth:kLineWidth]; |
| + [*returnInnerPath setLineWidth:lineWidth]; |
| } |
| if (returnClipPath) { |
| DCHECK(*returnClipPath == nil); |
| NSRect clipPathRect = |
| - NSInsetRect(drawFrame, -kHalfLineWidth, -kHalfLineWidth); |
| - *returnClipPath = [NSBezierPath |
| - bezierPathWithRoundedRect:clipPathRect |
| - xRadius:cornerRadius + kHalfLineWidth |
| - yRadius:cornerRadius + kHalfLineWidth]; |
| + NSInsetRect(drawFrame, -halfLineWidth, -halfLineWidth); |
| + *returnClipPath = |
| + [NSBezierPath bezierPathWithRoundedRect:clipPathRect |
| + xRadius:cornerRadius + halfLineWidth |
| + yRadius:cornerRadius + halfLineWidth]; |
| } |
| } |
| @@ -743,7 +750,6 @@ static const NSTimeInterval kAnimationHideDuration = 0.4; |
| if (shouldClipTheTitle) |
| [NSBezierPath clipRect:solidPart]; |
| - CGFloat textLeft = [self textStartXOffset]; |
| // For some reason, the height of cellFrame as passed in is totally bogus. |
| // For vertical centering purposes, we need the bounds of the containing |
| @@ -751,17 +757,15 @@ static const NSTimeInterval kAnimationHideDuration = 0.4; |
| NSRect buttonFrame = [[self controlView] frame]; |
| // Call the vertical offset to match native NSButtonCell's version. |
| - textOffset = NSMakePoint(textLeft, |
| - (NSHeight(buttonFrame) - size.height) / 2 + |
| - [self verticalTextOffset]); |
| + textOffset = NSMakePoint( |
| + NSMinX(cellFrame), |
| + (NSHeight(buttonFrame) - size.height) / 2 + [self verticalTextOffset]); |
| // WIth Material Design we want an ellipsis if the title is too long to fit, |
| // so have to use drawInRect: instead of drawAtPoint:. |
| if (isModeMaterial) { |
| - NSRect textBounds = NSMakeRect(textOffset.x, |
| - textOffset.y, |
| - NSWidth(buttonFrame) - textOffset.x, |
| - NSHeight(buttonFrame)); |
| - [title drawInRect:textBounds]; |
| + NSRect textFrame = NSMakeRect(textOffset.x, textOffset.y, |
| + NSWidth(cellFrame), NSHeight(buttonFrame)); |
| + [title drawInRect:textFrame]; |
| } else { |
| [title drawAtPoint:textOffset]; |
| } |