Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
|
Elly Fong-Jones
2017/05/03 17:03:14
this might be a dumb question but now that we do M
lgrey
2017/05/03 21:32:48
I'd like to but Find Bar still uses it. We discuss
| |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/cocoa/gradient_button_cell.h" | 5 #include "chrome/browser/ui/cocoa/gradient_button_cell.h" |
| 6 | 6 |
| 7 #include <cmath> | 7 #include <cmath> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #import "base/mac/scoped_nsobject.h" | 10 #import "base/mac/scoped_nsobject.h" |
| 11 #import "chrome/browser/themes/theme_properties.h" | 11 #import "chrome/browser/themes/theme_properties.h" |
| (...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 483 ThemeProperties::COLOR_TOOLBAR_BUTTON_STROKE_INACTIVE) : | 483 ThemeProperties::COLOR_TOOLBAR_BUTTON_STROKE_INACTIVE) : |
| 484 [NSColor colorWithCalibratedWhite:0.0 | 484 [NSColor colorWithCalibratedWhite:0.0 |
| 485 alpha:0.3 * outerStrokeAlphaMult_]; | 485 alpha:0.3 * outerStrokeAlphaMult_]; |
| 486 } | 486 } |
| 487 [strokeColor setStroke]; | 487 [strokeColor setStroke]; |
| 488 | 488 |
| 489 [innerPath setLineWidth:1]; | 489 [innerPath setLineWidth:1]; |
| 490 [innerPath stroke]; | 490 [innerPath stroke]; |
| 491 } | 491 } |
| 492 | 492 |
| 493 - (CGFloat)insetInView:(NSView*)controlView { | |
| 494 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
| |
| 495 return [[NSScreen mainScreen] convertRectToBacking:NSMakeRect(0, 0, 1, 1)] | |
| 496 .size.width; | |
| 497 return [controlView cr_lineWidth]; | |
| 498 } | |
| 499 | |
| 493 // TODO(viettrungluu): clean this up. | 500 // TODO(viettrungluu): clean this up. |
| 494 // (Private) | 501 // (Private) |
| 495 - (void)getDrawParamsForFrame:(NSRect)cellFrame | 502 - (void)getDrawParamsForFrame:(NSRect)cellFrame |
| 496 inView:(NSView*)controlView | 503 inView:(NSView*)controlView |
| 497 innerFrame:(NSRect*)returnInnerFrame | 504 innerFrame:(NSRect*)returnInnerFrame |
| 498 innerPath:(NSBezierPath**)returnInnerPath | 505 innerPath:(NSBezierPath**)returnInnerPath |
| 499 clipPath:(NSBezierPath**)returnClipPath { | 506 clipPath:(NSBezierPath**)returnClipPath { |
| 500 const CGFloat kLineWidth = [controlView cr_lineWidth]; | 507 const CGFloat lineWidth = [self insetInView:controlView]; |
| 501 const CGFloat kHalfLineWidth = kLineWidth / 2.0; | 508 const CGFloat halfLineWidth = lineWidth / 2.0; |
| 502 | 509 |
| 503 NSRect drawFrame = NSZeroRect; | 510 NSRect drawFrame = NSZeroRect; |
| 504 NSRect innerFrame = NSZeroRect; | 511 NSRect innerFrame = NSZeroRect; |
| 505 CGFloat cornerRadius = 2; | 512 CGFloat cornerRadius = 2; |
| 506 if (![self isMaterialDesignButtonType]) { | 513 if (![self isMaterialDesignButtonType]) { |
| 507 drawFrame = NSInsetRect(cellFrame, 1.5 * kLineWidth, 1.5 * kLineWidth); | 514 drawFrame = NSInsetRect(cellFrame, 1.5 * lineWidth, 1.5 * lineWidth); |
| 508 innerFrame = NSInsetRect(cellFrame, kLineWidth, kLineWidth); | 515 innerFrame = NSInsetRect(cellFrame, lineWidth, lineWidth); |
| 509 cornerRadius = 3; | 516 cornerRadius = 3; |
| 510 } else { | 517 } else { |
| 511 drawFrame = cellFrame; | 518 drawFrame = cellFrame; |
| 512 // Hover and click paths are always 20pt tall, regardless of the button's | 519 // Hover and click paths are always 20pt tall, regardless of the button's |
| 513 // height. | 520 // height. |
| 514 drawFrame.size.height = 20; | 521 drawFrame.size.height = 20; |
| 515 innerFrame = NSInsetRect(drawFrame, kLineWidth, kLineWidth); | 522 innerFrame = NSInsetRect(drawFrame, lineWidth, lineWidth); |
| 516 } | 523 } |
| 517 | 524 |
| 518 ButtonType type = [[(NSControl*)controlView cell] tag]; | 525 ButtonType type = [[(NSControl*)controlView cell] tag]; |
| 519 switch (type) { | 526 switch (type) { |
| 520 case kMiddleButtonType: | 527 case kMiddleButtonType: |
| 521 drawFrame.size.width += 20; | 528 drawFrame.size.width += 20; |
| 522 innerFrame.size.width += 2; | 529 innerFrame.size.width += 2; |
| 523 // Fallthrough | 530 // Fallthrough |
| 524 case kRightButtonType: | 531 case kRightButtonType: |
| 525 drawFrame.origin.x -= 20; | 532 drawFrame.origin.x -= 20; |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 543 drawFrame.origin.y += | 550 drawFrame.origin.y += |
| 544 [self hoverBackgroundVerticalOffsetInControlView:controlView]; | 551 [self hoverBackgroundVerticalOffsetInControlView:controlView]; |
| 545 | 552 |
| 546 if ([self tag] == kMaterialMenuButtonTypeWithLimitedClickFeedback) { | 553 if ([self tag] == kMaterialMenuButtonTypeWithLimitedClickFeedback) { |
| 547 *returnInnerPath = [NSBezierPath bezierPathWithRect:drawFrame]; | 554 *returnInnerPath = [NSBezierPath bezierPathWithRect:drawFrame]; |
| 548 } else { | 555 } else { |
| 549 *returnInnerPath = [NSBezierPath bezierPathWithRoundedRect:drawFrame | 556 *returnInnerPath = [NSBezierPath bezierPathWithRoundedRect:drawFrame |
| 550 xRadius:cornerRadius | 557 xRadius:cornerRadius |
| 551 yRadius:cornerRadius]; | 558 yRadius:cornerRadius]; |
| 552 } | 559 } |
| 553 [*returnInnerPath setLineWidth:kLineWidth]; | 560 [*returnInnerPath setLineWidth:lineWidth]; |
| 554 } | 561 } |
| 555 if (returnClipPath) { | 562 if (returnClipPath) { |
| 556 DCHECK(*returnClipPath == nil); | 563 DCHECK(*returnClipPath == nil); |
| 557 NSRect clipPathRect = | 564 NSRect clipPathRect = |
| 558 NSInsetRect(drawFrame, -kHalfLineWidth, -kHalfLineWidth); | 565 NSInsetRect(drawFrame, -halfLineWidth, -halfLineWidth); |
| 559 *returnClipPath = [NSBezierPath | 566 *returnClipPath = |
| 560 bezierPathWithRoundedRect:clipPathRect | 567 [NSBezierPath bezierPathWithRoundedRect:clipPathRect |
| 561 xRadius:cornerRadius + kHalfLineWidth | 568 xRadius:cornerRadius + halfLineWidth |
| 562 yRadius:cornerRadius + kHalfLineWidth]; | 569 yRadius:cornerRadius + halfLineWidth]; |
| 563 } | 570 } |
| 564 } | 571 } |
| 565 | 572 |
| 566 // TODO(viettrungluu): clean this up. | 573 // TODO(viettrungluu): clean this up. |
| 567 - (void)drawWithFrame:(NSRect)cellFrame inView:(NSView*)controlView { | 574 - (void)drawWithFrame:(NSRect)cellFrame inView:(NSView*)controlView { |
| 568 NSRect innerFrame; | 575 NSRect innerFrame; |
| 569 NSBezierPath* innerPath = nil; | 576 NSBezierPath* innerPath = nil; |
| 570 [self getDrawParamsForFrame:cellFrame | 577 [self getDrawParamsForFrame:cellFrame |
| 571 inView:controlView | 578 inView:controlView |
| 572 innerFrame:&innerFrame | 579 innerFrame:&innerFrame |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 736 NSDivideRect(cellFrame, &gradientPart, &solidPart, gradientWidth, NSMaxXEdge); | 743 NSDivideRect(cellFrame, &gradientPart, &solidPart, gradientWidth, NSMaxXEdge); |
| 737 | 744 |
| 738 // Draw non-gradient part without transparency layer, as light text on a dark | 745 // Draw non-gradient part without transparency layer, as light text on a dark |
| 739 // background looks bad with a gradient layer. | 746 // background looks bad with a gradient layer. |
| 740 NSPoint textOffset = NSZeroPoint; | 747 NSPoint textOffset = NSZeroPoint; |
| 741 { | 748 { |
| 742 gfx::ScopedNSGraphicsContextSaveGState scopedGState; | 749 gfx::ScopedNSGraphicsContextSaveGState scopedGState; |
| 743 if (shouldClipTheTitle) | 750 if (shouldClipTheTitle) |
| 744 [NSBezierPath clipRect:solidPart]; | 751 [NSBezierPath clipRect:solidPart]; |
| 745 | 752 |
| 746 CGFloat textLeft = [self textStartXOffset]; | |
| 747 | 753 |
| 748 // For some reason, the height of cellFrame as passed in is totally bogus. | 754 // For some reason, the height of cellFrame as passed in is totally bogus. |
| 749 // For vertical centering purposes, we need the bounds of the containing | 755 // For vertical centering purposes, we need the bounds of the containing |
| 750 // view. | 756 // view. |
| 751 NSRect buttonFrame = [[self controlView] frame]; | 757 NSRect buttonFrame = [[self controlView] frame]; |
| 752 | 758 |
| 753 // Call the vertical offset to match native NSButtonCell's version. | 759 // Call the vertical offset to match native NSButtonCell's version. |
| 754 textOffset = NSMakePoint(textLeft, | 760 textOffset = NSMakePoint( |
| 755 (NSHeight(buttonFrame) - size.height) / 2 + | 761 NSMinX(cellFrame), |
| 756 [self verticalTextOffset]); | 762 (NSHeight(buttonFrame) - size.height) / 2 + [self verticalTextOffset]); |
| 757 // WIth Material Design we want an ellipsis if the title is too long to fit, | 763 // WIth Material Design we want an ellipsis if the title is too long to fit, |
| 758 // so have to use drawInRect: instead of drawAtPoint:. | 764 // so have to use drawInRect: instead of drawAtPoint:. |
| 759 if (isModeMaterial) { | 765 if (isModeMaterial) { |
| 760 NSRect textBounds = NSMakeRect(textOffset.x, | 766 NSRect textFrame = NSMakeRect(textOffset.x, textOffset.y, |
| 761 textOffset.y, | 767 NSWidth(cellFrame), NSHeight(buttonFrame)); |
| 762 NSWidth(buttonFrame) - textOffset.x, | 768 [title drawInRect:textFrame]; |
| 763 NSHeight(buttonFrame)); | |
| 764 [title drawInRect:textBounds]; | |
| 765 } else { | 769 } else { |
| 766 [title drawAtPoint:textOffset]; | 770 [title drawAtPoint:textOffset]; |
| 767 } | 771 } |
| 768 } | 772 } |
| 769 | 773 |
| 770 if (!shouldClipTheTitle) | 774 if (!shouldClipTheTitle) |
| 771 return cellFrame; | 775 return cellFrame; |
| 772 | 776 |
| 773 // Draw the gradient part with a transparency layer. This makes the text look | 777 // Draw the gradient part with a transparency layer. This makes the text look |
| 774 // suboptimal, but since it fades out, that's ok. | 778 // suboptimal, but since it fades out, that's ok. |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 845 options:options | 849 options:options |
| 846 owner:self | 850 owner:self |
| 847 userInfo:nil]); | 851 userInfo:nil]); |
| 848 if (isMouseInside_ != mouseInView) { | 852 if (isMouseInside_ != mouseInView) { |
| 849 [self setMouseInside:mouseInView animate:NO]; | 853 [self setMouseInside:mouseInView animate:NO]; |
| 850 [controlView setNeedsDisplay:YES]; | 854 [controlView setNeedsDisplay:YES]; |
| 851 } | 855 } |
| 852 } | 856 } |
| 853 | 857 |
| 854 @end | 858 @end |
| OLD | NEW |