initial import
[vuplus_webkit] / Source / WebCore / rendering / svg / RenderSVGPath.h
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 Computer, Inc
6  * Copyright (C) 2009 Google, Inc.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public License
19  * along with this library; see the file COPYING.LIB.  If not, write to
20  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21  * Boston, MA 02110-1301, USA.
22  */
23
24 #ifndef RenderSVGPath_h
25 #define RenderSVGPath_h
26
27 #if ENABLE(SVG)
28 #include "AffineTransform.h"
29 #include "FloatRect.h"
30 #include "RenderSVGModelObject.h"
31 #include "SVGMarkerLayoutInfo.h"
32
33 namespace WebCore {
34
35 class FloatPoint;
36 class GraphicsContextStateSaver;
37 class RenderSVGContainer;
38 class SVGStyledTransformableElement;
39
40 class RenderSVGPath : public RenderSVGModelObject {
41 public:
42     explicit RenderSVGPath(SVGStyledTransformableElement*);
43     virtual ~RenderSVGPath();
44
45     const Path& path() const { return m_path; }
46     void setNeedsPathUpdate() { m_needsPathUpdate = true; }
47     virtual void setNeedsBoundariesUpdate() { m_needsBoundariesUpdate = true; }
48     virtual void setNeedsTransformUpdate() { m_needsTransformUpdate = true; }
49
50 private:
51     // Hit-detection seperated for the fill and the stroke
52     bool fillContains(const FloatPoint&, bool requiresFill = true, WindRule fillRule = RULE_NONZERO);
53     bool strokeContains(const FloatPoint&, bool requiresStroke = true);
54
55     virtual FloatRect objectBoundingBox() const { return m_fillBoundingBox; }
56     virtual FloatRect strokeBoundingBox() const { return m_strokeAndMarkerBoundingBox; }
57     virtual FloatRect repaintRectInLocalCoordinates() const { return m_repaintBoundingBox; }
58     virtual const AffineTransform& localToParentTransform() const { return m_localTransform; }
59
60     virtual bool isSVGPath() const { return true; }
61     virtual const char* renderName() const { return "RenderSVGPath"; }
62
63     virtual void layout();
64     virtual void paint(PaintInfo&, const LayoutPoint&);
65     virtual void addFocusRingRects(Vector<LayoutRect>&, const LayoutPoint&);
66
67     virtual bool nodeAtFloatPoint(const HitTestRequest&, HitTestResult&, const FloatPoint& pointInParent, HitTestAction);
68
69     FloatRect calculateMarkerBoundsIfNeeded();
70     void updateCachedBoundaries();
71
72     void setupSquareCapPath(Path*& usePath, int& applyMode);
73     bool setupNonScalingStrokePath(Path*& usePath, GraphicsContextStateSaver&);
74     bool shouldStrokeZeroLengthSubpath() const;
75     FloatRect zeroLengthSubpathRect() const;
76
77 private:
78     virtual AffineTransform localTransform() const { return m_localTransform; }
79     void fillAndStrokePath(GraphicsContext*);
80
81     bool m_needsBoundariesUpdate : 1;
82     bool m_needsPathUpdate : 1;
83     bool m_needsTransformUpdate : 1;
84
85     mutable Path m_path;
86     FloatRect m_fillBoundingBox;
87     FloatRect m_strokeAndMarkerBoundingBox;
88     FloatRect m_repaintBoundingBox;
89     SVGMarkerLayoutInfo m_markerLayoutInfo;
90     AffineTransform m_localTransform;
91 };
92
93 inline RenderSVGPath* toRenderSVGPath(RenderObject* object)
94 {
95     ASSERT(!object || object->isSVGPath());
96     return static_cast<RenderSVGPath*>(object);
97 }
98
99 inline const RenderSVGPath* toRenderSVGPath(const RenderObject* object)
100 {
101     ASSERT(!object || object->isSVGPath());
102     return static_cast<const RenderSVGPath*>(object);
103 }
104
105 // This will catch anyone doing an unnecessary cast.
106 void toRenderSVGPath(const RenderSVGPath*);
107
108 }
109
110 #endif // ENABLE(SVG)
111 #endif