| 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 "config.h" | 5 #include "config.h" |
| 6 #include "core/paint/InlineTextBoxPainter.h" | 6 #include "core/paint/InlineTextBoxPainter.h" |
| 7 | 7 |
| 8 #include "core/dom/DocumentMarkerController.h" | 8 #include "core/dom/DocumentMarkerController.h" |
| 9 #include "core/dom/RenderedDocumentMarker.h" | 9 #include "core/dom/RenderedDocumentMarker.h" |
| 10 #include "core/editing/CompositionUnderline.h" | 10 #include "core/editing/CompositionUnderline.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 static InlineTextBoxBlobCacheMap* gTextBlobCache; | 26 static InlineTextBoxBlobCacheMap* gTextBlobCache; |
| 27 | 27 |
| 28 static const int misspellingLineThickness = 3; | 28 static const int misspellingLineThickness = 3; |
| 29 | 29 |
| 30 void InlineTextBoxPainter::removeFromTextBlobCache(InlineTextBox& inlineTextBox) | 30 void InlineTextBoxPainter::removeFromTextBlobCache(InlineTextBox& inlineTextBox) |
| 31 { | 31 { |
| 32 if (gTextBlobCache) | 32 if (gTextBlobCache) |
| 33 gTextBlobCache->remove(&inlineTextBox); | 33 gTextBlobCache->remove(&inlineTextBox); |
| 34 } | 34 } |
| 35 | 35 |
| 36 static TextBlobPtr* addToTextBlobCache(InlineTextBox& inlineTextBox) |
| 37 { |
| 38 if (!gTextBlobCache) |
| 39 gTextBlobCache = new InlineTextBoxBlobCacheMap; |
| 40 return &gTextBlobCache->add(&inlineTextBox, nullptr).storedValue->value; |
| 41 } |
| 42 |
| 36 void InlineTextBoxPainter::paint(PaintInfo& paintInfo, const LayoutPoint& paintO
ffset) | 43 void InlineTextBoxPainter::paint(PaintInfo& paintInfo, const LayoutPoint& paintO
ffset) |
| 37 { | 44 { |
| 38 if (m_inlineTextBox.isLineBreak() || !paintInfo.shouldPaintWithinRoot(&m_inl
ineTextBox.renderer()) || m_inlineTextBox.renderer().style()->visibility() != VI
SIBLE | 45 if (m_inlineTextBox.isLineBreak() || !paintInfo.shouldPaintWithinRoot(&m_inl
ineTextBox.renderer()) || m_inlineTextBox.renderer().style()->visibility() != VI
SIBLE |
| 39 || m_inlineTextBox.truncation() == cFullTruncation || paintInfo.phase ==
PaintPhaseOutline || !m_inlineTextBox.len()) | 46 || m_inlineTextBox.truncation() == cFullTruncation || paintInfo.phase ==
PaintPhaseOutline || !m_inlineTextBox.len()) |
| 40 return; | 47 return; |
| 41 | 48 |
| 42 ASSERT(paintInfo.phase != PaintPhaseSelfOutline && paintInfo.phase != PaintP
haseChildOutlines); | 49 ASSERT(paintInfo.phase != PaintPhaseSelfOutline && paintInfo.phase != PaintP
haseChildOutlines); |
| 43 | 50 |
| 44 LayoutRect logicalVisualOverflow = m_inlineTextBox.logicalOverflowRect(); | 51 LayoutRect logicalVisualOverflow = m_inlineTextBox.logicalOverflowRect(); |
| 45 LayoutUnit logicalStart = logicalVisualOverflow.x() + (m_inlineTextBox.isHor
izontal() ? paintOffset.x() : paintOffset.y()); | 52 LayoutUnit logicalStart = logicalVisualOverflow.x() + (m_inlineTextBox.isHor
izontal() ? paintOffset.x() : paintOffset.y()); |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 if (paintSelectedTextSeparately && selectionStart < selectionEnd) { | 187 if (paintSelectedTextSeparately && selectionStart < selectionEnd) { |
| 181 startOffset = selectionEnd; | 188 startOffset = selectionEnd; |
| 182 endOffset = selectionStart; | 189 endOffset = selectionStart; |
| 183 } | 190 } |
| 184 | 191 |
| 185 // FIXME: This cache should probably ultimately be held somewhere else. | 192 // FIXME: This cache should probably ultimately be held somewhere else. |
| 186 // A hashmap is convenient to avoid a memory hit when the | 193 // A hashmap is convenient to avoid a memory hit when the |
| 187 // RuntimeEnabledFeature is off. | 194 // RuntimeEnabledFeature is off. |
| 188 bool textBlobIsCacheable = RuntimeEnabledFeatures::textBlobEnabled() &&
startOffset == 0 && endOffset == length; | 195 bool textBlobIsCacheable = RuntimeEnabledFeatures::textBlobEnabled() &&
startOffset == 0 && endOffset == length; |
| 189 TextBlobPtr* cachedTextBlob = 0; | 196 TextBlobPtr* cachedTextBlob = 0; |
| 190 if (textBlobIsCacheable) { | 197 if (textBlobIsCacheable) |
| 191 if (!gTextBlobCache) | 198 cachedTextBlob = addToTextBlobCache(m_inlineTextBox); |
| 192 gTextBlobCache = new InlineTextBoxBlobCacheMap; | |
| 193 cachedTextBlob = &gTextBlobCache->add(&m_inlineTextBox, nullptr).sto
redValue->value; | |
| 194 } | |
| 195 textPainter.paint(startOffset, endOffset, length, textStyle, cachedTextB
lob); | 199 textPainter.paint(startOffset, endOffset, length, textStyle, cachedTextB
lob); |
| 196 } | 200 } |
| 197 | 201 |
| 198 if ((paintSelectedTextOnly || paintSelectedTextSeparately) && selectionStart
< selectionEnd) { | 202 if ((paintSelectedTextOnly || paintSelectedTextSeparately) && selectionStart
< selectionEnd) { |
| 199 // paint only the text that is selected | 203 // paint only the text that is selected |
| 200 textPainter.paint(selectionStart, selectionEnd, length, selectionStyle); | 204 bool textBlobIsCacheable = RuntimeEnabledFeatures::textBlobEnabled() &&
selectionStart == 0 && selectionEnd == length; |
| 205 TextBlobPtr* cachedTextBlob = 0; |
| 206 if (textBlobIsCacheable) |
| 207 cachedTextBlob = addToTextBlobCache(m_inlineTextBox); |
| 208 textPainter.paint(selectionStart, selectionEnd, length, selectionStyle,
cachedTextBlob); |
| 201 } | 209 } |
| 202 | 210 |
| 203 // Paint decorations | 211 // Paint decorations |
| 204 TextDecoration textDecorations = styleToUse->textDecorationsInEffect(); | 212 TextDecoration textDecorations = styleToUse->textDecorationsInEffect(); |
| 205 if (textDecorations != TextDecorationNone && !paintSelectedTextOnly) { | 213 if (textDecorations != TextDecorationNone && !paintSelectedTextOnly) { |
| 206 GraphicsContextStateSaver stateSaver(*context, false); | 214 GraphicsContextStateSaver stateSaver(*context, false); |
| 207 TextPainter::updateGraphicsContext(context, textStyle, m_inlineTextBox.i
sHorizontal(), stateSaver); | 215 TextPainter::updateGraphicsContext(context, textStyle, m_inlineTextBox.i
sHorizontal(), stateSaver); |
| 208 if (combinedText) | 216 if (combinedText) |
| 209 | 217 |
| 210 context->concatCTM(InlineTextBox::rotation(boxRect, InlineTextBox::C
lockwise)); | 218 context->concatCTM(InlineTextBox::rotation(boxRect, InlineTextBox::C
lockwise)); |
| (...skipping 572 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 783 RenderTheme::theme().platformActiveTextSearchHighlightColor() : | 791 RenderTheme::theme().platformActiveTextSearchHighlightColor() : |
| 784 RenderTheme::theme().platformInactiveTextSearchHighlightColor(); | 792 RenderTheme::theme().platformInactiveTextSearchHighlightColor(); |
| 785 GraphicsContextStateSaver stateSaver(*pt); | 793 GraphicsContextStateSaver stateSaver(*pt); |
| 786 pt->clip(FloatRect(boxOrigin.x(), boxOrigin.y() - deltaY, m_inlineTextBo
x.logicalWidth(), selHeight)); | 794 pt->clip(FloatRect(boxOrigin.x(), boxOrigin.y() - deltaY, m_inlineTextBo
x.logicalWidth(), selHeight)); |
| 787 pt->drawHighlightForText(font, run, FloatPoint(boxOrigin.x(), boxOrigin.
y() - deltaY), selHeight, color, sPos, ePos); | 795 pt->drawHighlightForText(font, run, FloatPoint(boxOrigin.x(), boxOrigin.
y() - deltaY), selHeight, color, sPos, ePos); |
| 788 } | 796 } |
| 789 } | 797 } |
| 790 | 798 |
| 791 | 799 |
| 792 } // namespace blink | 800 } // namespace blink |
| OLD | NEW |