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/SkTypeface.h" | 23 #include "third_party/skia/include/core/SkTypeface.h" |
24 #include "third_party/skia/include/effects/SkGradientShader.h" | 24 #include "third_party/skia/include/effects/SkGradientShader.h" |
| 25 #include "third_party/skia/include/effects/SkMorphologyImageFilter.h" |
25 #include "ui/gfx/canvas.h" | 26 #include "ui/gfx/canvas.h" |
26 #include "ui/gfx/geometry/insets.h" | 27 #include "ui/gfx/geometry/insets.h" |
27 #include "ui/gfx/geometry/safe_integer_conversions.h" | 28 #include "ui/gfx/geometry/safe_integer_conversions.h" |
28 #include "ui/gfx/platform_font.h" | 29 #include "ui/gfx/platform_font.h" |
29 #include "ui/gfx/render_text_harfbuzz.h" | 30 #include "ui/gfx/render_text_harfbuzz.h" |
30 #include "ui/gfx/scoped_canvas.h" | 31 #include "ui/gfx/scoped_canvas.h" |
31 #include "ui/gfx/skia_util.h" | 32 #include "ui/gfx/skia_util.h" |
32 #include "ui/gfx/switches.h" | 33 #include "ui/gfx/switches.h" |
33 #include "ui/gfx/text_elider.h" | 34 #include "ui/gfx/text_elider.h" |
34 #include "ui/gfx/text_utils.h" | 35 #include "ui/gfx/text_utils.h" |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 } | 249 } |
249 | 250 |
250 void SkiaTextRenderer::SetForegroundColor(SkColor foreground) { | 251 void SkiaTextRenderer::SetForegroundColor(SkColor foreground) { |
251 paint_.setColor(foreground); | 252 paint_.setColor(foreground); |
252 } | 253 } |
253 | 254 |
254 void SkiaTextRenderer::SetShader(sk_sp<SkShader> shader) { | 255 void SkiaTextRenderer::SetShader(sk_sp<SkShader> shader) { |
255 paint_.setShader(std::move(shader)); | 256 paint_.setShader(std::move(shader)); |
256 } | 257 } |
257 | 258 |
| 259 void SkiaTextRenderer::SetHaloEffect() { |
| 260 paint_.setImageFilter(SkDilateImageFilter::Make(1, 1, nullptr)); |
| 261 } |
| 262 |
258 void SkiaTextRenderer::SetUnderlineMetrics(SkScalar thickness, | 263 void SkiaTextRenderer::SetUnderlineMetrics(SkScalar thickness, |
259 SkScalar position) { | 264 SkScalar position) { |
260 underline_thickness_ = thickness; | 265 underline_thickness_ = thickness; |
261 underline_position_ = position; | 266 underline_position_ = position; |
262 } | 267 } |
263 | 268 |
264 void SkiaTextRenderer::DrawPosText(const SkPoint* pos, | 269 void SkiaTextRenderer::DrawPosText(const SkPoint* pos, |
265 const uint16_t* glyphs, | 270 const uint16_t* glyphs, |
266 size_t glyph_count) { | 271 size_t glyph_count) { |
267 const size_t byte_length = glyph_count * sizeof(glyphs[0]); | 272 const size_t byte_length = glyph_count * sizeof(glyphs[0]); |
(...skipping 555 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
823 } | 828 } |
824 | 829 |
825 if (!text().empty() && focused()) | 830 if (!text().empty() && focused()) |
826 DrawSelection(canvas); | 831 DrawSelection(canvas); |
827 | 832 |
828 if (cursor_enabled() && cursor_visible() && focused()) | 833 if (cursor_enabled() && cursor_visible() && focused()) |
829 DrawCursor(canvas, selection_model_); | 834 DrawCursor(canvas, selection_model_); |
830 | 835 |
831 if (!text().empty()) { | 836 if (!text().empty()) { |
832 internal::SkiaTextRenderer renderer(canvas); | 837 internal::SkiaTextRenderer renderer(canvas); |
| 838 if (halo_effect()) |
| 839 renderer.SetHaloEffect(); |
833 DrawVisualText(&renderer); | 840 DrawVisualText(&renderer); |
834 } | 841 } |
835 | 842 |
836 if (clip_to_display_rect()) | 843 if (clip_to_display_rect()) |
837 canvas->Restore(); | 844 canvas->Restore(); |
838 } | 845 } |
839 | 846 |
840 void RenderText::DrawCursor(Canvas* canvas, const SelectionModel& position) { | 847 void RenderText::DrawCursor(Canvas* canvas, const SelectionModel& position) { |
841 // Paint cursor. Replace cursor is drawn as rectangle for now. | 848 // Paint cursor. Replace cursor is drawn as rectangle for now. |
842 // TODO(msw): Draw a better cursor with a better indication of association. | 849 // TODO(msw): Draw a better cursor with a better indication of association. |
(...skipping 716 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1559 | 1566 |
1560 SetDisplayOffset(display_offset_.x() + delta_x); | 1567 SetDisplayOffset(display_offset_.x() + delta_x); |
1561 } | 1568 } |
1562 | 1569 |
1563 void RenderText::DrawSelection(Canvas* canvas) { | 1570 void RenderText::DrawSelection(Canvas* canvas) { |
1564 for (const Rect& s : GetSubstringBounds(selection())) | 1571 for (const Rect& s : GetSubstringBounds(selection())) |
1565 canvas->FillRect(s, selection_background_focused_color_); | 1572 canvas->FillRect(s, selection_background_focused_color_); |
1566 } | 1573 } |
1567 | 1574 |
1568 } // namespace gfx | 1575 } // namespace gfx |
OLD | NEW |