| Index: ui/gfx/render_text.cc
|
| diff --git a/ui/gfx/render_text.cc b/ui/gfx/render_text.cc
|
| index c3a4f00e0fd14524e3ad0247c4efb3085a34ee1d..fddb5563b76ea56fbd96e430480e6a9c17aa6f21 100644
|
| --- a/ui/gfx/render_text.cc
|
| +++ b/ui/gfx/render_text.cc
|
| @@ -367,10 +367,15 @@ void SkiaTextRenderer::DiagonalStrike::Draw() {
|
| }
|
| }
|
|
|
| -StyleIterator::StyleIterator(const BreakList<SkColor>& colors,
|
| +StyleIterator::StyleIterator(const BreakList<uint32_t>& font_sizes,
|
| + const BreakList<SkColor>& colors,
|
| const BreakList<BaselineStyle>& baselines,
|
| const std::vector<BreakList<bool>>& styles)
|
| - : colors_(colors), baselines_(baselines), styles_(styles) {
|
| + : font_sizes_(font_sizes),
|
| + colors_(colors),
|
| + baselines_(baselines),
|
| + styles_(styles) {
|
| + font_size_ = font_sizes_.breaks().begin();
|
| color_ = colors_.breaks().begin();
|
| baseline_ = baselines_.breaks().begin();
|
| for (size_t i = 0; i < styles_.size(); ++i)
|
| @@ -381,6 +386,7 @@ StyleIterator::~StyleIterator() {}
|
|
|
| Range StyleIterator::GetRange() const {
|
| Range range(colors_.GetRange(color_));
|
| + range = range.Intersect(font_sizes_.GetRange(font_size_));
|
| range = range.Intersect(baselines_.GetRange(baseline_));
|
| for (size_t i = 0; i < NUM_TEXT_STYLES; ++i)
|
| range = range.Intersect(styles_[i].GetRange(style_[i]));
|
| @@ -388,6 +394,7 @@ Range StyleIterator::GetRange() const {
|
| }
|
|
|
| void StyleIterator::UpdatePosition(size_t position) {
|
| + font_size_ = font_sizes_.GetBreak(position);
|
| color_ = colors_.GetBreak(position);
|
| baseline_ = baselines_.GetBreak(position);
|
| for (size_t i = 0; i < NUM_TEXT_STYLES; ++i)
|
| @@ -450,6 +457,7 @@ void RenderText::SetText(const base::string16& text) {
|
|
|
| // Clear style ranges as they might break new text graphemes and apply
|
| // the first style to the whole text instead.
|
| + font_sizes_.SetValue(font_sizes_.breaks().begin()->second);
|
| colors_.SetValue(colors_.breaks().begin()->second);
|
| baselines_.SetValue(baselines_.breaks().begin()->second);
|
| for (size_t style = 0; style < NUM_TEXT_STYLES; ++style)
|
| @@ -484,6 +492,14 @@ void RenderText::SetHorizontalAlignment(HorizontalAlignment alignment) {
|
| }
|
| }
|
|
|
| +void RenderText::SetVerticalAlignment(VerticalAlignment alignment) {
|
| + if (vertical_alignment_ != alignment) {
|
| + vertical_alignment_ = alignment;
|
| + display_offset_ = Vector2d();
|
| + cached_bounds_and_offset_valid_ = false;
|
| + }
|
| +}
|
| +
|
| void RenderText::SetFontList(const FontList& font_list) {
|
| font_list_ = font_list;
|
| const int font_style = font_list.GetFontStyle();
|
| @@ -699,6 +715,18 @@ void RenderText::SetCompositionRange(const Range& composition_range) {
|
| OnLayoutTextAttributeChanged(false);
|
| }
|
|
|
| +void RenderText::SetFontSize(uint32_t value) {
|
| + font_sizes_.SetValue(value);
|
| + cached_bounds_and_offset_valid_ = false;
|
| + OnLayoutTextAttributeChanged(false);
|
| +}
|
| +
|
| +void RenderText::ApplyFontSize(uint32_t value, const Range& range) {
|
| + font_sizes_.ApplyValue(value, range);
|
| + cached_bounds_and_offset_valid_ = false;
|
| + OnLayoutTextAttributeChanged(false);
|
| +}
|
| +
|
| void RenderText::SetColor(SkColor value) {
|
| colors_.SetValue(value);
|
| }
|
| @@ -955,6 +983,7 @@ Vector2d RenderText::GetLineOffset(size_t line_number) {
|
|
|
| RenderText::RenderText()
|
| : horizontal_alignment_(base::i18n::IsRTL() ? ALIGN_RIGHT : ALIGN_LEFT),
|
| + vertical_alignment_(VALIGN_MIDDLE),
|
| directionality_mode_(DIRECTIONALITY_FROM_TEXT),
|
| text_direction_(base::i18n::UNKNOWN_DIRECTION),
|
| cursor_enabled_(true),
|
| @@ -965,6 +994,7 @@ RenderText::RenderText()
|
| selection_background_focused_color_(kDefaultSelectionBackgroundColor),
|
| focused_(false),
|
| composition_range_(Range::InvalidRange()),
|
| + font_sizes_(0),
|
| colors_(kDefaultColor),
|
| baselines_(NORMAL_BASELINE),
|
| styles_(NUM_TEXT_STYLES),
|
| @@ -1155,15 +1185,28 @@ Vector2d RenderText::GetAlignmentOffset(size_t line_number) {
|
| offset.set_x((offset.x() + 1) / 2);
|
| }
|
|
|
| - // Vertically center the text.
|
| + // Vertically align the text.
|
| if (multiline_) {
|
| - const int text_height = lines_.back().preceding_heights +
|
| - lines_.back().size.height();
|
| - offset.set_y((display_rect_.height() - text_height) / 2);
|
| + const int text_height =
|
| + lines_.back().preceding_heights + lines_.back().size.height();
|
| + if (vertical_alignment_ == VALIGN_TOP) {
|
| + offset.set_y(lines_.back().preceding_heights);
|
| + } else if (vertical_alignment_ == VALIGN_BOTTOM) {
|
| + offset.set_y(display_rect_.height() - text_height);
|
| + } else {
|
| + // Vertically center the text.
|
| + offset.set_y((display_rect_.height() - text_height) / 2);
|
| + }
|
| } else {
|
| - offset.set_y(GetBaseline() - GetDisplayTextBaseline());
|
| + if (vertical_alignment_ == VALIGN_TOP) {
|
| + offset.set_y(0);
|
| + } else if (vertical_alignment_ == VALIGN_BOTTOM) {
|
| + offset.set_y(display_rect_.height() - font_list_.GetHeight());
|
| + } else {
|
| + // Vertically center the text.
|
| + offset.set_y(GetBaseline() - GetDisplayTextBaseline());
|
| + }
|
| }
|
| -
|
| return offset;
|
| }
|
|
|
| @@ -1246,6 +1289,7 @@ size_t RenderText::TextIndexToGivenTextIndex(const base::string16& given_text,
|
|
|
| void RenderText::UpdateStyleLengths() {
|
| const size_t text_length = text_.length();
|
| + font_sizes_.SetMax(text_length);
|
| colors_.SetMax(text_length);
|
| baselines_.SetMax(text_length);
|
| for (size_t style = 0; style < NUM_TEXT_STYLES; ++style)
|
| @@ -1351,6 +1395,7 @@ base::string16 RenderText::Elide(const base::string16& text,
|
| render_text->styles_ = styles_;
|
| render_text->baselines_ = baselines_;
|
| render_text->colors_ = colors_;
|
| + render_text->font_sizes_ = font_sizes_;
|
| if (text_width == 0) {
|
| render_text->SetText(text);
|
| text_width = render_text->GetContentWidthF();
|
| @@ -1408,6 +1453,7 @@ base::string16 RenderText::Elide(const base::string16& text,
|
| for (size_t style = 0; style < NUM_TEXT_STYLES; ++style)
|
| RestoreBreakList(render_text.get(), render_text->styles_[style]);
|
| RestoreBreakList(render_text.get(), baselines_);
|
| + RestoreBreakList(render_text.get(), font_sizes_);
|
|
|
| // We check the width of the whole desired string at once to ensure we
|
| // handle kerning/ligatures/etc. correctly.
|
|
|