| Index: ui/gfx/render_text.cc
|
| diff --git a/ui/gfx/render_text.cc b/ui/gfx/render_text.cc
|
| index 50ef6440e33fbfe8048b1cedb210c8cb40d9eb20..72a8c7ab1f828c5010180b47cd4bd515ce0a2e78 100644
|
| --- a/ui/gfx/render_text.cc
|
| +++ b/ui/gfx/render_text.cc
|
| @@ -78,11 +78,11 @@ int DetermineBaselineCenteringText(const Rect& display_rect,
|
| return baseline + std::max(min_shift, std::min(max_shift, baseline_shift));
|
| }
|
|
|
| -// Converts |gfx::Font::FontStyle| flags to |SkTypeface::Style| flags.
|
| +// Converts |Font::FontStyle| flags to |SkTypeface::Style| flags.
|
| SkTypeface::Style ConvertFontStyleToSkiaTypefaceStyle(int font_style) {
|
| int skia_style = SkTypeface::kNormal;
|
| - skia_style |= (font_style & gfx::Font::BOLD) ? SkTypeface::kBold : 0;
|
| - skia_style |= (font_style & gfx::Font::ITALIC) ? SkTypeface::kItalic : 0;
|
| + skia_style |= (font_style & Font::BOLD) ? SkTypeface::kBold : 0;
|
| + skia_style |= (font_style & Font::ITALIC) ? SkTypeface::kItalic : 0;
|
| return static_cast<SkTypeface::Style>(skia_style);
|
| }
|
|
|
| @@ -229,7 +229,7 @@ void SkiaTextRenderer::SetFontFamilyWithStyle(const std::string& family,
|
|
|
| // Enable fake bold text if bold style is needed but new typeface does not
|
| // have it.
|
| - paint_.setFakeBoldText((style & gfx::Font::BOLD) && !typeface->isBold());
|
| + paint_.setFakeBoldText((style & Font::BOLD) && !typeface->isBold());
|
| }
|
| }
|
|
|
| @@ -509,7 +509,7 @@ void RenderText::SetDisplayRect(const Rect& r) {
|
| baseline_ = kInvalidBaseline;
|
| cached_bounds_and_offset_valid_ = false;
|
| lines_.clear();
|
| - if (elide_behavior_ != gfx::NO_ELIDE)
|
| + if (elide_behavior_ != TRUNCATE)
|
| UpdateLayoutText();
|
| }
|
| }
|
| @@ -890,10 +890,8 @@ RenderText::RenderText()
|
| obscured_(false),
|
| obscured_reveal_index_(-1),
|
| truncate_length_(0),
|
| - elide_behavior_(NO_ELIDE),
|
| + elide_behavior_(TRUNCATE),
|
| multiline_(false),
|
| - fade_head_(false),
|
| - fade_tail_(false),
|
| background_is_transparent_(false),
|
| clip_to_display_rect_(true),
|
| baseline_(kInvalidBaseline),
|
| @@ -1074,37 +1072,23 @@ Vector2d RenderText::GetAlignmentOffset(size_t line_number) {
|
| }
|
|
|
| void RenderText::ApplyFadeEffects(internal::SkiaTextRenderer* renderer) {
|
| - if (multiline() || (!fade_head() && !fade_tail()))
|
| + const int width = display_rect().width();
|
| + if (multiline() || elide_behavior_ != FADE_TAIL || GetContentWidth() <= width)
|
| return;
|
|
|
| - const int display_width = display_rect().width();
|
| -
|
| - // If the text fits as-is, no need to fade.
|
| - if (GetStringSize().width() <= display_width)
|
| - return;
|
| -
|
| - int gradient_width = CalculateFadeGradientWidth(font_list(), display_width);
|
| + const int gradient_width = CalculateFadeGradientWidth(font_list(), width);
|
| if (gradient_width == 0)
|
| return;
|
|
|
| - bool fade_left = fade_head();
|
| - bool fade_right = fade_tail();
|
| - // Under RTL, |fade_right| == |fade_head|.
|
| - // TODO(asvitkine): This is currently not based on GetTextDirection() because
|
| - // RenderTextWin does not return a direction that's based on
|
| - // the text content.
|
| - if (horizontal_alignment_ == ALIGN_RIGHT)
|
| - std::swap(fade_left, fade_right);
|
| -
|
| Rect solid_part = display_rect();
|
| Rect left_part;
|
| Rect right_part;
|
| - if (fade_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 (fade_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);
|
| @@ -1149,7 +1133,7 @@ void RenderText::UpdateLayoutText() {
|
|
|
| if (obscured_) {
|
| size_t obscured_text_length =
|
| - static_cast<size_t>(gfx::UTF16IndexToOffset(text_, 0, text_.length()));
|
| + static_cast<size_t>(UTF16IndexToOffset(text_, 0, text_.length()));
|
| layout_text_.assign(obscured_text_length, kPasswordReplacementChar);
|
|
|
| if (obscured_reveal_index_ >= 0 &&
|
| @@ -1163,7 +1147,7 @@ void RenderText::UpdateLayoutText() {
|
|
|
| // Gets the index in |layout_text_| to be replaced.
|
| const size_t cp_start =
|
| - static_cast<size_t>(gfx::UTF16IndexToOffset(text_, 0, start));
|
| + static_cast<size_t>(UTF16IndexToOffset(text_, 0, start));
|
| if (layout_text_.length() > cp_start)
|
| layout_text_.replace(cp_start, 1, text_.substr(start, end - start));
|
| }
|
| @@ -1176,11 +1160,12 @@ void RenderText::UpdateLayoutText() {
|
| // Truncate the text at a valid character break and append an ellipsis.
|
| icu::StringCharacterIterator iter(text.c_str());
|
| iter.setIndex32(truncate_length_ - 1);
|
| - layout_text_.assign(text.substr(0, iter.getIndex()) + gfx::kEllipsisUTF16);
|
| + layout_text_.assign(text.substr(0, iter.getIndex()) + kEllipsisUTF16);
|
| }
|
|
|
| - if (elide_behavior_ != NO_ELIDE && display_rect_.width() > 0 &&
|
| - !layout_text_.empty() && GetContentWidth() > display_rect_.width()) {
|
| + if (elide_behavior_ != TRUNCATE && elide_behavior_ != FADE_TAIL &&
|
| + display_rect_.width() > 0 && !layout_text_.empty() &&
|
| + GetContentWidth() > display_rect_.width()) {
|
| // This doesn't trim styles so ellipsis may get rendered as a different
|
| // style than the preceding text. See crbug.com/327850.
|
| layout_text_.assign(ElideText(layout_text_));
|
| @@ -1192,7 +1177,7 @@ void RenderText::UpdateLayoutText() {
|
| // TODO(skanuj): Fix code duplication with ElideText in ui/gfx/text_elider.cc
|
| // See crbug.com/327846
|
| base::string16 RenderText::ElideText(const base::string16& text) {
|
| - const bool insert_ellipsis = (elide_behavior_ != TRUNCATE_AT_END);
|
| + const bool insert_ellipsis = (elide_behavior_ != TRUNCATE);
|
| // Create a RenderText copy with attributes that affect the rendering width.
|
| scoped_ptr<RenderText> render_text(CreateInstance());
|
| render_text->SetFontList(font_list_);
|
| @@ -1204,7 +1189,7 @@ base::string16 RenderText::ElideText(const base::string16& text) {
|
| render_text->SetText(text);
|
| const int current_text_pixel_width = render_text->GetContentWidth();
|
|
|
| - const base::string16 ellipsis = base::string16(gfx::kEllipsisUTF16);
|
| + const base::string16 ellipsis = base::string16(kEllipsisUTF16);
|
| const bool elide_in_middle = false;
|
| const bool elide_at_beginning = false;
|
| StringSlicer slicer(text, ellipsis, elide_in_middle, elide_at_beginning);
|
|
|