Skip to content

Commit

Permalink
Cleanup pathFromGraphicsElement
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=264967

Reviewed by Chris Dumez.

Use switch statement instead of a HashMap in pathFromGraphicsElement.
Also make pathFromGraphicsElement take a reference, not a pointer, to SVGElement.

* Source/WebCore/rendering/PathOperation.cpp:
(WebCore::ReferencePathOperation::ReferencePathOperation):
* Source/WebCore/rendering/svg/RenderSVGModelObject.cpp:
(WebCore::RenderSVGModelObject::computeClipPath const):
* Source/WebCore/rendering/svg/RenderSVGShape.cpp:
(WebCore::RenderSVGShape::createPath const):
* Source/WebCore/rendering/svg/RenderSVGTextPath.cpp:
(WebCore::RenderSVGTextPath::layoutPath const):
* Source/WebCore/rendering/svg/SVGPathData.cpp:
(WebCore::pathFromGraphicsElement):
* Source/WebCore/rendering/svg/SVGPathData.h:
* Source/WebCore/rendering/svg/legacy/LegacyRenderSVGShape.cpp:
(WebCore::LegacyRenderSVGShape::createPath const):
* Source/WebCore/svg/SVGAnimateMotionElement.cpp:
(WebCore::SVGAnimateMotionElement::updateAnimationPath):
* Source/WebCore/svg/SVGGraphicsElement.cpp:
(WebCore::SVGGraphicsElement::toClipPath):

Canonical link: https://commits.webkit.org/270850@main
  • Loading branch information
rniwa committed Nov 16, 2023
1 parent eb56cc4 commit 0296432
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 26 deletions.
2 changes: 1 addition & 1 deletion Source/WebCore/rendering/PathOperation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ ReferencePathOperation::ReferencePathOperation(const String& url, const AtomStri
, m_fragment(fragment)
{
if (is<SVGPathElement>(element) || is<SVGGeometryElement>(element))
m_path = pathFromGraphicsElement(element.get());
m_path = pathFromGraphicsElement(*element);
}

ReferencePathOperation::ReferencePathOperation(std::optional<Path>&& path)
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/rendering/svg/RenderSVGModelObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ Path RenderSVGModelObject::computeClipPath(AffineTransform& transform) const
if (layer()->isTransformed())
transform.multiply(layer()->currentTransform(RenderStyle::individualTransformOperations()).toAffineTransform());

return pathFromGraphicsElement(&downcast<SVGGraphicsElement>(element()));
return pathFromGraphicsElement(downcast<SVGGraphicsElement>(element()));
}

} // namespace WebCore
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/rendering/svg/RenderSVGShape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ Path& RenderSVGShape::ensurePath()

std::unique_ptr<Path> RenderSVGShape::createPath() const
{
return makeUnique<Path>(pathFromGraphicsElement(&graphicsElement()));
return makeUnique<Path>(pathFromGraphicsElement(graphicsElement()));
}

void RenderSVGShape::styleWillChange(StyleDifference diff, const RenderStyle& newStyle)
Expand Down
4 changes: 2 additions & 2 deletions Source/WebCore/rendering/svg/RenderSVGTextPath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ SVGGeometryElement* RenderSVGTextPath::targetElement() const

Path RenderSVGTextPath::layoutPath() const
{
auto element = targetElement();
RefPtr element = targetElement();
if (!is<SVGGeometryElement>(element))
return { };

auto path = pathFromGraphicsElement(element);
auto path = pathFromGraphicsElement(*element);

// Spec: The transform attribute on the referenced 'path' element represents a
// supplemental transformation relative to the current user coordinate system for
Expand Down
36 changes: 19 additions & 17 deletions Source/WebCore/rendering/svg/SVGPathData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "config.h"
#include "SVGPathData.h"

#include "NodeName.h"
#include "Path.h"
#include "RenderElement.h"
#include "RenderStyle.h"
Expand Down Expand Up @@ -182,26 +183,27 @@ static Path pathFromRectElement(const SVGElement& element)
return path;
}

Path pathFromGraphicsElement(const SVGElement* element)
Path pathFromGraphicsElement(const SVGElement& element)
{
ASSERT(element);

typedef Path (*PathFromFunction)(const SVGElement&);
static HashMap<AtomStringImpl*, PathFromFunction>* map = 0;
if (!map) {
map = new HashMap<AtomStringImpl*, PathFromFunction>;
map->set(SVGNames::circleTag->localName().impl(), pathFromCircleElement);
map->set(SVGNames::ellipseTag->localName().impl(), pathFromEllipseElement);
map->set(SVGNames::lineTag->localName().impl(), pathFromLineElement);
map->set(SVGNames::pathTag->localName().impl(), pathFromPathElement);
map->set(SVGNames::polygonTag->localName().impl(), pathFromPolygonElement);
map->set(SVGNames::polylineTag->localName().impl(), pathFromPolylineElement);
map->set(SVGNames::rectTag->localName().impl(), pathFromRectElement);
switch (element.tagQName().nodeName()) {
case ElementNames::SVG::circle:
return pathFromCircleElement(element);
case ElementNames::SVG::ellipse:
return pathFromEllipseElement(element);
case ElementNames::SVG::line:
return pathFromLineElement(element);
case ElementNames::SVG::path:
return pathFromPathElement(element);
case ElementNames::SVG::polygon:
return pathFromPolygonElement(element);
case ElementNames::SVG::polyline:
return pathFromPolylineElement(element);
case ElementNames::SVG::rect:
return pathFromRectElement(element);
default:
break;
}

if (PathFromFunction pathFromFunction = map->get(element->localName().impl()))
return (*pathFromFunction)(*element);

return { };
}

Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/rendering/svg/SVGPathData.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ namespace WebCore {
class SVGElement;
class Path;

Path pathFromGraphicsElement(const SVGElement*);
Path pathFromGraphicsElement(const SVGElement&);

} // namespace WebCore
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ Path& LegacyRenderSVGShape::ensurePath()

std::unique_ptr<Path> LegacyRenderSVGShape::createPath() const
{
return makeUnique<Path>(pathFromGraphicsElement(&graphicsElement()));
return makeUnique<Path>(pathFromGraphicsElement(graphicsElement()));
}

}
2 changes: 1 addition & 1 deletion Source/WebCore/svg/SVGAnimateMotionElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ void SVGAnimateMotionElement::updateAnimationPath()
for (auto& mPath : childrenOfType<SVGMPathElement>(*this)) {
auto pathElement = mPath.pathElement();
if (pathElement) {
m_animationPath = pathFromGraphicsElement(pathElement.get());
m_animationPath = pathFromGraphicsElement(*pathElement);
foundMPath = true;
break;
}
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/svg/SVGGraphicsElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ void SVGGraphicsElement::didAttachRenderers()
Path SVGGraphicsElement::toClipPath()
{
// FIXME: [LBSE] Stop mutating the path here and stop calling animatedLocalTransform().
Path path = pathFromGraphicsElement(this);
Path path = pathFromGraphicsElement(*this);
// FIXME: How do we know the element has done a layout?
path.transform(animatedLocalTransform());
return path;
Expand Down

0 comments on commit 0296432

Please sign in to comment.