This source file includes following definitions.
- m_usePathFallback
- updateShapeFromElement
- fillShape
- strokeShape
- shapeDependentStrokeContains
- shapeDependentFillContains
#include "config.h"
#include "core/rendering/svg/RenderSVGRect.h"
#include "SVGNames.h"
namespace WebCore {
RenderSVGRect::RenderSVGRect(SVGRectElement* node)
: RenderSVGShape(node)
, m_usePathFallback(false)
{
}
RenderSVGRect::~RenderSVGRect()
{
}
void RenderSVGRect::updateShapeFromElement()
{
m_fillBoundingBox = FloatRect();
m_innerStrokeRect = FloatRect();
m_outerStrokeRect = FloatRect();
SVGRectElement* rect = toSVGRectElement(element());
ASSERT(rect);
SVGLengthContext lengthContext(rect);
if (rect->rx()->currentValue()->value(lengthContext) > 0 || rect->ry()->currentValue()->value(lengthContext) > 0 || hasNonScalingStroke()) {
RenderSVGShape::updateShapeFromElement();
m_usePathFallback = true;
return;
}
m_usePathFallback = false;
FloatSize boundingBoxSize(rect->width()->currentValue()->value(lengthContext), rect->height()->currentValue()->value(lengthContext));
if (boundingBoxSize.isZero() || boundingBoxSize.width() < 0 || boundingBoxSize.height() < 0)
return;
m_fillBoundingBox = FloatRect(FloatPoint(rect->x()->currentValue()->value(lengthContext), rect->y()->currentValue()->value(lengthContext)), boundingBoxSize);
m_innerStrokeRect = m_fillBoundingBox;
m_outerStrokeRect = m_fillBoundingBox;
if (style()->svgStyle()->hasStroke()) {
float strokeWidth = this->strokeWidth();
m_innerStrokeRect.inflate(-strokeWidth / 2);
m_outerStrokeRect.inflate(strokeWidth / 2);
}
m_strokeBoundingBox = m_outerStrokeRect;
}
void RenderSVGRect::fillShape(GraphicsContext* context) const
{
if (m_usePathFallback) {
RenderSVGShape::fillShape(context);
return;
}
context->fillRect(m_fillBoundingBox);
}
void RenderSVGRect::strokeShape(GraphicsContext* context) const
{
if (!style()->svgStyle()->hasVisibleStroke())
return;
if (m_usePathFallback) {
RenderSVGShape::strokeShape(context);
return;
}
context->strokeRect(m_fillBoundingBox, strokeWidth());
}
bool RenderSVGRect::shapeDependentStrokeContains(const FloatPoint& point)
{
if (m_usePathFallback || !hasSmoothStroke()) {
if (!hasPath())
RenderSVGShape::updateShapeFromElement();
return RenderSVGShape::shapeDependentStrokeContains(point);
}
return m_outerStrokeRect.contains(point, FloatRect::InsideOrOnStroke) && !m_innerStrokeRect.contains(point, FloatRect::InsideButNotOnStroke);
}
bool RenderSVGRect::shapeDependentFillContains(const FloatPoint& point, const WindRule fillRule) const
{
if (m_usePathFallback)
return RenderSVGShape::shapeDependentFillContains(point, fillRule);
return m_fillBoundingBox.contains(point.x(), point.y());
}
}