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

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

Issue 1868363002: Replace scoped_ptr with std::unique_ptr in //ui (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@scopedptrcc
Patch Set: scopedptrui: rebase-make_scoped_ptr Created 4 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.h ('k') | ui/gfx/chromeos/codec/jpeg_codec_robust_slow.cc » ('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 "ui/gfx/canvas.h"
6
7 #include <limits.h> 5 #include <limits.h>
8 #include <stddef.h> 6 #include <stddef.h>
9 #include <stdint.h> 7 #include <stdint.h>
10 8
9 #include <memory>
10
11 #include "base/i18n/rtl.h" 11 #include "base/i18n/rtl.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/numerics/safe_conversions.h" 13 #include "base/numerics/safe_conversions.h"
15 #include "build/build_config.h" 14 #include "build/build_config.h"
16 #include "third_party/skia/include/core/SkBitmap.h" 15 #include "third_party/skia/include/core/SkBitmap.h"
17 #include "third_party/skia/include/core/SkPixmap.h" 16 #include "third_party/skia/include/core/SkPixmap.h"
17 #include "ui/gfx/canvas.h"
18 #include "ui/gfx/font_list.h" 18 #include "ui/gfx/font_list.h"
19 #include "ui/gfx/geometry/insets.h" 19 #include "ui/gfx/geometry/insets.h"
20 #include "ui/gfx/geometry/rect.h" 20 #include "ui/gfx/geometry/rect.h"
21 #include "ui/gfx/range/range.h" 21 #include "ui/gfx/range/range.h"
22 #include "ui/gfx/render_text.h" 22 #include "ui/gfx/render_text.h"
23 #include "ui/gfx/shadow_value.h" 23 #include "ui/gfx/shadow_value.h"
24 #include "ui/gfx/skia_util.h" 24 #include "ui/gfx/skia_util.h"
25 #include "ui/gfx/text_elider.h" 25 #include "ui/gfx/text_elider.h"
26 #include "ui/gfx/text_utils.h" 26 #include "ui/gfx/text_utils.h"
27 27
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 WordWrapBehavior wrap_behavior = TRUNCATE_LONG_WORDS; 143 WordWrapBehavior wrap_behavior = TRUNCATE_LONG_WORDS;
144 if (flags & CHARACTER_BREAK) 144 if (flags & CHARACTER_BREAK)
145 wrap_behavior = WRAP_LONG_WORDS; 145 wrap_behavior = WRAP_LONG_WORDS;
146 else if (!(flags & NO_ELLIPSIS)) 146 else if (!(flags & NO_ELLIPSIS))
147 wrap_behavior = ELIDE_LONG_WORDS; 147 wrap_behavior = ELIDE_LONG_WORDS;
148 148
149 std::vector<base::string16> strings; 149 std::vector<base::string16> strings;
150 ElideRectangleText(text, font_list, *width, INT_MAX, wrap_behavior, 150 ElideRectangleText(text, font_list, *width, INT_MAX, wrap_behavior,
151 &strings); 151 &strings);
152 Rect rect(base::saturated_cast<int>(*width), INT_MAX); 152 Rect rect(base::saturated_cast<int>(*width), INT_MAX);
153 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); 153 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance());
154 UpdateRenderText(rect, base::string16(), font_list, flags, 0, 154 UpdateRenderText(rect, base::string16(), font_list, flags, 0,
155 render_text.get()); 155 render_text.get());
156 156
157 float h = 0; 157 float h = 0;
158 float w = 0; 158 float w = 0;
159 for (size_t i = 0; i < strings.size(); ++i) { 159 for (size_t i = 0; i < strings.size(); ++i) {
160 StripAcceleratorChars(flags, &strings[i]); 160 StripAcceleratorChars(flags, &strings[i]);
161 render_text->SetText(strings[i]); 161 render_text->SetText(strings[i]);
162 const SizeF& string_size = render_text->GetStringSizeF(); 162 const SizeF& string_size = render_text->GetStringSizeF();
163 w = std::max(w, string_size.width()); 163 w = std::max(w, string_size.width());
164 h += (i > 0 && line_height > 0) ? 164 h += (i > 0 && line_height > 0) ?
165 std::max(static_cast<float>(line_height), string_size.height()) 165 std::max(static_cast<float>(line_height), string_size.height())
166 : string_size.height(); 166 : string_size.height();
167 } 167 }
168 *width = w; 168 *width = w;
169 *height = h; 169 *height = h;
170 } else { 170 } else {
171 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); 171 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance());
172 Rect rect(base::saturated_cast<int>(*width), 172 Rect rect(base::saturated_cast<int>(*width),
173 base::saturated_cast<int>(*height)); 173 base::saturated_cast<int>(*height));
174 base::string16 adjusted_text = text; 174 base::string16 adjusted_text = text;
175 StripAcceleratorChars(flags, &adjusted_text); 175 StripAcceleratorChars(flags, &adjusted_text);
176 UpdateRenderText(rect, adjusted_text, font_list, flags, 0, 176 UpdateRenderText(rect, adjusted_text, font_list, flags, 0,
177 render_text.get()); 177 render_text.get());
178 const SizeF& string_size = render_text->GetStringSizeF(); 178 const SizeF& string_size = render_text->GetStringSizeF();
179 *width = string_size.width(); 179 *width = string_size.width();
180 *height = string_size.height(); 180 *height = string_size.height();
181 } 181 }
(...skipping 10 matching lines...) Expand all
192 return; 192 return;
193 193
194 Rect clip_rect(text_bounds); 194 Rect clip_rect(text_bounds);
195 clip_rect.Inset(ShadowValue::GetMargin(shadows)); 195 clip_rect.Inset(ShadowValue::GetMargin(shadows));
196 196
197 canvas_->save(); 197 canvas_->save();
198 ClipRect(clip_rect); 198 ClipRect(clip_rect);
199 199
200 Rect rect(text_bounds); 200 Rect rect(text_bounds);
201 201
202 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); 202 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance());
203 render_text->set_shadows(shadows); 203 render_text->set_shadows(shadows);
204 204
205 if (flags & MULTI_LINE) { 205 if (flags & MULTI_LINE) {
206 WordWrapBehavior wrap_behavior = IGNORE_LONG_WORDS; 206 WordWrapBehavior wrap_behavior = IGNORE_LONG_WORDS;
207 if (flags & CHARACTER_BREAK) 207 if (flags & CHARACTER_BREAK)
208 wrap_behavior = WRAP_LONG_WORDS; 208 wrap_behavior = WRAP_LONG_WORDS;
209 else if (!(flags & NO_ELLIPSIS)) 209 else if (!(flags & NO_ELLIPSIS))
210 wrap_behavior = ELIDE_LONG_WORDS; 210 wrap_behavior = ELIDE_LONG_WORDS;
211 211
212 std::vector<base::string16> strings; 212 std::vector<base::string16> strings;
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 if (GetStringWidth(text, font_list) <= display_rect.width()) { 334 if (GetStringWidth(text, font_list) <= display_rect.width()) {
335 DrawStringRectWithFlags(text, font_list, color, display_rect, flags); 335 DrawStringRectWithFlags(text, font_list, color, display_rect, flags);
336 return; 336 return;
337 } 337 }
338 // Align with content directionality instead of fading both ends. 338 // Align with content directionality instead of fading both ends.
339 flags &= ~TEXT_ALIGN_CENTER; 339 flags &= ~TEXT_ALIGN_CENTER;
340 if (!(flags & (TEXT_ALIGN_LEFT | TEXT_ALIGN_RIGHT))) 340 if (!(flags & (TEXT_ALIGN_LEFT | TEXT_ALIGN_RIGHT)))
341 flags |= TEXT_ALIGN_TO_HEAD; 341 flags |= TEXT_ALIGN_TO_HEAD;
342 flags |= NO_ELLIPSIS; 342 flags |= NO_ELLIPSIS;
343 343
344 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); 344 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance());
345 Rect rect = display_rect; 345 Rect rect = display_rect;
346 UpdateRenderText(rect, text, font_list, flags, color, render_text.get()); 346 UpdateRenderText(rect, text, font_list, flags, color, render_text.get());
347 render_text->SetElideBehavior(FADE_TAIL); 347 render_text->SetElideBehavior(FADE_TAIL);
348 348
349 canvas_->save(); 349 canvas_->save();
350 ClipRect(display_rect); 350 ClipRect(display_rect);
351 render_text->Draw(this); 351 render_text->Draw(this);
352 canvas_->restore(); 352 canvas_->restore();
353 } 353 }
354 354
355 } // namespace gfx 355 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/canvas.h ('k') | ui/gfx/chromeos/codec/jpeg_codec_robust_slow.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698