Minor code cleanup around WebCore::Path
authorwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 26 Dec 2019 19:01:03 +0000 (19:01 +0000)
committerwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 26 Dec 2019 19:01:03 +0000 (19:01 +0000)
https://bugs.webkit.org/show_bug.cgi?id=205574

Reviewed by Anders Carlsson.

Carry out some minor refactoring in WebCore::Path:
- Change PathElementType into an 8-bit-wide enum class, and move it under PathElement's namespace as simply Type.
- Change PathElement's `FloatPoint*` that points to an array of 3 FloatPoints into a `FloatPoint[3]`.
- Change Path::strokeContains() to take a `StrokeStyleApplier&` instead of a `StrokeStyleApplier*`, since it
  assumes that the given `StrokeStyleApplier` is nonnull anyways.
- Change Path::RoundedRectStrategy into an 8-bit enum class.
- Other miscellaneous style fixes.

No change in behavior.

* accessibility/mac/WebAccessibilityObjectWrapperBase.mm:
(convertPathToScreenSpaceFunction):
* html/canvas/CanvasRenderingContext2DBase.cpp:
(WebCore::CanvasRenderingContext2DBase::isPointInStrokeInternal):
* inspector/InspectorOverlay.cpp:
(WebCore::drawShapeHighlight):
* platform/graphics/FontCascade.cpp:
(WebCore::findPathIntersections):
* platform/graphics/Path.cpp:
(WebCore::Path::addRoundedRect):
(WebCore::operator<<):
* platform/graphics/Path.h:
(WebCore::Path::encode const):
(WebCore::Path::decode):
* platform/graphics/PathTraversalState.cpp:
(WebCore::PathTraversalState::appendPathElement):
(WebCore::PathTraversalState::processPathElement):
* platform/graphics/PathTraversalState.h:
* platform/graphics/cairo/PathCairo.cpp:
(WebCore::Path::strokeContains const):
(WebCore::Path::apply const):
* platform/graphics/cg/PathCG.cpp:
(WebCore::Path::strokeContains const):
(WebCore::CGPathApplierToPathApplier):
* platform/graphics/win/PathDirect2D.cpp:
(WebCore::Path::strokeContains const):
* rendering/shapes/BoxShape.cpp:
(WebCore::BoxShape::buildDisplayPaths const):
* rendering/shapes/RectangleShape.cpp:
(WebCore::RectangleShape::buildDisplayPaths const):
* rendering/svg/RenderSVGShape.cpp:
(WebCore::RenderSVGShape::shapeDependentStrokeContains):
* rendering/svg/SVGMarkerData.h:
(WebCore::SVGMarkerData::updateMarkerDataForPathElement):
* rendering/svg/SVGPathData.cpp:
(WebCore::pathFromRectElement):
* rendering/svg/SVGSubpathData.h:
(WebCore::SVGSubpathData::updateFromPathElement):
* svg/SVGPathTraversalStateBuilder.cpp:
(WebCore::SVGPathTraversalStateBuilder::moveTo):
(WebCore::SVGPathTraversalStateBuilder::lineTo):
(WebCore::SVGPathTraversalStateBuilder::curveToCubic):
(WebCore::SVGPathTraversalStateBuilder::closePath):
* svg/SVGPathUtilities.cpp:
(WebCore::buildStringFromPath):
* testing/Internals.cpp:
(WebCore::Internals::pathStringWithShrinkWrappedRects):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@253916 268f45cc-cd09-0410-ab3c-d52691b4dbfc

21 files changed:
Source/WebCore/ChangeLog
Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapperBase.mm
Source/WebCore/html/canvas/CanvasRenderingContext2DBase.cpp
Source/WebCore/inspector/InspectorOverlay.cpp
Source/WebCore/platform/graphics/FontCascade.cpp
Source/WebCore/platform/graphics/Path.cpp
Source/WebCore/platform/graphics/Path.h
Source/WebCore/platform/graphics/PathTraversalState.cpp
Source/WebCore/platform/graphics/PathTraversalState.h
Source/WebCore/platform/graphics/cairo/PathCairo.cpp
Source/WebCore/platform/graphics/cg/PathCG.cpp
Source/WebCore/platform/graphics/win/PathDirect2D.cpp
Source/WebCore/rendering/shapes/BoxShape.cpp
Source/WebCore/rendering/shapes/RectangleShape.cpp
Source/WebCore/rendering/svg/RenderSVGShape.cpp
Source/WebCore/rendering/svg/SVGMarkerData.h
Source/WebCore/rendering/svg/SVGPathData.cpp
Source/WebCore/rendering/svg/SVGSubpathData.h
Source/WebCore/svg/SVGPathTraversalStateBuilder.cpp
Source/WebCore/svg/SVGPathUtilities.cpp
Source/WebCore/testing/Internals.cpp

index 8c08a88..6c0dc7f 100644 (file)
@@ -1,3 +1,68 @@
+2019-12-26  Wenson Hsieh  <wenson_hsieh@apple.com>
+
+        Minor code cleanup around WebCore::Path
+        https://bugs.webkit.org/show_bug.cgi?id=205574
+
+        Reviewed by Anders Carlsson.
+
+        Carry out some minor refactoring in WebCore::Path:
+        - Change PathElementType into an 8-bit-wide enum class, and move it under PathElement's namespace as simply Type.
+        - Change PathElement's `FloatPoint*` that points to an array of 3 FloatPoints into a `FloatPoint[3]`.
+        - Change Path::strokeContains() to take a `StrokeStyleApplier&` instead of a `StrokeStyleApplier*`, since it
+          assumes that the given `StrokeStyleApplier` is nonnull anyways.
+        - Change Path::RoundedRectStrategy into an 8-bit enum class.
+        - Other miscellaneous style fixes.
+
+        No change in behavior.
+
+        * accessibility/mac/WebAccessibilityObjectWrapperBase.mm:
+        (convertPathToScreenSpaceFunction):
+        * html/canvas/CanvasRenderingContext2DBase.cpp:
+        (WebCore::CanvasRenderingContext2DBase::isPointInStrokeInternal):
+        * inspector/InspectorOverlay.cpp:
+        (WebCore::drawShapeHighlight):
+        * platform/graphics/FontCascade.cpp:
+        (WebCore::findPathIntersections):
+        * platform/graphics/Path.cpp:
+        (WebCore::Path::addRoundedRect):
+        (WebCore::operator<<):
+        * platform/graphics/Path.h:
+        (WebCore::Path::encode const):
+        (WebCore::Path::decode):
+        * platform/graphics/PathTraversalState.cpp:
+        (WebCore::PathTraversalState::appendPathElement):
+        (WebCore::PathTraversalState::processPathElement):
+        * platform/graphics/PathTraversalState.h:
+        * platform/graphics/cairo/PathCairo.cpp:
+        (WebCore::Path::strokeContains const):
+        (WebCore::Path::apply const):
+        * platform/graphics/cg/PathCG.cpp:
+        (WebCore::Path::strokeContains const):
+        (WebCore::CGPathApplierToPathApplier):
+        * platform/graphics/win/PathDirect2D.cpp:
+        (WebCore::Path::strokeContains const):
+        * rendering/shapes/BoxShape.cpp:
+        (WebCore::BoxShape::buildDisplayPaths const):
+        * rendering/shapes/RectangleShape.cpp:
+        (WebCore::RectangleShape::buildDisplayPaths const):
+        * rendering/svg/RenderSVGShape.cpp:
+        (WebCore::RenderSVGShape::shapeDependentStrokeContains):
+        * rendering/svg/SVGMarkerData.h:
+        (WebCore::SVGMarkerData::updateMarkerDataForPathElement):
+        * rendering/svg/SVGPathData.cpp:
+        (WebCore::pathFromRectElement):
+        * rendering/svg/SVGSubpathData.h:
+        (WebCore::SVGSubpathData::updateFromPathElement):
+        * svg/SVGPathTraversalStateBuilder.cpp:
+        (WebCore::SVGPathTraversalStateBuilder::moveTo):
+        (WebCore::SVGPathTraversalStateBuilder::lineTo):
+        (WebCore::SVGPathTraversalStateBuilder::curveToCubic):
+        (WebCore::SVGPathTraversalStateBuilder::closePath):
+        * svg/SVGPathUtilities.cpp:
+        (WebCore::buildStringFromPath):
+        * testing/Internals.cpp:
+        (WebCore::Internals::pathStringWithShrinkWrappedRects):
+
 2019-12-26  Zalan Bujtas  <zalan@apple.com>
 
         [LFC][IFC] When align the inline content we need to align the line as well
index 4f9b4d9..7246906 100644 (file)
@@ -367,21 +367,21 @@ static void convertPathToScreenSpaceFunction(PathConversionInfo& conversion, con
     CGMutablePathRef newPath = conversion.path;
     FloatRect rect;
     switch (element.type) {
-    case PathElementMoveToPoint:
+    case PathElement::Type::MoveToPoint:
     {
         rect = FloatRect(element.points[0], FloatSize());
         CGPoint newPoint = [wrapper convertRectToSpace:rect space:AccessibilityConversionSpace::Screen].origin;
         CGPathMoveToPoint(newPath, nil, newPoint.x, newPoint.y);
         break;
     }
-    case PathElementAddLineToPoint:
+    case PathElement::Type::AddLineToPoint:
     {
         rect = FloatRect(element.points[0], FloatSize());
         CGPoint newPoint = [wrapper convertRectToSpace:rect space:AccessibilityConversionSpace::Screen].origin;
         CGPathAddLineToPoint(newPath, nil, newPoint.x, newPoint.y);
         break;
     }
-    case PathElementAddQuadCurveToPoint:
+    case PathElement::Type::AddQuadCurveToPoint:
     {
         rect = FloatRect(element.points[0], FloatSize());
         CGPoint newPoint1 = [wrapper convertRectToSpace:rect space:AccessibilityConversionSpace::Screen].origin;
@@ -391,7 +391,7 @@ static void convertPathToScreenSpaceFunction(PathConversionInfo& conversion, con
         CGPathAddQuadCurveToPoint(newPath, nil, newPoint1.x, newPoint1.y, newPoint2.x, newPoint2.y);
         break;
     }
-    case PathElementAddCurveToPoint:
+    case PathElement::Type::AddCurveToPoint:
     {
         rect = FloatRect(element.points[0], FloatSize());
         CGPoint newPoint1 = [wrapper convertRectToSpace:rect space:AccessibilityConversionSpace::Screen].origin;
@@ -404,7 +404,7 @@ static void convertPathToScreenSpaceFunction(PathConversionInfo& conversion, con
         CGPathAddCurveToPoint(newPath, nil, newPoint1.x, newPoint1.y, newPoint2.x, newPoint2.y, newPoint3.x, newPoint3.y);
         break;
     }
-    case PathElementCloseSubpath:
+    case PathElement::Type::CloseSubpath:
     {
         CGPathCloseSubpath(newPath);
         break;
index 3fa6d8a..bdb6cea 100644 (file)
@@ -1216,7 +1216,7 @@ bool CanvasRenderingContext2DBase::isPointInStrokeInternal(const Path& path, flo
         return false;
 
     CanvasStrokeStyleApplier applier(this);
-    return path.strokeContains(&applier, transformedPoint);
+    return path.strokeContains(applier, transformedPoint);
 }
 
 void CanvasRenderingContext2DBase::clearRect(float x, float y, float width, float height)
index 6638655..6ebdda3 100644 (file)
@@ -315,23 +315,23 @@ static void drawShapeHighlight(GraphicsContext& context, Node& node, Highlight::
             };
 
             switch (pathElement.type) {
-            case PathElementMoveToPoint:
+            case PathElement::Type::MoveToPoint:
                 newPath.moveTo(localToRoot(0));
                 break;
 
-            case PathElementAddLineToPoint:
+            case PathElement::Type::AddLineToPoint:
                 newPath.addLineTo(localToRoot(0));
                 break;
 
-            case PathElementAddCurveToPoint:
+            case PathElement::Type::AddCurveToPoint:
                 newPath.addBezierCurveTo(localToRoot(0), localToRoot(1), localToRoot(2));
                 break;
 
-            case PathElementAddQuadCurveToPoint:
+            case PathElement::Type::AddQuadCurveToPoint:
                 newPath.addQuadCurveTo(localToRoot(0), localToRoot(1));
                 break;
 
-            case PathElementCloseSubpath:
+            case PathElement::Type::CloseSubpath:
                 newPath.closeSubpath();
                 break;
             }
index 412747a..1a6f73a 100644 (file)
@@ -1706,23 +1706,23 @@ static void findPathIntersections(GlyphIterationState& state, const PathElement&
     bool doIntersection = false;
     FloatPoint point = FloatPoint();
     switch (element.type) {
-    case PathElementMoveToPoint:
+    case PathElement::Type::MoveToPoint:
         state.startingPoint = element.points[0];
         state.currentPoint = element.points[0];
         break;
-    case PathElementAddLineToPoint:
+    case PathElement::Type::AddLineToPoint:
         doIntersection = true;
         point = element.points[0];
         break;
-    case PathElementAddQuadCurveToPoint:
+    case PathElement::Type::AddQuadCurveToPoint:
         doIntersection = true;
         point = element.points[1];
         break;
-    case PathElementAddCurveToPoint:
+    case PathElement::Type::AddCurveToPoint:
         doIntersection = true;
         point = element.points[2];
         break;
-    case PathElementCloseSubpath:
+    case PathElement::Type::CloseSubpath:
         doIntersection = true;
         point = state.startingPoint;
         break;
index a099ad5..b425f73 100644 (file)
@@ -111,7 +111,7 @@ void Path::addRoundedRect(const FloatRoundedRect& r, RoundedRectStrategy strateg
         return;
     }
 
-    if (strategy == PreferNativeRoundedRect) {
+    if (strategy == RoundedRectStrategy::PreferNative) {
 #if USE(CG) || USE(DIRECT2D)
         platformAddPathForRoundedRect(rect, radii.topLeft(), radii.topRight(), radii.bottomLeft(), radii.bottomRight());
         return;
@@ -192,19 +192,19 @@ TextStream& operator<<(TextStream& stream, const Path& path)
             stream << ", ";
         isFirst = false;
         switch (element.type) {
-        case PathElementMoveToPoint: // The points member will contain 1 value.
+        case PathElement::Type::MoveToPoint: // The points member will contain 1 value.
             stream << "move to " << element.points[0];
             break;
-        case PathElementAddLineToPoint: // The points member will contain 1 value.
+        case PathElement::Type::AddLineToPoint: // The points member will contain 1 value.
             stream << "add line to " << element.points[0];
             break;
-        case PathElementAddQuadCurveToPoint: // The points member will contain 2 values.
+        case PathElement::Type::AddQuadCurveToPoint: // The points member will contain 2 values.
             stream << "add quad curve to " << element.points[0] << " " << element.points[1];
             break;
-        case PathElementAddCurveToPoint: // The points member will contain 3 values.
+        case PathElement::Type::AddCurveToPoint: // The points member will contain 3 values.
             stream << "add curve to " << element.points[0] << " " << element.points[1] << " " << element.points[2];
             break;
-        case PathElementCloseSubpath: // The points member will contain no values.
+        case PathElement::Type::CloseSubpath: // The points member will contain no values.
             stream << "close subpath";
             break;
         }
index 1a775ed..e5c2b7c 100644 (file)
@@ -91,20 +91,20 @@ class PathTraversalState;
 class RoundedRect;
 class StrokeStyleApplier;
 
-enum PathElementType {
-    PathElementMoveToPoint, // The points member will contain 1 value.
-    PathElementAddLineToPoint, // The points member will contain 1 value.
-    PathElementAddQuadCurveToPoint, // The points member will contain 2 values.
-    PathElementAddCurveToPoint, // The points member will contain 3 values.
-    PathElementCloseSubpath // The points member will contain no values.
-};
-
 // The points in the structure are the same as those that would be used with the
 // add... method. For example, a line returns the endpoint, while a cubic returns
 // two tangent points and the endpoint.
 struct PathElement {
-    PathElementType type;
-    FloatPoint* points;
+    enum class Type : uint8_t {
+        MoveToPoint, // The points member will contain 1 value.
+        AddLineToPoint, // The points member will contain 1 value.
+        AddQuadCurveToPoint, // The points member will contain 2 values.
+        AddCurveToPoint, // The points member will contain 3 values.
+        CloseSubpath // The points member will contain no values.
+    };
+
+    FloatPoint points[3];
+    Type type;
 };
 
 using PathApplierFunction = WTF::Function<void(const PathElement&)>;
@@ -126,7 +126,7 @@ public:
     static Path polygonPathFromPoints(const Vector<FloatPoint>&);
 
     bool contains(const FloatPoint&, WindRule = WindRule::NonZero) const;
-    bool strokeContains(StrokeStyleApplier*, const FloatPoint&) const;
+    bool strokeContains(StrokeStyleApplier&, const FloatPoint&) const;
     // fastBoundingRect() should equal or contain boundingRect(); boundingRect()
     // should perfectly bound the points within the path.
     FloatRect boundingRect() const;
@@ -157,13 +157,13 @@ public:
     void addEllipse(FloatPoint, float radiusX, float radiusY, float rotation, float startAngle, float endAngle, bool anticlockwise);
     void addEllipse(const FloatRect&);
 
-    enum RoundedRectStrategy {
-        PreferNativeRoundedRect,
-        PreferBezierRoundedRect
+    enum class RoundedRectStrategy : uint8_t {
+        PreferNative,
+        PreferBezier
     };
 
-    WEBCORE_EXPORT void addRoundedRect(const FloatRect&, const FloatSize& roundingRadii, RoundedRectStrategy = PreferNativeRoundedRect);
-    WEBCORE_EXPORT void addRoundedRect(const FloatRoundedRect&, RoundedRectStrategy = PreferNativeRoundedRect);
+    WEBCORE_EXPORT void addRoundedRect(const FloatRect&, const FloatSize& roundingRadii, RoundedRectStrategy = RoundedRectStrategy::PreferNative);
+    WEBCORE_EXPORT void addRoundedRect(const FloatRoundedRect&, RoundedRectStrategy = RoundedRectStrategy::PreferNative);
     void addRoundedRect(const RoundedRect&);
 
     void addPath(const Path&, const AffineTransform&);
@@ -239,22 +239,22 @@ template<class Encoder> void Path::encode(Encoder& encoder) const
         encoder.encodeEnum(element.type);
 
         switch (element.type) {
-        case PathElementMoveToPoint:
+        case PathElement::Type::MoveToPoint:
             encoder << element.points[0];
             break;
-        case PathElementAddLineToPoint:
+        case PathElement::Type::AddLineToPoint:
             encoder << element.points[0];
             break;
-        case PathElementAddQuadCurveToPoint:
+        case PathElement::Type::AddQuadCurveToPoint:
             encoder << element.points[0];
             encoder << element.points[1];
             break;
-        case PathElementAddCurveToPoint:
+        case PathElement::Type::AddCurveToPoint:
             encoder << element.points[0];
             encoder << element.points[1];
             encoder << element.points[2];
             break;
-        case PathElementCloseSubpath:
+        case PathElement::Type::CloseSubpath:
             break;
         }
     });
@@ -270,26 +270,26 @@ template<class Decoder> Optional<Path> Path::decode(Decoder& decoder)
     path.clear();
 
     for (uint64_t i = 0; i < numPoints; ++i) {
-        PathElementType elementType;
+        PathElement::Type elementType;
         if (!decoder.decodeEnum(elementType))
             return WTF::nullopt;
 
         switch (elementType) {
-        case PathElementMoveToPoint: {
+        case PathElement::Type::MoveToPoint: {
             FloatPoint point;
             if (!decoder.decode(point))
                 return WTF::nullopt;
             path.moveTo(point);
             break;
         }
-        case PathElementAddLineToPoint: {
+        case PathElement::Type::AddLineToPoint: {
             FloatPoint point;
             if (!decoder.decode(point))
                 return WTF::nullopt;
             path.addLineTo(point);
             break;
         }
-        case PathElementAddQuadCurveToPoint: {
+        case PathElement::Type::AddQuadCurveToPoint: {
             FloatPoint controlPoint;
             if (!decoder.decode(controlPoint))
                 return WTF::nullopt;
@@ -301,7 +301,7 @@ template<class Decoder> Optional<Path> Path::decode(Decoder& decoder)
             path.addQuadCurveTo(controlPoint, endPoint);
             break;
         }
-        case PathElementAddCurveToPoint: {
+        case PathElement::Type::AddCurveToPoint: {
             FloatPoint controlPoint1;
             if (!decoder.decode(controlPoint1))
                 return WTF::nullopt;
@@ -317,7 +317,7 @@ template<class Decoder> Optional<Path> Path::decode(Decoder& decoder)
             path.addBezierCurveTo(controlPoint1, controlPoint2, endPoint);
             break;
         }
-        case PathElementCloseSubpath:
+        case PathElement::Type::CloseSubpath:
             path.closeSubpath();
             break;
         }
index 9c5339a..8a78222 100644 (file)
@@ -243,22 +243,22 @@ bool PathTraversalState::finalizeAppendPathElement()
     return m_success;
 }
 
-bool PathTraversalState::appendPathElement(PathElementType type, const FloatPoint* points)
+bool PathTraversalState::appendPathElement(PathElement::Type type, const FloatPoint* points)
 {
     switch (type) {
-    case PathElementMoveToPoint:
+    case PathElement::Type::MoveToPoint:
         moveTo(points[0]);
         break;
-    case PathElementAddLineToPoint:
+    case PathElement::Type::AddLineToPoint:
         lineTo(points[0]);
         break;
-    case PathElementAddQuadCurveToPoint:
+    case PathElement::Type::AddQuadCurveToPoint:
         quadraticBezierTo(points[0], points[1]);
         break;
-    case PathElementAddCurveToPoint:
+    case PathElement::Type::AddCurveToPoint:
         cubicBezierTo(points[0], points[1], points[2]);
         break;
-    case PathElementCloseSubpath:
+    case PathElement::Type::CloseSubpath:
         closeSubpath();
         break;
     }
@@ -266,7 +266,7 @@ bool PathTraversalState::appendPathElement(PathElementType type, const FloatPoin
     return finalizeAppendPathElement();
 }
 
-bool PathTraversalState::processPathElement(PathElementType type, const FloatPoint* points)
+bool PathTraversalState::processPathElement(PathElement::Type type, const FloatPoint* points)
 {
     if (m_success)
         return true;
index bd3c0f1..223dff4 100644 (file)
@@ -43,7 +43,7 @@ public:
     PathTraversalState(Action, float desiredLength = 0);
 
 public:
-    bool processPathElement(PathElementType, const FloatPoint*);
+    bool processPathElement(PathElement::Type, const FloatPoint*);
     bool processPathElement(const PathElement& element) { return processPathElement(element.type, element.points); }
 
     Action action() const { return m_action; }
@@ -65,7 +65,7 @@ private:
     void cubicBezierTo(const FloatPoint&, const FloatPoint&, const FloatPoint&);
 
     bool finalizeAppendPathElement();
-    bool appendPathElement(PathElementType, const FloatPoint*);
+    bool appendPathElement(PathElement::Type, const FloatPoint*);
 
 private:
     Action m_action;
index dc288b3..f04f190 100644 (file)
@@ -394,16 +394,15 @@ bool Path::contains(const FloatPoint& point, WindRule rule) const
     return contains;
 }
 
-bool Path::strokeContains(StrokeStyleApplier* applier, const FloatPoint& point) const
+bool Path::strokeContains(StrokeStyleApplier& applier, const FloatPoint& point) const
 {
     if (isNull())
         return false;
 
-    ASSERT(applier);
     cairo_t* cr = platformPath()->context();
     {
-        GraphicsContext gc(GraphicsContextImplCairo::createFactory(cr));
-        applier->strokeStyle(&gc);
+        GraphicsContext graphicsContext(GraphicsContextImplCairo::createFactory(cr));
+        applier.strokeStyle(&graphicsContext);
     }
 
     return cairo_in_stroke(cr, point.x(), point.y());
@@ -417,33 +416,31 @@ void Path::apply(const PathApplierFunction& function) const
     cairo_t* cr = platformPath()->context();
     auto pathCopy = cairo_copy_path(cr);
     cairo_path_data_t* data;
-    PathElement pelement;
-    FloatPoint points[3];
-    pelement.points = points;
+    PathElement pathElement;
 
     for (int i = 0; i < pathCopy->num_data; i += pathCopy->data[i].header.length) {
         data = &pathCopy->data[i];
         switch (data->header.type) {
         case CAIRO_PATH_MOVE_TO:
-            pelement.type = PathElementMoveToPoint;
-            pelement.points[0] = FloatPoint(data[1].point.x,data[1].point.y);
-            function(pelement);
+            pathElement.type = PathElement::Type::MoveToPoint;
+            pathElement.points[0] = FloatPoint(data[1].point.x, data[1].point.y);
+            function(pathElement);
             break;
         case CAIRO_PATH_LINE_TO:
-            pelement.type = PathElementAddLineToPoint;
-            pelement.points[0] = FloatPoint(data[1].point.x,data[1].point.y);
-            function(pelement);
+            pathElement.type = PathElement::Type::AddLineToPoint;
+            pathElement.points[0] = FloatPoint(data[1].point.x, data[1].point.y);
+            function(pathElement);
             break;
         case CAIRO_PATH_CURVE_TO:
-            pelement.type = PathElementAddCurveToPoint;
-            pelement.points[0] = FloatPoint(data[1].point.x,data[1].point.y);
-            pelement.points[1] = FloatPoint(data[2].point.x,data[2].point.y);
-            pelement.points[2] = FloatPoint(data[3].point.x,data[3].point.y);
-            function(pelement);
+            pathElement.type = PathElement::Type::AddCurveToPoint;
+            pathElement.points[0] = FloatPoint(data[1].point.x, data[1].point.y);
+            pathElement.points[1] = FloatPoint(data[2].point.x, data[2].point.y);
+            pathElement.points[2] = FloatPoint(data[3].point.x, data[3].point.y);
+            function(pathElement);
             break;
         case CAIRO_PATH_CLOSE_PATH:
-            pelement.type = PathElementCloseSubpath;
-            function(pelement);
+            pathElement.type = PathElement::Type::CloseSubpath;
+            function(pathElement);
             break;
         }
     }
index e4ae5d5..3d1d5f1 100644 (file)
@@ -185,21 +185,19 @@ bool Path::contains(const FloatPoint &point, WindRule rule) const
     return ret;
 }
 
-bool Path::strokeContains(StrokeStyleApplier* applier, const FloatPoint& point) const
+bool Path::strokeContains(StrokeStyleApplier& applier, const FloatPoint& point) const
 {
     if (isNull())
         return false;
 
-    ASSERT(applier);
-
     CGContextRef context = scratchContext();
 
     CGContextSaveGState(context);
     CGContextBeginPath(context);
     CGContextAddPath(context, platformPath());
 
-    GraphicsContext gc(context);
-    applier->strokeStyle(&gc);
+    GraphicsContext graphicsContext(context);
+    applier.strokeStyle(&graphicsContext);
 
     bool hitSuccess = CGContextPathContainsPoint(context, point, kCGPathStroke);
     CGContextRestoreGState(context);
@@ -429,29 +427,27 @@ FloatPoint Path::currentPoint() const
 static void CGPathApplierToPathApplier(void* info, const CGPathElement* element)
 {
     const PathApplierFunction& function = *(PathApplierFunction*)info;
-    FloatPoint points[3];
-    PathElement pelement;
-    pelement.type = (PathElementType)element->type;
-    pelement.points = points;
+    PathElement pathElement;
+    pathElement.type = (PathElement::Type)element->type;
     CGPoint* cgPoints = element->points;
     switch (element->type) {
     case kCGPathElementMoveToPoint:
     case kCGPathElementAddLineToPoint:
-        points[0] = cgPoints[0];
+        pathElement.points[0] = cgPoints[0];
         break;
     case kCGPathElementAddQuadCurveToPoint:
-        points[0] = cgPoints[0];
-        points[1] = cgPoints[1];
+        pathElement.points[0] = cgPoints[0];
+        pathElement.points[1] = cgPoints[1];
         break;
     case kCGPathElementAddCurveToPoint:
-        points[0] = cgPoints[0];
-        points[1] = cgPoints[1];
-        points[2] = cgPoints[2];
+        pathElement.points[0] = cgPoints[0];
+        pathElement.points[1] = cgPoints[1];
+        pathElement.points[2] = cgPoints[2];
         break;
     case kCGPathElementCloseSubpath:
         break;
     }
-    function(pelement);
+    function(pathElement);
 }
 
 void Path::apply(const PathApplierFunction& function) const
index aa69ef3..81ab6a2 100644 (file)
@@ -225,16 +225,14 @@ bool Path::contains(const FloatPoint& point, WindRule rule) const
     return contains;
 }
 
-bool Path::strokeContains(StrokeStyleApplier* applier, const FloatPoint& point) const
+bool Path::strokeContains(StrokeStyleApplier& applier, const FloatPoint& point) const
 {
     if (isNull())
         return false;
 
-    ASSERT(applier);
-
     PlatformContextDirect2D scratchContextD2D(scratchRenderTarget());
     GraphicsContext scratchContext(&scratchContextD2D, GraphicsContext::BitmapRenderingContextType::GPUMemory);
-    applier->strokeStyle(&scratchContext);
+    applier.strokeStyle(&scratchContext);
 
 #if !ASSERT_DISABLED
     unsigned before = refCount(m_path.get());
index 0da709e..c2e53dd 100644 (file)
@@ -159,9 +159,9 @@ LineSegment BoxShape::getExcludedInterval(LayoutUnit logicalTop, LayoutUnit logi
 
 void BoxShape::buildDisplayPaths(DisplayPaths& paths) const
 {
-    paths.shape.addRoundedRect(m_bounds, Path::PreferBezierRoundedRect);
+    paths.shape.addRoundedRect(m_bounds, Path::RoundedRectStrategy::PreferBezier);
     if (shapeMargin())
-        paths.marginShape.addRoundedRect(shapeMarginBounds(), Path::PreferBezierRoundedRect);
+        paths.marginShape.addRoundedRect(shapeMarginBounds(), Path::RoundedRectStrategy::PreferBezier);
 }
 
 } // namespace WebCore
index f3619d6..429deb8 100644 (file)
@@ -90,9 +90,9 @@ LineSegment RectangleShape::getExcludedInterval(LayoutUnit logicalTop, LayoutUni
 
 void RectangleShape::buildDisplayPaths(DisplayPaths& paths) const
 {
-    paths.shape.addRoundedRect(m_bounds, FloatSize(m_radii.width(), m_radii.height()), Path::PreferBezierRoundedRect);
+    paths.shape.addRoundedRect(m_bounds, FloatSize(m_radii.width(), m_radii.height()), Path::RoundedRectStrategy::PreferBezier);
     if (shapeMargin())
-        paths.marginShape.addRoundedRect(shapeMarginBounds(), FloatSize(m_radii.width() + shapeMargin(), m_radii.height() + shapeMargin()), Path::PreferBezierRoundedRect);
+        paths.marginShape.addRoundedRect(shapeMarginBounds(), FloatSize(m_radii.width() + shapeMargin(), m_radii.height() + shapeMargin()), Path::RoundedRectStrategy::PreferBezier);
 }
 
 } // namespace WebCore
index 7d8861a..8438eda 100644 (file)
@@ -120,10 +120,10 @@ bool RenderSVGShape::shapeDependentStrokeContains(const FloatPoint& point, Point
         AffineTransform nonScalingTransform = nonScalingStrokeTransform();
         Path* usePath = nonScalingStrokePath(m_path.get(), nonScalingTransform);
 
-        return usePath->strokeContains(&applier, nonScalingTransform.mapPoint(point));
+        return usePath->strokeContains(applier, nonScalingTransform.mapPoint(point));
     }
 
-    return m_path->strokeContains(&applier, point);
+    return m_path->strokeContains(applier, point);
 }
 
 bool RenderSVGShape::shapeDependentFillContains(const FloatPoint& point, const WindRule fillRule) const
index 53da371..6f5b14b 100644 (file)
@@ -111,26 +111,26 @@ private:
 
     void updateMarkerDataForPathElement(const PathElement& element)
     {
-        FloatPoint* points = element.points;
+        auto& points = element.points;
 
         switch (element.type) {
-        case PathElementAddQuadCurveToPoint:
-            // FIXME: https://bugs.webkit.org/show_bug.cgi?id=33115 (PathElementAddQuadCurveToPoint not handled for <marker>)
+        case PathElement::Type::AddQuadCurveToPoint:
+            // FIXME: https://bugs.webkit.org/show_bug.cgi?id=33115 (PathElement::Type::AddQuadCurveToPoint not handled for <marker>)
             m_origin = points[1];
             break;
-        case PathElementAddCurveToPoint:
+        case PathElement::Type::AddCurveToPoint:
             m_inslopePoints[0] = points[1];
             m_inslopePoints[1] = points[2];
             m_origin = points[2];
             break;
-        case PathElementMoveToPoint:
+        case PathElement::Type::MoveToPoint:
             m_subpathStart = points[0];
             FALLTHROUGH;
-        case PathElementAddLineToPoint:
+        case PathElement::Type::AddLineToPoint:
             updateInslope(points[0]);
             m_origin = points[0];
             break;
-        case PathElementCloseSubpath:
+        case PathElement::Type::CloseSubpath:
             updateInslope(points[0]);
             m_origin = m_subpathStart;
             m_subpathStart = FloatPoint();
index 2bab180..3c91ac3 100644 (file)
@@ -161,7 +161,7 @@ static Path pathFromRectElement(const SVGElement& element)
         // FIXME: We currently enforce using beziers here, as at least on CoreGraphics/Lion, as
         // the native method uses a different line dash origin, causing svg/custom/dashOrigin.svg to fail.
         // See bug https://bugs.webkit.org/show_bug.cgi?id=79932 which tracks this issue.
-        path.addRoundedRect(FloatRect(x, y, width, height), FloatSize(rx, ry), Path::PreferBezierRoundedRect);
+        path.addRoundedRect(FloatRect(x, y, width, height), FloatSize(rx, ry), Path::RoundedRectStrategy::PreferBezier);
         return path;
     }
 
index 0ffbeed..8c72234 100644 (file)
@@ -34,35 +34,35 @@ public:
     static void updateFromPathElement(SVGSubpathData& subpathFinder, const PathElement& element)
     {
         switch (element.type) {
-        case PathElementMoveToPoint:
+        case PathElement::Type::MoveToPoint:
             if (subpathFinder.m_pathIsZeroLength && !subpathFinder.m_haveSeenMoveOnly)
                 subpathFinder.m_zeroLengthSubpathLocations.append(subpathFinder.m_lastPoint);
             subpathFinder.m_lastPoint = subpathFinder.m_movePoint = element.points[0];
             subpathFinder.m_haveSeenMoveOnly = true;
             subpathFinder.m_pathIsZeroLength = true;
             break;
-        case PathElementAddLineToPoint:
+        case PathElement::Type::AddLineToPoint:
             if (subpathFinder.m_lastPoint != element.points[0]) {
                 subpathFinder.m_pathIsZeroLength = false;
                 subpathFinder.m_lastPoint = element.points[0];
             }
             subpathFinder.m_haveSeenMoveOnly = false;
             break;
-        case PathElementAddQuadCurveToPoint:
+        case PathElement::Type::AddQuadCurveToPoint:
             if (subpathFinder.m_lastPoint != element.points[0] || element.points[0] != element.points[1]) {
                 subpathFinder.m_pathIsZeroLength = false;
                 subpathFinder.m_lastPoint = element.points[1];
             }
             subpathFinder.m_haveSeenMoveOnly = false;
             break;
-        case PathElementAddCurveToPoint:
+        case PathElement::Type::AddCurveToPoint:
             if (subpathFinder.m_lastPoint != element.points[0] || element.points[0] != element.points[1] || element.points[1] != element.points[2]) {
                 subpathFinder.m_pathIsZeroLength = false;
                 subpathFinder.m_lastPoint = element.points[2];
             }
             subpathFinder.m_haveSeenMoveOnly = false;
             break;
-        case PathElementCloseSubpath:
+        case PathElement::Type::CloseSubpath:
             if (subpathFinder.m_pathIsZeroLength)
                 subpathFinder.m_zeroLengthSubpathLocations.append(subpathFinder.m_lastPoint);
             subpathFinder.m_haveSeenMoveOnly = true; // This is an implicit move for the next element
index de1a0ca..6c84823 100644 (file)
@@ -36,24 +36,24 @@ SVGPathTraversalStateBuilder::SVGPathTraversalStateBuilder(PathTraversalState& s
 
 void SVGPathTraversalStateBuilder::moveTo(const FloatPoint& targetPoint, bool, PathCoordinateMode)
 {
-    m_traversalState.processPathElement(PathElementMoveToPoint, &targetPoint);
+    m_traversalState.processPathElement(PathElement::Type::MoveToPoint, &targetPoint);
 }
 
 void SVGPathTraversalStateBuilder::lineTo(const FloatPoint& targetPoint, PathCoordinateMode)
 {
-    m_traversalState.processPathElement(PathElementAddLineToPoint, &targetPoint);
+    m_traversalState.processPathElement(PathElement::Type::AddLineToPoint, &targetPoint);
 }
 
 void SVGPathTraversalStateBuilder::curveToCubic(const FloatPoint& point1, const FloatPoint& point2, const FloatPoint& targetPoint, PathCoordinateMode)
 {
     FloatPoint points[] = { point1, point2, targetPoint };
 
-    m_traversalState.processPathElement(PathElementAddCurveToPoint, points);
+    m_traversalState.processPathElement(PathElement::Type::AddCurveToPoint, points);
 }
 
 void SVGPathTraversalStateBuilder::closePath()
 {
-    m_traversalState.processPathElement(PathElementCloseSubpath, nullptr);
+    m_traversalState.processPathElement(PathElement::Type::CloseSubpath, nullptr);
 }
 
 bool SVGPathTraversalStateBuilder::continueConsuming()
index b197d5b..dd0f922 100644 (file)
@@ -58,19 +58,19 @@ String buildStringFromPath(const Path& path)
     if (!path.isNull() && !path.isEmpty()) {
         path.apply([&builder] (const PathElement& element) {
             switch (element.type) {
-            case PathElementMoveToPoint:
+            case PathElement::Type::MoveToPoint:
                 builder.append('M');
                 builder.appendNumber(element.points[0].x());
                 builder.append(' ');
                 builder.appendNumber(element.points[0].y());
                 break;
-            case PathElementAddLineToPoint:
+            case PathElement::Type::AddLineToPoint:
                 builder.append('L');
                 builder.appendNumber(element.points[0].x());
                 builder.append(' ');
                 builder.appendNumber(element.points[0].y());
                 break;
-            case PathElementAddQuadCurveToPoint:
+            case PathElement::Type::AddQuadCurveToPoint:
                 builder.append('Q');
                 builder.appendNumber(element.points[0].x());
                 builder.append(' ');
@@ -80,7 +80,7 @@ String buildStringFromPath(const Path& path)
                 builder.append(' ');
                 builder.appendNumber(element.points[1].y());
                 break;
-            case PathElementAddCurveToPoint:
+            case PathElement::Type::AddCurveToPoint:
                 builder.append('C');
                 builder.appendNumber(element.points[0].x());
                 builder.append(' ');
@@ -94,7 +94,7 @@ String buildStringFromPath(const Path& path)
                 builder.append(' ');
                 builder.appendNumber(element.points[2].y());
                 break;
-            case PathElementCloseSubpath:
+            case PathElement::Type::CloseSubpath:
                 builder.append('Z');
                 break;
             }
index f22837c..47018bd 100644 (file)
@@ -4418,19 +4418,19 @@ ExceptionOr<String> Internals::pathStringWithShrinkWrappedRects(const Vector<dou
     SVGPathStringBuilder builder;
     PathUtilities::pathWithShrinkWrappedRects(rects, radius).apply([&builder](const PathElement& element) {
         switch (element.type) {
-        case PathElementMoveToPoint:
+        case PathElement::Type::MoveToPoint:
             builder.moveTo(element.points[0], false, AbsoluteCoordinates);
             return;
-        case PathElementAddLineToPoint:
+        case PathElement::Type::AddLineToPoint:
             builder.lineTo(element.points[0], AbsoluteCoordinates);
             return;
-        case PathElementAddQuadCurveToPoint:
+        case PathElement::Type::AddQuadCurveToPoint:
             builder.curveToQuadratic(element.points[0], element.points[1], AbsoluteCoordinates);
             return;
-        case PathElementAddCurveToPoint:
+        case PathElement::Type::AddCurveToPoint:
             builder.curveToCubic(element.points[0], element.points[1], element.points[2], AbsoluteCoordinates);
             return;
-        case PathElementCloseSubpath:
+        case PathElement::Type::CloseSubpath:
             builder.closePath();
             return;
         }