diff options
author | thomasvl@chromium.org <thomasvl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-10 19:19:07 +0000 |
---|---|---|
committer | thomasvl@chromium.org <thomasvl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-10 19:19:07 +0000 |
commit | 18662b90ae6caf7c9798b3b621f7e7ebd01558e8 (patch) | |
tree | ed2dd40913a3420be7eaf383d8c4464f1b6b3b01 /chrome/browser/cocoa/download_item_controller.mm | |
parent | d2bbcc8d3d11b0d53b0a8229b7d253ff448b1824 (diff) | |
download | chromium_src-18662b90ae6caf7c9798b3b621f7e7ebd01558e8.zip chromium_src-18662b90ae6caf7c9798b3b621f7e7ebd01558e8.tar.gz chromium_src-18662b90ae6caf7c9798b3b621f7e7ebd01558e8.tar.bz2 |
[Mac] autosize the dangerous download info to always fit the text.
- DEPS roll to pick up newer GTM with wrapping support.
- Bring the Mac dangerous download closer inline with what windows does, already have mail out to UX about a real spec since all 3 platforms do different things in different cases.
BUG=28705
TEST=see bug
Review URL: http://codereview.chromium.org/787004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@41186 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/cocoa/download_item_controller.mm')
-rw-r--r-- | chrome/browser/cocoa/download_item_controller.mm | 57 |
1 files changed, 47 insertions, 10 deletions
diff --git a/chrome/browser/cocoa/download_item_controller.mm b/chrome/browser/cocoa/download_item_controller.mm index cf0caf8..674dffd 100644 --- a/chrome/browser/cocoa/download_item_controller.mm +++ b/chrome/browser/cocoa/download_item_controller.mm @@ -23,10 +23,18 @@ #include "grit/theme_resources.h" #include "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h" -static const int kTextWidth = 140; // Pixels - namespace { +// NOTE: Mac currently doesn't use this like Windows does. Mac uses this to +// control the min size on the dangerous download text. TVL sent a query off to +// UX to fully spec all the the behaviors of download items and truncations +// rules so all platforms can get inline in the future. +const int kTextWidth = 140; // Pixels + +// The maximum number of characters we show in a file name when displaying the +// dangerous download message. +const int kFileNameMaxLength = 20; + // Helper to widen a view. void WidenView(NSView* view, CGFloat widthChange) { // If it is an NSBox, the autoresize of the contentView is the issue. @@ -115,10 +123,18 @@ class DownloadShelfContextMenuMac : public DownloadShelfContextMenu { [[[GTMUILocalizerAndLayoutTweaker alloc] init] autorelease]; [localizerAndLayoutTweaker applyLocalizer:localizer_ tweakingUI:[self view]]; - // Since the shelf keeps laying out views as more items are added, relying on - // the WidthBaseTweaker to resize the dangerous download part does not work. + // The strings are based on the download item's name, sizing tweaks have to be + // manually done. DCHECK(buttonTweaker_ != nil); CGFloat widthChange = [buttonTweaker_ changedWidth]; + // If it's a dangerous download, size the two lines so the text/filename + // is always visible. + if ([self isDangerousMode]) { + widthChange += + [GTMUILocalizerAndLayoutTweaker + sizeToFitFixedHeightTextField:dangerousDownloadLabel_ + minWidth:kTextWidth]; + } // Grow the parent views WidenView([self view], widthChange); WidenView(dangerousDownloadView_, widthChange); @@ -152,13 +168,34 @@ class DownloadShelfContextMenuMac : public DownloadShelfContextMenu { confirmButtonTitle = l10n_util::GetNSStringWithFixup( IDS_CONTINUE_EXTENSION_DOWNLOAD); } else { - NSFont* font = [dangerousDownloadLabel_ font]; - gfx::Font chromeFont = gfx::Font::CreateFont( - base::SysNSStringToWide([font fontName]), [font pointSize]); - string16 elidedFilename = WideToUTF16(ElideFilename( - downloadModel->download()->original_name(), chromeFont, kTextWidth)); + // This basic fixup copies Windows DownloadItemView::DownloadItemView(). + + // Extract the file extension (if any). + FilePath filepath(downloadModel->download()->original_name()); + FilePath::StringType extension = filepath.Extension(); + + // Remove leading '.' from the extension + if (extension.length() > 0) + extension = extension.substr(1); + + // Elide giant extensions. + if (extension.length() > kFileNameMaxLength / 2) { + std::wstring wide_extension; + ElideString(UTF8ToWide(extension), kFileNameMaxLength / 2, + &wide_extension); + extension = WideToUTF8(wide_extension); + } + + // Rebuild the filename.extension. + std::wstring rootname = + UTF8ToWide(filepath.BaseName().RemoveExtension().value()); + ElideString(rootname, kFileNameMaxLength - extension.length(), &rootname); + std::string filename = WideToUTF8(rootname); + if (extension.length()) + filename += std::string(".") + extension; + dangerousWarning = l10n_util::GetNSStringFWithFixup( - IDS_PROMPT_DANGEROUS_DOWNLOAD, elidedFilename); + IDS_PROMPT_DANGEROUS_DOWNLOAD, UTF8ToUTF16(filename)); confirmButtonTitle = l10n_util::GetNSStringWithFixup(IDS_SAVE_DOWNLOAD); } [dangerousDownloadLabel_ setStringValue:dangerousWarning]; |