This source file includes following definitions.
- layout
- removeAllClientsFromCache
- removeClientFromCache
- applyViewportClip
- markerBoundaries
- localToParentTransform
- referencePoint
- angle
- markerTransformation
- draw
- markerContentTransformation
- viewportTransform
- calcViewport
#include "config.h"
#include "core/rendering/svg/RenderSVGResourceMarker.h"
#include "core/rendering/LayoutRectRecorder.h"
#include "core/rendering/svg/RenderSVGContainer.h"
#include "core/rendering/svg/SVGRenderSupport.h"
#include "platform/graphics/GraphicsContextStateSaver.h"
#include "wtf/TemporaryChange.h"
namespace WebCore {
const RenderSVGResourceType RenderSVGResourceMarker::s_resourceType = MarkerResourceType;
RenderSVGResourceMarker::RenderSVGResourceMarker(SVGMarkerElement* node)
: RenderSVGResourceContainer(node)
{
}
RenderSVGResourceMarker::~RenderSVGResourceMarker()
{
}
void RenderSVGResourceMarker::layout()
{
ASSERT(needsLayout());
if (m_isInLayout)
return;
LayoutRectRecorder recorder(*this);
TemporaryChange<bool> inLayoutChange(m_isInLayout, true);
RenderSVGContainer::layout();
clearInvalidationMask();
}
void RenderSVGResourceMarker::removeAllClientsFromCache(bool markForInvalidation)
{
markAllClientsForInvalidation(markForInvalidation ? LayoutAndBoundariesInvalidation : ParentOnlyInvalidation);
}
void RenderSVGResourceMarker::removeClientFromCache(RenderObject* client, bool markForInvalidation)
{
ASSERT(client);
markClientForInvalidation(client, markForInvalidation ? BoundariesInvalidation : ParentOnlyInvalidation);
}
void RenderSVGResourceMarker::applyViewportClip(PaintInfo& paintInfo)
{
if (SVGRenderSupport::isOverflowHidden(this))
paintInfo.context->clip(m_viewport);
}
FloatRect RenderSVGResourceMarker::markerBoundaries(const AffineTransform& markerTransformation) const
{
FloatRect coordinates = RenderSVGContainer::repaintRectInLocalCoordinates();
coordinates = localToParentTransform().mapRect(coordinates);
return markerTransformation.mapRect(coordinates);
}
const AffineTransform& RenderSVGResourceMarker::localToParentTransform() const
{
m_localToParentTransform = AffineTransform::translation(m_viewport.x(), m_viewport.y()) * viewportTransform();
return m_localToParentTransform;
}
FloatPoint RenderSVGResourceMarker::referencePoint() const
{
SVGMarkerElement* marker = toSVGMarkerElement(element());
ASSERT(marker);
SVGLengthContext lengthContext(marker);
return FloatPoint(marker->refX()->currentValue()->value(lengthContext), marker->refY()->currentValue()->value(lengthContext));
}
float RenderSVGResourceMarker::angle() const
{
SVGMarkerElement* marker = toSVGMarkerElement(element());
ASSERT(marker);
float angle = -1;
if (marker->orientType()->currentValue()->enumValue() == SVGMarkerOrientAngle)
angle = marker->orientAngle()->currentValue()->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()->currentValue()->enumValue() == SVGMarkerUnitsStrokeWidth;
AffineTransform transform;
transform.translate(origin.x(), origin.y());
transform.rotate(markerAngle == -1 ? autoAngle : markerAngle);
transform = markerContentTransformation(transform, referencePoint(), useStrokeWidth ? strokeWidth : -1);
return transform;
}
void RenderSVGResourceMarker::draw(PaintInfo& paintInfo, const AffineTransform& transform)
{
clearInvalidationMask();
SVGMarkerElement* marker = toSVGMarkerElement(element());
ASSERT(marker);
if (marker->hasAttribute(SVGNames::viewBoxAttr) && marker->viewBox()->currentValue()->isValid() && marker->viewBox()->currentValue()->value().isEmpty())
return;
PaintInfo info(paintInfo);
GraphicsContextStateSaver stateSaver(*info.context, false);
if (!transform.isIdentity()) {
stateSaver.save();
info.applyTransform(transform, false);
}
RenderSVGContainer::paint(info, IntPoint());
}
AffineTransform RenderSVGResourceMarker::markerContentTransformation(const AffineTransform& contentTransformation, const FloatPoint& origin, float strokeWidth) const
{
FloatPoint mappedOrigin = viewportTransform().mapPoint(origin);
AffineTransform transformation = contentTransformation;
if (strokeWidth != -1)
transformation.scaleNonUniform(strokeWidth, strokeWidth);
transformation.translate(-mappedOrigin.x(), -mappedOrigin.y());
return transformation;
}
AffineTransform RenderSVGResourceMarker::viewportTransform() const
{
SVGMarkerElement* marker = toSVGMarkerElement(element());
ASSERT(marker);
return marker->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()->currentValue()->value(lengthContext);
float h = marker->markerHeight()->currentValue()->value(lengthContext);
m_viewport = FloatRect(0, 0, w, h);
}
}