| Index: ui/gfx/render_text.cc
|
| diff --git a/ui/gfx/render_text.cc b/ui/gfx/render_text.cc
|
| index f2f691ee9e283f214f5606dc22edb72a7ecd425d..a56f8a76ff1ef78f21b491fa703a6d98123c2945 100644
|
| --- a/ui/gfx/render_text.cc
|
| +++ b/ui/gfx/render_text.cc
|
| @@ -20,6 +20,7 @@
|
| #include "third_party/icu/source/common/unicode/rbbi.h"
|
| #include "third_party/icu/source/common/unicode/utf16.h"
|
| #include "third_party/skia/include/core/SkDrawLooper.h"
|
| +#include "third_party/skia/include/core/SkFontStyle.h"
|
| #include "third_party/skia/include/core/SkTypeface.h"
|
| #include "third_party/skia/include/effects/SkGradientShader.h"
|
| #include "ui/gfx/canvas.h"
|
| @@ -366,10 +367,15 @@ void SkiaTextRenderer::DiagonalStrike::Draw() {
|
|
|
| StyleIterator::StyleIterator(const BreakList<SkColor>& colors,
|
| const BreakList<BaselineStyle>& baselines,
|
| + const BreakList<Font::Weight>& weights,
|
| const std::vector<BreakList<bool>>& styles)
|
| - : colors_(colors), baselines_(baselines), styles_(styles) {
|
| + : colors_(colors),
|
| + baselines_(baselines),
|
| + weights_(weights),
|
| + styles_(styles) {
|
| color_ = colors_.breaks().begin();
|
| baseline_ = baselines_.breaks().begin();
|
| + weight_ = weights_.breaks().begin();
|
| for (size_t i = 0; i < styles_.size(); ++i)
|
| style_.push_back(styles_[i].breaks().begin());
|
| }
|
| @@ -379,6 +385,7 @@ StyleIterator::~StyleIterator() {}
|
| Range StyleIterator::GetRange() const {
|
| Range range(colors_.GetRange(color_));
|
| range = range.Intersect(baselines_.GetRange(baseline_));
|
| + range = range.Intersect(weights_.GetRange(weight_));
|
| for (size_t i = 0; i < NUM_TEXT_STYLES; ++i)
|
| range = range.Intersect(styles_[i].GetRange(style_[i]));
|
| return range;
|
| @@ -387,6 +394,7 @@ Range StyleIterator::GetRange() const {
|
| void StyleIterator::UpdatePosition(size_t position) {
|
| color_ = colors_.GetBreak(position);
|
| baseline_ = baselines_.GetBreak(position);
|
| + weight_ = weights_.GetBreak(position);
|
| for (size_t i = 0; i < NUM_TEXT_STYLES; ++i)
|
| style_[i] = styles_[i].GetBreak(position);
|
| }
|
| @@ -446,6 +454,7 @@ std::unique_ptr<RenderText> RenderText::CreateInstanceOfSameStyle(
|
| render_text->styles_ = styles_;
|
| render_text->baselines_ = baselines_;
|
| render_text->colors_ = colors_;
|
| + render_text->weights_ = weights_;
|
| return render_text;
|
| }
|
|
|
| @@ -460,6 +469,7 @@ void RenderText::SetText(const base::string16& text) {
|
| // the first style to the whole text instead.
|
| colors_.SetValue(colors_.breaks().begin()->second);
|
| baselines_.SetValue(baselines_.breaks().begin()->second);
|
| + weights_.SetValue(weights_.breaks().begin()->second);
|
| for (size_t style = 0; style < NUM_TEXT_STYLES; ++style)
|
| styles_[style].SetValue(styles_[style].breaks().begin()->second);
|
| cached_bounds_and_offset_valid_ = false;
|
| @@ -495,9 +505,9 @@ 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);
|
| + weights_.SetValue(font_list.GetFontWeight());
|
| + styles_[ITALIC].SetValue((font_style & Font::ITALIC) != 0);
|
| + styles_[UNDERLINE].SetValue((font_style & Font::UNDERLINE) != 0);
|
| baseline_ = kInvalidBaseline;
|
| cached_bounds_and_offset_valid_ = false;
|
| OnLayoutTextAttributeChanged(false);
|
| @@ -766,6 +776,20 @@ void RenderText::ApplyStyle(TextStyle style, bool value, const Range& range) {
|
| OnLayoutTextAttributeChanged(false);
|
| }
|
|
|
| +void RenderText::SetWeight(Font::Weight weight) {
|
| + weights_.SetValue(weight);
|
| +
|
| + cached_bounds_and_offset_valid_ = false;
|
| + OnLayoutTextAttributeChanged(false);
|
| +}
|
| +
|
| +void RenderText::ApplyWeight(Font::Weight weight, const Range& range) {
|
| + weights_.ApplyValue(weight, range);
|
| +
|
| + cached_bounds_and_offset_valid_ = false;
|
| + OnLayoutTextAttributeChanged(false);
|
| +}
|
| +
|
| bool RenderText::GetStyle(TextStyle style) const {
|
| return (styles_[style].breaks().size() == 1) &&
|
| styles_[style].breaks().front().second;
|
| @@ -791,7 +815,7 @@ VisualCursorDirection RenderText::GetVisualDirectionOfLogicalEnd() {
|
| }
|
|
|
| SizeF RenderText::GetStringSizeF() {
|
| - return gfx::SizeF(GetStringSize());
|
| + return SizeF(GetStringSize());
|
| }
|
|
|
| float RenderText::GetContentWidthF() {
|
| @@ -997,6 +1021,7 @@ RenderText::RenderText()
|
| composition_range_(Range::InvalidRange()),
|
| colors_(kDefaultColor),
|
| baselines_(NORMAL_BASELINE),
|
| + weights_(Font::Weight::NORMAL),
|
| styles_(NUM_TEXT_STYLES),
|
| composition_and_selection_styles_applied_(false),
|
| obscured_(false),
|
| @@ -1308,6 +1333,7 @@ void RenderText::UpdateStyleLengths() {
|
| const size_t text_length = text_.length();
|
| colors_.SetMax(text_length);
|
| baselines_.SetMax(text_length);
|
| + weights_.SetMax(text_length);
|
| for (size_t style = 0; style < NUM_TEXT_STYLES; ++style)
|
| styles_[style].SetMax(text_length);
|
| }
|
| @@ -1460,6 +1486,8 @@ 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(), &render_text->baselines_);
|
| + render_text->weights_ = weights_;
|
| + RestoreBreakList(render_text.get(), &render_text->weights_);
|
|
|
| // We check the width of the whole desired string at once to ensure we
|
| // handle kerning/ligatures/etc. correctly.
|
|
|