Index: ui/gfx/render_text.cc |
diff --git a/ui/gfx/render_text.cc b/ui/gfx/render_text.cc |
index 8497aa5bef99a204079b8b47364ee0f284f98910..22a8f31ad091820d87d3549a1e1d8a9435da35a3 100644 |
--- a/ui/gfx/render_text.cc |
+++ b/ui/gfx/render_text.cc |
@@ -469,6 +469,10 @@ void RenderText::SetHorizontalAlignment(HorizontalAlignment alignment) { |
void RenderText::SetFontList(const FontList& font_list) { |
font_list_ = font_list; |
+ const int font_style = font_list.GetFontStyle(); |
+ SetStyle(BOLD, (font_style & gfx::Font::BOLD) != 0); |
+ SetStyle(ITALIC, (font_style & gfx::Font::ITALIC) != 0); |
+ SetStyle(UNDERLINE, (font_style & gfx::Font::UNDERLINE) != 0); |
baseline_ = kInvalidBaseline; |
cached_bounds_and_offset_valid_ = false; |
ResetLayout(); |
@@ -502,6 +506,12 @@ void RenderText::SetObscuredRevealIndex(int index) { |
UpdateLayoutText(); |
} |
+void RenderText::SetReplaceNewlineCharsWithSymbols(bool replace) { |
+ replace_newline_chars_with_symbols_ = replace; |
+ cached_bounds_and_offset_valid_ = false; |
+ UpdateLayoutText(); |
+} |
+ |
void RenderText::SetMultiline(bool multiline) { |
if (multiline != multiline_) { |
multiline_ = multiline; |
@@ -938,6 +948,7 @@ RenderText::RenderText() |
obscured_reveal_index_(-1), |
truncate_length_(0), |
elide_behavior_(NO_ELIDE), |
+ replace_newline_chars_with_symbols_(true), |
multiline_(false), |
background_is_transparent_(false), |
clip_to_display_rect_(true), |
@@ -1083,13 +1094,21 @@ std::vector<Rect> RenderText::TextBoundsToViewBounds(const Range& x) { |
return rects; |
} |
+HorizontalAlignment RenderText::GetCurrentHorizontalAlignment() { |
+ if (horizontal_alignment_ != ALIGN_TO_HEAD) |
+ return horizontal_alignment_; |
+ return GetTextDirection() == base::i18n::RIGHT_TO_LEFT ? ALIGN_RIGHT |
+ : ALIGN_LEFT; |
+} |
+ |
Vector2d RenderText::GetAlignmentOffset(size_t line_number) { |
// TODO(ckocagil): Enable |lines_| usage in other platforms. |
#if defined(OS_WIN) |
DCHECK_LT(line_number, lines_.size()); |
#endif |
Vector2d offset; |
- if (horizontal_alignment_ != ALIGN_LEFT) { |
+ HorizontalAlignment horizontal_alignment = GetCurrentHorizontalAlignment(); |
+ if (horizontal_alignment != ALIGN_LEFT) { |
#if defined(OS_WIN) |
const int width = lines_[line_number].size.width() + |
(cursor_enabled_ ? 1 : 0); |
@@ -1097,8 +1116,9 @@ Vector2d RenderText::GetAlignmentOffset(size_t line_number) { |
const int width = GetContentWidth(); |
#endif |
offset.set_x(display_rect().width() - width); |
- if (horizontal_alignment_ == ALIGN_CENTER) |
- offset.set_x(offset.x() / 2); |
+ // Put any extra margin pixel on the left to match legacy behavior. |
+ if (horizontal_alignment == ALIGN_CENTER) |
+ offset.set_x((offset.x() + 1) / 2); |
} |
// Vertically center the text. |
@@ -1122,15 +1142,16 @@ void RenderText::ApplyFadeEffects(internal::SkiaTextRenderer* renderer) { |
if (gradient_width == 0) |
return; |
+ HorizontalAlignment horizontal_alignment = GetCurrentHorizontalAlignment(); |
Rect solid_part = display_rect(); |
Rect left_part; |
Rect right_part; |
- if (horizontal_alignment_ != ALIGN_LEFT) { |
+ if (horizontal_alignment != ALIGN_LEFT) { |
left_part = solid_part; |
left_part.Inset(0, 0, solid_part.width() - gradient_width, 0); |
solid_part.Inset(gradient_width, 0, 0, 0); |
} |
- if (horizontal_alignment_ != ALIGN_RIGHT) { |
+ if (horizontal_alignment != ALIGN_RIGHT) { |
right_part = solid_part; |
right_part.Inset(solid_part.width() - gradient_width, 0, 0, 0); |
solid_part.Inset(0, 0, gradient_width, 0); |
@@ -1230,7 +1251,7 @@ void RenderText::UpdateLayoutText() { |
// Replace the newline character with a newline symbol in single line mode. |
static const base::char16 kNewline[] = { '\n', 0 }; |
static const base::char16 kNewlineSymbol[] = { 0x2424, 0 }; |
- if (!multiline_) |
+ if (!multiline_ && replace_newline_chars_with_symbols_) |
base::ReplaceChars(layout_text_, kNewline, kNewlineSymbol, &layout_text_); |
ResetLayout(); |
@@ -1411,7 +1432,8 @@ void RenderText::UpdateCachedBoundsAndOffset() { |
} else if (display_offset_.x() != 0) { |
// Reduce the pan offset to show additional overflow text when the display |
// width increases. |
- const int negate_rtl = horizontal_alignment_ == ALIGN_RIGHT ? -1 : 1; |
+ HorizontalAlignment horizontal_alignment = GetCurrentHorizontalAlignment(); |
+ const int negate_rtl = horizontal_alignment == ALIGN_RIGHT ? -1 : 1; |
const int offset = negate_rtl * display_offset_.x(); |
if (display_width > (content_width + offset)) { |
delta_x = negate_rtl * (display_width - (content_width + offset)); |