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

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

Issue 2654853002: Remove gfx::Canvas::DrawStringRectWithHalo. (Closed)
Patch Set: fix test Created 3 years, 8 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
« no previous file with comments | « ui/gfx/canvas_notimplemented.cc ('k') | ui/gfx/render_text.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 int flags) { 151 int flags) {
152 if (!IntersectsClipRect(RectToSkRect(text_bounds))) 152 if (!IntersectsClipRect(RectToSkRect(text_bounds)))
153 return; 153 return;
154 154
155 canvas_->save(); 155 canvas_->save();
156 ClipRect(text_bounds); 156 ClipRect(text_bounds);
157 157
158 Rect rect(text_bounds); 158 Rect rect(text_bounds);
159 159
160 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); 160 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance());
161 render_text->set_halo_effect(!!(flags & HALO_EFFECT));
162 161
163 if (flags & MULTI_LINE) { 162 if (flags & MULTI_LINE) {
164 WordWrapBehavior wrap_behavior = IGNORE_LONG_WORDS; 163 WordWrapBehavior wrap_behavior = IGNORE_LONG_WORDS;
165 if (flags & CHARACTER_BREAK) 164 if (flags & CHARACTER_BREAK)
166 wrap_behavior = WRAP_LONG_WORDS; 165 wrap_behavior = WRAP_LONG_WORDS;
167 else if (!(flags & NO_ELLIPSIS)) 166 else if (!(flags & NO_ELLIPSIS))
168 wrap_behavior = ELIDE_LONG_WORDS; 167 wrap_behavior = ELIDE_LONG_WORDS;
169 168
170 std::vector<base::string16> strings; 169 std::vector<base::string16> strings;
171 ElideRectangleText(text, font_list, 170 ElideRectangleText(text, font_list,
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 UpdateRenderText(rect, adjusted_text, font_list, flags, color, 221 UpdateRenderText(rect, adjusted_text, font_list, flags, color,
223 render_text.get()); 222 render_text.get());
224 if (range.IsValid()) 223 if (range.IsValid())
225 render_text->ApplyStyle(UNDERLINE, true, range); 224 render_text->ApplyStyle(UNDERLINE, true, range);
226 render_text->Draw(this); 225 render_text->Draw(this);
227 } 226 }
228 227
229 canvas_->restore(); 228 canvas_->restore();
230 } 229 }
231 230
232 void Canvas::DrawStringRectWithHalo(const base::string16& text,
233 const FontList& font_list,
234 SkColor text_color,
235 SkColor halo_color_in,
236 const Rect& display_rect,
237 int flags) {
238 // Some callers will have semitransparent halo colors, which we don't handle
239 // (since the resulting image can have 1-bit transparency only).
240 SkColor halo_color = SkColorSetA(halo_color_in, 0xFF);
241
242 // Draw the halo.
243 DrawStringRectWithFlags(text, font_list, halo_color, display_rect,
244 flags | HALO_EFFECT | NO_SUBPIXEL_RENDERING);
245 // Draw the text.
246 DrawStringRectWithFlags(text, font_list, text_color, display_rect,
247 flags | NO_SUBPIXEL_RENDERING);
248 }
249
250 void Canvas::DrawFadedString(const base::string16& text, 231 void Canvas::DrawFadedString(const base::string16& text,
251 const FontList& font_list, 232 const FontList& font_list,
252 SkColor color, 233 SkColor color,
253 const Rect& display_rect, 234 const Rect& display_rect,
254 int flags) { 235 int flags) {
255 // If the whole string fits in the destination then just draw it directly. 236 // If the whole string fits in the destination then just draw it directly.
256 if (GetStringWidth(text, font_list) <= display_rect.width()) { 237 if (GetStringWidth(text, font_list) <= display_rect.width()) {
257 DrawStringRectWithFlags(text, font_list, color, display_rect, flags); 238 DrawStringRectWithFlags(text, font_list, color, display_rect, flags);
258 return; 239 return;
259 } 240 }
260 // Align with content directionality instead of fading both ends. 241 // Align with content directionality instead of fading both ends.
261 flags &= ~TEXT_ALIGN_CENTER; 242 flags &= ~TEXT_ALIGN_CENTER;
262 if (!(flags & (TEXT_ALIGN_LEFT | TEXT_ALIGN_RIGHT))) 243 if (!(flags & (TEXT_ALIGN_LEFT | TEXT_ALIGN_RIGHT)))
263 flags |= TEXT_ALIGN_TO_HEAD; 244 flags |= TEXT_ALIGN_TO_HEAD;
264 flags |= NO_ELLIPSIS; 245 flags |= NO_ELLIPSIS;
265 246
266 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); 247 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance());
267 Rect rect = display_rect; 248 Rect rect = display_rect;
268 UpdateRenderText(rect, text, font_list, flags, color, render_text.get()); 249 UpdateRenderText(rect, text, font_list, flags, color, render_text.get());
269 render_text->SetElideBehavior(FADE_TAIL); 250 render_text->SetElideBehavior(FADE_TAIL);
270 251
271 canvas_->save(); 252 canvas_->save();
272 ClipRect(display_rect); 253 ClipRect(display_rect);
273 render_text->Draw(this); 254 render_text->Draw(this);
274 canvas_->restore(); 255 canvas_->restore();
275 } 256 }
276 257
277 } // namespace gfx 258 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/canvas_notimplemented.cc ('k') | ui/gfx/render_text.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698