tagging audio streams and changing audio sink to pulseaudio
[profile/ivi/webkit-efl.git] / Source / WebCore / platform / graphics / Path.h
1 /*
2  * Copyright (C) 2003, 2006, 2009 Apple Inc. All rights reserved.
3  *               2006 Rob Buis <buis@kde.org>
4  * Copyright (C) 2007-2008 Torch Mobile, Inc.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
16  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
19  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
23  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
26  */
27
28 #ifndef Path_h
29 #define Path_h
30
31 #include "RoundedRect.h"
32 #include "WindRule.h"
33 #include <wtf/FastAllocBase.h>
34 #include <wtf/Forward.h>
35
36 #if USE(CG)
37 typedef struct CGPath PlatformPath;
38 #elif PLATFORM(OPENVG)
39 namespace WebCore {
40 class PlatformPathOpenVG;
41 }
42 typedef WebCore::PlatformPathOpenVG PlatformPath;
43 #elif PLATFORM(QT)
44 #include <qpainterpath.h>
45 typedef QPainterPath PlatformPath;
46 #elif PLATFORM(WX) && USE(WXGC)
47 class wxGraphicsPath;
48 typedef wxGraphicsPath PlatformPath;
49 #elif USE(CAIRO)
50 namespace WebCore {
51 class CairoPath;
52 }
53 typedef WebCore::CairoPath PlatformPath;
54 #elif USE(SKIA)
55 class SkPath;
56 typedef SkPath PlatformPath;
57 #elif OS(WINCE)
58 namespace WebCore {
59     class PlatformPath;
60 }
61 typedef WebCore::PlatformPath PlatformPath;
62 #else
63 typedef void PlatformPath;
64 #endif
65
66 #if PLATFORM(QT)
67 /* QPainterPath is valued based */
68 typedef PlatformPath PlatformPathPtr;
69 #else
70 typedef PlatformPath* PlatformPathPtr;
71 #endif
72
73 namespace WebCore {
74
75     class AffineTransform;
76     class FloatPoint;
77     class FloatRect;
78     class FloatSize;
79     class GraphicsContext;
80     class StrokeStyleApplier;
81
82     enum PathElementType {
83         PathElementMoveToPoint, // The points member will contain 1 value.
84         PathElementAddLineToPoint, // The points member will contain 1 value.
85         PathElementAddQuadCurveToPoint, // The points member will contain 2 values.
86         PathElementAddCurveToPoint, // The points member will contain 3 values.
87         PathElementCloseSubpath // The points member will contain no values.
88     };
89
90     // The points in the sturcture are the same as those that would be used with the
91     // add... method. For example, a line returns the endpoint, while a cubic returns
92     // two tangent points and the endpoint.
93     struct PathElement {
94         PathElementType type;
95         FloatPoint* points;
96     };
97
98     typedef void (*PathApplierFunction)(void* info, const PathElement*);
99
100     class Path {
101         WTF_MAKE_FAST_ALLOCATED;
102     public:
103         Path();
104         ~Path();
105
106         Path(const Path&);
107         Path& operator=(const Path&);
108
109         bool contains(const FloatPoint&, WindRule rule = RULE_NONZERO) const;
110         bool strokeContains(StrokeStyleApplier*, const FloatPoint&) const;
111         // fastBoundingRect() should equal or contain boundingRect(); boundingRect()
112         // should perfectly bound the points within the path.
113         FloatRect boundingRect() const;
114         FloatRect fastBoundingRect() const;
115         FloatRect strokeBoundingRect(StrokeStyleApplier* = 0) const;
116         
117         float length() const;
118         FloatPoint pointAtLength(float length, bool& ok) const;
119         float normalAngleAtLength(float length, bool& ok) const;
120
121         void clear();
122         bool isEmpty() const;
123         // Gets the current point of the current path, which is conceptually the final point reached by the path so far.
124         // Note the Path can be empty (isEmpty() == true) and still have a current point.
125         bool hasCurrentPoint() const;
126         FloatPoint currentPoint() const;
127
128         void moveTo(const FloatPoint&);
129         void addLineTo(const FloatPoint&);
130         void addQuadCurveTo(const FloatPoint& controlPoint, const FloatPoint& endPoint);
131         void addBezierCurveTo(const FloatPoint& controlPoint1, const FloatPoint& controlPoint2, const FloatPoint& endPoint);
132         void addArcTo(const FloatPoint&, const FloatPoint&, float radius);
133         void closeSubpath();
134
135         void addArc(const FloatPoint&, float radius, float startAngle, float endAngle, bool anticlockwise);
136         void addRect(const FloatRect&);
137         void addEllipse(const FloatRect&);
138
139         enum RoundedRectStrategy {
140             PreferNativeRoundedRect,
141             PreferBezierRoundedRect
142         };
143
144         void addRoundedRect(const FloatRect&, const FloatSize& roundingRadii, RoundedRectStrategy = PreferNativeRoundedRect);
145         void addRoundedRect(const FloatRect&, const FloatSize& topLeftRadius, const FloatSize& topRightRadius, const FloatSize& bottomLeftRadius, const FloatSize& bottomRightRadius, RoundedRectStrategy = PreferNativeRoundedRect);
146         void addRoundedRect(const RoundedRect&);
147
148         void translate(const FloatSize&);
149
150         PlatformPathPtr platformPath() const { return m_path; }
151
152         void apply(void* info, PathApplierFunction) const;
153         void transform(const AffineTransform&);
154
155         void addPathForRoundedRect(const FloatRect&, const FloatSize& topLeftRadius, const FloatSize& topRightRadius, const FloatSize& bottomLeftRadius, const FloatSize& bottomRightRadius, RoundedRectStrategy = PreferNativeRoundedRect);
156         void addBeziersForRoundedRect(const FloatRect&, const FloatSize& topLeftRadius, const FloatSize& topRightRadius, const FloatSize& bottomLeftRadius, const FloatSize& bottomRightRadius);
157
158 #if USE(CG)
159         void platformAddPathForRoundedRect(const FloatRect&, const FloatSize& topLeftRadius, const FloatSize& topRightRadius, const FloatSize& bottomLeftRadius, const FloatSize& bottomRightRadius);
160 #endif
161
162 #if PLATFORM(BLACKBERRY)
163         Path(const SkPath&);
164 #endif
165
166     private:
167         PlatformPathPtr m_path;
168     };
169
170 }
171
172 #endif