summaryrefslogtreecommitdiffstats
path: root/chrome/views/label.h
diff options
context:
space:
mode:
authorxji@chromium.org <xji@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-23 06:00:44 +0000
committerxji@chromium.org <xji@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-23 06:00:44 +0000
commit4ea6cab1939dff2111f779d8fff80e5dc5d7b8c6 (patch)
treeaa3de08379aab61f8ac17f55b419ec5119eea2ab /chrome/views/label.h
parentb285a98a45c5ddd4ad9080a06d5a7d4943ac19d9 (diff)
downloadchromium_src-4ea6cab1939dff2111f779d8fff80e5dc5d7b8c6.zip
chromium_src-4ea6cab1939dff2111f779d8fff80e5dc5d7b8c6.tar.gz
chromium_src-4ea6cab1939dff2111f779d8fff80e5dc5d7b8c6.tar.bz2
This CL fixes issue 6099 -- bad display of multi-line English message in pop ups.
(http://crbug.com/6099) Currently, in RTL locales, a pure *multi-line* English message is displayed as right aligned and has RTL directionality (such as the ending punctuation appears at the very left). Single-line message works fine. I do not know why, but simply putting LRE-PDF around a multi-line English text which has the following flags DT_WORDBREAK | DT_RTLREADING wont render the English message as LTR. We have to remove the DT_RTLREADING to render multi-line English message correctly in LTR direction. The fix is that in RTL locales, for JavaScript message, if the message is pure English, the alignment is set to be left-aligned, and the directionality is set to be left-to-right. If the message is mixed BiDi text, the alignment and the directionality is determined by the directionality of the first character with strong directionality in the text. JavaScript message is a MessageBoxView, and the message is a view::Label. Both MessageBoxView and Label are used by Chrome's UI as well. If the message is one of Chrome UI's, the alignment and directionality of the message should be taken from that of the UI's. In order to distinguish where the message comes from, a new flag kFlagWebMessage is introduced in MessageBoxView, and a new argument is introduced in Label::SetHorizontalAlignment() to control whether the alignment need to be flipped or not for RTL locales. Consequently, quite a few files which calls Label::SetHorizontalAlignment() are changed. The main changes are in 5 areas. Other files are changed due to the signature change of Label::SetHorizontalAlignment(). 1. jsmessage_box_handler.cc: pass in extra flag kFlagWebPage when creating MessageBoxView to indicate the message box is one from a web page, not from Chrome UI. 2. l10n_util.h/.cc added function GetFirstStrongDirection() 3. label.h/.cc a new argument is introduced in Label::SetHorizontalAlignment() to control whether the alignment need to be flipped or not for RTL locales. 4. message_box_view.cc when init message box view, if the flag is kFlagWebPage, get the text directionality from the text itself (not Chrome UI's) and calls Label::SetHorizontalAlignment() to not resetting the flag for RTL locales. 5. chrome_canvas_win.cc 5.1 ComputeFormatFlags() only set flag DT_RTLREADING for RTL locales if the text contains strong RTL characters and the alignment is RIGHT aligned. All labels of Chrome's UI and other Chrome UI components in RTL locales have been set as (or flipped to) RIGHT aligned. 5.2 DoDrawText() Only adjust string for locale is the reading direction is DT_RTLREADING. Review URL: http://codereview.chromium.org/18863 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@10178 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/views/label.h')
-rw-r--r--chrome/views/label.h41
1 files changed, 40 insertions, 1 deletions
diff --git a/chrome/views/label.h b/chrome/views/label.h
index 84e685c..d70ff3a 100644
--- a/chrome/views/label.h
+++ b/chrome/views/label.h
@@ -26,6 +26,22 @@ class Label : public View {
ALIGN_CENTER,
ALIGN_RIGHT };
+ // The following enum is used to indicate whether using the Chrome UI's
+ // alignment as the label's alignment, or autodetecting the label's
+ // alignment.
+ //
+ // If the label text originates from the Chrome UI, we should use the Chrome
+ // UI's alignment as the label's alignment.
+ //
+ // If the text originates from a web page, the text's alignment is determined
+ // based on the first character with strong directionality, disregarding what
+ // directionality the Chrome UI is. And its alignment will not be flipped
+ // around in RTL locales.
+ enum RTLAlignmentMode {
+ USE_UI_ALIGNMENT = 0,
+ AUTO_DETECT_ALIGNMENT
+ };
+
// The view class name.
static const char kViewClassName[];
@@ -81,10 +97,29 @@ class Label : public View {
// Return a reference to the currently used color
virtual const SkColor GetColor() const;
- // Alignment
+ // Set horizontal alignment. If the locale is RTL, and the RTL alignment
+ // setting is set as USE_UI_ALIGNMENT, the alignment is flipped around.
+ //
+ // Caveat: for labels originating from a web page, the RTL alignment mode
+ // should be reset to AUTO_DETECT_ALIGNMENT before the horizontal alignment
+ // is set. Otherwise, the label's alignment specified as a parameter will be
+ // flipped in RTL locales. Please see the comments in SetRTLAlignmentMode for
+ // more information.
void SetHorizontalAlignment(Alignment a);
+
Alignment GetHorizontalAlignment() const;
+ // Set the RTL alignment mode. The RTL alignment mode is initialized to
+ // USE_UI_ALIGNMENT when the label is constructed. USE_UI_ALIGNMENT applies
+ // to every label that originates from the Chrome UI. However, if the label
+ // originates from a web page, its alignment should not be flipped around for
+ // RTL locales. For such labels, we need to set the RTL alignment mode to
+ // AUTO_DETECT_ALIGNMENT so that subsequent SetHorizontalAlignment() calls
+ // will not flip the label's alignment around.
+ void SetRTLAlignmentMode(RTLAlignmentMode mode);
+
+ RTLAlignmentMode GetRTLAlignmentMode() const;
+
// Set whether the label text can wrap on multiple lines.
// Default is false
void SetMultiLine(bool f);
@@ -192,6 +227,10 @@ class Label : public View {
scoped_ptr<Background> mouse_over_background_;
// Whether to collapse the label when it's not visible.
bool collapse_when_hidden_;
+ // The following member variable is used to control whether the alignment
+ // needs to be flipped around for RTL locales. Please refer to the definition
+ // of RTLAlignmentMode for more information.
+ RTLAlignmentMode rtl_alignment_mode_;
DISALLOW_COPY_AND_ASSIGN(Label);
};