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/DocumentMarkerController.h" | 9 #include "core/editing/markers/DocumentMarkerController.h" |
10 #include "core/frame/LocalFrame.h" | 10 #include "core/frame/LocalFrame.h" |
(...skipping 688 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
699 default: | 699 default: |
700 NOTREACHED(); | 700 NOTREACHED(); |
701 } | 701 } |
702 } | 702 } |
703 } | 703 } |
704 | 704 |
705 namespace { | 705 namespace { |
706 | 706 |
707 #if !OS(MACOSX) | 707 #if !OS(MACOSX) |
708 | 708 |
| 709 static const float kMarkerWidth = 4; |
| 710 static const float kMarkerHeight = 2; |
| 711 |
709 sk_sp<PaintRecord> RecordMarker(DocumentMarker::MarkerType marker_type) { | 712 sk_sp<PaintRecord> RecordMarker(DocumentMarker::MarkerType marker_type) { |
710 SkColor color = (marker_type == DocumentMarker::kGrammar) | 713 SkColor color = (marker_type == DocumentMarker::kGrammar) |
711 ? SkColorSetRGB(0xC0, 0xC0, 0xC0) | 714 ? SkColorSetRGB(0xC0, 0xC0, 0xC0) |
712 : SK_ColorRED; | 715 : SK_ColorRED; |
713 | 716 |
714 // Record the path equivalent to this legacy pattern: | 717 // Record the path equivalent to this legacy pattern: |
715 // X o o X o o X | 718 // X o o X o o X |
716 // o X o o X o | 719 // o X o o X o |
717 | 720 |
718 static const float kW = 4; | |
719 static const float kH = 2; | |
720 | |
721 // Adjust the phase such that f' == 0 is "pixel"-centered | 721 // Adjust the phase such that f' == 0 is "pixel"-centered |
722 // (for optimal rasterization at native rez). | 722 // (for optimal rasterization at native rez). |
723 SkPath path; | 723 SkPath path; |
724 path.moveTo(kW * -3 / 8, kH * 3 / 4); | 724 path.moveTo(kMarkerWidth * -3 / 8, kMarkerHeight * 3 / 4); |
725 path.cubicTo(kW * -1 / 8, kH * 3 / 4, | 725 path.cubicTo(kMarkerWidth * -1 / 8, kMarkerHeight * 3 / 4, |
726 kW * -1 / 8, kH * 1 / 4, | 726 kMarkerWidth * -1 / 8, kMarkerHeight * 1 / 4, |
727 kW * 1 / 8, kH * 1 / 4); | 727 kMarkerWidth * 1 / 8, kMarkerHeight * 1 / 4); |
728 path.cubicTo(kW * 3 / 8, kH * 1 / 4, | 728 path.cubicTo(kMarkerWidth * 3 / 8, kMarkerHeight * 1 / 4, |
729 kW * 3 / 8, kH * 3 / 4, | 729 kMarkerWidth * 3 / 8, kMarkerHeight * 3 / 4, |
730 kW * 5 / 8, kH * 3 / 4); | 730 kMarkerWidth * 5 / 8, kMarkerHeight * 3 / 4); |
731 path.cubicTo(kW * 7 / 8, kH * 3 / 4, | 731 path.cubicTo(kMarkerWidth * 7 / 8, kMarkerHeight * 3 / 4, |
732 kW * 7 / 8, kH * 1 / 4, | 732 kMarkerWidth * 7 / 8, kMarkerHeight * 1 / 4, |
733 kW * 9 / 8, kH * 1 / 4); | 733 kMarkerWidth * 9 / 8, kMarkerHeight * 1 / 4); |
734 | 734 |
735 PaintFlags flags; | 735 PaintFlags flags; |
736 flags.setAntiAlias(true); | 736 flags.setAntiAlias(true); |
737 flags.setColor(color); | 737 flags.setColor(color); |
738 flags.setStyle(PaintFlags::kStroke_Style); | 738 flags.setStyle(PaintFlags::kStroke_Style); |
739 flags.setStrokeWidth(kH * 1 / 2); | 739 flags.setStrokeWidth(kMarkerHeight * 1 / 2); |
740 | 740 |
741 PaintRecorder recorder; | 741 PaintRecorder recorder; |
742 recorder.beginRecording(kW, kH); | 742 recorder.beginRecording(kMarkerWidth, kMarkerHeight); |
743 recorder.getRecordingCanvas()->drawPath(path, flags); | 743 recorder.getRecordingCanvas()->drawPath(path, flags); |
744 | 744 |
745 return recorder.finishRecordingAsPicture(); | 745 return recorder.finishRecordingAsPicture(); |
746 } | 746 } |
747 | 747 |
748 #else // OS(MACOSX) | 748 #else // OS(MACOSX) |
749 | 749 |
| 750 static const float kMarkerWidth = 4; |
| 751 static const float kMarkerHeight = 3; |
| 752 |
750 sk_sp<PaintRecord> RecordMarker(DocumentMarker::MarkerType marker_type) { | 753 sk_sp<PaintRecord> RecordMarker(DocumentMarker::MarkerType marker_type) { |
751 SkColor color = (marker_type == DocumentMarker::kGrammar) | 754 SkColor color = (marker_type == DocumentMarker::kGrammar) |
752 ? SkColorSetRGB(0x6B, 0x6B, 0x6B) | 755 ? SkColorSetRGB(0x6B, 0x6B, 0x6B) |
753 : SkColorSetRGB(0xFB, 0x2D, 0x1D); | 756 : SkColorSetRGB(0xFB, 0x2D, 0x1D); |
754 | 757 |
755 // Match the artwork used by the Mac. | 758 // Match the artwork used by the Mac. |
756 static const float kW = 4; | |
757 static const float kH = 3; | |
758 static const float kR = 1.5f; | 759 static const float kR = 1.5f; |
759 | 760 |
760 // top->bottom translucent gradient. | 761 // top->bottom translucent gradient. |
761 const SkColor colors[2] = { | 762 const SkColor colors[2] = { |
762 SkColorSetARGB(0x48, | 763 SkColorSetARGB(0x48, |
763 SkColorGetR(color), | 764 SkColorGetR(color), |
764 SkColorGetG(color), | 765 SkColorGetG(color), |
765 SkColorGetB(color)), | 766 SkColorGetB(color)), |
766 color | 767 color |
767 }; | 768 }; |
768 const SkPoint pts[2] = { | 769 const SkPoint pts[2] = { |
769 SkPoint::Make(0, 0), | 770 SkPoint::Make(0, 0), |
770 SkPoint::Make(0, 2 * kR) | 771 SkPoint::Make(0, 2 * kR) |
771 }; | 772 }; |
772 | 773 |
773 PaintFlags flags; | 774 PaintFlags flags; |
774 flags.setAntiAlias(true); | 775 flags.setAntiAlias(true); |
775 flags.setColor(color); | 776 flags.setColor(color); |
776 flags.setShader(SkGradientShader::MakeLinear( | 777 flags.setShader(SkGradientShader::MakeLinear( |
777 pts, colors, nullptr, ARRAY_SIZE(colors), SkShader::kClamp_TileMode)); | 778 pts, colors, nullptr, ARRAY_SIZE(colors), SkShader::kClamp_TileMode)); |
778 PaintRecorder recorder; | 779 PaintRecorder recorder; |
779 recorder.beginRecording(kW, kH); | 780 recorder.beginRecording(kMarkerWidth, kMarkerHeight); |
780 recorder.getRecordingCanvas()->drawCircle(kR, kR, kR, flags); | 781 recorder.getRecordingCanvas()->drawCircle(kR, kR, kR, flags); |
781 | 782 |
782 return recorder.finishRecordingAsPicture(); | 783 return recorder.finishRecordingAsPicture(); |
783 } | 784 } |
784 | 785 |
785 #endif // OS(MACOSX) | 786 #endif // OS(MACOSX) |
786 | 787 |
787 void DrawDocumentMarker(GraphicsContext& context, | 788 void DrawDocumentMarker(GraphicsContext& context, |
788 const FloatPoint& pt, | 789 const FloatPoint& pt, |
789 float width, | 790 float width, |
790 DocumentMarker::MarkerType marker_type, | 791 DocumentMarker::MarkerType marker_type, |
791 float zoom) { | 792 float zoom) { |
792 DCHECK(marker_type == DocumentMarker::kSpelling || | 793 DCHECK(marker_type == DocumentMarker::kSpelling || |
793 marker_type == DocumentMarker::kGrammar); | 794 marker_type == DocumentMarker::kGrammar); |
794 | 795 |
795 DEFINE_STATIC_LOCAL(PaintRecord*, spelling_marker, | 796 DEFINE_STATIC_LOCAL(PaintRecord*, spelling_marker, |
796 (RecordMarker(DocumentMarker::kSpelling).release())); | 797 (RecordMarker(DocumentMarker::kSpelling).release())); |
797 DEFINE_STATIC_LOCAL(PaintRecord*, grammar_marker, | 798 DEFINE_STATIC_LOCAL(PaintRecord*, grammar_marker, |
798 (RecordMarker(DocumentMarker::kGrammar).release())); | 799 (RecordMarker(DocumentMarker::kGrammar).release())); |
799 const auto& marker = marker_type == DocumentMarker::kSpelling | 800 const auto& marker = marker_type == DocumentMarker::kSpelling |
800 ? spelling_marker | 801 ? spelling_marker |
801 : grammar_marker; | 802 : grammar_marker; |
802 | 803 |
803 // Position already includes zoom and device scale factor. | 804 // Position already includes zoom and device scale factor. |
804 SkScalar origin_x = WebCoreFloatToSkScalar(pt.X()); | 805 SkScalar origin_x = WebCoreFloatToSkScalar(pt.X()); |
805 SkScalar origin_y = WebCoreFloatToSkScalar(pt.Y()); | 806 SkScalar origin_y = WebCoreFloatToSkScalar(pt.Y()); |
806 | 807 |
807 #if OS(MACOSX) | 808 #if OS(MACOSX) |
808 // Make sure to draw only complete dots, and finish inside the marked text. | 809 // Make sure to draw only complete dots, and finish inside the marked text. |
809 width -= fmodf(width, marker->cullRect().width() * zoom); | 810 width -= fmodf(width, kMarkerWidth * zoom); |
810 #else | 811 #else |
811 // Offset it vertically by 1 so that there's some space under the text. | 812 // Offset it vertically by 1 so that there's some space under the text. |
812 origin_y += 1; | 813 origin_y += 1; |
813 #endif | 814 #endif |
814 | 815 |
815 const auto rect = SkRect::MakeWH(width, marker->cullRect().height() * zoom); | 816 const auto rect = SkRect::MakeWH(width, kMarkerHeight * zoom); |
816 const auto local_matrix = SkMatrix::MakeScale(zoom, zoom); | 817 const auto local_matrix = SkMatrix::MakeScale(zoom, zoom); |
817 | 818 |
818 PaintFlags flags; | 819 PaintFlags flags; |
819 flags.setAntiAlias(true); | 820 flags.setAntiAlias(true); |
820 flags.setShader(WrapSkShader(MakePaintShaderRecord( | 821 flags.setShader(WrapSkShader(MakePaintShaderRecord( |
821 sk_ref_sp(marker), SkShader::kRepeat_TileMode, SkShader::kClamp_TileMode, | 822 sk_ref_sp(marker), FloatRect(0, 0, kMarkerWidth, kMarkerHeight), |
822 &local_matrix, nullptr))); | 823 SkShader::kRepeat_TileMode, SkShader::kClamp_TileMode, &local_matrix))); |
823 | 824 |
824 // Apply the origin translation as a global transform. This ensures that the | 825 // Apply the origin translation as a global transform. This ensures that the |
825 // shader local matrix depends solely on zoom => Skia can reuse the same | 826 // shader local matrix depends solely on zoom => Skia can reuse the same |
826 // cached tile for all markers at a given zoom level. | 827 // cached tile for all markers at a given zoom level. |
827 GraphicsContextStateSaver saver(context); | 828 GraphicsContextStateSaver saver(context); |
828 context.Translate(origin_x, origin_y); | 829 context.Translate(origin_x, origin_y); |
829 context.DrawRect(rect, flags); | 830 context.DrawRect(rect, flags); |
830 } | 831 } |
831 | 832 |
832 } // anonymous ns | 833 } // anonymous ns |
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1180 | 1181 |
1181 LayoutRect box_rect(box_origin, LayoutSize(inline_text_box_.LogicalWidth(), | 1182 LayoutRect box_rect(box_origin, LayoutSize(inline_text_box_.LogicalWidth(), |
1182 inline_text_box_.LogicalHeight())); | 1183 inline_text_box_.LogicalHeight())); |
1183 context.Clip(FloatRect(box_rect)); | 1184 context.Clip(FloatRect(box_rect)); |
1184 context.DrawHighlightForText(font, run, FloatPoint(box_origin), | 1185 context.DrawHighlightForText(font, run, FloatPoint(box_origin), |
1185 box_rect.Height().ToInt(), color, | 1186 box_rect.Height().ToInt(), color, |
1186 paint_offsets.first, paint_offsets.second); | 1187 paint_offsets.first, paint_offsets.second); |
1187 } | 1188 } |
1188 | 1189 |
1189 } // namespace blink | 1190 } // namespace blink |
OLD | NEW |