#include "config.h"
#if ENABLE(SVG)
#include "RenderSVGRect.h"
#include "SVGNames.h"
#include "SVGRectElement.h"
#include <wtf/Platform.h>
namespace WebCore {
RenderSVGRect::RenderSVGRect(SVGRectElement* node)
: RenderSVGShape(node)
{
}
RenderSVGRect::~RenderSVGRect()
{
}
void RenderSVGRect::createShape()
{
m_boundingBox = FloatRect();
m_innerStrokeRect = FloatRect();
m_outerStrokeRect = FloatRect();
SVGRectElement* rect = static_cast<SVGRectElement*>(node());
ASSERT(rect);
bool nonScalingStroke = style()->svgStyle()->vectorEffect() == VE_NON_SCALING_STROKE;
if (rect->hasAttribute(SVGNames::rxAttr) || rect->hasAttribute(SVGNames::ryAttr) || nonScalingStroke) {
RenderSVGShape::createShape();
setIsPaintingFallback(true);
return;
}
SVGLengthContext lengthContext(rect);
FloatSize boundingBoxSize(rect->width().value(lengthContext), rect->height().value(lengthContext));
if (boundingBoxSize.isEmpty())
return;
m_boundingBox = FloatRect(FloatPoint(rect->x().value(lengthContext), rect->y().value(lengthContext)), boundingBoxSize);
m_innerStrokeRect = m_boundingBox;
m_outerStrokeRect = m_boundingBox;
if (style()->svgStyle()->hasStroke()) {
float strokeWidth = this->strokeWidth();
m_innerStrokeRect.inflate(-strokeWidth / 2);
m_outerStrokeRect.inflate(strokeWidth / 2);
}
m_strokeBoundingRect = m_outerStrokeRect;
#if USE(CG)
if (style()->svgStyle()->shapeRendering() == SR_CRISPEDGES)
m_strokeBoundingRect.inflate(1);
#endif
}
FloatRect RenderSVGRect::objectBoundingBox() const
{
if (isPaintingFallback())
return RenderSVGShape::objectBoundingBox();
return m_boundingBox;
}
FloatRect RenderSVGRect::strokeBoundingBox() const
{
if (isPaintingFallback())
return RenderSVGShape::strokeBoundingBox();
return m_strokeBoundingRect;
}
void RenderSVGRect::fillShape(GraphicsContext* context) const
{
if (!isPaintingFallback()) {
#if USE(CG)
if (context->hasShadow()) {
GraphicsContextStateSaver stateSaver(*context);
context->clearShadow();
context->fillRect(m_boundingBox);
return;
}
#endif
context->fillRect(m_boundingBox);
return;
}
RenderSVGShape::fillShape(context);
}
void RenderSVGRect::strokeShape(GraphicsContext* context) const
{
if (!style()->svgStyle()->hasVisibleStroke())
return;
if (!isPaintingFallback()) {
context->strokeRect(m_boundingBox, strokeWidth());
return;
}
RenderSVGShape::strokeShape(context);
}
bool RenderSVGRect::shapeDependentStrokeContains(const FloatPoint& point) const
{
return m_outerStrokeRect.contains(point, FloatRect::InsideOrOnStroke) && !m_innerStrokeRect.contains(point, FloatRect::InsideButNotOnStroke);
}
bool RenderSVGRect::shapeDependentFillContains(const FloatPoint& point, const WindRule fillRule) const
{
if (isPaintingFallback())
return RenderSVGShape::shapeDependentFillContains(point, fillRule);
return m_boundingBox.contains(point.x(), point.y());
}
}
#endif // ENABLE(SVG)