OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
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" |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 shouldTheme_ = YES; | 278 shouldTheme_ = YES; |
279 pulseState_ = gradient_button_cell::kPulsedOff; | 279 pulseState_ = gradient_button_cell::kPulsedOff; |
280 outerStrokeAlphaMult_ = 1.0; | 280 outerStrokeAlphaMult_ = 1.0; |
281 gradient_.reset([[self gradientForHoverAlpha:0.0 isThemed:NO] retain]); | 281 gradient_.reset([[self gradientForHoverAlpha:0.0 isThemed:NO] retain]); |
282 } | 282 } |
283 | 283 |
284 - (void)setShouldTheme:(BOOL)shouldTheme { | 284 - (void)setShouldTheme:(BOOL)shouldTheme { |
285 shouldTheme_ = shouldTheme; | 285 shouldTheme_ = shouldTheme; |
286 } | 286 } |
287 | 287 |
288 - (NSImage*)overlayImage { | |
289 return overlayImage_.get(); | |
290 } | |
291 | |
292 - (void)setOverlayImage:(NSImage*)image { | |
293 overlayImage_.reset([image retain]); | |
294 [[self controlView] setNeedsDisplay:YES]; | |
295 } | |
296 | |
297 - (NSBackgroundStyle)interiorBackgroundStyle { | 288 - (NSBackgroundStyle)interiorBackgroundStyle { |
298 // Never lower the interior, since that just leads to a weird shadow which can | 289 // Never lower the interior, since that just leads to a weird shadow which can |
299 // often interact badly with the theme. | 290 // often interact badly with the theme. |
300 return NSBackgroundStyleRaised; | 291 return NSBackgroundStyleRaised; |
301 } | 292 } |
302 | 293 |
303 - (void)mouseEntered:(NSEvent*)theEvent { | 294 - (void)mouseEntered:(NSEvent*)theEvent { |
304 [self setMouseInside:YES animate:YES]; | 295 [self setMouseInside:YES animate:YES]; |
305 } | 296 } |
306 | 297 |
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
675 [color set]; | 666 [color set]; |
676 NSRectFillUsingOperation(cellFrame, NSCompositeSourceAtop); | 667 NSRectFillUsingOperation(cellFrame, NSCompositeSourceAtop); |
677 } | 668 } |
678 CGContextEndTransparencyLayer(context); | 669 CGContextEndTransparencyLayer(context); |
679 } else { | 670 } else { |
680 // NSCell draws these off-center for some reason, probably because of the | 671 // NSCell draws these off-center for some reason, probably because of the |
681 // positioning of the control in the xib. | 672 // positioning of the control in the xib. |
682 [super drawInteriorWithFrame:NSOffsetRect(cellFrame, 0, lineWidth) | 673 [super drawInteriorWithFrame:NSOffsetRect(cellFrame, 0, lineWidth) |
683 inView:controlView]; | 674 inView:controlView]; |
684 } | 675 } |
685 | |
686 if (overlayImage_) { | |
687 NSRect imageRect = NSZeroRect; | |
688 imageRect.size = [overlayImage_ size]; | |
689 [overlayImage_ drawInRect:[self imageRectForBounds:cellFrame] | |
690 fromRect:imageRect | |
691 operation:NSCompositeSourceOver | |
692 fraction:[self isEnabled] ? 1.0 : 0.5 | |
693 respectFlipped:YES | |
694 hints:nil]; | |
695 } | |
696 } | 676 } |
697 | 677 |
698 - (int)verticalTextOffset { | 678 - (int)verticalTextOffset { |
699 return 1; | 679 return 1; |
700 } | 680 } |
701 | 681 |
702 - (CGFloat)hoverBackgroundVerticalOffsetInControlView:(NSView*)controlView { | 682 - (CGFloat)hoverBackgroundVerticalOffsetInControlView:(NSView*)controlView { |
703 return 0.0; | 683 return 0.0; |
704 } | 684 } |
705 | 685 |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
846 options:options | 826 options:options |
847 owner:self | 827 owner:self |
848 userInfo:nil]); | 828 userInfo:nil]); |
849 if (isMouseInside_ != mouseInView) { | 829 if (isMouseInside_ != mouseInView) { |
850 [self setMouseInside:mouseInView animate:NO]; | 830 [self setMouseInside:mouseInView animate:NO]; |
851 [controlView setNeedsDisplay:YES]; | 831 [controlView setNeedsDisplay:YES]; |
852 } | 832 } |
853 } | 833 } |
854 | 834 |
855 @end | 835 @end |
OLD | NEW |