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

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

Issue 1986963004: Revert of [Mac][Material Design] Update bookmarks bar to Material Design. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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/gradient_button_cell.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/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 33333b832785b60f3951e3975ee5ceda73ecaf20..8d44cbd8217eff38f3205c490e360c7b185a6565 100644
--- a/chrome/browser/ui/cocoa/gradient_button_cell.mm
+++ b/chrome/browser/ui/cocoa/gradient_button_cell.mm
@@ -206,13 +206,6 @@
isMouseInside_ = flag;
if (pulseState_ != gradient_button_cell::kPulsingContinuous) {
if (animated) {
- // In Material Design, if the button is already fully on, don't pulse it
- // on again if the mouse is within its bounds.
- if ([self tag] == kMaterialStandardButtonTypeWithLimitedClickFeedback &&
- isMouseInside_ && pulseState_ == gradient_button_cell::kPulsedOn) {
- return;
- }
-
[self setPulseState:(isMouseInside_ ? gradient_button_cell::kPulsingOn :
gradient_button_cell::kPulsingOff)];
} else {
@@ -324,19 +317,6 @@
- (BOOL)isMouseInside {
return trackingArea_ && isMouseInside_;
-}
-
-- (BOOL)startTrackingAt:(NSPoint)startPoint inView:(NSView *)controlView {
- if ([self tag] == kMaterialStandardButtonTypeWithLimitedClickFeedback) {
- // The user has just clicked down in the button. In Material Design, set the
- // pulsed (hover) state to off now so that if the user keeps the mouse held
- // down while dragging it out of the button's bounds, the button will draw
- // itself in its normal state. This is unrelated to dragging the button
- // in the button bar, which takes a different path through the code.
- [self setPulseState:gradient_button_cell::kPulsedOff];
- }
-
- return [super startTrackingAt:startPoint inView:controlView];
}
// Since we have our own drawWithFrame:, we need to also have our own
@@ -368,35 +348,6 @@
active:(BOOL)active
cellFrame:(NSRect)cellFrame
defaultGradient:(NSGradient*)defaultGradient {
- // For Material Design, draw a solid rounded rect behind the button, based on
- // the hover and pressed states.
- if ([self tag] == kMaterialStandardButtonTypeWithLimitedClickFeedback) {
- const CGFloat kEightPercentAlpha = 0.08;
- const CGFloat kFourPercentAlpha = 0.04;
-
- // The alpha is always at least 8%. Default the color to black.
- CGFloat alpha = kEightPercentAlpha;
- CGFloat color = 0.0;
- // If a dark theme, incrase the opacity slightly and use white.
- if ([[controlView window] hasDarkTheme]) {
- alpha += kFourPercentAlpha;
- color = 1.0;
- }
- // If clicked or highlighted, the background is slightly more opaque. If not
- // clicked or highlighted, adjust the alpha by the animation fade in
- // percentage.
- if (showClickedGradient || showHighlightGradient) {
- alpha += kFourPercentAlpha;
- } else {
- alpha *= hoverAlpha;
- }
-
- // Fill the path.
- [[NSColor colorWithCalibratedWhite:color alpha:alpha] set];
- [innerPath fill];
- return;
- }
-
BOOL isFlatButton = [self showsBorderOnlyWhileMouseInside];
// For flat (unbordered when not hovered) buttons, never use the toolbar
@@ -510,16 +461,14 @@
innerFrame:(NSRect*)returnInnerFrame
innerPath:(NSBezierPath**)returnInnerPath
clipPath:(NSBezierPath**)returnClipPath {
- const CGFloat kLineWidth = [controlView cr_lineWidth];
- const CGFloat kHalfLineWidth = kLineWidth / 2.0;
-
- NSRect drawFrame = cellFrame;
- NSRect innerFrame = NSInsetRect(cellFrame, kLineWidth, kLineWidth);
- CGFloat cornerRadius = 2;
- if ([self tag] != kMaterialStandardButtonTypeWithLimitedClickFeedback) {
- drawFrame = NSInsetRect(cellFrame, 1.5 * kLineWidth, 1.5 * kLineWidth);
- cornerRadius = 3;
- }
+ const CGFloat lineWidth = [controlView cr_lineWidth];
+ const CGFloat halfLineWidth = lineWidth / 2.0;
+
+ // Constants from Cole. Will kConstant them once the feedback loop
+ // is complete.
+ NSRect drawFrame = NSInsetRect(cellFrame, 1.5 * lineWidth, 1.5 * lineWidth);
+ NSRect innerFrame = NSInsetRect(cellFrame, lineWidth, lineWidth);
+ const CGFloat radius = 3;
ButtonType type = [[(NSControl*)controlView cell] tag];
switch (type) {
@@ -547,18 +496,18 @@
if (returnInnerPath) {
DCHECK(*returnInnerPath == nil);
*returnInnerPath = [NSBezierPath bezierPathWithRoundedRect:drawFrame
- xRadius:cornerRadius
- yRadius:cornerRadius];
- [*returnInnerPath setLineWidth:kLineWidth];
+ xRadius:radius
+ yRadius:radius];
+ [*returnInnerPath setLineWidth:lineWidth];
}
if (returnClipPath) {
DCHECK(*returnClipPath == nil);
NSRect clipPathRect =
- NSInsetRect(drawFrame, -kHalfLineWidth, -kHalfLineWidth);
+ NSInsetRect(drawFrame, -halfLineWidth, -halfLineWidth);
*returnClipPath = [NSBezierPath
bezierPathWithRoundedRect:clipPathRect
- xRadius:cornerRadius + kHalfLineWidth
- yRadius:cornerRadius + kHalfLineWidth];
+ xRadius:radius + halfLineWidth
+ yRadius:radius + halfLineWidth];
}
}
@@ -614,12 +563,6 @@
NSCompositeSourceOver);
}
[self drawInteriorWithFrame:innerFrame inView:controlView];
-}
-
-- (CGFloat)textStartXOffset {
- // 11 is the magic number needed to make this match the native
- // NSButtonCell's label display.
- return [[self image] size].width + 11;
}
- (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView*)controlView {
@@ -702,14 +645,10 @@
// Empirically, Cocoa will draw an extra 2 pixels past NSWidth(cellFrame)
// before it clips the text.
const CGFloat kOverflowBeforeClip = 2;
- BOOL isModeMaterial =
- [self tag] == kMaterialStandardButtonTypeWithLimitedClickFeedback;
- // For Material Design we don't want to clip the text. For all other button
- // cell modes, we do.
- BOOL shouldClipTheTitle = !isModeMaterial;
+ BOOL clipping = YES;
if (std::floor(size.width) <= (NSWidth(cellFrame) + kOverflowBeforeClip)) {
cellFrame.origin.y += ([self verticalTextOffset] - 1);
- shouldClipTheTitle = NO;
+ clipping = NO;
}
// Gradient is about twice our line height long.
@@ -723,10 +662,12 @@
NSPoint textOffset = NSZeroPoint;
{
gfx::ScopedNSGraphicsContextSaveGState scopedGState;
- if (shouldClipTheTitle)
+ if (clipping)
[NSBezierPath clipRect:solidPart];
- CGFloat textLeft = [self textStartXOffset];
+ // 11 is the magic number needed to make this match the native
+ // NSButtonCell's label display.
+ CGFloat textLeft = [[self image] size].width + 11;
// For some reason, the height of cellFrame as passed in is totally bogus.
// For vertical centering purposes, we need the bounds of the containing
@@ -737,20 +678,10 @@
textOffset = NSMakePoint(textLeft,
(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];
- } else {
- [title drawAtPoint:textOffset];
- }
- }
-
- if (!shouldClipTheTitle)
+ [title drawAtPoint:textOffset];
+ }
+
+ if (!clipping)
return cellFrame;
// Draw the gradient part with a transparency layer. This makes the text look
« no previous file with comments | « chrome/browser/ui/cocoa/gradient_button_cell.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698