Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(117)

Side by Side Diff: chrome/browser/cocoa/download_item_controller.mm

Issue 377015: Theme the text of the download item so it's readable with dark themes.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_controller.h" 5 #import "chrome/browser/cocoa/download_item_controller.h"
6 6
7 #include "app/gfx/text_elider.h" 7 #include "app/gfx/text_elider.h"
8 #include "app/l10n_util_mac.h" 8 #include "app/l10n_util_mac.h"
9 #include "app/resource_bundle.h" 9 #include "app/resource_bundle.h"
10 #include "base/mac_util.h" 10 #include "base/mac_util.h"
11 #include "base/sys_string_conversions.h" 11 #include "base/sys_string_conversions.h"
12 #import "chrome/browser/cocoa/download_item_cell.h" 12 #import "chrome/browser/cocoa/download_item_cell.h"
13 #include "chrome/browser/cocoa/download_item_mac.h" 13 #include "chrome/browser/cocoa/download_item_mac.h"
14 #import "chrome/browser/cocoa/download_shelf_controller.h" 14 #import "chrome/browser/cocoa/download_shelf_controller.h"
15 #import "chrome/browser/cocoa/ui_localizer.h" 15 #import "chrome/browser/cocoa/ui_localizer.h"
16 #include "chrome/browser/download/download_item_model.h" 16 #include "chrome/browser/download/download_item_model.h"
17 #include "chrome/browser/download/download_shelf.h" 17 #include "chrome/browser/download/download_shelf.h"
18 #include "chrome/browser/download/download_util.h" 18 #include "chrome/browser/download/download_util.h"
19 #include "grit/generated_resources.h" 19 #include "grit/generated_resources.h"
20 #include "grit/theme_resources.h" 20 #include "grit/theme_resources.h"
21 #import "third_party/GTM/AppKit/GTMTheme.h"
21 #include "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h" 22 #include "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h"
22 23
23 static const int kTextWidth = 140; // Pixels 24 static const int kTextWidth = 140; // Pixels
24 25
25 namespace { 26 namespace {
26 27
27 // Helper to widen a view. 28 // Helper to widen a view.
28 void WidenView(NSView* view, CGFloat widthChange) { 29 void WidenView(NSView* view, CGFloat widthChange) {
29 // If it is an NSBox, the autoresize of the contentView is the issue. 30 // If it is an NSBox, the autoresize of the contentView is the issue.
30 NSView* contentView = view; 31 NSView* contentView = view;
(...skipping 27 matching lines...) Expand all
58 using DownloadShelfContextMenu::ItemIsChecked; 59 using DownloadShelfContextMenu::ItemIsChecked;
59 using DownloadShelfContextMenu::IsItemCommandEnabled; 60 using DownloadShelfContextMenu::IsItemCommandEnabled;
60 61
61 using DownloadShelfContextMenu::SHOW_IN_FOLDER; 62 using DownloadShelfContextMenu::SHOW_IN_FOLDER;
62 using DownloadShelfContextMenu::OPEN_WHEN_COMPLETE; 63 using DownloadShelfContextMenu::OPEN_WHEN_COMPLETE;
63 using DownloadShelfContextMenu::ALWAYS_OPEN_TYPE; 64 using DownloadShelfContextMenu::ALWAYS_OPEN_TYPE;
64 using DownloadShelfContextMenu::CANCEL; 65 using DownloadShelfContextMenu::CANCEL;
65 }; 66 };
66 67
67 @interface DownloadItemController (Private) 68 @interface DownloadItemController (Private)
69 - (void)themeDidChangeNotification:(NSNotification*)aNotification;
70 - (void)updateTheme:(GTMTheme*)theme;
68 - (void)setState:(DownoadItemState)state; 71 - (void)setState:(DownoadItemState)state;
69 @end 72 @end
70 73
71 // Implementation of DownloadItemController 74 // Implementation of DownloadItemController
72 75
73 @implementation DownloadItemController 76 @implementation DownloadItemController
74 77
75 - (id)initWithModel:(BaseDownloadItemModel*)downloadModel 78 - (id)initWithModel:(BaseDownloadItemModel*)downloadModel
76 shelf:(DownloadShelfController*)shelf { 79 shelf:(DownloadShelfController*)shelf {
77 if ((self = [super initWithNibName:@"DownloadItem" 80 if ((self = [super initWithNibName:@"DownloadItem"
78 bundle:mac_util::MainAppBundle()])) { 81 bundle:mac_util::MainAppBundle()])) {
79 // Must be called before [self view], so that bridge_ is set in awakeFromNib 82 // Must be called before [self view], so that bridge_ is set in awakeFromNib
80 bridge_.reset(new DownloadItemMac(downloadModel, self)); 83 bridge_.reset(new DownloadItemMac(downloadModel, self));
81 menuBridge_.reset(new DownloadShelfContextMenuMac(downloadModel)); 84 menuBridge_.reset(new DownloadShelfContextMenuMac(downloadModel));
82 85
86 NSNotificationCenter* defaultCenter = [NSNotificationCenter defaultCenter];
87 [defaultCenter addObserver:self
88 selector:@selector(themeDidChangeNotification:)
89 name:kGTMThemeDidChangeNotification
90 object:nil];
Nico 2009/11/08 09:37:14 Oh, and you need to removeObserver:self in dealloc
Avi (use Gerrit) 2009/11/08 17:45:26 Um, I already _do_. Well, _I_ don't, but it's alre
91
83 shelf_ = shelf; 92 shelf_ = shelf;
84 state_ = kNormal; 93 state_ = kNormal;
85 creationTime_ = base::Time::Now(); 94 creationTime_ = base::Time::Now();
86 } 95 }
87 return self; 96 return self;
88 } 97 }
89 98
90 - (void)dealloc { 99 - (void)dealloc {
91 [[NSNotificationCenter defaultCenter] removeObserver:self]; 100 [[NSNotificationCenter defaultCenter] removeObserver:self];
92 [[self view] removeFromSuperview]; 101 [[self view] removeFromSuperview];
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 - (void)setIcon:(NSImage*)icon { 173 - (void)setIcon:(NSImage*)icon {
165 [cell_ setImage:icon]; 174 [cell_ setImage:icon];
166 } 175 }
167 176
168 - (void)remove { 177 - (void)remove {
169 // We are deleted after this! 178 // We are deleted after this!
170 [shelf_ remove:self]; 179 [shelf_ remove:self];
171 } 180 }
172 181
173 - (void)updateVisibility:(id)sender { 182 - (void)updateVisibility:(id)sender {
183 if ([[self view] window])
184 [self updateTheme:[[self view] gtm_theme]];
185
174 // TODO(thakis): Make this prettier, by fading the items out or overlaying 186 // TODO(thakis): Make this prettier, by fading the items out or overlaying
175 // the partial visible one with a horizontal alpha gradient -- crbug.com/17830 187 // the partial visible one with a horizontal alpha gradient -- crbug.com/17830
176 NSView* view = [self view]; 188 NSView* view = [self view];
177 NSRect containerFrame = [[view superview] frame]; 189 NSRect containerFrame = [[view superview] frame];
178 [view setHidden:(NSMaxX([view frame]) > NSWidth(containerFrame))]; 190 [view setHidden:(NSMaxX([view frame]) > NSWidth(containerFrame))];
179 } 191 }
180 192
181 - (IBAction)handleButtonClick:(id)sender { 193 - (IBAction)handleButtonClick:(id)sender {
182 if ([cell_ isButtonPartPressed]) { 194 if ([cell_ isButtonPartPressed]) {
183 DownloadItem* download = bridge_->download_model()->download(); 195 DownloadItem* download = bridge_->download_model()->download();
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 [progressView_ setHidden:NO]; 231 [progressView_ setHidden:NO];
220 [dangerousDownloadView_ setHidden:YES]; 232 [dangerousDownloadView_ setHidden:YES];
221 } else { 233 } else {
222 DCHECK_EQ(kDangerous, state_); 234 DCHECK_EQ(kDangerous, state_);
223 [progressView_ setHidden:YES]; 235 [progressView_ setHidden:YES];
224 [dangerousDownloadView_ setHidden:NO]; 236 [dangerousDownloadView_ setHidden:NO];
225 } 237 }
226 [shelf_ layoutItems]; 238 [shelf_ layoutItems];
227 } 239 }
228 240
241 - (void)themeDidChangeNotification:(NSNotification*)aNotification {
242 GTMTheme* theme = [aNotification object];
243 [self updateTheme:theme];
244 }
245
246 - (void)updateTheme:(GTMTheme*)theme {
247 NSColor* color = [theme textColorForStyle:GTMThemeStyleTabBarSelected
248 state:GTMThemeStateActiveWindow];
249 [dangerousDownloadLabel_ setTextColor:color];
250 }
251
229 - (IBAction)saveDownload:(id)sender { 252 - (IBAction)saveDownload:(id)sender {
230 // The user has confirmed a dangerous download. We record how quickly the 253 // The user has confirmed a dangerous download. We record how quickly the
231 // user did this to detect whether we're being clickjacked. 254 // user did this to detect whether we're being clickjacked.
232 UMA_HISTOGRAM_LONG_TIMES("clickjacking.save_download", 255 UMA_HISTOGRAM_LONG_TIMES("clickjacking.save_download",
233 base::Time::Now() - creationTime_); 256 base::Time::Now() - creationTime_);
234 // This will change the state and notify us. 257 // This will change the state and notify us.
235 bridge_->download_model()->download()->manager()->DangerousDownloadValidated( 258 bridge_->download_model()->download()->manager()->DangerousDownloadValidated(
236 bridge_->download_model()->download()); 259 bridge_->download_model()->download());
237 } 260 }
238 261
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 310
288 - (IBAction)handleReveal:(id)sender { 311 - (IBAction)handleReveal:(id)sender {
289 menuBridge_->ExecuteItemCommand(DownloadShelfContextMenuMac::SHOW_IN_FOLDER); 312 menuBridge_->ExecuteItemCommand(DownloadShelfContextMenuMac::SHOW_IN_FOLDER);
290 } 313 }
291 314
292 - (IBAction)handleCancel:(id)sender { 315 - (IBAction)handleCancel:(id)sender {
293 menuBridge_->ExecuteItemCommand(DownloadShelfContextMenuMac::CANCEL); 316 menuBridge_->ExecuteItemCommand(DownloadShelfContextMenuMac::CANCEL);
294 } 317 }
295 318
296 @end 319 @end
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698