| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/l10n_util_mac.h" | 7 #include "app/l10n_util_mac.h" |
| 8 #include "app/resource_bundle.h" | 8 #include "app/resource_bundle.h" |
| 9 #include "app/text_elider.h" | 9 #include "app/text_elider.h" |
| 10 #include "base/mac_util.h" | 10 #include "base/mac_util.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 // NOTE: Mac currently doesn't use this like Windows does. Mac uses this to | 29 // NOTE: Mac currently doesn't use this like Windows does. Mac uses this to |
| 30 // control the min size on the dangerous download text. TVL sent a query off to | 30 // control the min size on the dangerous download text. TVL sent a query off to |
| 31 // UX to fully spec all the the behaviors of download items and truncations | 31 // UX to fully spec all the the behaviors of download items and truncations |
| 32 // rules so all platforms can get inline in the future. | 32 // rules so all platforms can get inline in the future. |
| 33 const int kTextWidth = 140; // Pixels | 33 const int kTextWidth = 140; // Pixels |
| 34 | 34 |
| 35 // The maximum number of characters we show in a file name when displaying the | 35 // The maximum number of characters we show in a file name when displaying the |
| 36 // dangerous download message. | 36 // dangerous download message. |
| 37 const int kFileNameMaxLength = 20; | 37 const int kFileNameMaxLength = 20; |
| 38 | 38 |
| 39 // The maximum width in pixels for the file name tooltip. |
| 40 const int kToolTipMaxWidth = 900; |
| 41 |
| 42 |
| 39 // Helper to widen a view. | 43 // Helper to widen a view. |
| 40 void WidenView(NSView* view, CGFloat widthChange) { | 44 void WidenView(NSView* view, CGFloat widthChange) { |
| 41 // If it is an NSBox, the autoresize of the contentView is the issue. | 45 // If it is an NSBox, the autoresize of the contentView is the issue. |
| 42 NSView* contentView = view; | 46 NSView* contentView = view; |
| 43 if ([view isKindOfClass:[NSBox class]]) { | 47 if ([view isKindOfClass:[NSBox class]]) { |
| 44 contentView = [(NSBox*)view contentView]; | 48 contentView = [(NSBox*)view contentView]; |
| 45 } | 49 } |
| 46 BOOL autoresizesSubviews = [contentView autoresizesSubviews]; | 50 BOOL autoresizesSubviews = [contentView autoresizesSubviews]; |
| 47 if (autoresizesSubviews) { | 51 if (autoresizesSubviews) { |
| 48 [contentView setAutoresizesSubviews:NO]; | 52 [contentView setAutoresizesSubviews:NO]; |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 NSPoint frameOrigin = [buttonTweaker_ frame].origin; | 147 NSPoint frameOrigin = [buttonTweaker_ frame].origin; |
| 144 frameOrigin.x += widthChange; | 148 frameOrigin.x += widthChange; |
| 145 [buttonTweaker_ setFrameOrigin:frameOrigin]; | 149 [buttonTweaker_ setFrameOrigin:frameOrigin]; |
| 146 | 150 |
| 147 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 151 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 148 NSImage* alertIcon = rb.GetNSImageNamed(IDR_WARNING); | 152 NSImage* alertIcon = rb.GetNSImageNamed(IDR_WARNING); |
| 149 DCHECK(alertIcon); | 153 DCHECK(alertIcon); |
| 150 [image_ setImage:alertIcon]; | 154 [image_ setImage:alertIcon]; |
| 151 | 155 |
| 152 bridge_->LoadIcon(); | 156 bridge_->LoadIcon(); |
| 157 [self updateToolTip]; |
| 153 } | 158 } |
| 154 | 159 |
| 155 - (void)setStateFromDownload:(BaseDownloadItemModel*)downloadModel { | 160 - (void)setStateFromDownload:(BaseDownloadItemModel*)downloadModel { |
| 156 DCHECK_EQ(bridge_->download_model(), downloadModel); | 161 DCHECK_EQ(bridge_->download_model(), downloadModel); |
| 157 | 162 |
| 158 // Handle dangerous downloads. | 163 // Handle dangerous downloads. |
| 159 if (downloadModel->download()->safety_state() == DownloadItem::DANGEROUS) { | 164 if (downloadModel->download()->safety_state() == DownloadItem::DANGEROUS) { |
| 160 [self setState:kDangerous]; | 165 [self setState:kDangerous]; |
| 161 | 166 |
| 162 NSString* dangerousWarning; | 167 NSString* dangerousWarning; |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 if (state_ == kNormal) | 252 if (state_ == kNormal) |
| 248 return [progressView_ frame].size; | 253 return [progressView_ frame].size; |
| 249 DCHECK_EQ(kDangerous, state_); | 254 DCHECK_EQ(kDangerous, state_); |
| 250 return [dangerousDownloadView_ frame].size; | 255 return [dangerousDownloadView_ frame].size; |
| 251 } | 256 } |
| 252 | 257 |
| 253 - (DownloadItem*)download { | 258 - (DownloadItem*)download { |
| 254 return bridge_->download_model()->download(); | 259 return bridge_->download_model()->download(); |
| 255 } | 260 } |
| 256 | 261 |
| 262 - (void)updateToolTip { |
| 263 std::wstring elidedFilename = gfx::ElideFilename( |
| 264 [self download]->GetFileName(), |
| 265 gfx::Font(), kToolTipMaxWidth); |
| 266 [progressView_ setToolTip:base::SysWideToNSString(elidedFilename)]; |
| 267 } |
| 268 |
| 257 - (void)clearDangerousMode { | 269 - (void)clearDangerousMode { |
| 258 [self setState:kNormal]; | 270 [self setState:kNormal]; |
| 259 // The state change hide the dangerouse download view and is now showing the | 271 // The state change hide the dangerouse download view and is now showing the |
| 260 // download progress view. This means the view is likely to be a different | 272 // download progress view. This means the view is likely to be a different |
| 261 // size, so trigger a shelf layout to fix up spacing. | 273 // size, so trigger a shelf layout to fix up spacing. |
| 262 [shelf_ layoutItems]; | 274 [shelf_ layoutItems]; |
| 263 } | 275 } |
| 264 | 276 |
| 265 - (BOOL)isDangerousMode { | 277 - (BOOL)isDangerousMode { |
| 266 return state_ == kDangerous; | 278 return state_ == kDangerous; |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 [sender setTitle:l10n_util::GetNSStringWithFixup( | 384 [sender setTitle:l10n_util::GetNSStringWithFixup( |
| 373 IDS_DOWNLOAD_MENU_PAUSE_ITEM)]; | 385 IDS_DOWNLOAD_MENU_PAUSE_ITEM)]; |
| 374 } else { | 386 } else { |
| 375 [sender setTitle:l10n_util::GetNSStringWithFixup( | 387 [sender setTitle:l10n_util::GetNSStringWithFixup( |
| 376 IDS_DOWNLOAD_MENU_RESUME_ITEM)]; | 388 IDS_DOWNLOAD_MENU_RESUME_ITEM)]; |
| 377 } | 389 } |
| 378 menuBridge_->ExecuteCommand(DownloadShelfContextMenuMac::TOGGLE_PAUSE); | 390 menuBridge_->ExecuteCommand(DownloadShelfContextMenuMac::TOGGLE_PAUSE); |
| 379 } | 391 } |
| 380 | 392 |
| 381 @end | 393 @end |
| OLD | NEW |