diff options
author | thestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-24 02:59:14 +0000 |
---|---|---|
committer | thestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-24 02:59:14 +0000 |
commit | c4eaca55f090aa2d3b5b61b604f456b7dbcfd99e (patch) | |
tree | 6ed8985fe2c88d2892d5e3088212736072085cf0 /chrome/common/gfx | |
parent | 40ecd8a10372b6be9a2cb830dd1fe004b51ca2ec (diff) | |
download | chromium_src-c4eaca55f090aa2d3b5b61b604f456b7dbcfd99e.zip chromium_src-c4eaca55f090aa2d3b5b61b604f456b7dbcfd99e.tar.gz chromium_src-c4eaca55f090aa2d3b5b61b604f456b7dbcfd99e.tar.bz2 |
Remove deprecated file_util::GetFilenameWithoutExtensionFromPath(), also convert ElideFilename() to take a FilePath.
Review URL: http://codereview.chromium.org/92060
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@14409 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common/gfx')
-rw-r--r-- | chrome/common/gfx/text_elider.cc | 22 | ||||
-rw-r--r-- | chrome/common/gfx/text_elider.h | 3 | ||||
-rw-r--r-- | chrome/common/gfx/text_elider_unittest.cc | 68 |
3 files changed, 51 insertions, 42 deletions
diff --git a/chrome/common/gfx/text_elider.cc b/chrome/common/gfx/text_elider.cc index 3122d3d..e25f19c 100644 --- a/chrome/common/gfx/text_elider.cc +++ b/chrome/common/gfx/text_elider.cc @@ -2,8 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "base/file_util.h" +#include "base/file_path.h" #include "base/string_util.h" +#include "base/sys_string_conversions.h" #include "chrome/common/gfx/chrome_font.h" #include "chrome/common/gfx/text_elider.h" #include "chrome/common/pref_names.h" @@ -271,22 +272,23 @@ std::wstring ElideUrl(const GURL& url, return ElideText(final_elided_url_string, font, available_pixel_width); } -std::wstring ElideFilename(const std::wstring& filename, +std::wstring ElideFilename(const FilePath& filename, const ChromeFont& font, int available_pixel_width) { - int full_width = font.GetStringWidth(filename); + int full_width = font.GetStringWidth(filename.ToWStringHack()); if (full_width <= available_pixel_width) - return filename; + return filename.ToWStringHack(); - std::wstring extension = - file_util::GetFileExtensionFromPath(filename); +#if defined(OS_WIN) + std::wstring extension = filename.Extension(); +#elif defined(OS_POSIX) + std::wstring extension = base::SysNativeMBToWide(filename.Extension()); +#endif std::wstring rootname = - file_util::GetFilenameWithoutExtensionFromPath(filename); + filename.BaseName().RemoveExtension().ToWStringHack(); if (rootname.empty() || extension.empty()) - return ElideText(filename, font, available_pixel_width); - - extension = L"." + extension; + return ElideText(filename.ToWStringHack(), font, available_pixel_width); int ext_width = font.GetStringWidth(extension); int root_width = font.GetStringWidth(rootname); diff --git a/chrome/common/gfx/text_elider.h b/chrome/common/gfx/text_elider.h index 1aa4334..2f88845 100644 --- a/chrome/common/gfx/text_elider.h +++ b/chrome/common/gfx/text_elider.h @@ -12,6 +12,7 @@ #include "base/string16.h" #include "chrome/common/gfx/chrome_font.h" +class FilePath; class GURL; namespace url_parse { @@ -57,7 +58,7 @@ std::wstring ElideText(const std::wstring& text, // Elide a filename to fit a given pixel width, with an emphasis on not hiding // the extension unless we have to. If filename contains a path, the path will // be removed if filename doesn't fit into available_pixel_width. -std::wstring ElideFilename(const std::wstring& filename, +std::wstring ElideFilename(const FilePath& filename, const ChromeFont& font, int available_pixel_width); diff --git a/chrome/common/gfx/text_elider_unittest.cc b/chrome/common/gfx/text_elider_unittest.cc index 06b9755..c47e0bd 100644 --- a/chrome/common/gfx/text_elider_unittest.cc +++ b/chrome/common/gfx/text_elider_unittest.cc @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "base/file_path.h" #include "base/string_util.h" #include "chrome/common/gfx/chrome_font.h" #include "chrome/common/gfx/text_elider.h" @@ -19,6 +20,11 @@ struct Testcase { const std::wstring output; }; +struct FileTestcase { + const FilePath::StringType input; + const std::wstring output; +}; + struct WideTestcase { const std::wstring input; const std::wstring output; @@ -138,41 +144,41 @@ TEST(TextEliderTest, TestFileURLEliding) { TEST(TextEliderTest, TestFilenameEliding) { const std::wstring kEllipsisStr(kEllipsis); -// TODO(port): this should probably use FilePath::kPathSeparators[0], but we -// will change this unit test after porting text elider to string16/FilePath, -// so it's not worth using FilePath stuff at the moment. -#if defined(OS_POSIX) - const std::wstring kPathSeparator(L"/"); -#elif defined(OS_WIN) - const std::wstring kPathSeparator(L"\\"); -#endif - - WideTestcase testcases[] = { - {L"", L""}, - {L".", L"."}, - {L"filename.exe", L"filename.exe"}, - {L".longext", L".longext"}, - {L"pie", L"pie"}, - {L"c:" + kPathSeparator + L"path" + kPathSeparator + L"filename.pie", - L"filename.pie"}, - {L"c:" + kPathSeparator + L"path" + kPathSeparator + L"longfilename.pie", - L"long" + kEllipsisStr + L".pie"}, - {L"http://path.com/filename.pie", L"filename.pie"}, - {L"http://path.com/longfilename.pie", L"long" + kEllipsisStr + L".pie"}, - {L"piesmashingtacularpants", L"pie" + kEllipsisStr}, - {L".piesmashingtacularpants", L".pie" + kEllipsisStr}, - {L"cheese.", L"cheese."}, - {L"file name.longext", L"file" + kEllipsisStr + L".longext"}, - {L"fil ename.longext", L"fil " + kEllipsisStr + L".longext"}, - {L"filename.longext", L"file" + kEllipsisStr + L".longext"}, - {L"filename.middleext.longext", - L"filename.mid" + kEllipsisStr + L".longext"} + const FilePath::StringType kPathSeparator = + FilePath::StringType().append(1, FilePath::kSeparators[0]); + + FileTestcase testcases[] = { + {FILE_PATH_LITERAL(""), L""}, + {FILE_PATH_LITERAL("."), L"."}, + {FILE_PATH_LITERAL("filename.exe"), L"filename.exe"}, + {FILE_PATH_LITERAL(".longext"), L".longext"}, + {FILE_PATH_LITERAL("pie"), L"pie"}, + {FILE_PATH_LITERAL("c:") + kPathSeparator + FILE_PATH_LITERAL("path") + + kPathSeparator + FILE_PATH_LITERAL("filename.pie"), + L"filename.pie"}, + {FILE_PATH_LITERAL("c:") + kPathSeparator + FILE_PATH_LITERAL("path") + + kPathSeparator + FILE_PATH_LITERAL("longfilename.pie"), + L"long" + kEllipsisStr + L".pie"}, + {FILE_PATH_LITERAL("http://path.com/filename.pie"), L"filename.pie"}, + {FILE_PATH_LITERAL("http://path.com/longfilename.pie"), + L"long" + kEllipsisStr + L".pie"}, + {FILE_PATH_LITERAL("piesmashingtacularpants"), L"pie" + kEllipsisStr}, + {FILE_PATH_LITERAL(".piesmashingtacularpants"), L".pie" + kEllipsisStr}, + {FILE_PATH_LITERAL("cheese."), L"cheese."}, + {FILE_PATH_LITERAL("file name.longext"), + L"file" + kEllipsisStr + L".longext"}, + {FILE_PATH_LITERAL("fil ename.longext"), + L"fil " + kEllipsisStr + L".longext"}, + {FILE_PATH_LITERAL("filename.longext"), + L"file" + kEllipsisStr + L".longext"}, + {FILE_PATH_LITERAL("filename.middleext.longext"), + L"filename.mid" + kEllipsisStr + L".longext"} }; static const ChromeFont font; for (size_t i = 0; i < arraysize(testcases); ++i) { - const std::wstring filename(testcases[i].input); - EXPECT_EQ(testcases[i].output, ElideFilename(filename, + FilePath filepath(testcases[i].input); + EXPECT_EQ(testcases[i].output, ElideFilename(filepath, font, font.GetStringWidth(testcases[i].output))); } |