| 1 | /* |
| 2 | * Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org> |
| 3 | * Copyright (C) 2004, 2005 Rob Buis <buis@kde.org> |
| 4 | * Copyright (C) 2005 Eric Seidel <eric@webkit.org> |
| 5 | * Copyright (C) 2006 Apple Inc. |
| 6 | * Copyright (C) 2009 Google, Inc. |
| 7 | * Copyright (C) 2011 Renata Hodovan <reni@webkit.org> |
| 8 | * Copyright (C) 2011 University of Szeged |
| 9 | * |
| 10 | * This library is free software; you can redistribute it and/or |
| 11 | * modify it under the terms of the GNU Library General Public |
| 12 | * License as published by the Free Software Foundation; either |
| 13 | * version 2 of the License, or (at your option) any later version. |
| 14 | * |
| 15 | * This library is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 18 | * Library General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU Library General Public License |
| 21 | * along with this library; see the file COPYING.LIB. If not, write to |
| 22 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 23 | * Boston, MA 02110-1301, USA. |
| 24 | */ |
| 25 | |
| 26 | #pragma once |
| 27 | |
| 28 | #include "AffineTransform.h" |
| 29 | #include "FloatRect.h" |
| 30 | #include "RenderSVGModelObject.h" |
| 31 | #include "SVGGraphicsElement.h" |
| 32 | #include "SVGMarkerData.h" |
| 33 | #include <memory> |
| 34 | #include <wtf/Vector.h> |
| 35 | |
| 36 | namespace WebCore { |
| 37 | |
| 38 | class FloatPoint; |
| 39 | class GraphicsContextStateSaver; |
| 40 | class RenderSVGContainer; |
| 41 | class RenderSVGPath; |
| 42 | class RenderSVGResource; |
| 43 | class SVGGraphicsElement; |
| 44 | |
| 45 | class RenderSVGShape : public RenderSVGModelObject { |
| 46 | WTF_MAKE_ISO_ALLOCATED(RenderSVGShape); |
| 47 | public: |
| 48 | enum PointCoordinateSpace { |
| 49 | GlobalCoordinateSpace, |
| 50 | LocalCoordinateSpace |
| 51 | }; |
| 52 | RenderSVGShape(SVGGraphicsElement&, RenderStyle&&); |
| 53 | virtual ~RenderSVGShape(); |
| 54 | |
| 55 | SVGGraphicsElement& graphicsElement() const { return downcast<SVGGraphicsElement>(RenderSVGModelObject::element()); } |
| 56 | |
| 57 | void setNeedsShapeUpdate() { m_needsShapeUpdate = true; } |
| 58 | void setNeedsBoundariesUpdate() final { m_needsBoundariesUpdate = true; } |
| 59 | bool needsBoundariesUpdate() final { return m_needsBoundariesUpdate; } |
| 60 | void setNeedsTransformUpdate() final { m_needsTransformUpdate = true; } |
| 61 | virtual void fillShape(GraphicsContext&) const; |
| 62 | virtual void strokeShape(GraphicsContext&) const; |
| 63 | virtual bool isRenderingDisabled() const = 0; |
| 64 | |
| 65 | bool isPointInFill(const FloatPoint&); |
| 66 | bool isPointInStroke(const FloatPoint&); |
| 67 | |
| 68 | float getTotalLength() const; |
| 69 | void getPointAtLength(FloatPoint&, float distance) const; |
| 70 | |
| 71 | bool hasPath() const { return m_path.get(); } |
| 72 | Path& path() const |
| 73 | { |
| 74 | ASSERT(m_path); |
| 75 | return *m_path; |
| 76 | } |
| 77 | void clearPath() { m_path = nullptr; } |
| 78 | |
| 79 | protected: |
| 80 | void element() const = delete; |
| 81 | |
| 82 | virtual void updateShapeFromElement(); |
| 83 | virtual bool isEmpty() const; |
| 84 | virtual bool shapeDependentStrokeContains(const FloatPoint&, PointCoordinateSpace = GlobalCoordinateSpace); |
| 85 | virtual bool shapeDependentFillContains(const FloatPoint&, const WindRule) const; |
| 86 | float strokeWidth() const; |
| 87 | bool hasSmoothStroke() const; |
| 88 | |
| 89 | bool hasNonScalingStroke() const { return style().svgStyle().vectorEffect() == VectorEffect::NonScalingStroke; } |
| 90 | AffineTransform nonScalingStrokeTransform() const; |
| 91 | Path* nonScalingStrokePath(const Path*, const AffineTransform&) const; |
| 92 | |
| 93 | FloatRect m_fillBoundingBox; |
| 94 | FloatRect m_strokeBoundingBox; |
| 95 | |
| 96 | private: |
| 97 | // Hit-detection separated for the fill and the stroke |
| 98 | bool fillContains(const FloatPoint&, bool requiresFill = true, const WindRule fillRule = WindRule::NonZero); |
| 99 | bool strokeContains(const FloatPoint&, bool requiresStroke = true); |
| 100 | |
| 101 | FloatRect repaintRectInLocalCoordinates() const final { return m_repaintBoundingBox; } |
| 102 | const AffineTransform& localToParentTransform() const final { return m_localTransform; } |
| 103 | AffineTransform localTransform() const final { return m_localTransform; } |
| 104 | |
| 105 | bool isSVGShape() const final { return true; } |
| 106 | bool canHaveChildren() const final { return false; } |
| 107 | const char* renderName() const override { return "RenderSVGShape" ; } |
| 108 | |
| 109 | void layout() final; |
| 110 | void paint(PaintInfo&, const LayoutPoint&) final; |
| 111 | void addFocusRingRects(Vector<LayoutRect>&, const LayoutPoint& additionalOffset, const RenderLayerModelObject* paintContainer = 0) final; |
| 112 | |
| 113 | bool nodeAtFloatPoint(const HitTestRequest&, HitTestResult&, const FloatPoint& pointInParent, HitTestAction) final; |
| 114 | |
| 115 | FloatRect objectBoundingBox() const final { return m_fillBoundingBox; } |
| 116 | FloatRect strokeBoundingBox() const final { return m_strokeBoundingBox; } |
| 117 | FloatRect calculateObjectBoundingBox() const; |
| 118 | FloatRect calculateStrokeBoundingBox() const; |
| 119 | void updateRepaintBoundingBox(); |
| 120 | |
| 121 | bool setupNonScalingStrokeContext(AffineTransform&, GraphicsContextStateSaver&); |
| 122 | |
| 123 | bool shouldGenerateMarkerPositions() const; |
| 124 | FloatRect markerRect(float strokeWidth) const; |
| 125 | void processMarkerPositions(); |
| 126 | |
| 127 | void fillShape(const RenderStyle&, GraphicsContext&); |
| 128 | void strokeShape(const RenderStyle&, GraphicsContext&); |
| 129 | void strokeShape(GraphicsContext&); |
| 130 | void fillStrokeMarkers(PaintInfo&); |
| 131 | void drawMarkers(PaintInfo&); |
| 132 | |
| 133 | private: |
| 134 | FloatRect m_repaintBoundingBox; |
| 135 | FloatRect m_repaintBoundingBoxExcludingShadow; |
| 136 | |
| 137 | bool m_needsBoundariesUpdate : 1; |
| 138 | bool m_needsShapeUpdate : 1; |
| 139 | bool m_needsTransformUpdate : 1; |
| 140 | |
| 141 | AffineTransform m_localTransform; |
| 142 | std::unique_ptr<Path> m_path; |
| 143 | Vector<MarkerPosition> m_markerPositions; |
| 144 | }; |
| 145 | |
| 146 | } // namespace WebCore |
| 147 | |
| 148 | SPECIALIZE_TYPE_TRAITS_RENDER_OBJECT(RenderSVGShape, isSVGShape()) |
| 149 | |