diff options
Diffstat (limited to 'Source/WebCore/rendering/svg/RenderSVGRect.cpp')
-rw-r--r-- | Source/WebCore/rendering/svg/RenderSVGRect.cpp | 61 |
1 files changed, 34 insertions, 27 deletions
diff --git a/Source/WebCore/rendering/svg/RenderSVGRect.cpp b/Source/WebCore/rendering/svg/RenderSVGRect.cpp index bfda62f5f..2ceba5d91 100644 --- a/Source/WebCore/rendering/svg/RenderSVGRect.cpp +++ b/Source/WebCore/rendering/svg/RenderSVGRect.cpp @@ -26,16 +26,12 @@ */ #include "config.h" - -#if ENABLE(SVG) #include "RenderSVGRect.h" -#include "SVGNames.h" - namespace WebCore { -RenderSVGRect::RenderSVGRect(SVGRectElement& element, PassRef<RenderStyle> style) - : RenderSVGShape(element, std::move(style)) +RenderSVGRect::RenderSVGRect(SVGRectElement& element, RenderStyle&& style) + : RenderSVGShape(element, WTFMove(style)) , m_usePathFallback(false) { } @@ -46,7 +42,7 @@ RenderSVGRect::~RenderSVGRect() SVGRectElement& RenderSVGRect::rectElement() const { - return toSVGRectElement(RenderSVGShape::graphicsElement()); + return downcast<SVGRectElement>(RenderSVGShape::graphicsElement()); } void RenderSVGRect::updateShapeFromElement() @@ -58,19 +54,26 @@ void RenderSVGRect::updateShapeFromElement() m_outerStrokeRect = FloatRect(); SVGLengthContext lengthContext(&rectElement()); - // Fallback to RenderSVGShape if rect has rounded corners or a non-scaling stroke. - if (rectElement().rx().value(lengthContext) > 0 || rectElement().ry().value(lengthContext) > 0 || hasNonScalingStroke()) { - RenderSVGShape::updateShapeFromElement(); - m_usePathFallback = true; - return; - } + FloatSize boundingBoxSize(lengthContext.valueForLength(style().width(), LengthModeWidth), lengthContext.valueForLength(style().height(), LengthModeHeight)); - m_usePathFallback = false; - FloatSize boundingBoxSize(rectElement().width().value(lengthContext), rectElement().height().value(lengthContext)); - if (boundingBoxSize.isEmpty()) + // Element is invalid if either dimension is negative. + if (boundingBoxSize.width() < 0 || boundingBoxSize.height() < 0) return; - m_fillBoundingBox = FloatRect(FloatPoint(rectElement().x().value(lengthContext), rectElement().y().value(lengthContext)), boundingBoxSize); + // Rendering enabled? Spec: "A value of zero disables rendering of the element." + if (!boundingBoxSize.isEmpty()) { + if (rectElement().rx().value(lengthContext) > 0 || rectElement().ry().value(lengthContext) > 0 || hasNonScalingStroke()) { + // Fall back to RenderSVGShape + RenderSVGShape::updateShapeFromElement(); + m_usePathFallback = true; + return; + } + m_usePathFallback = false; + } + + m_fillBoundingBox = FloatRect(FloatPoint(lengthContext.valueForLength(style().svgStyle().x(), LengthModeWidth), + lengthContext.valueForLength(style().svgStyle().y(), LengthModeHeight)), + boundingBoxSize); // To decide if the stroke contains a point we create two rects which represent the inner and // the outer stroke borders. A stroke contains the point, if the point is between them. @@ -92,7 +95,7 @@ void RenderSVGRect::updateShapeFromElement() #endif } -void RenderSVGRect::fillShape(GraphicsContext* context) const +void RenderSVGRect::fillShape(GraphicsContext& context) const { if (m_usePathFallback) { RenderSVGShape::fillShape(context); @@ -104,20 +107,20 @@ void RenderSVGRect::fillShape(GraphicsContext* context) const // shadow drawing method, which draws an extra shadow. // This is a workaround for switching off the extra shadow. // https://bugs.webkit.org/show_bug.cgi?id=68899 - if (context->hasShadow()) { - GraphicsContextStateSaver stateSaver(*context); - context->clearShadow(); - context->fillRect(m_fillBoundingBox); + if (context.hasShadow()) { + GraphicsContextStateSaver stateSaver(context); + context.clearShadow(); + context.fillRect(m_fillBoundingBox); return; } #endif - context->fillRect(m_fillBoundingBox); + context.fillRect(m_fillBoundingBox); } -void RenderSVGRect::strokeShape(GraphicsContext* context) const +void RenderSVGRect::strokeShape(GraphicsContext& context) const { - if (!style().svgStyle().hasVisibleStroke()) + if (!style().hasVisibleStroke()) return; if (m_usePathFallback) { @@ -125,7 +128,7 @@ void RenderSVGRect::strokeShape(GraphicsContext* context) const return; } - context->strokeRect(m_fillBoundingBox, strokeWidth()); + context.strokeRect(m_fillBoundingBox, strokeWidth()); } bool RenderSVGRect::shapeDependentStrokeContains(const FloatPoint& point) @@ -148,6 +151,10 @@ bool RenderSVGRect::shapeDependentFillContains(const FloatPoint& point, const Wi return m_fillBoundingBox.contains(point.x(), point.y()); } +bool RenderSVGRect::isRenderingDisabled() const +{ + // A width or height of zero disables rendering for the element, and results in an empty bounding box. + return m_fillBoundingBox.isEmpty(); } -#endif // ENABLE(SVG) +} |