summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/gfx/canvas.h10
-rw-r--r--app/gfx/canvas_win.cc14
-rw-r--r--chrome/browser/autocomplete/autocomplete.h2
-rw-r--r--chrome/browser/views/autocomplete/autocomplete_popup_contents_view.cc22
4 files changed, 38 insertions, 10 deletions
diff --git a/app/gfx/canvas.h b/app/gfx/canvas.h
index 90cfad8..e6b07a1 100644
--- a/app/gfx/canvas.h
+++ b/app/gfx/canvas.h
@@ -66,6 +66,16 @@ class Canvas : public skia::PlatformCanvas {
// Specifies if words can be split by new lines.
// This only works with MULTI_LINE.
CHARACTER_BREAK = 1024,
+
+ // Instructs DrawStringInt() to render the text using RTL directionality.
+ // In most cases, passing this flag is not necessary because information
+ // about the text directionality is going to be embedded within the string
+ // in the form of special Unicode characters. However, we don't insert
+ // directionality characters into strings if the locale is LTR because some
+ // platforms (for example, an English Windows XP with no RTL fonts
+ // installed) don't support these characters. Thus, this flag should be
+ // used to render text using RTL directionality when the locale is LTR.
+ FORCE_RTL_DIRECTIONALITY = 2048,
};
// Creates an empty Canvas. Callers must use initialize before using the
diff --git a/app/gfx/canvas_win.cc b/app/gfx/canvas_win.cc
index 9f70136..8b5e685 100644
--- a/app/gfx/canvas_win.cc
+++ b/app/gfx/canvas_win.cc
@@ -106,12 +106,16 @@ int ComputeFormatFlags(int flags, const std::wstring& text) {
// Caveat: If the string is purely LTR, don't set DTL_RTLREADING since when
// the flag is set, LRE-PDF don't have the desired effect of rendering
// multiline English-only text as LTR.
- if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT &&
- (f & DT_RIGHT)) {
- if (l10n_util::StringContainsStrongRTLChars(text)) {
- f |= DT_RTLREADING;
- }
+ //
+ // Note that if the caller is explicitly requesting displaying the text
+ // using RTL directionality then we respect that and pass DT_RTLREADING to
+ // ::DrawText even if the locale is LTR.
+ if ((flags & gfx::Canvas::FORCE_RTL_DIRECTIONALITY) ||
+ ((l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) &&
+ (f & DT_RIGHT) && l10n_util::StringContainsStrongRTLChars(text))) {
+ f |= DT_RTLREADING;
}
+
return f;
}
diff --git a/chrome/browser/autocomplete/autocomplete.h b/chrome/browser/autocomplete/autocomplete.h
index f5d9ac0..2a8f1b0 100644
--- a/chrome/browser/autocomplete/autocomplete.h
+++ b/chrome/browser/autocomplete/autocomplete.h
@@ -287,7 +287,7 @@ struct AutocompleteMatch {
// 0, | 15, | 4,
// 11,match 0,match
//
- // This structure holds the classifiction information for each span.
+ // This structure holds the classification information for each span.
struct ACMatchClassification {
// The values in here are not mutually exclusive -- use them like a
// bitfield. This also means we use "int" instead of this enum type when
diff --git a/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.cc b/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.cc
index 419e0bb..c3b93db 100644
--- a/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.cc
+++ b/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.cc
@@ -147,7 +147,8 @@ class AutocompleteResultView : public views::View {
const std::wstring& text,
int style,
int x,
- int y);
+ int y,
+ bool force_rtl_directionality);
// Gets the font and text color for a fragment with the specified style.
gfx::Font GetFragmentFont(int style) const;
@@ -513,10 +514,20 @@ int AutocompleteResultView::DrawString(
int style = classifications[i].style;
if (force_dim)
style |= ACMatchClassification::DIM;
+
+ // We specify RTL directionlity explicitly only if the run is an RTL run
+ // and we can't specify the string directionlaity using an LRE/PDF pair.
+ // Note that URLs are always displayed using LTR directionality
+ // (regardless of the locale) and therefore they are excluded.
+ const bool force_rtl_directionality =
+ !(classifications[i].style & ACMatchClassification::URL) &&
+ (run_direction == UBIDI_RTL) &&
+ (l10n_util::GetTextDirection() == l10n_util::LEFT_TO_RIGHT);
+
if (text_start < text_end) {
x += DrawStringFragment(canvas,
text.substr(text_start, text_end - text_start),
- style, x, y);
+ style, x, y, force_rtl_directionality);
}
}
}
@@ -528,16 +539,19 @@ int AutocompleteResultView::DrawStringFragment(
const std::wstring& text,
int style,
int x,
- int y) {
+ int y,
+ bool force_rtl_directionality) {
gfx::Font display_font = GetFragmentFont(style);
// Clamp text width to the available width within the popup so we elide if
// necessary.
int string_width = std::min(display_font.GetStringWidth(text),
width() - kRowRightPadding - x);
int string_left = mirroring_context_->GetLeft(x, x + string_width);
+ const int flags = force_rtl_directionality ?
+ gfx::Canvas::FORCE_RTL_DIRECTIONALITY : 0;
canvas->DrawStringInt(text, GetFragmentFont(style),
GetFragmentTextColor(style), string_left, y,
- string_width, display_font.height());
+ string_width, display_font.height(), flags);
return string_width;
}