| OLD | NEW |
| (Empty) |
| 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 * Copyright (C) 2013 Google Inc. All rights reserved. | |
| 6 * | |
| 7 * Redistribution and use in source and binary forms, with or without | |
| 8 * modification, are permitted provided that the following conditions | |
| 9 * are met: | |
| 10 * 1. Redistributions of source code must retain the above copyright | |
| 11 * notice, this list of conditions and the following disclaimer. | |
| 12 * 2. Redistributions in binary form must reproduce the above copyright | |
| 13 * notice, this list of conditions and the following disclaimer in the | |
| 14 * documentation and/or other materials provided with the distribution. | |
| 15 * | |
| 16 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY | |
| 17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
| 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
| 19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR | |
| 20 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
| 21 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
| 22 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
| 23 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | |
| 24 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| 26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 27 */ | |
| 28 | |
| 29 #ifndef Path_h | |
| 30 #define Path_h | |
| 31 | |
| 32 #include "platform/geometry/RoundedRect.h" | |
| 33 #include "platform/graphics/WindRule.h" | |
| 34 #include "third_party/skia/include/core/SkPath.h" | |
| 35 #include "wtf/FastAllocBase.h" | |
| 36 #include "wtf/Forward.h" | |
| 37 | |
| 38 class SkPath; | |
| 39 | |
| 40 namespace WebCore { | |
| 41 | |
| 42 class AffineTransform; | |
| 43 class FloatPoint; | |
| 44 class FloatRect; | |
| 45 class FloatSize; | |
| 46 class GraphicsContext; | |
| 47 class StrokeData; | |
| 48 | |
| 49 enum PathElementType { | |
| 50 PathElementMoveToPoint, // The points member will contain 1 value. | |
| 51 PathElementAddLineToPoint, // The points member will contain 1 value. | |
| 52 PathElementAddQuadCurveToPoint, // The points member will contain 2 values. | |
| 53 PathElementAddCurveToPoint, // The points member will contain 3 values. | |
| 54 PathElementCloseSubpath // The points member will contain no values. | |
| 55 }; | |
| 56 | |
| 57 // The points in the sturcture are the same as those that would be used with the | |
| 58 // add... method. For example, a line returns the endpoint, while a cubic return
s | |
| 59 // two tangent points and the endpoint. | |
| 60 struct PathElement { | |
| 61 PathElementType type; | |
| 62 FloatPoint* points; | |
| 63 }; | |
| 64 | |
| 65 typedef void (*PathApplierFunction)(void* info, const PathElement*); | |
| 66 | |
| 67 class Path { | |
| 68 WTF_MAKE_FAST_ALLOCATED; | |
| 69 public: | |
| 70 Path(); | |
| 71 ~Path(); | |
| 72 | |
| 73 Path(const Path&); | |
| 74 Path& operator=(const Path&); | |
| 75 bool operator==(const Path&) const; | |
| 76 | |
| 77 bool contains(const FloatPoint&, WindRule = RULE_NONZERO) const; | |
| 78 bool strokeContains(const FloatPoint&, const StrokeData&) const; | |
| 79 FloatRect boundingRect() const; | |
| 80 FloatRect strokeBoundingRect(const StrokeData&) const; | |
| 81 | |
| 82 float length() const; | |
| 83 FloatPoint pointAtLength(float length, bool& ok) const; | |
| 84 float normalAngleAtLength(float length, bool& ok) const; | |
| 85 bool pointAndNormalAtLength(float length, FloatPoint&, float&) const; | |
| 86 | |
| 87 void clear(); | |
| 88 bool isEmpty() const; | |
| 89 // Gets the current point of the current path, which is conceptually the fin
al point reached by the path so far. | |
| 90 // Note the Path can be empty (isEmpty() == true) and still have a current p
oint. | |
| 91 bool hasCurrentPoint() const; | |
| 92 FloatPoint currentPoint() const; | |
| 93 | |
| 94 WindRule windRule() const; | |
| 95 void setWindRule(const WindRule); | |
| 96 | |
| 97 void moveTo(const FloatPoint&); | |
| 98 void addLineTo(const FloatPoint&); | |
| 99 void addQuadCurveTo(const FloatPoint& controlPoint, const FloatPoint& endPoi
nt); | |
| 100 void addBezierCurveTo(const FloatPoint& controlPoint1, const FloatPoint& con
trolPoint2, const FloatPoint& endPoint); | |
| 101 void addArcTo(const FloatPoint&, const FloatPoint&, float radius); | |
| 102 void closeSubpath(); | |
| 103 | |
| 104 void addArc(const FloatPoint&, float radius, float startAngle, float endAngl
e, bool anticlockwise); | |
| 105 void addRect(const FloatRect&); | |
| 106 void addEllipse(const FloatPoint&, float radiusX, float radiusY, float rotat
ion, float startAngle, float endAngle, bool anticlockwise); | |
| 107 void addEllipse(const FloatRect&); | |
| 108 | |
| 109 void addRoundedRect(const FloatRect&, const FloatSize& roundingRadii); | |
| 110 void addRoundedRect(const FloatRect&, const FloatSize& topLeftRadius, const
FloatSize& topRightRadius, const FloatSize& bottomLeftRadius, const FloatSize& b
ottomRightRadius); | |
| 111 void addRoundedRect(const RoundedRect&); | |
| 112 | |
| 113 void translate(const FloatSize&); | |
| 114 | |
| 115 const SkPath& skPath() const { return m_path; } | |
| 116 | |
| 117 void apply(void* info, PathApplierFunction) const; | |
| 118 void transform(const AffineTransform&); | |
| 119 | |
| 120 void addPathForRoundedRect(const FloatRect&, const FloatSize& topLeftRadius,
const FloatSize& topRightRadius, const FloatSize& bottomLeftRadius, const Float
Size& bottomRightRadius); | |
| 121 void addBeziersForRoundedRect(const FloatRect&, const FloatSize& topLeftRadi
us, const FloatSize& topRightRadius, const FloatSize& bottomLeftRadius, const Fl
oatSize& bottomRightRadius); | |
| 122 | |
| 123 // Updates the path to the union (inclusive-or) of itself with the given arg
ument. | |
| 124 bool unionPath(const Path& other); | |
| 125 | |
| 126 private: | |
| 127 void addEllipse(const FloatPoint&, float radiusX, float radiusY, float start
Angle, float endAngle, bool anticlockwise); | |
| 128 | |
| 129 SkPath m_path; | |
| 130 }; | |
| 131 | |
| 132 } | |
| 133 | |
| 134 #endif | |
| OLD | NEW |