| 1 | /* |
| 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. |
| 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 | |
| 22 | #pragma once |
| 23 | |
| 24 | #include "InlineTextBox.h" |
| 25 | #include "RenderSVGInlineText.h" |
| 26 | #include "RenderSVGResource.h" |
| 27 | |
| 28 | namespace WebCore { |
| 29 | |
| 30 | class RenderSVGResource; |
| 31 | class SVGRootInlineBox; |
| 32 | struct SVGTextFragment; |
| 33 | |
| 34 | class SVGInlineTextBox final : public InlineTextBox { |
| 35 | WTF_MAKE_ISO_ALLOCATED(SVGInlineTextBox); |
| 36 | public: |
| 37 | explicit SVGInlineTextBox(RenderSVGInlineText&); |
| 38 | |
| 39 | RenderSVGInlineText& renderer() const { return downcast<RenderSVGInlineText>(InlineTextBox::renderer()); } |
| 40 | |
| 41 | float virtualLogicalHeight() const override { return m_logicalHeight; } |
| 42 | void setLogicalHeight(float height) { m_logicalHeight = height; } |
| 43 | |
| 44 | int selectionTop() { return top(); } |
| 45 | int selectionHeight() { return static_cast<int>(ceilf(m_logicalHeight)); } |
| 46 | int offsetForPosition(float x, bool includePartialGlyphs = true) const override; |
| 47 | float positionForOffset(unsigned offset) const override; |
| 48 | |
| 49 | void paintSelectionBackground(PaintInfo&); |
| 50 | void paint(PaintInfo&, const LayoutPoint&, LayoutUnit lineTop, LayoutUnit lineBottom) override; |
| 51 | LayoutRect localSelectionRect(unsigned startPosition, unsigned endPosition) const override; |
| 52 | |
| 53 | bool mapStartEndPositionsIntoFragmentCoordinates(const SVGTextFragment&, unsigned& startPosition, unsigned& endPosition) const; |
| 54 | |
| 55 | FloatRect calculateBoundaries() const override; |
| 56 | |
| 57 | void clearTextFragments() { m_textFragments.clear(); } |
| 58 | Vector<SVGTextFragment>& textFragments() { return m_textFragments; } |
| 59 | const Vector<SVGTextFragment>& textFragments() const { return m_textFragments; } |
| 60 | |
| 61 | void dirtyOwnLineBoxes() override; |
| 62 | void dirtyLineBoxes() override; |
| 63 | |
| 64 | bool startsNewTextChunk() const { return m_startsNewTextChunk; } |
| 65 | void setStartsNewTextChunk(bool newTextChunk) { m_startsNewTextChunk = newTextChunk; } |
| 66 | |
| 67 | int offsetForPositionInFragment(const SVGTextFragment&, float position, bool includePartialGlyphs) const; |
| 68 | FloatRect selectionRectForTextFragment(const SVGTextFragment&, unsigned fragmentStartPosition, unsigned fragmentEndPosition, const RenderStyle&) const; |
| 69 | |
| 70 | OptionSet<RenderSVGResourceMode> paintingResourceMode() const { return OptionSet<RenderSVGResourceMode>::fromRaw(m_paintingResourceMode); } |
| 71 | void setPaintingResourceMode(OptionSet<RenderSVGResourceMode> mode) { m_paintingResourceMode = mode.toRaw(); } |
| 72 | |
| 73 | private: |
| 74 | bool isSVGInlineTextBox() const override { return true; } |
| 75 | |
| 76 | TextRun constructTextRun(const RenderStyle&, const SVGTextFragment&) const; |
| 77 | |
| 78 | bool acquirePaintingResource(GraphicsContext*&, float scalingFactor, RenderBoxModelObject&, const RenderStyle&); |
| 79 | void releasePaintingResource(GraphicsContext*&, const Path*); |
| 80 | |
| 81 | bool prepareGraphicsContextForTextPainting(GraphicsContext*&, float scalingFactor, const RenderStyle&); |
| 82 | void restoreGraphicsContextAfterTextPainting(GraphicsContext*&); |
| 83 | |
| 84 | void paintDecoration(GraphicsContext&, OptionSet<TextDecoration>, const SVGTextFragment&); |
| 85 | void paintDecorationWithStyle(GraphicsContext&, OptionSet<TextDecoration>, const SVGTextFragment&, RenderBoxModelObject& decorationRenderer); |
| 86 | void paintTextWithShadows(GraphicsContext&, const RenderStyle&, TextRun&, const SVGTextFragment&, unsigned startPosition, unsigned endPosition); |
| 87 | void paintText(GraphicsContext&, const RenderStyle&, const RenderStyle& selectionStyle, const SVGTextFragment&, bool hasSelection, bool paintSelectedTextOnly); |
| 88 | |
| 89 | bool nodeAtPoint(const HitTestRequest&, HitTestResult&, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, LayoutUnit lineTop, LayoutUnit lineBottom, HitTestAction) override; |
| 90 | |
| 91 | private: |
| 92 | float m_logicalHeight { 0 }; |
| 93 | unsigned m_paintingResourceMode : 4; // RenderSVGResourceMode |
| 94 | unsigned m_startsNewTextChunk : 1; |
| 95 | RenderSVGResource* m_paintingResource { nullptr }; |
| 96 | Vector<SVGTextFragment> m_textFragments; |
| 97 | }; |
| 98 | |
| 99 | } // namespace WebCore |
| 100 | |
| 101 | SPECIALIZE_TYPE_TRAITS_INLINE_BOX(SVGInlineTextBox, isSVGInlineTextBox()) |
| 102 | |