summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorevan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-01 08:27:32 +0000
committerevan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-01 08:27:32 +0000
commitf8f606ef03a8afd7564c7f5a1bf82b54e6a6b392 (patch)
treebebb9be6f4b3a4a090917db063177fb5fb58f1dc
parent2cf57c8de64c62ec4f9c18ebf30b30961b208c3e (diff)
downloadchromium_src-f8f606ef03a8afd7564c7f5a1bf82b54e6a6b392.zip
chromium_src-f8f606ef03a8afd7564c7f5a1bf82b54e6a6b392.tar.gz
chromium_src-f8f606ef03a8afd7564c7f5a1bf82b54e6a6b392.tar.bz2
linux: use ICU direction for determining text direction in renderer
We use the GTK text direction in the browser process, but that is not available in the renderer. BUG=36624 TEST=Arabic error pages are properly RTL Review URL: http://codereview.chromium.org/660176 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@40260 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--app/l10n_util.cc26
-rw-r--r--app/l10n_util.h4
-rw-r--r--chrome/renderer/localized_error.cc22
-rw-r--r--chrome/renderer/localized_error.h2
-rw-r--r--chrome/renderer/render_view.cc3
5 files changed, 38 insertions, 19 deletions
diff --git a/app/l10n_util.cc b/app/l10n_util.cc
index 8d418d2..727fe25 100644
--- a/app/l10n_util.cc
+++ b/app/l10n_util.cc
@@ -434,8 +434,8 @@ void SplitAndNormalizeLanguageList(const std::string& env_language,
namespace l10n_util {
-// Represents the locale-specific text direction.
-static TextDirection g_text_direction = UNKNOWN_DIRECTION;
+// Represents the locale-specific ICU text direction.
+static TextDirection g_icu_text_direction = UNKNOWN_DIRECTION;
std::string GetApplicationLocale(const std::wstring& pref_locale) {
#if !defined(OS_MACOSX)
@@ -809,21 +809,21 @@ string16 ToUpper(const string16& string) {
return result;
}
-// Returns the text direction for the default ICU locale. It is assumed
-// that SetICUDefaultLocale has been called to set the default locale to
-// the UI locale of Chrome.
+TextDirection GetICUTextDirection() {
+ if (g_icu_text_direction == UNKNOWN_DIRECTION) {
+ const icu::Locale& locale = icu::Locale::getDefault();
+ g_icu_text_direction = GetTextDirectionForLocale(locale.getName());
+ }
+ return g_icu_text_direction;
+}
+
TextDirection GetTextDirection() {
- if (g_text_direction == UNKNOWN_DIRECTION) {
#if defined(TOOLKIT_GTK)
- GtkTextDirection gtk_dir = gtk_widget_get_default_direction();
- g_text_direction =
- (gtk_dir == GTK_TEXT_DIR_LTR) ? LEFT_TO_RIGHT : RIGHT_TO_LEFT;
+ GtkTextDirection gtk_dir = gtk_widget_get_default_direction();
+ return (gtk_dir == GTK_TEXT_DIR_LTR) ? LEFT_TO_RIGHT : RIGHT_TO_LEFT;
#else
- const icu::Locale& locale = icu::Locale::getDefault();
- g_text_direction = GetTextDirectionForLocale(locale.getName());
+ return GetICUTextDirection();
#endif
- }
- return g_text_direction;
}
TextDirection GetTextDirectionForLocale(const char* locale_name) {
diff --git a/app/l10n_util.h b/app/l10n_util.h
index 66b9d23..b87442c 100644
--- a/app/l10n_util.h
+++ b/app/l10n_util.h
@@ -194,6 +194,10 @@ enum TextDirection {
// * LEFT_TO_RIGHT: Left-To-Right (e.g. English, Chinese, etc.);
// * RIGHT_TO_LEFT: Right-To-Left (e.g. Arabic, Hebrew, etc.), and;
// * UNKNOWN_DIRECTION: unknown (or error).
+TextDirection GetICUTextDirection();
+
+// Get the application text direction. (This is just the ICU direction,
+// except on GTK.)
TextDirection GetTextDirection();
// Returns the text direction for |locale_name|.
diff --git a/chrome/renderer/localized_error.cc b/chrome/renderer/localized_error.cc
index 2b49390..37dea28 100644
--- a/chrome/renderer/localized_error.cc
+++ b/chrome/renderer/localized_error.cc
@@ -90,10 +90,23 @@ WebErrorNetErrorMap net_error_options[] = {
},
};
+bool LocaleIsRTL() {
+#if defined(TOOLKIT_GTK)
+ // l10n_util::GetTextDirection uses the GTK text direction, which doesn't work
+ // within the renderer sandbox.
+ return l10n_util::GetICUTextDirection() == l10n_util::RIGHT_TO_LEFT;
+#else
+ return l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT;
+#endif
+}
+
} // namespace
void GetLocalizedErrorValues(const WebURLError& error,
DictionaryValue* error_strings) {
+ bool rtl = LocaleIsRTL();
+ error_strings->SetString(L"textdirection", rtl ? L"rtl" : L"ltr");
+
// Grab strings that are applicable to all error pages
error_strings->SetString(L"detailsLink",
l10n_util::GetString(IDS_ERRORPAGES_DETAILS_LINK));
@@ -128,7 +141,7 @@ void GetLocalizedErrorValues(const WebURLError& error,
std::wstring failed_url(
ASCIIToWide(std::string(error.unreachableURL.spec())));
// URLs are always LTR.
- if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT)
+ if (rtl)
l10n_util::WrapStringWithLTRFormatting(&failed_url);
error_strings->SetString(L"title",
l10n_util::GetStringF(options.title_resource_id,
@@ -169,7 +182,7 @@ void GetLocalizedErrorValues(const WebURLError& error,
l10n_util::GetString(IDS_ERRORPAGES_SUGGESTION_HOMEPAGE));
std::wstring homepage(ASCIIToWide(failed_url.GetWithEmptyPath().spec()));
// URLs are always LTR.
- if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT)
+ if (rtl)
l10n_util::WrapStringWithLTRFormatting(&homepage);
suggest_home_page->SetString(L"homePage", homepage);
// TODO(tc): we actually want the unicode hostname
@@ -209,9 +222,12 @@ void GetLocalizedErrorValues(const WebURLError& error,
void GetFormRepostErrorValues(const GURL& display_url,
DictionaryValue* error_strings) {
+ bool rtl = LocaleIsRTL();
+ error_strings->SetString(L"textdirection", rtl ? L"rtl" : L"ltr");
+
std::wstring failed_url(ASCIIToWide(display_url.spec()));
// URLs are always LTR.
- if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT)
+ if (rtl)
l10n_util::WrapStringWithLTRFormatting(&failed_url);
error_strings->SetString(
L"title", l10n_util::GetStringF(IDS_ERRORPAGES_TITLE_NOT_AVAILABLE,
diff --git a/chrome/renderer/localized_error.h b/chrome/renderer/localized_error.h
index 33300c4..1b3464b 100644
--- a/chrome/renderer/localized_error.h
+++ b/chrome/renderer/localized_error.h
@@ -12,6 +12,8 @@ namespace WebKit {
struct WebURLError;
}
+// Fills |error_strings| with values to be used to build an error page used
+// on HTTP errors, like 404 or connection reset.
void GetLocalizedErrorValues(const WebKit::WebURLError& error,
DictionaryValue* error_strings);
diff --git a/chrome/renderer/render_view.cc b/chrome/renderer/render_view.cc
index b3ef04b..fdf49a5 100644
--- a/chrome/renderer/render_view.cc
+++ b/chrome/renderer/render_view.cc
@@ -1391,9 +1391,6 @@ void RenderView::LoadNavigationErrorPage(WebFrame* frame,
GetLocalizedErrorValues(error, &error_strings);
resource_id = IDR_NET_ERROR_HTML;
}
- error_strings.SetString(L"textdirection",
- (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) ?
- L"rtl" : L"ltr");
alt_html = GetAltHTMLForTemplate(error_strings, resource_id);
} else {