Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
CTTE: RenderSVGResourceMarker always has an SVGMarkerElement.
<https://webkit.org/b/121345>

Reviewed by Brent Fulgham.

This renderer is never anonymous. Tighten things up with a maskElement()
reference getter. Removed some unnecessary type casts and assertions.

Canonical link: https://commits.webkit.org/139307@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@155750 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
Andreas Kling committed Sep 14, 2013
1 parent f01878a commit c85081c
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 36 deletions.
10 changes: 10 additions & 0 deletions Source/WebCore/ChangeLog
@@ -1,3 +1,13 @@
2013-09-13 Andreas Kling <akling@apple.com>

CTTE: RenderSVGResourceMarker always has an SVGMarkerElement.
<https://webkit.org/b/121345>

Reviewed by Brent Fulgham.

This renderer is never anonymous. Tighten things up with a maskElement()
reference getter. Removed some unnecessary type casts and assertions.

2013-09-13 Andreas Kling <akling@apple.com>

CTTE: RenderSVGResourceMasker always has an SVGMaskElement.
Expand Down
41 changes: 12 additions & 29 deletions Source/WebCore/rendering/svg/RenderSVGResourceMarker.cpp
Expand Up @@ -37,8 +37,8 @@ namespace WebCore {

RenderSVGResourceType RenderSVGResourceMarker::s_resourceType = MarkerResourceType;

RenderSVGResourceMarker::RenderSVGResourceMarker(SVGMarkerElement* node)
: RenderSVGResourceContainer(node)
RenderSVGResourceMarker::RenderSVGResourceMarker(SVGMarkerElement& element)
: RenderSVGResourceContainer(&element)
{
}

Expand Down Expand Up @@ -96,32 +96,23 @@ const AffineTransform& RenderSVGResourceMarker::localToParentTransform() const

FloatPoint RenderSVGResourceMarker::referencePoint() const
{
SVGMarkerElement* marker = toSVGMarkerElement(element());
ASSERT(marker);

SVGLengthContext lengthContext(marker);
return FloatPoint(marker->refX().value(lengthContext), marker->refY().value(lengthContext));
SVGLengthContext lengthContext(&markerElement());
return FloatPoint(markerElement().refX().value(lengthContext), markerElement().refY().value(lengthContext));
}

float RenderSVGResourceMarker::angle() const
{
SVGMarkerElement* marker = toSVGMarkerElement(element());
ASSERT(marker);

float angle = -1;
if (marker->orientType() == SVGMarkerOrientAngle)
angle = marker->orientAngle().value();
if (markerElement().orientType() == SVGMarkerOrientAngle)
angle = markerElement().orientAngle().value();

return angle;
}

AffineTransform RenderSVGResourceMarker::markerTransformation(const FloatPoint& origin, float autoAngle, float strokeWidth) const
{
SVGMarkerElement* marker = toSVGMarkerElement(element());
ASSERT(marker);

float markerAngle = angle();
bool useStrokeWidth = marker->markerUnits() == SVGMarkerUnitsStrokeWidth;
bool useStrokeWidth = markerElement().markerUnits() == SVGMarkerUnitsStrokeWidth;

AffineTransform transform;
transform.translate(origin.x(), origin.y());
Expand All @@ -133,9 +124,7 @@ AffineTransform RenderSVGResourceMarker::markerTransformation(const FloatPoint&
void RenderSVGResourceMarker::draw(PaintInfo& paintInfo, const AffineTransform& transform)
{
// An empty viewBox disables rendering.
SVGMarkerElement* marker = toSVGMarkerElement(element());
ASSERT(marker);
if (marker->hasAttribute(SVGNames::viewBoxAttr) && marker->viewBoxIsValid() && marker->viewBox().isEmpty())
if (markerElement().hasAttribute(SVGNames::viewBoxAttr) && markerElement().viewBoxIsValid() && markerElement().viewBox().isEmpty())
return;

PaintInfo info(paintInfo);
Expand All @@ -159,23 +148,17 @@ AffineTransform RenderSVGResourceMarker::markerContentTransformation(const Affin

AffineTransform RenderSVGResourceMarker::viewportTransform() const
{
SVGMarkerElement* marker = toSVGMarkerElement(element());
ASSERT(marker);

return marker->viewBoxToViewTransform(m_viewport.width(), m_viewport.height());
return markerElement().viewBoxToViewTransform(m_viewport.width(), m_viewport.height());
}

void RenderSVGResourceMarker::calcViewport()
{
if (!selfNeedsLayout())
return;

SVGMarkerElement* marker = toSVGMarkerElement(element());
ASSERT(marker);

SVGLengthContext lengthContext(marker);
float w = marker->markerWidth().value(lengthContext);
float h = marker->markerHeight().value(lengthContext);
SVGLengthContext lengthContext(&markerElement());
float w = markerElement().markerWidth().value(lengthContext);
float h = markerElement().markerHeight().value(lengthContext);
m_viewport = FloatRect(0, 0, w, h);
}

Expand Down
10 changes: 7 additions & 3 deletions Source/WebCore/rendering/svg/RenderSVGResourceMarker.h
Expand Up @@ -35,10 +35,10 @@ class RenderObject;

class RenderSVGResourceMarker FINAL : public RenderSVGResourceContainer {
public:
RenderSVGResourceMarker(SVGMarkerElement*);
explicit RenderSVGResourceMarker(SVGMarkerElement&);
virtual ~RenderSVGResourceMarker();

virtual const char* renderName() const { return "RenderSVGResourceMarker"; }
SVGMarkerElement& markerElement() const { return toSVGMarkerElement(*RenderSVGResourceContainer::element()); }

virtual void removeAllClientsFromCache(bool markForInvalidation = true);
virtual void removeClientFromCache(RenderObject*, bool markForInvalidation = true);
Expand All @@ -60,12 +60,16 @@ class RenderSVGResourceMarker FINAL : public RenderSVGResourceContainer {

FloatPoint referencePoint() const;
float angle() const;
SVGMarkerUnitsType markerUnits() const { return toSVGMarkerElement(element())->markerUnits(); }
SVGMarkerUnitsType markerUnits() const { return markerElement().markerUnits(); }

virtual RenderSVGResourceType resourceType() const { return s_resourceType; }
static RenderSVGResourceType s_resourceType;

private:
void element() const WTF_DELETED_FUNCTION;

virtual const char* renderName() const OVERRIDE { return "RenderSVGResourceMarker"; }

// Generates a transformation matrix usable to render marker content. Handles scaling the marker content
// acording to SVGs markerUnits="strokeWidth" concept, when a strokeWidth value != -1 is passed in.
AffineTransform markerContentTransformation(const AffineTransform& contentTransformation, const FloatPoint& origin, float strokeWidth = -1) const;
Expand Down
6 changes: 3 additions & 3 deletions Source/WebCore/rendering/svg/SVGResources.cpp
Expand Up @@ -658,11 +658,11 @@ void SVGResources::dump(const RenderObject* object)

if (m_markerData) {
if (RenderSVGResourceMarker* markerStart = m_markerData->markerStart)
fprintf(stderr, " |-> MarkerStart: %p (node=%p)\n", markerStart, markerStart->element());
fprintf(stderr, " |-> MarkerStart: %p (node=%p)\n", markerStart, &markerStart->markerElement());
if (RenderSVGResourceMarker* markerMid = m_markerData->markerMid)
fprintf(stderr, " |-> MarkerMid : %p (node=%p)\n", markerMid, markerMid->element());
fprintf(stderr, " |-> MarkerMid : %p (node=%p)\n", markerMid, &markerMid->markerElement());
if (RenderSVGResourceMarker* markerEnd = m_markerData->markerEnd)
fprintf(stderr, " |-> MarkerEnd : %p (node=%p)\n", markerEnd, markerEnd->element());
fprintf(stderr, " |-> MarkerEnd : %p (node=%p)\n", markerEnd, &markerEnd->markerElement());
}

if (m_fillStrokeData) {
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/svg/SVGMarkerElement.cpp
Expand Up @@ -216,7 +216,7 @@ void SVGMarkerElement::setOrientToAngle(const SVGAngle& angle)

RenderObject* SVGMarkerElement::createRenderer(RenderArena* arena, RenderStyle*)
{
return new (arena) RenderSVGResourceMarker(this);
return new (arena) RenderSVGResourceMarker(*this);
}

bool SVGMarkerElement::selfHasRelativeLengths() const
Expand Down

0 comments on commit c85081c

Please sign in to comment.