| 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_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" |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 | 93 |
| 94 shelf_ = shelf; | 94 shelf_ = shelf; |
| 95 state_ = kNormal; | 95 state_ = kNormal; |
| 96 creationTime_ = base::Time::Now(); | 96 creationTime_ = base::Time::Now(); |
| 97 } | 97 } |
| 98 return self; | 98 return self; |
| 99 } | 99 } |
| 100 | 100 |
| 101 - (void)dealloc { | 101 - (void)dealloc { |
| 102 [[NSNotificationCenter defaultCenter] removeObserver:self]; | 102 [[NSNotificationCenter defaultCenter] removeObserver:self]; |
| 103 [progressView_ setController:nil]; |
| 103 [[self view] removeFromSuperview]; | 104 [[self view] removeFromSuperview]; |
| 104 [super dealloc]; | 105 [super dealloc]; |
| 105 } | 106 } |
| 106 | 107 |
| 107 - (void)awakeFromNib { | 108 - (void)awakeFromNib { |
| 109 [progressView_ setController:self]; |
| 110 |
| 108 [self setStateFromDownload:bridge_->download_model()]; | 111 [self setStateFromDownload:bridge_->download_model()]; |
| 109 | 112 |
| 110 GTMUILocalizerAndLayoutTweaker* localizerAndLayoutTweaker = | 113 GTMUILocalizerAndLayoutTweaker* localizerAndLayoutTweaker = |
| 111 [[[GTMUILocalizerAndLayoutTweaker alloc] init] autorelease]; | 114 [[[GTMUILocalizerAndLayoutTweaker alloc] init] autorelease]; |
| 112 [localizerAndLayoutTweaker applyLocalizer:localizer_ tweakingUI:[self view]]; | 115 [localizerAndLayoutTweaker applyLocalizer:localizer_ tweakingUI:[self view]]; |
| 113 | 116 |
| 114 // Since the shelf keeps laying out views as more items are added, relying on | 117 // Since the shelf keeps laying out views as more items are added, relying on |
| 115 // the WidthBaseTweaker to resize the dangerous download part does not work. | 118 // the WidthBaseTweaker to resize the dangerous download part does not work. |
| 116 DCHECK(buttonTweaker_ != nil); | 119 DCHECK(buttonTweaker_ != nil); |
| 117 CGFloat widthChange = [buttonTweaker_ changedWidth]; | 120 CGFloat widthChange = [buttonTweaker_ changedWidth]; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 IDS_PROMPT_DANGEROUS_DOWNLOAD, elidedFilename); | 160 IDS_PROMPT_DANGEROUS_DOWNLOAD, elidedFilename); |
| 158 confirmButtonTitle = l10n_util::GetNSStringWithFixup(IDS_SAVE_DOWNLOAD); | 161 confirmButtonTitle = l10n_util::GetNSStringWithFixup(IDS_SAVE_DOWNLOAD); |
| 159 } | 162 } |
| 160 [dangerousDownloadLabel_ setStringValue:dangerousWarning]; | 163 [dangerousDownloadLabel_ setStringValue:dangerousWarning]; |
| 161 [dangerousDownloadConfirmButton_ setTitle:confirmButtonTitle]; | 164 [dangerousDownloadConfirmButton_ setTitle:confirmButtonTitle]; |
| 162 return; | 165 return; |
| 163 } | 166 } |
| 164 | 167 |
| 165 // Set correct popup menu. Also, set draggable download on completion. | 168 // Set correct popup menu. Also, set draggable download on completion. |
| 166 if (downloadModel->download()->state() == DownloadItem::COMPLETE) { | 169 if (downloadModel->download()->state() == DownloadItem::COMPLETE) { |
| 167 currentMenu_ = completeDownloadMenu_; | 170 [progressView_ setMenu:completeDownloadMenu_]; |
| 168 [progressView_ setDownload:downloadModel->download()->full_path()]; | 171 [progressView_ setDownload:downloadModel->download()->full_path()]; |
| 169 } else { | 172 } else { |
| 170 currentMenu_ = activeDownloadMenu_; | 173 [progressView_ setMenu:activeDownloadMenu_]; |
| 171 } | 174 } |
| 172 | 175 |
| 173 [progressView_ setMenu:currentMenu_]; // for context menu | |
| 174 [cell_ setStateFromDownload:downloadModel]; | 176 [cell_ setStateFromDownload:downloadModel]; |
| 175 } | 177 } |
| 176 | 178 |
| 177 - (void)setIcon:(NSImage*)icon { | 179 - (void)setIcon:(NSImage*)icon { |
| 178 [cell_ setImage:icon]; | 180 [cell_ setImage:icon]; |
| 179 } | 181 } |
| 180 | 182 |
| 181 - (void)remove { | 183 - (void)remove { |
| 182 // We are deleted after this! | 184 // We are deleted after this! |
| 183 [shelf_ remove:self]; | 185 [shelf_ remove:self]; |
| 184 } | 186 } |
| 185 | 187 |
| 186 - (void)updateVisibility:(id)sender { | 188 - (void)updateVisibility:(id)sender { |
| 187 if ([[self view] window]) | 189 if ([[self view] window]) |
| 188 [self updateTheme:[[self view] gtm_theme]]; | 190 [self updateTheme:[[self view] gtm_theme]]; |
| 189 | 191 |
| 190 // TODO(thakis): Make this prettier, by fading the items out or overlaying | 192 // TODO(thakis): Make this prettier, by fading the items out or overlaying |
| 191 // the partial visible one with a horizontal alpha gradient -- crbug.com/17830 | 193 // the partial visible one with a horizontal alpha gradient -- crbug.com/17830 |
| 192 NSView* view = [self view]; | 194 NSView* view = [self view]; |
| 193 NSRect containerFrame = [[view superview] frame]; | 195 NSRect containerFrame = [[view superview] frame]; |
| 194 [view setHidden:(NSMaxX([view frame]) > NSWidth(containerFrame))]; | 196 [view setHidden:(NSMaxX([view frame]) > NSWidth(containerFrame))]; |
| 195 } | 197 } |
| 196 | 198 |
| 197 - (IBAction)handleButtonClick:(id)sender { | 199 - (IBAction)handleButtonClick:(id)sender { |
| 198 if ([cell_ isButtonPartPressed]) { | 200 DownloadItem* download = bridge_->download_model()->download(); |
| 199 DownloadItem* download = bridge_->download_model()->download(); | 201 if (download->state() == DownloadItem::IN_PROGRESS) |
| 200 if (download->state() == DownloadItem::IN_PROGRESS) | 202 download->set_open_when_complete(!download->open_when_complete()); |
| 201 download->set_open_when_complete(!download->open_when_complete()); | 203 else if (download->state() == DownloadItem::COMPLETE) |
| 202 else if (download->state() == DownloadItem::COMPLETE) | 204 download_util::OpenDownload(download); |
| 203 download_util::OpenDownload(download); | |
| 204 } else { | |
| 205 // Hold a reference to ourselves in case the download completes and we | |
| 206 // represent a file that's auto-removed (e.g. a theme). | |
| 207 scoped_nsobject<DownloadItemController> ref([self retain]); | |
| 208 [NSMenu popUpContextMenu:currentMenu_ | |
| 209 withEvent:[NSApp currentEvent] | |
| 210 forView:progressView_]; | |
| 211 } | |
| 212 } | 205 } |
| 213 | 206 |
| 214 - (NSSize)preferredSize { | 207 - (NSSize)preferredSize { |
| 215 if (state_ == kNormal) | 208 if (state_ == kNormal) |
| 216 return [progressView_ frame].size; | 209 return [progressView_ frame].size; |
| 217 DCHECK_EQ(kDangerous, state_); | 210 DCHECK_EQ(kDangerous, state_); |
| 218 return [dangerousDownloadView_ frame].size; | 211 return [dangerousDownloadView_ frame].size; |
| 219 } | 212 } |
| 220 | 213 |
| 221 - (DownloadItem*)download { | 214 - (DownloadItem*)download { |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 326 | 319 |
| 327 - (IBAction)handleCancel:(id)sender { | 320 - (IBAction)handleCancel:(id)sender { |
| 328 menuBridge_->ExecuteItemCommand(DownloadShelfContextMenuMac::CANCEL); | 321 menuBridge_->ExecuteItemCommand(DownloadShelfContextMenuMac::CANCEL); |
| 329 } | 322 } |
| 330 | 323 |
| 331 - (IBAction)handleTogglePause:(id)sender { | 324 - (IBAction)handleTogglePause:(id)sender { |
| 332 menuBridge_->ExecuteItemCommand(DownloadShelfContextMenuMac::TOGGLE_PAUSE); | 325 menuBridge_->ExecuteItemCommand(DownloadShelfContextMenuMac::TOGGLE_PAUSE); |
| 333 } | 326 } |
| 334 | 327 |
| 335 @end | 328 @end |
| OLD | NEW |