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 "ui/gfx/canvas.h" | 27 #include "ui/gfx/canvas.h" |
27 #include "ui/gfx/geometry/insets.h" | 28 #include "ui/gfx/geometry/insets.h" |
28 #include "ui/gfx/geometry/safe_integer_conversions.h" | 29 #include "ui/gfx/geometry/safe_integer_conversions.h" |
29 #include "ui/gfx/platform_font.h" | 30 #include "ui/gfx/platform_font.h" |
30 #include "ui/gfx/render_text_harfbuzz.h" | 31 #include "ui/gfx/render_text_harfbuzz.h" |
31 #include "ui/gfx/scoped_canvas.h" | 32 #include "ui/gfx/scoped_canvas.h" |
32 #include "ui/gfx/skia_util.h" | 33 #include "ui/gfx/skia_util.h" |
33 #include "ui/gfx/switches.h" | 34 #include "ui/gfx/switches.h" |
34 #include "ui/gfx/text_elider.h" | 35 #include "ui/gfx/text_elider.h" |
35 #include "ui/gfx/text_utils.h" | 36 #include "ui/gfx/text_utils.h" |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 } | 250 } |
250 | 251 |
251 void SkiaTextRenderer::SetForegroundColor(SkColor foreground) { | 252 void SkiaTextRenderer::SetForegroundColor(SkColor foreground) { |
252 paint_.setColor(foreground); | 253 paint_.setColor(foreground); |
253 } | 254 } |
254 | 255 |
255 void SkiaTextRenderer::SetShader(sk_sp<SkShader> shader) { | 256 void SkiaTextRenderer::SetShader(sk_sp<SkShader> shader) { |
256 paint_.setShader(std::move(shader)); | 257 paint_.setShader(std::move(shader)); |
257 } | 258 } |
258 | 259 |
| 260 void SkiaTextRenderer::SetHaloEffect() { |
| 261 paint_.setImageFilter(SkDilateImageFilter::Make(1, 1, nullptr)); |
| 262 } |
| 263 |
259 void SkiaTextRenderer::SetUnderlineMetrics(SkScalar thickness, | 264 void SkiaTextRenderer::SetUnderlineMetrics(SkScalar thickness, |
260 SkScalar position) { | 265 SkScalar position) { |
261 underline_thickness_ = thickness; | 266 underline_thickness_ = thickness; |
262 underline_position_ = position; | 267 underline_position_ = position; |
263 } | 268 } |
264 | 269 |
265 void SkiaTextRenderer::DrawPosText(const SkPoint* pos, | 270 void SkiaTextRenderer::DrawPosText(const SkPoint* pos, |
266 const uint16_t* glyphs, | 271 const uint16_t* glyphs, |
267 size_t glyph_count) { | 272 size_t glyph_count) { |
268 const size_t byte_length = glyph_count * sizeof(glyphs[0]); | 273 const size_t byte_length = glyph_count * sizeof(glyphs[0]); |
(...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
842 } | 847 } |
843 | 848 |
844 if (!text().empty() && focused()) | 849 if (!text().empty() && focused()) |
845 DrawSelection(canvas); | 850 DrawSelection(canvas); |
846 | 851 |
847 if (cursor_enabled() && cursor_visible() && focused()) | 852 if (cursor_enabled() && cursor_visible() && focused()) |
848 DrawCursor(canvas, selection_model_); | 853 DrawCursor(canvas, selection_model_); |
849 | 854 |
850 if (!text().empty()) { | 855 if (!text().empty()) { |
851 internal::SkiaTextRenderer renderer(canvas); | 856 internal::SkiaTextRenderer renderer(canvas); |
| 857 if (halo_effect()) |
| 858 renderer.SetHaloEffect(); |
852 DrawVisualText(&renderer); | 859 DrawVisualText(&renderer); |
853 } | 860 } |
854 | 861 |
855 if (clip_to_display_rect()) | 862 if (clip_to_display_rect()) |
856 canvas->Restore(); | 863 canvas->Restore(); |
857 } | 864 } |
858 | 865 |
859 void RenderText::DrawCursor(Canvas* canvas, const SelectionModel& position) { | 866 void RenderText::DrawCursor(Canvas* canvas, const SelectionModel& position) { |
860 // Paint cursor. Replace cursor is drawn as rectangle for now. | 867 // Paint cursor. Replace cursor is drawn as rectangle for now. |
861 // TODO(msw): Draw a better cursor with a better indication of association. | 868 // TODO(msw): Draw a better cursor with a better indication of association. |
(...skipping 719 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1581 | 1588 |
1582 SetDisplayOffset(display_offset_.x() + delta_x); | 1589 SetDisplayOffset(display_offset_.x() + delta_x); |
1583 } | 1590 } |
1584 | 1591 |
1585 void RenderText::DrawSelection(Canvas* canvas) { | 1592 void RenderText::DrawSelection(Canvas* canvas) { |
1586 for (const Rect& s : GetSubstringBounds(selection())) | 1593 for (const Rect& s : GetSubstringBounds(selection())) |
1587 canvas->FillRect(s, selection_background_focused_color_); | 1594 canvas->FillRect(s, selection_background_focused_color_); |
1588 } | 1595 } |
1589 | 1596 |
1590 } // namespace gfx | 1597 } // namespace gfx |
OLD | NEW |