| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "base/logging.h" | 5 #include "base/logging.h" |
| 6 #import "base/scoped_nsobject.h" | 6 #import "base/scoped_nsobject.h" |
| 7 #include "chrome/browser/cocoa/gradient_button_cell.h" | 7 #include "chrome/browser/cocoa/gradient_button_cell.h" |
| 8 #import "third_party/GTM/AppKit/GTMTheme.h" | 8 #import "third_party/GTM/AppKit/GTMTheme.h" |
| 9 #import "third_party/GTM/AppKit/GTMNSColor+Luminance.h" | 9 #import "third_party/GTM/AppKit/GTMNSColor+Luminance.h" |
| 10 | 10 |
| 11 @interface GradientButtonCell (Private) | 11 @interface GradientButtonCell (Private) |
| 12 - (void)sharedInit; | 12 - (void)sharedInit; |
| 13 - (void)drawUnderlayImageWithFrame:(NSRect)cellFrame | 13 - (void)drawUnderlayImageWithFrame:(NSRect)cellFrame |
| 14 inView:(NSView*)controlView; | 14 inView:(NSView*)controlView; |
| 15 | 15 |
| 16 // Get drawing parameters for a given cell frame in a given view. The inner | 16 // Get drawing parameters for a given cell frame in a given view. The inner |
| 17 // frame is the one required by |-drawInteriorWithFrame:inView:|. The inner and | 17 // frame is the one required by |-drawInteriorWithFrame:inView:|. The inner and |
| 18 // outer paths are the ones required by |-drawBorderAndFillForTheme:...|. The | 18 // outer paths are the ones required by |-drawBorderAndFillForTheme:...|. The |
| 19 // outer path also gives the area in which to clip. Any of the |return...| | 19 // outer path also gives the area in which to clip. Any of the |return...| |
| 20 // arguments may be NULL (in which case the given parameter won't be returned). | 20 // arguments may be NULL (in which case the given parameter won't be returned). |
| 21 // If |returnInnerPath| or |returnOuterPath|, |*returnInnerPath| or | 21 // If |returnInnerPath| or |returnOuterPath|, |*returnInnerPath| or |
| 22 // |*returnOuterPath| should be nil, respectively. | 22 // |*returnOuterPath| should be nil, respectively. |
| 23 - (void)getDrawParamsForFrame:(NSRect)cellFrame | 23 - (void)getDrawParamsForFrame:(NSRect)cellFrame |
| 24 inView:(NSView*)controlView | 24 inView:(NSView*)controlView |
| 25 innerFrame:(NSRect*)returnInnerFrame | 25 innerFrame:(NSRect*)returnInnerFrame |
| 26 innerPath:(NSBezierPath**)returnInnerPath | 26 innerPath:(NSBezierPath**)returnInnerPath |
| 27 outerPath:(NSBezierPath**)returnOuterPath | |
| 28 clipPath:(NSBezierPath**)returnClipPath; | 27 clipPath:(NSBezierPath**)returnClipPath; |
| 29 @end | 28 @end |
| 30 | 29 |
| 31 static const NSTimeInterval kAnimationShowDuration = 0.2; | 30 static const NSTimeInterval kAnimationShowDuration = 0.2; |
| 32 static const NSTimeInterval kAnimationHideDuration = 0.4; | 31 static const NSTimeInterval kAnimationHideDuration = 0.4; |
| 33 | 32 |
| 34 @implementation GradientButtonCell | 33 @implementation GradientButtonCell |
| 35 @synthesize hoverAlpha = hoverAlpha_; | 34 @synthesize hoverAlpha = hoverAlpha_; |
| 36 | 35 |
| 37 - (void)adjustHoverValue { | 36 - (void)adjustHoverValue { |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 [[self controlView] removeTrackingArea:trackingArea_]; | 168 [[self controlView] removeTrackingArea:trackingArea_]; |
| 170 trackingArea_.reset(nil); | 169 trackingArea_.reset(nil); |
| 171 isMouseInside_ = NO; | 170 isMouseInside_ = NO; |
| 172 } | 171 } |
| 173 } | 172 } |
| 174 } | 173 } |
| 175 | 174 |
| 176 // TODO(viettrungluu): clean up/reorganize. | 175 // TODO(viettrungluu): clean up/reorganize. |
| 177 - (void)drawBorderAndFillForTheme:(GTMTheme*)theme | 176 - (void)drawBorderAndFillForTheme:(GTMTheme*)theme |
| 178 controlView:(NSView*)controlView | 177 controlView:(NSView*)controlView |
| 179 outerPath:(NSBezierPath*)outerPath | |
| 180 innerPath:(NSBezierPath*)innerPath | 178 innerPath:(NSBezierPath*)innerPath |
| 181 showClickedGradient:(BOOL)showClickedGradient | 179 showClickedGradient:(BOOL)showClickedGradient |
| 182 showHighlightGradient:(BOOL)showHighlightGradient | 180 showHighlightGradient:(BOOL)showHighlightGradient |
| 183 hoverAlpha:(CGFloat)hoverAlpha | 181 hoverAlpha:(CGFloat)hoverAlpha |
| 184 active:(BOOL)active | 182 active:(BOOL)active |
| 185 cellFrame:(NSRect)cellFrame | 183 cellFrame:(NSRect)cellFrame |
| 186 defaultGradient:(NSGradient*)defaultGradient { | 184 defaultGradient:(NSGradient*)defaultGradient { |
| 187 BOOL isFlatButton = [self showsBorderOnlyWhileMouseInside]; | 185 BOOL isFlatButton = [self showsBorderOnlyWhileMouseInside]; |
| 188 | 186 |
| 189 // For flat (unbordered when not hovered) buttons, never use the toolbar | 187 // For flat (unbordered when not hovered) buttons, never use the toolbar |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 [innerPath setLineWidth:1]; | 270 [innerPath setLineWidth:1]; |
| 273 [innerPath stroke]; | 271 [innerPath stroke]; |
| 274 } | 272 } |
| 275 | 273 |
| 276 // TODO(viettrungluu): clean this up. | 274 // TODO(viettrungluu): clean this up. |
| 277 // (Private) | 275 // (Private) |
| 278 - (void)getDrawParamsForFrame:(NSRect)cellFrame | 276 - (void)getDrawParamsForFrame:(NSRect)cellFrame |
| 279 inView:(NSView*)controlView | 277 inView:(NSView*)controlView |
| 280 innerFrame:(NSRect*)returnInnerFrame | 278 innerFrame:(NSRect*)returnInnerFrame |
| 281 innerPath:(NSBezierPath**)returnInnerPath | 279 innerPath:(NSBezierPath**)returnInnerPath |
| 282 outerPath:(NSBezierPath**)returnOuterPath | |
| 283 clipPath:(NSBezierPath**)returnClipPath { | 280 clipPath:(NSBezierPath**)returnClipPath { |
| 284 // Constants from Cole. Will kConstant them once the feedback loop | 281 // Constants from Cole. Will kConstant them once the feedback loop |
| 285 // is complete. | 282 // is complete. |
| 286 NSRect drawFrame = NSInsetRect(cellFrame, 1.5, 1.5); | 283 NSRect drawFrame = NSInsetRect(cellFrame, 1.5, 1.5); |
| 287 NSRect innerFrame = NSInsetRect(cellFrame, 2, 1); | 284 NSRect innerFrame = NSInsetRect(cellFrame, 2, 1); |
| 288 const CGFloat radius = 3.5; | 285 const CGFloat radius = 3.5; |
| 289 | 286 |
| 290 ButtonType type = [[(NSControl*)controlView cell] tag]; | 287 ButtonType type = [[(NSControl*)controlView cell] tag]; |
| 291 switch (type) { | 288 switch (type) { |
| 292 case kMiddleButtonType: | 289 case kMiddleButtonType: |
| (...skipping 16 matching lines...) Expand all Loading... |
| 309 | 306 |
| 310 // Return results if |return...| not null. | 307 // Return results if |return...| not null. |
| 311 if (returnInnerFrame) | 308 if (returnInnerFrame) |
| 312 *returnInnerFrame = innerFrame; | 309 *returnInnerFrame = innerFrame; |
| 313 if (returnInnerPath) { | 310 if (returnInnerPath) { |
| 314 DCHECK(*returnInnerPath == nil); | 311 DCHECK(*returnInnerPath == nil); |
| 315 *returnInnerPath = [NSBezierPath bezierPathWithRoundedRect:drawFrame | 312 *returnInnerPath = [NSBezierPath bezierPathWithRoundedRect:drawFrame |
| 316 xRadius:radius | 313 xRadius:radius |
| 317 yRadius:radius]; | 314 yRadius:radius]; |
| 318 } | 315 } |
| 319 if (returnOuterPath) { | |
| 320 DCHECK(*returnOuterPath == nil); | |
| 321 NSRect outerPathRect = NSInsetRect(drawFrame, -1, -1); | |
| 322 *returnOuterPath = [NSBezierPath bezierPathWithRoundedRect:outerPathRect | |
| 323 xRadius:radius + 1 | |
| 324 yRadius:radius + 1]; | |
| 325 } | |
| 326 if (returnClipPath) { | 316 if (returnClipPath) { |
| 327 DCHECK(*returnClipPath == nil); | 317 DCHECK(*returnClipPath == nil); |
| 328 NSRect clipPathRect = NSInsetRect(drawFrame, -0.5, -0.5); | 318 NSRect clipPathRect = NSInsetRect(drawFrame, -0.5, -0.5); |
| 329 *returnClipPath = [NSBezierPath bezierPathWithRoundedRect:clipPathRect | 319 *returnClipPath = [NSBezierPath bezierPathWithRoundedRect:clipPathRect |
| 330 xRadius:radius + 0.5 | 320 xRadius:radius + 0.5 |
| 331 yRadius:radius + 0.5]; | 321 yRadius:radius + 0.5]; |
| 332 } | 322 } |
| 333 } | 323 } |
| 334 | 324 |
| 335 // TODO(viettrungluu): clean this up. | 325 // TODO(viettrungluu): clean this up. |
| 336 - (void)drawWithFrame:(NSRect)cellFrame inView:(NSView*)controlView { | 326 - (void)drawWithFrame:(NSRect)cellFrame inView:(NSView*)controlView { |
| 337 NSRect innerFrame; | 327 NSRect innerFrame; |
| 338 NSBezierPath* innerPath = nil; | 328 NSBezierPath* innerPath = nil; |
| 339 NSBezierPath* outerPath = nil; | |
| 340 [self getDrawParamsForFrame:cellFrame | 329 [self getDrawParamsForFrame:cellFrame |
| 341 inView:controlView | 330 inView:controlView |
| 342 innerFrame:&innerFrame | 331 innerFrame:&innerFrame |
| 343 innerPath:&innerPath | 332 innerPath:&innerPath |
| 344 outerPath:&outerPath | |
| 345 clipPath:NULL]; | 333 clipPath:NULL]; |
| 346 | 334 |
| 347 BOOL pressed = [self isHighlighted]; | 335 BOOL pressed = [self isHighlighted]; |
| 348 NSWindow* window = [controlView window]; | 336 NSWindow* window = [controlView window]; |
| 349 BOOL active = [window isKeyWindow] || [window isMainWindow]; | 337 BOOL active = [window isKeyWindow] || [window isMainWindow]; |
| 350 | 338 |
| 351 GTMTheme* theme = [controlView gtm_theme]; | 339 GTMTheme* theme = [controlView gtm_theme]; |
| 352 | 340 |
| 353 // Stroke the borders and appropriate fill gradient. If we're borderless, | 341 // Stroke the borders and appropriate fill gradient. If we're borderless, |
| 354 // the only time we want to draw the inner gradient is if we're highlighted. | 342 // the only time we want to draw the inner gradient is if we're highlighted. |
| 355 if (([self isBordered] && ![self showsBorderOnlyWhileMouseInside]) || | 343 if (([self isBordered] && ![self showsBorderOnlyWhileMouseInside]) || |
| 356 pressed || | 344 pressed || |
| 357 [self isMouseInside]) { | 345 [self isMouseInside]) { |
| 358 | 346 |
| 359 [self drawBorderAndFillForTheme:theme | 347 [self drawBorderAndFillForTheme:theme |
| 360 controlView:controlView | 348 controlView:controlView |
| 361 outerPath:outerPath | |
| 362 innerPath:innerPath | 349 innerPath:innerPath |
| 363 showClickedGradient:pressed | 350 showClickedGradient:pressed |
| 364 showHighlightGradient:[self isHighlighted] | 351 showHighlightGradient:[self isHighlighted] |
| 365 hoverAlpha:[self hoverAlpha] | 352 hoverAlpha:[self hoverAlpha] |
| 366 active:active | 353 active:active |
| 367 cellFrame:cellFrame | 354 cellFrame:cellFrame |
| 368 defaultGradient:nil]; | 355 defaultGradient:nil]; |
| 369 } | 356 } |
| 370 | 357 |
| 371 // If this is the left side of a segmented button, draw a slight shadow. | 358 // If this is the left side of a segmented button, draw a slight shadow. |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 449 } | 436 } |
| 450 } | 437 } |
| 451 | 438 |
| 452 - (NSBezierPath*)clipPathForFrame:(NSRect)cellFrame | 439 - (NSBezierPath*)clipPathForFrame:(NSRect)cellFrame |
| 453 inView:(NSView*)controlView { | 440 inView:(NSView*)controlView { |
| 454 NSBezierPath* boundingPath = nil; | 441 NSBezierPath* boundingPath = nil; |
| 455 [self getDrawParamsForFrame:cellFrame | 442 [self getDrawParamsForFrame:cellFrame |
| 456 inView:controlView | 443 inView:controlView |
| 457 innerFrame:NULL | 444 innerFrame:NULL |
| 458 innerPath:NULL | 445 innerPath:NULL |
| 459 outerPath:NULL | |
| 460 clipPath:&boundingPath]; | 446 clipPath:&boundingPath]; |
| 461 return boundingPath; | 447 return boundingPath; |
| 462 } | 448 } |
| 463 | 449 |
| 464 @end | 450 @end |
| OLD | NEW |