OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/ui/cocoa/download/download_item_controller.h" | 5 #import "chrome/browser/ui/cocoa/download/download_item_controller.h" |
6 | 6 |
7 #include "base/mac/bundle_locations.h" | 7 #include "base/mac/bundle_locations.h" |
8 #include "base/mac/mac_util.h" | 8 #include "base/mac/mac_util.h" |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "base/string16.h" | 10 #include "base/string16.h" |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 [contentView setAutoresizesSubviews:YES]; | 67 [contentView setAutoresizesSubviews:YES]; |
68 } | 68 } |
69 } | 69 } |
70 | 70 |
71 } // namespace | 71 } // namespace |
72 | 72 |
73 // A class for the chromium-side part of the download shelf context menu. | 73 // A class for the chromium-side part of the download shelf context menu. |
74 | 74 |
75 class DownloadShelfContextMenuMac : public DownloadShelfContextMenu { | 75 class DownloadShelfContextMenuMac : public DownloadShelfContextMenu { |
76 public: | 76 public: |
77 DownloadShelfContextMenuMac(DownloadItemModel* model, | 77 DownloadShelfContextMenuMac(DownloadItem* downloadItem, |
78 content::PageNavigator* navigator) | 78 content::PageNavigator* navigator) |
79 : DownloadShelfContextMenu(model, navigator) { } | 79 : DownloadShelfContextMenu(downloadItem, navigator) { } |
80 | 80 |
81 using DownloadShelfContextMenu::ExecuteCommand; | 81 using DownloadShelfContextMenu::ExecuteCommand; |
82 using DownloadShelfContextMenu::IsCommandIdChecked; | 82 using DownloadShelfContextMenu::IsCommandIdChecked; |
83 using DownloadShelfContextMenu::IsCommandIdEnabled; | 83 using DownloadShelfContextMenu::IsCommandIdEnabled; |
84 | 84 |
85 using DownloadShelfContextMenu::SHOW_IN_FOLDER; | 85 using DownloadShelfContextMenu::SHOW_IN_FOLDER; |
86 using DownloadShelfContextMenu::OPEN_WHEN_COMPLETE; | 86 using DownloadShelfContextMenu::OPEN_WHEN_COMPLETE; |
87 using DownloadShelfContextMenu::ALWAYS_OPEN_TYPE; | 87 using DownloadShelfContextMenu::ALWAYS_OPEN_TYPE; |
88 using DownloadShelfContextMenu::CANCEL; | 88 using DownloadShelfContextMenu::CANCEL; |
89 using DownloadShelfContextMenu::TOGGLE_PAUSE; | 89 using DownloadShelfContextMenu::TOGGLE_PAUSE; |
90 }; | 90 }; |
91 | 91 |
92 @interface DownloadItemController (Private) | 92 @interface DownloadItemController (Private) |
93 - (void)themeDidChangeNotification:(NSNotification*)aNotification; | 93 - (void)themeDidChangeNotification:(NSNotification*)aNotification; |
94 - (void)updateTheme:(ui::ThemeProvider*)themeProvider; | 94 - (void)updateTheme:(ui::ThemeProvider*)themeProvider; |
95 - (void)setState:(DownoadItemState)state; | 95 - (void)setState:(DownoadItemState)state; |
96 @end | 96 @end |
97 | 97 |
98 // Implementation of DownloadItemController | 98 // Implementation of DownloadItemController |
99 | 99 |
100 @implementation DownloadItemController | 100 @implementation DownloadItemController |
101 | 101 |
102 - (id)initWithModel:(DownloadItemModel*)downloadModel | 102 - (id)initWithDownload:(DownloadItem*)downloadItem |
103 shelf:(DownloadShelfController*)shelf | 103 shelf:(DownloadShelfController*)shelf |
104 navigator:(content::PageNavigator*)navigator { | 104 navigator:(content::PageNavigator*)navigator { |
105 if ((self = [super initWithNibName:@"DownloadItem" | 105 if ((self = [super initWithNibName:@"DownloadItem" |
106 bundle:base::mac::FrameworkBundle()])) { | 106 bundle:base::mac::FrameworkBundle()])) { |
107 // Must be called before [self view], so that bridge_ is set in awakeFromNib | 107 // Must be called before [self view], so that bridge_ is set in awakeFromNib |
108 bridge_.reset(new DownloadItemMac(downloadModel, self)); | 108 bridge_.reset(new DownloadItemMac(downloadItem, self)); |
109 menuBridge_.reset(new DownloadShelfContextMenuMac(downloadModel, | 109 menuBridge_.reset(new DownloadShelfContextMenuMac(downloadItem, |
110 navigator)); | 110 navigator)); |
111 | 111 |
112 NSNotificationCenter* defaultCenter = [NSNotificationCenter defaultCenter]; | 112 NSNotificationCenter* defaultCenter = [NSNotificationCenter defaultCenter]; |
113 [defaultCenter addObserver:self | 113 [defaultCenter addObserver:self |
114 selector:@selector(themeDidChangeNotification:) | 114 selector:@selector(themeDidChangeNotification:) |
115 name:kBrowserThemeDidChangeNotification | 115 name:kBrowserThemeDidChangeNotification |
116 object:nil]; | 116 object:nil]; |
117 | 117 |
118 shelf_ = shelf; | 118 shelf_ = shelf; |
119 state_ = kNormal; | 119 state_ = kNormal; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 // Slide the two buttons over. | 157 // Slide the two buttons over. |
158 NSPoint frameOrigin = [buttonTweaker_ frame].origin; | 158 NSPoint frameOrigin = [buttonTweaker_ frame].origin; |
159 frameOrigin.x += widthChange; | 159 frameOrigin.x += widthChange; |
160 [buttonTweaker_ setFrameOrigin:frameOrigin]; | 160 [buttonTweaker_ setFrameOrigin:frameOrigin]; |
161 | 161 |
162 bridge_->LoadIcon(); | 162 bridge_->LoadIcon(); |
163 [self updateToolTip]; | 163 [self updateToolTip]; |
164 } | 164 } |
165 | 165 |
166 - (void)setStateFromDownload:(DownloadItemModel*)downloadModel { | 166 - (void)setStateFromDownload:(DownloadItemModel*)downloadModel { |
167 DCHECK_EQ(bridge_->download_model(), downloadModel); | 167 DCHECK_EQ([self download], downloadModel->download()); |
168 | 168 |
169 // Handle dangerous downloads. | 169 // Handle dangerous downloads. |
170 if (downloadModel->IsDangerous()) { | 170 if (downloadModel->IsDangerous()) { |
171 [self setState:kDangerous]; | 171 [self setState:kDangerous]; |
172 | 172 |
173 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 173 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
174 NSString* dangerousWarning; | 174 NSString* dangerousWarning; |
175 NSString* confirmButtonTitle; | 175 NSString* confirmButtonTitle; |
176 NSImage* alertIcon; | 176 NSImage* alertIcon; |
177 | 177 |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 [sender setTitle:l10n_util::GetNSStringWithFixup( | 372 [sender setTitle:l10n_util::GetNSStringWithFixup( |
373 IDS_DOWNLOAD_MENU_PAUSE_ITEM)]; | 373 IDS_DOWNLOAD_MENU_PAUSE_ITEM)]; |
374 } else { | 374 } else { |
375 [sender setTitle:l10n_util::GetNSStringWithFixup( | 375 [sender setTitle:l10n_util::GetNSStringWithFixup( |
376 IDS_DOWNLOAD_MENU_RESUME_ITEM)]; | 376 IDS_DOWNLOAD_MENU_RESUME_ITEM)]; |
377 } | 377 } |
378 menuBridge_->ExecuteCommand(DownloadShelfContextMenuMac::TOGGLE_PAUSE); | 378 menuBridge_->ExecuteCommand(DownloadShelfContextMenuMac::TOGGLE_PAUSE); |
379 } | 379 } |
380 | 380 |
381 @end | 381 @end |
OLD | NEW |