| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/cocoa/gradient_button_cell.h" | 5 #include "chrome/browser/cocoa/gradient_button_cell.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #import "base/scoped_nsobject.h" | 8 #import "base/scoped_nsobject.h" |
| 9 #import "chrome/browser/browser_theme_provider.h" | 9 #import "chrome/browser/browser_theme_provider.h" |
| 10 #import "chrome/browser/cocoa/image_utils.h" | 10 #import "chrome/browser/cocoa/image_utils.h" |
| 11 #import "chrome/browser/cocoa/themed_window.h" | 11 #import "chrome/browser/cocoa/themed_window.h" |
| 12 #include "grit/theme_resources.h" | 12 #include "grit/theme_resources.h" |
| 13 #import "third_party/GTM/AppKit/GTMNSColor+Luminance.h" | 13 #import "third_party/GTM/AppKit/GTMNSColor+Luminance.h" |
| 14 | 14 |
| 15 @interface GradientButtonCell (Private) | 15 @interface GradientButtonCell (Private) |
| 16 - (void)sharedInit; | 16 - (void)sharedInit; |
| 17 - (void)drawUnderlayImageWithFrame:(NSRect)cellFrame | |
| 18 inView:(NSView*)controlView; | |
| 19 | 17 |
| 20 // Get drawing parameters for a given cell frame in a given view. The inner | 18 // Get drawing parameters for a given cell frame in a given view. The inner |
| 21 // frame is the one required by |-drawInteriorWithFrame:inView:|. The inner and | 19 // frame is the one required by |-drawInteriorWithFrame:inView:|. The inner and |
| 22 // outer paths are the ones required by |-drawBorderAndFillForTheme:...|. The | 20 // outer paths are the ones required by |-drawBorderAndFillForTheme:...|. The |
| 23 // outer path also gives the area in which to clip. Any of the |return...| | 21 // outer path also gives the area in which to clip. Any of the |return...| |
| 24 // arguments may be NULL (in which case the given parameter won't be returned). | 22 // arguments may be NULL (in which case the given parameter won't be returned). |
| 25 // If |returnInnerPath| or |returnOuterPath|, |*returnInnerPath| or | 23 // If |returnInnerPath| or |returnOuterPath|, |*returnInnerPath| or |
| 26 // |*returnOuterPath| should be nil, respectively. | 24 // |*returnOuterPath| should be nil, respectively. |
| 27 - (void)getDrawParamsForFrame:(NSRect)cellFrame | 25 - (void)getDrawParamsForFrame:(NSRect)cellFrame |
| 28 inView:(NSView*)controlView | 26 inView:(NSView*)controlView |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 | 113 |
| 116 - (void)sharedInit { | 114 - (void)sharedInit { |
| 117 shouldTheme_ = YES; | 115 shouldTheme_ = YES; |
| 118 gradient_.reset([[self gradientForHoverAlpha:0.0 isThemed:NO] retain]); | 116 gradient_.reset([[self gradientForHoverAlpha:0.0 isThemed:NO] retain]); |
| 119 } | 117 } |
| 120 | 118 |
| 121 - (void)setShouldTheme:(BOOL)shouldTheme { | 119 - (void)setShouldTheme:(BOOL)shouldTheme { |
| 122 shouldTheme_ = shouldTheme; | 120 shouldTheme_ = shouldTheme; |
| 123 } | 121 } |
| 124 | 122 |
| 125 - (NSImage*)underlayImage { | |
| 126 return underlayImage_; | |
| 127 } | |
| 128 | |
| 129 - (void)setUnderlayImage:(NSImage*)image { | |
| 130 underlayImage_.reset([image retain]); | |
| 131 | |
| 132 [[self controlView] setNeedsDisplay:YES]; | |
| 133 } | |
| 134 | |
| 135 - (NSBackgroundStyle)interiorBackgroundStyle { | 123 - (NSBackgroundStyle)interiorBackgroundStyle { |
| 136 // Never lower the interior, since that just leads to a weird shadow which can | 124 // Never lower the interior, since that just leads to a weird shadow which can |
| 137 // often interact badly with the theme. | 125 // often interact badly with the theme. |
| 138 return NSBackgroundStyleRaised; | 126 return NSBackgroundStyleRaised; |
| 139 } | 127 } |
| 140 | 128 |
| 141 - (void)mouseEntered:(NSEvent*)theEvent { | 129 - (void)mouseEntered:(NSEvent*)theEvent { |
| 142 [self setMouseInside:YES animate:YES]; | 130 [self setMouseInside:YES animate:YES]; |
| 143 } | 131 } |
| 144 | 132 |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 403 if (isTemplate) { | 391 if (isTemplate) { |
| 404 scoped_nsobject<NSShadow> shadow([[NSShadow alloc] init]); | 392 scoped_nsobject<NSShadow> shadow([[NSShadow alloc] init]); |
| 405 NSColor* shadowColor = [color gtm_legibleTextColor]; | 393 NSColor* shadowColor = [color gtm_legibleTextColor]; |
| 406 shadowColor = [shadowColor colorWithAlphaComponent:0.25]; | 394 shadowColor = [shadowColor colorWithAlphaComponent:0.25]; |
| 407 [shadow.get() setShadowColor:shadowColor]; | 395 [shadow.get() setShadowColor:shadowColor]; |
| 408 [shadow.get() setShadowOffset:NSMakeSize(0, -1.0)]; | 396 [shadow.get() setShadowOffset:NSMakeSize(0, -1.0)]; |
| 409 [shadow setShadowBlurRadius:1.0]; | 397 [shadow setShadowBlurRadius:1.0]; |
| 410 [shadow set]; | 398 [shadow set]; |
| 411 } | 399 } |
| 412 | 400 |
| 413 [self drawUnderlayImageWithFrame:cellFrame inView:controlView]; | |
| 414 | |
| 415 CGContextBeginTransparencyLayer(context, 0); | 401 CGContextBeginTransparencyLayer(context, 0); |
| 416 NSRect imageRect = NSZeroRect; | 402 NSRect imageRect = NSZeroRect; |
| 417 imageRect.size = [[self image] size]; | 403 imageRect.size = [[self image] size]; |
| 418 NSRect drawRect = [self imageRectForBounds:cellFrame]; | 404 NSRect drawRect = [self imageRectForBounds:cellFrame]; |
| 419 [[self image] drawInRect:drawRect | 405 [[self image] drawInRect:drawRect |
| 420 fromRect:imageRect | 406 fromRect:imageRect |
| 421 operation:NSCompositeSourceOver | 407 operation:NSCompositeSourceOver |
| 422 fraction:[self isEnabled] ? 1.0 : 0.5 | 408 fraction:[self isEnabled] ? 1.0 : 0.5 |
| 423 neverFlipped:YES]; | 409 neverFlipped:YES]; |
| 424 if (isTemplate) { | 410 if (isTemplate) { |
| 425 if (color) { | 411 if (color) { |
| 426 [color set]; | 412 [color set]; |
| 427 NSRectFillUsingOperation(cellFrame, NSCompositeSourceAtop); | 413 NSRectFillUsingOperation(cellFrame, NSCompositeSourceAtop); |
| 428 } | 414 } |
| 429 } | 415 } |
| 430 | 416 |
| 431 CGContextEndTransparencyLayer(context); | 417 CGContextEndTransparencyLayer(context); |
| 432 [NSGraphicsContext restoreGraphicsState]; | 418 [NSGraphicsContext restoreGraphicsState]; |
| 433 } else { | 419 } else { |
| 434 [self drawUnderlayImageWithFrame:cellFrame inView:controlView]; | |
| 435 | |
| 436 // NSCell draws these uncentered for some reason, probably because of the | 420 // NSCell draws these uncentered for some reason, probably because of the |
| 437 // of control in the xib | 421 // of control in the xib |
| 438 [super drawInteriorWithFrame:NSOffsetRect(cellFrame, 0, 1) | 422 [super drawInteriorWithFrame:NSOffsetRect(cellFrame, 0, 1) |
| 439 inView:controlView]; | 423 inView:controlView]; |
| 440 } | 424 } |
| 441 } | 425 } |
| 442 | 426 |
| 443 - (void)drawUnderlayImageWithFrame:(NSRect)cellFrame | |
| 444 inView:(NSView*)controlView { | |
| 445 if (underlayImage_) { | |
| 446 NSRect imageRect = NSZeroRect; | |
| 447 imageRect.size = [underlayImage_ size]; | |
| 448 [underlayImage_ setFlipped:[controlView isFlipped]]; | |
| 449 [underlayImage_ drawInRect:[self imageRectForBounds:cellFrame] | |
| 450 fromRect:imageRect | |
| 451 operation:NSCompositeSourceOver | |
| 452 fraction:[self isEnabled] ? 1.0 : 0.5]; | |
| 453 } | |
| 454 } | |
| 455 | |
| 456 - (NSBezierPath*)clipPathForFrame:(NSRect)cellFrame | 427 - (NSBezierPath*)clipPathForFrame:(NSRect)cellFrame |
| 457 inView:(NSView*)controlView { | 428 inView:(NSView*)controlView { |
| 458 NSBezierPath* boundingPath = nil; | 429 NSBezierPath* boundingPath = nil; |
| 459 [self getDrawParamsForFrame:cellFrame | 430 [self getDrawParamsForFrame:cellFrame |
| 460 inView:controlView | 431 inView:controlView |
| 461 innerFrame:NULL | 432 innerFrame:NULL |
| 462 innerPath:NULL | 433 innerPath:NULL |
| 463 clipPath:&boundingPath]; | 434 clipPath:&boundingPath]; |
| 464 return boundingPath; | 435 return boundingPath; |
| 465 } | 436 } |
| 466 | 437 |
| 467 @end | 438 @end |
| OLD | NEW |