diff options
author | thakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-13 16:44:16 +0000 |
---|---|---|
committer | thakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-13 16:44:16 +0000 |
commit | 386f10102b36328294a6707b455275e6bebfa125 (patch) | |
tree | a06724c1973d08e6293df036c402659bba2029b9 | |
parent | b5f65ce63d3b1b8085ce5295687b6808e76323f8 (diff) | |
download | chromium_src-386f10102b36328294a6707b455275e6bebfa125.zip chromium_src-386f10102b36328294a6707b455275e6bebfa125.tar.gz chromium_src-386f10102b36328294a6707b455275e6bebfa125.tar.bz2 |
Draw download item background like windows does if a theme is installed.
BUG=27221
TEST=Download something, install theme. Download item should look different.
Review URL: http://codereview.chromium.org/384115
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@31907 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/cocoa/download_item_cell.h | 3 | ||||
-rw-r--r-- | chrome/browser/cocoa/download_item_cell.mm | 65 | ||||
-rw-r--r-- | chrome/browser/cocoa/gradient_button_cell.h | 3 | ||||
-rw-r--r-- | chrome/browser/cocoa/gradient_button_cell.mm | 11 |
4 files changed, 75 insertions, 7 deletions
diff --git a/chrome/browser/cocoa/download_item_cell.h b/chrome/browser/cocoa/download_item_cell.h index 3c2b7d5..248225c 100644 --- a/chrome/browser/cocoa/download_item_cell.h +++ b/chrome/browser/cocoa/download_item_cell.h @@ -11,6 +11,7 @@ #include "base/file_path.h" class BaseDownloadItemModel; +@class GTMTheme; // A button cell that implements the weird button/popup button hybrid that is // used by the download items. @@ -42,6 +43,8 @@ enum DownloadItemMousePosition { CGFloat titleY_; CGFloat statusAlpha_; scoped_nsobject<NSAnimation> hideStatusAnimation_; + + scoped_nsobject<GTMTheme> theme_; } - (void)setStateFromDownload:(BaseDownloadItemModel*)downloadModel; diff --git a/chrome/browser/cocoa/download_item_cell.mm b/chrome/browser/cocoa/download_item_cell.mm index 8c180c7..e910ce4 100644 --- a/chrome/browser/cocoa/download_item_cell.mm +++ b/chrome/browser/cocoa/download_item_cell.mm @@ -88,6 +88,7 @@ const int kCompleteAnimationDuration = 2.5; progressed:(NSAnimationProgress)progress; - (NSString*)elideTitle:(int)availableWidth; - (NSString*)elideStatus:(int)availableWidth; +- (GTMTheme*)backgroundTheme:(NSView*)controlView; @end @implementation DownloadItemCell @@ -322,6 +323,48 @@ const int kCompleteAnimationDuration = 2.5; availableWidth)); } +- (GTMTheme*)backgroundTheme:(NSView*)controlView { + if (!theme_) { + theme_.reset([[GTMTheme alloc] init]); + NSColor* bgColor = [NSColor colorWithCalibratedRed:241/255.0 + green:245/255.0 + blue:250/255.0 + alpha:77/255.0]; + NSColor* clickedColor = [NSColor colorWithCalibratedRed:239/255.0 + green:245/255.0 + blue:252/255.0 + alpha:51/255.0]; + + NSColor* borderColor = [NSColor colorWithCalibratedWhite:0 alpha:36/255.0]; + scoped_nsobject<NSGradient> bgGradient([[NSGradient alloc] + initWithColors:[NSArray arrayWithObject:bgColor]]); + scoped_nsobject<NSGradient> clickedGradient([[NSGradient alloc] + initWithColors:[NSArray arrayWithObject:clickedColor]]); + + GTMThemeState states[] = { + GTMThemeStateActiveWindow, GTMThemeStateInactiveWindow + }; + + for (size_t i = 0; i < arraysize(states); ++i) { + [theme_.get() setValue:bgGradient + forAttribute:@"gradient" + style:GTMThemeStyleToolBarButton + state:states[i]]; + + [theme_.get() setValue:clickedGradient + forAttribute:@"gradient" + style:GTMThemeStyleToolBarButtonPressed + state:states[i]]; + + [theme_.get() setValue:borderColor + forAttribute:@"iconColor" + style:GTMThemeStyleToolBarButton + state:states[i]]; + } + } + return theme_.get(); +} + - (void)drawWithFrame:(NSRect)cellFrame inView:(NSView*)controlView { // Constants from Cole. Will kConstant them once the feedback loop // is complete. @@ -332,7 +375,21 @@ const int kCompleteAnimationDuration = 2.5; NSWindow* window = [controlView window]; BOOL active = [window isKeyWindow] || [window isMainWindow]; + // In the default theme, draw download items with the bookmark button + // gradient. For some themes, this leads to unreadable text, so draw the item + // with a background that looks like windows (some transparent white) if a + // theme is used. Use custom theme object with a white color gradient to trick + // the superclass into drawing what we want. GTMTheme* theme = [controlView gtm_theme]; + bool isDefaultTheme = [theme + backgroundImageForStyle:GTMThemeStyleToolBarButton state:YES] == nil; + + NSGradient* bgGradient = nil; + if (!isDefaultTheme) { + theme = [self backgroundTheme:controlView]; + bgGradient = [theme gradientForStyle:GTMThemeStyleToolBarButton + state:active]; + } NSRect buttonDrawRect, dropdownDrawRect; NSDivideRect(drawFrame, &dropdownDrawRect, &buttonDrawRect, @@ -359,9 +416,10 @@ const int kCompleteAnimationDuration = 2.5; showHighlightGradient:[self isMouseOverButtonPart] hoverAlpha:0.0 active:active - cellFrame:cellFrame]; + cellFrame:cellFrame + defaultGradient:bgGradient]; - [self drawBorderAndFillForTheme: theme + [self drawBorderAndFillForTheme:theme controlView:controlView outerPath:dropdownOuterPath innerPath:dropdownInnerPath @@ -369,7 +427,8 @@ const int kCompleteAnimationDuration = 2.5; showHighlightGradient:[self isMouseOverDropdownPart] hoverAlpha:0.0 active:active - cellFrame:cellFrame]; + cellFrame:cellFrame + defaultGradient:bgGradient]; [self drawInteriorWithFrame:innerFrame inView:controlView]; } diff --git a/chrome/browser/cocoa/gradient_button_cell.h b/chrome/browser/cocoa/gradient_button_cell.h index 7308b6c..23dc5d1 100644 --- a/chrome/browser/cocoa/gradient_button_cell.h +++ b/chrome/browser/cocoa/gradient_button_cell.h @@ -51,7 +51,8 @@ typedef NSInteger ButtonType; showHighlightGradient:(BOOL)showHighlightGradient hoverAlpha:(CGFloat)hoverAlpha active:(BOOL)active - cellFrame:(NSRect)cellFrame; + cellFrame:(NSRect)cellFrame + defaultGradient:(NSGradient*)defaultGradient; // An image to underlay beneath the existing image; not themed. May be nil. - (NSImage*)underlayImage; diff --git a/chrome/browser/cocoa/gradient_button_cell.mm b/chrome/browser/cocoa/gradient_button_cell.mm index 5a7a08a..6af6689 100644 --- a/chrome/browser/cocoa/gradient_button_cell.mm +++ b/chrome/browser/cocoa/gradient_button_cell.mm @@ -165,10 +165,14 @@ static const NSTimeInterval kAnimationHideDuration = 0.4; showHighlightGradient:(BOOL)showHighlightGradient hoverAlpha:(CGFloat)hoverAlpha active:(BOOL)active - cellFrame:(NSRect)cellFrame { + cellFrame:(NSRect)cellFrame + defaultGradient:(NSGradient*)defaultGradient { NSImage* backgroundImage = [theme backgroundImageForStyle:GTMThemeStyleToolBarButton state:YES]; + if (!defaultGradient) + defaultGradient = gradient_; + if (backgroundImage) { NSColor* patternColor = [NSColor colorWithPatternImage:backgroundImage]; [patternColor set]; @@ -209,7 +213,7 @@ static const NSTimeInterval kAnimationHideDuration = 0.4; NSGradient *gradient = nil; if (hoverAlpha == 0 && !isCustomTheme) { - gradient = gradient_; + gradient = defaultGradient; } else { gradient = [self gradientForHoverAlpha:hoverAlpha isThemed:isCustomTheme]; } @@ -284,7 +288,8 @@ static const NSTimeInterval kAnimationHideDuration = 0.4; showHighlightGradient:[self isHighlighted] hoverAlpha:[self hoverAlpha] active:active - cellFrame:cellFrame]; + cellFrame:cellFrame + defaultGradient:nil]; } // If this is the left side of a segmented button, draw a slight shadow. |