summaryrefslogtreecommitdiffstats
path: root/app/gfx
diff options
context:
space:
mode:
authorxji@chromium.org <xji@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-16 17:21:13 +0000
committerxji@chromium.org <xji@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-16 17:21:13 +0000
commit48c70517e3bb914c4157e27fb0d70492f4f76cbe (patch)
treea4f31a59aaf2f2133dacc5440b285b9e6070ae6b /app/gfx
parent873043ae174de16897b9c9ff84ecd0e4f07ae516 (diff)
downloadchromium_src-48c70517e3bb914c4157e27fb0d70492f4f76cbe.zip
chromium_src-48c70517e3bb914c4157e27fb0d70492f4f76cbe.tar.gz
chromium_src-48c70517e3bb914c4157e27fb0d70492f4f76cbe.tar.bz2
This CL fixes issue 10860 - RTL: Hebrew file names should have forced LTR
directionality in download shelf. File names in download shelf are forced to be LTR in DownloadItemView and through ElideFileName(). BUG=http://crbug.com/10860 TEST=1. Open chrome with Hebrew UI. 2. Right click a link and chose Save As... (4th item from the top for non-Hebrew speakers) 3. In the save as dialog name the file קובץ.html 4. In the download shelf the filename should display as קובץ.html (not html.קובץ) Review URL: http://codereview.chromium.org/131001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@26359 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'app/gfx')
-rw-r--r--app/gfx/text_elider.cc24
-rw-r--r--app/gfx/text_elider.h5
-rw-r--r--app/gfx/text_elider_unittest.cc6
3 files changed, 26 insertions, 9 deletions
diff --git a/app/gfx/text_elider.cc b/app/gfx/text_elider.cc
index 7f56fac..a1db1c6 100644
--- a/app/gfx/text_elider.cc
+++ b/app/gfx/text_elider.cc
@@ -4,6 +4,7 @@
#include "app/gfx/font.h"
#include "app/gfx/text_elider.h"
+#include "app/l10n_util.h"
#include "base/file_path.h"
#include "base/string_util.h"
#include "base/sys_string_conversions.h"
@@ -257,8 +258,10 @@ std::wstring ElideFilename(const FilePath& filename,
const gfx::Font& font,
int available_pixel_width) {
int full_width = font.GetStringWidth(filename.ToWStringHack());
- if (full_width <= available_pixel_width)
- return filename.ToWStringHack();
+ if (full_width <= available_pixel_width) {
+ std::wstring elided_name = filename.ToWStringHack();
+ return l10n_util::GetDisplayStringInLTRDirectionality(&elided_name);
+ }
#if defined(OS_WIN)
std::wstring extension = filename.Extension();
@@ -268,18 +271,25 @@ std::wstring ElideFilename(const FilePath& filename,
std::wstring rootname =
filename.BaseName().RemoveExtension().ToWStringHack();
- if (rootname.empty() || extension.empty())
- return ElideText(filename.ToWStringHack(), font, available_pixel_width);
+ if (rootname.empty() || extension.empty()) {
+ std::wstring elided_name = ElideText(filename.ToWStringHack(), font,
+ available_pixel_width);
+ return l10n_util::GetDisplayStringInLTRDirectionality(&elided_name);
+ }
int ext_width = font.GetStringWidth(extension);
int root_width = font.GetStringWidth(rootname);
// We may have trimmed the path.
- if (root_width + ext_width <= available_pixel_width)
- return rootname + extension;
+ if (root_width + ext_width <= available_pixel_width) {
+ std::wstring elided_name = rootname + extension;
+ return l10n_util::GetDisplayStringInLTRDirectionality(&elided_name);
+ }
int available_root_width = available_pixel_width - ext_width;
- return ElideText(rootname, font, available_root_width) + extension;
+ std::wstring elided_name = ElideText(rootname, font, available_root_width);
+ elided_name += extension;
+ return l10n_util::GetDisplayStringInLTRDirectionality(&elided_name);
}
// This function adds an ellipsis at the end of the text if the text
diff --git a/app/gfx/text_elider.h b/app/gfx/text_elider.h
index 4c9c1fa..aa33c29 100644
--- a/app/gfx/text_elider.h
+++ b/app/gfx/text_elider.h
@@ -42,7 +42,10 @@ 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.
+// be removed if filename doesn't fit into available_pixel_width. The elided
+// filename is forced to have LTR directionality, which means that in RTL UI
+// the elided filename is wrapped with LRE (Left-To-Right Embedding) mark and
+// PDF (Pop Directional Formatting) mark.
std::wstring ElideFilename(const FilePath& filename,
const gfx::Font& font,
int available_pixel_width);
diff --git a/app/gfx/text_elider_unittest.cc b/app/gfx/text_elider_unittest.cc
index abb7c23..fb6e7523 100644
--- a/app/gfx/text_elider_unittest.cc
+++ b/app/gfx/text_elider_unittest.cc
@@ -4,6 +4,7 @@
#include "app/gfx/font.h"
#include "app/gfx/text_elider.h"
+#include "app/l10n_util.h"
#include "base/file_path.h"
#include "base/string_util.h"
#include "googleurl/src/gurl.h"
@@ -176,7 +177,10 @@ TEST(TextEliderTest, TestFilenameEliding) {
static const gfx::Font font;
for (size_t i = 0; i < arraysize(testcases); ++i) {
FilePath filepath(testcases[i].input);
- EXPECT_EQ(testcases[i].output, ElideFilename(filepath,
+ std::wstring expected = testcases[i].output;
+ if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT)
+ l10n_util::WrapStringWithLTRFormatting(&expected);
+ EXPECT_EQ(expected, ElideFilename(filepath,
font,
font.GetStringWidth(testcases[i].output)));
}