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

Unified Diff: ui/gfx/canvas_skia.cc

Issue 953093003: Cleanup unnecessary code in canvas_skia (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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
Index: ui/gfx/canvas_skia.cc
diff --git a/ui/gfx/canvas_skia.cc b/ui/gfx/canvas_skia.cc
index 3de9b939bd19cefadda1b84d87999c1902eed241..4ffb974d9c8e22b8805d96550527ee06f33d0d08 100644
--- a/ui/gfx/canvas_skia.cc
+++ b/ui/gfx/canvas_skia.cc
@@ -21,41 +21,6 @@ namespace gfx {
namespace {
-#if defined(OS_WIN)
-// 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, base::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 & Canvas::FORCE_LTR_DIRECTIONALITY))
- return false;
-
- // If RTL is forced, apply it to the string.
- if (flags & 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;
-}
-#endif // defined(OS_WIN)
-
// 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
@@ -131,11 +96,14 @@ void UpdateRenderText(const Rect& rect,
// if not specified.
if (!(flags & (Canvas::TEXT_ALIGN_CENTER |
Canvas::TEXT_ALIGN_RIGHT |
- Canvas::TEXT_ALIGN_LEFT))) {
+ Canvas::TEXT_ALIGN_LEFT |
+ Canvas::TEXT_ALIGN_TO_HEAD))) {
flags |= Canvas::DefaultCanvasTextAlignment();
}
- if (flags & Canvas::TEXT_ALIGN_RIGHT)
+ if (flags & Canvas::TEXT_ALIGN_TO_HEAD)
+ render_text->SetHorizontalAlignment(ALIGN_TO_HEAD);
+ else if (flags & Canvas::TEXT_ALIGN_RIGHT)
render_text->SetHorizontalAlignment(ALIGN_RIGHT);
else if (flags & Canvas::TEXT_ALIGN_CENTER)
render_text->SetHorizontalAlignment(ALIGN_CENTER);
@@ -163,11 +131,6 @@ void Canvas::SizeStringFloat(const base::string16& text,
DCHECK_GE(*width, 0);
DCHECK_GE(*height, 0);
- base::string16 adjusted_text = text;
-#if defined(OS_WIN)
- AdjustStringDirection(flags, &adjusted_text);
-#endif
-
if ((flags & MULTI_LINE) && *width != 0) {
WordWrapBehavior wrap_behavior = TRUNCATE_LONG_WORDS;
if (flags & CHARACTER_BREAK)
@@ -176,7 +139,7 @@ void Canvas::SizeStringFloat(const base::string16& text,
wrap_behavior = ELIDE_LONG_WORDS;
std::vector<base::string16> strings;
- ElideRectangleText(adjusted_text, font_list,
+ ElideRectangleText(text, font_list,
msw 2015/02/25 17:05:20 nit: update line wrapping.
oshima 2015/03/04 08:01:50 Done.
*width, INT_MAX,
wrap_behavior, &strings);
Rect rect(ClampToInt(*width), INT_MAX);
@@ -198,23 +161,15 @@ void Canvas::SizeStringFloat(const base::string16& text,
*width = w;
*height = h;
} else {
- // If the string is too long, the call by |RenderTextWin| to |ScriptShape()|
- // will inexplicably fail with result E_INVALIDARG. Guard against this.
- const size_t kMaxRenderTextLength = 5000;
msw 2015/03/04 17:09:36 You should update the comment in text_elider.cc re
- if (adjusted_text.length() >= kMaxRenderTextLength) {
msw 2015/02/25 17:05:20 Did you test some very long strings here? (up to 1
oshima 2015/03/04 08:01:50 RenderTextWin no longer exists, so E_INVALIDARG ca
msw 2015/03/04 17:09:36 This was unconditionally clamping at 5k chars, eve
oshima 2015/03/04 20:17:42 In the omibox, which uses TextField that uses RT d
- *width = static_cast<float>(
- font_list.GetExpectedTextWidth(adjusted_text.length()));
- *height = static_cast<float>(font_list.GetHeight());
- } else {
- scoped_ptr<RenderText> render_text(RenderText::CreateInstance());
- Rect rect(ClampToInt(*width), ClampToInt(*height));
- StripAcceleratorChars(flags, &adjusted_text);
- UpdateRenderText(rect, adjusted_text, font_list, flags, 0,
- render_text.get());
- const SizeF& string_size = render_text->GetStringSizeF();
- *width = string_size.width();
- *height = string_size.height();
- }
+ scoped_ptr<RenderText> render_text(RenderText::CreateInstance());
+ Rect rect(ClampToInt(*width), ClampToInt(*height));
+ base::string16 adjusted_text = text;
+ StripAcceleratorChars(flags, &adjusted_text);
+ UpdateRenderText(rect, adjusted_text, font_list, flags, 0,
+ render_text.get());
+ const SizeF& string_size = render_text->GetStringSizeF();
+ *width = string_size.width();
+ *height = string_size.height();
}
}
@@ -235,11 +190,6 @@ void Canvas::DrawStringRectWithShadows(const base::string16& text,
ClipRect(clip_rect);
Rect rect(text_bounds);
- base::string16 adjusted_text = text;
-
-#if defined(OS_WIN)
- AdjustStringDirection(flags, &adjusted_text);
-#endif
scoped_ptr<RenderText> render_text(RenderText::CreateInstance());
render_text->set_shadows(shadows);
@@ -252,7 +202,7 @@ void Canvas::DrawStringRectWithShadows(const base::string16& text,
wrap_behavior = ELIDE_LONG_WORDS;
std::vector<base::string16> strings;
- ElideRectangleText(adjusted_text, font_list,
+ ElideRectangleText(text, font_list,
static_cast<float>(text_bounds.width()),
text_bounds.height(), wrap_behavior, &strings);
@@ -284,6 +234,7 @@ void Canvas::DrawStringRectWithShadows(const base::string16& text,
rect += Vector2d(0, line_height);
}
} else {
+ base::string16 adjusted_text = text;
Range range = StripAcceleratorChars(flags, &adjusted_text);
bool elide_text = ((flags & NO_ELLIPSIS) == 0);
@@ -373,20 +324,11 @@ void Canvas::DrawFadedString(const base::string16& text,
DrawStringRectWithFlags(text, font_list, color, display_rect, flags);
return;
}
-
- // Align with forced content directionality, overriding alignment flags.
- if (flags & FORCE_RTL_DIRECTIONALITY) {
- flags &= ~(TEXT_ALIGN_CENTER | TEXT_ALIGN_LEFT);
- flags |= TEXT_ALIGN_RIGHT;
- } else if (flags & FORCE_LTR_DIRECTIONALITY) {
- flags &= ~(TEXT_ALIGN_CENTER | TEXT_ALIGN_RIGHT);
- flags |= TEXT_ALIGN_LEFT;
- } else if (!(flags & TEXT_ALIGN_LEFT) && !(flags & TEXT_ALIGN_RIGHT)) {
- // Also align with content directionality instead of fading both ends.
+ if (!(flags &
+ (TEXT_ALIGN_LEFT | TEXT_ALIGN_RIGHT | TEXT_ALIGN_TO_HEAD))) {
+ // align with content directionality instead of fading both ends.
msw 2015/02/25 17:05:20 nit: Align
oshima 2015/03/04 08:01:50 Done.
flags &= ~TEXT_ALIGN_CENTER;
msw 2015/02/25 17:05:20 nit: refactor the code to unconditionally prevent
oshima 2015/03/04 08:01:50 Done.
- const bool is_rtl = base::i18n::GetFirstStrongCharacterDirection(text) ==
- base::i18n::RIGHT_TO_LEFT;
- flags |= is_rtl ? TEXT_ALIGN_RIGHT : TEXT_ALIGN_LEFT;
+ flags |= TEXT_ALIGN_TO_HEAD;
}
flags |= NO_ELLIPSIS;
« ui/gfx/canvas.h ('K') | « ui/gfx/canvas.h ('k') | ui/message_center/views/bounded_label.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698