Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8126)

Unified Diff: chrome/browser/views/download_item_view.cc

Issue 8991: Always show file extensions in the shelf. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 12 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/file_util.cc ('k') | chrome/common/gfx/chrome_canvas.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/views/download_item_view.cc
===================================================================
--- chrome/browser/views/download_item_view.cc (revision 4245)
+++ chrome/browser/views/download_item_view.cc (working copy)
@@ -201,10 +201,23 @@
AddChildView(save_button_);
AddChildView(discard_button_);
std::wstring file_name = download->original_name();
+
// Ensure the file name is not too long.
- ElideString(file_name, kFileNameMaxLength, &file_name);
+
+ // Extract the file extension (if any).
+ std::wstring extension = file_util::GetFileExtensionFromPath(file_name);
+ std::wstring rootname =
+ file_util::GetFilenameWithoutExtensionFromPath(file_name);
+
+ // Elide giant extensions (this shouldn't currently be hit, but might
+ // in future, should we ever notice unsafe giant extensions).
+ if (extension.length() > kFileNameMaxLength / 2)
+ ElideString(extension, kFileNameMaxLength / 2, &extension);
+
+ ElideString(rootname, kFileNameMaxLength - extension.length(), &rootname);
dangerous_download_label_ = new views::Label(
- l10n_util::GetStringF(IDS_PROMPT_DANGEROUS_DOWNLOAD, file_name));
+ l10n_util::GetStringF(IDS_PROMPT_DANGEROUS_DOWNLOAD,
+ rootname + L"." + extension));
dangerous_download_label_->SetMultiLine(true);
dangerous_download_label_->SetHorizontalAlignment(
views::Label::ALIGN_LEFT);
@@ -438,15 +451,51 @@
}
}
- // Print the text, left aligned.
+ // Print the text, left aligned and always print the file extension.
// Last value of x was the end of the right image, just before the button.
// Note that in dangerous mode we use a label (as the text is multi-line).
if (!IsDangerousMode()) {
+ // Because just drawing the filename using DrawStringInt results in
+ // Windows eliding the text and potentially chopping off the file
+ // extension, we need to draw the file's name and extension separately.
+
+ // Extract the file extension (if any).
+ std::wstring extension = L"." +
+ file_util::GetFileExtensionFromPath(download_->GetFileName());
+ std::wstring rootname = file_util::GetFilenameWithoutExtensionFromPath(
+ download_->GetFileName());
+
+ // Figure out the width of the extension.
+ int ext_width = 0;
+ int file_width = 0;
+ int h = 0;
+ canvas->SizeStringInt(extension, font_, &ext_width, &h,
+ ChromeCanvas::NO_ELLIPSIS);
+ canvas->SizeStringInt(rootname, font_, &file_width, &h,
+ ChromeCanvas::NO_ELLIPSIS);
+
+ // If the extension is ridiculously long, truncate it.
+ if (ext_width > kTextWidth / 2)
+ ext_width = kTextWidth / 2;
+
+ // Expand the extension width to fill any spare space so that
+ // it is aligned to the right edge of the file.
+ if (file_width < kTextWidth - ext_width)
+ ext_width = kTextWidth - file_width;
+
if (show_status_text_) {
int y = box_y_ + kVerticalPadding;
- canvas->DrawStringInt(download_->GetFileName(), font_, kFileNameColor,
+
+ // Draw the file's name.
+ canvas->DrawStringInt(rootname, font_, kFileNameColor,
download_util::kSmallProgressIconSize, y,
- kTextWidth, font_.height());
+ kTextWidth - ext_width, font_.height());
+
+ // Draw the file's extension.
+ canvas->DrawStringInt(extension, font_, kFileNameColor,
+ download_util::kSmallProgressIconSize +
+ kTextWidth - ext_width, y,
+ ext_width, font_.height());
y += font_.height() + kVerticalTextPadding;
canvas->DrawStringInt(status_text_, font_, kStatusColor,
@@ -454,9 +503,17 @@
kTextWidth, font_.height());
} else {
int y = box_y_ + (box_height_ - font_.height()) / 2;
- canvas->DrawStringInt(download_->GetFileName(), font_, kFileNameColor,
+
+ // Draw the file's name.
+ canvas->DrawStringInt(rootname, font_, kFileNameColor,
download_util::kSmallProgressIconSize, y,
- kTextWidth, font_.height());
+ kTextWidth - ext_width, font_.height());
+
+ // Draw the file's extension.
+ canvas->DrawStringInt(extension, font_, kFileNameColor,
+ download_util::kSmallProgressIconSize +
+ kTextWidth - ext_width, y,
+ ext_width, font_.height());
}
}
« no previous file with comments | « base/file_util.cc ('k') | chrome/common/gfx/chrome_canvas.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698