summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorglen@chromium.org <glen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-11-03 16:14:46 +0000
committerglen@chromium.org <glen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-11-03 16:14:46 +0000
commit52ab8f9091d3892f5528d5a71655d75635d1e66c (patch)
treec66d682d7753e3021eb3072d32517334199e779b /chrome
parent5d6c69626c90ffce59fcb13eb8e66a29d400907b (diff)
downloadchromium_src-52ab8f9091d3892f5528d5a71655d75635d1e66c.zip
chromium_src-52ab8f9091d3892f5528d5a71655d75635d1e66c.tar.gz
chromium_src-52ab8f9091d3892f5528d5a71655d75635d1e66c.tar.bz2
Always show file extensions in the shelf.
BUG=1208 Review URL: http://codereview.chromium.org/8991 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@4450 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/views/download_item_view.cc71
-rw-r--r--chrome/common/gfx/chrome_canvas.cc9
-rw-r--r--chrome/common/gfx/chrome_canvas.h3
3 files changed, 73 insertions, 10 deletions
diff --git a/chrome/browser/views/download_item_view.cc b/chrome/browser/views/download_item_view.cc
index bc81238..01efbd6 100644
--- a/chrome/browser/views/download_item_view.cc
+++ b/chrome/browser/views/download_item_view.cc
@@ -201,10 +201,23 @@ DownloadItemView::DownloadItemView(DownloadItem* download,
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 @@ void DownloadItemView::Paint(ChromeCanvas* canvas) {
}
}
- // 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 @@ void DownloadItemView::Paint(ChromeCanvas* canvas) {
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());
}
}
diff --git a/chrome/common/gfx/chrome_canvas.cc b/chrome/common/gfx/chrome_canvas.cc
index 064a931..3114b14 100644
--- a/chrome/common/gfx/chrome_canvas.cc
+++ b/chrome/common/gfx/chrome_canvas.cc
@@ -232,10 +232,13 @@ int ChromeCanvas::ComputeFormatFlags(int flags) {
else if ((flags & SHOW_PREFIX) == 0)
f |= DT_NOPREFIX;
- if (flags & MULTI_LINE)
+ if (flags & MULTI_LINE) {
f |= DT_WORDBREAK;
- else
- f |= DT_SINGLELINE | DT_END_ELLIPSIS | DT_VCENTER;
+ } else {
+ f |= DT_SINGLELINE | DT_VCENTER;
+ if (!(flags & NO_ELLIPSIS))
+ f |= DT_END_ELLIPSIS;
+ }
// vertical alignment
if (flags & TEXT_VALIGN_TOP)
diff --git a/chrome/common/gfx/chrome_canvas.h b/chrome/common/gfx/chrome_canvas.h
index b32516d..b48fe0d 100644
--- a/chrome/common/gfx/chrome_canvas.h
+++ b/chrome/common/gfx/chrome_canvas.h
@@ -52,6 +52,9 @@ class ChromeCanvas : public gfx::PlatformCanvasWin {
static const int SHOW_PREFIX = 128;
static const int HIDE_PREFIX = 256;
+ // Prevent ellipsizing
+ static const int NO_ELLIPSIS = 512;
+
// Creates an empty ChromeCanvas. Callers must use initialize before using
// the canvas.
ChromeCanvas();