| 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/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 Loading... |
| 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 Loading... |
| 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 Loading... |
| 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 |
| OLD | NEW |