OLD | NEW |
1 /** | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 * Copyright (C) 2007 Rob Buis <buis@kde.org> | 2 // Use of this source code is governed by a BSD-style license that can be |
3 * Copyright (C) 2007 Nikolas Zimmermann <zimmermann@kde.org> | 3 // found in the LICENSE file. |
4 * Copyright (C) Research In Motion Limited 2010. All rights reserved. | |
5 * | |
6 * This library is free software; you can redistribute it and/or | |
7 * modify it under the terms of the GNU Library General Public | |
8 * License as published by the Free Software Foundation; either | |
9 * version 2 of the License, or (at your option) any later version. | |
10 * | |
11 * This library is distributed in the hope that it will be useful, | |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 * Library General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU Library General Public License | |
17 * along with this library; see the file COPYING.LIB. If not, write to | |
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | |
19 * Boston, MA 02110-1301, USA. | |
20 */ | |
21 | 4 |
22 #include "config.h" | 5 #include "config.h" |
23 #include "core/rendering/svg/SVGInlineTextBox.h" | 6 #include "core/paint/SVGInlineTextBoxPainter.h" |
24 | 7 |
25 #include "core/dom/DocumentMarkerController.h" | 8 #include "core/dom/DocumentMarkerController.h" |
26 #include "core/dom/RenderedDocumentMarker.h" | 9 #include "core/dom/RenderedDocumentMarker.h" |
27 #include "core/editing/Editor.h" | 10 #include "core/editing/Editor.h" |
28 #include "core/frame/LocalFrame.h" | 11 #include "core/frame/LocalFrame.h" |
29 #include "core/paint/InlinePainter.h" | 12 #include "core/paint/InlinePainter.h" |
30 #include "core/paint/InlineTextBoxPainter.h" | 13 #include "core/paint/InlineTextBoxPainter.h" |
31 #include "core/rendering/HitTestResult.h" | |
32 #include "core/rendering/InlineFlowBox.h" | |
33 #include "core/rendering/PaintInfo.h" | 14 #include "core/rendering/PaintInfo.h" |
34 #include "core/rendering/PointerEventsHitRules.h" | |
35 #include "core/rendering/RenderInline.h" | 15 #include "core/rendering/RenderInline.h" |
36 #include "core/rendering/RenderTheme.h" | 16 #include "core/rendering/RenderTheme.h" |
37 #include "core/rendering/style/ShadowList.h" | 17 #include "core/rendering/style/ShadowList.h" |
38 #include "core/rendering/svg/RenderSVGInlineText.h" | 18 #include "core/rendering/svg/RenderSVGInlineText.h" |
39 #include "core/rendering/svg/RenderSVGResource.h" | 19 #include "core/rendering/svg/RenderSVGResource.h" |
40 #include "core/rendering/svg/RenderSVGResourceSolidColor.h" | 20 #include "core/rendering/svg/RenderSVGResourceSolidColor.h" |
| 21 #include "core/rendering/svg/SVGInlineTextBox.h" |
41 #include "core/rendering/svg/SVGRenderSupport.h" | 22 #include "core/rendering/svg/SVGRenderSupport.h" |
42 #include "core/rendering/svg/SVGResourcesCache.h" | 23 #include "core/rendering/svg/SVGResourcesCache.h" |
43 #include "core/rendering/svg/SVGTextRunRenderingContext.h" | |
44 #include "platform/FloatConversion.h" | |
45 #include "platform/fonts/FontCache.h" | |
46 #include "platform/graphics/GraphicsContextStateSaver.h" | |
47 | 24 |
48 namespace blink { | 25 namespace blink { |
49 | 26 |
50 struct ExpectedSVGInlineTextBoxSize : public InlineTextBox { | |
51 float float1; | |
52 uint32_t bitfields : 1; | |
53 Vector<SVGTextFragment> vector; | |
54 }; | |
55 | |
56 COMPILE_ASSERT(sizeof(SVGInlineTextBox) == sizeof(ExpectedSVGInlineTextBoxSize),
SVGInlineTextBox_is_not_of_expected_size); | |
57 | |
58 SVGInlineTextBox::SVGInlineTextBox(RenderObject& object) | |
59 : InlineTextBox(object) | |
60 , m_logicalHeight(0) | |
61 , m_startsNewTextChunk(false) | |
62 { | |
63 } | |
64 | |
65 void SVGInlineTextBox::dirtyLineBoxes() | |
66 { | |
67 InlineTextBox::dirtyLineBoxes(); | |
68 | |
69 // Clear the now stale text fragments | |
70 clearTextFragments(); | |
71 | |
72 // And clear any following text fragments as the text on which they | |
73 // depend may now no longer exist, or glyph positions may be wrong | |
74 InlineTextBox* nextBox = nextTextBox(); | |
75 if (nextBox) | |
76 nextBox->dirtyLineBoxes(); | |
77 } | |
78 | |
79 int SVGInlineTextBox::offsetForPosition(float, bool) const | |
80 { | |
81 // SVG doesn't use the standard offset <-> position selection system, as it'
s not suitable for SVGs complex needs. | |
82 // vertical text selection, inline boxes spanning multiple lines (contrary t
o HTML, etc.) | |
83 ASSERT_NOT_REACHED(); | |
84 return 0; | |
85 } | |
86 | |
87 int SVGInlineTextBox::offsetForPositionInFragment(const SVGTextFragment& fragmen
t, float position, bool includePartialGlyphs) const | |
88 { | |
89 RenderSVGInlineText& textRenderer = toRenderSVGInlineText(this->renderer()); | |
90 | |
91 float scalingFactor = textRenderer.scalingFactor(); | |
92 ASSERT(scalingFactor); | |
93 | |
94 RenderStyle* style = textRenderer.style(); | |
95 ASSERT(style); | |
96 | |
97 TextRun textRun = constructTextRun(style, fragment); | |
98 | |
99 // Eventually handle lengthAdjust="spacingAndGlyphs". | |
100 // FIXME: Handle vertical text. | |
101 AffineTransform fragmentTransform; | |
102 fragment.buildFragmentTransform(fragmentTransform); | |
103 if (!fragmentTransform.isIdentity()) | |
104 textRun.setHorizontalGlyphStretch(narrowPrecisionToFloat(fragmentTransfo
rm.xScale())); | |
105 | |
106 return fragment.characterOffset - start() + textRenderer.scaledFont().offset
ForPosition(textRun, position * scalingFactor, includePartialGlyphs); | |
107 } | |
108 | |
109 float SVGInlineTextBox::positionForOffset(int) const | |
110 { | |
111 // SVG doesn't use the offset <-> position selection system. | |
112 ASSERT_NOT_REACHED(); | |
113 return 0; | |
114 } | |
115 | |
116 FloatRect SVGInlineTextBox::selectionRectForTextFragment(const SVGTextFragment&
fragment, int startPosition, int endPosition, RenderStyle* style) | |
117 { | |
118 ASSERT(startPosition < endPosition); | |
119 ASSERT(style); | |
120 | |
121 FontCachePurgePreventer fontCachePurgePreventer; | |
122 | |
123 RenderSVGInlineText& textRenderer = toRenderSVGInlineText(this->renderer()); | |
124 | |
125 float scalingFactor = textRenderer.scalingFactor(); | |
126 ASSERT(scalingFactor); | |
127 | |
128 const Font& scaledFont = textRenderer.scaledFont(); | |
129 const FontMetrics& scaledFontMetrics = scaledFont.fontMetrics(); | |
130 FloatPoint textOrigin(fragment.x, fragment.y); | |
131 if (scalingFactor != 1) | |
132 textOrigin.scale(scalingFactor, scalingFactor); | |
133 | |
134 textOrigin.move(0, -scaledFontMetrics.floatAscent()); | |
135 | |
136 FloatRect selectionRect = scaledFont.selectionRectForText(constructTextRun(s
tyle, fragment), textOrigin, fragment.height * scalingFactor, startPosition, end
Position); | |
137 if (scalingFactor == 1) | |
138 return selectionRect; | |
139 | |
140 selectionRect.scale(1 / scalingFactor); | |
141 return selectionRect; | |
142 } | |
143 | |
144 LayoutRect SVGInlineTextBox::localSelectionRect(int startPosition, int endPositi
on) | |
145 { | |
146 int boxStart = start(); | |
147 startPosition = std::max(startPosition - boxStart, 0); | |
148 endPosition = std::min(endPosition - boxStart, static_cast<int>(len())); | |
149 if (startPosition >= endPosition) | |
150 return LayoutRect(); | |
151 | |
152 RenderStyle* style = renderer().style(); | |
153 ASSERT(style); | |
154 | |
155 AffineTransform fragmentTransform; | |
156 FloatRect selectionRect; | |
157 int fragmentStartPosition = 0; | |
158 int fragmentEndPosition = 0; | |
159 | |
160 unsigned textFragmentsSize = m_textFragments.size(); | |
161 for (unsigned i = 0; i < textFragmentsSize; ++i) { | |
162 const SVGTextFragment& fragment = m_textFragments.at(i); | |
163 | |
164 fragmentStartPosition = startPosition; | |
165 fragmentEndPosition = endPosition; | |
166 if (!mapStartEndPositionsIntoFragmentCoordinates(fragment, fragmentStart
Position, fragmentEndPosition)) | |
167 continue; | |
168 | |
169 FloatRect fragmentRect = selectionRectForTextFragment(fragment, fragment
StartPosition, fragmentEndPosition, style); | |
170 fragment.buildFragmentTransform(fragmentTransform); | |
171 fragmentRect = fragmentTransform.mapRect(fragmentRect); | |
172 | |
173 selectionRect.unite(fragmentRect); | |
174 } | |
175 | |
176 return enclosingIntRect(selectionRect); | |
177 } | |
178 | |
179 static inline bool textShouldBePainted(RenderSVGInlineText& textRenderer) | 27 static inline bool textShouldBePainted(RenderSVGInlineText& textRenderer) |
180 { | 28 { |
181 // 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)". |
182 // 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
. |
183 return textRenderer.scaledFont().fontDescription().computedPixelSize(); | 31 return textRenderer.scaledFont().fontDescription().computedPixelSize(); |
184 } | 32 } |
185 | 33 |
186 void SVGInlineTextBox::paintSelectionBackground(PaintInfo& paintInfo) | 34 void SVGInlineTextBoxPainter::paint(PaintInfo& paintInfo, const LayoutPoint& pai
ntOffset) |
187 { | 35 { |
188 ASSERT(paintInfo.shouldPaintWithinRoot(&renderer())); | 36 ASSERT(paintInfo.shouldPaintWithinRoot(&m_svgInlineTextBox.renderer())); |
189 ASSERT(paintInfo.phase == PaintPhaseForeground || paintInfo.phase == PaintPh
aseSelection); | 37 ASSERT(paintInfo.phase == PaintPhaseForeground || paintInfo.phase == PaintPh
aseSelection); |
190 ASSERT(truncation() == cNoTruncation); | 38 ASSERT(m_svgInlineTextBox.truncation() == cNoTruncation); |
191 | 39 |
192 if (renderer().style()->visibility() != VISIBLE) | 40 if (m_svgInlineTextBox.renderer().style()->visibility() != VISIBLE) |
193 return; | 41 return; |
194 | 42 |
195 RenderObject& parentRenderer = parent()->renderer(); | 43 // Note: We're explicitely not supporting composition & custom underlines an
d custom highlighters - unlike InlineTextBox. |
196 ASSERT(!parentRenderer.document().printing()); | 44 // If we ever need that for SVG, it's very easy to refactor and reuse the co
de. |
197 | 45 |
198 // Determine whether or not we're selected. | 46 RenderObject& parentRenderer = m_svgInlineTextBox.parent()->renderer(); |
| 47 |
199 bool paintSelectedTextOnly = paintInfo.phase == PaintPhaseSelection; | 48 bool paintSelectedTextOnly = paintInfo.phase == PaintPhaseSelection; |
200 bool hasSelection = selectionState() != RenderObject::SelectionNone; | 49 bool hasSelection = !parentRenderer.document().printing() && m_svgInlineText
Box.selectionState() != RenderObject::SelectionNone; |
201 if (!hasSelection || paintSelectedTextOnly) | 50 if (!hasSelection && paintSelectedTextOnly) |
202 return; | 51 return; |
203 | 52 |
204 Color backgroundColor = renderer().selectionBackgroundColor(); | 53 RenderSVGInlineText& textRenderer = toRenderSVGInlineText(m_svgInlineTextBox
.renderer()); |
205 if (!backgroundColor.alpha()) | |
206 return; | |
207 | |
208 RenderSVGInlineText& textRenderer = toRenderSVGInlineText(this->renderer()); | |
209 if (!textShouldBePainted(textRenderer)) | 54 if (!textShouldBePainted(textRenderer)) |
210 return; | 55 return; |
211 | 56 |
212 RenderStyle* style = parentRenderer.style(); | 57 RenderStyle* style = parentRenderer.style(); |
213 ASSERT(style); | 58 ASSERT(style); |
214 | 59 |
215 int startPosition, endPosition; | 60 InlineTextBoxPainter(m_svgInlineTextBox).paintDocumentMarkers(paintInfo.cont
ext, paintOffset, style, textRenderer.scaledFont(), true); |
216 selectionStartEnd(startPosition, endPosition); | |
217 | |
218 int fragmentStartPosition = 0; | |
219 int fragmentEndPosition = 0; | |
220 AffineTransform fragmentTransform; | |
221 unsigned textFragmentsSize = m_textFragments.size(); | |
222 for (unsigned i = 0; i < textFragmentsSize; ++i) { | |
223 SVGTextFragment& fragment = m_textFragments.at(i); | |
224 | |
225 fragmentStartPosition = startPosition; | |
226 fragmentEndPosition = endPosition; | |
227 if (!mapStartEndPositionsIntoFragmentCoordinates(fragment, fragmentStart
Position, fragmentEndPosition)) | |
228 continue; | |
229 | |
230 GraphicsContextStateSaver stateSaver(*paintInfo.context); | |
231 fragment.buildFragmentTransform(fragmentTransform); | |
232 if (!fragmentTransform.isIdentity()) | |
233 paintInfo.context->concatCTM(fragmentTransform); | |
234 | |
235 paintInfo.context->setFillColor(backgroundColor); | |
236 paintInfo.context->fillRect(selectionRectForTextFragment(fragment, fragm
entStartPosition, fragmentEndPosition, style), backgroundColor); | |
237 } | |
238 } | |
239 | |
240 void SVGInlineTextBox::paint(PaintInfo& paintInfo, const LayoutPoint& paintOffse
t, LayoutUnit, LayoutUnit) | |
241 { | |
242 ASSERT(paintInfo.shouldPaintWithinRoot(&renderer())); | |
243 ASSERT(paintInfo.phase == PaintPhaseForeground || paintInfo.phase == PaintPh
aseSelection); | |
244 ASSERT(truncation() == cNoTruncation); | |
245 | |
246 if (renderer().style()->visibility() != VISIBLE) | |
247 return; | |
248 | |
249 // Note: We're explicitely not supporting composition & custom underlines an
d custom highlighters - unlike InlineTextBox. | |
250 // If we ever need that for SVG, it's very easy to refactor and reuse the co
de. | |
251 | |
252 RenderObject& parentRenderer = parent()->renderer(); | |
253 | |
254 bool paintSelectedTextOnly = paintInfo.phase == PaintPhaseSelection; | |
255 bool hasSelection = !parentRenderer.document().printing() && selectionState(
) != RenderObject::SelectionNone; | |
256 if (!hasSelection && paintSelectedTextOnly) | |
257 return; | |
258 | |
259 RenderSVGInlineText& textRenderer = toRenderSVGInlineText(this->renderer()); | |
260 if (!textShouldBePainted(textRenderer)) | |
261 return; | |
262 | |
263 RenderStyle* style = parentRenderer.style(); | |
264 ASSERT(style); | |
265 | |
266 InlineTextBoxPainter(*this).paintDocumentMarkers(paintInfo.context, paintOff
set, style, textRenderer.scaledFont(), true); | |
267 | 61 |
268 const SVGRenderStyle& svgStyle = style->svgStyle(); | 62 const SVGRenderStyle& svgStyle = style->svgStyle(); |
269 | 63 |
270 bool hasFill = svgStyle.hasFill(); | 64 bool hasFill = svgStyle.hasFill(); |
271 bool hasVisibleStroke = svgStyle.hasVisibleStroke(); | 65 bool hasVisibleStroke = svgStyle.hasVisibleStroke(); |
272 | 66 |
273 RenderStyle* selectionStyle = style; | 67 RenderStyle* selectionStyle = style; |
274 if (hasSelection) { | 68 if (hasSelection) { |
275 selectionStyle = parentRenderer.getCachedPseudoStyle(SELECTION); | 69 selectionStyle = parentRenderer.getCachedPseudoStyle(SELECTION); |
276 if (selectionStyle) { | 70 if (selectionStyle) { |
277 const SVGRenderStyle& svgSelectionStyle = selectionStyle->svgStyle()
; | 71 const SVGRenderStyle& svgSelectionStyle = selectionStyle->svgStyle()
; |
278 | 72 |
279 if (!hasFill) | 73 if (!hasFill) |
280 hasFill = svgSelectionStyle.hasFill(); | 74 hasFill = svgSelectionStyle.hasFill(); |
281 if (!hasVisibleStroke) | 75 if (!hasVisibleStroke) |
282 hasVisibleStroke = svgSelectionStyle.hasVisibleStroke(); | 76 hasVisibleStroke = svgSelectionStyle.hasVisibleStroke(); |
283 } else { | 77 } else { |
284 selectionStyle = style; | 78 selectionStyle = style; |
285 } | 79 } |
286 } | 80 } |
287 | 81 |
288 if (SVGRenderSupport::isRenderingClipPathAsMaskImage(textRenderer)) { | 82 if (SVGRenderSupport::isRenderingClipPathAsMaskImage(textRenderer)) { |
289 hasFill = true; | 83 hasFill = true; |
290 hasVisibleStroke = false; | 84 hasVisibleStroke = false; |
291 } | 85 } |
292 | 86 |
293 AffineTransform fragmentTransform; | 87 AffineTransform fragmentTransform; |
294 unsigned textFragmentsSize = m_textFragments.size(); | 88 unsigned textFragmentsSize = m_svgInlineTextBox.textFragments().size(); |
295 for (unsigned i = 0; i < textFragmentsSize; ++i) { | 89 for (unsigned i = 0; i < textFragmentsSize; ++i) { |
296 SVGTextFragment& fragment = m_textFragments.at(i); | 90 SVGTextFragment& fragment = m_svgInlineTextBox.textFragments().at(i); |
297 | 91 |
298 GraphicsContextStateSaver stateSaver(*paintInfo.context, false); | 92 GraphicsContextStateSaver stateSaver(*paintInfo.context, false); |
299 fragment.buildFragmentTransform(fragmentTransform); | 93 fragment.buildFragmentTransform(fragmentTransform); |
300 if (!fragmentTransform.isIdentity()) { | 94 if (!fragmentTransform.isIdentity()) { |
301 stateSaver.save(); | 95 stateSaver.save(); |
302 paintInfo.context->concatCTM(fragmentTransform); | 96 paintInfo.context->concatCTM(fragmentTransform); |
303 } | 97 } |
304 | 98 |
305 // Spec: All text decorations except line-through should be drawn before
the text is filled and stroked; thus, the text is rendered on top of these deco
rations. | 99 // Spec: All text decorations except line-through should be drawn before
the text is filled and stroked; thus, the text is rendered on top of these deco
rations. |
306 unsigned decorations = style->textDecorationsInEffect(); | 100 unsigned decorations = style->textDecorationsInEffect(); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 } | 176 } |
383 | 177 |
384 void PaintingResourceScope::releasePaintingResource(GraphicsContext*& context) | 178 void PaintingResourceScope::releasePaintingResource(GraphicsContext*& context) |
385 { | 179 { |
386 ASSERT(m_paintingResource); | 180 ASSERT(m_paintingResource); |
387 | 181 |
388 m_paintingResource->postApplyResource(context); | 182 m_paintingResource->postApplyResource(context); |
389 m_paintingResource = 0; | 183 m_paintingResource = 0; |
390 } | 184 } |
391 | 185 |
392 TextRun SVGInlineTextBox::constructTextRun(RenderStyle* style, const SVGTextFrag
ment& fragment) const | 186 void SVGInlineTextBoxPainter::paintSelectionBackground(PaintInfo& paintInfo) |
393 { | 187 { |
| 188 if (m_svgInlineTextBox.renderer().style()->visibility() != VISIBLE) |
| 189 return; |
| 190 |
| 191 RenderObject& parentRenderer = m_svgInlineTextBox.parent()->renderer(); |
| 192 ASSERT(!parentRenderer.document().printing()); |
| 193 |
| 194 // Determine whether or not we're selected. |
| 195 bool paintSelectedTextOnly = paintInfo.phase == PaintPhaseSelection; |
| 196 bool hasSelection = m_svgInlineTextBox.selectionState() != RenderObject::Sel
ectionNone; |
| 197 if (!hasSelection || paintSelectedTextOnly) |
| 198 return; |
| 199 |
| 200 Color backgroundColor = m_svgInlineTextBox.renderer().selectionBackgroundCol
or(); |
| 201 if (!backgroundColor.alpha()) |
| 202 return; |
| 203 |
| 204 RenderSVGInlineText& textRenderer = toRenderSVGInlineText(m_svgInlineTextBox
.renderer()); |
| 205 if (!textShouldBePainted(textRenderer)) |
| 206 return; |
| 207 |
| 208 RenderStyle* style = parentRenderer.style(); |
394 ASSERT(style); | 209 ASSERT(style); |
395 | 210 |
396 RenderText* text = &renderer(); | 211 int startPosition, endPosition; |
| 212 m_svgInlineTextBox.selectionStartEnd(startPosition, endPosition); |
397 | 213 |
398 // FIXME(crbug.com/264211): This should not be necessary but can occur if we | 214 int fragmentStartPosition = 0; |
399 // layout during layout. Remove this when 264211 is
fixed. | 215 int fragmentEndPosition = 0; |
400 RELEASE_ASSERT(!text->needsLayout()); | 216 AffineTransform fragmentTransform; |
| 217 unsigned textFragmentsSize = m_svgInlineTextBox.textFragments().size(); |
| 218 for (unsigned i = 0; i < textFragmentsSize; ++i) { |
| 219 SVGTextFragment& fragment = m_svgInlineTextBox.textFragments().at(i); |
401 | 220 |
402 TextRun run(static_cast<const LChar*>(0) // characters, will be set below if
non-zero. | 221 fragmentStartPosition = startPosition; |
403 , 0 // length, will be set below if non-zero. | 222 fragmentEndPosition = endPosition; |
404 , 0 // xPos, only relevant with allowTabs=true | 223 if (!m_svgInlineTextBox.mapStartEndPositionsIntoFragmentCoordinates(frag
ment, fragmentStartPosition, fragmentEndPosition)) |
405 , 0 // padding, only relevant for justified text, not relevant f
or SVG | 224 continue; |
406 , TextRun::AllowTrailingExpansion | |
407 , direction() | |
408 , dirOverride() || style->rtlOrdering() == VisualOrder /* direct
ionalOverride */); | |
409 | 225 |
410 if (fragment.length) { | 226 GraphicsContextStateSaver stateSaver(*paintInfo.context); |
411 if (text->is8Bit()) | 227 fragment.buildFragmentTransform(fragmentTransform); |
412 run.setText(text->characters8() + fragment.characterOffset, fragment
.length); | 228 if (!fragmentTransform.isIdentity()) |
413 else | 229 paintInfo.context->concatCTM(fragmentTransform); |
414 run.setText(text->characters16() + fragment.characterOffset, fragmen
t.length); | 230 |
| 231 paintInfo.context->setFillColor(backgroundColor); |
| 232 paintInfo.context->fillRect(m_svgInlineTextBox.selectionRectForTextFragm
ent(fragment, fragmentStartPosition, fragmentEndPosition, style), backgroundColo
r); |
415 } | 233 } |
416 | |
417 if (textRunNeedsRenderingContext(style->font())) | |
418 run.setRenderingContext(SVGTextRunRenderingContext::create(text)); | |
419 | |
420 // We handle letter & word spacing ourselves. | |
421 run.disableSpacing(); | |
422 | |
423 // Propagate the maximum length of the characters buffer to the TextRun, eve
n when we're only processing a substring. | |
424 run.setCharactersLength(text->textLength() - fragment.characterOffset); | |
425 ASSERT(run.charactersLength() >= run.length()); | |
426 return run; | |
427 } | |
428 | |
429 bool SVGInlineTextBox::mapStartEndPositionsIntoFragmentCoordinates(const SVGText
Fragment& fragment, int& startPosition, int& endPosition) const | |
430 { | |
431 if (startPosition >= endPosition) | |
432 return false; | |
433 | |
434 int offset = static_cast<int>(fragment.characterOffset) - start(); | |
435 int length = static_cast<int>(fragment.length); | |
436 | |
437 if (startPosition >= offset + length || endPosition <= offset) | |
438 return false; | |
439 | |
440 if (startPosition < offset) | |
441 startPosition = 0; | |
442 else | |
443 startPosition -= offset; | |
444 | |
445 if (endPosition > offset + length) | |
446 endPosition = length; | |
447 else { | |
448 ASSERT(endPosition >= offset); | |
449 endPosition -= offset; | |
450 } | |
451 | |
452 ASSERT(startPosition < endPosition); | |
453 return true; | |
454 } | |
455 | |
456 // Offset from the baseline for |decoration|. Positive offsets are above the bas
eline. | |
457 static inline float baselineOffsetForDecoration(TextDecoration decoration, const
FontMetrics& fontMetrics, float thickness) | |
458 { | |
459 // FIXME: For SVG Fonts we need to use the attributes defined in the <font-f
ace> if specified. | |
460 // Compatible with Batik/Presto. | |
461 if (decoration == TextDecorationUnderline) | |
462 return -thickness * 1.5f; | |
463 if (decoration == TextDecorationOverline) | |
464 return fontMetrics.floatAscent() - thickness; | |
465 if (decoration == TextDecorationLineThrough) | |
466 return fontMetrics.floatAscent() * 3 / 8.0f; | |
467 | |
468 ASSERT_NOT_REACHED(); | |
469 return 0.0f; | |
470 } | |
471 | |
472 static inline float thicknessForDecoration(TextDecoration, const Font& font) | |
473 { | |
474 // FIXME: For SVG Fonts we need to use the attributes defined in the <font-f
ace> if specified. | |
475 // Compatible with Batik/Presto | |
476 return font.fontDescription().computedSize() / 20.0f; | |
477 } | 234 } |
478 | 235 |
479 static inline RenderObject* findRenderObjectDefininingTextDecoration(InlineFlowB
ox* parentBox) | 236 static inline RenderObject* findRenderObjectDefininingTextDecoration(InlineFlowB
ox* parentBox) |
480 { | 237 { |
481 // Lookup first render object in parent hierarchy which has text-decoration
set. | 238 // Lookup first render object in parent hierarchy which has text-decoration
set. |
482 RenderObject* renderer = 0; | 239 RenderObject* renderer = 0; |
483 while (parentBox) { | 240 while (parentBox) { |
484 renderer = &parentBox->renderer(); | 241 renderer = &parentBox->renderer(); |
485 | 242 |
486 if (renderer->style() && renderer->style()->textDecoration() != TextDeco
rationNone) | 243 if (renderer->style() && renderer->style()->textDecoration() != TextDeco
rationNone) |
487 break; | 244 break; |
488 | 245 |
489 parentBox = parentBox->parent(); | 246 parentBox = parentBox->parent(); |
490 } | 247 } |
491 | 248 |
492 ASSERT(renderer); | 249 ASSERT(renderer); |
493 return renderer; | 250 return renderer; |
494 } | 251 } |
495 | 252 |
496 void SVGInlineTextBox::paintDecoration(GraphicsContext* context, TextDecoration
decoration, const SVGTextFragment& fragment) | 253 void SVGInlineTextBoxPainter::paintDecoration(GraphicsContext* context, TextDeco
ration decoration, const SVGTextFragment& fragment) |
497 { | 254 { |
498 if (renderer().style()->textDecorationsInEffect() == TextDecorationNone) | 255 if (m_svgInlineTextBox.renderer().style()->textDecorationsInEffect() == Text
DecorationNone) |
499 return; | 256 return; |
500 | 257 |
501 // Find out which render style defined the text-decoration, as its fill/stro
ke properties have to be used for drawing instead of ours. | 258 // Find out which render style defined the text-decoration, as its fill/stro
ke properties have to be used for drawing instead of ours. |
502 RenderObject* decorationRenderer = findRenderObjectDefininingTextDecoration(
parent()); | 259 RenderObject* decorationRenderer = findRenderObjectDefininingTextDecoration(
m_svgInlineTextBox.parent()); |
503 RenderStyle* decorationStyle = decorationRenderer->style(); | 260 RenderStyle* decorationStyle = decorationRenderer->style(); |
504 ASSERT(decorationStyle); | 261 ASSERT(decorationStyle); |
505 | 262 |
506 if (decorationStyle->visibility() == HIDDEN) | 263 if (decorationStyle->visibility() == HIDDEN) |
507 return; | 264 return; |
508 | 265 |
509 const SVGRenderStyle& svgDecorationStyle = decorationStyle->svgStyle(); | 266 const SVGRenderStyle& svgDecorationStyle = decorationStyle->svgStyle(); |
510 | 267 |
511 for (int i = 0; i < 3; i++) { | 268 for (int i = 0; i < 3; i++) { |
512 switch (svgDecorationStyle.paintOrderType(i)) { | 269 switch (svgDecorationStyle.paintOrderType(i)) { |
513 case PT_FILL: | 270 case PT_FILL: |
514 if (svgDecorationStyle.hasFill()) | 271 if (svgDecorationStyle.hasFill()) |
515 paintDecorationWithStyle(context, decoration, fragment, decorati
onRenderer, ApplyToFillMode); | 272 paintDecorationWithStyle(context, decoration, fragment, decorati
onRenderer, ApplyToFillMode); |
516 break; | 273 break; |
517 case PT_STROKE: | 274 case PT_STROKE: |
518 if (svgDecorationStyle.hasVisibleStroke()) | 275 if (svgDecorationStyle.hasVisibleStroke()) |
519 paintDecorationWithStyle(context, decoration, fragment, decorati
onRenderer, ApplyToStrokeMode); | 276 paintDecorationWithStyle(context, decoration, fragment, decorati
onRenderer, ApplyToStrokeMode); |
520 break; | 277 break; |
521 case PT_MARKERS: | 278 case PT_MARKERS: |
522 break; | 279 break; |
523 default: | 280 default: |
524 ASSERT_NOT_REACHED(); | 281 ASSERT_NOT_REACHED(); |
525 } | 282 } |
526 } | 283 } |
527 } | 284 } |
528 | 285 |
529 void SVGInlineTextBox::paintDecorationWithStyle(GraphicsContext* context, TextDe
coration decoration, | 286 // Offset from the baseline for |decoration|. Positive offsets are above the bas
eline. |
| 287 static inline float baselineOffsetForDecoration(TextDecoration decoration, const
FontMetrics& fontMetrics, float thickness) |
| 288 { |
| 289 // FIXME: For SVG Fonts we need to use the attributes defined in the <font-f
ace> if specified. |
| 290 // Compatible with Batik/Presto. |
| 291 if (decoration == TextDecorationUnderline) |
| 292 return -thickness * 1.5f; |
| 293 if (decoration == TextDecorationOverline) |
| 294 return fontMetrics.floatAscent() - thickness; |
| 295 if (decoration == TextDecorationLineThrough) |
| 296 return fontMetrics.floatAscent() * 3 / 8.0f; |
| 297 |
| 298 ASSERT_NOT_REACHED(); |
| 299 return 0.0f; |
| 300 } |
| 301 |
| 302 static inline float thicknessForDecoration(TextDecoration, const Font& font) |
| 303 { |
| 304 // FIXME: For SVG Fonts we need to use the attributes defined in the <font-f
ace> if specified. |
| 305 // Compatible with Batik/Presto |
| 306 return font.fontDescription().computedSize() / 20.0f; |
| 307 } |
| 308 |
| 309 void SVGInlineTextBoxPainter::paintDecorationWithStyle(GraphicsContext* context,
TextDecoration decoration, |
530 const SVGTextFragment& fragment, RenderObject* decorationRenderer, RenderSVG
ResourceModeFlags resourceMode) | 310 const SVGTextFragment& fragment, RenderObject* decorationRenderer, RenderSVG
ResourceModeFlags resourceMode) |
531 { | 311 { |
532 RenderStyle* decorationStyle = decorationRenderer->style(); | 312 RenderStyle* decorationStyle = decorationRenderer->style(); |
533 ASSERT(decorationStyle); | 313 ASSERT(decorationStyle); |
534 | 314 |
535 float scalingFactor = 1; | 315 float scalingFactor = 1; |
536 Font scaledFont; | 316 Font scaledFont; |
537 RenderSVGInlineText::computeNewScaledFontForStyle(decorationRenderer, decora
tionStyle, scalingFactor, scaledFont); | 317 RenderSVGInlineText::computeNewScaledFontForStyle(decorationRenderer, decora
tionStyle, scalingFactor, scaledFont); |
538 ASSERT(scalingFactor); | 318 ASSERT(scalingFactor); |
539 | 319 |
540 float thickness = thicknessForDecoration(decoration, scaledFont); | 320 float thickness = thicknessForDecoration(decoration, scaledFont); |
541 | 321 |
542 if (fragment.width <= 0 && thickness <= 0) | 322 if (fragment.width <= 0 && thickness <= 0) |
543 return; | 323 return; |
544 | 324 |
545 float decorationOffset = baselineOffsetForDecoration(decoration, scaledFont.
fontMetrics(), thickness); | 325 float decorationOffset = baselineOffsetForDecoration(decoration, scaledFont.
fontMetrics(), thickness); |
546 FloatPoint decorationOrigin(fragment.x, fragment.y - decorationOffset / scal
ingFactor); | 326 FloatPoint decorationOrigin(fragment.x, fragment.y - decorationOffset / scal
ingFactor); |
547 | 327 |
548 Path path; | 328 Path path; |
549 path.addRect(FloatRect(decorationOrigin, FloatSize(fragment.width, thickness
/ scalingFactor))); | 329 path.addRect(FloatRect(decorationOrigin, FloatSize(fragment.width, thickness
/ scalingFactor))); |
550 | 330 |
551 PaintingResourceScope resourceScope(*decorationRenderer); | 331 PaintingResourceScope resourceScope(*decorationRenderer); |
552 if (resourceScope.acquirePaintingResource(context, decorationStyle, resource
Mode)) { | 332 if (resourceScope.acquirePaintingResource(context, decorationStyle, resource
Mode)) { |
553 SVGRenderSupport::fillOrStrokePath(context, resourceMode, path); | 333 SVGRenderSupport::fillOrStrokePath(context, resourceMode, path); |
554 resourceScope.releasePaintingResource(context); | 334 resourceScope.releasePaintingResource(context); |
555 } | 335 } |
556 } | 336 } |
557 | 337 |
558 void SVGInlineTextBox::paintTextWithShadows(GraphicsContext* context, RenderStyl
e* style, | 338 void SVGInlineTextBoxPainter::paintTextWithShadows(GraphicsContext* context, Ren
derStyle* style, |
559 TextRun& textRun, const SVGTextFragment& fragment, int startPosition, int en
dPosition, | 339 TextRun& textRun, const SVGTextFragment& fragment, int startPosition, int en
dPosition, |
560 RenderSVGResourceModeFlags resourceMode) | 340 RenderSVGResourceModeFlags resourceMode) |
561 { | 341 { |
562 RenderSVGInlineText& textRenderer = toRenderSVGInlineText(this->renderer()); | 342 RenderSVGInlineText& textRenderer = toRenderSVGInlineText(m_svgInlineTextBox
.renderer()); |
563 | 343 |
564 float scalingFactor = textRenderer.scalingFactor(); | 344 float scalingFactor = textRenderer.scalingFactor(); |
565 ASSERT(scalingFactor); | 345 ASSERT(scalingFactor); |
566 | 346 |
567 const Font& scaledFont = textRenderer.scaledFont(); | 347 const Font& scaledFont = textRenderer.scaledFont(); |
568 const ShadowList* shadowList = style->textShadow(); | 348 const ShadowList* shadowList = style->textShadow(); |
569 | 349 |
570 // Text shadows are disabled when printing. http://crbug.com/258321 | 350 // Text shadows are disabled when printing. http://crbug.com/258321 |
571 bool hasShadow = shadowList && !context->printing(); | 351 bool hasShadow = shadowList && !context->printing(); |
572 | 352 |
573 FloatPoint textOrigin(fragment.x, fragment.y); | 353 FloatPoint textOrigin(fragment.x, fragment.y); |
574 FloatSize textSize(fragment.width, fragment.height); | 354 FloatSize textSize(fragment.width, fragment.height); |
575 | 355 |
576 if (scalingFactor != 1) { | 356 if (scalingFactor != 1) { |
577 textOrigin.scale(scalingFactor, scalingFactor); | 357 textOrigin.scale(scalingFactor, scalingFactor); |
578 textSize.scale(scalingFactor); | 358 textSize.scale(scalingFactor); |
579 context->save(); | 359 context->save(); |
580 context->scale(1 / scalingFactor, 1 / scalingFactor); | 360 context->scale(1 / scalingFactor, 1 / scalingFactor); |
581 } | 361 } |
582 | 362 |
583 if (hasShadow) | 363 if (hasShadow) |
584 context->setDrawLooper(shadowList->createDrawLooper(DrawLooperBuilder::S
hadowRespectsAlpha)); | 364 context->setDrawLooper(shadowList->createDrawLooper(DrawLooperBuilder::S
hadowRespectsAlpha)); |
585 | 365 |
586 PaintingResourceScope resourceScope(parent()->renderer()); | 366 PaintingResourceScope resourceScope(m_svgInlineTextBox.parent()->renderer())
; |
587 if (resourceScope.acquirePaintingResource(context, style, resourceMode)) { | 367 if (resourceScope.acquirePaintingResource(context, style, resourceMode)) { |
588 if (scalingFactor != 1 && resourceMode & ApplyToStrokeMode) | 368 if (scalingFactor != 1 && resourceMode & ApplyToStrokeMode) |
589 context->setStrokeThickness(context->strokeThickness() * scalingFact
or); | 369 context->setStrokeThickness(context->strokeThickness() * scalingFact
or); |
590 | 370 |
591 TextRunPaintInfo textRunPaintInfo(textRun); | 371 TextRunPaintInfo textRunPaintInfo(textRun); |
592 textRunPaintInfo.from = startPosition; | 372 textRunPaintInfo.from = startPosition; |
593 textRunPaintInfo.to = endPosition; | 373 textRunPaintInfo.to = endPosition; |
594 | 374 |
595 float baseline = scaledFont.fontMetrics().floatAscent(); | 375 float baseline = scaledFont.fontMetrics().floatAscent(); |
596 textRunPaintInfo.bounds = FloatRect(textOrigin.x(), textOrigin.y() - bas
eline, | 376 textRunPaintInfo.bounds = FloatRect(textOrigin.x(), textOrigin.y() - bas
eline, |
597 textSize.width(), textSize.height()); | 377 textSize.width(), textSize.height()); |
598 | 378 |
599 scaledFont.drawText(context, textRunPaintInfo, textOrigin); | 379 scaledFont.drawText(context, textRunPaintInfo, textOrigin); |
600 resourceScope.releasePaintingResource(context); | 380 resourceScope.releasePaintingResource(context); |
601 } | 381 } |
602 | 382 |
603 if (scalingFactor != 1) | 383 if (scalingFactor != 1) |
604 context->restore(); | 384 context->restore(); |
605 else if (hasShadow) | 385 else if (hasShadow) |
606 context->clearShadow(); | 386 context->clearShadow(); |
607 } | 387 } |
608 | 388 |
609 void SVGInlineTextBox::paintText(GraphicsContext* context, RenderStyle* style, | 389 void SVGInlineTextBoxPainter::paintText(GraphicsContext* context, RenderStyle* s
tyle, |
610 RenderStyle* selectionStyle, const SVGTextFragment& fragment, | 390 RenderStyle* selectionStyle, const SVGTextFragment& fragment, |
611 RenderSVGResourceModeFlags resourceMode, bool hasSelection, bool paintSelect
edTextOnly) | 391 RenderSVGResourceModeFlags resourceMode, bool hasSelection, bool paintSelect
edTextOnly) |
612 { | 392 { |
613 ASSERT(style); | 393 ASSERT(style); |
614 ASSERT(selectionStyle); | 394 ASSERT(selectionStyle); |
615 | 395 |
616 int startPosition = 0; | 396 int startPosition = 0; |
617 int endPosition = 0; | 397 int endPosition = 0; |
618 if (hasSelection) { | 398 if (hasSelection) { |
619 selectionStartEnd(startPosition, endPosition); | 399 m_svgInlineTextBox.selectionStartEnd(startPosition, endPosition); |
620 hasSelection = mapStartEndPositionsIntoFragmentCoordinates(fragment, sta
rtPosition, endPosition); | 400 hasSelection = m_svgInlineTextBox.mapStartEndPositionsIntoFragmentCoordi
nates(fragment, startPosition, endPosition); |
621 } | 401 } |
622 | 402 |
623 // Fast path if there is no selection, just draw the whole chunk part using
the regular style | 403 // Fast path if there is no selection, just draw the whole chunk part using
the regular style |
624 TextRun textRun = constructTextRun(style, fragment); | 404 TextRun textRun = m_svgInlineTextBox.constructTextRun(style, fragment); |
625 if (!hasSelection || startPosition >= endPosition) { | 405 if (!hasSelection || startPosition >= endPosition) { |
626 paintTextWithShadows(context, style, textRun, fragment, 0, fragment.leng
th, resourceMode); | 406 paintTextWithShadows(context, style, textRun, fragment, 0, fragment.leng
th, resourceMode); |
627 return; | 407 return; |
628 } | 408 } |
629 | 409 |
630 // Eventually draw text using regular style until the start position of the
selection | 410 // Eventually draw text using regular style until the start position of the
selection |
631 if (startPosition > 0 && !paintSelectedTextOnly) | 411 if (startPosition > 0 && !paintSelectedTextOnly) |
632 paintTextWithShadows(context, style, textRun, fragment, 0, startPosition
, resourceMode); | 412 paintTextWithShadows(context, style, textRun, fragment, 0, startPosition
, resourceMode); |
633 | 413 |
634 // Draw text using selection style from the start to the end position of the
selection | 414 // Draw text using selection style from the start to the end position of the
selection |
635 if (style != selectionStyle) { | 415 if (style != selectionStyle) { |
636 StyleDifference diff; | 416 StyleDifference diff; |
637 diff.setNeedsPaintInvalidationObject(); | 417 diff.setNeedsPaintInvalidationObject(); |
638 SVGResourcesCache::clientStyleChanged(&parent()->renderer(), diff, selec
tionStyle); | 418 SVGResourcesCache::clientStyleChanged(&m_svgInlineTextBox.parent()->rend
erer(), diff, selectionStyle); |
639 } | 419 } |
640 | 420 |
641 paintTextWithShadows(context, selectionStyle, textRun, fragment, startPositi
on, endPosition, resourceMode); | 421 paintTextWithShadows(context, selectionStyle, textRun, fragment, startPositi
on, endPosition, resourceMode); |
642 | 422 |
643 if (style != selectionStyle) { | 423 if (style != selectionStyle) { |
644 StyleDifference diff; | 424 StyleDifference diff; |
645 diff.setNeedsPaintInvalidationObject(); | 425 diff.setNeedsPaintInvalidationObject(); |
646 SVGResourcesCache::clientStyleChanged(&parent()->renderer(), diff, style
); | 426 SVGResourcesCache::clientStyleChanged(&m_svgInlineTextBox.parent()->rend
erer(), diff, style); |
647 } | 427 } |
648 | 428 |
649 // Eventually draw text using regular style from the end position of the sel
ection to the end of the current chunk part | 429 // Eventually draw text using regular style from the end position of the sel
ection to the end of the current chunk part |
650 if (endPosition < static_cast<int>(fragment.length) && !paintSelectedTextOnl
y) | 430 if (endPosition < static_cast<int>(fragment.length) && !paintSelectedTextOnl
y) |
651 paintTextWithShadows(context, style, textRun, fragment, endPosition, fra
gment.length, resourceMode); | 431 paintTextWithShadows(context, style, textRun, fragment, endPosition, fra
gment.length, resourceMode); |
652 } | 432 } |
653 | 433 |
654 void SVGInlineTextBox::paintDocumentMarker(GraphicsContext*, const FloatPoint&,
DocumentMarker*, RenderStyle*, const Font&, bool) | 434 void SVGInlineTextBoxPainter::paintTextMatchMarker(GraphicsContext* context, con
st FloatPoint&, DocumentMarker* marker, RenderStyle* style, const Font& font) |
655 { | |
656 // SVG does not have support for generic document markers (e.g., spellchecki
ng, etc). | |
657 } | |
658 | |
659 void SVGInlineTextBox::paintTextMatchMarker(GraphicsContext* context, const Floa
tPoint&, DocumentMarker* marker, RenderStyle* style, const Font& font) | |
660 { | 435 { |
661 // SVG is only interested in the TextMatch markers. | 436 // SVG is only interested in the TextMatch markers. |
662 if (marker->type() != DocumentMarker::TextMatch) | 437 if (marker->type() != DocumentMarker::TextMatch) |
663 return; | 438 return; |
664 | 439 |
665 RenderSVGInlineText& textRenderer = toRenderSVGInlineText(this->renderer()); | 440 RenderSVGInlineText& textRenderer = toRenderSVGInlineText(m_svgInlineTextBox
.renderer()); |
666 | 441 |
667 FloatRect markerRect; | 442 FloatRect markerRect; |
668 AffineTransform fragmentTransform; | 443 AffineTransform fragmentTransform; |
669 for (InlineTextBox* box = textRenderer.firstTextBox(); box; box = box->nextT
extBox()) { | 444 for (InlineTextBox* box = textRenderer.firstTextBox(); box; box = box->nextT
extBox()) { |
670 if (!box->isSVGInlineTextBox()) | 445 if (!box->isSVGInlineTextBox()) |
671 continue; | 446 continue; |
672 | 447 |
673 SVGInlineTextBox* textBox = toSVGInlineTextBox(box); | 448 SVGInlineTextBox* textBox = toSVGInlineTextBox(box); |
674 | 449 |
675 int markerStartPosition = std::max<int>(marker->startOffset() - textBox-
>start(), 0); | 450 int markerStartPosition = std::max<int>(marker->startOffset() - textBox-
>start(), 0); |
676 int markerEndPosition = std::min<int>(marker->endOffset() - textBox->sta
rt(), textBox->len()); | 451 int markerEndPosition = std::min<int>(marker->endOffset() - textBox->sta
rt(), textBox->len()); |
677 | 452 |
678 if (markerStartPosition >= markerEndPosition) | 453 if (markerStartPosition >= markerEndPosition) |
679 continue; | 454 continue; |
680 | 455 |
681 const Vector<SVGTextFragment>& fragments = textBox->textFragments(); | 456 const Vector<SVGTextFragment>& fragments = textBox->textFragments(); |
682 unsigned textFragmentsSize = fragments.size(); | 457 unsigned textFragmentsSize = fragments.size(); |
683 for (unsigned i = 0; i < textFragmentsSize; ++i) { | 458 for (unsigned i = 0; i < textFragmentsSize; ++i) { |
684 const SVGTextFragment& fragment = fragments.at(i); | 459 const SVGTextFragment& fragment = fragments.at(i); |
685 | 460 |
686 int fragmentStartPosition = markerStartPosition; | 461 int fragmentStartPosition = markerStartPosition; |
687 int fragmentEndPosition = markerEndPosition; | 462 int fragmentEndPosition = markerEndPosition; |
688 if (!textBox->mapStartEndPositionsIntoFragmentCoordinates(fragment,
fragmentStartPosition, fragmentEndPosition)) | 463 if (!textBox->mapStartEndPositionsIntoFragmentCoordinates(fragment,
fragmentStartPosition, fragmentEndPosition)) |
689 continue; | 464 continue; |
690 | 465 |
691 FloatRect fragmentRect = textBox->selectionRectForTextFragment(fragm
ent, fragmentStartPosition, fragmentEndPosition, style); | 466 FloatRect fragmentRect = textBox->selectionRectForTextFragment(fragm
ent, fragmentStartPosition, fragmentEndPosition, style); |
692 fragment.buildFragmentTransform(fragmentTransform); | 467 fragment.buildFragmentTransform(fragmentTransform); |
693 | 468 |
694 // Draw the marker highlight. | 469 // Draw the marker highlight. |
695 if (renderer().frame()->editor().markedTextMatchesAreHighlighted())
{ | 470 if (m_svgInlineTextBox.renderer().frame()->editor().markedTextMatche
sAreHighlighted()) { |
696 Color color = marker->activeMatch() ? | 471 Color color = marker->activeMatch() ? |
697 RenderTheme::theme().platformActiveTextSearchHighlightColor(
) : | 472 RenderTheme::theme().platformActiveTextSearchHighlightColor(
) : |
698 RenderTheme::theme().platformInactiveTextSearchHighlightColo
r(); | 473 RenderTheme::theme().platformInactiveTextSearchHighlightColo
r(); |
699 GraphicsContextStateSaver stateSaver(*context); | 474 GraphicsContextStateSaver stateSaver(*context); |
700 if (!fragmentTransform.isIdentity()) | 475 if (!fragmentTransform.isIdentity()) |
701 context->concatCTM(fragmentTransform); | 476 context->concatCTM(fragmentTransform); |
702 context->setFillColor(color); | 477 context->setFillColor(color); |
703 context->fillRect(fragmentRect, color); | 478 context->fillRect(fragmentRect, color); |
704 } | 479 } |
705 | 480 |
706 fragmentRect = fragmentTransform.mapRect(fragmentRect); | 481 fragmentRect = fragmentTransform.mapRect(fragmentRect); |
707 markerRect.unite(fragmentRect); | 482 markerRect.unite(fragmentRect); |
708 } | 483 } |
709 } | 484 } |
710 | 485 |
711 toRenderedDocumentMarker(marker)->setRenderedRect(textRenderer.localToAbsolu
teQuad(markerRect).enclosingBoundingBox()); | 486 toRenderedDocumentMarker(marker)->setRenderedRect(textRenderer.localToAbsolu
teQuad(markerRect).enclosingBoundingBox()); |
712 } | 487 } |
713 | 488 |
714 FloatRect SVGInlineTextBox::calculateBoundaries() const | |
715 { | |
716 FloatRect textRect; | |
717 | |
718 RenderSVGInlineText& textRenderer = toRenderSVGInlineText(this->renderer()); | |
719 | |
720 float scalingFactor = textRenderer.scalingFactor(); | |
721 ASSERT(scalingFactor); | |
722 | |
723 float baseline = textRenderer.scaledFont().fontMetrics().floatAscent() / sca
lingFactor; | |
724 | |
725 AffineTransform fragmentTransform; | |
726 unsigned textFragmentsSize = m_textFragments.size(); | |
727 for (unsigned i = 0; i < textFragmentsSize; ++i) { | |
728 const SVGTextFragment& fragment = m_textFragments.at(i); | |
729 FloatRect fragmentRect(fragment.x, fragment.y - baseline, fragment.width
, fragment.height); | |
730 fragment.buildFragmentTransform(fragmentTransform); | |
731 fragmentRect = fragmentTransform.mapRect(fragmentRect); | |
732 | |
733 textRect.unite(fragmentRect); | |
734 } | |
735 | |
736 return textRect; | |
737 } | |
738 | |
739 bool SVGInlineTextBox::nodeAtPoint(const HitTestRequest& request, HitTestResult&
result, const HitTestLocation& locationInContainer, const LayoutPoint& accumula
tedOffset, LayoutUnit, LayoutUnit) | |
740 { | |
741 // FIXME: integrate with InlineTextBox::nodeAtPoint better. | |
742 ASSERT(!isLineBreak()); | |
743 | |
744 PointerEventsHitRules hitRules(PointerEventsHitRules::SVG_TEXT_HITTESTING, r
equest, renderer().style()->pointerEvents()); | |
745 bool isVisible = renderer().style()->visibility() == VISIBLE; | |
746 if (isVisible || !hitRules.requireVisible) { | |
747 if (hitRules.canHitBoundingBox | |
748 || (hitRules.canHitStroke && (renderer().style()->svgStyle().hasStro
ke() || !hitRules.requireStroke)) | |
749 || (hitRules.canHitFill && (renderer().style()->svgStyle().hasFill()
|| !hitRules.requireFill))) { | |
750 FloatPoint boxOrigin(x(), y()); | |
751 boxOrigin.moveBy(accumulatedOffset); | |
752 FloatRect rect(boxOrigin, size()); | |
753 if (locationInContainer.intersects(rect)) { | |
754 renderer().updateHitTestResult(result, locationInContainer.point
() - toLayoutSize(accumulatedOffset)); | |
755 if (!result.addNodeToRectBasedTestResult(renderer().node(), requ
est, locationInContainer, rect)) | |
756 return true; | |
757 } | |
758 } | |
759 } | |
760 return false; | |
761 } | |
762 | |
763 } // namespace blink | 489 } // namespace blink |
OLD | NEW |