OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 #include "chrome/browser/views/download_item_view.h" | 5 #include "chrome/browser/views/download_item_view.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 l10n_util::GetString(IDS_SAVE_DOWNLOAD)); | 194 l10n_util::GetString(IDS_SAVE_DOWNLOAD)); |
195 save_button_->set_enforce_dlu_min_size(false); | 195 save_button_->set_enforce_dlu_min_size(false); |
196 save_button_->SetListener(this); | 196 save_button_->SetListener(this); |
197 discard_button_ = new views::NativeButton( | 197 discard_button_ = new views::NativeButton( |
198 l10n_util::GetString(IDS_DISCARD_DOWNLOAD)); | 198 l10n_util::GetString(IDS_DISCARD_DOWNLOAD)); |
199 discard_button_->SetListener(this); | 199 discard_button_->SetListener(this); |
200 discard_button_->set_enforce_dlu_min_size(false); | 200 discard_button_->set_enforce_dlu_min_size(false); |
201 AddChildView(save_button_); | 201 AddChildView(save_button_); |
202 AddChildView(discard_button_); | 202 AddChildView(discard_button_); |
203 std::wstring file_name = download->original_name(); | 203 std::wstring file_name = download->original_name(); |
| 204 |
204 // Ensure the file name is not too long. | 205 // Ensure the file name is not too long. |
205 ElideString(file_name, kFileNameMaxLength, &file_name); | 206 |
| 207 // Extract the file extension (if any). |
| 208 std::wstring extension = file_util::GetFileExtensionFromPath(file_name); |
| 209 std::wstring rootname = |
| 210 file_util::GetFilenameWithoutExtensionFromPath(file_name); |
| 211 |
| 212 // Elide giant extensions (this shouldn't currently be hit, but might |
| 213 // in future, should we ever notice unsafe giant extensions). |
| 214 if (extension.length() > kFileNameMaxLength / 2) |
| 215 ElideString(extension, kFileNameMaxLength / 2, &extension); |
| 216 |
| 217 ElideString(rootname, kFileNameMaxLength - extension.length(), &rootname); |
206 dangerous_download_label_ = new views::Label( | 218 dangerous_download_label_ = new views::Label( |
207 l10n_util::GetStringF(IDS_PROMPT_DANGEROUS_DOWNLOAD, file_name)); | 219 l10n_util::GetStringF(IDS_PROMPT_DANGEROUS_DOWNLOAD, |
| 220 rootname + L"." + extension)); |
208 dangerous_download_label_->SetMultiLine(true); | 221 dangerous_download_label_->SetMultiLine(true); |
209 dangerous_download_label_->SetHorizontalAlignment( | 222 dangerous_download_label_->SetHorizontalAlignment( |
210 views::Label::ALIGN_LEFT); | 223 views::Label::ALIGN_LEFT); |
211 dangerous_download_label_->SetColor(kFileNameColor); | 224 dangerous_download_label_->SetColor(kFileNameColor); |
212 AddChildView(dangerous_download_label_); | 225 AddChildView(dangerous_download_label_); |
213 SizeLabelToMinWidth(); | 226 SizeLabelToMinWidth(); |
214 } | 227 } |
215 | 228 |
216 // Set up our animation. | 229 // Set up our animation. |
217 StartDownloadProgress(); | 230 StartDownloadProgress(); |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
431 | 444 |
432 PaintBitmaps(canvas, | 445 PaintBitmaps(canvas, |
433 drop_down_image_set->top, drop_down_image_set->center, | 446 drop_down_image_set->top, drop_down_image_set->center, |
434 drop_down_image_set->bottom, | 447 drop_down_image_set->bottom, |
435 x, box_y_, box_height_, drop_down_image_set->top->width()); | 448 x, box_y_, box_height_, drop_down_image_set->top->width()); |
436 | 449 |
437 canvas->restore(); | 450 canvas->restore(); |
438 } | 451 } |
439 } | 452 } |
440 | 453 |
441 // Print the text, left aligned. | 454 // Print the text, left aligned and always print the file extension. |
442 // Last value of x was the end of the right image, just before the button. | 455 // Last value of x was the end of the right image, just before the button. |
443 // Note that in dangerous mode we use a label (as the text is multi-line). | 456 // Note that in dangerous mode we use a label (as the text is multi-line). |
444 if (!IsDangerousMode()) { | 457 if (!IsDangerousMode()) { |
| 458 // Because just drawing the filename using DrawStringInt results in |
| 459 // Windows eliding the text and potentially chopping off the file |
| 460 // extension, we need to draw the file's name and extension separately. |
| 461 |
| 462 // Extract the file extension (if any). |
| 463 std::wstring extension = L"." + |
| 464 file_util::GetFileExtensionFromPath(download_->GetFileName()); |
| 465 std::wstring rootname = file_util::GetFilenameWithoutExtensionFromPath( |
| 466 download_->GetFileName()); |
| 467 |
| 468 // Figure out the width of the extension. |
| 469 int ext_width = 0; |
| 470 int file_width = 0; |
| 471 int h = 0; |
| 472 canvas->SizeStringInt(extension, font_, &ext_width, &h, |
| 473 ChromeCanvas::NO_ELLIPSIS); |
| 474 canvas->SizeStringInt(rootname, font_, &file_width, &h, |
| 475 ChromeCanvas::NO_ELLIPSIS); |
| 476 |
| 477 // If the extension is ridiculously long, truncate it. |
| 478 if (ext_width > kTextWidth / 2) |
| 479 ext_width = kTextWidth / 2; |
| 480 |
| 481 // Expand the extension width to fill any spare space so that |
| 482 // it is aligned to the right edge of the file. |
| 483 if (file_width < kTextWidth - ext_width) |
| 484 ext_width = kTextWidth - file_width; |
| 485 |
445 if (show_status_text_) { | 486 if (show_status_text_) { |
446 int y = box_y_ + kVerticalPadding; | 487 int y = box_y_ + kVerticalPadding; |
447 canvas->DrawStringInt(download_->GetFileName(), font_, kFileNameColor, | 488 |
| 489 // Draw the file's name. |
| 490 canvas->DrawStringInt(rootname, font_, kFileNameColor, |
448 download_util::kSmallProgressIconSize, y, | 491 download_util::kSmallProgressIconSize, y, |
449 kTextWidth, font_.height()); | 492 kTextWidth - ext_width, font_.height()); |
| 493 |
| 494 // Draw the file's extension. |
| 495 canvas->DrawStringInt(extension, font_, kFileNameColor, |
| 496 download_util::kSmallProgressIconSize + |
| 497 kTextWidth - ext_width, y, |
| 498 ext_width, font_.height()); |
450 y += font_.height() + kVerticalTextPadding; | 499 y += font_.height() + kVerticalTextPadding; |
451 | 500 |
452 canvas->DrawStringInt(status_text_, font_, kStatusColor, | 501 canvas->DrawStringInt(status_text_, font_, kStatusColor, |
453 download_util::kSmallProgressIconSize, y, | 502 download_util::kSmallProgressIconSize, y, |
454 kTextWidth, font_.height()); | 503 kTextWidth, font_.height()); |
455 } else { | 504 } else { |
456 int y = box_y_ + (box_height_ - font_.height()) / 2; | 505 int y = box_y_ + (box_height_ - font_.height()) / 2; |
457 canvas->DrawStringInt(download_->GetFileName(), font_, kFileNameColor, | 506 |
| 507 // Draw the file's name. |
| 508 canvas->DrawStringInt(rootname, font_, kFileNameColor, |
458 download_util::kSmallProgressIconSize, y, | 509 download_util::kSmallProgressIconSize, y, |
459 kTextWidth, font_.height()); | 510 kTextWidth - ext_width, font_.height()); |
| 511 |
| 512 // Draw the file's extension. |
| 513 canvas->DrawStringInt(extension, font_, kFileNameColor, |
| 514 download_util::kSmallProgressIconSize + |
| 515 kTextWidth - ext_width, y, |
| 516 ext_width, font_.height()); |
460 } | 517 } |
461 } | 518 } |
462 | 519 |
463 // Paint the icon. | 520 // Paint the icon. |
464 IconManager* im = g_browser_process->icon_manager(); | 521 IconManager* im = g_browser_process->icon_manager(); |
465 SkBitmap* icon = IsDangerousMode() ? warning_icon_ : | 522 SkBitmap* icon = IsDangerousMode() ? warning_icon_ : |
466 im->LookupIcon(download_->full_path(), IconLoader::SMALL); | 523 im->LookupIcon(download_->full_path(), IconLoader::SMALL); |
467 | 524 |
468 if (icon) { | 525 if (icon) { |
469 if (!IsDangerousMode()) { | 526 if (!IsDangerousMode()) { |
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
786 sp_index = text.find(L" ", sp_index + 1); | 843 sp_index = text.find(L" ", sp_index + 1); |
787 } | 844 } |
788 | 845 |
789 // If we have a line with no space, we won't cut it. | 846 // If we have a line with no space, we won't cut it. |
790 if (min_width == -1) | 847 if (min_width == -1) |
791 size = dangerous_download_label_->GetPreferredSize(); | 848 size = dangerous_download_label_->GetPreferredSize(); |
792 | 849 |
793 dangerous_download_label_->SetBounds(0, 0, size.width(), size.height()); | 850 dangerous_download_label_->SetBounds(0, 0, size.width(), size.height()); |
794 dangerous_download_label_sized_ = true; | 851 dangerous_download_label_sized_ = true; |
795 } | 852 } |
OLD | NEW |