Chromium Code Reviews| 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 <limits.h> | 7 #include <limits.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <climits> | 10 #include <climits> |
| 11 | 11 |
| 12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/i18n/break_iterator.h" | 13 #include "base/i18n/break_iterator.h" |
| 14 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "base/stl_util.h" | 15 #include "base/stl_util.h" |
| 16 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
| 17 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
| 18 #include "base/trace_event/trace_event.h" | 18 #include "base/trace_event/trace_event.h" |
| 19 #include "build/build_config.h" | 19 #include "build/build_config.h" |
| 20 #include "third_party/icu/source/common/unicode/rbbi.h" | 20 #include "third_party/icu/source/common/unicode/rbbi.h" |
| 21 #include "third_party/icu/source/common/unicode/utf16.h" | 21 #include "third_party/icu/source/common/unicode/utf16.h" |
| 22 #include "third_party/skia/include/core/SkDrawLooper.h" | 22 #include "third_party/skia/include/core/SkDrawLooper.h" |
| 23 #include "third_party/skia/include/core/SkFontStyle.h" | 23 #include "third_party/skia/include/core/SkFontStyle.h" |
| 24 #include "third_party/skia/include/core/SkTypeface.h" | 24 #include "third_party/skia/include/core/SkTypeface.h" |
| 25 #include "third_party/skia/include/effects/SkGradientShader.h" | 25 #include "third_party/skia/include/effects/SkGradientShader.h" |
| 26 #include "third_party/skia/include/effects/SkMorphologyImageFilter.h" | 26 #include "third_party/skia/include/effects/SkMorphologyImageFilter.h" |
|
msw
2017/01/25 18:09:07
nit: remove
Evan Stade
2017/01/26 00:43:10
Done.
| |
| 27 #include "ui/gfx/canvas.h" | 27 #include "ui/gfx/canvas.h" |
| 28 #include "ui/gfx/geometry/insets.h" | 28 #include "ui/gfx/geometry/insets.h" |
| 29 #include "ui/gfx/geometry/safe_integer_conversions.h" | 29 #include "ui/gfx/geometry/safe_integer_conversions.h" |
| 30 #include "ui/gfx/platform_font.h" | 30 #include "ui/gfx/platform_font.h" |
| 31 #include "ui/gfx/render_text_harfbuzz.h" | 31 #include "ui/gfx/render_text_harfbuzz.h" |
| 32 #include "ui/gfx/scoped_canvas.h" | 32 #include "ui/gfx/scoped_canvas.h" |
| 33 #include "ui/gfx/skia_util.h" | 33 #include "ui/gfx/skia_util.h" |
| 34 #include "ui/gfx/switches.h" | 34 #include "ui/gfx/switches.h" |
| 35 #include "ui/gfx/text_elider.h" | 35 #include "ui/gfx/text_elider.h" |
| 36 #include "ui/gfx/text_utils.h" | 36 #include "ui/gfx/text_utils.h" |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 245 } | 245 } |
| 246 | 246 |
| 247 void SkiaTextRenderer::SetForegroundColor(SkColor foreground) { | 247 void SkiaTextRenderer::SetForegroundColor(SkColor foreground) { |
| 248 paint_.setColor(foreground); | 248 paint_.setColor(foreground); |
| 249 } | 249 } |
| 250 | 250 |
| 251 void SkiaTextRenderer::SetShader(sk_sp<SkShader> shader) { | 251 void SkiaTextRenderer::SetShader(sk_sp<SkShader> shader) { |
| 252 paint_.setShader(std::move(shader)); | 252 paint_.setShader(std::move(shader)); |
| 253 } | 253 } |
| 254 | 254 |
| 255 void SkiaTextRenderer::SetHaloEffect() { | |
| 256 paint_.setImageFilter(SkDilateImageFilter::Make(1, 1, nullptr)); | |
| 257 } | |
| 258 | |
| 259 void SkiaTextRenderer::SetUnderlineMetrics(SkScalar thickness, | 255 void SkiaTextRenderer::SetUnderlineMetrics(SkScalar thickness, |
| 260 SkScalar position) { | 256 SkScalar position) { |
| 261 underline_thickness_ = thickness; | 257 underline_thickness_ = thickness; |
| 262 underline_position_ = position; | 258 underline_position_ = position; |
| 263 } | 259 } |
| 264 | 260 |
| 265 void SkiaTextRenderer::DrawPosText(const SkPoint* pos, | 261 void SkiaTextRenderer::DrawPosText(const SkPoint* pos, |
| 266 const uint16_t* glyphs, | 262 const uint16_t* glyphs, |
| 267 size_t glyph_count) { | 263 size_t glyph_count) { |
| 268 const size_t byte_length = glyph_count * sizeof(glyphs[0]); | 264 const size_t byte_length = glyph_count * sizeof(glyphs[0]); |
| (...skipping 588 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 857 canvas->ClipRect(clip_rect); | 853 canvas->ClipRect(clip_rect); |
| 858 } | 854 } |
| 859 | 855 |
| 860 if (!text().empty() && focused()) | 856 if (!text().empty() && focused()) |
| 861 DrawSelection(canvas); | 857 DrawSelection(canvas); |
| 862 | 858 |
| 863 if (cursor_enabled() && cursor_visible() && focused()) | 859 if (cursor_enabled() && cursor_visible() && focused()) |
| 864 DrawCursor(canvas, selection_model_); | 860 DrawCursor(canvas, selection_model_); |
| 865 | 861 |
| 866 if (!text().empty()) { | 862 if (!text().empty()) { |
| 867 internal::SkiaTextRenderer renderer(canvas); | 863 internal::SkiaTextRenderer renderer(canvas); |
|
msw
2017/01/25 18:09:07
nit: inline |renderer| and remove curlies
Evan Stade
2017/01/26 00:43:10
I don't think I can do that --- how does one take
msw
2017/01/26 00:52:09
Ah, I missed that; disregard my comment.
| |
| 868 if (halo_effect()) | |
| 869 renderer.SetHaloEffect(); | |
| 870 DrawVisualText(&renderer); | 864 DrawVisualText(&renderer); |
| 871 } | 865 } |
| 872 | 866 |
| 873 if (clip_to_display_rect()) | 867 if (clip_to_display_rect()) |
| 874 canvas->Restore(); | 868 canvas->Restore(); |
| 875 } | 869 } |
| 876 | 870 |
| 877 void RenderText::DrawCursor(Canvas* canvas, const SelectionModel& position) { | 871 void RenderText::DrawCursor(Canvas* canvas, const SelectionModel& position) { |
| 878 // Paint cursor. Replace cursor is drawn as rectangle for now. | 872 // Paint cursor. Replace cursor is drawn as rectangle for now. |
| 879 // TODO(msw): Draw a better cursor with a better indication of association. | 873 // TODO(msw): Draw a better cursor with a better indication of association. |
| (...skipping 830 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1710 | 1704 |
| 1711 for (; range_max < length; ++range_max) | 1705 for (; range_max < length; ++range_max) |
| 1712 if (iter.IsEndOfWord(range_max) || iter.IsStartOfWord(range_max)) | 1706 if (iter.IsEndOfWord(range_max) || iter.IsStartOfWord(range_max)) |
| 1713 break; | 1707 break; |
| 1714 | 1708 |
| 1715 return range.is_reversed() ? Range(range_max, range_min) | 1709 return range.is_reversed() ? Range(range_max, range_min) |
| 1716 : Range(range_min, range_max); | 1710 : Range(range_min, range_max); |
| 1717 } | 1711 } |
| 1718 | 1712 |
| 1719 } // namespace gfx | 1713 } // namespace gfx |
| OLD | NEW |