Chromium Code Reviews| Index: ui/gfx/render_text.cc |
| diff --git a/ui/gfx/render_text.cc b/ui/gfx/render_text.cc |
| index 27c9e5ada81279d215723897c8cafe6b79820023..8507d34b547a035e3a3677da91bdaf2dc17ca48b 100644 |
| --- a/ui/gfx/render_text.cc |
| +++ b/ui/gfx/render_text.cc |
| @@ -95,12 +95,12 @@ SkTypeface::Style ConvertFontStyleToSkiaTypefaceStyle(int font_style) { |
| // Given |font| and |display_width|, returns the width of the fade gradient. |
| int CalculateFadeGradientWidth(const FontList& font_list, int display_width) { |
| - // Fade in/out about 2.5 characters of the beginning/end of the string. |
| + // Fade in/out about 3 characters of the beginning/end of the string. |
| // The .5 here is helpful if one of the characters is a space. |
| - // Use a quarter of the display width if the display width is very short. |
| + // Use a 1/3 of the display width if the display width is very short. |
| const int average_character_width = font_list.GetExpectedTextWidth(1); |
|
Peter Kasting
2015/12/03 05:29:25
While here: Instead of getting the width of 1 char
Tomasz Moniuszko
2015/12/03 11:18:42
Done.
|
| - const double gradient_width = std::min(average_character_width * 2.5, |
| - display_width / 4.0); |
| + const double gradient_width = |
| + std::min(average_character_width * 3.0, display_width / 3.0); |
| DCHECK_GE(gradient_width, 0.0); |
| return static_cast<int>(floor(gradient_width + 0.5)); |
|
Peter Kasting
2015/12/03 05:29:25
Nit: For now, define a round() helper in this file
Tomasz Moniuszko
2015/12/03 11:18:42
Done.
|
| } |
| @@ -130,12 +130,21 @@ void AddFadeEffect(const Rect& text_rect, |
| // Creates a SkShader to fade the text, with |left_part| specifying the left |
| // fade effect, if any, and |right_part| specifying the right fade effect. |
| -skia::RefPtr<SkShader> CreateFadeShader(const Rect& text_rect, |
| +skia::RefPtr<SkShader> CreateFadeShader(const FontList& font_list, |
| + const Rect& text_rect, |
| const Rect& left_part, |
| const Rect& right_part, |
| SkColor color) { |
| - // Fade alpha of 51/255 corresponds to a fade of 0.2 of the original color. |
| - const SkColor fade_color = SkColorSetA(color, 51); |
| + // Use 0 fade target alpha. But if text is narrow (less than 4 average |
| + // characters) linearly increase fade target alpha up to 51/255 what |
| + // corresponds to a fade of 0.2 of the original color. |
| + const int average_character_width = font_list.GetExpectedTextWidth(1); |
| + int alpha = |
| + text_rect.width() > 4 * average_character_width |
| + ? 0 |
| + : static_cast<int>( |
| + 51 * (1 - text_rect.width() / (4.0 * average_character_width))); |
| + const SkColor fade_color = SkColorSetA(color, alpha); |
|
Peter Kasting
2015/12/03 05:29:25
How about this:
// In general, fade down to 0 a
Tomasz Moniuszko
2015/12/03 11:18:42
Done.
|
| std::vector<SkScalar> positions; |
| std::vector<SkColor> colors; |
| @@ -1209,8 +1218,9 @@ void RenderText::ApplyFadeEffects(internal::SkiaTextRenderer* renderer) { |
| text_rect.Inset(GetAlignmentOffset(0).x(), 0, 0, 0); |
| // TODO(msw): Use the actual text colors corresponding to each faded part. |
| - skia::RefPtr<SkShader> shader = CreateFadeShader( |
| - text_rect, left_part, right_part, colors_.breaks().front().second); |
| + skia::RefPtr<SkShader> shader = |
| + CreateFadeShader(font_list(), text_rect, left_part, right_part, |
| + colors_.breaks().front().second); |
| if (shader) |
| renderer->SetShader(shader.get()); |
| } |