OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "core/paint/InlineTextBoxPainter.h" | 5 #include "core/paint/InlineTextBoxPainter.h" |
6 | 6 |
7 #include "core/editing/CompositionUnderline.h" | 7 #include "core/editing/CompositionUnderline.h" |
8 #include "core/editing/Editor.h" | 8 #include "core/editing/Editor.h" |
9 #include "core/editing/markers/CompositionMarker.h" | 9 #include "core/editing/markers/CompositionMarker.h" |
10 #include "core/editing/markers/DocumentMarkerController.h" | 10 #include "core/editing/markers/DocumentMarkerController.h" |
11 #include "core/editing/markers/TextMatchMarker.h" | 11 #include "core/editing/markers/TextMatchMarker.h" |
12 #include "core/frame/LocalFrame.h" | 12 #include "core/frame/LocalFrame.h" |
13 #include "core/layout/LayoutTextCombine.h" | 13 #include "core/layout/LayoutTextCombine.h" |
14 #include "core/layout/LayoutTheme.h" | 14 #include "core/layout/LayoutTheme.h" |
15 #include "core/layout/api/LineLayoutAPIShim.h" | 15 #include "core/layout/api/LineLayoutAPIShim.h" |
16 #include "core/layout/api/LineLayoutBox.h" | 16 #include "core/layout/api/LineLayoutBox.h" |
17 #include "core/layout/line/InlineTextBox.h" | 17 #include "core/layout/line/InlineTextBox.h" |
18 #include "core/paint/AppliedDecorationPainter.h" | 18 #include "core/paint/AppliedDecorationPainter.h" |
19 #include "core/paint/DecorationInfo.h" | 19 #include "core/paint/DecorationInfo.h" |
20 #include "core/paint/PaintInfo.h" | 20 #include "core/paint/PaintInfo.h" |
21 #include "core/paint/TextPainter.h" | 21 #include "core/paint/TextPainter.h" |
22 #include "platform/graphics/GraphicsContextStateSaver.h" | 22 #include "platform/graphics/GraphicsContextStateSaver.h" |
23 #include "platform/graphics/paint/DrawingRecorder.h" | 23 #include "platform/graphics/paint/DrawingRecorder.h" |
24 #include "platform/graphics/paint/PaintRecord.h" | 24 #include "platform/graphics/paint/PaintRecord.h" |
25 #include "platform/graphics/paint/PaintRecorder.h" | 25 #include "platform/graphics/paint/PaintRecorder.h" |
26 #include "platform/graphics/paint/PaintShader.h" | |
27 #include "platform/wtf/Optional.h" | 26 #include "platform/wtf/Optional.h" |
28 #include "third_party/skia/include/effects/SkGradientShader.h" | 27 #include "third_party/skia/include/effects/SkGradientShader.h" |
29 | 28 |
30 namespace blink { | 29 namespace blink { |
31 | 30 |
32 namespace { | 31 namespace { |
33 | 32 |
34 std::pair<unsigned, unsigned> GetMarkerPaintOffsets( | 33 std::pair<unsigned, unsigned> GetMarkerPaintOffsets( |
35 const DocumentMarker& marker, | 34 const DocumentMarker& marker, |
36 const InlineTextBox& text_box) { | 35 const InlineTextBox& text_box) { |
(...skipping 725 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
762 color | 761 color |
763 }; | 762 }; |
764 const SkPoint pts[2] = { | 763 const SkPoint pts[2] = { |
765 SkPoint::Make(0, 0), | 764 SkPoint::Make(0, 0), |
766 SkPoint::Make(0, 2 * kR) | 765 SkPoint::Make(0, 2 * kR) |
767 }; | 766 }; |
768 | 767 |
769 PaintFlags flags; | 768 PaintFlags flags; |
770 flags.setAntiAlias(true); | 769 flags.setAntiAlias(true); |
771 flags.setColor(color); | 770 flags.setColor(color); |
772 flags.setShader(PaintShader::MakeLinearGradient( | 771 flags.setShader(SkGradientShader::MakeLinear( |
773 pts, colors, nullptr, ARRAY_SIZE(colors), SkShader::kClamp_TileMode)); | 772 pts, colors, nullptr, ARRAY_SIZE(colors), SkShader::kClamp_TileMode)); |
774 PaintRecorder recorder; | 773 PaintRecorder recorder; |
775 recorder.beginRecording(kMarkerWidth, kMarkerHeight); | 774 recorder.beginRecording(kMarkerWidth, kMarkerHeight); |
776 recorder.getRecordingCanvas()->drawCircle(kR, kR, kR, flags); | 775 recorder.getRecordingCanvas()->drawCircle(kR, kR, kR, flags); |
777 | 776 |
778 return recorder.finishRecordingAsPicture(); | 777 return recorder.finishRecordingAsPicture(); |
779 } | 778 } |
780 | 779 |
781 #endif // OS(MACOSX) | 780 #endif // OS(MACOSX) |
782 | 781 |
(...skipping 23 matching lines...) Expand all Loading... |
806 #else | 805 #else |
807 // Offset it vertically by 1 so that there's some space under the text. | 806 // Offset it vertically by 1 so that there's some space under the text. |
808 origin_y += 1; | 807 origin_y += 1; |
809 #endif | 808 #endif |
810 | 809 |
811 const auto rect = SkRect::MakeWH(width, kMarkerHeight * zoom); | 810 const auto rect = SkRect::MakeWH(width, kMarkerHeight * zoom); |
812 const auto local_matrix = SkMatrix::MakeScale(zoom, zoom); | 811 const auto local_matrix = SkMatrix::MakeScale(zoom, zoom); |
813 | 812 |
814 PaintFlags flags; | 813 PaintFlags flags; |
815 flags.setAntiAlias(true); | 814 flags.setAntiAlias(true); |
816 flags.setShader(PaintShader::MakePaintRecord( | 815 flags.setShader(WrapSkShader(MakePaintShaderRecord( |
817 sk_ref_sp(marker), FloatRect(0, 0, kMarkerWidth, kMarkerHeight), | 816 sk_ref_sp(marker), FloatRect(0, 0, kMarkerWidth, kMarkerHeight), |
818 SkShader::kRepeat_TileMode, SkShader::kClamp_TileMode, &local_matrix)); | 817 SkShader::kRepeat_TileMode, SkShader::kClamp_TileMode, &local_matrix))); |
819 | 818 |
820 // Apply the origin translation as a global transform. This ensures that the | 819 // Apply the origin translation as a global transform. This ensures that the |
821 // shader local matrix depends solely on zoom => Skia can reuse the same | 820 // shader local matrix depends solely on zoom => Skia can reuse the same |
822 // cached tile for all markers at a given zoom level. | 821 // cached tile for all markers at a given zoom level. |
823 GraphicsContextStateSaver saver(context); | 822 GraphicsContextStateSaver saver(context); |
824 context.Translate(origin_x, origin_y); | 823 context.Translate(origin_x, origin_y); |
825 context.DrawRect(rect, flags); | 824 context.DrawRect(rect, flags); |
826 } | 825 } |
827 | 826 |
828 } // anonymous ns | 827 } // anonymous ns |
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1176 | 1175 |
1177 LayoutRect box_rect(box_origin, LayoutSize(inline_text_box_.LogicalWidth(), | 1176 LayoutRect box_rect(box_origin, LayoutSize(inline_text_box_.LogicalWidth(), |
1178 inline_text_box_.LogicalHeight())); | 1177 inline_text_box_.LogicalHeight())); |
1179 context.Clip(FloatRect(box_rect)); | 1178 context.Clip(FloatRect(box_rect)); |
1180 context.DrawHighlightForText(font, run, FloatPoint(box_origin), | 1179 context.DrawHighlightForText(font, run, FloatPoint(box_origin), |
1181 box_rect.Height().ToInt(), color, | 1180 box_rect.Height().ToInt(), color, |
1182 paint_offsets.first, paint_offsets.second); | 1181 paint_offsets.first, paint_offsets.second); |
1183 } | 1182 } |
1184 | 1183 |
1185 } // namespace blink | 1184 } // namespace blink |
OLD | NEW |