Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(413)

Unified Diff: ui/gfx/canvas_skia.cc

Issue 10695101: Remove code that forces text directionality. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync and merge. Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/gfx/canvas.h ('k') | ui/views/controls/label.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/canvas_skia.cc
diff --git a/ui/gfx/canvas_skia.cc b/ui/gfx/canvas_skia.cc
index 4a6ef61adb98b2db12e67eff04cc4f68e54a63f7..63156f586692d6f27b378e59b6a74677138be649 100644
--- a/ui/gfx/canvas_skia.cc
+++ b/ui/gfx/canvas_skia.cc
@@ -19,39 +19,6 @@
namespace {
-// If necessary, wraps |text| with RTL/LTR directionality characters based on
-// |flags| and |text| content.
-// Returns true if the text will be rendered right-to-left.
-// TODO(msw): Nix this, now that RenderTextWin supports directionality directly.
-bool AdjustStringDirection(int flags, string16* text) {
- // TODO(msw): FORCE_LTR_DIRECTIONALITY does not work for RTL text now.
-
- // If the string is empty or LTR was forced, simply return false since the
- // default RenderText directionality is already LTR.
- if (text->empty() || (flags & gfx::Canvas::FORCE_LTR_DIRECTIONALITY))
- return false;
-
- // If RTL is forced, apply it to the string.
- if (flags & gfx::Canvas::FORCE_RTL_DIRECTIONALITY) {
- base::i18n::WrapStringWithRTLFormatting(text);
- return true;
- }
-
- // If a direction wasn't forced but the UI language is RTL and there were
- // strong RTL characters, ensure RTL is applied.
- if (base::i18n::IsRTL() && base::i18n::StringContainsStrongRTLChars(*text)) {
- base::i18n::WrapStringWithRTLFormatting(text);
- return true;
- }
-
- // In the default case, the string should be rendered as LTR. RenderText's
- // default directionality is LTR, so the text doesn't need to be wrapped.
- // Note that individual runs within the string may still be rendered RTL
- // (which will be the case for RTL text under non-RTL locales, since under RTL
- // locales it will be handled by the if statement above).
- return false;
-}
-
// Checks each pixel immediately adjacent to the given pixel in the bitmap. If
// any of them are not the halo color, returns true. This defines the halo of
// pixels that will appear around the text. Note that we have to check each
@@ -206,11 +173,7 @@ void Canvas::SizeStringInt(const string16& text,
DCHECK_GE(*height, 0);
flags = AdjustPlatformSpecificFlags(text, flags);
-
string16 adjusted_text = text;
-#if defined(OS_WIN)
- AdjustStringDirection(flags, &adjusted_text);
-#endif
if ((flags & MULTI_LINE) && *width != 0) {
ui::WordWrapBehavior wrap_behavior = ui::TRUNCATE_LONG_WORDS;
@@ -285,10 +248,6 @@ void Canvas::DrawStringWithShadows(const string16& text,
gfx::Rect rect(text_bounds);
string16 adjusted_text = text;
-#if defined(OS_WIN)
- AdjustStringDirection(flags, &adjusted_text);
-#endif
-
scoped_ptr<RenderText> render_text(RenderText::CreateInstance());
render_text->SetTextShadows(shadows);
@@ -428,17 +387,23 @@ void Canvas::DrawFadeTruncatingString(
scoped_ptr<RenderText> render_text(RenderText::CreateInstance());
string16 clipped_text = text;
- const bool is_rtl = AdjustStringDirection(flags, &clipped_text);
+
+ // TODO(msw): Text alignment and fading should probably just derive from the
+ // text directionality, and ignore the UI locale. But the legacy behavior uses
+ // the UI locale, except for LTR text in RTL locales. See crbug.com/134746
+ const bool text_rtl = base::i18n::RIGHT_TO_LEFT ==
+ base::i18n::GetFirstStrongCharacterDirection(text);
+ const bool use_rtl = base::i18n::IsRTL() && text_rtl;
switch (truncate_mode) {
case TruncateFadeTail:
render_text->set_fade_tail(true);
- if (is_rtl)
+ if (use_rtl)
flags |= TEXT_ALIGN_RIGHT;
break;
case TruncateFadeHead:
render_text->set_fade_head(true);
- if (!is_rtl)
+ if (!use_rtl)
flags |= TEXT_ALIGN_RIGHT;
break;
case TruncateFadeHeadAndTail:
« no previous file with comments | « ui/gfx/canvas.h ('k') | ui/views/controls/label.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698