Use is<>() / downcast<>() for ClipPathOperation subclasses
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 15 Oct 2014 17:13:41 +0000 (17:13 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 15 Oct 2014 17:13:41 +0000 (17:13 +0000)
https://bugs.webkit.org/show_bug.cgi?id=137733

Reviewed by Mihnea Ovidenie.

Use is<>() / downcast<>() for ClipPathOperation subclasses.

No new tests, no behavior change.

* css/CSSComputedStyleDeclaration.cpp:
(WebCore::ComputedStyleExtractor::propertyValue):
* css/DeprecatedStyleBuilder.cpp:
(WebCore::ApplyPropertyClipPath::applyValue):
* rendering/ClipPathOperation.h:
* rendering/RenderBlock.cpp:
(WebCore::RenderBlock::nodeAtPoint):
* rendering/RenderLayer.cpp:
(WebCore::RenderLayer::setupClipPath):
* rendering/svg/SVGRenderingContext.cpp:
(WebCore::SVGRenderingContext::prepareToRenderSVGContent):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@174729 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/css/CSSComputedStyleDeclaration.cpp
Source/WebCore/css/DeprecatedStyleBuilder.cpp
Source/WebCore/rendering/ClipPathOperation.h
Source/WebCore/rendering/RenderBlock.cpp
Source/WebCore/rendering/RenderLayer.cpp
Source/WebCore/rendering/svg/SVGRenderingContext.cpp

index b4f157f..5cc7c02 100644 (file)
@@ -1,5 +1,28 @@
 2014-10-15  Chris Dumez  <cdumez@apple.com>
 
+        Use is<>() / downcast<>() for ClipPathOperation subclasses
+        https://bugs.webkit.org/show_bug.cgi?id=137733
+
+        Reviewed by Mihnea Ovidenie.
+
+        Use is<>() / downcast<>() for ClipPathOperation subclasses.
+
+        No new tests, no behavior change.
+
+        * css/CSSComputedStyleDeclaration.cpp:
+        (WebCore::ComputedStyleExtractor::propertyValue):
+        * css/DeprecatedStyleBuilder.cpp:
+        (WebCore::ApplyPropertyClipPath::applyValue):
+        * rendering/ClipPathOperation.h:
+        * rendering/RenderBlock.cpp:
+        (WebCore::RenderBlock::nodeAtPoint):
+        * rendering/RenderLayer.cpp:
+        (WebCore::RenderLayer::setupClipPath):
+        * rendering/svg/SVGRenderingContext.cpp:
+        (WebCore::SVGRenderingContext::prepareToRenderSVGContent):
+
+2014-10-15  Chris Dumez  <cdumez@apple.com>
+
         [Mac] Use CFDictionaryContainsKey() in ImageSource::isSizeAvailable()
         https://bugs.webkit.org/show_bug.cgi?id=137723
 
index 6b7836b..b1b888c 100644 (file)
@@ -2852,19 +2852,19 @@ PassRefPtr<CSSValue> ComputedStyleExtractor::propertyValue(CSSPropertyID propert
             ClipPathOperation* operation = style->clipPath();
             if (!operation)
                 return cssValuePool().createIdentifierValue(CSSValueNone);
-            if (operation->type() == ClipPathOperation::Reference) {
-                ReferenceClipPathOperation& referenceOperation = toReferenceClipPathOperation(*operation);
+            if (is<ReferenceClipPathOperation>(*operation)) {
+                const auto& referenceOperation = downcast<ReferenceClipPathOperation>(*operation);
                 return CSSPrimitiveValue::create(referenceOperation.url(), CSSPrimitiveValue::CSS_URI);
             }
             RefPtr<CSSValueList> list = CSSValueList::createSpaceSeparated();
-            if (operation->type() == ClipPathOperation::Shape) {
-                ShapeClipPathOperation& shapeOperation = toShapeClipPathOperation(*operation);
+            if (is<ShapeClipPathOperation>(*operation)) {
+                const auto& shapeOperation = downcast<ShapeClipPathOperation>(*operation);
                 list->append(valueForBasicShape(style.get(), shapeOperation.basicShape()));
                 if (shapeOperation.referenceBox() != BoxMissing)
                     list->append(cssValuePool().createValue(shapeOperation.referenceBox()));
             }
-            if (operation->type() == ClipPathOperation::Box) {
-                BoxClipPathOperation& boxOperation = toBoxClipPathOperation(*operation);
+            if (is<BoxClipPathOperation>(*operation)) {
+                const auto& boxOperation = downcast<BoxClipPathOperation>(*operation);
                 list->append(cssValuePool().createValue(boxOperation.referenceBox()));
             }
             return list.release();
index 529ead7..cb829ee 100644 (file)
@@ -2163,7 +2163,7 @@ public:
                 return;
             operation = BoxClipPathOperation::create(referenceBox);
         } else
-            toShapeClipPathOperation(operation.get())->setReferenceBox(referenceBox);
+            downcast<ShapeClipPathOperation>(*operation).setReferenceBox(referenceBox);
         setValue(styleResolver->style(), operation.release());
     }
     static PropertyHandler createHandler()
index af60a98..67fe559 100644 (file)
@@ -34,6 +34,7 @@
 #include "Path.h"
 #include "RenderStyleConstants.h"
 #include <wtf/RefCounted.h>
+#include <wtf/TypeCasts.h>
 #include <wtf/text/WTFString.h>
 
 namespace WebCore {
@@ -166,13 +167,15 @@ private:
     CSSBoxType m_referenceBox;
 };
 
-#define CLIP_PATH_OPERATION_CASTS(ToValueTypeName, predicate) \
-    TYPE_CASTS_BASE(ToValueTypeName, ClipPathOperation, operation, operation->type() == ClipPathOperation::predicate, operation.type() == ClipPathOperation::predicate)
+} // namespace WebCore
 
-CLIP_PATH_OPERATION_CASTS(ReferenceClipPathOperation, Reference)
-CLIP_PATH_OPERATION_CASTS(ShapeClipPathOperation, Shape)
-CLIP_PATH_OPERATION_CASTS(BoxClipPathOperation, Box)
+#define SPECIALIZE_TYPE_TRAITS_CLIP_PATH_OPERATION(ToValueTypeName, predicate) \
+SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::ToValueTypeName) \
+    static bool isType(const WebCore::ClipPathOperation& operation) { return operation.type() == WebCore::predicate; } \
+SPECIALIZE_TYPE_TRAITS_END()
 
-} // namespace WebCore
+SPECIALIZE_TYPE_TRAITS_CLIP_PATH_OPERATION(ReferenceClipPathOperation, ClipPathOperation::Reference)
+SPECIALIZE_TYPE_TRAITS_CLIP_PATH_OPERATION(ShapeClipPathOperation, ClipPathOperation::Shape)
+SPECIALIZE_TYPE_TRAITS_CLIP_PATH_OPERATION(BoxClipPathOperation, ClipPathOperation::Box)
 
 #endif // ClipPathOperation_h
index f066140..e14f04a 100644 (file)
@@ -2453,10 +2453,10 @@ bool RenderBlock::nodeAtPoint(const HitTestRequest& request, HitTestResult& resu
     if (style().clipPath()) {
         switch (style().clipPath()->type()) {
         case ClipPathOperation::Shape: {
-            ShapeClipPathOperation* clipPath = toShapeClipPathOperation(style().clipPath());
+            const auto& clipPath = downcast<ShapeClipPathOperation>(*style().clipPath());
 
             LayoutRect referenceBoxRect;
-            switch (clipPath->referenceBox()) {
+            switch (clipPath.referenceBox()) {
             case CSSBoxType::MarginBox:
                 referenceBoxRect = marginBoxRect();
                 break;
@@ -2475,7 +2475,7 @@ bool RenderBlock::nodeAtPoint(const HitTestRequest& request, HitTestResult& resu
             case CSSBoxType::ViewBox:
                 referenceBoxRect = borderBoxRect();
             }
-            if (!clipPath->pathForReferenceRect(referenceBoxRect).contains(locationInContainer.point() - localOffset, clipPath->windRule()))
+            if (!clipPath.pathForReferenceRect(referenceBoxRect).contains(locationInContainer.point() - localOffset, clipPath.windRule()))
                 return false;
             break;
         }
index c40bfa8..8d697b5 100644 (file)
@@ -3925,23 +3925,23 @@ bool RenderLayer::setupClipPath(GraphicsContext* context, const LayerPaintingInf
 
     RenderStyle& style = renderer().style();
     ASSERT(style.clipPath());
-    if (style.clipPath()->type() == ClipPathOperation::Shape) {
-        ShapeClipPathOperation& clippingPath = toShapeClipPathOperation(*(style.clipPath()));
+    if (is<ShapeClipPathOperation>(*style.clipPath())) {
+        const auto& clipPath = downcast<ShapeClipPathOperation>(*style.clipPath());
 
-        LayoutRect referenceBox = computeReferenceBox(renderer(), clippingPath, offsetFromRoot, rootRelativeBounds);
+        LayoutRect referenceBox = computeReferenceBox(renderer(), clipPath, offsetFromRoot, rootRelativeBounds);
         context->save();
-        context->clipPath(clippingPath.pathForReferenceRect(referenceBox), clippingPath.windRule());
+        context->clipPath(clipPath.pathForReferenceRect(referenceBox), clipPath.windRule());
         return true;
     }
 
-    if (style.clipPath()->type() == ClipPathOperation::Box && renderer().isBox()) {
-        BoxClipPathOperation& clippingPath = toBoxClipPathOperation(*(style.clipPath()));
+    if (is<BoxClipPathOperation>(*style.clipPath()) && is<RenderBox>(renderer())) {
+        const auto& clipPath = downcast<BoxClipPathOperation>(*style.clipPath());
 
-        RoundedRect shapeRect = computeRoundedRectForBoxShape(clippingPath.referenceBox(), toRenderBox(renderer()));
+        RoundedRect shapeRect = computeRoundedRectForBoxShape(clipPath.referenceBox(), downcast<RenderBox>(renderer()));
         shapeRect.move(offsetFromRoot);
 
         context->save();
-        context->clipPath(clippingPath.pathForReferenceRect(shapeRect), RULE_NONZERO);
+        context->clipPath(clipPath.pathForReferenceRect(shapeRect), RULE_NONZERO);
         return true;
     }
 
index eb6b89b..1768a60 100644 (file)
@@ -136,8 +136,8 @@ void SVGRenderingContext::prepareToRenderSVGContent(RenderElement& renderer, Pai
     }
 
     ClipPathOperation* clipPathOperation = style.clipPath();
-    if (clipPathOperation && clipPathOperation->type() == ClipPathOperation::Shape) {
-        ShapeClipPathOperation& clipPath = toShapeClipPathOperation(*clipPathOperation);
+    if (is<ShapeClipPathOperation>(clipPathOperation)) {
+        const auto& clipPath = downcast<ShapeClipPathOperation>(*clipPathOperation);
         FloatRect referenceBox;
         if (clipPath.referenceBox() == Stroke)
             // FIXME: strokeBoundingBox() takes dasharray into account but shouldn't.