25eb7cb80399b4ff9bff3ce77c885d6f3921c217
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / rendering / svg / RenderSVGShape.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  * 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 #ifndef RenderSVGShape_h
27 #define RenderSVGShape_h
28
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"
35
36 namespace blink {
37
38 class FloatPoint;
39 class GraphicsContextStateSaver;
40 class PointerEventsHitRules;
41 class SVGGraphicsElement;
42
43 class RenderSVGShape : public RenderSVGModelObject {
44 public:
45     explicit RenderSVGShape(SVGGraphicsElement*);
46     RenderSVGShape(SVGGraphicsElement*, Path*, bool);
47     virtual ~RenderSVGShape();
48
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;
54
55     bool nodeAtFloatPointInternal(const HitTestRequest&, const FloatPoint&, PointerEventsHitRules);
56
57     Path& path() const
58     {
59         ASSERT(m_path);
60         return *m_path;
61     }
62
63     virtual bool isShapeEmpty() const { return path().isEmpty(); }
64
65 protected:
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;
72
73     bool hasNonScalingStroke() const { return style()->svgStyle().vectorEffect() == VE_NON_SCALING_STROKE; }
74     AffineTransform nonScalingStrokeTransform() const;
75     Path* nonScalingStrokePath(const Path*, const AffineTransform&) const;
76
77     FloatRect m_fillBoundingBox;
78     FloatRect m_strokeBoundingBox;
79
80 private:
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);
84
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; }
88
89     virtual bool isSVGShape() const OVERRIDE FINAL { return true; }
90     virtual const char* renderName() const OVERRIDE { return "RenderSVGShape"; }
91
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;
95
96     virtual bool nodeAtFloatPoint(const HitTestRequest&, HitTestResult&, const FloatPoint& pointInParent, HitTestAction) OVERRIDE FINAL;
97
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();
103
104     bool setupNonScalingStrokeContext(AffineTransform&, GraphicsContextStateSaver&);
105
106     bool shouldGenerateMarkerPositions() const;
107     FloatRect markerRect(float strokeWidth) const;
108     void processMarkerPositions();
109
110     void fillShape(RenderStyle*, GraphicsContext*);
111     void strokeShape(RenderStyle*, GraphicsContext*);
112     void drawMarkers(PaintInfo&);
113
114 private:
115     FloatRect m_paintInvalidationBoundingBox;
116     AffineTransform m_localTransform;
117     OwnPtr<Path> m_path;
118     Vector<MarkerPosition> m_markerPositions;
119
120     bool m_needsBoundariesUpdate : 1;
121     bool m_needsShapeUpdate : 1;
122     bool m_needsTransformUpdate : 1;
123 };
124
125 DEFINE_RENDER_OBJECT_TYPE_CASTS(RenderSVGShape, isSVGShape());
126
127 }
128
129 #endif