Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(90)

Side by Side Diff: ui/gfx/canvas_skia.cc

Issue 2654853002: Remove gfx::Canvas::DrawStringRectWithHalo. (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <limits.h> 5 #include <limits.h>
6 #include <stddef.h> 6 #include <stddef.h>
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <memory> 9 #include <memory>
10 10
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 int flags) { 150 int flags) {
151 if (!IntersectsClipRect(RectToSkRect(text_bounds))) 151 if (!IntersectsClipRect(RectToSkRect(text_bounds)))
152 return; 152 return;
153 153
154 canvas_->save(); 154 canvas_->save();
155 ClipRect(text_bounds); 155 ClipRect(text_bounds);
156 156
157 Rect rect(text_bounds); 157 Rect rect(text_bounds);
158 158
159 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); 159 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance());
160 render_text->set_halo_effect(!!(flags & HALO_EFFECT));
161 160
162 if (flags & MULTI_LINE) { 161 if (flags & MULTI_LINE) {
163 WordWrapBehavior wrap_behavior = IGNORE_LONG_WORDS; 162 WordWrapBehavior wrap_behavior = IGNORE_LONG_WORDS;
164 if (flags & CHARACTER_BREAK) 163 if (flags & CHARACTER_BREAK)
165 wrap_behavior = WRAP_LONG_WORDS; 164 wrap_behavior = WRAP_LONG_WORDS;
166 else if (!(flags & NO_ELLIPSIS)) 165 else if (!(flags & NO_ELLIPSIS))
167 wrap_behavior = ELIDE_LONG_WORDS; 166 wrap_behavior = ELIDE_LONG_WORDS;
168 167
169 std::vector<base::string16> strings; 168 std::vector<base::string16> strings;
170 ElideRectangleText(text, font_list, 169 ElideRectangleText(text, font_list,
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 UpdateRenderText(rect, adjusted_text, font_list, flags, color, 220 UpdateRenderText(rect, adjusted_text, font_list, flags, color,
222 render_text.get()); 221 render_text.get());
223 if (range.IsValid()) 222 if (range.IsValid())
224 render_text->ApplyStyle(UNDERLINE, true, range); 223 render_text->ApplyStyle(UNDERLINE, true, range);
225 render_text->Draw(this); 224 render_text->Draw(this);
226 } 225 }
227 226
228 canvas_->restore(); 227 canvas_->restore();
229 } 228 }
230 229
231 void Canvas::DrawStringRectWithHalo(const base::string16& text,
232 const FontList& font_list,
233 SkColor text_color,
234 SkColor halo_color_in,
235 const Rect& display_rect,
236 int flags) {
237 // Some callers will have semitransparent halo colors, which we don't handle
238 // (since the resulting image can have 1-bit transparency only).
239 SkColor halo_color = SkColorSetA(halo_color_in, 0xFF);
240
241 // Draw the halo.
242 DrawStringRectWithFlags(text, font_list, halo_color, display_rect,
243 flags | HALO_EFFECT | NO_SUBPIXEL_RENDERING);
244 // Draw the text.
245 DrawStringRectWithFlags(text, font_list, text_color, display_rect,
246 flags | NO_SUBPIXEL_RENDERING);
247 }
248
249 void Canvas::DrawFadedString(const base::string16& text, 230 void Canvas::DrawFadedString(const base::string16& text,
250 const FontList& font_list, 231 const FontList& font_list,
251 SkColor color, 232 SkColor color,
252 const Rect& display_rect, 233 const Rect& display_rect,
253 int flags) { 234 int flags) {
254 // If the whole string fits in the destination then just draw it directly. 235 // If the whole string fits in the destination then just draw it directly.
255 if (GetStringWidth(text, font_list) <= display_rect.width()) { 236 if (GetStringWidth(text, font_list) <= display_rect.width()) {
256 DrawStringRectWithFlags(text, font_list, color, display_rect, flags); 237 DrawStringRectWithFlags(text, font_list, color, display_rect, flags);
257 return; 238 return;
258 } 239 }
259 // Align with content directionality instead of fading both ends. 240 // Align with content directionality instead of fading both ends.
260 flags &= ~TEXT_ALIGN_CENTER; 241 flags &= ~TEXT_ALIGN_CENTER;
261 if (!(flags & (TEXT_ALIGN_LEFT | TEXT_ALIGN_RIGHT))) 242 if (!(flags & (TEXT_ALIGN_LEFT | TEXT_ALIGN_RIGHT)))
262 flags |= TEXT_ALIGN_TO_HEAD; 243 flags |= TEXT_ALIGN_TO_HEAD;
263 flags |= NO_ELLIPSIS; 244 flags |= NO_ELLIPSIS;
264 245
265 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); 246 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance());
266 Rect rect = display_rect; 247 Rect rect = display_rect;
267 UpdateRenderText(rect, text, font_list, flags, color, render_text.get()); 248 UpdateRenderText(rect, text, font_list, flags, color, render_text.get());
268 render_text->SetElideBehavior(FADE_TAIL); 249 render_text->SetElideBehavior(FADE_TAIL);
269 250
270 canvas_->save(); 251 canvas_->save();
271 ClipRect(display_rect); 252 ClipRect(display_rect);
272 render_text->Draw(this); 253 render_text->Draw(this);
273 canvas_->restore(); 254 canvas_->restore();
274 } 255 }
275 256
276 } // namespace gfx 257 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698