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 21 matching lines...) Expand all Loading... |
32 gTextBlobCache->remove(&inlineTextBox); | 32 gTextBlobCache->remove(&inlineTextBox); |
33 } | 33 } |
34 | 34 |
35 static TextBlobPtr* addToTextBlobCache(const InlineTextBox& inlineTextBox) | 35 static TextBlobPtr* addToTextBlobCache(const InlineTextBox& inlineTextBox) |
36 { | 36 { |
37 if (!gTextBlobCache) | 37 if (!gTextBlobCache) |
38 gTextBlobCache = new InlineTextBoxBlobCacheMap; | 38 gTextBlobCache = new InlineTextBoxBlobCacheMap; |
39 return &gTextBlobCache->add(&inlineTextBox, nullptr).storedValue->value; | 39 return &gTextBlobCache->add(&inlineTextBox, nullptr).storedValue->value; |
40 } | 40 } |
41 | 41 |
| 42 LayoutObject& InlineTextBoxPainter::inlineLayoutObject() const |
| 43 { |
| 44 return *LineLayoutAPIShim::layoutObjectFrom(m_inlineTextBox.getLineLayoutIte
m()); |
| 45 } |
| 46 |
42 bool InlineTextBoxPainter::paintsMarkerHighlights(const LayoutObject& layoutObje
ct) | 47 bool InlineTextBoxPainter::paintsMarkerHighlights(const LayoutObject& layoutObje
ct) |
43 { | 48 { |
44 return layoutObject.node() && layoutObject.document().markers().hasMarkers(l
ayoutObject.node()); | 49 return layoutObject.node() && layoutObject.document().markers().hasMarkers(l
ayoutObject.node()); |
45 } | 50 } |
46 | 51 |
47 static bool paintsCompositionMarkers(const LayoutObject& layoutObject) | 52 static bool paintsCompositionMarkers(const LayoutObject& layoutObject) |
48 { | 53 { |
49 return layoutObject.node() && layoutObject.document().markers().markersFor(l
ayoutObject.node(), DocumentMarker::Composition).size() > 0; | 54 return layoutObject.node() && layoutObject.document().markers().markersFor(l
ayoutObject.node(), DocumentMarker::Composition).size() > 0; |
50 } | 55 } |
51 | 56 |
(...skipping 29 matching lines...) Expand all Loading... |
81 } | 86 } |
82 | 87 |
83 // The text clip phase already has a LayoutObjectDrawingRecorder. Text clips
are initiated only in BoxPainter::paintFillLayer, | 88 // The text clip phase already has a LayoutObjectDrawingRecorder. Text clips
are initiated only in BoxPainter::paintFillLayer, |
84 // which is already within a LayoutObjectDrawingRecorder. | 89 // which is already within a LayoutObjectDrawingRecorder. |
85 Optional<DrawingRecorder> drawingRecorder; | 90 Optional<DrawingRecorder> drawingRecorder; |
86 if (paintInfo.phase != PaintPhaseTextClip) { | 91 if (paintInfo.phase != PaintPhaseTextClip) { |
87 if (DrawingRecorder::useCachedDrawingIfPossible(paintInfo.context, m_inl
ineTextBox, DisplayItem::paintPhaseToDrawingType(paintInfo.phase))) | 92 if (DrawingRecorder::useCachedDrawingIfPossible(paintInfo.context, m_inl
ineTextBox, DisplayItem::paintPhaseToDrawingType(paintInfo.phase))) |
88 return; | 93 return; |
89 LayoutRect paintRect(logicalVisualOverflow); | 94 LayoutRect paintRect(logicalVisualOverflow); |
90 m_inlineTextBox.logicalRectToPhysicalRect(paintRect); | 95 m_inlineTextBox.logicalRectToPhysicalRect(paintRect); |
91 if (paintInfo.phase != PaintPhaseSelection && (haveSelection || paintsMa
rkerHighlights(*LineLayoutAPIShim::layoutObjectFrom(m_inlineTextBox.getLineLayou
tItem())))) | 96 if (paintInfo.phase != PaintPhaseSelection && (haveSelection || paintsMa
rkerHighlights(inlineLayoutObject()))) |
92 paintRect.unite(m_inlineTextBox.localSelectionRect(m_inlineTextBox.s
tart(), m_inlineTextBox.start() + m_inlineTextBox.len())); | 97 paintRect.unite(m_inlineTextBox.localSelectionRect(m_inlineTextBox.s
tart(), m_inlineTextBox.start() + m_inlineTextBox.len())); |
93 paintRect.moveBy(adjustedPaintOffset); | 98 paintRect.moveBy(adjustedPaintOffset); |
94 drawingRecorder.emplace(paintInfo.context, m_inlineTextBox, DisplayItem:
:paintPhaseToDrawingType(paintInfo.phase), FloatRect(paintRect)); | 99 drawingRecorder.emplace(paintInfo.context, m_inlineTextBox, DisplayItem:
:paintPhaseToDrawingType(paintInfo.phase), FloatRect(paintRect)); |
95 } | 100 } |
96 | 101 |
97 GraphicsContext& context = paintInfo.context; | 102 GraphicsContext& context = paintInfo.context; |
98 const ComputedStyle& styleToUse = m_inlineTextBox.getLineLayoutItem().styleR
ef(m_inlineTextBox.isFirstLineStyle()); | 103 const ComputedStyle& styleToUse = m_inlineTextBox.getLineLayoutItem().styleR
ef(m_inlineTextBox.isFirstLineStyle()); |
99 | 104 |
100 LayoutPoint boxOrigin(m_inlineTextBox.locationIncludingFlipping()); | 105 LayoutPoint boxOrigin(m_inlineTextBox.locationIncludingFlipping()); |
101 boxOrigin.move(adjustedPaintOffset.x(), adjustedPaintOffset.y()); | 106 boxOrigin.move(adjustedPaintOffset.x(), adjustedPaintOffset.y()); |
102 LayoutRect boxRect(boxOrigin, LayoutSize(m_inlineTextBox.logicalWidth(), m_i
nlineTextBox.logicalHeight())); | 107 LayoutRect boxRect(boxOrigin, LayoutSize(m_inlineTextBox.logicalWidth(), m_i
nlineTextBox.logicalHeight())); |
103 | 108 |
104 bool shouldRotate = false; | 109 bool shouldRotate = false; |
105 LayoutTextCombine* combinedText = nullptr; | 110 LayoutTextCombine* combinedText = nullptr; |
106 if (!m_inlineTextBox.isHorizontal()) { | 111 if (!m_inlineTextBox.isHorizontal()) { |
107 if (styleToUse.hasTextCombine() && m_inlineTextBox.getLineLayoutItem().i
sCombineText()) { | 112 if (styleToUse.hasTextCombine() && m_inlineTextBox.getLineLayoutItem().i
sCombineText()) { |
108 combinedText = &toLayoutTextCombine(*LineLayoutAPIShim::layoutObject
From(m_inlineTextBox.getLineLayoutItem())); | 113 combinedText = &toLayoutTextCombine(inlineLayoutObject()); |
109 if (!combinedText->isCombined()) | 114 if (!combinedText->isCombined()) |
110 combinedText = nullptr; | 115 combinedText = nullptr; |
111 } | 116 } |
112 if (combinedText) { | 117 if (combinedText) { |
113 combinedText->updateFont(); | 118 combinedText->updateFont(); |
114 boxRect.setWidth(combinedText->inlineWidthForLayout()); | 119 boxRect.setWidth(combinedText->inlineWidthForLayout()); |
115 } else { | 120 } else { |
116 shouldRotate = true; | 121 shouldRotate = true; |
117 context.concatCTM(TextPainter::rotation(boxRect, TextPainter::Clockw
ise)); | 122 context.concatCTM(TextPainter::rotation(boxRect, TextPainter::Clockw
ise)); |
118 } | 123 } |
119 } | 124 } |
120 | 125 |
121 // Determine text colors. | 126 // Determine text colors. |
122 TextPainter::Style textStyle = TextPainter::textPaintingStyle(m_inlineTextBo
x.getLineLayoutItem(), styleToUse, paintInfo); | 127 TextPainter::Style textStyle = TextPainter::textPaintingStyle(m_inlineTextBo
x.getLineLayoutItem(), styleToUse, paintInfo); |
123 TextPainter::Style selectionStyle = TextPainter::selectionPaintingStyle(m_in
lineTextBox.getLineLayoutItem(), haveSelection, paintInfo, textStyle); | 128 TextPainter::Style selectionStyle = TextPainter::selectionPaintingStyle(m_in
lineTextBox.getLineLayoutItem(), haveSelection, paintInfo, textStyle); |
124 bool paintSelectedTextOnly = (paintInfo.phase == PaintPhaseSelection); | 129 bool paintSelectedTextOnly = (paintInfo.phase == PaintPhaseSelection); |
125 bool paintSelectedTextSeparately = !paintSelectedTextOnly && textStyle != se
lectionStyle; | 130 bool paintSelectedTextSeparately = !paintSelectedTextOnly && textStyle != se
lectionStyle; |
126 | 131 |
127 // Set our font. | 132 // Set our font. |
128 const Font& font = styleToUse.font(); | 133 const Font& font = styleToUse.font(); |
129 | 134 |
130 LayoutPoint textOrigin(boxOrigin.x(), boxOrigin.y() + font.getFontMetrics().
ascent()); | 135 LayoutPoint textOrigin(boxOrigin.x(), boxOrigin.y() + font.getFontMetrics().
ascent()); |
131 | 136 |
132 // 1. Paint backgrounds behind text if needed. Examples of such backgrounds
include selection | 137 // 1. Paint backgrounds behind text if needed. Examples of such backgrounds
include selection |
133 // and composition highlights. | 138 // and composition highlights. |
134 if (paintInfo.phase != PaintPhaseSelection && paintInfo.phase != PaintPhaseT
extClip && !isPrinting) { | 139 if (paintInfo.phase != PaintPhaseSelection && paintInfo.phase != PaintPhaseT
extClip && !isPrinting) { |
135 paintDocumentMarkers(paintInfo, boxOrigin, styleToUse, font, DocumentMar
kerPaintPhase::Background); | 140 paintDocumentMarkers(paintInfo, boxOrigin, styleToUse, font, DocumentMar
kerPaintPhase::Background); |
136 | 141 |
137 const LayoutObject& textBoxLayoutObject = *LineLayoutAPIShim::layoutObje
ctFrom(m_inlineTextBox.getLineLayoutItem()); | 142 const LayoutObject& textBoxLayoutObject = inlineLayoutObject(); |
138 if (haveSelection && !paintsCompositionMarkers(textBoxLayoutObject)) { | 143 if (haveSelection && !paintsCompositionMarkers(textBoxLayoutObject)) { |
139 if (combinedText) | 144 if (combinedText) |
140 paintSelection<InlineTextBoxPainter::PaintOptions::CombinedText>
(context, boxRect, styleToUse, font, selectionStyle.fillColor, combinedText); | 145 paintSelection<InlineTextBoxPainter::PaintOptions::CombinedText>
(context, boxRect, styleToUse, font, selectionStyle.fillColor, combinedText); |
141 else | 146 else |
142 paintSelection<InlineTextBoxPainter::PaintOptions::Normal>(conte
xt, boxRect, styleToUse, font, selectionStyle.fillColor); | 147 paintSelection<InlineTextBoxPainter::PaintOptions::Normal>(conte
xt, boxRect, styleToUse, font, selectionStyle.fillColor); |
143 } | 148 } |
144 } | 149 } |
145 | 150 |
146 // 2. Now paint the foreground, including text and decorations like underlin
e/overline (in quirks mode only). | 151 // 2. Now paint the foreground, including text and decorations like underlin
e/overline (in quirks mode only). |
147 int length = m_inlineTextBox.len(); | 152 int length = m_inlineTextBox.len(); |
(...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
712 if (m_inlineTextBox.truncation() != cNoTruncation) { | 717 if (m_inlineTextBox.truncation() != cNoTruncation) { |
713 width = LayoutUnit(m_inlineTextBox.getLineLayoutItem().width( | 718 width = LayoutUnit(m_inlineTextBox.getLineLayoutItem().width( |
714 m_inlineTextBox.start(), m_inlineTextBox.truncation(), m_inlineTextB
ox.textPos(), | 719 m_inlineTextBox.start(), m_inlineTextBox.truncation(), m_inlineTextB
ox.textPos(), |
715 m_inlineTextBox.isLeftToRightDirection() ? LTR : RTL, m_inlineTextBo
x.isFirstLineStyle())); | 720 m_inlineTextBox.isLeftToRightDirection() ? LTR : RTL, m_inlineTextBo
x.isFirstLineStyle())); |
716 if (!m_inlineTextBox.isLeftToRightDirection()) | 721 if (!m_inlineTextBox.isLeftToRightDirection()) |
717 localOrigin.move(m_inlineTextBox.logicalWidth() - width, LayoutUnit(
)); | 722 localOrigin.move(m_inlineTextBox.logicalWidth() - width, LayoutUnit(
)); |
718 } | 723 } |
719 | 724 |
720 // Get the text decoration colors. | 725 // Get the text decoration colors. |
721 LayoutObject::AppliedTextDecoration underline, overline, linethrough; | 726 LayoutObject::AppliedTextDecoration underline, overline, linethrough; |
722 LayoutObject& textBoxLayoutObject = *LineLayoutAPIShim::layoutObjectFrom(m_i
nlineTextBox.getLineLayoutItem()); | 727 LayoutObject& textBoxLayoutObject = inlineLayoutObject(); |
723 textBoxLayoutObject.getTextDecorations(deco, underline, overline, linethroug
h, true); | 728 textBoxLayoutObject.getTextDecorations(deco, underline, overline, linethroug
h, true); |
724 if (m_inlineTextBox.isFirstLineStyle()) | 729 if (m_inlineTextBox.isFirstLineStyle()) |
725 textBoxLayoutObject.getTextDecorations(deco, underline, overline, lineth
rough, true, true); | 730 textBoxLayoutObject.getTextDecorations(deco, underline, overline, lineth
rough, true, true); |
726 | 731 |
727 // Use a special function for underlines to get the positioning exactly righ
t. | 732 // Use a special function for underlines to get the positioning exactly righ
t. |
728 bool isPrinting = paintInfo.isPrinting(); | 733 bool isPrinting = paintInfo.isPrinting(); |
729 | 734 |
730 const ComputedStyle& styleToUse = textBoxLayoutObject.styleRef(m_inlineTextB
ox.isFirstLineStyle()); | 735 const ComputedStyle& styleToUse = textBoxLayoutObject.styleRef(m_inlineTextB
ox.isFirstLineStyle()); |
731 float baseline = styleToUse.getFontMetrics().ascent(); | 736 float baseline = styleToUse.getFontMetrics().ascent(); |
732 | 737 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
797 start += 1; | 802 start += 1; |
798 width -= 2; | 803 width -= 2; |
799 | 804 |
800 context.setStrokeColor(underline.color); | 805 context.setStrokeColor(underline.color); |
801 context.setStrokeThickness(lineThickness); | 806 context.setStrokeThickness(lineThickness); |
802 context.drawLineForText(FloatPoint(boxOrigin.x() + start, (boxOrigin.y() + m
_inlineTextBox.logicalHeight() - lineThickness).toFloat()), width, m_inlineTextB
ox.getLineLayoutItem().document().printing()); | 807 context.drawLineForText(FloatPoint(boxOrigin.x() + start, (boxOrigin.y() + m
_inlineTextBox.logicalHeight() - lineThickness).toFloat()), width, m_inlineTextB
ox.getLineLayoutItem().document().printing()); |
803 } | 808 } |
804 | 809 |
805 void InlineTextBoxPainter::paintTextMatchMarkerForeground(const PaintInfo& paint
Info, const LayoutPoint& boxOrigin, DocumentMarker* marker, const ComputedStyle&
style, const Font& font) | 810 void InlineTextBoxPainter::paintTextMatchMarkerForeground(const PaintInfo& paint
Info, const LayoutPoint& boxOrigin, DocumentMarker* marker, const ComputedStyle&
style, const Font& font) |
806 { | 811 { |
807 if (!LineLayoutAPIShim::layoutObjectFrom(m_inlineTextBox.getLineLayoutItem()
)->frame()->editor().markedTextMatchesAreHighlighted()) | 812 if (!inlineLayoutObject().frame()->editor().markedTextMatchesAreHighlighted(
)) |
808 return; | 813 return; |
809 | 814 |
810 // TODO(ramya.v): Extract this into a helper function and share many copies
of this code. | 815 // TODO(ramya.v): Extract this into a helper function and share many copies
of this code. |
811 int sPos = std::max(marker->startOffset() - m_inlineTextBox.start(), (unsign
ed)0); | 816 int sPos = std::max(marker->startOffset() - m_inlineTextBox.start(), (unsign
ed)0); |
812 int ePos = std::min(marker->endOffset() - m_inlineTextBox.start(), m_inlineT
extBox.len()); | 817 int ePos = std::min(marker->endOffset() - m_inlineTextBox.start(), m_inlineT
extBox.len()); |
813 TextRun run = m_inlineTextBox.constructTextRun(style, font); | 818 TextRun run = m_inlineTextBox.constructTextRun(style, font); |
814 | 819 |
815 Color textColor = LayoutTheme::theme().platformTextSearchColor(marker->activ
eMatch()); | 820 Color textColor = LayoutTheme::theme().platformTextSearchColor(marker->activ
eMatch()); |
816 if (style.visitedDependentColor(CSSPropertyColor) == textColor) | 821 if (style.visitedDependentColor(CSSPropertyColor) == textColor) |
817 return; | 822 return; |
(...skipping 22 matching lines...) Expand all Loading... |
840 GraphicsContext& context = paintInfo.context; | 845 GraphicsContext& context = paintInfo.context; |
841 GraphicsContextStateSaver stateSaver(context); | 846 GraphicsContextStateSaver stateSaver(context); |
842 | 847 |
843 LayoutRect boxRect(boxOrigin, LayoutSize(m_inlineTextBox.logicalWidth(), m_i
nlineTextBox.logicalHeight())); | 848 LayoutRect boxRect(boxOrigin, LayoutSize(m_inlineTextBox.logicalWidth(), m_i
nlineTextBox.logicalHeight())); |
844 context.clip(FloatRect(boxRect)); | 849 context.clip(FloatRect(boxRect)); |
845 context.drawHighlightForText(font, run, FloatPoint(boxOrigin), boxRect.heigh
t(), color, sPos, ePos); | 850 context.drawHighlightForText(font, run, FloatPoint(boxOrigin), boxRect.heigh
t(), color, sPos, ePos); |
846 } | 851 } |
847 | 852 |
848 | 853 |
849 } // namespace blink | 854 } // namespace blink |
OLD | NEW |