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 26 matching lines...) Expand all Loading... |
37 namespace { | 37 namespace { |
38 | 38 |
39 // NOTE: Mac currently doesn't use this like Windows does. Mac uses this to | 39 // NOTE: Mac currently doesn't use this like Windows does. Mac uses this to |
40 // control the min size on the dangerous download text. TVL sent a query off to | 40 // control the min size on the dangerous download text. TVL sent a query off to |
41 // UX to fully spec all the the behaviors of download items and truncations | 41 // UX to fully spec all the the behaviors of download items and truncations |
42 // rules so all platforms can get inline in the future. | 42 // rules so all platforms can get inline in the future. |
43 const int kTextWidth = 140; // Pixels | 43 const int kTextWidth = 140; // Pixels |
44 | 44 |
45 // The maximum width in pixels for the file name tooltip. | 45 // The maximum width in pixels for the file name tooltip. |
46 const int kToolTipMaxWidth = 900; | 46 const int kToolTipMaxWidth = 900; |
| 47 const int kToolTipErrorMessageMaxHeight = kToolTipMaxWidth / 4; |
47 | 48 |
48 | 49 |
49 // Helper to widen a view. | 50 // Helper to widen a view. |
50 void WidenView(NSView* view, CGFloat widthChange) { | 51 void WidenView(NSView* view, CGFloat widthChange) { |
51 // If it is an NSBox, the autoresize of the contentView is the issue. | 52 // If it is an NSBox, the autoresize of the contentView is the issue. |
52 NSView* contentView = view; | 53 NSView* contentView = view; |
53 if ([view isKindOfClass:[NSBox class]]) { | 54 if ([view isKindOfClass:[NSBox class]]) { |
54 contentView = [(NSBox*)view contentView]; | 55 contentView = [(NSBox*)view contentView]; |
55 } | 56 } |
56 BOOL autoresizesSubviews = [contentView autoresizesSubviews]; | 57 BOOL autoresizesSubviews = [contentView autoresizesSubviews]; |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 return [progressView_ frame].size; | 239 return [progressView_ frame].size; |
239 DCHECK_EQ(kDangerous, state_); | 240 DCHECK_EQ(kDangerous, state_); |
240 return [dangerousDownloadView_ frame].size; | 241 return [dangerousDownloadView_ frame].size; |
241 } | 242 } |
242 | 243 |
243 - (DownloadItem*)download { | 244 - (DownloadItem*)download { |
244 return bridge_->download_model()->download(); | 245 return bridge_->download_model()->download(); |
245 } | 246 } |
246 | 247 |
247 - (void)updateToolTip { | 248 - (void)updateToolTip { |
248 string16 elidedFilename = ui::ElideFilename( | 249 string16 tooltip_text = ui::ElideFilename( |
249 [self download]->GetFileNameToReportUser(), *font_, kToolTipMaxWidth); | 250 [self download]->GetFileNameToReportUser(), *font_, kToolTipMaxWidth); |
250 [progressView_ setToolTip:base::SysUTF16ToNSString(elidedFilename)]; | 251 |
| 252 if ([self download]->GetState() == content::DownloadItem::INTERRUPTED) { |
| 253 content::DownloadInterruptReason reason = [self download]->GetLastReason(); |
| 254 DCHECK(reason != 0); |
| 255 |
| 256 // Split up the error description string as necessary. |
| 257 std::vector<string16> elidedMessages; |
| 258 ui::ElideRectangleText( |
| 259 DownloadItemModel::InterruptReasonMessage(reason), |
| 260 *font_, |
| 261 kToolTipMaxWidth, |
| 262 kToolTipErrorMessageMaxHeight, |
| 263 ui::IGNORE_LONG_WORDS, |
| 264 &elidedMessages); |
| 265 |
| 266 string16 new_line = ASCIIToUTF16("\n"); |
| 267 tooltip_text += new_line; |
| 268 |
| 269 for (size_t i = 0; i < elidedMessages.size(); ++i) { |
| 270 tooltip_text += elidedMessages[i]; |
| 271 tooltip_text += new_line; |
| 272 } |
| 273 |
| 274 tooltip_text += bridge_->download_model()->GetProgressText(); |
| 275 } |
| 276 |
| 277 [progressView_ setToolTip:base::SysUTF16ToNSString(tooltip_text)]; |
251 } | 278 } |
252 | 279 |
253 - (void)clearDangerousMode { | 280 - (void)clearDangerousMode { |
254 [self setState:kNormal]; | 281 [self setState:kNormal]; |
255 // The state change hide the dangerouse download view and is now showing the | 282 // The state change hide the dangerouse download view and is now showing the |
256 // download progress view. This means the view is likely to be a different | 283 // download progress view. This means the view is likely to be a different |
257 // size, so trigger a shelf layout to fix up spacing. | 284 // size, so trigger a shelf layout to fix up spacing. |
258 [shelf_ layoutItems]; | 285 [shelf_ layoutItems]; |
259 } | 286 } |
260 | 287 |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 [sender setTitle:l10n_util::GetNSStringWithFixup( | 394 [sender setTitle:l10n_util::GetNSStringWithFixup( |
368 IDS_DOWNLOAD_MENU_PAUSE_ITEM)]; | 395 IDS_DOWNLOAD_MENU_PAUSE_ITEM)]; |
369 } else { | 396 } else { |
370 [sender setTitle:l10n_util::GetNSStringWithFixup( | 397 [sender setTitle:l10n_util::GetNSStringWithFixup( |
371 IDS_DOWNLOAD_MENU_RESUME_ITEM)]; | 398 IDS_DOWNLOAD_MENU_RESUME_ITEM)]; |
372 } | 399 } |
373 menuBridge_->ExecuteCommand(DownloadShelfContextMenuMac::TOGGLE_PAUSE); | 400 menuBridge_->ExecuteCommand(DownloadShelfContextMenuMac::TOGGLE_PAUSE); |
374 } | 401 } |
375 | 402 |
376 @end | 403 @end |
OLD | NEW |