Chromium Code Reviews| 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/canvas_paint.h" | 7 #include "app/gfx/canvas_paint.h" |
| 8 #include "app/gfx/text_elider.h" | 8 #include "app/gfx/text_elider.h" |
| 9 #include "app/l10n_util.h" | 9 #include "app/l10n_util.h" |
| 10 #include "base/mac_util.h" | 10 #include "base/mac_util.h" |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 81 animationCurve:(NSAnimationCurve)animationCurve; | 81 animationCurve:(NSAnimationCurve)animationCurve; |
| 82 @end | 82 @end |
| 83 | 83 |
| 84 @interface DownloadItemCell(Private) | 84 @interface DownloadItemCell(Private) |
| 85 - (void)updateTrackingAreas:(id)sender; | 85 - (void)updateTrackingAreas:(id)sender; |
| 86 - (void)hideSecondaryTitle; | 86 - (void)hideSecondaryTitle; |
| 87 - (void)animation:(NSAnimation*)animation | 87 - (void)animation:(NSAnimation*)animation |
| 88 progressed:(NSAnimationProgress)progress; | 88 progressed:(NSAnimationProgress)progress; |
| 89 - (NSString*)elideTitle:(int)availableWidth; | 89 - (NSString*)elideTitle:(int)availableWidth; |
| 90 - (NSString*)elideStatus:(int)availableWidth; | 90 - (NSString*)elideStatus:(int)availableWidth; |
| 91 - (GTMTheme*)backgroundTheme:(NSView*)controlView; | |
| 91 @end | 92 @end |
| 92 | 93 |
| 93 @implementation DownloadItemCell | 94 @implementation DownloadItemCell |
| 94 | 95 |
| 95 @synthesize secondaryTitle = secondaryTitle_; | 96 @synthesize secondaryTitle = secondaryTitle_; |
| 96 @synthesize secondaryFont = secondaryFont_; | 97 @synthesize secondaryFont = secondaryFont_; |
| 97 | 98 |
| 98 - (void)setInitialState { | 99 - (void)setInitialState { |
| 99 isStatusTextVisible_ = NO; | 100 isStatusTextVisible_ = NO; |
| 100 titleY_ = kPrimaryTextPosTop; | 101 titleY_ = kPrimaryTextPosTop; |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 315 gfx::Font font_chr = | 316 gfx::Font font_chr = |
| 316 gfx::Font::CreateFont(base::SysNSStringToWide([font fontName]), | 317 gfx::Font::CreateFont(base::SysNSStringToWide([font fontName]), |
| 317 [font pointSize]); | 318 [font pointSize]); |
| 318 | 319 |
| 319 return base::SysWideToNSString(ElideText( | 320 return base::SysWideToNSString(ElideText( |
| 320 base::SysNSStringToWide([self secondaryTitle]), | 321 base::SysNSStringToWide([self secondaryTitle]), |
| 321 font_chr, | 322 font_chr, |
| 322 availableWidth)); | 323 availableWidth)); |
| 323 } | 324 } |
| 324 | 325 |
| 326 - (GTMTheme*)backgroundTheme:(NSView*)controlView { | |
| 327 if (!theme_) { | |
| 328 theme_.reset([[GTMTheme alloc] init]); | |
| 329 NSColor* bgColor = [NSColor colorWithCalibratedRed:241/255.0 | |
| 330 green:245/255.0 | |
| 331 blue:250/255.0 | |
| 332 alpha:77/255.0]; | |
| 333 NSColor* clickedColor = [NSColor colorWithCalibratedRed:239/255.0 | |
| 334 green:245/255.0 | |
| 335 blue:252/255.0 | |
| 336 alpha:51/255.0]; | |
|
Avi (use Gerrit)
2009/11/13 16:13:59
File a bug to get these colors from the theme. We
Nico
2009/11/13 16:23:07
No, these colors should be hardcoded. If the curre
| |
| 337 | |
| 338 NSColor* borderColor = [NSColor colorWithCalibratedWhite:0 alpha:36/255.0]; | |
| 339 scoped_nsobject<NSGradient> bgGradient([[NSGradient alloc] | |
| 340 initWithColors:[NSArray arrayWithObject:bgColor]]); | |
| 341 scoped_nsobject<NSGradient> clickedGradient([[NSGradient alloc] | |
| 342 initWithColors:[NSArray arrayWithObject:clickedColor]]); | |
| 343 | |
| 344 GTMThemeState states[] = { | |
| 345 GTMThemeStateActiveWindow, GTMThemeStateInactiveWindow | |
| 346 }; | |
| 347 | |
| 348 for (size_t i = 0; i < arraysize(states); ++i) { | |
| 349 [theme_.get() setValue:bgGradient | |
| 350 forAttribute:@"gradient" | |
| 351 style:GTMThemeStyleToolBarButton | |
| 352 state:states[i]]; | |
| 353 | |
| 354 [theme_.get() setValue:clickedGradient | |
| 355 forAttribute:@"gradient" | |
| 356 style:GTMThemeStyleToolBarButtonPressed | |
| 357 state:states[i]]; | |
| 358 | |
| 359 [theme_.get() setValue:borderColor | |
| 360 forAttribute:@"iconColor" | |
| 361 style:GTMThemeStyleToolBarButton | |
| 362 state:states[i]]; | |
| 363 } | |
| 364 } | |
| 365 return theme_.get(); | |
| 366 } | |
| 367 | |
| 325 - (void)drawWithFrame:(NSRect)cellFrame inView:(NSView*)controlView { | 368 - (void)drawWithFrame:(NSRect)cellFrame inView:(NSView*)controlView { |
| 326 // Constants from Cole. Will kConstant them once the feedback loop | 369 // Constants from Cole. Will kConstant them once the feedback loop |
| 327 // is complete. | 370 // is complete. |
| 328 NSRect drawFrame = NSInsetRect(cellFrame, 1.5, 1.5); | 371 NSRect drawFrame = NSInsetRect(cellFrame, 1.5, 1.5); |
| 329 NSRect innerFrame = NSInsetRect(cellFrame, 2, 2); | 372 NSRect innerFrame = NSInsetRect(cellFrame, 2, 2); |
| 330 | 373 |
| 331 const float radius = 5; | 374 const float radius = 5; |
| 332 NSWindow* window = [controlView window]; | 375 NSWindow* window = [controlView window]; |
| 333 BOOL active = [window isKeyWindow] || [window isMainWindow]; | 376 BOOL active = [window isKeyWindow] || [window isMainWindow]; |
| 334 | 377 |
| 378 // In the default theme, draw download items with the bookmark button | |
| 379 // gradient. For some themes, this leads to unreadable text, so draw the item | |
| 380 // with a background that looks like windows (some transparent white) if a | |
| 381 // theme is used. Use custom theme object with a white color gradient to trick | |
| 382 // the superclass into drawing what we want. | |
| 335 GTMTheme* theme = [controlView gtm_theme]; | 383 GTMTheme* theme = [controlView gtm_theme]; |
| 384 bool isDefaultTheme = [theme | |
| 385 backgroundImageForStyle:GTMThemeStyleToolBarButton state:YES] == nil; | |
| 386 | |
| 387 NSGradient* bgGradient = nil; | |
| 388 if (!isDefaultTheme) { | |
| 389 theme = [self backgroundTheme:controlView]; | |
| 390 bgGradient = [theme gradientForStyle:GTMThemeStyleToolBarButton | |
| 391 state:active]; | |
| 392 } | |
| 336 | 393 |
| 337 NSRect buttonDrawRect, dropdownDrawRect; | 394 NSRect buttonDrawRect, dropdownDrawRect; |
| 338 NSDivideRect(drawFrame, &dropdownDrawRect, &buttonDrawRect, | 395 NSDivideRect(drawFrame, &dropdownDrawRect, &buttonDrawRect, |
| 339 kDropdownAreaWidth, NSMaxXEdge); | 396 kDropdownAreaWidth, NSMaxXEdge); |
| 340 | 397 |
| 341 NSBezierPath* buttonInnerPath = [self | 398 NSBezierPath* buttonInnerPath = [self |
| 342 leftRoundedPath:radius inRect:buttonDrawRect]; | 399 leftRoundedPath:radius inRect:buttonDrawRect]; |
| 343 NSBezierPath* buttonOuterPath = [self | 400 NSBezierPath* buttonOuterPath = [self |
| 344 leftRoundedPath:(radius + 1) | 401 leftRoundedPath:(radius + 1) |
| 345 inRect:NSInsetRect(buttonDrawRect, -1, -1)]; | 402 inRect:NSInsetRect(buttonDrawRect, -1, -1)]; |
| 346 | 403 |
| 347 NSBezierPath* dropdownInnerPath = [self | 404 NSBezierPath* dropdownInnerPath = [self |
| 348 rightRoundedPath:radius inRect:dropdownDrawRect]; | 405 rightRoundedPath:radius inRect:dropdownDrawRect]; |
| 349 NSBezierPath* dropdownOuterPath = [self | 406 NSBezierPath* dropdownOuterPath = [self |
| 350 rightRoundedPath:(radius + 1) | 407 rightRoundedPath:(radius + 1) |
| 351 inRect:NSInsetRect(dropdownDrawRect, -1, -1)]; | 408 inRect:NSInsetRect(dropdownDrawRect, -1, -1)]; |
| 352 | 409 |
| 353 // Stroke the borders and appropriate fill gradient. | 410 // Stroke the borders and appropriate fill gradient. |
| 354 [self drawBorderAndFillForTheme:theme | 411 [self drawBorderAndFillForTheme:theme |
| 355 controlView:controlView | 412 controlView:controlView |
| 356 outerPath:buttonOuterPath | 413 outerPath:buttonOuterPath |
| 357 innerPath:buttonInnerPath | 414 innerPath:buttonInnerPath |
| 358 showClickedGradient:[self isButtonPartPressed] | 415 showClickedGradient:[self isButtonPartPressed] |
| 359 showHighlightGradient:[self isMouseOverButtonPart] | 416 showHighlightGradient:[self isMouseOverButtonPart] |
| 360 hoverAlpha:0.0 | 417 hoverAlpha:0.0 |
| 361 active:active | 418 active:active |
| 362 cellFrame:cellFrame]; | 419 cellFrame:cellFrame |
| 420 defaultGradient:bgGradient]; | |
| 363 | 421 |
| 364 [self drawBorderAndFillForTheme: theme | 422 [self drawBorderAndFillForTheme:theme |
| 365 controlView:controlView | 423 controlView:controlView |
| 366 outerPath:dropdownOuterPath | 424 outerPath:dropdownOuterPath |
| 367 innerPath:dropdownInnerPath | 425 innerPath:dropdownInnerPath |
| 368 showClickedGradient:[self isDropdownPartPressed] | 426 showClickedGradient:[self isDropdownPartPressed] |
| 369 showHighlightGradient:[self isMouseOverDropdownPart] | 427 showHighlightGradient:[self isMouseOverDropdownPart] |
| 370 hoverAlpha:0.0 | 428 hoverAlpha:0.0 |
| 371 active:active | 429 active:active |
| 372 cellFrame:cellFrame]; | 430 cellFrame:cellFrame |
| 431 defaultGradient:bgGradient]; | |
| 373 | 432 |
| 374 [self drawInteriorWithFrame:innerFrame inView:controlView]; | 433 [self drawInteriorWithFrame:innerFrame inView:controlView]; |
| 375 } | 434 } |
| 376 | 435 |
| 377 - (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView*)controlView { | 436 - (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView*)controlView { |
| 378 // Draw title | 437 // Draw title |
| 379 CGFloat textWidth = cellFrame.size.width - | 438 CGFloat textWidth = cellFrame.size.width - |
| 380 (kTextPosLeft + kTextPaddingRight + kDropdownAreaWidth); | 439 (kTextPosLeft + kTextPaddingRight + kDropdownAreaWidth); |
| 381 [self setTitle:[self elideTitle:textWidth]]; | 440 [self setTitle:[self elideTitle:textWidth]]; |
| 382 | 441 |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 556 } | 615 } |
| 557 return self; | 616 return self; |
| 558 } | 617 } |
| 559 | 618 |
| 560 - (void)setCurrentProgress:(NSAnimationProgress)progress { | 619 - (void)setCurrentProgress:(NSAnimationProgress)progress { |
| 561 [super setCurrentProgress:progress]; | 620 [super setCurrentProgress:progress]; |
| 562 [cell_ animation:self progressed:progress]; | 621 [cell_ animation:self progressed:progress]; |
| 563 } | 622 } |
| 564 | 623 |
| 565 @end | 624 @end |
| OLD | NEW |