Introduce toBasicShapeFoo() instead of static_cast<BasicShapeFoo*>
authorgyuyoung.kim@samsung.com <gyuyoung.kim@samsung.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 8 Sep 2014 01:36:07 +0000 (01:36 +0000)
committergyuyoung.kim@samsung.com <gyuyoung.kim@samsung.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 8 Sep 2014 01:36:07 +0000 (01:36 +0000)
https://bugs.webkit.org/show_bug.cgi?id=136609

Reviewed by Darin Adler.

To use BasicShapeFoo() helps to detect wrong type casting and improve code readability.

No new tests, no behavior changes.

* css/BasicShapeFunctions.cpp:
(WebCore::valueForBasicShape):
* rendering/shapes/Shape.cpp:
(WebCore::Shape::createShape):
* rendering/style/BasicShapes.cpp:
(WebCore::BasicShape::canBlend):
(WebCore::BasicShapeCircle::blend):
(WebCore::BasicShapeEllipse::blend):
(WebCore::BasicShapePolygon::blend):
(WebCore::BasicShapeInset::blend):
* rendering/style/BasicShapes.h:

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

Source/WebCore/ChangeLog
Source/WebCore/css/BasicShapeFunctions.cpp
Source/WebCore/rendering/shapes/Shape.cpp
Source/WebCore/rendering/style/BasicShapes.cpp
Source/WebCore/rendering/style/BasicShapes.h

index 023876a..cef796f 100644 (file)
@@ -1,3 +1,26 @@
+2014-09-07  Gyuyoung Kim  <gyuyoung.kim@samsung.com>
+
+        Introduce toBasicShapeFoo() instead of static_cast<BasicShapeFoo*>
+        https://bugs.webkit.org/show_bug.cgi?id=136609
+
+        Reviewed by Darin Adler.
+
+        To use BasicShapeFoo() helps to detect wrong type casting and improve code readability.
+
+        No new tests, no behavior changes.
+
+        * css/BasicShapeFunctions.cpp:
+        (WebCore::valueForBasicShape):
+        * rendering/shapes/Shape.cpp:
+        (WebCore::Shape::createShape):
+        * rendering/style/BasicShapes.cpp:
+        (WebCore::BasicShape::canBlend):
+        (WebCore::BasicShapeCircle::blend):
+        (WebCore::BasicShapeEllipse::blend):
+        (WebCore::BasicShapePolygon::blend):
+        (WebCore::BasicShapeInset::blend):
+        * rendering/style/BasicShapes.h:
+
 2014-09-06  Jer Noble  <jer.noble@apple.com>
 
         [Fullscreen] Add a site-specific hack to work around "flash on exit" behavior of YouTube.com.
index 019de9f..04ebafe 100644 (file)
@@ -71,7 +71,7 @@ PassRef<CSSValue> valueForBasicShape(const RenderStyle* style, const BasicShape*
     RefPtr<CSSBasicShape> basicShapeValue;
     switch (basicShape->type()) {
     case BasicShape::BasicShapeCircleType: {
-        const BasicShapeCircle* circle = static_cast<const BasicShapeCircle*>(basicShape);
+        const BasicShapeCircle* circle = toBasicShapeCircle(basicShape);
         RefPtr<CSSBasicShapeCircle> circleValue = CSSBasicShapeCircle::create();
 
         circleValue->setCenterX(valueForCenterCoordinate(pool, style, circle->centerX(), HORIZONTAL));
@@ -81,7 +81,7 @@ PassRef<CSSValue> valueForBasicShape(const RenderStyle* style, const BasicShape*
         break;
     }
     case BasicShape::BasicShapeEllipseType: {
-        const BasicShapeEllipse* ellipse = static_cast<const BasicShapeEllipse*>(basicShape);
+        const BasicShapeEllipse* ellipse = toBasicShapeEllipse(basicShape);
         RefPtr<CSSBasicShapeEllipse> ellipseValue = CSSBasicShapeEllipse::create();
 
         ellipseValue->setCenterX(valueForCenterCoordinate(pool, style, ellipse->centerX(), HORIZONTAL));
@@ -92,7 +92,7 @@ PassRef<CSSValue> valueForBasicShape(const RenderStyle* style, const BasicShape*
         break;
     }
     case BasicShape::BasicShapePolygonType: {
-        const BasicShapePolygon* polygon = static_cast<const BasicShapePolygon*>(basicShape);
+        const BasicShapePolygon* polygon = toBasicShapePolygon(basicShape);
         RefPtr<CSSBasicShapePolygon> polygonValue = CSSBasicShapePolygon::create();
 
         polygonValue->setWindRule(polygon->windRule());
@@ -104,7 +104,7 @@ PassRef<CSSValue> valueForBasicShape(const RenderStyle* style, const BasicShape*
         break;
     }
     case BasicShape::BasicShapeInsetType: {
-        const BasicShapeInset* inset = static_cast<const BasicShapeInset*>(basicShape);
+        const BasicShapeInset* inset = toBasicShapeInset(basicShape);
         RefPtr<CSSBasicShapeInset> insetValue = CSSBasicShapeInset::create();
 
         insetValue->setTop(pool.createValue(inset->top(), style));
index 82f2a28..8c92a4c 100644 (file)
@@ -102,7 +102,7 @@ std::unique_ptr<Shape> Shape::createShape(const BasicShape* basicShape, const La
     switch (basicShape->type()) {
 
     case BasicShape::BasicShapeCircleType: {
-        const BasicShapeCircle* circle = static_cast<const BasicShapeCircle*>(basicShape);
+        const BasicShapeCircle* circle = toBasicShapeCircle(basicShape);
         float centerX = floatValueForCenterCoordinate(circle->centerX(), boxWidth);
         float centerY = floatValueForCenterCoordinate(circle->centerY(), boxHeight);
         float radius = circle->floatValueForRadiusInBox(boxWidth, boxHeight);
@@ -113,7 +113,7 @@ std::unique_ptr<Shape> Shape::createShape(const BasicShape* basicShape, const La
     }
 
     case BasicShape::BasicShapeEllipseType: {
-        const BasicShapeEllipse* ellipse = static_cast<const BasicShapeEllipse*>(basicShape);
+        const BasicShapeEllipse* ellipse = toBasicShapeEllipse(basicShape);
         float centerX = floatValueForCenterCoordinate(ellipse->centerX(), boxWidth);
         float centerY = floatValueForCenterCoordinate(ellipse->centerY(), boxHeight);
         float radiusX = ellipse->floatValueForRadiusInBox(ellipse->radiusX(), centerX, boxWidth);
@@ -125,7 +125,7 @@ std::unique_ptr<Shape> Shape::createShape(const BasicShape* basicShape, const La
     }
 
     case BasicShape::BasicShapePolygonType: {
-        const BasicShapePolygon& polygon = *static_cast<const BasicShapePolygon*>(basicShape);
+        const BasicShapePolygon& polygon = *toBasicShapePolygon(basicShape);
         const Vector<Length>& values = polygon.values();
         size_t valuesSize = values.size();
         ASSERT(!(valuesSize % 2));
@@ -142,7 +142,7 @@ std::unique_ptr<Shape> Shape::createShape(const BasicShape* basicShape, const La
     }
 
     case BasicShape::BasicShapeInsetType: {
-        const BasicShapeInset& inset = *static_cast<const BasicShapeInset*>(basicShape);
+        const BasicShapeInset& inset = *toBasicShapeInset(basicShape);
         float left = floatValueForLength(inset.left(), boxWidth);
         float top = floatValueForLength(inset.top(), boxHeight);
         FloatRect rect(left,
index 082f95d..75de19b 100644 (file)
@@ -66,14 +66,14 @@ bool BasicShape::canBlend(const BasicShape* other) const
 
     // Just polygons with same number of vertices can be animated.
     if (type() == BasicShape::BasicShapePolygonType
-        && (static_cast<const BasicShapePolygon*>(this)->values().size() != static_cast<const BasicShapePolygon*>(other)->values().size()
-        || static_cast<const BasicShapePolygon*>(this)->windRule() != static_cast<const BasicShapePolygon*>(other)->windRule()))
+        && (toBasicShapePolygon(this)->values().size() != toBasicShapePolygon(other)->values().size()
+        || toBasicShapePolygon(this)->windRule() != toBasicShapePolygon(other)->windRule()))
         return false;
 
     // Circles with keywords for radii coordinates cannot be animated.
     if (type() == BasicShape::BasicShapeCircleType) {
-        const BasicShapeCircle* thisCircle = static_cast<const BasicShapeCircle*>(this);
-        const BasicShapeCircle* otherCircle = static_cast<const BasicShapeCircle*>(other);
+        const BasicShapeCircle* thisCircle = toBasicShapeCircle(this);
+        const BasicShapeCircle* otherCircle = toBasicShapeCircle(other);
         if (!thisCircle->radius().canBlend(otherCircle->radius()))
             return false;
     }
@@ -82,8 +82,8 @@ bool BasicShape::canBlend(const BasicShape* other) const
     if (type() != BasicShape::BasicShapeEllipseType)
         return true;
 
-    const BasicShapeEllipse* thisEllipse = static_cast<const BasicShapeEllipse*>(this);
-    const BasicShapeEllipse* otherEllipse = static_cast<const BasicShapeEllipse*>(other);
+    const BasicShapeEllipse* thisEllipse = toBasicShapeEllipse(this);
+    const BasicShapeEllipse* otherEllipse = toBasicShapeEllipse(other);
     return (thisEllipse->radiusX().canBlend(otherEllipse->radiusX())
         && thisEllipse->radiusY().canBlend(otherEllipse->radiusY()));
 }
@@ -121,7 +121,7 @@ void BasicShapeCircle::path(Path& path, const FloatRect& boundingBox)
 PassRefPtr<BasicShape> BasicShapeCircle::blend(const BasicShape* other, double progress) const
 {
     ASSERT(type() == other->type());
-    const BasicShapeCircle* o = static_cast<const BasicShapeCircle*>(other);
+    const BasicShapeCircle* o = toBasicShapeCircle(other);
     RefPtr<BasicShapeCircle> result =  BasicShapeCircle::create();
 
     result->setCenterX(m_centerX.blend(o->centerX(), progress));
@@ -160,7 +160,7 @@ void BasicShapeEllipse::path(Path& path, const FloatRect& boundingBox)
 PassRefPtr<BasicShape> BasicShapeEllipse::blend(const BasicShape* other, double progress) const
 {
     ASSERT(type() == other->type());
-    const BasicShapeEllipse* o = static_cast<const BasicShapeEllipse*>(other);
+    const BasicShapeEllipse* o = toBasicShapeEllipse(other);
     RefPtr<BasicShapeEllipse> result = BasicShapeEllipse::create();
 
     if (m_radiusX.type() != BasicShapeRadius::Value || o->radiusX().type() != BasicShapeRadius::Value
@@ -201,7 +201,7 @@ PassRefPtr<BasicShape> BasicShapePolygon::blend(const BasicShape* other, double
 {
     ASSERT(type() == other->type());
 
-    const BasicShapePolygon* o = static_cast<const BasicShapePolygon*>(other);
+    const BasicShapePolygon* o = toBasicShapePolygon(other);
     ASSERT(m_values.size() == o->values().size());
     ASSERT(!(m_values.size() % 2));
 
@@ -250,7 +250,7 @@ PassRefPtr<BasicShape> BasicShapeInset::blend(const BasicShape* other, double pr
 {
     ASSERT(type() == other->type());
 
-    const BasicShapeInset* o = static_cast<const BasicShapeInset*>(other);
+    const BasicShapeInset* o = toBasicShapeInset(other);
     RefPtr<BasicShapeInset> result =  BasicShapeInset::create();
     result->setTop(m_top.blend(o->top(), progress));
     result->setRight(m_right.blend(o->right(), progress));
index 5892f10..75fa904 100644 (file)
@@ -64,6 +64,9 @@ public:
     virtual Type type() const = 0;
 };
 
+#define BASIC_SHAPES_TYPE_CASTS(ToValueTypeName, predicate) \
+    TYPE_CASTS_BASE(ToValueTypeName, BasicShape, basicShape, basicShape->type() == predicate, basicShape.type() == predicate)
+
 class BasicShapeCenterCoordinate {
 public:
     enum Direction {
@@ -169,6 +172,8 @@ private:
     BasicShapeRadius m_radius;
 };
 
+BASIC_SHAPES_TYPE_CASTS(BasicShapeCircle, BasicShape::BasicShapeCircleType)
+
 class BasicShapeEllipse : public BasicShape {
 public:
     static PassRefPtr<BasicShapeEllipse> create() { return adoptRef(new BasicShapeEllipse); }
@@ -197,6 +202,8 @@ private:
     BasicShapeRadius m_radiusY;
 };
 
+BASIC_SHAPES_TYPE_CASTS(BasicShapeEllipse, BasicShape::BasicShapeEllipseType)
+
 class BasicShapePolygon : public BasicShape {
 public:
     static PassRefPtr<BasicShapePolygon> create() { return adoptRef(new BasicShapePolygon); }
@@ -223,6 +230,8 @@ private:
     Vector<Length> m_values;
 };
 
+BASIC_SHAPES_TYPE_CASTS(BasicShapePolygon, BasicShape::BasicShapePolygonType)
+
 class BasicShapeInset : public BasicShape {
 public:
     static PassRefPtr<BasicShapeInset> create() { return adoptRef(new BasicShapeInset); }
@@ -265,5 +274,7 @@ private:
     LengthSize m_bottomLeftRadius;
 };
 
+BASIC_SHAPES_TYPE_CASTS(BasicShapeInset, BasicShape::BasicShapeInsetType)
+
 }
 #endif