| 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/SVGInlineTextBoxPainter.h" | 6 #include "core/paint/SVGInlineTextBoxPainter.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/Editor.h" | 10 #include "core/editing/Editor.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 // If we ever need that for SVG, it's very easy to refactor and reuse the co
de. | 49 // If we ever need that for SVG, it's very easy to refactor and reuse the co
de. |
| 50 | 50 |
| 51 if (paintInfo.phase == PaintPhaseSelection && !shouldPaintSelection()) | 51 if (paintInfo.phase == PaintPhaseSelection && !shouldPaintSelection()) |
| 52 return; | 52 return; |
| 53 | 53 |
| 54 RenderSVGInlineText& textRenderer = toRenderSVGInlineText(m_svgInlineTextBox
.renderer()); | 54 RenderSVGInlineText& textRenderer = toRenderSVGInlineText(m_svgInlineTextBox
.renderer()); |
| 55 if (!textShouldBePainted(textRenderer)) | 55 if (!textShouldBePainted(textRenderer)) |
| 56 return; | 56 return; |
| 57 | 57 |
| 58 RenderObject& parentRenderer = m_svgInlineTextBox.parent()->renderer(); | 58 RenderObject& parentRenderer = m_svgInlineTextBox.parent()->renderer(); |
| 59 RenderStyle* style = parentRenderer.style(); | 59 const RenderStyle* style = parentRenderer.style(); |
| 60 ASSERT(style); | 60 ASSERT(style); |
| 61 | 61 |
| 62 InlineTextBoxPainter(m_svgInlineTextBox).paintDocumentMarkers( | 62 InlineTextBoxPainter(m_svgInlineTextBox).paintDocumentMarkers( |
| 63 paintInfo.context, FloatPoint(paintOffset), style, | 63 paintInfo.context, FloatPoint(paintOffset), style, |
| 64 textRenderer.scaledFont(), true); | 64 textRenderer.scaledFont(), true); |
| 65 | 65 |
| 66 if (!m_svgInlineTextBox.textFragments().isEmpty()) { | 66 if (!m_svgInlineTextBox.textFragments().isEmpty()) { |
| 67 RenderDrawingRecorder recorder(paintInfo.context, m_svgInlineTextBox.ren
derer(), paintInfo.phase, paintInfo.rect); | 67 RenderDrawingRecorder recorder(paintInfo.context, m_svgInlineTextBox.ren
derer(), paintInfo.phase, paintInfo.rect); |
| 68 if (!recorder.canUseCachedDrawing()) | 68 if (!recorder.canUseCachedDrawing()) |
| 69 paintTextFragments(paintInfo, parentRenderer); | 69 paintTextFragments(paintInfo, parentRenderer); |
| 70 } | 70 } |
| 71 | 71 |
| 72 if (style->hasOutline() && parentRenderer.isRenderInline()) | 72 if (style->hasOutline() && parentRenderer.isRenderInline()) |
| 73 InlinePainter(toRenderInline(parentRenderer)).paintOutline(paintInfo, pa
intOffset); | 73 InlinePainter(toRenderInline(parentRenderer)).paintOutline(paintInfo, pa
intOffset); |
| 74 } | 74 } |
| 75 | 75 |
| 76 void SVGInlineTextBoxPainter::paintTextFragments(const PaintInfo& paintInfo, Ren
derObject& parentRenderer) | 76 void SVGInlineTextBoxPainter::paintTextFragments(const PaintInfo& paintInfo, Ren
derObject& parentRenderer) |
| 77 { | 77 { |
| 78 RenderStyle* style = parentRenderer.style(); | 78 const RenderStyle* style = parentRenderer.style(); |
| 79 const SVGRenderStyle& svgStyle = style->svgStyle(); | 79 const SVGRenderStyle& svgStyle = style->svgStyle(); |
| 80 | 80 |
| 81 bool hasFill = svgStyle.hasFill(); | 81 bool hasFill = svgStyle.hasFill(); |
| 82 bool hasVisibleStroke = svgStyle.hasVisibleStroke(); | 82 bool hasVisibleStroke = svgStyle.hasVisibleStroke(); |
| 83 | 83 |
| 84 RenderStyle* selectionStyle = style; | 84 const RenderStyle* selectionStyle = style; |
| 85 bool shouldPaintSelection = this->shouldPaintSelection(); | 85 bool shouldPaintSelection = this->shouldPaintSelection(); |
| 86 if (shouldPaintSelection) { | 86 if (shouldPaintSelection) { |
| 87 selectionStyle = parentRenderer.getCachedPseudoStyle(SELECTION); | 87 selectionStyle = parentRenderer.getCachedPseudoStyle(SELECTION); |
| 88 if (selectionStyle) { | 88 if (selectionStyle) { |
| 89 const SVGRenderStyle& svgSelectionStyle = selectionStyle->svgStyle()
; | 89 const SVGRenderStyle& svgSelectionStyle = selectionStyle->svgStyle()
; |
| 90 | 90 |
| 91 if (!hasFill) | 91 if (!hasFill) |
| 92 hasFill = svgSelectionStyle.hasFill(); | 92 hasFill = svgSelectionStyle.hasFill(); |
| 93 if (!hasVisibleStroke) | 93 if (!hasVisibleStroke) |
| 94 hasVisibleStroke = svgSelectionStyle.hasVisibleStroke(); | 94 hasVisibleStroke = svgSelectionStyle.hasVisibleStroke(); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 return; | 157 return; |
| 158 | 158 |
| 159 Color backgroundColor = m_svgInlineTextBox.renderer().selectionBackgroundCol
or(); | 159 Color backgroundColor = m_svgInlineTextBox.renderer().selectionBackgroundCol
or(); |
| 160 if (!backgroundColor.alpha()) | 160 if (!backgroundColor.alpha()) |
| 161 return; | 161 return; |
| 162 | 162 |
| 163 RenderSVGInlineText& textRenderer = toRenderSVGInlineText(m_svgInlineTextBox
.renderer()); | 163 RenderSVGInlineText& textRenderer = toRenderSVGInlineText(m_svgInlineTextBox
.renderer()); |
| 164 if (!textShouldBePainted(textRenderer)) | 164 if (!textShouldBePainted(textRenderer)) |
| 165 return; | 165 return; |
| 166 | 166 |
| 167 RenderStyle* style = m_svgInlineTextBox.parent()->renderer().style(); | 167 const RenderStyle* style = m_svgInlineTextBox.parent()->renderer().style(); |
| 168 ASSERT(style); | 168 ASSERT(style); |
| 169 | 169 |
| 170 int startPosition, endPosition; | 170 int startPosition, endPosition; |
| 171 m_svgInlineTextBox.selectionStartEnd(startPosition, endPosition); | 171 m_svgInlineTextBox.selectionStartEnd(startPosition, endPosition); |
| 172 | 172 |
| 173 int fragmentStartPosition = 0; | 173 int fragmentStartPosition = 0; |
| 174 int fragmentEndPosition = 0; | 174 int fragmentEndPosition = 0; |
| 175 AffineTransform fragmentTransform; | 175 AffineTransform fragmentTransform; |
| 176 unsigned textFragmentsSize = m_svgInlineTextBox.textFragments().size(); | 176 unsigned textFragmentsSize = m_svgInlineTextBox.textFragments().size(); |
| 177 for (unsigned i = 0; i < textFragmentsSize; ++i) { | 177 for (unsigned i = 0; i < textFragmentsSize; ++i) { |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 void SVGInlineTextBoxPainter::paintDecoration(const PaintInfo& paintInfo, TextDe
coration decoration, const SVGTextFragment& fragment) | 235 void SVGInlineTextBoxPainter::paintDecoration(const PaintInfo& paintInfo, TextDe
coration decoration, const SVGTextFragment& fragment) |
| 236 { | 236 { |
| 237 if (m_svgInlineTextBox.renderer().style()->textDecorationsInEffect() == Text
DecorationNone) | 237 if (m_svgInlineTextBox.renderer().style()->textDecorationsInEffect() == Text
DecorationNone) |
| 238 return; | 238 return; |
| 239 | 239 |
| 240 if (fragment.width <= 0) | 240 if (fragment.width <= 0) |
| 241 return; | 241 return; |
| 242 | 242 |
| 243 // Find out which render style defined the text-decoration, as its fill/stro
ke properties have to be used for drawing instead of ours. | 243 // Find out which render style defined the text-decoration, as its fill/stro
ke properties have to be used for drawing instead of ours. |
| 244 RenderObject* decorationRenderer = findRenderObjectDefininingTextDecoration(
m_svgInlineTextBox.parent()); | 244 RenderObject* decorationRenderer = findRenderObjectDefininingTextDecoration(
m_svgInlineTextBox.parent()); |
| 245 RenderStyle* decorationStyle = decorationRenderer->style(); | 245 const RenderStyle* decorationStyle = decorationRenderer->style(); |
| 246 ASSERT(decorationStyle); | 246 ASSERT(decorationStyle); |
| 247 | 247 |
| 248 if (decorationStyle->visibility() == HIDDEN) | 248 if (decorationStyle->visibility() == HIDDEN) |
| 249 return; | 249 return; |
| 250 | 250 |
| 251 float scalingFactor = 1; | 251 float scalingFactor = 1; |
| 252 Font scaledFont; | 252 Font scaledFont; |
| 253 RenderSVGInlineText::computeNewScaledFontForStyle(decorationRenderer, decora
tionStyle, scalingFactor, scaledFont); | 253 RenderSVGInlineText::computeNewScaledFontForStyle(decorationRenderer, decora
tionStyle, scalingFactor, scaledFont); |
| 254 ASSERT(scalingFactor); | 254 ASSERT(scalingFactor); |
| 255 | 255 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 285 } | 285 } |
| 286 break; | 286 break; |
| 287 case PT_MARKERS: | 287 case PT_MARKERS: |
| 288 break; | 288 break; |
| 289 default: | 289 default: |
| 290 ASSERT_NOT_REACHED(); | 290 ASSERT_NOT_REACHED(); |
| 291 } | 291 } |
| 292 } | 292 } |
| 293 } | 293 } |
| 294 | 294 |
| 295 void SVGInlineTextBoxPainter::paintTextWithShadows(const PaintInfo& paintInfo, R
enderStyle* style, | 295 void SVGInlineTextBoxPainter::paintTextWithShadows(const PaintInfo& paintInfo, c
onst RenderStyle* style, |
| 296 TextRun& textRun, const SVGTextFragment& fragment, int startPosition, int en
dPosition, | 296 TextRun& textRun, const SVGTextFragment& fragment, int startPosition, int en
dPosition, |
| 297 RenderSVGResourceMode resourceMode) | 297 RenderSVGResourceMode resourceMode) |
| 298 { | 298 { |
| 299 RenderSVGInlineText& textRenderer = toRenderSVGInlineText(m_svgInlineTextBox
.renderer()); | 299 RenderSVGInlineText& textRenderer = toRenderSVGInlineText(m_svgInlineTextBox
.renderer()); |
| 300 | 300 |
| 301 float scalingFactor = textRenderer.scalingFactor(); | 301 float scalingFactor = textRenderer.scalingFactor(); |
| 302 ASSERT(scalingFactor); | 302 ASSERT(scalingFactor); |
| 303 | 303 |
| 304 const Font& scaledFont = textRenderer.scaledFont(); | 304 const Font& scaledFont = textRenderer.scaledFont(); |
| 305 const ShadowList* shadowList = style->textShadow(); | 305 const ShadowList* shadowList = style->textShadow(); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 textRunPaintInfo.from = startPosition; | 343 textRunPaintInfo.from = startPosition; |
| 344 textRunPaintInfo.to = endPosition; | 344 textRunPaintInfo.to = endPosition; |
| 345 | 345 |
| 346 float baseline = scaledFont.fontMetrics().floatAscent(); | 346 float baseline = scaledFont.fontMetrics().floatAscent(); |
| 347 textRunPaintInfo.bounds = FloatRect(textOrigin.x(), textOrigin.y() - baselin
e, | 347 textRunPaintInfo.bounds = FloatRect(textOrigin.x(), textOrigin.y() - baselin
e, |
| 348 textSize.width(), textSize.height()); | 348 textSize.width(), textSize.height()); |
| 349 | 349 |
| 350 scaledFont.drawText(context, textRunPaintInfo, textOrigin); | 350 scaledFont.drawText(context, textRunPaintInfo, textOrigin); |
| 351 } | 351 } |
| 352 | 352 |
| 353 void SVGInlineTextBoxPainter::paintText(const PaintInfo& paintInfo, RenderStyle*
style, | 353 void SVGInlineTextBoxPainter::paintText(const PaintInfo& paintInfo, const Render
Style* style, |
| 354 RenderStyle* selectionStyle, const SVGTextFragment& fragment, | 354 const RenderStyle* selectionStyle, const SVGTextFragment& fragment, |
| 355 RenderSVGResourceMode resourceMode, bool shouldPaintSelection) | 355 RenderSVGResourceMode resourceMode, bool shouldPaintSelection) |
| 356 { | 356 { |
| 357 ASSERT(style); | 357 ASSERT(style); |
| 358 ASSERT(selectionStyle); | 358 ASSERT(selectionStyle); |
| 359 | 359 |
| 360 int startPosition = 0; | 360 int startPosition = 0; |
| 361 int endPosition = 0; | 361 int endPosition = 0; |
| 362 if (shouldPaintSelection) { | 362 if (shouldPaintSelection) { |
| 363 m_svgInlineTextBox.selectionStartEnd(startPosition, endPosition); | 363 m_svgInlineTextBox.selectionStartEnd(startPosition, endPosition); |
| 364 shouldPaintSelection = m_svgInlineTextBox.mapStartEndPositionsIntoFragme
ntCoordinates(fragment, startPosition, endPosition); | 364 shouldPaintSelection = m_svgInlineTextBox.mapStartEndPositionsIntoFragme
ntCoordinates(fragment, startPosition, endPosition); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 389 StyleDifference diff; | 389 StyleDifference diff; |
| 390 diff.setNeedsPaintInvalidationObject(); | 390 diff.setNeedsPaintInvalidationObject(); |
| 391 SVGResourcesCache::clientStyleChanged(&m_svgInlineTextBox.parent()->rend
erer(), diff, style); | 391 SVGResourcesCache::clientStyleChanged(&m_svgInlineTextBox.parent()->rend
erer(), diff, style); |
| 392 } | 392 } |
| 393 | 393 |
| 394 // Eventually draw text using regular style from the end position of the sel
ection to the end of the current chunk part | 394 // Eventually draw text using regular style from the end position of the sel
ection to the end of the current chunk part |
| 395 if (endPosition < static_cast<int>(fragment.length) && !paintSelectedTextOnl
y) | 395 if (endPosition < static_cast<int>(fragment.length) && !paintSelectedTextOnl
y) |
| 396 paintTextWithShadows(paintInfo, style, textRun, fragment, endPosition, f
ragment.length, resourceMode); | 396 paintTextWithShadows(paintInfo, style, textRun, fragment, endPosition, f
ragment.length, resourceMode); |
| 397 } | 397 } |
| 398 | 398 |
| 399 void SVGInlineTextBoxPainter::paintTextMatchMarker(GraphicsContext* context, con
st FloatPoint&, DocumentMarker* marker, RenderStyle* style, const Font& font) | 399 void SVGInlineTextBoxPainter::paintTextMatchMarker(GraphicsContext* context, con
st FloatPoint&, DocumentMarker* marker, const RenderStyle* style, const Font& fo
nt) |
| 400 { | 400 { |
| 401 // SVG is only interested in the TextMatch markers. | 401 // SVG is only interested in the TextMatch markers. |
| 402 if (marker->type() != DocumentMarker::TextMatch) | 402 if (marker->type() != DocumentMarker::TextMatch) |
| 403 return; | 403 return; |
| 404 | 404 |
| 405 RenderSVGInlineText& textRenderer = toRenderSVGInlineText(m_svgInlineTextBox
.renderer()); | 405 RenderSVGInlineText& textRenderer = toRenderSVGInlineText(m_svgInlineTextBox
.renderer()); |
| 406 | 406 |
| 407 FloatRect markerRect; | 407 FloatRect markerRect; |
| 408 AffineTransform fragmentTransform; | 408 AffineTransform fragmentTransform; |
| 409 for (InlineTextBox* box = textRenderer.firstTextBox(); box; box = box->nextT
extBox()) { | 409 for (InlineTextBox* box = textRenderer.firstTextBox(); box; box = box->nextT
extBox()) { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 | 445 |
| 446 fragmentRect = fragmentTransform.mapRect(fragmentRect); | 446 fragmentRect = fragmentTransform.mapRect(fragmentRect); |
| 447 markerRect.unite(fragmentRect); | 447 markerRect.unite(fragmentRect); |
| 448 } | 448 } |
| 449 } | 449 } |
| 450 | 450 |
| 451 toRenderedDocumentMarker(marker)->setRenderedRect(textRenderer.localToAbsolu
teQuad(markerRect).enclosingBoundingBox()); | 451 toRenderedDocumentMarker(marker)->setRenderedRect(textRenderer.localToAbsolu
teQuad(markerRect).enclosingBoundingBox()); |
| 452 } | 452 } |
| 453 | 453 |
| 454 } // namespace blink | 454 } // namespace blink |
| OLD | NEW |