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
This commit is contained in:
base
chrome
@ -90,13 +90,21 @@ std::wstring GetFilenameFromPath(const std::wstring& path) {
|
||||
// TODO(erikkay): fix this - it's not using kPathSeparator, but win unit test
|
||||
// are exercising '/' as a path separator as well.
|
||||
std::wstring::size_type pos = path.find_last_of(L"\\/");
|
||||
return std::wstring(path, pos == std::wstring::npos ? 0 : pos+1);
|
||||
return std::wstring(path, pos == std::wstring::npos ? 0 : pos + 1);
|
||||
}
|
||||
|
||||
std::wstring GetFileExtensionFromPath(const std::wstring& path) {
|
||||
std::wstring file_name = GetFilenameFromPath(path);
|
||||
std::wstring::size_type last_dot = file_name.rfind(L'.');
|
||||
return std::wstring(last_dot == std::wstring::npos? L"" : file_name, last_dot+1);
|
||||
return std::wstring(last_dot == std::wstring::npos ?
|
||||
L"" :
|
||||
file_name, last_dot+1);
|
||||
}
|
||||
|
||||
std::wstring GetFilenameWithoutExtensionFromPath(const std::wstring& path) {
|
||||
std::wstring file_name = GetFilenameFromPath(path);
|
||||
std::wstring::size_type last_dot = file_name.rfind(L'.');
|
||||
return file_name.substr(0, last_dot);
|
||||
}
|
||||
|
||||
void AppendToPath(std::wstring* path, const std::wstring& new_ending) {
|
||||
|
@ -69,6 +69,9 @@ std::wstring GetFilenameFromPath(const std::wstring& path);
|
||||
// the file has no extension.
|
||||
std::wstring GetFileExtensionFromPath(const std::wstring& path);
|
||||
|
||||
// Returns 'jojo' for path "C:\pics\jojo.jpg".
|
||||
std::wstring GetFilenameWithoutExtensionFromPath(const std::wstring& path);
|
||||
|
||||
// Returns the directory component of a path, without the trailing
|
||||
// path separator, or an empty string on error. The function does not
|
||||
// check for the existence of the path, so if it is passed a directory
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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();
|
||||
|
Reference in New Issue
Block a user