| 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 #import "chrome/browser/cocoa/download_item_cell.h" | 5 #import "chrome/browser/cocoa/download_item_cell.h" |
| 6 | 6 |
| 7 #include "app/gfx/text_elider.h" | 7 #include "app/gfx/text_elider.h" |
| 8 #include "app/l10n_util.h" | 8 #include "app/l10n_util.h" |
| 9 #include "base/mac_util.h" | 9 #include "base/mac_util.h" |
| 10 #include "base/sys_string_conversions.h" | 10 #include "base/sys_string_conversions.h" |
| 11 #import "chrome/browser/cocoa/download_item_cell.h" | 11 #import "chrome/browser/cocoa/download_item_cell.h" |
| 12 #include "chrome/browser/download/download_item_model.h" | 12 #include "chrome/browser/download/download_item_model.h" |
| 13 #include "chrome/browser/download/download_manager.h" | 13 #include "chrome/browser/download/download_manager.h" |
| 14 #import "third_party/GTM/AppKit/GTMTheme.h" | 14 #import "third_party/GTM/AppKit/GTMTheme.h" |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 // Distance from top border to icon | 18 // Distance from top border to icon |
| 19 const CGFloat kImagePaddingTop = 1; | 19 const CGFloat kImagePaddingTop = 8; |
| 20 | 20 |
| 21 // Distance from left border to icon | 21 // Distance from left border to icon |
| 22 const CGFloat kImagePaddingLeft = 1; | 22 const CGFloat kImagePaddingLeft = 5; |
| 23 | 23 |
| 24 // Width of icon | 24 // Width of icon |
| 25 const CGFloat kImageWidth = 32; | 25 const CGFloat kImageWidth = 16; |
| 26 | 26 |
| 27 // Height of icon | 27 // Height of icon |
| 28 const CGFloat kImageHeight = 32; | 28 const CGFloat kImageHeight = 16; |
| 29 | 29 |
| 30 // x coordinate of download name string, in view coords | 30 // x coordinate of download name string, in view coords |
| 31 const CGFloat kTextPosLeft = kImagePaddingLeft + kImageWidth + 1; | 31 const CGFloat kTextPosLeft = kImagePaddingLeft + kImageWidth + 4 + 1; |
| 32 | 32 |
| 33 // Distance from end of download name string to dropdown area | 33 // Distance from end of download name string to dropdown area |
| 34 const CGFloat kTextPaddingRight = 3; | 34 const CGFloat kTextPaddingRight = 3; |
| 35 | 35 |
| 36 // y coordinate of download name string, in view coords, when status message | 36 // y coordinate of download name string, in view coords, when status message |
| 37 // is visible | 37 // is visible |
| 38 const CGFloat kPrimaryTextPosTop = 5; | 38 const CGFloat kPrimaryTextPosTop = 5; |
| 39 | 39 |
| 40 // y coordinate of download name string, in view coords, when status message | 40 // y coordinate of download name string, in view coords, when status message |
| 41 // is not visible | 41 // is not visible |
| 42 const CGFloat kPrimaryTextOnlyPosTop = 10; | 42 const CGFloat kPrimaryTextOnlyPosTop = 10; |
| 43 | 43 |
| 44 // y coordinate of status message, in view coords | 44 // y coordinate of status message, in view coords |
| 45 const CGFloat kSecondaryTextPosTop = 17; | 45 const CGFloat kSecondaryTextPosTop = 17; |
| 46 | 46 |
| 47 // Width of dropdown area on the right | 47 // Width of dropdown area on the right (includes 1px for the border on each |
| 48 const CGFloat kDropdownAreaWidth = 18; | 48 // side). |
| 49 const CGFloat kDropdownAreaWidth = 14; |
| 49 | 50 |
| 50 // Width of dropdown arrow | 51 // Width of dropdown arrow |
| 51 const CGFloat kDropdownArrowWidth = 5; | 52 const CGFloat kDropdownArrowWidth = 5; |
| 52 | 53 |
| 53 // Height of dropdown arrow | 54 // Height of dropdown arrow |
| 54 const CGFloat kDropdownArrowHeight = 3; | 55 const CGFloat kDropdownArrowHeight = 3; |
| 55 | 56 |
| 56 // Duration of the two-lines-to-one-line animation, in seconds | 57 // Duration of the two-lines-to-one-line animation, in seconds |
| 57 NSTimeInterval kHideStatusDuration = 0.3; | 58 NSTimeInterval kHideStatusDuration = 0.3; |
| 58 | 59 |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 gfx::Font font_chr = | 254 gfx::Font font_chr = |
| 254 gfx::Font::CreateFont(base::SysNSStringToWide([font fontName]), | 255 gfx::Font::CreateFont(base::SysNSStringToWide([font fontName]), |
| 255 [font pointSize]); | 256 [font pointSize]); |
| 256 | 257 |
| 257 NSString* titleString = base::SysWideToNSString( | 258 NSString* titleString = base::SysWideToNSString( |
| 258 ElideFilename(downloadPath_, font_chr, availableWidth)); | 259 ElideFilename(downloadPath_, font_chr, availableWidth)); |
| 259 [self setTitle:titleString]; | 260 [self setTitle:titleString]; |
| 260 } | 261 } |
| 261 | 262 |
| 262 - (void)drawWithFrame:(NSRect)cellFrame inView:(NSView*)controlView { | 263 - (void)drawWithFrame:(NSRect)cellFrame inView:(NSView*)controlView { |
| 263 | 264 // Constants from Cole. Will kConstant them once the feedback loop |
| 264 // Constants from Cole. Will kConstan them once the feedback loop | |
| 265 // is complete. | 265 // is complete. |
| 266 NSRect drawFrame = NSInsetRect(cellFrame, 0.5, 0.5); | 266 NSRect drawFrame = NSInsetRect(cellFrame, 0.5, 0.5); |
| 267 NSRect innerFrame = NSInsetRect(cellFrame, 1, 1); | 267 NSRect innerFrame = NSInsetRect(cellFrame, 1, 1); |
| 268 | 268 |
| 269 const float radius = 3.5; | 269 const float radius = 5; |
| 270 NSWindow* window = [controlView window]; | 270 NSWindow* window = [controlView window]; |
| 271 BOOL active = [window isKeyWindow] || [window isMainWindow]; | 271 BOOL active = [window isKeyWindow] || [window isMainWindow]; |
| 272 | 272 |
| 273 GTMTheme* theme = [controlView gtm_theme]; | 273 GTMTheme* theme = [controlView gtm_theme]; |
| 274 | 274 |
| 275 NSRect buttonDrawRect, dropdownDrawRect; | 275 NSRect buttonDrawRect, dropdownDrawRect; |
| 276 NSDivideRect(drawFrame, &dropdownDrawRect, &buttonDrawRect, | 276 NSDivideRect(drawFrame, &dropdownDrawRect, &buttonDrawRect, |
| 277 kDropdownAreaWidth, NSMaxXEdge); | 277 kDropdownAreaWidth, NSMaxXEdge); |
| 278 | 278 |
| 279 NSRect buttonInnerRect, dropdownInnerRect; | |
| 280 NSDivideRect(innerFrame, &dropdownInnerRect, &buttonInnerRect, | |
| 281 kDropdownAreaWidth, NSMaxXEdge); | |
| 282 | |
| 283 NSBezierPath* buttonInnerPath = [self | 279 NSBezierPath* buttonInnerPath = [self |
| 284 leftRoundedPath:radius inRect:buttonDrawRect]; | 280 leftRoundedPath:radius inRect:buttonDrawRect]; |
| 285 NSBezierPath* buttonOuterPath = [self | 281 NSBezierPath* buttonOuterPath = [self |
| 286 leftRoundedPath:(radius + 1) | 282 leftRoundedPath:(radius + 1) |
| 287 inRect:NSInsetRect(buttonDrawRect, -1, -1)]; | 283 inRect:NSInsetRect(buttonDrawRect, -1, -1)]; |
| 288 | 284 |
| 289 NSBezierPath* dropdownInnerPath = [self | 285 NSBezierPath* dropdownInnerPath = [self |
| 290 rightRoundedPath:radius inRect:dropdownDrawRect]; | 286 rightRoundedPath:radius inRect:dropdownDrawRect]; |
| 291 NSBezierPath* dropdownOuterPath = [self | 287 NSBezierPath* dropdownOuterPath = [self |
| 292 rightRoundedPath:(radius + 1) | 288 rightRoundedPath:(radius + 1) |
| 293 inRect:NSInsetRect(dropdownDrawRect, -1, -1)]; | 289 inRect:NSInsetRect(dropdownDrawRect, -1, -1)]; |
| 294 | 290 |
| 295 // Stroke the borders and appropriate fill gradient. If we're borderless, | 291 // Stroke the borders and appropriate fill gradient. |
| 296 // the only time we want to draw the inner gradient is if we're highlighted. | 292 [self drawBorderAndFillForTheme:theme |
| 297 if ([self isHighlighted] || [self isMouseInside]) { | 293 controlView:controlView |
| 298 [self drawBorderAndFillForTheme:theme | 294 outerPath:buttonOuterPath |
| 299 controlView:controlView | 295 innerPath:buttonInnerPath |
| 300 outerPath:buttonOuterPath | 296 showHighlightGradient:[self isMouseOverButtonPart] |
| 301 innerPath:buttonInnerPath | 297 showClickedGradient:[self isButtonPartPressed] |
| 302 showHighlightGradient:[self isMouseOverButtonPart] | 298 active:active |
| 303 showClickedGradient:[self isButtonPartPressed] | 299 cellFrame:cellFrame]; |
| 304 active:active | |
| 305 cellFrame:cellFrame]; | |
| 306 | 300 |
| 307 [self drawBorderAndFillForTheme: theme | 301 [self drawBorderAndFillForTheme: theme |
| 308 controlView:controlView | 302 controlView:controlView |
| 309 outerPath:dropdownOuterPath | 303 outerPath:dropdownOuterPath |
| 310 innerPath:dropdownInnerPath | 304 innerPath:dropdownInnerPath |
| 311 showHighlightGradient:[self isMouseOverDropdownPart] | 305 showHighlightGradient:[self isMouseOverDropdownPart] |
| 312 showClickedGradient:[self isDropdownPartPressed] | 306 showClickedGradient:[self isDropdownPartPressed] |
| 313 active:active | 307 active:active |
| 314 cellFrame:cellFrame]; | 308 cellFrame:cellFrame]; |
| 315 } | |
| 316 | 309 |
| 317 [self drawInteriorWithFrame:innerFrame inView:controlView]; | 310 [self drawInteriorWithFrame:innerFrame inView:controlView]; |
| 318 } | 311 } |
| 319 | 312 |
| 320 - (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView*)controlView { | 313 - (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView*)controlView { |
| 321 // Draw title | 314 // Draw title |
| 322 [self elideTitle:cellFrame.size.width - | 315 [self elideTitle:cellFrame.size.width - |
| 323 (kTextPosLeft + kTextPaddingRight + kDropdownAreaWidth)]; | 316 (kTextPosLeft + kTextPaddingRight + kDropdownAreaWidth)]; |
| 324 | 317 |
| 325 NSColor* color = [self isButtonPartPressed] | 318 NSColor* color = [self isButtonPartPressed] |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 NSRect imageRect = NSZeroRect; | 350 NSRect imageRect = NSZeroRect; |
| 358 imageRect.size = [[self image] size]; | 351 imageRect.size = [[self image] size]; |
| 359 [[self image] setFlipped:[controlView isFlipped]]; | 352 [[self image] setFlipped:[controlView isFlipped]]; |
| 360 [[self image] drawInRect:[self imageRectForBounds:cellFrame] | 353 [[self image] drawInRect:[self imageRectForBounds:cellFrame] |
| 361 fromRect:imageRect | 354 fromRect:imageRect |
| 362 operation:NSCompositeSourceOver | 355 operation:NSCompositeSourceOver |
| 363 fraction:[self isEnabled] ? 1.0 : 0.5]; | 356 fraction:[self isEnabled] ? 1.0 : 0.5]; |
| 364 | 357 |
| 365 // Popup arrow. Put center of mass of the arrow in the center of the | 358 // Popup arrow. Put center of mass of the arrow in the center of the |
| 366 // dropdown area. | 359 // dropdown area. |
| 367 CGFloat cx = NSMaxX(cellFrame) - kDropdownAreaWidth/2; | 360 CGFloat cx = NSMaxX(cellFrame) - kDropdownAreaWidth/2 + 0.5; |
| 368 CGFloat cy = NSMidY(cellFrame); | 361 CGFloat cy = NSMidY(cellFrame); |
| 369 NSPoint p1 = NSMakePoint(cx - kDropdownArrowWidth/2, | 362 NSPoint p1 = NSMakePoint(cx - kDropdownArrowWidth/2, |
| 370 cy - kDropdownArrowHeight/3); | 363 cy - kDropdownArrowHeight/3); |
| 371 NSPoint p2 = NSMakePoint(cx + kDropdownArrowWidth/2, | 364 NSPoint p2 = NSMakePoint(cx + kDropdownArrowWidth/2, |
| 372 cy - kDropdownArrowHeight/3); | 365 cy - kDropdownArrowHeight/3); |
| 373 NSPoint p3 = NSMakePoint(cx, cy + kDropdownArrowHeight*2/3); | 366 NSPoint p3 = NSMakePoint(cx, cy + kDropdownArrowHeight*2/3); |
| 374 NSBezierPath *triangle = [NSBezierPath bezierPath]; | 367 NSBezierPath *triangle = [NSBezierPath bezierPath]; |
| 375 [triangle moveToPoint:p1]; | 368 [triangle moveToPoint:p1]; |
| 376 [triangle lineToPoint:p2]; | 369 [triangle lineToPoint:p2]; |
| 377 [triangle lineToPoint:p3]; | 370 [triangle lineToPoint:p3]; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 424 } | 417 } |
| 425 return self; | 418 return self; |
| 426 } | 419 } |
| 427 | 420 |
| 428 - (void)setCurrentProgress:(NSAnimationProgress)progress { | 421 - (void)setCurrentProgress:(NSAnimationProgress)progress { |
| 429 [super setCurrentProgress:progress]; | 422 [super setCurrentProgress:progress]; |
| 430 [cell_ animationProgressed:progress]; | 423 [cell_ animationProgressed:progress]; |
| 431 } | 424 } |
| 432 | 425 |
| 433 @end | 426 @end |
| OLD | NEW |