2 * Copyright (C) 2007 Rob Buis <buis@kde.org>
3 * Copyright (C) 2007 Nikolas Zimmermann <zimmermann@kde.org>
4 * Copyright (C) Research In Motion Limited 2010. All rights reserved.
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.
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.
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.
23 #include "SVGInlineTextBox.h"
26 #include "FrameView.h"
27 #include "GraphicsContext.h"
28 #include "HitTestResult.h"
29 #include "InlineFlowBox.h"
30 #include "PointerEventsHitRules.h"
31 #include "RenderBlock.h"
32 #include "RenderInline.h"
33 #include "RenderSVGResourceSolidColor.h"
34 #include "RenderView.h"
35 #include "SVGRenderingContext.h"
36 #include "SVGResourcesCache.h"
37 #include "SVGRootInlineBox.h"
38 #include "TextPainter.h"
42 struct ExpectedSVGInlineTextBoxSize : public InlineTextBox {
44 uint32_t bitfields : 5;
46 Vector<SVGTextFragment> vector;
49 COMPILE_ASSERT(sizeof(SVGInlineTextBox) == sizeof(ExpectedSVGInlineTextBoxSize), SVGInlineTextBox_is_not_of_expected_size);
51 SVGInlineTextBox::SVGInlineTextBox(RenderSVGInlineText& renderer)
52 : InlineTextBox(renderer)
54 , m_paintingResourceMode(ApplyToDefaultMode)
55 , m_startsNewTextChunk(false)
56 , m_paintingResource(nullptr)
60 void SVGInlineTextBox::dirtyOwnLineBoxes()
62 InlineTextBox::dirtyLineBoxes();
64 // Clear the now stale text fragments
68 void SVGInlineTextBox::dirtyLineBoxes()
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 for (InlineTextBox* nextBox = nextTextBox(); nextBox; nextBox = nextBox->nextTextBox())
75 nextBox->dirtyOwnLineBoxes();
78 int SVGInlineTextBox::offsetForPosition(float, bool) const
80 // SVG doesn't use the standard offset <-> position selection system, as it's not suitable for SVGs complex needs.
81 // vertical text selection, inline boxes spanning multiple lines (contrary to HTML, etc.)
86 int SVGInlineTextBox::offsetForPositionInFragment(const SVGTextFragment& fragment, float position, bool includePartialGlyphs) const
88 float scalingFactor = renderer().scalingFactor();
89 ASSERT(scalingFactor);
91 TextRun textRun = constructTextRun(&renderer().style(), fragment);
93 // Eventually handle lengthAdjust="spacingAndGlyphs".
94 // FIXME: Handle vertical text.
95 AffineTransform fragmentTransform;
96 fragment.buildFragmentTransform(fragmentTransform);
97 if (!fragmentTransform.isIdentity())
98 textRun.setHorizontalGlyphStretch(narrowPrecisionToFloat(fragmentTransform.xScale()));
100 return fragment.characterOffset - start() + renderer().scaledFont().offsetForPosition(textRun, position * scalingFactor, includePartialGlyphs);
103 float SVGInlineTextBox::positionForOffset(int) const
105 // SVG doesn't use the offset <-> position selection system.
106 ASSERT_NOT_REACHED();
110 FloatRect SVGInlineTextBox::selectionRectForTextFragment(const SVGTextFragment& fragment, int startPosition, int endPosition, const RenderStyle* style) const
112 ASSERT_WITH_SECURITY_IMPLICATION(startPosition < endPosition);
115 float scalingFactor = renderer().scalingFactor();
116 ASSERT(scalingFactor);
118 const FontCascade& scaledFont = renderer().scaledFont();
119 const FontMetrics& scaledFontMetrics = scaledFont.fontMetrics();
120 FloatPoint textOrigin(fragment.x, fragment.y);
121 if (scalingFactor != 1)
122 textOrigin.scale(scalingFactor, scalingFactor);
124 textOrigin.move(0, -scaledFontMetrics.floatAscent());
126 LayoutRect selectionRect = LayoutRect(textOrigin, LayoutSize(0, fragment.height * scalingFactor));
127 TextRun run = constructTextRun(style, fragment);
128 scaledFont.adjustSelectionRectForText(run, selectionRect, startPosition, endPosition);
129 FloatRect snappedSelectionRect = snapRectToDevicePixelsWithWritingDirection(selectionRect, renderer().document().deviceScaleFactor(), run.ltr());
130 if (scalingFactor == 1)
131 return snappedSelectionRect;
133 snappedSelectionRect.scale(1 / scalingFactor);
134 return snappedSelectionRect;
137 LayoutRect SVGInlineTextBox::localSelectionRect(int startPosition, int endPosition) const
139 int boxStart = start();
140 startPosition = std::max(startPosition - boxStart, 0);
141 endPosition = std::min(endPosition - boxStart, static_cast<int>(len()));
142 if (startPosition >= endPosition)
145 auto& style = renderer().style();
147 AffineTransform fragmentTransform;
148 FloatRect selectionRect;
149 int fragmentStartPosition = 0;
150 int fragmentEndPosition = 0;
152 unsigned textFragmentsSize = m_textFragments.size();
153 for (unsigned i = 0; i < textFragmentsSize; ++i) {
154 const SVGTextFragment& fragment = m_textFragments.at(i);
156 fragmentStartPosition = startPosition;
157 fragmentEndPosition = endPosition;
158 if (!mapStartEndPositionsIntoFragmentCoordinates(fragment, fragmentStartPosition, fragmentEndPosition))
161 FloatRect fragmentRect = selectionRectForTextFragment(fragment, fragmentStartPosition, fragmentEndPosition, &style);
162 fragment.buildFragmentTransform(fragmentTransform);
163 if (!fragmentTransform.isIdentity())
164 fragmentRect = fragmentTransform.mapRect(fragmentRect);
166 selectionRect.unite(fragmentRect);
169 return enclosingIntRect(selectionRect);
172 static inline bool textShouldBePainted(const RenderSVGInlineText& textRenderer)
174 // FontCascade::pixelSize(), returns FontDescription::computedPixelSize(), which returns "int(x + 0.5)".
175 // If the absolute font size on screen is below x=0.5, don't render anything.
176 return textRenderer.scaledFont().pixelSize();
179 void SVGInlineTextBox::paintSelectionBackground(PaintInfo& paintInfo)
181 ASSERT(paintInfo.shouldPaintWithinRoot(renderer()));
182 ASSERT(paintInfo.phase == PaintPhaseForeground || paintInfo.phase == PaintPhaseSelection);
183 ASSERT(truncation() == cNoTruncation);
185 if (renderer().style().visibility() != VISIBLE)
188 auto& parentRenderer = parent()->renderer();
189 ASSERT(!parentRenderer.document().printing());
191 // Determine whether or not we're selected.
192 bool paintSelectedTextOnly = paintInfo.phase == PaintPhaseSelection;
193 bool hasSelection = selectionState() != RenderObject::SelectionNone;
194 if (!hasSelection || paintSelectedTextOnly)
197 Color backgroundColor = renderer().selectionBackgroundColor();
198 if (!backgroundColor.isValid() || !backgroundColor.alpha())
201 if (!textShouldBePainted(renderer()))
204 auto& style = parentRenderer.style();
208 std::tie(startPosition, endPosition) = selectionStartEnd();
210 int fragmentStartPosition = 0;
211 int fragmentEndPosition = 0;
212 AffineTransform fragmentTransform;
213 unsigned textFragmentsSize = m_textFragments.size();
214 for (unsigned i = 0; i < textFragmentsSize; ++i) {
215 SVGTextFragment& fragment = m_textFragments.at(i);
216 ASSERT(!m_paintingResource);
218 fragmentStartPosition = startPosition;
219 fragmentEndPosition = endPosition;
220 if (!mapStartEndPositionsIntoFragmentCoordinates(fragment, fragmentStartPosition, fragmentEndPosition))
223 GraphicsContextStateSaver stateSaver(paintInfo.context());
224 fragment.buildFragmentTransform(fragmentTransform);
225 if (!fragmentTransform.isIdentity())
226 paintInfo.context().concatCTM(fragmentTransform);
228 paintInfo.context().setFillColor(backgroundColor);
229 paintInfo.context().fillRect(selectionRectForTextFragment(fragment, fragmentStartPosition, fragmentEndPosition, &style), backgroundColor);
231 m_paintingResourceMode = ApplyToDefaultMode;
234 ASSERT(!m_paintingResource);
237 void SVGInlineTextBox::paint(PaintInfo& paintInfo, const LayoutPoint& paintOffset, LayoutUnit, LayoutUnit)
239 ASSERT(paintInfo.shouldPaintWithinRoot(renderer()));
240 ASSERT(paintInfo.phase == PaintPhaseForeground || paintInfo.phase == PaintPhaseSelection);
241 ASSERT(truncation() == cNoTruncation);
243 if (renderer().style().visibility() != VISIBLE)
246 // Note: We're explicitely not supporting composition & custom underlines and custom highlighters - unlike InlineTextBox.
247 // If we ever need that for SVG, it's very easy to refactor and reuse the code.
249 auto& parentRenderer = parent()->renderer();
251 bool paintSelectedTextOnly = paintInfo.phase == PaintPhaseSelection;
252 bool hasSelection = !parentRenderer.document().printing() && selectionState() != RenderObject::SelectionNone;
253 if (!hasSelection && paintSelectedTextOnly)
256 if (!textShouldBePainted(renderer()))
259 auto& style = parentRenderer.style();
261 const SVGRenderStyle& svgStyle = style.svgStyle();
263 bool hasFill = svgStyle.hasFill();
264 bool hasVisibleStroke = svgStyle.hasVisibleStroke();
266 const RenderStyle* selectionStyle = &style;
268 selectionStyle = parentRenderer.getCachedPseudoStyle(SELECTION);
269 if (selectionStyle) {
270 const SVGRenderStyle& svgSelectionStyle = selectionStyle->svgStyle();
273 hasFill = svgSelectionStyle.hasFill();
274 if (!hasVisibleStroke)
275 hasVisibleStroke = svgSelectionStyle.hasVisibleStroke();
277 selectionStyle = &style;
280 if (renderer().view().frameView().paintBehavior() & PaintBehaviorRenderingSVGMask) {
282 hasVisibleStroke = false;
285 AffineTransform fragmentTransform;
286 unsigned textFragmentsSize = m_textFragments.size();
287 for (unsigned i = 0; i < textFragmentsSize; ++i) {
288 SVGTextFragment& fragment = m_textFragments.at(i);
289 ASSERT(!m_paintingResource);
291 GraphicsContextStateSaver stateSaver(paintInfo.context());
292 fragment.buildFragmentTransform(fragmentTransform);
293 if (!fragmentTransform.isIdentity())
294 paintInfo.context().concatCTM(fragmentTransform);
296 // 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 decorations.
297 int decorations = style.textDecorationsInEffect();
298 if (decorations & TextDecorationUnderline)
299 paintDecoration(paintInfo.context(), TextDecorationUnderline, fragment);
300 if (decorations & TextDecorationOverline)
301 paintDecoration(paintInfo.context(), TextDecorationOverline, fragment);
303 auto paintOrder = style.svgStyle().paintTypesForPaintOrder();
304 for (unsigned i = 0; i < paintOrder.size(); ++i) {
305 switch (paintOrder.at(i)) {
309 m_paintingResourceMode = ApplyToFillMode | ApplyToTextMode;
310 paintText(paintInfo.context(), &style, selectionStyle, fragment, hasSelection, paintSelectedTextOnly);
312 case PaintTypeStroke:
313 if (!hasVisibleStroke)
315 m_paintingResourceMode = ApplyToStrokeMode | ApplyToTextMode;
316 paintText(paintInfo.context(), &style, selectionStyle, fragment, hasSelection, paintSelectedTextOnly);
318 case PaintTypeMarkers:
323 // Spec: Line-through should be drawn after the text is filled and stroked; thus, the line-through is rendered on top of the text.
324 if (decorations & TextDecorationLineThrough)
325 paintDecoration(paintInfo.context(), TextDecorationLineThrough, fragment);
327 m_paintingResourceMode = ApplyToDefaultMode;
330 // Finally, paint the outline if any.
331 if (renderer().style().hasOutline() && is<RenderInline>(parentRenderer))
332 downcast<RenderInline>(parentRenderer).paintOutline(paintInfo, paintOffset);
334 ASSERT(!m_paintingResource);
337 bool SVGInlineTextBox::acquirePaintingResource(GraphicsContext*& context, float scalingFactor, RenderBoxModelObject& renderer, const RenderStyle* style)
339 ASSERT(scalingFactor);
341 ASSERT(m_paintingResourceMode != ApplyToDefaultMode);
344 if (m_paintingResourceMode & ApplyToFillMode)
345 m_paintingResource = RenderSVGResource::fillPaintingResource(renderer, *style, fallbackColor);
346 else if (m_paintingResourceMode & ApplyToStrokeMode)
347 m_paintingResource = RenderSVGResource::strokePaintingResource(renderer, *style, fallbackColor);
349 // We're either called for stroking or filling.
350 ASSERT_NOT_REACHED();
353 if (!m_paintingResource)
356 if (!m_paintingResource->applyResource(renderer, *style, context, m_paintingResourceMode)) {
357 if (fallbackColor.isValid()) {
358 RenderSVGResourceSolidColor* fallbackResource = RenderSVGResource::sharedSolidPaintingResource();
359 fallbackResource->setColor(fallbackColor);
361 m_paintingResource = fallbackResource;
362 m_paintingResource->applyResource(renderer, *style, context, m_paintingResourceMode);
366 if (scalingFactor != 1 && m_paintingResourceMode & ApplyToStrokeMode)
367 context->setStrokeThickness(context->strokeThickness() * scalingFactor);
372 void SVGInlineTextBox::releasePaintingResource(GraphicsContext*& context, const Path* path)
374 ASSERT(m_paintingResource);
376 m_paintingResource->postApplyResource(parent()->renderer(), context, m_paintingResourceMode, path, /*RenderSVGShape*/ nullptr);
377 m_paintingResource = nullptr;
380 bool SVGInlineTextBox::prepareGraphicsContextForTextPainting(GraphicsContext*& context, float scalingFactor, const RenderStyle* style)
382 return acquirePaintingResource(context, scalingFactor, parent()->renderer(), style);
385 void SVGInlineTextBox::restoreGraphicsContextAfterTextPainting(GraphicsContext*& context)
387 releasePaintingResource(context, /* path */nullptr);
390 TextRun SVGInlineTextBox::constructTextRun(const RenderStyle* style, const SVGTextFragment& fragment) const
394 TextRun run(StringView(renderer().text()).substring(fragment.characterOffset, fragment.length)
395 , 0 /* xPos, only relevant with allowTabs=true */
396 , 0 /* padding, only relevant for justified text, not relevant for SVG */
397 , AllowTrailingExpansion
399 , dirOverride() || style->rtlOrdering() == VisualOrder /* directionalOverride */);
401 // We handle letter & word spacing ourselves.
402 run.disableSpacing();
404 // Propagate the maximum length of the characters buffer to the TextRun, even when we're only processing a substring.
405 run.setCharactersLength(renderer().textLength() - fragment.characterOffset);
406 ASSERT(run.charactersLength() >= run.length());
410 bool SVGInlineTextBox::mapStartEndPositionsIntoFragmentCoordinates(const SVGTextFragment& fragment, int& startPosition, int& endPosition) const
412 if (startPosition >= endPosition)
415 int offset = static_cast<int>(fragment.characterOffset) - start();
416 int length = static_cast<int>(fragment.length);
418 if (startPosition >= offset + length || endPosition <= offset)
421 if (startPosition < offset)
424 startPosition -= offset;
426 if (endPosition > offset + length)
427 endPosition = length;
429 ASSERT(endPosition >= offset);
430 endPosition -= offset;
433 ASSERT_WITH_SECURITY_IMPLICATION(startPosition < endPosition);
437 static inline float positionOffsetForDecoration(TextDecoration decoration, const FontMetrics& fontMetrics, float thickness)
439 // FIXME: For SVG Fonts we need to use the attributes defined in the <font-face> if specified.
440 // Compatible with Batik/Opera.
441 if (decoration == TextDecorationUnderline)
442 return fontMetrics.floatAscent() + thickness * 1.5f;
443 if (decoration == TextDecorationOverline)
445 if (decoration == TextDecorationLineThrough)
446 return fontMetrics.floatAscent() * 5 / 8.0f;
448 ASSERT_NOT_REACHED();
452 static inline float thicknessForDecoration(TextDecoration, const FontCascade& font)
454 // FIXME: For SVG Fonts we need to use the attributes defined in the <font-face> if specified.
455 // Compatible with Batik/Opera
456 return font.size() / 20.0f;
459 static inline RenderBoxModelObject& findRendererDefininingTextDecoration(InlineFlowBox* parentBox)
461 // Lookup first render object in parent hierarchy which has text-decoration set.
462 RenderBoxModelObject* renderer = nullptr;
464 renderer = &parentBox->renderer();
466 if (renderer->style().textDecoration() != TextDecorationNone)
469 parentBox = parentBox->parent();
476 void SVGInlineTextBox::paintDecoration(GraphicsContext& context, TextDecoration decoration, const SVGTextFragment& fragment)
478 if (renderer().style().textDecorationsInEffect() == TextDecorationNone)
481 // Find out which render style defined the text-decoration, as its fill/stroke properties have to be used for drawing instead of ours.
482 auto& decorationRenderer = findRendererDefininingTextDecoration(parent());
483 const RenderStyle& decorationStyle = decorationRenderer.style();
485 if (decorationStyle.visibility() == HIDDEN)
488 const SVGRenderStyle& svgDecorationStyle = decorationStyle.svgStyle();
490 bool hasDecorationFill = svgDecorationStyle.hasFill();
491 bool hasVisibleDecorationStroke = svgDecorationStyle.hasVisibleStroke();
493 if (hasDecorationFill) {
494 m_paintingResourceMode = ApplyToFillMode;
495 paintDecorationWithStyle(context, decoration, fragment, decorationRenderer);
498 if (hasVisibleDecorationStroke) {
499 m_paintingResourceMode = ApplyToStrokeMode;
500 paintDecorationWithStyle(context, decoration, fragment, decorationRenderer);
504 void SVGInlineTextBox::paintDecorationWithStyle(GraphicsContext& context, TextDecoration decoration, const SVGTextFragment& fragment, RenderBoxModelObject& decorationRenderer)
506 ASSERT(!m_paintingResource);
507 ASSERT(m_paintingResourceMode != ApplyToDefaultMode);
509 auto& decorationStyle = decorationRenderer.style();
511 float scalingFactor = 1;
512 FontCascade scaledFont;
513 RenderSVGInlineText::computeNewScaledFontForStyle(decorationRenderer, decorationStyle, scalingFactor, scaledFont);
514 ASSERT(scalingFactor);
516 // The initial y value refers to overline position.
517 float thickness = thicknessForDecoration(decoration, scaledFont);
519 if (fragment.width <= 0 && thickness <= 0)
522 FloatPoint decorationOrigin(fragment.x, fragment.y);
523 float width = fragment.width;
524 const FontMetrics& scaledFontMetrics = scaledFont.fontMetrics();
526 GraphicsContextStateSaver stateSaver(context);
527 if (scalingFactor != 1) {
528 width *= scalingFactor;
529 decorationOrigin.scale(scalingFactor, scalingFactor);
530 context.scale(FloatSize(1 / scalingFactor, 1 / scalingFactor));
533 decorationOrigin.move(0, -scaledFontMetrics.floatAscent() + positionOffsetForDecoration(decoration, scaledFontMetrics, thickness));
536 path.addRect(FloatRect(decorationOrigin, FloatSize(width, thickness)));
538 GraphicsContext* contextPtr = &context;
539 if (acquirePaintingResource(contextPtr, scalingFactor, decorationRenderer, &decorationStyle))
540 releasePaintingResource(contextPtr, &path);
543 void SVGInlineTextBox::paintTextWithShadows(GraphicsContext& context, const RenderStyle* style, TextRun& textRun, const SVGTextFragment& fragment, int startPosition, int endPosition)
545 float scalingFactor = renderer().scalingFactor();
546 ASSERT(scalingFactor);
548 const FontCascade& scaledFont = renderer().scaledFont();
549 const ShadowData* shadow = style->textShadow();
551 FloatPoint textOrigin(fragment.x, fragment.y);
552 FloatSize textSize(fragment.width, fragment.height);
554 if (scalingFactor != 1) {
555 textOrigin.scale(scalingFactor, scalingFactor);
556 textSize.scale(scalingFactor);
559 FloatRect shadowRect(FloatPoint(textOrigin.x(), textOrigin.y() - scaledFont.fontMetrics().floatAscent()), textSize);
561 GraphicsContext* usedContext = &context;
563 if (!prepareGraphicsContextForTextPainting(usedContext, scalingFactor, style))
567 ShadowApplier shadowApplier(*usedContext, shadow, shadowRect);
569 if (!shadowApplier.didSaveContext())
571 usedContext->scale(FloatSize(1 / scalingFactor, 1 / scalingFactor));
573 scaledFont.drawText(*usedContext, textRun, textOrigin + shadowApplier.extraOffset(), startPosition, endPosition);
575 if (!shadowApplier.didSaveContext())
576 usedContext->restore();
579 restoreGraphicsContextAfterTextPainting(usedContext);
584 shadow = shadow->next();
588 void SVGInlineTextBox::paintText(GraphicsContext& context, const RenderStyle* style, const RenderStyle* selectionStyle, const SVGTextFragment& fragment, bool hasSelection, bool paintSelectedTextOnly)
591 ASSERT(selectionStyle);
593 int startPosition = 0;
596 std::tie(startPosition, endPosition) = selectionStartEnd();
597 hasSelection = mapStartEndPositionsIntoFragmentCoordinates(fragment, startPosition, endPosition);
600 // Fast path if there is no selection, just draw the whole chunk part using the regular style
601 TextRun textRun = constructTextRun(style, fragment);
602 if (!hasSelection || startPosition >= endPosition) {
603 paintTextWithShadows(context, style, textRun, fragment, 0, fragment.length);
607 // Eventually draw text using regular style until the start position of the selection
608 if (startPosition > 0 && !paintSelectedTextOnly)
609 paintTextWithShadows(context, style, textRun, fragment, 0, startPosition);
611 // Draw text using selection style from the start to the end position of the selection
612 if (style != selectionStyle)
613 SVGResourcesCache::clientStyleChanged(parent()->renderer(), StyleDifferenceRepaint, *selectionStyle);
615 paintTextWithShadows(context, selectionStyle, textRun, fragment, startPosition, endPosition);
617 if (style != selectionStyle)
618 SVGResourcesCache::clientStyleChanged(parent()->renderer(), StyleDifferenceRepaint, *style);
620 // Eventually draw text using regular style from the end position of the selection to the end of the current chunk part
621 if (endPosition < static_cast<int>(fragment.length) && !paintSelectedTextOnly)
622 paintTextWithShadows(context, style, textRun, fragment, endPosition, fragment.length);
625 FloatRect SVGInlineTextBox::calculateBoundaries() const
629 float scalingFactor = renderer().scalingFactor();
630 ASSERT(scalingFactor);
632 float baseline = renderer().scaledFont().fontMetrics().floatAscent() / scalingFactor;
634 AffineTransform fragmentTransform;
635 unsigned textFragmentsSize = m_textFragments.size();
636 for (unsigned i = 0; i < textFragmentsSize; ++i) {
637 const SVGTextFragment& fragment = m_textFragments.at(i);
638 FloatRect fragmentRect(fragment.x, fragment.y - baseline, fragment.width, fragment.height);
639 fragment.buildFragmentTransform(fragmentTransform);
640 if (!fragmentTransform.isIdentity())
641 fragmentRect = fragmentTransform.mapRect(fragmentRect);
643 textRect.unite(fragmentRect);
649 bool SVGInlineTextBox::nodeAtPoint(const HitTestRequest& request, HitTestResult& result, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, LayoutUnit, LayoutUnit, HitTestAction)
651 // FIXME: integrate with InlineTextBox::nodeAtPoint better.
652 ASSERT(!isLineBreak());
654 PointerEventsHitRules hitRules(PointerEventsHitRules::SVG_TEXT_HITTESTING, request, renderer().style().pointerEvents());
655 bool isVisible = renderer().style().visibility() == VISIBLE;
656 if (isVisible || !hitRules.requireVisible) {
657 if ((hitRules.canHitStroke && (renderer().style().svgStyle().hasStroke() || !hitRules.requireStroke))
658 || (hitRules.canHitFill && (renderer().style().svgStyle().hasFill() || !hitRules.requireFill))) {
659 FloatPoint boxOrigin(x(), y());
660 boxOrigin.moveBy(accumulatedOffset);
661 FloatRect rect(boxOrigin, size());
662 if (locationInContainer.intersects(rect)) {
664 float scalingFactor = renderer().scalingFactor();
665 ASSERT(scalingFactor);
667 float baseline = renderer().scaledFont().fontMetrics().floatAscent() / scalingFactor;
669 AffineTransform fragmentTransform;
670 for (auto& fragment : m_textFragments) {
671 FloatQuad fragmentQuad(FloatRect(fragment.x, fragment.y - baseline, fragment.width, fragment.height));
672 fragment.buildFragmentTransform(fragmentTransform);
673 if (!fragmentTransform.isIdentity())
674 fragmentQuad = fragmentTransform.mapQuad(fragmentQuad);
676 if (fragmentQuad.containsPoint(locationInContainer.point())) {
677 renderer().updateHitTestResult(result, locationInContainer.point() - toLayoutSize(accumulatedOffset));
678 if (!result.addNodeToRectBasedTestResult(&renderer().textNode(), request, locationInContainer, rect))
688 } // namespace WebCore