summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--base/i18n/rtl.cc52
-rw-r--r--base/i18n/rtl.h1
-rw-r--r--chrome/browser/extensions/extension_install_ui.cc5
-rw-r--r--chrome/browser/gtk/extension_installed_bubble_gtk.cc4
-rw-r--r--chrome/browser/ui/cocoa/extension_installed_bubble_controller.mm5
-rw-r--r--chrome/browser/ui/views/extensions/extension_installed_bubble.cc5
6 files changed, 68 insertions, 4 deletions
diff --git a/base/i18n/rtl.cc b/base/i18n/rtl.cc
index 6a5d293..12b376d 100644
--- a/base/i18n/rtl.cc
+++ b/base/i18n/rtl.cc
@@ -163,6 +163,7 @@ TextDirection GetFirstStrongCharacterDirection(const std::wstring& text) {
}
#endif
+#if defined(OS_WIN)
bool AdjustStringForLocaleDirection(string16* text) {
if (!IsRTL() || text->empty())
return false;
@@ -177,6 +178,57 @@ bool AdjustStringForLocaleDirection(string16* text) {
return true;
}
+#else
+bool AdjustStringForLocaleDirection(string16* text) {
+ // On OS X & GTK the directionality of a label is determined by the first
+ // strongly directional character.
+ // However, we want to make sure that in an LTR-language-UI all strings are
+ // left aligned and vice versa.
+ // A problem can arise if we display a string which starts with user input.
+ // User input may be of the opposite directionality to the UI. So the whole
+ // string will be displayed in the opposite directionality, e.g. if we want to
+ // display in an LTR UI [such as US English]:
+ //
+ // EMAN_NOISNETXE is now installed.
+ //
+ // Since EXTENSION_NAME begins with a strong RTL char, the label's
+ // directionality will be set to RTL and the string will be displayed visually
+ // as:
+ //
+ // .is now installed EMAN_NOISNETXE
+ //
+ // In order to solve this issue, we prepend an LRM to the string. An LRM is a
+ // strongly directional LTR char.
+ // We also append an LRM at the end, which ensures that we're in an LTR
+ // context.
+
+ // Unlike Windows, Linux and OS X can correctly display RTL glyphs out of the
+ // box so there is no issue with displaying zero-width bidi control characters
+ // on any system. Thus no need for the !IsRTL() check here.
+ if (text->empty())
+ return false;
+
+ bool ui_direction_is_rtl = IsRTL();
+
+ bool has_rtl_chars = StringContainsStrongRTLChars(*text);
+ if (!ui_direction_is_rtl && has_rtl_chars) {
+ WrapStringWithRTLFormatting(text);
+ text->insert(0, 1, kLeftToRightMark);
+ text->push_back(kLeftToRightMark);
+ } else if (ui_direction_is_rtl && has_rtl_chars) {
+ WrapStringWithRTLFormatting(text);
+ text->insert(0, 1, kRightToLeftMark);
+ text->push_back(kRightToLeftMark);
+ } else if (ui_direction_is_rtl) {
+ WrapStringWithLTRFormatting(text);
+ text->insert(0, 1, kRightToLeftMark);
+ text->push_back(kRightToLeftMark);
+ }
+
+ return true;
+}
+
+#endif // !OS_WIN
#if defined(WCHAR_T_IS_UTF32)
bool AdjustStringForLocaleDirection(std::wstring* text) {
diff --git a/base/i18n/rtl.h b/base/i18n/rtl.h
index 82ac576..a75ed4f 100644
--- a/base/i18n/rtl.h
+++ b/base/i18n/rtl.h
@@ -84,6 +84,7 @@ TextDirection GetFirstStrongCharacterDirection(const std::wstring& text);
// string is always treated as a right-to-left string. This is done by
// inserting certain Unicode formatting marks into the returned string.
//
+// ** Notes about the Windows version of this function:
// TODO(idana) bug 6806: this function adjusts the string in question only
// if the current locale is right-to-left. The function does not take care of
// the opposite case (an RTL string displayed in an LTR context) since
diff --git a/chrome/browser/extensions/extension_install_ui.cc b/chrome/browser/extensions/extension_install_ui.cc
index 180300a..313a21a 100644
--- a/chrome/browser/extensions/extension_install_ui.cc
+++ b/chrome/browser/extensions/extension_install_ui.cc
@@ -10,6 +10,7 @@
#include "app/resource_bundle.h"
#include "base/command_line.h"
#include "base/file_util.h"
+#include "base/i18n/rtl.h"
#include "base/string_number_conversions.h"
#include "base/string_util.h"
#include "base/utf_string_conversions.h"
@@ -289,9 +290,11 @@ void ExtensionInstallUI::ShowGenericExtensionInstalledInfoBar(
if (!tab_contents)
return;
+ string16 extension_name = UTF8ToUTF16(new_extension->name());
+ base::i18n::AdjustStringForLocaleDirection(&extension_name);
string16 msg =
l10n_util::GetStringFUTF16(IDS_EXTENSION_INSTALLED_HEADING,
- UTF8ToUTF16(new_extension->name())) +
+ extension_name) +
UTF8ToUTF16(" ") +
l10n_util::GetStringUTF16(IDS_EXTENSION_INSTALLED_MANAGE_INFO_MAC);
InfoBarDelegate* delegate = new SimpleAlertInfoBarDelegate(
diff --git a/chrome/browser/gtk/extension_installed_bubble_gtk.cc b/chrome/browser/gtk/extension_installed_bubble_gtk.cc
index adb2b7b..8c45e40 100644
--- a/chrome/browser/gtk/extension_installed_bubble_gtk.cc
+++ b/chrome/browser/gtk/extension_installed_bubble_gtk.cc
@@ -197,8 +197,10 @@ void ExtensionInstalledBubbleGtk::ShowInternal() {
// Heading label
GtkWidget* heading_label = gtk_label_new(NULL);
+ string16 extension_name = UTF8ToUTF16(extension_->name());
+ base::i18n::AdjustStringForLocaleDirection(&extension_name);
std::string heading_text = l10n_util::GetStringFUTF8(
- IDS_EXTENSION_INSTALLED_HEADING, UTF8ToUTF16(extension_->name()));
+ IDS_EXTENSION_INSTALLED_HEADING, extension_name);
char* markup = g_markup_printf_escaped("<span size=\"larger\">%s</span>",
heading_text.c_str());
gtk_label_set_markup(GTK_LABEL(heading_label), markup);
diff --git a/chrome/browser/ui/cocoa/extension_installed_bubble_controller.mm b/chrome/browser/ui/cocoa/extension_installed_bubble_controller.mm
index 1744fb7..a178ca0 100644
--- a/chrome/browser/ui/cocoa/extension_installed_bubble_controller.mm
+++ b/chrome/browser/ui/cocoa/extension_installed_bubble_controller.mm
@@ -5,6 +5,7 @@
#import "extension_installed_bubble_controller.h"
#include "app/l10n_util.h"
+#include "base/i18n/rtl.h"
#include "base/mac_util.h"
#include "base/sys_string_conversions.h"
#include "base/utf_string_conversions.h"
@@ -283,8 +284,10 @@ class ExtensionLoadedNotificationObserver : public NotificationObserver {
int newWindowHeight = 2 * extension_installed_bubble::kOuterVerticalMargin;
// First part of extension installed message.
+ string16 extension_name = UTF8ToUTF16(extension_->name().c_str());
+ base::i18n::AdjustStringForLocaleDirection(&extension_name);
[extensionInstalledMsg_ setStringValue:l10n_util::GetNSStringF(
- IDS_EXTENSION_INSTALLED_HEADING, UTF8ToUTF16(extension_->name()))];
+ IDS_EXTENSION_INSTALLED_HEADING, extension_name)];
[GTMUILocalizerAndLayoutTweaker
sizeToFitFixedWidthTextField:extensionInstalledMsg_];
newWindowHeight += [extensionInstalledMsg_ frame].size.height +
diff --git a/chrome/browser/ui/views/extensions/extension_installed_bubble.cc b/chrome/browser/ui/views/extensions/extension_installed_bubble.cc
index 50edc13..fd5cf0b 100644
--- a/chrome/browser/ui/views/extensions/extension_installed_bubble.cc
+++ b/chrome/browser/ui/views/extensions/extension_installed_bubble.cc
@@ -6,6 +6,7 @@
#include "app/l10n_util.h"
#include "app/resource_bundle.h"
+#include "base/i18n/rtl.h"
#include "base/message_loop.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/browser_window.h"
@@ -82,9 +83,11 @@ class InstalledBubbleContent : public views::View,
icon_->SetImage(*icon);
AddChildView(icon_);
+ std::wstring extension_name = UTF8ToWide(extension->name());
+ base::i18n::AdjustStringForLocaleDirection(&extension_name);
heading_ = new views::Label(
l10n_util::GetStringF(IDS_EXTENSION_INSTALLED_HEADING,
- UTF8ToWide(extension->name())));
+ extension_name));
heading_->SetFont(rb.GetFont(ResourceBundle::MediumFont));
heading_->SetMultiLine(true);
heading_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);