Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(316)

Unified Diff: Source/core/paint/SVGInlineTextBoxPainter.cpp

Issue 627773002: Move painting code from SVGInlineTextBox to SVGInlineTextBoxPainter. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fix debug build. Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/paint/SVGInlineTextBoxPainter.h ('k') | Source/core/rendering/InlineTextBox.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/paint/SVGInlineTextBoxPainter.cpp
diff --git a/Source/core/rendering/svg/SVGInlineTextBox.cpp b/Source/core/paint/SVGInlineTextBoxPainter.cpp
similarity index 55%
copy from Source/core/rendering/svg/SVGInlineTextBox.cpp
copy to Source/core/paint/SVGInlineTextBoxPainter.cpp
index 07c1c3191a7b7042e57585162d5f6a9a9273129d..95b716f5ad4c80cd26e9f3b9273649d6e3b9d4aa 100644
--- a/Source/core/rendering/svg/SVGInlineTextBox.cpp
+++ b/Source/core/paint/SVGInlineTextBoxPainter.cpp
@@ -1,26 +1,9 @@
-/**
- * Copyright (C) 2007 Rob Buis <buis@kde.org>
- * Copyright (C) 2007 Nikolas Zimmermann <zimmermann@kde.org>
- * Copyright (C) Research In Motion Limited 2010. All rights reserved.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public License
- * along with this library; see the file COPYING.LIB. If not, write to
- * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- */
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
#include "config.h"
-#include "core/rendering/svg/SVGInlineTextBox.h"
+#include "core/paint/SVGInlineTextBoxPainter.h"
#include "core/dom/DocumentMarkerController.h"
#include "core/dom/RenderedDocumentMarker.h"
@@ -28,154 +11,19 @@
#include "core/frame/LocalFrame.h"
#include "core/paint/InlinePainter.h"
#include "core/paint/InlineTextBoxPainter.h"
-#include "core/rendering/HitTestResult.h"
-#include "core/rendering/InlineFlowBox.h"
#include "core/rendering/PaintInfo.h"
-#include "core/rendering/PointerEventsHitRules.h"
#include "core/rendering/RenderInline.h"
#include "core/rendering/RenderTheme.h"
#include "core/rendering/style/ShadowList.h"
#include "core/rendering/svg/RenderSVGInlineText.h"
#include "core/rendering/svg/RenderSVGResource.h"
#include "core/rendering/svg/RenderSVGResourceSolidColor.h"
+#include "core/rendering/svg/SVGInlineTextBox.h"
#include "core/rendering/svg/SVGRenderSupport.h"
#include "core/rendering/svg/SVGResourcesCache.h"
-#include "core/rendering/svg/SVGTextRunRenderingContext.h"
-#include "platform/FloatConversion.h"
-#include "platform/fonts/FontCache.h"
-#include "platform/graphics/GraphicsContextStateSaver.h"
namespace blink {
-struct ExpectedSVGInlineTextBoxSize : public InlineTextBox {
- float float1;
- uint32_t bitfields : 1;
- Vector<SVGTextFragment> vector;
-};
-
-COMPILE_ASSERT(sizeof(SVGInlineTextBox) == sizeof(ExpectedSVGInlineTextBoxSize), SVGInlineTextBox_is_not_of_expected_size);
-
-SVGInlineTextBox::SVGInlineTextBox(RenderObject& object)
- : InlineTextBox(object)
- , m_logicalHeight(0)
- , m_startsNewTextChunk(false)
-{
-}
-
-void SVGInlineTextBox::dirtyLineBoxes()
-{
- InlineTextBox::dirtyLineBoxes();
-
- // Clear the now stale text fragments
- clearTextFragments();
-
- // And clear any following text fragments as the text on which they
- // depend may now no longer exist, or glyph positions may be wrong
- InlineTextBox* nextBox = nextTextBox();
- if (nextBox)
- nextBox->dirtyLineBoxes();
-}
-
-int SVGInlineTextBox::offsetForPosition(float, bool) const
-{
- // SVG doesn't use the standard offset <-> position selection system, as it's not suitable for SVGs complex needs.
- // vertical text selection, inline boxes spanning multiple lines (contrary to HTML, etc.)
- ASSERT_NOT_REACHED();
- return 0;
-}
-
-int SVGInlineTextBox::offsetForPositionInFragment(const SVGTextFragment& fragment, float position, bool includePartialGlyphs) const
-{
- RenderSVGInlineText& textRenderer = toRenderSVGInlineText(this->renderer());
-
- float scalingFactor = textRenderer.scalingFactor();
- ASSERT(scalingFactor);
-
- RenderStyle* style = textRenderer.style();
- ASSERT(style);
-
- TextRun textRun = constructTextRun(style, fragment);
-
- // Eventually handle lengthAdjust="spacingAndGlyphs".
- // FIXME: Handle vertical text.
- AffineTransform fragmentTransform;
- fragment.buildFragmentTransform(fragmentTransform);
- if (!fragmentTransform.isIdentity())
- textRun.setHorizontalGlyphStretch(narrowPrecisionToFloat(fragmentTransform.xScale()));
-
- return fragment.characterOffset - start() + textRenderer.scaledFont().offsetForPosition(textRun, position * scalingFactor, includePartialGlyphs);
-}
-
-float SVGInlineTextBox::positionForOffset(int) const
-{
- // SVG doesn't use the offset <-> position selection system.
- ASSERT_NOT_REACHED();
- return 0;
-}
-
-FloatRect SVGInlineTextBox::selectionRectForTextFragment(const SVGTextFragment& fragment, int startPosition, int endPosition, RenderStyle* style)
-{
- ASSERT(startPosition < endPosition);
- ASSERT(style);
-
- FontCachePurgePreventer fontCachePurgePreventer;
-
- RenderSVGInlineText& textRenderer = toRenderSVGInlineText(this->renderer());
-
- float scalingFactor = textRenderer.scalingFactor();
- ASSERT(scalingFactor);
-
- const Font& scaledFont = textRenderer.scaledFont();
- const FontMetrics& scaledFontMetrics = scaledFont.fontMetrics();
- FloatPoint textOrigin(fragment.x, fragment.y);
- if (scalingFactor != 1)
- textOrigin.scale(scalingFactor, scalingFactor);
-
- textOrigin.move(0, -scaledFontMetrics.floatAscent());
-
- FloatRect selectionRect = scaledFont.selectionRectForText(constructTextRun(style, fragment), textOrigin, fragment.height * scalingFactor, startPosition, endPosition);
- if (scalingFactor == 1)
- return selectionRect;
-
- selectionRect.scale(1 / scalingFactor);
- return selectionRect;
-}
-
-LayoutRect SVGInlineTextBox::localSelectionRect(int startPosition, int endPosition)
-{
- int boxStart = start();
- startPosition = std::max(startPosition - boxStart, 0);
- endPosition = std::min(endPosition - boxStart, static_cast<int>(len()));
- if (startPosition >= endPosition)
- return LayoutRect();
-
- RenderStyle* style = renderer().style();
- ASSERT(style);
-
- AffineTransform fragmentTransform;
- FloatRect selectionRect;
- int fragmentStartPosition = 0;
- int fragmentEndPosition = 0;
-
- unsigned textFragmentsSize = m_textFragments.size();
- for (unsigned i = 0; i < textFragmentsSize; ++i) {
- const SVGTextFragment& fragment = m_textFragments.at(i);
-
- fragmentStartPosition = startPosition;
- fragmentEndPosition = endPosition;
- if (!mapStartEndPositionsIntoFragmentCoordinates(fragment, fragmentStartPosition, fragmentEndPosition))
- continue;
-
- FloatRect fragmentRect = selectionRectForTextFragment(fragment, fragmentStartPosition, fragmentEndPosition, style);
- fragment.buildFragmentTransform(fragmentTransform);
- fragmentRect = fragmentTransform.mapRect(fragmentRect);
-
- selectionRect.unite(fragmentRect);
- }
-
- return enclosingIntRect(selectionRect);
-}
-
static inline bool textShouldBePainted(RenderSVGInlineText& textRenderer)
{
// Font::pixelSize(), returns FontDescription::computedPixelSize(), which returns "int(x + 0.5)".
@@ -183,87 +31,33 @@ static inline bool textShouldBePainted(RenderSVGInlineText& textRenderer)
return textRenderer.scaledFont().fontDescription().computedPixelSize();
}
-void SVGInlineTextBox::paintSelectionBackground(PaintInfo& paintInfo)
-{
- ASSERT(paintInfo.shouldPaintWithinRoot(&renderer()));
- ASSERT(paintInfo.phase == PaintPhaseForeground || paintInfo.phase == PaintPhaseSelection);
- ASSERT(truncation() == cNoTruncation);
-
- if (renderer().style()->visibility() != VISIBLE)
- return;
-
- RenderObject& parentRenderer = parent()->renderer();
- ASSERT(!parentRenderer.document().printing());
-
- // Determine whether or not we're selected.
- bool paintSelectedTextOnly = paintInfo.phase == PaintPhaseSelection;
- bool hasSelection = selectionState() != RenderObject::SelectionNone;
- if (!hasSelection || paintSelectedTextOnly)
- return;
-
- Color backgroundColor = renderer().selectionBackgroundColor();
- if (!backgroundColor.alpha())
- return;
-
- RenderSVGInlineText& textRenderer = toRenderSVGInlineText(this->renderer());
- if (!textShouldBePainted(textRenderer))
- return;
-
- RenderStyle* style = parentRenderer.style();
- ASSERT(style);
-
- int startPosition, endPosition;
- selectionStartEnd(startPosition, endPosition);
-
- int fragmentStartPosition = 0;
- int fragmentEndPosition = 0;
- AffineTransform fragmentTransform;
- unsigned textFragmentsSize = m_textFragments.size();
- for (unsigned i = 0; i < textFragmentsSize; ++i) {
- SVGTextFragment& fragment = m_textFragments.at(i);
-
- fragmentStartPosition = startPosition;
- fragmentEndPosition = endPosition;
- if (!mapStartEndPositionsIntoFragmentCoordinates(fragment, fragmentStartPosition, fragmentEndPosition))
- continue;
-
- GraphicsContextStateSaver stateSaver(*paintInfo.context);
- fragment.buildFragmentTransform(fragmentTransform);
- if (!fragmentTransform.isIdentity())
- paintInfo.context->concatCTM(fragmentTransform);
-
- paintInfo.context->setFillColor(backgroundColor);
- paintInfo.context->fillRect(selectionRectForTextFragment(fragment, fragmentStartPosition, fragmentEndPosition, style), backgroundColor);
- }
-}
-
-void SVGInlineTextBox::paint(PaintInfo& paintInfo, const LayoutPoint& paintOffset, LayoutUnit, LayoutUnit)
+void SVGInlineTextBoxPainter::paint(PaintInfo& paintInfo, const LayoutPoint& paintOffset)
{
- ASSERT(paintInfo.shouldPaintWithinRoot(&renderer()));
+ ASSERT(paintInfo.shouldPaintWithinRoot(&m_svgInlineTextBox.renderer()));
ASSERT(paintInfo.phase == PaintPhaseForeground || paintInfo.phase == PaintPhaseSelection);
- ASSERT(truncation() == cNoTruncation);
+ ASSERT(m_svgInlineTextBox.truncation() == cNoTruncation);
- if (renderer().style()->visibility() != VISIBLE)
+ if (m_svgInlineTextBox.renderer().style()->visibility() != VISIBLE)
return;
// Note: We're explicitely not supporting composition & custom underlines and custom highlighters - unlike InlineTextBox.
// If we ever need that for SVG, it's very easy to refactor and reuse the code.
- RenderObject& parentRenderer = parent()->renderer();
+ RenderObject& parentRenderer = m_svgInlineTextBox.parent()->renderer();
bool paintSelectedTextOnly = paintInfo.phase == PaintPhaseSelection;
- bool hasSelection = !parentRenderer.document().printing() && selectionState() != RenderObject::SelectionNone;
+ bool hasSelection = !parentRenderer.document().printing() && m_svgInlineTextBox.selectionState() != RenderObject::SelectionNone;
if (!hasSelection && paintSelectedTextOnly)
return;
- RenderSVGInlineText& textRenderer = toRenderSVGInlineText(this->renderer());
+ RenderSVGInlineText& textRenderer = toRenderSVGInlineText(m_svgInlineTextBox.renderer());
if (!textShouldBePainted(textRenderer))
return;
RenderStyle* style = parentRenderer.style();
ASSERT(style);
- InlineTextBoxPainter(*this).paintDocumentMarkers(paintInfo.context, paintOffset, style, textRenderer.scaledFont(), true);
+ InlineTextBoxPainter(m_svgInlineTextBox).paintDocumentMarkers(paintInfo.context, paintOffset, style, textRenderer.scaledFont(), true);
const SVGRenderStyle& svgStyle = style->svgStyle();
@@ -291,9 +85,9 @@ void SVGInlineTextBox::paint(PaintInfo& paintInfo, const LayoutPoint& paintOffse
}
AffineTransform fragmentTransform;
- unsigned textFragmentsSize = m_textFragments.size();
+ unsigned textFragmentsSize = m_svgInlineTextBox.textFragments().size();
for (unsigned i = 0; i < textFragmentsSize; ++i) {
- SVGTextFragment& fragment = m_textFragments.at(i);
+ SVGTextFragment& fragment = m_svgInlineTextBox.textFragments().at(i);
GraphicsContextStateSaver stateSaver(*paintInfo.context, false);
fragment.buildFragmentTransform(fragmentTransform);
@@ -389,91 +183,54 @@ void PaintingResourceScope::releasePaintingResource(GraphicsContext*& context)
m_paintingResource = 0;
}
-TextRun SVGInlineTextBox::constructTextRun(RenderStyle* style, const SVGTextFragment& fragment) const
+void SVGInlineTextBoxPainter::paintSelectionBackground(PaintInfo& paintInfo)
{
- ASSERT(style);
-
- RenderText* text = &renderer();
-
- // FIXME(crbug.com/264211): This should not be necessary but can occur if we
- // layout during layout. Remove this when 264211 is fixed.
- RELEASE_ASSERT(!text->needsLayout());
-
- TextRun run(static_cast<const LChar*>(0) // characters, will be set below if non-zero.
- , 0 // length, will be set below if non-zero.
- , 0 // xPos, only relevant with allowTabs=true
- , 0 // padding, only relevant for justified text, not relevant for SVG
- , TextRun::AllowTrailingExpansion
- , direction()
- , dirOverride() || style->rtlOrdering() == VisualOrder /* directionalOverride */);
-
- if (fragment.length) {
- if (text->is8Bit())
- run.setText(text->characters8() + fragment.characterOffset, fragment.length);
- else
- run.setText(text->characters16() + fragment.characterOffset, fragment.length);
- }
-
- if (textRunNeedsRenderingContext(style->font()))
- run.setRenderingContext(SVGTextRunRenderingContext::create(text));
-
- // We handle letter & word spacing ourselves.
- run.disableSpacing();
+ if (m_svgInlineTextBox.renderer().style()->visibility() != VISIBLE)
+ return;
- // Propagate the maximum length of the characters buffer to the TextRun, even when we're only processing a substring.
- run.setCharactersLength(text->textLength() - fragment.characterOffset);
- ASSERT(run.charactersLength() >= run.length());
- return run;
-}
+ RenderObject& parentRenderer = m_svgInlineTextBox.parent()->renderer();
+ ASSERT(!parentRenderer.document().printing());
-bool SVGInlineTextBox::mapStartEndPositionsIntoFragmentCoordinates(const SVGTextFragment& fragment, int& startPosition, int& endPosition) const
-{
- if (startPosition >= endPosition)
- return false;
+ // Determine whether or not we're selected.
+ bool paintSelectedTextOnly = paintInfo.phase == PaintPhaseSelection;
+ bool hasSelection = m_svgInlineTextBox.selectionState() != RenderObject::SelectionNone;
+ if (!hasSelection || paintSelectedTextOnly)
+ return;
- int offset = static_cast<int>(fragment.characterOffset) - start();
- int length = static_cast<int>(fragment.length);
+ Color backgroundColor = m_svgInlineTextBox.renderer().selectionBackgroundColor();
+ if (!backgroundColor.alpha())
+ return;
- if (startPosition >= offset + length || endPosition <= offset)
- return false;
+ RenderSVGInlineText& textRenderer = toRenderSVGInlineText(m_svgInlineTextBox.renderer());
+ if (!textShouldBePainted(textRenderer))
+ return;
- if (startPosition < offset)
- startPosition = 0;
- else
- startPosition -= offset;
+ RenderStyle* style = parentRenderer.style();
+ ASSERT(style);
- if (endPosition > offset + length)
- endPosition = length;
- else {
- ASSERT(endPosition >= offset);
- endPosition -= offset;
- }
+ int startPosition, endPosition;
+ m_svgInlineTextBox.selectionStartEnd(startPosition, endPosition);
- ASSERT(startPosition < endPosition);
- return true;
-}
+ int fragmentStartPosition = 0;
+ int fragmentEndPosition = 0;
+ AffineTransform fragmentTransform;
+ unsigned textFragmentsSize = m_svgInlineTextBox.textFragments().size();
+ for (unsigned i = 0; i < textFragmentsSize; ++i) {
+ SVGTextFragment& fragment = m_svgInlineTextBox.textFragments().at(i);
-// Offset from the baseline for |decoration|. Positive offsets are above the baseline.
-static inline float baselineOffsetForDecoration(TextDecoration decoration, const FontMetrics& fontMetrics, float thickness)
-{
- // FIXME: For SVG Fonts we need to use the attributes defined in the <font-face> if specified.
- // Compatible with Batik/Presto.
- if (decoration == TextDecorationUnderline)
- return -thickness * 1.5f;
- if (decoration == TextDecorationOverline)
- return fontMetrics.floatAscent() - thickness;
- if (decoration == TextDecorationLineThrough)
- return fontMetrics.floatAscent() * 3 / 8.0f;
+ fragmentStartPosition = startPosition;
+ fragmentEndPosition = endPosition;
+ if (!m_svgInlineTextBox.mapStartEndPositionsIntoFragmentCoordinates(fragment, fragmentStartPosition, fragmentEndPosition))
+ continue;
- ASSERT_NOT_REACHED();
- return 0.0f;
-}
+ GraphicsContextStateSaver stateSaver(*paintInfo.context);
+ fragment.buildFragmentTransform(fragmentTransform);
+ if (!fragmentTransform.isIdentity())
+ paintInfo.context->concatCTM(fragmentTransform);
-static inline float thicknessForDecoration(TextDecoration, const Font& font)
-{
- // FIXME: For SVG Fonts we need to use the attributes defined in the <font-face> if specified.
- // Compatible with Batik/Presto
- return font.fontDescription().computedSize() / 20.0f;
+ paintInfo.context->setFillColor(backgroundColor);
+ paintInfo.context->fillRect(m_svgInlineTextBox.selectionRectForTextFragment(fragment, fragmentStartPosition, fragmentEndPosition, style), backgroundColor);
+ }
}
static inline RenderObject* findRenderObjectDefininingTextDecoration(InlineFlowBox* parentBox)
@@ -493,13 +250,13 @@ static inline RenderObject* findRenderObjectDefininingTextDecoration(InlineFlowB
return renderer;
}
-void SVGInlineTextBox::paintDecoration(GraphicsContext* context, TextDecoration decoration, const SVGTextFragment& fragment)
+void SVGInlineTextBoxPainter::paintDecoration(GraphicsContext* context, TextDecoration decoration, const SVGTextFragment& fragment)
{
- if (renderer().style()->textDecorationsInEffect() == TextDecorationNone)
+ if (m_svgInlineTextBox.renderer().style()->textDecorationsInEffect() == TextDecorationNone)
return;
// Find out which render style defined the text-decoration, as its fill/stroke properties have to be used for drawing instead of ours.
- RenderObject* decorationRenderer = findRenderObjectDefininingTextDecoration(parent());
+ RenderObject* decorationRenderer = findRenderObjectDefininingTextDecoration(m_svgInlineTextBox.parent());
RenderStyle* decorationStyle = decorationRenderer->style();
ASSERT(decorationStyle);
@@ -526,7 +283,30 @@ void SVGInlineTextBox::paintDecoration(GraphicsContext* context, TextDecoration
}
}
-void SVGInlineTextBox::paintDecorationWithStyle(GraphicsContext* context, TextDecoration decoration,
+// Offset from the baseline for |decoration|. Positive offsets are above the baseline.
+static inline float baselineOffsetForDecoration(TextDecoration decoration, const FontMetrics& fontMetrics, float thickness)
+{
+ // FIXME: For SVG Fonts we need to use the attributes defined in the <font-face> if specified.
+ // Compatible with Batik/Presto.
+ if (decoration == TextDecorationUnderline)
+ return -thickness * 1.5f;
+ if (decoration == TextDecorationOverline)
+ return fontMetrics.floatAscent() - thickness;
+ if (decoration == TextDecorationLineThrough)
+ return fontMetrics.floatAscent() * 3 / 8.0f;
+
+ ASSERT_NOT_REACHED();
+ return 0.0f;
+}
+
+static inline float thicknessForDecoration(TextDecoration, const Font& font)
+{
+ // FIXME: For SVG Fonts we need to use the attributes defined in the <font-face> if specified.
+ // Compatible with Batik/Presto
+ return font.fontDescription().computedSize() / 20.0f;
+}
+
+void SVGInlineTextBoxPainter::paintDecorationWithStyle(GraphicsContext* context, TextDecoration decoration,
const SVGTextFragment& fragment, RenderObject* decorationRenderer, RenderSVGResourceModeFlags resourceMode)
{
RenderStyle* decorationStyle = decorationRenderer->style();
@@ -555,11 +335,11 @@ void SVGInlineTextBox::paintDecorationWithStyle(GraphicsContext* context, TextDe
}
}
-void SVGInlineTextBox::paintTextWithShadows(GraphicsContext* context, RenderStyle* style,
+void SVGInlineTextBoxPainter::paintTextWithShadows(GraphicsContext* context, RenderStyle* style,
TextRun& textRun, const SVGTextFragment& fragment, int startPosition, int endPosition,
RenderSVGResourceModeFlags resourceMode)
{
- RenderSVGInlineText& textRenderer = toRenderSVGInlineText(this->renderer());
+ RenderSVGInlineText& textRenderer = toRenderSVGInlineText(m_svgInlineTextBox.renderer());
float scalingFactor = textRenderer.scalingFactor();
ASSERT(scalingFactor);
@@ -583,7 +363,7 @@ void SVGInlineTextBox::paintTextWithShadows(GraphicsContext* context, RenderStyl
if (hasShadow)
context->setDrawLooper(shadowList->createDrawLooper(DrawLooperBuilder::ShadowRespectsAlpha));
- PaintingResourceScope resourceScope(parent()->renderer());
+ PaintingResourceScope resourceScope(m_svgInlineTextBox.parent()->renderer());
if (resourceScope.acquirePaintingResource(context, style, resourceMode)) {
if (scalingFactor != 1 && resourceMode & ApplyToStrokeMode)
context->setStrokeThickness(context->strokeThickness() * scalingFactor);
@@ -606,7 +386,7 @@ void SVGInlineTextBox::paintTextWithShadows(GraphicsContext* context, RenderStyl
context->clearShadow();
}
-void SVGInlineTextBox::paintText(GraphicsContext* context, RenderStyle* style,
+void SVGInlineTextBoxPainter::paintText(GraphicsContext* context, RenderStyle* style,
RenderStyle* selectionStyle, const SVGTextFragment& fragment,
RenderSVGResourceModeFlags resourceMode, bool hasSelection, bool paintSelectedTextOnly)
{
@@ -616,12 +396,12 @@ void SVGInlineTextBox::paintText(GraphicsContext* context, RenderStyle* style,
int startPosition = 0;
int endPosition = 0;
if (hasSelection) {
- selectionStartEnd(startPosition, endPosition);
- hasSelection = mapStartEndPositionsIntoFragmentCoordinates(fragment, startPosition, endPosition);
+ m_svgInlineTextBox.selectionStartEnd(startPosition, endPosition);
+ hasSelection = m_svgInlineTextBox.mapStartEndPositionsIntoFragmentCoordinates(fragment, startPosition, endPosition);
}
// Fast path if there is no selection, just draw the whole chunk part using the regular style
- TextRun textRun = constructTextRun(style, fragment);
+ TextRun textRun = m_svgInlineTextBox.constructTextRun(style, fragment);
if (!hasSelection || startPosition >= endPosition) {
paintTextWithShadows(context, style, textRun, fragment, 0, fragment.length, resourceMode);
return;
@@ -635,7 +415,7 @@ void SVGInlineTextBox::paintText(GraphicsContext* context, RenderStyle* style,
if (style != selectionStyle) {
StyleDifference diff;
diff.setNeedsPaintInvalidationObject();
- SVGResourcesCache::clientStyleChanged(&parent()->renderer(), diff, selectionStyle);
+ SVGResourcesCache::clientStyleChanged(&m_svgInlineTextBox.parent()->renderer(), diff, selectionStyle);
}
paintTextWithShadows(context, selectionStyle, textRun, fragment, startPosition, endPosition, resourceMode);
@@ -643,7 +423,7 @@ void SVGInlineTextBox::paintText(GraphicsContext* context, RenderStyle* style,
if (style != selectionStyle) {
StyleDifference diff;
diff.setNeedsPaintInvalidationObject();
- SVGResourcesCache::clientStyleChanged(&parent()->renderer(), diff, style);
+ SVGResourcesCache::clientStyleChanged(&m_svgInlineTextBox.parent()->renderer(), diff, style);
}
// Eventually draw text using regular style from the end position of the selection to the end of the current chunk part
@@ -651,18 +431,13 @@ void SVGInlineTextBox::paintText(GraphicsContext* context, RenderStyle* style,
paintTextWithShadows(context, style, textRun, fragment, endPosition, fragment.length, resourceMode);
}
-void SVGInlineTextBox::paintDocumentMarker(GraphicsContext*, const FloatPoint&, DocumentMarker*, RenderStyle*, const Font&, bool)
-{
- // SVG does not have support for generic document markers (e.g., spellchecking, etc).
-}
-
-void SVGInlineTextBox::paintTextMatchMarker(GraphicsContext* context, const FloatPoint&, DocumentMarker* marker, RenderStyle* style, const Font& font)
+void SVGInlineTextBoxPainter::paintTextMatchMarker(GraphicsContext* context, const FloatPoint&, DocumentMarker* marker, RenderStyle* style, const Font& font)
{
// SVG is only interested in the TextMatch markers.
if (marker->type() != DocumentMarker::TextMatch)
return;
- RenderSVGInlineText& textRenderer = toRenderSVGInlineText(this->renderer());
+ RenderSVGInlineText& textRenderer = toRenderSVGInlineText(m_svgInlineTextBox.renderer());
FloatRect markerRect;
AffineTransform fragmentTransform;
@@ -692,7 +467,7 @@ void SVGInlineTextBox::paintTextMatchMarker(GraphicsContext* context, const Floa
fragment.buildFragmentTransform(fragmentTransform);
// Draw the marker highlight.
- if (renderer().frame()->editor().markedTextMatchesAreHighlighted()) {
+ if (m_svgInlineTextBox.renderer().frame()->editor().markedTextMatchesAreHighlighted()) {
Color color = marker->activeMatch() ?
RenderTheme::theme().platformActiveTextSearchHighlightColor() :
RenderTheme::theme().platformInactiveTextSearchHighlightColor();
@@ -711,53 +486,4 @@ void SVGInlineTextBox::paintTextMatchMarker(GraphicsContext* context, const Floa
toRenderedDocumentMarker(marker)->setRenderedRect(textRenderer.localToAbsoluteQuad(markerRect).enclosingBoundingBox());
}
-FloatRect SVGInlineTextBox::calculateBoundaries() const
-{
- FloatRect textRect;
-
- RenderSVGInlineText& textRenderer = toRenderSVGInlineText(this->renderer());
-
- float scalingFactor = textRenderer.scalingFactor();
- ASSERT(scalingFactor);
-
- float baseline = textRenderer.scaledFont().fontMetrics().floatAscent() / scalingFactor;
-
- AffineTransform fragmentTransform;
- unsigned textFragmentsSize = m_textFragments.size();
- for (unsigned i = 0; i < textFragmentsSize; ++i) {
- const SVGTextFragment& fragment = m_textFragments.at(i);
- FloatRect fragmentRect(fragment.x, fragment.y - baseline, fragment.width, fragment.height);
- fragment.buildFragmentTransform(fragmentTransform);
- fragmentRect = fragmentTransform.mapRect(fragmentRect);
-
- textRect.unite(fragmentRect);
- }
-
- return textRect;
-}
-
-bool SVGInlineTextBox::nodeAtPoint(const HitTestRequest& request, HitTestResult& result, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, LayoutUnit, LayoutUnit)
-{
- // FIXME: integrate with InlineTextBox::nodeAtPoint better.
- ASSERT(!isLineBreak());
-
- PointerEventsHitRules hitRules(PointerEventsHitRules::SVG_TEXT_HITTESTING, request, renderer().style()->pointerEvents());
- bool isVisible = renderer().style()->visibility() == VISIBLE;
- if (isVisible || !hitRules.requireVisible) {
- if (hitRules.canHitBoundingBox
- || (hitRules.canHitStroke && (renderer().style()->svgStyle().hasStroke() || !hitRules.requireStroke))
- || (hitRules.canHitFill && (renderer().style()->svgStyle().hasFill() || !hitRules.requireFill))) {
- FloatPoint boxOrigin(x(), y());
- boxOrigin.moveBy(accumulatedOffset);
- FloatRect rect(boxOrigin, size());
- if (locationInContainer.intersects(rect)) {
- renderer().updateHitTestResult(result, locationInContainer.point() - toLayoutSize(accumulatedOffset));
- if (!result.addNodeToRectBasedTestResult(renderer().node(), request, locationInContainer, rect))
- return true;
- }
- }
- }
- return false;
-}
-
} // namespace blink
« no previous file with comments | « Source/core/paint/SVGInlineTextBoxPainter.h ('k') | Source/core/rendering/InlineTextBox.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698