Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #import "chrome/browser/ui/cocoa/new_tab_button.h" | 5 #import "chrome/browser/ui/cocoa/new_tab_button.h" |
| 6 | 6 |
| 7 #include "base/mac/foundation_util.h" | 7 #include "base/mac/foundation_util.h" |
| 8 #include "base/mac/sdk_forward_declarations.h" | 8 #include "base/mac/sdk_forward_declarations.h" |
| 9 #import "chrome/browser/ui/cocoa/image_button_cell.h" | 9 #import "chrome/browser/ui/cocoa/image_button_cell.h" |
| 10 #include "chrome/browser/ui/cocoa/tabs/tab_view.h" | 10 #include "chrome/browser/ui/cocoa/tabs/tab_view.h" |
| 11 #include "grit/theme_resources.h" | 11 #include "grit/theme_resources.h" |
| 12 #include "ui/base/cocoa/nsgraphics_context_additions.h" | 12 #include "ui/base/cocoa/nsgraphics_context_additions.h" |
| 13 #include "ui/base/material_design/material_design_controller.h" | 13 #include "ui/base/material_design/material_design_controller.h" |
| 14 #include "ui/base/resource/resource_bundle.h" | 14 #include "ui/base/resource/resource_bundle.h" |
| 15 #include "ui/base/theme_provider.h" | 15 #include "ui/base/theme_provider.h" |
| 16 | 16 |
| 17 @class NewTabButtonCell; | 17 @class NewTabButtonCell; |
| 18 | 18 |
| 19 namespace { | 19 namespace { |
| 20 | 20 |
| 21 enum class RenderingOption { | 21 enum class OverlayOption { |
| 22 NORMAL, | 22 NONE, |
| 23 OVERLAY_LIGHTEN, | 23 LIGHTEN, |
| 24 OVERLAY_LIGHTEN_INCOGNITO, | 24 DARKEN, |
| 25 OVERLAY_DARKEN, | |
| 26 INLAY_LIGHTEN, | |
| 27 }; | 25 }; |
| 28 | 26 |
| 27 const NSSize newTabButtonImageSize = NSMakeSize(34, 18); | |
|
Avi (use Gerrit)
2016/05/12 01:46:38
Is this a static initializer? NSMakeSize is a func
shrike
2016/05/12 02:37:19
I thought NSMakeSize was a non-function macro.
Avi (use Gerrit)
2016/05/12 02:46:09
In my 10.11 SDK's NSGeometry.h it has:
NS_INLINE
shrike
2016/05/12 02:50:00
Yeah, I checked after you pointed it out.
| |
| 28 | |
| 29 const CGFloat k7PercentAlpha = 0.07; | |
| 30 const CGFloat k8PercentAlpha = 0.08; | |
| 31 const CGFloat k10PercentAlpha = 0.1; | |
| 32 const CGFloat k20PercentAlpha = 0.2; | |
| 33 const CGFloat k25PercentAlpha = 0.25; | |
| 34 | |
| 29 NSImage* GetMaskImageFromCell(NewTabButtonCell* aCell) { | 35 NSImage* GetMaskImageFromCell(NewTabButtonCell* aCell) { |
| 30 if (!ui::MaterialDesignController::IsModeMaterial()) { | 36 if (!ui::MaterialDesignController::IsModeMaterial()) { |
| 31 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | 37 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
| 32 return bundle.GetNativeImageNamed(IDR_NEWTAB_BUTTON_MASK).ToNSImage(); | 38 return bundle.GetNativeImageNamed(IDR_NEWTAB_BUTTON_MASK).ToNSImage(); |
| 33 } | 39 } |
| 34 return [aCell imageForState:image_button_cell::kDefaultState view:nil]; | 40 return [aCell imageForState:image_button_cell::kDefaultState view:nil]; |
| 35 } | 41 } |
| 36 | 42 |
| 37 // Creates an NSImage with size |size| and bitmap image representations for both | 43 // Creates an NSImage with size |size| and bitmap image representations for both |
| 38 // 1x and 2x scale factors. |drawingHandler| is called once for every scale | 44 // 1x and 2x scale factors. |drawingHandler| is called once for every scale |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 126 CGRect deviceRect = CGContextConvertRectToDeviceSpace(context, unitRect); | 132 CGRect deviceRect = CGContextConvertRectToDeviceSpace(context, unitRect); |
| 127 return 1.0 / deviceRect.size.height; | 133 return 1.0 / deviceRect.size.height; |
| 128 } | 134 } |
| 129 | 135 |
| 130 } // namespace | 136 } // namespace |
| 131 | 137 |
| 132 @interface NewTabButtonCustomImageRep : NSCustomImageRep | 138 @interface NewTabButtonCustomImageRep : NSCustomImageRep |
| 133 @property (assign, nonatomic) NSView* destView; | 139 @property (assign, nonatomic) NSView* destView; |
| 134 @property (copy, nonatomic) NSColor* fillColor; | 140 @property (copy, nonatomic) NSColor* fillColor; |
| 135 @property (assign, nonatomic) NSPoint patternPhasePosition; | 141 @property (assign, nonatomic) NSPoint patternPhasePosition; |
| 136 @property (assign, nonatomic) RenderingOption renderingOption; | 142 @property (assign, nonatomic) OverlayOption overlayOption; |
| 137 @end | 143 @end |
| 138 | 144 |
| 139 @implementation NewTabButtonCustomImageRep | 145 @implementation NewTabButtonCustomImageRep |
| 140 | 146 |
| 141 @synthesize destView = destView_; | 147 @synthesize destView = destView_; |
| 142 @synthesize fillColor = fillColor_; | 148 @synthesize fillColor = fillColor_; |
| 143 @synthesize patternPhasePosition = patternPhasePosition_; | 149 @synthesize patternPhasePosition = patternPhasePosition_; |
| 144 @synthesize renderingOption = renderingOption_; | 150 @synthesize overlayOption = overlayOption_; |
| 145 | 151 |
| 146 - (void)dealloc { | 152 - (void)dealloc { |
| 147 [fillColor_ release]; | 153 [fillColor_ release]; |
| 148 [super dealloc]; | 154 [super dealloc]; |
| 149 } | 155 } |
| 150 | 156 |
| 151 @end | 157 @end |
| 152 | 158 |
| 153 // A simple override of the ImageButtonCell to disable handling of | 159 // A simple override of the ImageButtonCell to disable handling of |
| 154 // -mouseEntered. | 160 // -mouseEntered. |
| 155 @interface NewTabButtonCell : ImageButtonCell | 161 @interface NewTabButtonCell : ImageButtonCell |
| 156 | 162 |
| 157 - (void)mouseEntered:(NSEvent*)theEvent; | 163 - (void)mouseEntered:(NSEvent*)theEvent; |
| 158 | 164 |
| 159 @end | 165 @end |
| 160 | 166 |
| 161 @implementation NewTabButtonCell | 167 @implementation NewTabButtonCell |
| 162 | 168 |
| 163 - (void)mouseEntered:(NSEvent*)theEvent { | 169 - (void)mouseEntered:(NSEvent*)theEvent { |
| 164 // Ignore this since the NTB enter is handled by the TabStripController. | 170 // Ignore this since the NTB enter is handled by the TabStripController. |
| 165 } | 171 } |
| 166 | 172 |
| 167 - (void)drawFocusRingMaskWithFrame:(NSRect)cellFrame inView:(NSView*)view { | 173 - (void)drawFocusRingMaskWithFrame:(NSRect)cellFrame inView:(NSView*)view { |
| 168 // Match the button's shape. | 174 // Match the button's shape. |
| 169 [self drawImage:GetMaskImageFromCell(self) withFrame:cellFrame inView:view]; | 175 [self drawImage:GetMaskImageFromCell(self) withFrame:cellFrame inView:view]; |
| 170 } | 176 } |
| 171 | 177 |
| 172 @end | 178 @end |
| 173 | 179 |
| 180 @interface NewTabButton() | |
| 181 | |
| 182 // Returns a new tab button image appropriate for the specified button state | |
| 183 // (e.g. hover) and theme. In Material Design, the theme color affects the | |
| 184 // button color. | |
| 185 - (NSImage*)imageForState:(image_button_cell::ButtonState)state | |
| 186 theme:(const ui::ThemeProvider*)theme; | |
| 187 | |
| 188 // Returns a new tab button image bezier path with the specified line width. | |
| 189 + (NSBezierPath*)newTabButtonBezierPathWithLineWidth:(CGFloat)lineWidth; | |
| 190 | |
| 191 // NSCustomImageRep custom drawing method that renders the new tab button image. | |
| 192 + (void)drawNewTabButtonImage:(NewTabButtonCustomImageRep*)imageRep; | |
| 193 | |
| 194 // Returns a new tab button image filled with |fillColor|. | |
| 195 - (NSImage*)imageWithFillColor:(NSColor*)fillColor; | |
| 196 | |
| 197 @end | |
| 174 | 198 |
| 175 @implementation NewTabButton | 199 @implementation NewTabButton |
| 176 | 200 |
| 177 + (Class)cellClass { | 201 + (Class)cellClass { |
| 178 return [NewTabButtonCell class]; | 202 return [NewTabButtonCell class]; |
| 179 } | 203 } |
| 180 | 204 |
| 181 - (BOOL)pointIsOverButton:(NSPoint)point { | 205 - (BOOL)pointIsOverButton:(NSPoint)point { |
| 182 NSPoint localPoint = [self convertPoint:point fromView:[self superview]]; | 206 NSPoint localPoint = [self convertPoint:point fromView:[self superview]]; |
| 183 NSRect pointRect = NSMakeRect(localPoint.x, localPoint.y, 1, 1); | 207 NSRect pointRect = NSMakeRect(localPoint.x, localPoint.y, 1, 1); |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 297 [cell setImage:pressed forButtonState:image_button_cell::kPressedState]; | 321 [cell setImage:pressed forButtonState:image_button_cell::kPressedState]; |
| 298 [cell setImage:normalBackground | 322 [cell setImage:normalBackground |
| 299 forButtonState:image_button_cell::kDefaultStateBackground]; | 323 forButtonState:image_button_cell::kDefaultStateBackground]; |
| 300 [cell setImage:hoverBackground | 324 [cell setImage:hoverBackground |
| 301 forButtonState:image_button_cell::kHoverStateBackground]; | 325 forButtonState:image_button_cell::kHoverStateBackground]; |
| 302 } | 326 } |
| 303 | 327 |
| 304 - (NSImage*)imageForState:(image_button_cell::ButtonState)state | 328 - (NSImage*)imageForState:(image_button_cell::ButtonState)state |
| 305 theme:(const ui::ThemeProvider*)theme { | 329 theme:(const ui::ThemeProvider*)theme { |
| 306 NSColor* fillColor = nil; | 330 NSColor* fillColor = nil; |
| 307 RenderingOption renderingOption = RenderingOption::NORMAL; | 331 OverlayOption overlayOption = OverlayOption::NONE; |
| 308 | 332 |
| 309 switch (state) { | 333 switch (state) { |
| 310 case image_button_cell::kDefaultState: | 334 case image_button_cell::kDefaultState: |
| 335 // In the normal state, the NTP button looks like a background tab. | |
| 311 fillColor = theme->GetNSImageColorNamed(IDR_THEME_TAB_BACKGROUND); | 336 fillColor = theme->GetNSImageColorNamed(IDR_THEME_TAB_BACKGROUND); |
| 312 break; | 337 break; |
| 313 | 338 |
| 314 case image_button_cell::kHoverState: | 339 case image_button_cell::kHoverState: |
| 315 fillColor = theme->GetNSImageColorNamed(IDR_THEME_TAB_BACKGROUND); | 340 fillColor = theme->GetNSImageColorNamed(IDR_THEME_TAB_BACKGROUND); |
| 316 // When a custom theme highlight the entire area, otherwise only | 341 overlayOption = OverlayOption::LIGHTEN; |
| 317 // highlight the interior and not the border. | |
| 318 if (theme->HasCustomImage(IDR_THEME_TAB_BACKGROUND)) { | |
| 319 renderingOption = RenderingOption::OVERLAY_LIGHTEN; | |
| 320 } else if (theme->InIncognitoMode()) { | |
| 321 renderingOption = RenderingOption::OVERLAY_LIGHTEN_INCOGNITO; | |
| 322 } else { | |
| 323 renderingOption = RenderingOption::INLAY_LIGHTEN; | |
| 324 } | |
| 325 | 342 |
| 326 break; | 343 break; |
| 327 | 344 |
| 328 case image_button_cell::kPressedState: | 345 case image_button_cell::kPressedState: |
| 329 fillColor = theme->GetNSImageColorNamed(IDR_THEME_TAB_BACKGROUND); | 346 fillColor = theme->GetNSImageColorNamed(IDR_THEME_TAB_BACKGROUND); |
| 347 overlayOption = OverlayOption::DARKEN; | |
| 330 break; | 348 break; |
| 331 | 349 |
| 332 case image_button_cell::kDefaultStateBackground: | 350 case image_button_cell::kDefaultStateBackground: |
| 333 case image_button_cell::kHoverStateBackground: | 351 case image_button_cell::kHoverStateBackground: |
| 334 fillColor = | 352 fillColor = |
| 335 theme->GetNSImageColorNamed(IDR_THEME_TAB_BACKGROUND_INACTIVE); | 353 theme->GetNSImageColorNamed(IDR_THEME_TAB_BACKGROUND_INACTIVE); |
| 336 break; | 354 break; |
| 337 | 355 |
| 338 default: | 356 default: |
| 339 fillColor = [NSColor redColor]; | 357 fillColor = [NSColor redColor]; |
| 340 // All states should be accounted for above. | 358 // All states should be accounted for above. |
| 341 NOTREACHED(); | 359 NOTREACHED(); |
| 342 } | 360 } |
| 343 | 361 |
| 344 base::scoped_nsobject<NewTabButtonCustomImageRep> imageRep = | 362 base::scoped_nsobject<NewTabButtonCustomImageRep> imageRep = |
| 345 [[NewTabButtonCustomImageRep alloc] | 363 [[NewTabButtonCustomImageRep alloc] |
| 346 initWithDrawSelector:@selector(drawNewTabButtonImage:) | 364 initWithDrawSelector:@selector(drawNewTabButtonImage:) |
| 347 delegate:[NewTabButton class]]; | 365 delegate:[NewTabButton class]]; |
| 348 [imageRep setDestView:self]; | 366 [imageRep setDestView:self]; |
| 349 [imageRep setFillColor:fillColor]; | 367 [imageRep setFillColor:fillColor]; |
| 350 [imageRep setPatternPhasePosition: | 368 [imageRep setPatternPhasePosition: |
| 351 [[self window] | 369 [[self window] |
| 352 themeImagePositionForAlignment:THEME_IMAGE_ALIGN_WITH_TAB_STRIP]]; | 370 themeImagePositionForAlignment:THEME_IMAGE_ALIGN_WITH_TAB_STRIP]]; |
| 353 [imageRep setRenderingOption:renderingOption]; | 371 [imageRep setOverlayOption:overlayOption]; |
| 354 | 372 |
| 355 NSImage* newTabButtonImage = | 373 NSImage* newTabButtonImage = |
| 356 [[[NSImage alloc] initWithSize:NSMakeSize(34, 17)] autorelease]; | 374 [[[NSImage alloc] initWithSize:newTabButtonImageSize] autorelease]; |
| 357 [newTabButtonImage setCacheMode:NSImageCacheAlways]; | 375 [newTabButtonImage setCacheMode:NSImageCacheAlways]; |
| 358 [newTabButtonImage addRepresentation:imageRep]; | 376 [newTabButtonImage addRepresentation:imageRep]; |
| 359 | 377 |
| 360 return newTabButtonImage; | 378 return newTabButtonImage; |
| 361 } | 379 } |
| 362 | 380 |
| 363 + (NSBezierPath*)newTabButtonBezierPathWithInset:(int)inset | 381 + (NSBezierPath*)newTabButtonBezierPathWithLineWidth:(CGFloat)lineWidth { |
| 364 lineWidth:(CGFloat)lineWidth { | |
| 365 NSBezierPath* bezierPath = [NSBezierPath bezierPath]; | 382 NSBezierPath* bezierPath = [NSBezierPath bezierPath]; |
| 366 | 383 |
| 367 // Bottom edge. | 384 // This data comes straight from the SVG. |
| 368 [bezierPath moveToPoint:NSMakePoint(19 - inset, 1.2825 + inset)]; | 385 [bezierPath moveToPoint:NSMakePoint(15.2762236,30)]; |
| 369 [bezierPath lineToPoint:NSMakePoint(10.45 + inset, 1.2825 + inset)]; | |
| 370 | 386 |
| 371 // Lower-left corner. | 387 [bezierPath curveToPoint:NSMakePoint(11.0354216,27.1770115) |
| 372 [bezierPath curveToPoint:NSMakePoint(6.08 + inset, 2.85 + inset) | 388 controlPoint1:NSMakePoint(13.3667706,30) |
| 373 controlPoint1:NSMakePoint(10.1664 + inset, 1.3965 + inset) | 389 controlPoint2:NSMakePoint(11.7297681,28.8344828)]; |
| 374 controlPoint2:NSMakePoint(7.89222 + inset, 0.787708 + inset)]; | |
| 375 | 390 |
| 376 // Left side. | 391 [bezierPath curveToPoint:NSMakePoint(7.28528951e-08,2.01431416) |
| 377 [bezierPath lineToPoint:NSMakePoint(0.7125 + inset, 14.25 - inset)]; | 392 controlPoint1:NSMakePoint(11.0354216,27.1770115) |
| 393 controlPoint2:NSMakePoint(0.000412425082,3.87955717)]; | |
| 378 | 394 |
| 379 // Upper-left corner. | 395 [bezierPath curveToPoint:NSMakePoint(1.70510791,0) |
| 380 const float topEdgeY = 16.2688; | 396 controlPoint1:NSMakePoint(-0.000270516213,0.790325707) |
| 381 [bezierPath curveToPoint:NSMakePoint(1.71 + inset, topEdgeY - inset) | 397 controlPoint2:NSMakePoint(0.753255356,0)]; |
| 382 controlPoint1:NSMakePoint(0.246496 + inset, 15.2613 - inset) | |
| 383 controlPoint2:NSMakePoint(0.916972 + inset, 16.3489 - inset)]; | |
| 384 | 398 |
| 385 // Top edge. | 399 [bezierPath lineToPoint:NSMakePoint(48.7033642,0)]; |
| 386 [bezierPath lineToPoint:NSMakePoint(23.275 - inset, topEdgeY - inset)]; | |
| 387 | 400 |
| 388 // Upper right corner. | 401 [bezierPath curveToPoint:NSMakePoint(52.9464653,2.82643678) |
| 389 [bezierPath curveToPoint:NSMakePoint(27.645 - inset, 14.7012 - inset) | 402 controlPoint1:NSMakePoint(50.6151163,0) |
| 390 controlPoint1:NSMakePoint(26.4376 - inset, 16.3305 - inset) | 403 controlPoint2:NSMakePoint(52.2521188,1.16666667)]; |
| 391 controlPoint2:NSMakePoint(26.9257 - inset, 15.8059 - inset)]; | |
| 392 | 404 |
| 393 // Right side. | 405 [bezierPath curveToPoint:NSMakePoint(64.0268555,27.5961914) |
| 394 [bezierPath lineToPoint:NSMakePoint(32.9543 - inset, 3.62561 + inset)]; | 406 controlPoint1:NSMakePoint(52.9464653,2.82643678) |
| 407 controlPoint2:NSMakePoint(64.0268555,27.4111339)]; | |
| 395 | 408 |
| 396 // Lower right corner. | 409 [bezierPath curveToPoint:NSMakePoint(62.2756294,30) |
| 397 [bezierPath curveToPoint:NSMakePoint(32.015 - inset, 1.2825 + inset) | 410 controlPoint1:NSMakePoint(64.0268555,28.5502144) |
| 398 controlPoint1:NSMakePoint(34.069 - inset, 1.45303 + inset) | 411 controlPoint2:NSMakePoint(63.227482,29.9977011)]; |
| 399 controlPoint2:NSMakePoint(31.0348 - inset, 1.31455 + inset)]; | |
| 400 | 412 |
| 401 [bezierPath closePath]; | 413 [bezierPath closePath]; |
| 402 | 414 |
| 403 // On non-Retina machines, adjust the path so that the top line rests along | 415 // The SVG path is flipped for some reason, so flip it back. |
| 404 // a pixel line (to get a crisp line on the display). | 416 const CGFloat kSVGHeight = 32; |
| 405 if (lineWidth == 1) { | 417 NSAffineTransformStruct flipStruct = { 1, 0, 0, -1, 0, kSVGHeight }; |
| 406 NSAffineTransform* translateTransform = [NSAffineTransform transform]; | 418 NSAffineTransform* flipTransform = [NSAffineTransform transform]; |
| 407 [translateTransform translateXBy:0 | 419 [flipTransform setTransformStruct:flipStruct]; |
| 408 yBy:0.5 - (topEdgeY - trunc(topEdgeY))]; | 420 [bezierPath transformUsingAffineTransform:flipTransform]; |
| 409 [bezierPath transformUsingAffineTransform:translateTransform]; | 421 |
| 410 } | 422 // The SVG data is for the 2x version so scale it down. |
| 423 NSAffineTransform* scaleTransform = [NSAffineTransform transform]; | |
| 424 const CGFloat k50PercentScale = 0.5; | |
| 425 [scaleTransform scaleBy:k50PercentScale]; | |
| 426 [bezierPath transformUsingAffineTransform:scaleTransform]; | |
| 427 | |
| 428 // Adjust by half the line width to get crisp lines. | |
| 429 NSAffineTransform* transform = [NSAffineTransform transform]; | |
| 430 [transform translateXBy:lineWidth / 2 yBy:lineWidth / 2]; | |
| 431 [bezierPath transformUsingAffineTransform:transform]; | |
| 411 | 432 |
| 412 [bezierPath setLineWidth:lineWidth]; | 433 [bezierPath setLineWidth:lineWidth]; |
| 413 | 434 |
| 414 return bezierPath; | 435 return bezierPath; |
| 415 } | 436 } |
| 416 | 437 |
| 417 + (void)drawNewTabButtonImage:(NewTabButtonCustomImageRep*)imageRep { | 438 + (void)drawNewTabButtonImage:(NewTabButtonCustomImageRep*)imageRep { |
| 418 [[NSGraphicsContext currentContext] | 439 [[NSGraphicsContext currentContext] |
| 419 cr_setPatternPhase:[imageRep patternPhasePosition] | 440 cr_setPatternPhase:[imageRep patternPhasePosition] |
| 420 forView:[imageRep destView]]; | 441 forView:[imageRep destView]]; |
| 421 | 442 |
| 422 CGContextRef context = static_cast<CGContextRef>( | 443 CGContextRef context = static_cast<CGContextRef>( |
| 423 [[NSGraphicsContext currentContext] graphicsPort]); | 444 [[NSGraphicsContext currentContext] graphicsPort]); |
| 424 CGFloat lineWidth = LineWidthFromContext(context); | 445 CGFloat lineWidth = LineWidthFromContext(context); |
| 425 NSBezierPath* bezierPath = [self newTabButtonBezierPathWithInset:0 | 446 NSBezierPath* bezierPath = |
| 426 lineWidth:lineWidth]; | 447 [self newTabButtonBezierPathWithLineWidth:lineWidth]; |
| 427 | 448 |
| 428 if ([imageRep fillColor]) { | 449 if ([imageRep fillColor]) { |
| 429 [[imageRep fillColor] set]; | 450 [[imageRep fillColor] set]; |
| 430 [bezierPath fill]; | 451 [bezierPath fill]; |
| 431 } | 452 } |
| 432 | 453 |
| 433 static NSColor* strokeColor = | 454 static NSColor* strokeColor = |
| 434 [[NSColor colorWithCalibratedWhite:0 alpha:0.4] retain]; | 455 [[NSColor colorWithCalibratedWhite:0 alpha:k25PercentAlpha] retain]; |
| 435 [strokeColor set]; | 456 [strokeColor set]; |
| 436 [bezierPath stroke]; | 457 [bezierPath stroke]; |
| 437 | 458 |
| 438 // Bottom edge. | 459 // Bottom edge. |
| 439 bezierPath = [NSBezierPath bezierPath]; | 460 const CGFloat kBottomEdgeX = 9; |
| 440 [bezierPath moveToPoint:NSMakePoint(31, 1.2825)]; | 461 const CGFloat kBottomEdgeY = 1.2825; |
| 441 [bezierPath lineToPoint:NSMakePoint(9, 1.2825)]; | 462 const CGFloat kBottomEdgeWidth = 22; |
| 463 NSPoint bottomEdgeStart = NSMakePoint(kBottomEdgeX, kBottomEdgeY); | |
| 464 NSPoint bottomEdgeEnd = NSMakePoint(kBottomEdgeX + kBottomEdgeWidth, | |
| 465 kBottomEdgeY); | |
| 466 NSBezierPath* bottomEdgePath = [NSBezierPath bezierPath]; | |
| 467 [bottomEdgePath moveToPoint:bottomEdgeStart]; | |
| 468 [bottomEdgePath lineToPoint:bottomEdgeEnd]; | |
| 442 static NSColor* bottomEdgeColor = | 469 static NSColor* bottomEdgeColor = |
| 443 [[NSColor colorWithCalibratedWhite:0.25 alpha:0.3] retain]; | 470 [[NSColor colorWithCalibratedWhite:0 alpha:k7PercentAlpha] retain]; |
| 444 [bottomEdgeColor set]; | 471 [bottomEdgeColor set]; |
| 445 [bezierPath setLineWidth:lineWidth]; | 472 [bottomEdgePath setLineWidth:lineWidth]; |
| 446 [bezierPath setLineCapStyle:NSRoundLineCapStyle]; | 473 [bottomEdgePath setLineCapStyle:NSRoundLineCapStyle]; |
| 447 [bezierPath stroke]; | 474 [bottomEdgePath stroke]; |
| 448 | 475 |
| 449 // Shadow beneath the bottom edge. | 476 CGPoint shadowStart = NSZeroPoint; |
| 450 NSAffineTransform* translateTransform = [NSAffineTransform transform]; | 477 CGPoint shadowEnd = NSZeroPoint; |
| 451 [translateTransform translateXBy:0 yBy:-lineWidth]; | 478 NSColor* overlayColor = nil; |
| 452 [bezierPath transformUsingAffineTransform:translateTransform]; | 479 const CGFloat kBottomShadowX = 8; |
| 453 static NSColor* shadowColor = | 480 const CGFloat kBottomShadowY = kBottomEdgeY - lineWidth; |
| 454 [[NSColor colorWithCalibratedWhite:0.5 alpha:0.3] retain]; | 481 const CGFloat kTopShadowX = 1; |
| 455 [shadowColor set]; | 482 const CGFloat kTopShadowY = kBottomShadowY + 15; |
| 456 [bezierPath stroke]; | 483 const CGFloat kShadowWidth = 24; |
| 484 static NSColor* lightOverlayColor = | |
| 485 [[NSColor colorWithCalibratedWhite:1 alpha:k20PercentAlpha] retain]; | |
| 486 static NSColor* darkOverlayColor = | |
| 487 [[NSColor colorWithCalibratedWhite:0 alpha:k8PercentAlpha] retain]; | |
| 457 | 488 |
| 458 static NSColor* lightColor = | 489 switch ([imageRep overlayOption]) { |
| 459 [[NSColor colorWithCalibratedWhite:1 alpha:0.35] retain]; | 490 case OverlayOption::LIGHTEN: |
| 460 static NSColor* lightIncognitoColor = | 491 overlayColor = lightOverlayColor; |
| 461 [[NSColor colorWithCalibratedWhite:1 alpha:0.15] retain]; | |
| 462 static NSColor* darkColor = | |
| 463 [[NSColor colorWithCalibratedWhite:0 alpha:0.08] retain]; | |
| 464 | |
| 465 CGFloat inset = -1; | |
| 466 switch ([imageRep renderingOption]) { | |
| 467 case RenderingOption::OVERLAY_LIGHTEN: | |
| 468 [lightColor set]; | |
| 469 inset = 0; | |
| 470 break; | 492 break; |
| 471 | 493 |
| 472 case RenderingOption::OVERLAY_LIGHTEN_INCOGNITO: | 494 case OverlayOption::DARKEN: |
| 473 [lightIncognitoColor set]; | 495 overlayColor = darkOverlayColor; |
| 474 inset = 0; | 496 shadowStart = NSMakePoint(kTopShadowX, kTopShadowY); |
| 497 shadowEnd = NSMakePoint(kTopShadowX + kShadowWidth, kTopShadowY); | |
| 475 break; | 498 break; |
| 476 | 499 |
| 477 case RenderingOption::OVERLAY_DARKEN: | 500 case OverlayOption::NONE: |
| 478 [darkColor set]; | 501 shadowStart = NSMakePoint(kBottomShadowX, kBottomShadowY); |
| 479 NSRectFillUsingOperation(NSMakeRect(0, 0, 34, 17), NSCompositeSourceAtop); | 502 shadowEnd = NSMakePoint(kBottomShadowX + kShadowWidth, kBottomShadowY); |
| 480 break; | |
| 481 | |
| 482 case RenderingOption::INLAY_LIGHTEN: | |
| 483 [lightColor set]; | |
| 484 inset = 1; | |
| 485 break; | |
| 486 | |
| 487 case RenderingOption::NORMAL: | |
| 488 break; | 503 break; |
| 489 } | 504 } |
| 490 if (inset != -1) { | 505 |
| 491 bezierPath = [self newTabButtonBezierPathWithInset:inset | 506 // Shadow beneath the bottom or top edge. |
| 492 lineWidth:lineWidth]; | 507 if (!NSEqualPoints(shadowStart, NSZeroPoint)) { |
| 493 [bezierPath fill]; | 508 NSBezierPath* shadowPath = [NSBezierPath bezierPath]; |
| 509 [shadowPath moveToPoint:shadowStart]; | |
| 510 [shadowPath lineToPoint:shadowEnd]; | |
| 511 [shadowPath setLineWidth:lineWidth]; | |
| 512 [shadowPath setLineCapStyle:NSRoundLineCapStyle]; | |
| 513 static NSColor* shadowColor = | |
| 514 [[NSColor colorWithCalibratedWhite:0 alpha:k10PercentAlpha] retain]; | |
| 515 [shadowColor set]; | |
| 516 [shadowPath stroke]; | |
| 517 } | |
| 518 | |
| 519 if (overlayColor) { | |
| 520 [overlayColor set]; | |
| 521 [[self newTabButtonBezierPathWithLineWidth:lineWidth] fill]; | |
| 494 } | 522 } |
| 495 } | 523 } |
| 496 | 524 |
| 497 - (NSImage*)imageWithFillColor:(NSColor*)fillColor { | 525 - (NSImage*)imageWithFillColor:(NSColor*)fillColor { |
| 498 NSImage* image = | 526 NSImage* image = |
| 499 [[[NSImage alloc] initWithSize:NSMakeSize(34, 17)] autorelease]; | 527 [[[NSImage alloc] initWithSize:newTabButtonImageSize] autorelease]; |
| 500 | 528 |
| 501 [image lockFocus]; | 529 [image lockFocus]; |
| 502 [fillColor set]; | 530 [fillColor set]; |
| 503 CGContextRef context = static_cast<CGContextRef>( | 531 CGContextRef context = static_cast<CGContextRef>( |
| 504 [[NSGraphicsContext currentContext] graphicsPort]); | 532 [[NSGraphicsContext currentContext] graphicsPort]); |
| 505 CGFloat lineWidth = LineWidthFromContext(context); | 533 CGFloat lineWidth = LineWidthFromContext(context); |
| 506 [[NewTabButton newTabButtonBezierPathWithInset:0 lineWidth:lineWidth] fill]; | 534 [[NewTabButton newTabButtonBezierPathWithLineWidth:lineWidth] fill]; |
| 507 [image unlockFocus]; | 535 [image unlockFocus]; |
| 508 return image; | 536 return image; |
| 509 } | 537 } |
| 510 | 538 |
| 511 @end | 539 @end |
| OLD | NEW |