| 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_shelf_controller.h" | 5 #import "chrome/browser/cocoa/download_shelf_controller.h" |
| 6 | 6 |
| 7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
| 8 #include "app/resource_bundle.h" | 8 #include "app/resource_bundle.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" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 // Duration for download shelf closing animation, in seconds. | 38 // Duration for download shelf closing animation, in seconds. |
| 39 const NSTimeInterval kDownloadShelfCloseDuration = 0.12; | 39 const NSTimeInterval kDownloadShelfCloseDuration = 0.12; |
| 40 | 40 |
| 41 } // namespace | 41 } // namespace |
| 42 | 42 |
| 43 @interface DownloadShelfController(Private) | 43 @interface DownloadShelfController(Private) |
| 44 - (void)showDownloadShelf:(BOOL)enable; | 44 - (void)showDownloadShelf:(BOOL)enable; |
| 45 - (void)layoutItems:(BOOL)skipFirst; | 45 - (void)layoutItems:(BOOL)skipFirst; |
| 46 - (void)closed; | 46 - (void)closed; |
| 47 | 47 |
| 48 - (void)updateTheme:(GTMTheme*)theme; | 48 - (void)updateTheme; |
| 49 - (void)themeDidChangeNotification:(NSNotification*)aNotification; | 49 - (void)themeDidChangeNotification:(NSNotification*)aNotification; |
| 50 @end | 50 @end |
| 51 | 51 |
| 52 | 52 |
| 53 @implementation DownloadShelfController | 53 @implementation DownloadShelfController |
| 54 | 54 |
| 55 - (id)initWithBrowser:(Browser*)browser | 55 - (id)initWithBrowser:(Browser*)browser |
| 56 resizeDelegate:(id<ViewResizer>)resizeDelegate { | 56 resizeDelegate:(id<ViewResizer>)resizeDelegate { |
| 57 if ((self = [super initWithNibName:@"DownloadShelf" | 57 if ((self = [super initWithNibName:@"DownloadShelf" |
| 58 bundle:mac_util::MainAppBundle()])) { | 58 bundle:mac_util::MainAppBundle()])) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 72 | 72 |
| 73 bridge_.reset(new DownloadShelfMac(browser, self)); | 73 bridge_.reset(new DownloadShelfMac(browser, self)); |
| 74 } | 74 } |
| 75 return self; | 75 return self; |
| 76 } | 76 } |
| 77 | 77 |
| 78 - (void)awakeFromNib { | 78 - (void)awakeFromNib { |
| 79 NSNotificationCenter* defaultCenter = [NSNotificationCenter defaultCenter]; | 79 NSNotificationCenter* defaultCenter = [NSNotificationCenter defaultCenter]; |
| 80 [defaultCenter addObserver:self | 80 [defaultCenter addObserver:self |
| 81 selector:@selector(themeDidChangeNotification:) | 81 selector:@selector(themeDidChangeNotification:) |
| 82 name:kGTMThemeDidChangeNotification | 82 name:kBrowserThemeDidChangeNotification |
| 83 object:nil]; | 83 object:nil]; |
| 84 | 84 |
| 85 [[self animatableView] setResizeDelegate:resizeDelegate_]; | 85 [[self animatableView] setResizeDelegate:resizeDelegate_]; |
| 86 | 86 |
| 87 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 87 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 88 NSImage* favicon = rb.GetNSImageNamed(IDR_DOWNLOADS_FAVICON); | 88 NSImage* favicon = rb.GetNSImageNamed(IDR_DOWNLOADS_FAVICON); |
| 89 DCHECK(favicon); | 89 DCHECK(favicon); |
| 90 [image_ setImage:favicon]; | 90 [image_ setImage:favicon]; |
| 91 } | 91 } |
| 92 | 92 |
| 93 - (void)dealloc { | 93 - (void)dealloc { |
| 94 [[NSNotificationCenter defaultCenter] removeObserver:self]; | 94 [[NSNotificationCenter defaultCenter] removeObserver:self]; |
| 95 | 95 |
| 96 // The controllers will unregister themselves as observers when they are | 96 // The controllers will unregister themselves as observers when they are |
| 97 // deallocated. No need to do that here. | 97 // deallocated. No need to do that here. |
| 98 [super dealloc]; | 98 [super dealloc]; |
| 99 } | 99 } |
| 100 | 100 |
| 101 // Called after the current theme has changed. | 101 // Called after the current theme has changed. |
| 102 - (void)themeDidChangeNotification:(NSNotification*)aNotification { | 102 - (void)themeDidChangeNotification:(NSNotification*)notification { |
| 103 GTMTheme* theme = [aNotification object]; | 103 [self updateTheme]; |
| 104 [self updateTheme:theme]; | |
| 105 } | 104 } |
| 106 | 105 |
| 107 // Adapt appearance to the current theme. Called after theme changes and before | 106 // Adapt appearance to the current theme. Called after theme changes and before |
| 108 // this is shown for the first time. | 107 // this is shown for the first time. |
| 109 - (void)updateTheme:(GTMTheme*)theme { | 108 - (void)updateTheme { |
| 110 // For the default theme, use a blue color for the link. Ideally, we'd want to | 109 NSColor* color = nil; |
| 111 // compare the current theme id with kDefaultThemeID, but the classic theme | 110 |
| 112 // from the gallery does have a different id. Hence, we use the blue color if | |
| 113 // the current theme does not change the bookmark text color. | |
| 114 BOOL useDefaultColor = YES; | |
| 115 if (bridge_.get() && bridge_->browser() && bridge_->browser()->profile()) { | 111 if (bridge_.get() && bridge_->browser() && bridge_->browser()->profile()) { |
| 116 ThemeProvider* provider = bridge_->browser()->profile()->GetThemeProvider(); | 112 ThemeProvider* provider = bridge_->browser()->profile()->GetThemeProvider(); |
| 117 if (provider) { | 113 |
| 118 useDefaultColor = provider->GetColor( | 114 color = |
| 119 BrowserThemeProvider::COLOR_BOOKMARK_TEXT) == | 115 provider->GetNSColor(BrowserThemeProvider::COLOR_BOOKMARK_TEXT, false); |
| 120 BrowserThemeProvider::GetDefaultColor( | |
| 121 BrowserThemeProvider::COLOR_BOOKMARK_TEXT); | |
| 122 } | |
| 123 } | 116 } |
| 124 | 117 |
| 125 NSColor* color = useDefaultColor ? | 118 if (!color) |
| 126 [HyperlinkButtonCell defaultTextColor] : | 119 color = [HyperlinkButtonCell defaultTextColor]; |
| 127 [theme textColorForStyle:GTMThemeStyleBookmarksBarButton | 120 |
| 128 state:GTMThemeStateActiveWindow]; | |
| 129 [showAllDownloadsCell_ setTextColor:color]; | 121 [showAllDownloadsCell_ setTextColor:color]; |
| 130 } | 122 } |
| 131 | 123 |
| 132 - (AnimatableView*)animatableView { | 124 - (AnimatableView*)animatableView { |
| 133 return static_cast<AnimatableView*>([self view]); | 125 return static_cast<AnimatableView*>([self view]); |
| 134 } | 126 } |
| 135 | 127 |
| 136 - (void)showDownloadsTab:(id)sender { | 128 - (void)showDownloadsTab:(id)sender { |
| 137 bridge_->browser()->ShowDownloadsTab(); | 129 bridge_->browser()->ShowDownloadsTab(); |
| 138 } | 130 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 163 downloadItemControllers_.reset(); | 155 downloadItemControllers_.reset(); |
| 164 } | 156 } |
| 165 | 157 |
| 166 // Show or hide the bar based on the value of |enable|. Handles animating the | 158 // Show or hide the bar based on the value of |enable|. Handles animating the |
| 167 // resize of the content view. | 159 // resize of the content view. |
| 168 - (void)showDownloadShelf:(BOOL)enable { | 160 - (void)showDownloadShelf:(BOOL)enable { |
| 169 if ([self isVisible] == enable) | 161 if ([self isVisible] == enable) |
| 170 return; | 162 return; |
| 171 | 163 |
| 172 if ([[self view] window]) | 164 if ([[self view] window]) |
| 173 [self updateTheme:[[self view] gtm_theme]]; | 165 [self updateTheme]; |
| 174 | 166 |
| 175 // Animate the shelf out, but not in. | 167 // Animate the shelf out, but not in. |
| 176 // TODO(rohitrao): We do not animate on the way in because Cocoa is already | 168 // TODO(rohitrao): We do not animate on the way in because Cocoa is already |
| 177 // doing a lot of work to set up the download arrow animation. I've chosen to | 169 // doing a lot of work to set up the download arrow animation. I've chosen to |
| 178 // do no animation over janky animation. Find a way to make animating in | 170 // do no animation over janky animation. Find a way to make animating in |
| 179 // smoother. | 171 // smoother. |
| 180 AnimatableView* view = [self animatableView]; | 172 AnimatableView* view = [self animatableView]; |
| 181 if (enable) | 173 if (enable) |
| 182 [view setHeight:shelfHeight_]; | 174 [view setHeight:shelfHeight_]; |
| 183 else | 175 else |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 if (isTransferDone && | 292 if (isTransferDone && |
| 301 [itemController download]->safety_state() != DownloadItem::DANGEROUS) { | 293 [itemController download]->safety_state() != DownloadItem::DANGEROUS) { |
| 302 [self remove:itemController]; | 294 [self remove:itemController]; |
| 303 } else { | 295 } else { |
| 304 ++i; | 296 ++i; |
| 305 } | 297 } |
| 306 } | 298 } |
| 307 } | 299 } |
| 308 | 300 |
| 309 @end | 301 @end |
| OLD | NEW |