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 15 matching lines...) Expand all Loading... |
26 static inline bool textShouldBePainted(RenderSVGInlineText& textRenderer) | 26 static inline bool textShouldBePainted(RenderSVGInlineText& textRenderer) |
27 { | 27 { |
28 // Font::pixelSize(), returns FontDescription::computedPixelSize(), which re
turns "int(x + 0.5)". | 28 // Font::pixelSize(), returns FontDescription::computedPixelSize(), which re
turns "int(x + 0.5)". |
29 // If the absolute font size on screen is below x=0.5, don't render anything
. | 29 // If the absolute font size on screen is below x=0.5, don't render anything
. |
30 return textRenderer.scaledFont().fontDescription().computedPixelSize(); | 30 return textRenderer.scaledFont().fontDescription().computedPixelSize(); |
31 } | 31 } |
32 | 32 |
33 bool SVGInlineTextBoxPainter::shouldPaintSelection() const | 33 bool SVGInlineTextBoxPainter::shouldPaintSelection() const |
34 { | 34 { |
35 bool isPrinting = m_svgInlineTextBox.renderer().document().printing(); | 35 bool isPrinting = m_svgInlineTextBox.renderer().document().printing(); |
36 return !isPrinting && m_svgInlineTextBox.selectionState() != RenderObject::S
electionNone; | 36 return !isPrinting && m_svgInlineTextBox.selectionState() != LayoutObject::S
electionNone; |
37 } | 37 } |
38 | 38 |
39 void SVGInlineTextBoxPainter::paint(const PaintInfo& paintInfo, const LayoutPoin
t& paintOffset) | 39 void SVGInlineTextBoxPainter::paint(const PaintInfo& paintInfo, const LayoutPoin
t& paintOffset) |
40 { | 40 { |
41 ASSERT(paintInfo.shouldPaintWithinRoot(&m_svgInlineTextBox.renderer())); | 41 ASSERT(paintInfo.shouldPaintWithinRoot(&m_svgInlineTextBox.renderer())); |
42 ASSERT(paintInfo.phase == PaintPhaseForeground || paintInfo.phase == PaintPh
aseSelection); | 42 ASSERT(paintInfo.phase == PaintPhaseForeground || paintInfo.phase == PaintPh
aseSelection); |
43 ASSERT(m_svgInlineTextBox.truncation() == cNoTruncation); | 43 ASSERT(m_svgInlineTextBox.truncation() == cNoTruncation); |
44 | 44 |
45 if (m_svgInlineTextBox.renderer().style()->visibility() != VISIBLE) | 45 if (m_svgInlineTextBox.renderer().style()->visibility() != VISIBLE) |
46 return; | 46 return; |
47 | 47 |
48 // We're explicitly not supporting composition & custom underlines and custo
m highlighters -- unlike InlineTextBox. | 48 // We're explicitly not supporting composition & custom underlines and custo
m highlighters -- unlike InlineTextBox. |
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 LayoutObject& parentRenderer = m_svgInlineTextBox.parent()->renderer(); |
59 const RenderStyle& style = parentRenderer.styleRef(); | 59 const RenderStyle& style = parentRenderer.styleRef(); |
60 | 60 |
61 InlineTextBoxPainter(m_svgInlineTextBox).paintDocumentMarkers( | 61 InlineTextBoxPainter(m_svgInlineTextBox).paintDocumentMarkers( |
62 paintInfo.context, FloatPoint(paintOffset), style, | 62 paintInfo.context, FloatPoint(paintOffset), style, |
63 textRenderer.scaledFont(), true); | 63 textRenderer.scaledFont(), true); |
64 | 64 |
65 if (!m_svgInlineTextBox.textFragments().isEmpty()) { | 65 if (!m_svgInlineTextBox.textFragments().isEmpty()) { |
66 RenderDrawingRecorder recorder(paintInfo.context, m_svgInlineTextBox.ren
derer(), paintInfo.phase, paintInfo.rect); | 66 RenderDrawingRecorder recorder(paintInfo.context, m_svgInlineTextBox.ren
derer(), paintInfo.phase, paintInfo.rect); |
67 if (!recorder.canUseCachedDrawing()) | 67 if (!recorder.canUseCachedDrawing()) |
68 paintTextFragments(paintInfo, parentRenderer); | 68 paintTextFragments(paintInfo, parentRenderer); |
69 } | 69 } |
70 | 70 |
71 if (style.hasOutline() && parentRenderer.isRenderInline()) | 71 if (style.hasOutline() && parentRenderer.isRenderInline()) |
72 InlinePainter(toRenderInline(parentRenderer)).paintOutline(paintInfo, pa
intOffset); | 72 InlinePainter(toRenderInline(parentRenderer)).paintOutline(paintInfo, pa
intOffset); |
73 } | 73 } |
74 | 74 |
75 void SVGInlineTextBoxPainter::paintTextFragments(const PaintInfo& paintInfo, Ren
derObject& parentRenderer) | 75 void SVGInlineTextBoxPainter::paintTextFragments(const PaintInfo& paintInfo, Lay
outObject& parentRenderer) |
76 { | 76 { |
77 const RenderStyle& style = parentRenderer.styleRef(); | 77 const RenderStyle& style = parentRenderer.styleRef(); |
78 const SVGRenderStyle& svgStyle = style.svgStyle(); | 78 const SVGRenderStyle& svgStyle = style.svgStyle(); |
79 | 79 |
80 bool hasFill = svgStyle.hasFill(); | 80 bool hasFill = svgStyle.hasFill(); |
81 bool hasVisibleStroke = svgStyle.hasVisibleStroke(); | 81 bool hasVisibleStroke = svgStyle.hasVisibleStroke(); |
82 | 82 |
83 const RenderStyle* selectionStyle = &style; | 83 const RenderStyle* selectionStyle = &style; |
84 bool shouldPaintSelection = this->shouldPaintSelection(); | 84 bool shouldPaintSelection = this->shouldPaintSelection(); |
85 if (shouldPaintSelection) { | 85 if (shouldPaintSelection) { |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 GraphicsContextStateSaver stateSaver(*paintInfo.context); | 183 GraphicsContextStateSaver stateSaver(*paintInfo.context); |
184 fragment.buildFragmentTransform(fragmentTransform); | 184 fragment.buildFragmentTransform(fragmentTransform); |
185 if (!fragmentTransform.isIdentity()) | 185 if (!fragmentTransform.isIdentity()) |
186 paintInfo.context->concatCTM(fragmentTransform); | 186 paintInfo.context->concatCTM(fragmentTransform); |
187 | 187 |
188 paintInfo.context->setFillColor(backgroundColor); | 188 paintInfo.context->setFillColor(backgroundColor); |
189 paintInfo.context->fillRect(m_svgInlineTextBox.selectionRectForTextFragm
ent(fragment, fragmentStartPosition, fragmentEndPosition, style).toFloatRect(),
backgroundColor); | 189 paintInfo.context->fillRect(m_svgInlineTextBox.selectionRectForTextFragm
ent(fragment, fragmentStartPosition, fragmentEndPosition, style).toFloatRect(),
backgroundColor); |
190 } | 190 } |
191 } | 191 } |
192 | 192 |
193 static inline RenderObject* findRenderObjectDefininingTextDecoration(InlineFlowB
ox* parentBox) | 193 static inline LayoutObject* findLayoutObjectDefininingTextDecoration(InlineFlowB
ox* parentBox) |
194 { | 194 { |
195 // Lookup first render object in parent hierarchy which has text-decoration
set. | 195 // Lookup first render object in parent hierarchy which has text-decoration
set. |
196 RenderObject* renderer = 0; | 196 LayoutObject* renderer = 0; |
197 while (parentBox) { | 197 while (parentBox) { |
198 renderer = &parentBox->renderer(); | 198 renderer = &parentBox->renderer(); |
199 | 199 |
200 if (renderer->style() && renderer->style()->textDecoration() != TextDeco
rationNone) | 200 if (renderer->style() && renderer->style()->textDecoration() != TextDeco
rationNone) |
201 break; | 201 break; |
202 | 202 |
203 parentBox = parentBox->parent(); | 203 parentBox = parentBox->parent(); |
204 } | 204 } |
205 | 205 |
206 ASSERT(renderer); | 206 ASSERT(renderer); |
(...skipping 25 matching lines...) Expand all Loading... |
232 | 232 |
233 void SVGInlineTextBoxPainter::paintDecoration(const PaintInfo& paintInfo, TextDe
coration decoration, const SVGTextFragment& fragment) | 233 void SVGInlineTextBoxPainter::paintDecoration(const PaintInfo& paintInfo, TextDe
coration decoration, const SVGTextFragment& fragment) |
234 { | 234 { |
235 if (m_svgInlineTextBox.renderer().style()->textDecorationsInEffect() == Text
DecorationNone) | 235 if (m_svgInlineTextBox.renderer().style()->textDecorationsInEffect() == Text
DecorationNone) |
236 return; | 236 return; |
237 | 237 |
238 if (fragment.width <= 0) | 238 if (fragment.width <= 0) |
239 return; | 239 return; |
240 | 240 |
241 // Find out which render style defined the text-decoration, as its fill/stro
ke properties have to be used for drawing instead of ours. | 241 // Find out which render style defined the text-decoration, as its fill/stro
ke properties have to be used for drawing instead of ours. |
242 RenderObject* decorationRenderer = findRenderObjectDefininingTextDecoration(
m_svgInlineTextBox.parent()); | 242 LayoutObject* decorationRenderer = findLayoutObjectDefininingTextDecoration(
m_svgInlineTextBox.parent()); |
243 const RenderStyle& decorationStyle = decorationRenderer->styleRef(); | 243 const RenderStyle& decorationStyle = decorationRenderer->styleRef(); |
244 | 244 |
245 if (decorationStyle.visibility() == HIDDEN) | 245 if (decorationStyle.visibility() == HIDDEN) |
246 return; | 246 return; |
247 | 247 |
248 float scalingFactor = 1; | 248 float scalingFactor = 1; |
249 Font scaledFont; | 249 Font scaledFont; |
250 RenderSVGInlineText::computeNewScaledFontForStyle(decorationRenderer, &decor
ationStyle, scalingFactor, scaledFont); | 250 RenderSVGInlineText::computeNewScaledFontForStyle(decorationRenderer, &decor
ationStyle, scalingFactor, scaledFont); |
251 ASSERT(scalingFactor); | 251 ASSERT(scalingFactor); |
252 | 252 |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
439 | 439 |
440 fragmentRect = fragmentTransform.mapRect(fragmentRect); | 440 fragmentRect = fragmentTransform.mapRect(fragmentRect); |
441 markerRect.unite(fragmentRect); | 441 markerRect.unite(fragmentRect); |
442 } | 442 } |
443 } | 443 } |
444 | 444 |
445 toRenderedDocumentMarker(marker)->setRenderedRect(textRenderer.localToAbsolu
teQuad(markerRect).enclosingBoundingBox()); | 445 toRenderedDocumentMarker(marker)->setRenderedRect(textRenderer.localToAbsolu
teQuad(markerRect).enclosingBoundingBox()); |
446 } | 446 } |
447 | 447 |
448 } // namespace blink | 448 } // namespace blink |
OLD | NEW |