Title: [145598] trunk/Source/WebCore
Revision
145598
Author
p...@google.com
Date
2013-03-12 15:26:07 -0700 (Tue, 12 Mar 2013)

Log Message

Replace static_casts for SVG transformable and locatable elements
https://bugs.webkit.org/show_bug.cgi?id=111651

Reviewed by Abhishek Arya.

toSVGStyledTransformableElement and toSVGStyledLocatableElement are preferred over
static_casts because bad casts can be caught on our testing infrastructure. This patch
replaces all static_casts for SVGStyledTransformableElement and SVGStyledLocatableElement
with toSVGStyledTransformableElement and toSVGStyledLocatableElement, respectively.

No new tests as this is covered with existing tests.

* rendering/svg/RenderSVGResourceClipper.cpp:
(WebCore::RenderSVGResourceClipper::pathOnlyClipping):
* rendering/svg/RenderSVGResourceContainer.cpp:
(WebCore::RenderSVGResourceContainer::transformOnNonScalingStroke):
* rendering/svg/RenderSVGShape.cpp:
(WebCore::RenderSVGShape::updateShapeFromElement):
(WebCore::RenderSVGShape::layout):
(WebCore::RenderSVGShape::nonScalingStrokeTransform):
(WebCore::RenderSVGShape::shouldGenerateMarkerPositions):
* rendering/svg/RenderSVGTransformableContainer.cpp:
(WebCore::RenderSVGTransformableContainer::calculateLocalTransform):
* svg/SVGAnimatedLength.cpp:
(WebCore::SVGAnimatedLengthAnimator::calculateDistance):

    This was an unnecessary cast and has been removed.

* svg/SVGElement.cpp:
(WebCore::SVGElement::getBoundingBox):
* svg/SVGLocatable.cpp:
(WebCore::SVGLocatable::getTransformToElement):
* svg/SVGStyledLocatableElement.h:
(WebCore):
(WebCore::toSVGStyledLocatableElement):
* svg/SVGStyledTransformableElement.h:
(WebCore):
(WebCore::toSVGStyledTransformableElement):

    It makes the code cleaner to pass Node* in here, rather than converting the Node*
    to an SVGElement* before calling this function. The same was not necessary for
    SVGStyledLocatable.

* svg/SVGSVGElement.h:
(WebCore):
(WebCore::toSVGSVGElement):

    This code has been cleaned up. During the review of this patch, a similar cleanup
    was done in toSVGStyledTransformableElement.

* svg/SVGUseElement.cpp:
(WebCore::SVGUseElement::toClipPath):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (145597 => 145598)


--- trunk/Source/WebCore/ChangeLog	2013-03-12 22:21:38 UTC (rev 145597)
+++ trunk/Source/WebCore/ChangeLog	2013-03-12 22:26:07 UTC (rev 145598)
@@ -1,3 +1,58 @@
+2013-03-12  Philip Rogers  <p...@google.com>
+
+        Replace static_casts for SVG transformable and locatable elements
+        https://bugs.webkit.org/show_bug.cgi?id=111651
+
+        Reviewed by Abhishek Arya.
+
+        toSVGStyledTransformableElement and toSVGStyledLocatableElement are preferred over
+        static_casts because bad casts can be caught on our testing infrastructure. This patch
+        replaces all static_casts for SVGStyledTransformableElement and SVGStyledLocatableElement
+        with toSVGStyledTransformableElement and toSVGStyledLocatableElement, respectively.
+
+        No new tests as this is covered with existing tests.
+
+        * rendering/svg/RenderSVGResourceClipper.cpp:
+        (WebCore::RenderSVGResourceClipper::pathOnlyClipping):
+        * rendering/svg/RenderSVGResourceContainer.cpp:
+        (WebCore::RenderSVGResourceContainer::transformOnNonScalingStroke):
+        * rendering/svg/RenderSVGShape.cpp:
+        (WebCore::RenderSVGShape::updateShapeFromElement):
+        (WebCore::RenderSVGShape::layout):
+        (WebCore::RenderSVGShape::nonScalingStrokeTransform):
+        (WebCore::RenderSVGShape::shouldGenerateMarkerPositions):
+        * rendering/svg/RenderSVGTransformableContainer.cpp:
+        (WebCore::RenderSVGTransformableContainer::calculateLocalTransform):
+        * svg/SVGAnimatedLength.cpp:
+        (WebCore::SVGAnimatedLengthAnimator::calculateDistance):
+
+            This was an unnecessary cast and has been removed.
+
+        * svg/SVGElement.cpp:
+        (WebCore::SVGElement::getBoundingBox):
+        * svg/SVGLocatable.cpp:
+        (WebCore::SVGLocatable::getTransformToElement):
+        * svg/SVGStyledLocatableElement.h:
+        (WebCore):
+        (WebCore::toSVGStyledLocatableElement):
+        * svg/SVGStyledTransformableElement.h:
+        (WebCore):
+        (WebCore::toSVGStyledTransformableElement):
+
+            It makes the code cleaner to pass Node* in here, rather than converting the Node*
+            to an SVGElement* before calling this function. The same was not necessary for
+            SVGStyledLocatable.
+
+        * svg/SVGSVGElement.h:
+        (WebCore):
+        (WebCore::toSVGSVGElement):
+
+            This code has been cleaned up. During the review of this patch, a similar cleanup
+            was done in toSVGStyledTransformableElement.
+
+        * svg/SVGUseElement.cpp:
+        (WebCore::SVGUseElement::toClipPath):
+
 2013-03-12  Abhishek Arya  <infe...@chromium.org>
 
         Replace static_casts with to* helper functions.

Modified: trunk/Source/WebCore/rendering/svg/RenderSVGResourceClipper.cpp (145597 => 145598)


--- trunk/Source/WebCore/rendering/svg/RenderSVGResourceClipper.cpp	2013-03-12 22:21:38 UTC (rev 145597)
+++ trunk/Source/WebCore/rendering/svg/RenderSVGResourceClipper.cpp	2013-03-12 22:26:07 UTC (rev 145598)
@@ -119,7 +119,7 @@
             return false;
         if (!childNode->isSVGElement() || !toSVGElement(childNode)->isStyledTransformable())
             continue;
-        SVGStyledTransformableElement* styled = static_cast<SVGStyledTransformableElement*>(childNode);
+        SVGStyledTransformableElement* styled = toSVGStyledTransformableElement(childNode);
         RenderStyle* style = renderer->style();
         if (!style || style->display() == NONE || style->visibility() != VISIBLE)
              continue;

Modified: trunk/Source/WebCore/rendering/svg/RenderSVGResourceContainer.cpp (145597 => 145598)


--- trunk/Source/WebCore/rendering/svg/RenderSVGResourceContainer.cpp	2013-03-12 22:21:38 UTC (rev 145597)
+++ trunk/Source/WebCore/rendering/svg/RenderSVGResourceContainer.cpp	2013-03-12 22:26:07 UTC (rev 145598)
@@ -225,7 +225,7 @@
     if (!object->isSVGShape())
         return resourceTransform;
 
-    SVGStyledTransformableElement* element = static_cast<SVGStyledTransformableElement*>(object->node());
+    SVGStyledTransformableElement* element = toSVGStyledTransformableElement(object->node());
     AffineTransform transform = element->getScreenCTM(SVGLocatable::DisallowStyleUpdate);
     transform *= resourceTransform;
     return transform;

Modified: trunk/Source/WebCore/rendering/svg/RenderSVGShape.cpp (145597 => 145598)


--- trunk/Source/WebCore/rendering/svg/RenderSVGShape.cpp	2013-03-12 22:21:38 UTC (rev 145597)
+++ trunk/Source/WebCore/rendering/svg/RenderSVGShape.cpp	2013-03-12 22:26:07 UTC (rev 145598)
@@ -69,7 +69,7 @@
     m_path = adoptPtr(new Path);
     ASSERT(RenderSVGShape::isEmpty());
 
-    SVGStyledTransformableElement* element = static_cast<SVGStyledTransformableElement*>(node());
+    SVGStyledTransformableElement* element = toSVGStyledTransformableElement(node());
     updatePathFromGraphicsElement(element, path());
     processMarkerPositions();
 
@@ -146,7 +146,7 @@
 {
     StackStats::LayoutCheckPoint layoutCheckPoint;
     LayoutRepainter repainter(*this, SVGRenderSupport::checkForSVGRepaintDuringLayout(this) && selfNeedsLayout());
-    SVGStyledTransformableElement* element = static_cast<SVGStyledTransformableElement*>(node());
+    SVGStyledTransformableElement* element = toSVGStyledTransformableElement(node());
 
     bool updateCachedBoundariesInParents = false;
 
@@ -198,7 +198,7 @@
 
 AffineTransform RenderSVGShape::nonScalingStrokeTransform() const
 {
-    SVGStyledTransformableElement* element = static_cast<SVGStyledTransformableElement*>(node());
+    SVGStyledTransformableElement* element = toSVGStyledTransformableElement(node());
     return element->getScreenCTM(SVGLocatable::DisallowStyleUpdate);
 }
 
@@ -207,7 +207,7 @@
     if (!style()->svgStyle()->hasMarkers())
         return false;
 
-    SVGStyledTransformableElement* element = static_cast<SVGStyledTransformableElement*>(node());
+    SVGStyledTransformableElement* element = toSVGStyledTransformableElement(node());
     if (!element->supportsMarkers())
         return false;
 

Modified: trunk/Source/WebCore/rendering/svg/RenderSVGTransformableContainer.cpp (145597 => 145598)


--- trunk/Source/WebCore/rendering/svg/RenderSVGTransformableContainer.cpp	2013-03-12 22:21:38 UTC (rev 145597)
+++ trunk/Source/WebCore/rendering/svg/RenderSVGTransformableContainer.cpp	2013-03-12 22:26:07 UTC (rev 145598)
@@ -40,7 +40,7 @@
 
 bool RenderSVGTransformableContainer::calculateLocalTransform()
 {
-    SVGStyledTransformableElement* element = static_cast<SVGStyledTransformableElement*>(node());
+    SVGStyledTransformableElement* element = toSVGStyledTransformableElement(node());
 
     // If we're either the renderer for a <use> element, or for any <g> element inside the shadow
     // tree, that was created during the use/symbol/svg expansion in SVGUseElement. These containers

Modified: trunk/Source/WebCore/svg/SVGAnimatedLength.cpp (145597 => 145598)


--- trunk/Source/WebCore/svg/SVGAnimatedLength.cpp	2013-03-12 22:21:38 UTC (rev 145597)
+++ trunk/Source/WebCore/svg/SVGAnimatedLength.cpp	2013-03-12 22:26:07 UTC (rev 145598)
@@ -113,8 +113,7 @@
 {
     ASSERT(m_animationElement);
     ASSERT(m_contextElement);
-    SVGAnimateElement* animationElement = static_cast<SVGAnimateElement*>(m_animationElement);    
-    SVGLengthMode lengthMode = SVGLength::lengthModeForAnimatedLengthAttribute(animationElement->attributeName());
+    SVGLengthMode lengthMode = SVGLength::lengthModeForAnimatedLengthAttribute(m_animationElement->attributeName());
     SVGLength from = SVGLength(lengthMode, fromString);
     SVGLength to = SVGLength(lengthMode, toString);
     SVGLengthContext lengthContext(m_contextElement);

Modified: trunk/Source/WebCore/svg/SVGElement.cpp (145597 => 145598)


--- trunk/Source/WebCore/svg/SVGElement.cpp	2013-03-12 22:21:38 UTC (rev 145597)
+++ trunk/Source/WebCore/svg/SVGElement.cpp	2013-03-12 22:26:07 UTC (rev 145598)
@@ -253,7 +253,7 @@
 bool SVGElement::getBoundingBox(FloatRect& rect, SVGLocatable::StyleUpdateStrategy styleUpdateStrategy)
 {
     if (isStyledLocatable()) {
-        rect = static_cast<SVGStyledLocatableElement*>(this)->getBBox(styleUpdateStrategy);
+        rect = toSVGStyledLocatableElement(this)->getBBox(styleUpdateStrategy);
         return true;
     }
     if (hasTagName(SVGNames::textTag)) {

Modified: trunk/Source/WebCore/svg/SVGLocatable.cpp (145597 => 145598)


--- trunk/Source/WebCore/svg/SVGLocatable.cpp	2013-03-12 22:21:38 UTC (rev 145597)
+++ trunk/Source/WebCore/svg/SVGLocatable.cpp	2013-03-12 22:26:07 UTC (rev 145598)
@@ -104,7 +104,7 @@
     AffineTransform ctm = getCTM(styleUpdateStrategy);
 
     if (target && target->isStyledLocatable()) {
-        AffineTransform targetCTM = static_cast<SVGStyledLocatableElement*>(target)->getCTM(styleUpdateStrategy);
+        AffineTransform targetCTM = toSVGStyledLocatableElement(target)->getCTM(styleUpdateStrategy);
         if (!targetCTM.isInvertible()) {
             ec = SVGException::SVG_MATRIX_NOT_INVERTABLE;
             return ctm;

Modified: trunk/Source/WebCore/svg/SVGSVGElement.h (145597 => 145598)


--- trunk/Source/WebCore/svg/SVGSVGElement.h	2013-03-12 22:21:38 UTC (rev 145597)
+++ trunk/Source/WebCore/svg/SVGSVGElement.h	2013-03-12 22:26:07 UTC (rev 145598)
@@ -194,9 +194,9 @@
 
 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);
+    ASSERT_WITH_SECURITY_IMPLICATION(!node || node->isSVGElement());
+    ASSERT_WITH_SECURITY_IMPLICATION(!node || toSVGElement(node)->isSVGSVGElement());
+    return static_cast<SVGSVGElement*>(node);
 }
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/svg/SVGStyledLocatableElement.h (145597 => 145598)


--- trunk/Source/WebCore/svg/SVGStyledLocatableElement.h	2013-03-12 22:21:38 UTC (rev 145597)
+++ trunk/Source/WebCore/svg/SVGStyledLocatableElement.h	2013-03-12 22:26:07 UTC (rev 145598)
@@ -45,9 +45,15 @@
     SVGStyledLocatableElement(const QualifiedName&, Document*, ConstructionType = CreateSVGElement);
 
 private:
-    virtual bool isStyledLocatable() const { return true; }
+    virtual bool isStyledLocatable() const OVERRIDE { return true; }
 };
 
+inline SVGStyledLocatableElement* toSVGStyledLocatableElement(SVGElement* element)
+{
+    ASSERT_WITH_SECURITY_IMPLICATION(!element || element->isStyledLocatable());
+    return static_cast<SVGStyledLocatableElement*>(element);
+}
+
 } // namespace WebCore
 
 #endif // ENABLE(SVG)

Modified: trunk/Source/WebCore/svg/SVGStyledTransformableElement.h (145597 => 145598)


--- trunk/Source/WebCore/svg/SVGStyledTransformableElement.h	2013-03-12 22:21:38 UTC (rev 145597)
+++ trunk/Source/WebCore/svg/SVGStyledTransformableElement.h	2013-03-12 22:26:07 UTC (rev 145598)
@@ -63,12 +63,19 @@
     END_DECLARE_ANIMATED_PROPERTIES
 
 private:
-    virtual bool isStyledTransformable() const { return true; }
+    virtual bool isStyledTransformable() const OVERRIDE { return true; }
 
     // Used by <animateMotion>
     OwnPtr<AffineTransform> m_supplementalTransform;
 };
 
+inline SVGStyledTransformableElement* toSVGStyledTransformableElement(Node* node)
+{
+    ASSERT_WITH_SECURITY_IMPLICATION(!node || node->isSVGElement());
+    ASSERT_WITH_SECURITY_IMPLICATION(!node || toSVGElement(node)->isStyledTransformable());
+    return static_cast<SVGStyledTransformableElement*>(node);
+}
+
 } // namespace WebCore
 
 #endif // ENABLE(SVG)

Modified: trunk/Source/WebCore/svg/SVGUseElement.cpp (145597 => 145598)


--- trunk/Source/WebCore/svg/SVGUseElement.cpp	2013-03-12 22:21:38 UTC (rev 145597)
+++ trunk/Source/WebCore/svg/SVGUseElement.cpp	2013-03-12 22:26:07 UTC (rev 145598)
@@ -567,7 +567,7 @@
             // Spec: Indirect references are an error (14.3.5)
             document()->accessSVGExtensions()->reportError("Not allowed to use indirect reference in <clip-path>");
         else {
-            static_cast<SVGStyledTransformableElement*>(n)->toClipPath(path);
+            toSVGStyledTransformableElement(n)->toClipPath(path);
             // FIXME: Avoid manual resolution of x/y here. Its potentially harmful.
             SVGLengthContext lengthContext(this);
             path.translate(FloatSize(x().value(lengthContext), y().value(lengthContext)));
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to