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 13 matching lines...) Expand all Loading... |
24 | 24 |
25 namespace blink { | 25 namespace blink { |
26 | 26 |
27 static inline bool textShouldBePainted(LayoutSVGInlineText& textLayoutObject) | 27 static inline bool textShouldBePainted(LayoutSVGInlineText& textLayoutObject) |
28 { | 28 { |
29 // Font::pixelSize(), returns FontDescription::computedPixelSize(), which re
turns "int(x + 0.5)". | 29 // Font::pixelSize(), returns FontDescription::computedPixelSize(), which re
turns "int(x + 0.5)". |
30 // If the absolute font size on screen is below x=0.5, don't render anything
. | 30 // If the absolute font size on screen is below x=0.5, don't render anything
. |
31 return textLayoutObject.scaledFont().fontDescription().computedPixelSize(); | 31 return textLayoutObject.scaledFont().fontDescription().computedPixelSize(); |
32 } | 32 } |
33 | 33 |
34 bool SVGInlineTextBoxPainter::shouldPaintSelection() const | 34 bool SVGInlineTextBoxPainter::shouldPaintSelection(const PaintInfo& paintInfo) c
onst |
35 { | 35 { |
36 bool isPrinting = m_svgInlineTextBox.layoutObject().document().printing(); | 36 return !paintInfo.isPrinting() && m_svgInlineTextBox.selectionState() != Lay
outObject::SelectionNone; |
37 return !isPrinting && m_svgInlineTextBox.selectionState() != LayoutObject::S
electionNone; | |
38 } | 37 } |
39 | 38 |
40 void SVGInlineTextBoxPainter::paint(const PaintInfo& paintInfo, const LayoutPoin
t& paintOffset) | 39 void SVGInlineTextBoxPainter::paint(const PaintInfo& paintInfo, const LayoutPoin
t& paintOffset) |
41 { | 40 { |
42 ASSERT(paintInfo.shouldPaintWithinRoot(&m_svgInlineTextBox.layoutObject())); | 41 ASSERT(paintInfo.shouldPaintWithinRoot(&m_svgInlineTextBox.layoutObject())); |
43 ASSERT(paintInfo.phase == PaintPhaseForeground || paintInfo.phase == PaintPh
aseSelection); | 42 ASSERT(paintInfo.phase == PaintPhaseForeground || paintInfo.phase == PaintPh
aseSelection); |
44 ASSERT(m_svgInlineTextBox.truncation() == cNoTruncation); | 43 ASSERT(m_svgInlineTextBox.truncation() == cNoTruncation); |
45 | 44 |
46 if (m_svgInlineTextBox.layoutObject().style()->visibility() != VISIBLE) | 45 if (m_svgInlineTextBox.layoutObject().style()->visibility() != VISIBLE) |
47 return; | 46 return; |
48 | 47 |
49 // 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. |
50 // 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. |
51 | 50 |
52 if (paintInfo.phase == PaintPhaseSelection && !shouldPaintSelection()) | 51 if (paintInfo.phase == PaintPhaseSelection && !shouldPaintSelection(paintInf
o)) |
53 return; | 52 return; |
54 | 53 |
55 LayoutSVGInlineText& textLayoutObject = toLayoutSVGInlineText(m_svgInlineTex
tBox.layoutObject()); | 54 LayoutSVGInlineText& textLayoutObject = toLayoutSVGInlineText(m_svgInlineTex
tBox.layoutObject()); |
56 if (!textShouldBePainted(textLayoutObject)) | 55 if (!textShouldBePainted(textLayoutObject)) |
57 return; | 56 return; |
58 | 57 |
59 DisplayItem::Type displayItemType = DisplayItem::paintPhaseToDrawingType(pai
ntInfo.phase); | 58 DisplayItem::Type displayItemType = DisplayItem::paintPhaseToDrawingType(pai
ntInfo.phase); |
60 if (!DrawingRecorder::useCachedDrawingIfPossible(*paintInfo.context, m_svgIn
lineTextBox, displayItemType)) { | 59 if (!DrawingRecorder::useCachedDrawingIfPossible(*paintInfo.context, m_svgIn
lineTextBox, displayItemType)) { |
61 LayoutObject& parentLayoutObject = m_svgInlineTextBox.parent()->layoutOb
ject(); | 60 LayoutObject& parentLayoutObject = m_svgInlineTextBox.parent()->layoutOb
ject(); |
62 const ComputedStyle& style = parentLayoutObject.styleRef(); | 61 const ComputedStyle& style = parentLayoutObject.styleRef(); |
(...skipping 10 matching lines...) Expand all Loading... |
73 | 72 |
74 void SVGInlineTextBoxPainter::paintTextFragments(const PaintInfo& paintInfo, Lay
outObject& parentLayoutObject) | 73 void SVGInlineTextBoxPainter::paintTextFragments(const PaintInfo& paintInfo, Lay
outObject& parentLayoutObject) |
75 { | 74 { |
76 const ComputedStyle& style = parentLayoutObject.styleRef(); | 75 const ComputedStyle& style = parentLayoutObject.styleRef(); |
77 const SVGComputedStyle& svgStyle = style.svgStyle(); | 76 const SVGComputedStyle& svgStyle = style.svgStyle(); |
78 | 77 |
79 bool hasFill = svgStyle.hasFill(); | 78 bool hasFill = svgStyle.hasFill(); |
80 bool hasVisibleStroke = svgStyle.hasVisibleStroke(); | 79 bool hasVisibleStroke = svgStyle.hasVisibleStroke(); |
81 | 80 |
82 const ComputedStyle* selectionStyle = &style; | 81 const ComputedStyle* selectionStyle = &style; |
83 bool shouldPaintSelection = this->shouldPaintSelection(); | 82 bool shouldPaintSelection = this->shouldPaintSelection(paintInfo); |
84 if (shouldPaintSelection) { | 83 if (shouldPaintSelection) { |
85 selectionStyle = parentLayoutObject.getCachedPseudoStyle(SELECTION); | 84 selectionStyle = parentLayoutObject.getCachedPseudoStyle(SELECTION); |
86 if (selectionStyle) { | 85 if (selectionStyle) { |
87 const SVGComputedStyle& svgSelectionStyle = selectionStyle->svgStyle
(); | 86 const SVGComputedStyle& svgSelectionStyle = selectionStyle->svgStyle
(); |
88 | 87 |
89 if (!hasFill) | 88 if (!hasFill) |
90 hasFill = svgSelectionStyle.hasFill(); | 89 hasFill = svgSelectionStyle.hasFill(); |
91 if (!hasVisibleStroke) | 90 if (!hasVisibleStroke) |
92 hasVisibleStroke = svgSelectionStyle.hasVisibleStroke(); | 91 hasVisibleStroke = svgSelectionStyle.hasVisibleStroke(); |
93 } else { | 92 } else { |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 if (decorations & TextDecorationLineThrough) | 141 if (decorations & TextDecorationLineThrough) |
143 paintDecoration(paintInfo, TextDecorationLineThrough, fragment); | 142 paintDecoration(paintInfo, TextDecorationLineThrough, fragment); |
144 } | 143 } |
145 } | 144 } |
146 | 145 |
147 void SVGInlineTextBoxPainter::paintSelectionBackground(const PaintInfo& paintInf
o) | 146 void SVGInlineTextBoxPainter::paintSelectionBackground(const PaintInfo& paintInf
o) |
148 { | 147 { |
149 if (m_svgInlineTextBox.layoutObject().style()->visibility() != VISIBLE) | 148 if (m_svgInlineTextBox.layoutObject().style()->visibility() != VISIBLE) |
150 return; | 149 return; |
151 | 150 |
152 ASSERT(!m_svgInlineTextBox.layoutObject().document().printing()); | 151 ASSERT(!paintInfo.isPrinting()); |
153 | 152 |
154 if (paintInfo.phase == PaintPhaseSelection || !shouldPaintSelection()) | 153 if (paintInfo.phase == PaintPhaseSelection || !shouldPaintSelection(paintInf
o)) |
155 return; | 154 return; |
156 | 155 |
157 Color backgroundColor = m_svgInlineTextBox.layoutObject().selectionBackgroun
dColor(); | 156 Color backgroundColor = m_svgInlineTextBox.layoutObject().selectionBackgroun
dColor(); |
158 if (!backgroundColor.alpha()) | 157 if (!backgroundColor.alpha()) |
159 return; | 158 return; |
160 | 159 |
161 LayoutSVGInlineText& textLayoutObject = toLayoutSVGInlineText(m_svgInlineTex
tBox.layoutObject()); | 160 LayoutSVGInlineText& textLayoutObject = toLayoutSVGInlineText(m_svgInlineTex
tBox.layoutObject()); |
162 if (!textShouldBePainted(textLayoutObject)) | 161 if (!textShouldBePainted(textLayoutObject)) |
163 return; | 162 return; |
164 | 163 |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 LayoutSVGInlineText& textLayoutObject = toLayoutSVGInlineText(m_svgInlineTex
tBox.layoutObject()); | 300 LayoutSVGInlineText& textLayoutObject = toLayoutSVGInlineText(m_svgInlineTex
tBox.layoutObject()); |
302 | 301 |
303 float scalingFactor = textLayoutObject.scalingFactor(); | 302 float scalingFactor = textLayoutObject.scalingFactor(); |
304 ASSERT(scalingFactor); | 303 ASSERT(scalingFactor); |
305 | 304 |
306 const Font& scaledFont = textLayoutObject.scaledFont(); | 305 const Font& scaledFont = textLayoutObject.scaledFont(); |
307 const ShadowList* shadowList = style.textShadow(); | 306 const ShadowList* shadowList = style.textShadow(); |
308 GraphicsContext* context = paintInfo.context; | 307 GraphicsContext* context = paintInfo.context; |
309 | 308 |
310 // Text shadows are disabled when printing. http://crbug.com/258321 | 309 // Text shadows are disabled when printing. http://crbug.com/258321 |
311 bool hasShadow = shadowList && !context->printing(); | 310 bool hasShadow = shadowList && !paintInfo.isPrinting(); |
312 | 311 |
313 FloatPoint textOrigin(fragment.x, fragment.y); | 312 FloatPoint textOrigin(fragment.x, fragment.y); |
314 FloatSize textSize(fragment.width, fragment.height); | 313 FloatSize textSize(fragment.width, fragment.height); |
315 AffineTransform paintServerTransform; | 314 AffineTransform paintServerTransform; |
316 const AffineTransform* additionalPaintServerTransform = 0; | 315 const AffineTransform* additionalPaintServerTransform = 0; |
317 | 316 |
318 GraphicsContextStateSaver stateSaver(*context, false); | 317 GraphicsContextStateSaver stateSaver(*context, false); |
319 if (scalingFactor != 1) { | 318 if (scalingFactor != 1) { |
320 textOrigin.scale(scalingFactor, scalingFactor); | 319 textOrigin.scale(scalingFactor, scalingFactor); |
321 textSize.scale(scalingFactor); | 320 textSize.scale(scalingFactor); |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
442 if (!fragmentTransform.isIdentity()) | 441 if (!fragmentTransform.isIdentity()) |
443 context->concatCTM(fragmentTransform); | 442 context->concatCTM(fragmentTransform); |
444 context->setFillColor(color); | 443 context->setFillColor(color); |
445 context->fillRect(fragmentRect, color); | 444 context->fillRect(fragmentRect, color); |
446 } | 445 } |
447 } | 446 } |
448 } | 447 } |
449 } | 448 } |
450 | 449 |
451 } // namespace blink | 450 } // namespace blink |
OLD | NEW |