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 Computer, Inc
6 * Copyright (C) 2009 Google, Inc.
7 * Copyright (C) 2011 Renata Hodovan <reni@webkit.org>
8 * Copyright (C) 2011 University of Szeged
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.
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.
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.
26 #ifndef RenderSVGShape_h
27 #define RenderSVGShape_h
29 #include "core/rendering/svg/RenderSVGModelObject.h"
30 #include "core/rendering/svg/SVGMarkerData.h"
31 #include "platform/geometry/FloatRect.h"
32 #include "platform/transforms/AffineTransform.h"
33 #include "wtf/OwnPtr.h"
34 #include "wtf/Vector.h"
39 class GraphicsContextStateSaver;
40 class PointerEventsHitRules;
41 class SVGGraphicsElement;
43 class RenderSVGShape : public RenderSVGModelObject {
45 explicit RenderSVGShape(SVGGraphicsElement*);
46 RenderSVGShape(SVGGraphicsElement*, Path*, bool);
47 virtual ~RenderSVGShape();
49 void setNeedsShapeUpdate() { m_needsShapeUpdate = true; }
50 virtual void setNeedsBoundariesUpdate() OVERRIDE FINAL { m_needsBoundariesUpdate = true; }
51 virtual void setNeedsTransformUpdate() OVERRIDE FINAL { m_needsTransformUpdate = true; }
52 virtual void fillShape(GraphicsContext*) const;
53 virtual void strokeShape(GraphicsContext*) const;
55 bool nodeAtFloatPointInternal(const HitTestRequest&, const FloatPoint&, PointerEventsHitRules);
63 virtual bool isShapeEmpty() const { return path().isEmpty(); }
66 virtual void updateShapeFromElement();
67 virtual bool shapeDependentStrokeContains(const FloatPoint&);
68 virtual bool shapeDependentFillContains(const FloatPoint&, const WindRule) const;
69 float strokeWidth() const;
70 bool hasPath() const { return m_path.get(); }
71 bool hasSmoothStroke() const;
73 bool hasNonScalingStroke() const { return style()->svgStyle().vectorEffect() == VE_NON_SCALING_STROKE; }
74 AffineTransform nonScalingStrokeTransform() const;
75 Path* nonScalingStrokePath(const Path*, const AffineTransform&) const;
77 FloatRect m_fillBoundingBox;
78 FloatRect m_strokeBoundingBox;
81 // Hit-detection separated for the fill and the stroke
82 bool fillContains(const FloatPoint&, bool requiresFill = true, const WindRule fillRule = RULE_NONZERO);
83 bool strokeContains(const FloatPoint&, bool requiresStroke = true);
85 virtual FloatRect paintInvalidationRectInLocalCoordinates() const OVERRIDE FINAL { return m_paintInvalidationBoundingBox; }
86 virtual const AffineTransform& localToParentTransform() const OVERRIDE FINAL { return m_localTransform; }
87 virtual AffineTransform localTransform() const OVERRIDE FINAL { return m_localTransform; }
89 virtual bool isSVGShape() const OVERRIDE FINAL { return true; }
90 virtual const char* renderName() const OVERRIDE { return "RenderSVGShape"; }
92 virtual void layout() OVERRIDE FINAL;
93 virtual void paint(PaintInfo&, const LayoutPoint&) OVERRIDE FINAL;
94 virtual void addFocusRingRects(Vector<LayoutRect>&, const LayoutPoint& additionalOffset, const RenderLayerModelObject* paintContainer) const OVERRIDE FINAL;
96 virtual bool nodeAtFloatPoint(const HitTestRequest&, HitTestResult&, const FloatPoint& pointInParent, HitTestAction) OVERRIDE FINAL;
98 virtual FloatRect objectBoundingBox() const OVERRIDE FINAL { return m_fillBoundingBox; }
99 virtual FloatRect strokeBoundingBox() const OVERRIDE FINAL { return m_strokeBoundingBox; }
100 FloatRect calculateObjectBoundingBox() const;
101 FloatRect calculateStrokeBoundingBox() const;
102 void updatePaintInvalidationBoundingBox();
104 bool setupNonScalingStrokeContext(AffineTransform&, GraphicsContextStateSaver&);
106 bool shouldGenerateMarkerPositions() const;
107 FloatRect markerRect(float strokeWidth) const;
108 void processMarkerPositions();
110 void fillShape(RenderStyle*, GraphicsContext*);
111 void strokeShape(RenderStyle*, GraphicsContext*);
112 void drawMarkers(PaintInfo&);
115 FloatRect m_paintInvalidationBoundingBox;
116 AffineTransform m_localTransform;
118 Vector<MarkerPosition> m_markerPositions;
120 bool m_needsBoundariesUpdate : 1;
121 bool m_needsShapeUpdate : 1;
122 bool m_needsTransformUpdate : 1;
125 DEFINE_RENDER_OBJECT_TYPE_CASTS(RenderSVGShape, isSVGShape());