| 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/SVGInlineTextBoxPainter.h" | 5 #include "core/paint/SVGInlineTextBoxPainter.h" |
| 6 | 6 |
| 7 #include "core/editing/Editor.h" | 7 #include "core/editing/Editor.h" |
| 8 #include "core/editing/markers/DocumentMarkerController.h" | 8 #include "core/editing/markers/DocumentMarkerController.h" |
| 9 #include "core/editing/markers/RenderedDocumentMarker.h" | 9 #include "core/editing/markers/RenderedDocumentMarker.h" |
| 10 #include "core/frame/LocalFrame.h" | 10 #include "core/frame/LocalFrame.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 // Font::pixelSize(), returns FontDescription::computedPixelSize(), which re
turns "int(x + 0.5)". | 31 // Font::pixelSize(), returns FontDescription::computedPixelSize(), which re
turns "int(x + 0.5)". |
| 32 // If the absolute font size on screen is below x=0.5, don't render anything
. | 32 // If the absolute font size on screen is below x=0.5, don't render anything
. |
| 33 return textLayoutObject.scaledFont().getFontDescription().computedPixelSize(
); | 33 return textLayoutObject.scaledFont().getFontDescription().computedPixelSize(
); |
| 34 } | 34 } |
| 35 | 35 |
| 36 bool SVGInlineTextBoxPainter::shouldPaintSelection(const PaintInfo& paintInfo) c
onst | 36 bool SVGInlineTextBoxPainter::shouldPaintSelection(const PaintInfo& paintInfo) c
onst |
| 37 { | 37 { |
| 38 return !paintInfo.isPrinting() && m_svgInlineTextBox.getSelectionState() !=
SelectionNone; | 38 return !paintInfo.isPrinting() && m_svgInlineTextBox.getSelectionState() !=
SelectionNone; |
| 39 } | 39 } |
| 40 | 40 |
| 41 static bool hasShadow(const PaintInfo& paintInfo, const ComputedStyle& style) |
| 42 { |
| 43 // Text shadows are disabled when printing. http://crbug.com/258321 |
| 44 return style.textShadow() && !paintInfo.isPrinting(); |
| 45 } |
| 46 |
| 41 FloatRect SVGInlineTextBoxPainter::boundsForDrawingRecorder( | 47 FloatRect SVGInlineTextBoxPainter::boundsForDrawingRecorder( |
| 42 const LayoutPoint& paintOffset, bool includeSelectionRect) const | 48 const PaintInfo& paintInfo, const ComputedStyle& style, const LayoutPoint& p
aintOffset, bool includeSelectionRect) const |
| 43 { | 49 { |
| 44 // We compute the paint rect with what looks like the logical values, to mat
ch the | 50 // We compute the paint rect with what looks like the logical values, to mat
ch the |
| 45 // computation in SVGInlineTextBox::calculateBoundaries, and the fact that v
ertical (etc) | 51 // computation in SVGInlineTextBox::calculateBoundaries, and the fact that v
ertical (etc) |
| 46 // layouts are handled by SVGTextLayoutEngine. | 52 // layouts are handled by SVGTextLayoutEngine. |
| 47 LayoutRect bounds( | 53 LayoutRect bounds( |
| 48 LayoutPoint(m_svgInlineTextBox.topLeft() + paintOffset), | 54 LayoutPoint(m_svgInlineTextBox.topLeft() + paintOffset), |
| 49 LayoutSize(m_svgInlineTextBox.logicalWidth(), m_svgInlineTextBox.logical
Height())); | 55 LayoutSize(m_svgInlineTextBox.logicalWidth(), m_svgInlineTextBox.logical
Height())); |
| 56 if (hasShadow(paintInfo, style)) |
| 57 bounds.expand(style.textShadow()->rectOutsetsIncludingOriginal()); |
| 50 if (includeSelectionRect) { | 58 if (includeSelectionRect) { |
| 51 bounds.unite(m_svgInlineTextBox.localSelectionRect( | 59 bounds.unite(m_svgInlineTextBox.localSelectionRect( |
| 52 m_svgInlineTextBox.start(), m_svgInlineTextBox.start() + m_svgInline
TextBox.len())); | 60 m_svgInlineTextBox.start(), m_svgInlineTextBox.start() + m_svgInline
TextBox.len())); |
| 53 } | 61 } |
| 54 return FloatRect(bounds); | 62 return FloatRect(bounds); |
| 55 } | 63 } |
| 56 | 64 |
| 57 void SVGInlineTextBoxPainter::paint(const PaintInfo& paintInfo, const LayoutPoin
t& paintOffset) | 65 void SVGInlineTextBoxPainter::paint(const PaintInfo& paintInfo, const LayoutPoin
t& paintOffset) |
| 58 { | 66 { |
| 59 ASSERT(paintInfo.phase == PaintPhaseForeground || paintInfo.phase == PaintPh
aseSelection); | 67 ASSERT(paintInfo.phase == PaintPhaseForeground || paintInfo.phase == PaintPh
aseSelection); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 74 return; | 82 return; |
| 75 | 83 |
| 76 DisplayItem::Type displayItemType = DisplayItem::paintPhaseToDrawingType(pai
ntInfo.phase); | 84 DisplayItem::Type displayItemType = DisplayItem::paintPhaseToDrawingType(pai
ntInfo.phase); |
| 77 if (!DrawingRecorder::useCachedDrawingIfPossible(paintInfo.context, m_svgInl
ineTextBox, displayItemType)) { | 85 if (!DrawingRecorder::useCachedDrawingIfPossible(paintInfo.context, m_svgInl
ineTextBox, displayItemType)) { |
| 78 LayoutObject& parentLayoutObject = *LineLayoutAPIShim::layoutObjectFrom(
m_svgInlineTextBox.parent()->getLineLayoutItem()); | 86 LayoutObject& parentLayoutObject = *LineLayoutAPIShim::layoutObjectFrom(
m_svgInlineTextBox.parent()->getLineLayoutItem()); |
| 79 const ComputedStyle& style = parentLayoutObject.styleRef(); | 87 const ComputedStyle& style = parentLayoutObject.styleRef(); |
| 80 | 88 |
| 81 bool includeSelectionRect = paintInfo.phase != PaintPhaseSelection | 89 bool includeSelectionRect = paintInfo.phase != PaintPhaseSelection |
| 82 && (haveSelection || InlineTextBoxPainter::paintsMarkerHighlights(te
xtLayoutObject)); | 90 && (haveSelection || InlineTextBoxPainter::paintsMarkerHighlights(te
xtLayoutObject)); |
| 83 DrawingRecorder recorder(paintInfo.context, m_svgInlineTextBox, displayI
temType, | 91 DrawingRecorder recorder(paintInfo.context, m_svgInlineTextBox, displayI
temType, |
| 84 boundsForDrawingRecorder(paintOffset, includeSelectionRect)); | 92 boundsForDrawingRecorder(paintInfo, style, paintOffset, includeSelec
tionRect)); |
| 85 InlineTextBoxPainter(m_svgInlineTextBox).paintDocumentMarkers( | 93 InlineTextBoxPainter(m_svgInlineTextBox).paintDocumentMarkers( |
| 86 paintInfo, paintOffset, style, | 94 paintInfo, paintOffset, style, |
| 87 textLayoutObject.scaledFont(), DocumentMarkerPaintPhase::Background)
; | 95 textLayoutObject.scaledFont(), DocumentMarkerPaintPhase::Background)
; |
| 88 | 96 |
| 89 if (!m_svgInlineTextBox.textFragments().isEmpty()) | 97 if (!m_svgInlineTextBox.textFragments().isEmpty()) |
| 90 paintTextFragments(paintInfo, parentLayoutObject); | 98 paintTextFragments(paintInfo, parentLayoutObject); |
| 91 | 99 |
| 92 InlineTextBoxPainter(m_svgInlineTextBox).paintDocumentMarkers( | 100 InlineTextBoxPainter(m_svgInlineTextBox).paintDocumentMarkers( |
| 93 paintInfo, paintOffset, style, | 101 paintInfo, paintOffset, style, |
| 94 textLayoutObject.scaledFont(), DocumentMarkerPaintPhase::Foreground)
; | 102 textLayoutObject.scaledFont(), DocumentMarkerPaintPhase::Foreground)
; |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 } | 315 } |
| 308 | 316 |
| 309 bool SVGInlineTextBoxPainter::setupTextPaint(const PaintInfo& paintInfo, const C
omputedStyle& style, | 317 bool SVGInlineTextBoxPainter::setupTextPaint(const PaintInfo& paintInfo, const C
omputedStyle& style, |
| 310 LayoutSVGResourceMode resourceMode, SkPaint& paint) | 318 LayoutSVGResourceMode resourceMode, SkPaint& paint) |
| 311 { | 319 { |
| 312 LayoutSVGInlineText& textLayoutObject = toLayoutSVGInlineText(*LineLayoutAPI
Shim::layoutObjectFrom(m_svgInlineTextBox.getLineLayoutItem())); | 320 LayoutSVGInlineText& textLayoutObject = toLayoutSVGInlineText(*LineLayoutAPI
Shim::layoutObjectFrom(m_svgInlineTextBox.getLineLayoutItem())); |
| 313 | 321 |
| 314 float scalingFactor = textLayoutObject.scalingFactor(); | 322 float scalingFactor = textLayoutObject.scalingFactor(); |
| 315 ASSERT(scalingFactor); | 323 ASSERT(scalingFactor); |
| 316 | 324 |
| 317 const ShadowList* shadowList = style.textShadow(); | |
| 318 | |
| 319 // Text shadows are disabled when printing. http://crbug.com/258321 | |
| 320 bool hasShadow = shadowList && !paintInfo.isPrinting(); | |
| 321 | |
| 322 AffineTransform paintServerTransform; | 325 AffineTransform paintServerTransform; |
| 323 const AffineTransform* additionalPaintServerTransform = 0; | 326 const AffineTransform* additionalPaintServerTransform = 0; |
| 324 | 327 |
| 325 if (scalingFactor != 1) { | 328 if (scalingFactor != 1) { |
| 326 // Adjust the paint-server coordinate space. | 329 // Adjust the paint-server coordinate space. |
| 327 paintServerTransform.scale(scalingFactor); | 330 paintServerTransform.scale(scalingFactor); |
| 328 additionalPaintServerTransform = &paintServerTransform; | 331 additionalPaintServerTransform = &paintServerTransform; |
| 329 } | 332 } |
| 330 | 333 |
| 331 if (!SVGPaintContext::paintForLayoutObject(paintInfo, style, *LineLayoutAPIS
him::layoutObjectFrom(m_svgInlineTextBox.parent()->getLineLayoutItem()), resourc
eMode, paint, additionalPaintServerTransform)) | 334 if (!SVGPaintContext::paintForLayoutObject(paintInfo, style, *LineLayoutAPIS
him::layoutObjectFrom(m_svgInlineTextBox.parent()->getLineLayoutItem()), resourc
eMode, paint, additionalPaintServerTransform)) |
| 332 return false; | 335 return false; |
| 333 paint.setAntiAlias(true); | 336 paint.setAntiAlias(true); |
| 334 | 337 |
| 335 if (hasShadow) { | 338 if (hasShadow(paintInfo, style)) { |
| 336 std::unique_ptr<DrawLooperBuilder> drawLooperBuilder = shadowList->creat
eDrawLooper(DrawLooperBuilder::ShadowRespectsAlpha, style.visitedDependentColor(
CSSPropertyColor)); | 339 std::unique_ptr<DrawLooperBuilder> drawLooperBuilder = style.textShadow(
)->createDrawLooper(DrawLooperBuilder::ShadowRespectsAlpha, style.visitedDepende
ntColor(CSSPropertyColor)); |
| 337 paint.setLooper(toSkSp(drawLooperBuilder->detachDrawLooper())); | 340 paint.setLooper(toSkSp(drawLooperBuilder->detachDrawLooper())); |
| 338 } | 341 } |
| 339 | 342 |
| 340 if (resourceMode == ApplyToStrokeMode) { | 343 if (resourceMode == ApplyToStrokeMode) { |
| 341 StrokeData strokeData; | 344 StrokeData strokeData; |
| 342 SVGLayoutSupport::applyStrokeStyleToStrokeData(strokeData, style, *LineL
ayoutAPIShim::layoutObjectFrom(m_svgInlineTextBox.parent()->getLineLayoutItem())
, 1); | 345 SVGLayoutSupport::applyStrokeStyleToStrokeData(strokeData, style, *LineL
ayoutAPIShim::layoutObjectFrom(m_svgInlineTextBox.parent()->getLineLayoutItem())
, 1); |
| 343 if (style.svgStyle().vectorEffect() != VE_NON_SCALING_STROKE) | 346 if (style.svgStyle().vectorEffect() != VE_NON_SCALING_STROKE) |
| 344 strokeData.setThickness(strokeData.thickness() * scalingFactor); | 347 strokeData.setThickness(strokeData.thickness() * scalingFactor); |
| 345 strokeData.setupPaint(&paint); | 348 strokeData.setupPaint(&paint); |
| 346 } | 349 } |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 515 stateSaver.save(); | 518 stateSaver.save(); |
| 516 paintInfo.context.concatCTM(fragment.buildFragmentTransform()); | 519 paintInfo.context.concatCTM(fragment.buildFragmentTransform()); |
| 517 } | 520 } |
| 518 FloatRect fragmentRect = m_svgInlineTextBox.selectionRectForTextFragment
(fragment, textMatchInfo.startPosition, textMatchInfo.endPosition, style); | 521 FloatRect fragmentRect = m_svgInlineTextBox.selectionRectForTextFragment
(fragment, textMatchInfo.startPosition, textMatchInfo.endPosition, style); |
| 519 paintInfo.context.setFillColor(color); | 522 paintInfo.context.setFillColor(color); |
| 520 paintInfo.context.fillRect(fragmentRect); | 523 paintInfo.context.fillRect(fragmentRect); |
| 521 } | 524 } |
| 522 } | 525 } |
| 523 | 526 |
| 524 } // namespace blink | 527 } // namespace blink |
| OLD | NEW |