- Revision
- 145459
- Author
- [email protected]
- Date
- 2013-03-11 18:50:07 -0700 (Mon, 11 Mar 2013)
Log Message
Replace static_casts for SVGSVGElement and SVGStopElement
https://bugs.webkit.org/show_bug.cgi?id=111651
Reviewed by Stephen Chenney.
toSVGSVGElement and toSVGStopElement are preferred over static_casts because bad casts
can be caught on our testing infrastructure. This patches replaces all static_casts for
SVGSVGElement and SVGStopElement with toSVGSVGElement and toSVGStopElement, respectively.
Additionaly, this patch renames SVGElement::isSVG to SVGElement::isSVGSVGElement to
remove ambiguity for callers who may confuse this with isSVGElement.
No new tests as this is covered with existing tests.
* rendering/svg/RenderSVGRoot.cpp:
(WebCore::RenderSVGRoot::computeIntrinsicRatioInformation):
(WebCore::RenderSVGRoot::computeReplacedLogicalWidth):
(WebCore::RenderSVGRoot::computeReplacedLogicalHeight):
(WebCore::RenderSVGRoot::layout):
(WebCore::RenderSVGRoot::buildLocalToBorderBoxTransform):
(WebCore::RenderSVGRoot::hasRelativeDimensions):
(WebCore::RenderSVGRoot::hasRelativeIntrinsicLogicalWidth):
(WebCore::RenderSVGRoot::hasRelativeLogicalHeight):
* rendering/svg/RenderSVGViewportContainer.cpp:
(WebCore::RenderSVGViewportContainer::determineIfLayoutSizeChanged):
(WebCore::RenderSVGViewportContainer::calcViewport):
(WebCore::RenderSVGViewportContainer::viewportTransform):
* svg/SVGDocument.cpp:
(WebCore::SVGDocument::rootElement):
(WebCore::SVGDocument::childShouldCreateRenderer):
* svg/SVGElement.cpp:
(WebCore::SVGElement::ownerSVGElement):
* svg/SVGElement.h:
(WebCore::SVGElement::isSVGSVGElement):
* svg/SVGGradientElement.cpp:
(WebCore::SVGGradientElement::buildStops):
* svg/SVGLengthContext.cpp:
(WebCore::SVGLengthContext::determineViewport):
* svg/SVGSVGElement.h:
(WebCore):
(WebCore::toSVGSVGElement):
* svg/SVGStopElement.h:
(WebCore::toSVGStopElement):
(WebCore):
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (145458 => 145459)
--- trunk/Source/WebCore/ChangeLog 2013-03-12 01:42:07 UTC (rev 145458)
+++ trunk/Source/WebCore/ChangeLog 2013-03-12 01:50:07 UTC (rev 145459)
@@ -1,3 +1,50 @@
+2013-03-11 Philip Rogers <[email protected]>
+
+ Replace static_casts for SVGSVGElement and SVGStopElement
+ https://bugs.webkit.org/show_bug.cgi?id=111651
+
+ Reviewed by Stephen Chenney.
+
+ toSVGSVGElement and toSVGStopElement are preferred over static_casts because bad casts
+ can be caught on our testing infrastructure. This patches replaces all static_casts for
+ SVGSVGElement and SVGStopElement with toSVGSVGElement and toSVGStopElement, respectively.
+
+ Additionaly, this patch renames SVGElement::isSVG to SVGElement::isSVGSVGElement to
+ remove ambiguity for callers who may confuse this with isSVGElement.
+
+ No new tests as this is covered with existing tests.
+
+ * rendering/svg/RenderSVGRoot.cpp:
+ (WebCore::RenderSVGRoot::computeIntrinsicRatioInformation):
+ (WebCore::RenderSVGRoot::computeReplacedLogicalWidth):
+ (WebCore::RenderSVGRoot::computeReplacedLogicalHeight):
+ (WebCore::RenderSVGRoot::layout):
+ (WebCore::RenderSVGRoot::buildLocalToBorderBoxTransform):
+ (WebCore::RenderSVGRoot::hasRelativeDimensions):
+ (WebCore::RenderSVGRoot::hasRelativeIntrinsicLogicalWidth):
+ (WebCore::RenderSVGRoot::hasRelativeLogicalHeight):
+ * rendering/svg/RenderSVGViewportContainer.cpp:
+ (WebCore::RenderSVGViewportContainer::determineIfLayoutSizeChanged):
+ (WebCore::RenderSVGViewportContainer::calcViewport):
+ (WebCore::RenderSVGViewportContainer::viewportTransform):
+ * svg/SVGDocument.cpp:
+ (WebCore::SVGDocument::rootElement):
+ (WebCore::SVGDocument::childShouldCreateRenderer):
+ * svg/SVGElement.cpp:
+ (WebCore::SVGElement::ownerSVGElement):
+ * svg/SVGElement.h:
+ (WebCore::SVGElement::isSVGSVGElement):
+ * svg/SVGGradientElement.cpp:
+ (WebCore::SVGGradientElement::buildStops):
+ * svg/SVGLengthContext.cpp:
+ (WebCore::SVGLengthContext::determineViewport):
+ * svg/SVGSVGElement.h:
+ (WebCore):
+ (WebCore::toSVGSVGElement):
+ * svg/SVGStopElement.h:
+ (WebCore::toSVGStopElement):
+ (WebCore):
+
2013-03-11 Tony Chang <[email protected]>
Small code cleanup in RenderFlexibleBox
Modified: trunk/Source/WebCore/rendering/svg/RenderSVGRoot.cpp (145458 => 145459)
--- trunk/Source/WebCore/rendering/svg/RenderSVGRoot.cpp 2013-03-12 01:42:07 UTC (rev 145458)
+++ trunk/Source/WebCore/rendering/svg/RenderSVGRoot.cpp 2013-03-12 01:50:07 UTC (rev 145459)
@@ -77,7 +77,8 @@
// the same as the CSS width and height properties. Specifically, percentage values do not provide an intrinsic width or height,
// and do not indicate a percentage of the containing block. Rather, once the viewport is established, they indicate the portion
// of the viewport that is actually covered by image data.
- SVGSVGElement* svg = static_cast<SVGSVGElement*>(node());
+ SVGSVGElement* svg = toSVGSVGElement(node());
+ ASSERT(svg);
Length intrinsicWidthAttribute = svg->intrinsicWidth(SVGSVGElement::IgnoreCSSProperties);
Length intrinsicHeightAttribute = svg->intrinsicHeight(SVGSVGElement::IgnoreCSSProperties);
@@ -161,7 +162,7 @@
LayoutUnit RenderSVGRoot::computeReplacedLogicalWidth(ShouldComputePreferred shouldComputePreferred) const
{
- SVGSVGElement* svg = static_cast<SVGSVGElement*>(node());
+ SVGSVGElement* svg = toSVGSVGElement(node());
ASSERT(svg);
// When we're embedded through SVGImage (border-image/background-image/<html:img>/...) we're forced to resize to a specific size.
@@ -184,7 +185,7 @@
LayoutUnit RenderSVGRoot::computeReplacedLogicalHeight() const
{
- SVGSVGElement* svg = static_cast<SVGSVGElement*>(node());
+ SVGSVGElement* svg = toSVGSVGElement(node());
ASSERT(svg);
// When we're embedded through SVGImage (border-image/background-image/<html:img>/...) we're forced to resize to a specific size.
@@ -235,7 +236,8 @@
updateLogicalHeight();
buildLocalToBorderBoxTransform();
- SVGSVGElement* svg = static_cast<SVGSVGElement*>(node());
+ SVGSVGElement* svg = toSVGSVGElement(node());
+ ASSERT(svg);
m_isLayoutSizeChanged = needsLayout || (svg->hasRelativeLengths() && oldSize != size());
SVGRenderSupport::layoutChildren(this, needsLayout || SVGRenderSupport::filtersForceContainerLayout(this));
@@ -354,7 +356,8 @@
// relative to our borderBox origin. This method gives us exactly that.
void RenderSVGRoot::buildLocalToBorderBoxTransform()
{
- SVGSVGElement* svg = static_cast<SVGSVGElement*>(node());
+ SVGSVGElement* svg = toSVGSVGElement(node());
+ ASSERT(svg);
float scale = style()->effectiveZoom();
FloatPoint translate = svg->currentTranslate();
LayoutSize borderAndPadding(borderLeft() + paddingLeft(), borderTop() + paddingTop());
@@ -463,7 +466,7 @@
bool RenderSVGRoot::hasRelativeDimensions() const
{
- SVGSVGElement* svg = static_cast<SVGSVGElement*>(node());
+ SVGSVGElement* svg = toSVGSVGElement(node());
ASSERT(svg);
return svg->intrinsicHeight(SVGSVGElement::IgnoreCSSProperties).isPercent() || svg->intrinsicWidth(SVGSVGElement::IgnoreCSSProperties).isPercent();
@@ -471,14 +474,14 @@
bool RenderSVGRoot::hasRelativeIntrinsicLogicalWidth() const
{
- SVGSVGElement* svg = static_cast<SVGSVGElement*>(node());
+ SVGSVGElement* svg = toSVGSVGElement(node());
ASSERT(svg);
return svg->intrinsicWidth(SVGSVGElement::IgnoreCSSProperties).isPercent();
}
bool RenderSVGRoot::hasRelativeLogicalHeight() const
{
- SVGSVGElement* svg = static_cast<SVGSVGElement*>(node());
+ SVGSVGElement* svg = toSVGSVGElement(node());
ASSERT(svg);
return svg->intrinsicHeight(SVGSVGElement::IgnoreCSSProperties).isPercent();
Modified: trunk/Source/WebCore/rendering/svg/RenderSVGViewportContainer.cpp (145458 => 145459)
--- trunk/Source/WebCore/rendering/svg/RenderSVGViewportContainer.cpp 2013-03-12 01:42:07 UTC (rev 145458)
+++ trunk/Source/WebCore/rendering/svg/RenderSVGViewportContainer.cpp 2013-03-12 01:50:07 UTC (rev 145459)
@@ -47,7 +47,7 @@
if (!node()->hasTagName(SVGNames::svgTag))
return;
- m_isLayoutSizeChanged = static_cast<SVGSVGElement*>(node())->hasRelativeLengths() && selfNeedsLayout();
+ m_isLayoutSizeChanged = toSVGSVGElement(node())->hasRelativeLengths() && selfNeedsLayout();
}
void RenderSVGViewportContainer::applyViewportClip(PaintInfo& paintInfo)
@@ -61,7 +61,7 @@
SVGElement* element = static_cast<SVGElement*>(node());
if (!element->hasTagName(SVGNames::svgTag))
return;
- SVGSVGElement* svg = static_cast<SVGSVGElement*>(element);
+ SVGSVGElement* svg = toSVGSVGElement(element);
FloatRect oldViewport = m_viewport;
SVGLengthContext lengthContext(element);
@@ -133,7 +133,7 @@
AffineTransform RenderSVGViewportContainer::viewportTransform() const
{
if (node()->hasTagName(SVGNames::svgTag)) {
- SVGSVGElement* svg = static_cast<SVGSVGElement*>(node());
+ SVGSVGElement* svg = toSVGSVGElement(node());
return svg->viewBoxToViewTransform(m_viewport.width(), m_viewport.height());
}
Modified: trunk/Source/WebCore/svg/SVGDocument.cpp (145458 => 145459)
--- trunk/Source/WebCore/svg/SVGDocument.cpp 2013-03-12 01:42:07 UTC (rev 145458)
+++ trunk/Source/WebCore/svg/SVGDocument.cpp 2013-03-12 01:50:07 UTC (rev 145459)
@@ -45,7 +45,7 @@
{
Element* elem = documentElement();
if (elem && elem->hasTagName(SVGNames::svgTag))
- return static_cast<SVGSVGElement*>(elem);
+ return toSVGSVGElement(elem);
return 0;
}
@@ -97,7 +97,7 @@
bool SVGDocument::childShouldCreateRenderer(const NodeRenderingContext& childContext) const
{
if (childContext.node()->hasTagName(SVGNames::svgTag))
- return static_cast<SVGSVGElement*>(childContext.node())->isValid();
+ return toSVGSVGElement(childContext.node())->isValid();
return true;
}
Modified: trunk/Source/WebCore/svg/SVGElement.cpp (145458 => 145459)
--- trunk/Source/WebCore/svg/SVGElement.cpp 2013-03-12 01:42:07 UTC (rev 145458)
+++ trunk/Source/WebCore/svg/SVGElement.cpp 2013-03-12 01:50:07 UTC (rev 145459)
@@ -190,7 +190,7 @@
ContainerNode* n = parentOrShadowHostNode();
while (n) {
if (n->hasTagName(SVGNames::svgTag))
- return static_cast<SVGSVGElement*>(n);
+ return toSVGSVGElement(n);
n = n->parentOrShadowHostNode();
}
Modified: trunk/Source/WebCore/svg/SVGElement.h (145458 => 145459)
--- trunk/Source/WebCore/svg/SVGElement.h 2013-03-12 01:42:07 UTC (rev 145458)
+++ trunk/Source/WebCore/svg/SVGElement.h 2013-03-12 01:50:07 UTC (rev 145459)
@@ -60,7 +60,7 @@
virtual bool isSVGStyledElement() const { return false; }
virtual bool isStyledTransformable() const { return false; }
virtual bool isStyledLocatable() const { return false; }
- virtual bool isSVG() const { return false; }
+ virtual bool isSVGSVGElement() const { return false; }
virtual bool isFilterEffect() const { return false; }
virtual bool isGradientStop() const { return false; }
virtual bool isTextContent() const { return false; }
Modified: trunk/Source/WebCore/svg/SVGGradientElement.cpp (145458 => 145459)
--- trunk/Source/WebCore/svg/SVGGradientElement.cpp 2013-03-12 01:42:07 UTC (rev 145458)
+++ trunk/Source/WebCore/svg/SVGGradientElement.cpp 2013-03-12 01:50:07 UTC (rev 145459)
@@ -146,7 +146,7 @@
if (!element || !element->isGradientStop())
continue;
- SVGStopElement* stop = static_cast<SVGStopElement*>(element);
+ SVGStopElement* stop = toSVGStopElement(element);
Color color = stop->stopColorIncludingOpacity();
// Figure out right monotonic offset
Modified: trunk/Source/WebCore/svg/SVGLengthContext.cpp (145458 => 145459)
--- trunk/Source/WebCore/svg/SVGLengthContext.cpp 2013-03-12 01:42:07 UTC (rev 145458)
+++ trunk/Source/WebCore/svg/SVGLengthContext.cpp 2013-03-12 01:50:07 UTC (rev 145459)
@@ -299,7 +299,7 @@
// Take size from nearest viewport element.
SVGElement* viewportElement = m_context->viewportElement();
- if (!viewportElement || !viewportElement->isSVG())
+ if (!viewportElement || !viewportElement->isSVGSVGElement())
return false;
const SVGSVGElement* svg = static_cast<const SVGSVGElement*>(viewportElement);
Modified: trunk/Source/WebCore/svg/SVGSVGElement.h (145458 => 145459)
--- trunk/Source/WebCore/svg/SVGSVGElement.h 2013-03-12 01:42:07 UTC (rev 145458)
+++ trunk/Source/WebCore/svg/SVGSVGElement.h 2013-03-12 01:50:07 UTC (rev 145459)
@@ -142,7 +142,7 @@
SVGSVGElement(const QualifiedName&, Document*);
virtual ~SVGSVGElement();
- virtual bool isSVG() const { return true; }
+ virtual bool isSVGSVGElement() const OVERRIDE { return true; }
virtual void parseAttribute(const QualifiedName&, const AtomicString&) OVERRIDE;
@@ -192,6 +192,13 @@
RefPtr<SVGViewSpec> m_viewSpec;
};
+inline SVGSVGElement* toSVGSVGElement(Node* node)
+{
+ SVGElement* element = node && node->isSVGElement() ? toSVGElement(node) : 0;
+ ASSERT_WITH_SECURITY_IMPLICATION(!element || element->isSVGSVGElement());
+ return static_cast<SVGSVGElement*>(element);
+}
+
} // namespace WebCore
#endif // ENABLE(SVG)
Modified: trunk/Source/WebCore/svg/SVGStopElement.h (145458 => 145459)
--- trunk/Source/WebCore/svg/SVGStopElement.h 2013-03-12 01:42:07 UTC (rev 145458)
+++ trunk/Source/WebCore/svg/SVGStopElement.h 2013-03-12 01:50:07 UTC (rev 145459)
@@ -40,7 +40,7 @@
virtual void parseAttribute(const QualifiedName&, const AtomicString&) OVERRIDE;
virtual void svgAttributeChanged(const QualifiedName&);
- virtual bool isGradientStop() const { return true; }
+ virtual bool isGradientStop() const OVERRIDE { return true; }
virtual RenderObject* createRenderer(RenderArena*, RenderStyle*);
virtual bool rendererIsNeeded(const NodeRenderingContext&) OVERRIDE;
@@ -50,6 +50,12 @@
END_DECLARE_ANIMATED_PROPERTIES
};
+inline SVGStopElement* toSVGStopElement(SVGElement* element)
+{
+ ASSERT_WITH_SECURITY_IMPLICATION(!element || element->isGradientStop());
+ return static_cast<SVGStopElement*>(element);
+}
+
} // namespace WebCore
#endif // ENABLE(SVG)