Chromium Code Reviews| Index: Source/core/paint/SVGInlineTextBoxPainter.cpp |
| diff --git a/Source/core/rendering/svg/SVGInlineTextBox.cpp b/Source/core/paint/SVGInlineTextBoxPainter.cpp |
| similarity index 56% |
| copy from Source/core/rendering/svg/SVGInlineTextBox.cpp |
| copy to Source/core/paint/SVGInlineTextBoxPainter.cpp |
| index f8e6350717b59862a14fa0831c83d64691201d0a..0c36b51c9dabeb1a61b10aa2662fb406cf1aed01 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,20 @@ |
| #include "core/frame/FrameView.h" |
| #include "core/frame/LocalFrame.h" |
| #include "core/paint/InlinePainter.h" |
| -#include "core/rendering/HitTestResult.h" |
| -#include "core/rendering/InlineFlowBox.h" |
| +#include "core/paint/InlineTextBoxPainter.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 +32,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.phase == PaintPhaseForeground || paintInfo.phase == PaintPhaseSelection); |
| ASSERT(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); |
| - 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 +86,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); |
| @@ -344,137 +139,58 @@ void SVGInlineTextBox::paint(PaintInfo& paintInfo, const LayoutPoint& paintOffse |
| InlinePainter(toRenderInline(parentRenderer)).paintOutline(paintInfo, paintOffset); |
| } |
| -class PaintingResourceScope { |
| -public: |
| - PaintingResourceScope(RenderObject& renderer) |
| - : m_renderer(renderer) |
| - , m_paintingResource(0) |
| - { |
| - } |
| - ~PaintingResourceScope() { ASSERT(!m_paintingResource); } |
| - |
| - bool acquirePaintingResource(GraphicsContext*&, RenderStyle*, RenderSVGResourceModeFlags); |
| - void releasePaintingResource(GraphicsContext*&); |
| - |
| -private: |
| - RenderObject& m_renderer; |
| - RenderSVGResource* m_paintingResource; |
| -}; |
| - |
| -bool PaintingResourceScope::acquirePaintingResource(GraphicsContext*& context, RenderStyle* style, RenderSVGResourceModeFlags resourceModeFlags) |
| -{ |
| - ASSERT(style); |
| - ASSERT(resourceModeFlags != ApplyToDefaultMode); |
| - RenderSVGResourceMode resourceMode = static_cast<RenderSVGResourceMode>(resourceModeFlags & (ApplyToFillMode | ApplyToStrokeMode)); |
| - ASSERT(resourceMode == ApplyToFillMode || resourceMode == ApplyToStrokeMode); |
| - |
| - bool hasFallback = false; |
| - m_paintingResource = RenderSVGResource::requestPaintingResource(resourceMode, &m_renderer, style, hasFallback); |
| - if (!m_paintingResource) |
| - return false; |
| - |
| - if (!m_paintingResource->applyResource(&m_renderer, style, context, resourceModeFlags)) { |
| - if (hasFallback) { |
| - m_paintingResource = RenderSVGResource::sharedSolidPaintingResource(); |
| - m_paintingResource->applyResource(&m_renderer, style, context, resourceModeFlags); |
| - } |
| - } |
| - return true; |
| -} |
| - |
| -void PaintingResourceScope::releasePaintingResource(GraphicsContext*& context) |
| +void SVGInlineTextBoxPainter::paintSelectionBackground(PaintInfo& paintInfo) |
| { |
| - ASSERT(m_paintingResource); |
| + ASSERT(paintInfo.shouldPaintWithinRoot(&renderer())); |
| + ASSERT(paintInfo.phase == PaintPhaseForeground || paintInfo.phase == PaintPhaseSelection); |
| + ASSERT(m_svgInlineTextBox.truncation() == cNoTruncation); |
| - m_paintingResource->postApplyResource(&m_renderer, context); |
| - m_paintingResource = 0; |
| -} |
| + if (m_svgInlineTextBox.renderer().style()->visibility() != VISIBLE) |
| + return; |
| -TextRun SVGInlineTextBox::constructTextRun(RenderStyle* style, const SVGTextFragment& fragment) const |
| -{ |
| - ASSERT(style); |
| + RenderObject& parentRenderer = m_svgInlineTextBox.parent()->renderer(); |
| + ASSERT(!parentRenderer.document().printing()); |
| - 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); |
| - } |
| + // Determine whether or not we're selected. |
| + bool paintSelectedTextOnly = paintInfo.phase == PaintPhaseSelection; |
| + bool hasSelection = m_svgInlineTextBox.selectionState() != RenderObject::SelectionNone; |
| + if (!hasSelection || paintSelectedTextOnly) |
| + return; |
| - if (textRunNeedsRenderingContext(style->font())) |
| - run.setRenderingContext(SVGTextRunRenderingContext::create(text)); |
| + Color backgroundColor = m_svgInlineTextBox.renderer().selectionBackgroundColor(); |
| + if (!backgroundColor.alpha()) |
| + return; |
| - // We handle letter & word spacing ourselves. |
| - run.disableSpacing(); |
| + RenderSVGInlineText& textRenderer = toRenderSVGInlineText(m_svgInlineTextBox.renderer()); |
| + if (!textShouldBePainted(textRenderer)) |
| + 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; |
| -} |
| + RenderStyle* style = parentRenderer.style(); |
| + ASSERT(style); |
| -bool SVGInlineTextBox::mapStartEndPositionsIntoFragmentCoordinates(const SVGTextFragment& fragment, int& startPosition, int& endPosition) const |
| -{ |
| - if (startPosition >= endPosition) |
| - return false; |
| + int startPosition, endPosition; |
| + m_svgInlineTextBox.selectionStartEnd(startPosition, endPosition); |
| - int offset = static_cast<int>(fragment.characterOffset) - start(); |
| - int length = static_cast<int>(fragment.length); |
| + 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); |
| - if (startPosition >= offset + length || endPosition <= offset) |
| - return false; |
| + fragmentStartPosition = startPosition; |
| + fragmentEndPosition = endPosition; |
| + if (!m_svgInlineTextBox.mapStartEndPositionsIntoFragmentCoordinates(fragment, fragmentStartPosition, fragmentEndPosition)) |
| + continue; |
| - if (startPosition < offset) |
| - startPosition = 0; |
| - else |
| - startPosition -= offset; |
| + GraphicsContextStateSaver stateSaver(*paintInfo.context); |
| + fragment.buildFragmentTransform(fragmentTransform); |
| + if (!fragmentTransform.isIdentity()) |
| + paintInfo.context->concatCTM(fragmentTransform); |
| - if (endPosition > offset + length) |
| - endPosition = length; |
| - else { |
| - ASSERT(endPosition >= offset); |
| - endPosition -= offset; |
| + paintInfo.context->setFillColor(backgroundColor); |
| + paintInfo.context->fillRect(m_svgInlineTextBox.selectionRectForTextFragment(fragment, fragmentStartPosition, fragmentEndPosition, style), backgroundColor); |
| } |
| - |
| - ASSERT(startPosition < endPosition); |
| - return true; |
| -} |
| - |
| -// 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; |
| } |
| static inline RenderObject* findRenderObjectDefininingTextDecoration(InlineFlowBox* parentBox) |
| @@ -494,13 +210,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); |
| @@ -527,7 +243,77 @@ 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; |
| +} |
| + |
| +class PaintingResourceScope { |
| +public: |
| + PaintingResourceScope(RenderObject& renderer) |
| + : m_renderer(renderer) |
| + , m_paintingResource(0) |
| + { |
| + } |
| + ~PaintingResourceScope() { ASSERT(!m_paintingResource); } |
| + |
| + bool acquirePaintingResource(GraphicsContext*&, RenderStyle*, RenderSVGResourceModeFlags); |
| + void releasePaintingResource(GraphicsContext*&); |
| + |
| +private: |
| + RenderObject& m_renderer; |
| + RenderSVGResource* m_paintingResource; |
| +}; |
| + |
| +bool PaintingResourceScope::acquirePaintingResource(GraphicsContext*& context, RenderStyle* style, RenderSVGResourceModeFlags resourceModeFlags) |
| +{ |
| + ASSERT(style); |
| + ASSERT(resourceModeFlags != ApplyToDefaultMode); |
|
fs
2014/10/06 08:34:53
...and here (https://codereview.chromium.org/62239
|
| + RenderSVGResourceMode resourceMode = static_cast<RenderSVGResourceMode>(resourceModeFlags & (ApplyToFillMode | ApplyToStrokeMode)); |
| + ASSERT(resourceMode == ApplyToFillMode || resourceMode == ApplyToStrokeMode); |
| + |
| + bool hasFallback = false; |
| + m_paintingResource = RenderSVGResource::requestPaintingResource(resourceMode, &m_renderer, style, hasFallback); |
| + if (!m_paintingResource) |
| + return false; |
| + |
| + if (!m_paintingResource->applyResource(&m_renderer, style, context, resourceModeFlags)) { |
| + if (hasFallback) { |
| + m_paintingResource = RenderSVGResource::sharedSolidPaintingResource(); |
| + m_paintingResource->applyResource(&m_renderer, style, context, resourceModeFlags); |
| + } |
| + } |
| + return true; |
| +} |
| + |
| +void PaintingResourceScope::releasePaintingResource(GraphicsContext*& context) |
| +{ |
| + ASSERT(m_paintingResource); |
| + |
| + m_paintingResource->postApplyResource(&m_renderer, context); |
| + m_paintingResource = 0; |
| +} |
| + |
| + |
| +void SVGInlineTextBoxPainter::paintDecorationWithStyle(GraphicsContext* context, TextDecoration decoration, |
| const SVGTextFragment& fragment, RenderObject* decorationRenderer, RenderSVGResourceModeFlags resourceMode) |
| { |
| ASSERT(resourceMode != ApplyToDefaultMode); |
| @@ -558,11 +344,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); |
| @@ -586,7 +372,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); |
| @@ -609,7 +395,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) |
| { |
| @@ -619,12 +405,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; |
| @@ -638,7 +424,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); |
| @@ -646,7 +432,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 |
| @@ -654,18 +440,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; |
| @@ -695,7 +476,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(); |
| @@ -714,53 +495,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 |