OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/gfx/render_text.h" | 5 #include "ui/gfx/render_text.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
10 #include "base/i18n/break_iterator.h" | 10 #include "base/i18n/break_iterator.h" |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 } | 133 } |
134 | 134 |
135 // Creates a SkShader to fade the text, with |left_part| specifying the left | 135 // Creates a SkShader to fade the text, with |left_part| specifying the left |
136 // fade effect, if any, and |right_part| specifying the right fade effect. | 136 // fade effect, if any, and |right_part| specifying the right fade effect. |
137 SkShader* CreateFadeShader(const gfx::Rect& text_rect, | 137 SkShader* CreateFadeShader(const gfx::Rect& text_rect, |
138 const gfx::Rect& left_part, | 138 const gfx::Rect& left_part, |
139 const gfx::Rect& right_part, | 139 const gfx::Rect& right_part, |
140 SkColor color) { | 140 SkColor color) { |
141 // Fade alpha of 51/255 corresponds to a fade of 0.2 of the original color. | 141 // Fade alpha of 51/255 corresponds to a fade of 0.2 of the original color. |
142 const SkColor fade_color = SkColorSetA(color, 51); | 142 const SkColor fade_color = SkColorSetA(color, 51); |
143 const SkPoint points[2] = { | |
144 SkPoint::Make(text_rect.x(), text_rect.y()), | |
145 SkPoint::Make(text_rect.right(), text_rect.y()) | |
146 }; | |
147 std::vector<SkScalar> positions; | 143 std::vector<SkScalar> positions; |
148 std::vector<SkColor> colors; | 144 std::vector<SkColor> colors; |
149 | 145 |
150 if (!left_part.IsEmpty()) | 146 if (!left_part.IsEmpty()) |
151 AddFadeEffect(text_rect, left_part, fade_color, color, | 147 AddFadeEffect(text_rect, left_part, fade_color, color, |
152 &positions, &colors); | 148 &positions, &colors); |
153 if (!right_part.IsEmpty()) | 149 if (!right_part.IsEmpty()) |
154 AddFadeEffect(text_rect, right_part, color, fade_color, | 150 AddFadeEffect(text_rect, right_part, color, fade_color, |
155 &positions, &colors); | 151 &positions, &colors); |
156 DCHECK(!positions.empty()); | 152 DCHECK(!positions.empty()); |
157 | 153 |
158 // Terminate |positions| with 1.0, as required by Skia. | 154 // Terminate |positions| with 1.0, as required by Skia. |
159 if (positions.back() != 1.0) { | 155 if (positions.back() != 1.0) { |
160 positions.push_back(1.0); | 156 positions.push_back(1.0); |
161 colors.push_back(colors.back()); | 157 colors.push_back(colors.back()); |
162 } | 158 } |
163 | 159 |
| 160 SkPoint points[2]; |
| 161 points[0].iset(text_rect.x(), text_rect.y()); |
| 162 points[1].iset(text_rect.right(), text_rect.y()); |
| 163 |
164 return SkGradientShader::CreateLinear(&points[0], &colors[0], &positions[0], | 164 return SkGradientShader::CreateLinear(&points[0], &colors[0], &positions[0], |
165 colors.size(), | 165 colors.size(), SkShader::kClamp_TileMode); |
166 SkShader::kClamp_TileMode); | |
167 } | 166 } |
168 | 167 |
169 | |
170 } // namespace | 168 } // namespace |
171 | 169 |
172 namespace gfx { | 170 namespace gfx { |
173 | 171 |
174 namespace internal { | 172 namespace internal { |
175 | 173 |
176 SkiaTextRenderer::SkiaTextRenderer(Canvas* canvas) | 174 SkiaTextRenderer::SkiaTextRenderer(Canvas* canvas) |
177 : canvas_skia_(canvas->GetSkCanvas()) { | 175 : canvas_skia_(canvas->GetSkCanvas()) { |
178 DCHECK(canvas_skia_); | 176 DCHECK(canvas_skia_); |
179 paint_.setTextEncoding(SkPaint::kGlyphID_TextEncoding); | 177 paint_.setTextEncoding(SkPaint::kGlyphID_TextEncoding); |
(...skipping 704 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
884 if (cursor_enabled() && cursor_visible() && focused()) { | 882 if (cursor_enabled() && cursor_visible() && focused()) { |
885 const Rect& bounds = GetUpdatedCursorBounds(); | 883 const Rect& bounds = GetUpdatedCursorBounds(); |
886 if (bounds.width() != 0) | 884 if (bounds.width() != 0) |
887 canvas->FillRect(bounds, cursor_color_); | 885 canvas->FillRect(bounds, cursor_color_); |
888 else | 886 else |
889 canvas->DrawRect(bounds, cursor_color_); | 887 canvas->DrawRect(bounds, cursor_color_); |
890 } | 888 } |
891 } | 889 } |
892 | 890 |
893 } // namespace gfx | 891 } // namespace gfx |
OLD | NEW |