Generate toCSSFooValue for CSSGradientValue, CSSLinearGradientValue and CSSRadialGradient
authorgyuyoung.kim@samsung.com <gyuyoung.kim@samsung.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 30 Sep 2013 07:35:29 +0000 (07:35 +0000)
committergyuyoung.kim@samsung.com <gyuyoung.kim@samsung.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 30 Sep 2013 07:35:29 +0000 (07:35 +0000)
https://bugs.webkit.org/show_bug.cgi?id=122060

Reviewed by Antti Koivisto.

As a step to generate toCSSFooValue, toCSSGradientValuem toCSSLinearGradientValue and
toCSSRadialGradient are generated. isLinearGradient() and isRadialGradient() are moved
from each class to CSSValue in order to generate toCSSFooValue.

No new tests, no behavior change.

* css/CSSGradientValue.cpp:
(WebCore::CSSGradientValue::image):
(WebCore::CSSGradientValue::gradientWithStylesResolved):
* css/CSSGradientValue.h:
* css/CSSImageGeneratorValue.cpp:
(WebCore::CSSImageGeneratorValue::image):
(WebCore::CSSImageGeneratorValue::fixedSize):
(WebCore::CSSImageGeneratorValue::loadSubimages):
* css/CSSParser.cpp:
(WebCore::CSSParser::parseDeprecatedGradient):
* css/CSSValue.cpp:
(WebCore::CSSValue::destroy):
* css/CSSValue.h:
(WebCore::CSSValue::isLinearGradient):
(WebCore::CSSValue::isRadialGradient):
* css/StyleResolver.cpp:
(WebCore::StyleResolver::applyProperty):
(WebCore::StyleResolver::styleImage):

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

Source/WebCore/ChangeLog
Source/WebCore/css/CSSGradientValue.cpp
Source/WebCore/css/CSSGradientValue.h
Source/WebCore/css/CSSImageGeneratorValue.cpp
Source/WebCore/css/CSSParser.cpp
Source/WebCore/css/CSSValue.cpp
Source/WebCore/css/CSSValue.h
Source/WebCore/css/StyleResolver.cpp

index ef03348..0b4f73b 100644 (file)
@@ -1,3 +1,35 @@
+2013-09-30  Gyuyoung Kim  <gyuyoung.kim@samsung.com>
+
+        Generate toCSSFooValue for CSSGradientValue, CSSLinearGradientValue and CSSRadialGradient
+        https://bugs.webkit.org/show_bug.cgi?id=122060
+
+        Reviewed by Antti Koivisto.
+
+        As a step to generate toCSSFooValue, toCSSGradientValuem toCSSLinearGradientValue and
+        toCSSRadialGradient are generated. isLinearGradient() and isRadialGradient() are moved
+        from each class to CSSValue in order to generate toCSSFooValue.
+
+        No new tests, no behavior change.
+
+        * css/CSSGradientValue.cpp:
+        (WebCore::CSSGradientValue::image):
+        (WebCore::CSSGradientValue::gradientWithStylesResolved):
+        * css/CSSGradientValue.h:
+        * css/CSSImageGeneratorValue.cpp:
+        (WebCore::CSSImageGeneratorValue::image):
+        (WebCore::CSSImageGeneratorValue::fixedSize):
+        (WebCore::CSSImageGeneratorValue::loadSubimages):
+        * css/CSSParser.cpp:
+        (WebCore::CSSParser::parseDeprecatedGradient):
+        * css/CSSValue.cpp:
+        (WebCore::CSSValue::destroy):
+        * css/CSSValue.h:
+        (WebCore::CSSValue::isLinearGradient):
+        (WebCore::CSSValue::isRadialGradient):
+        * css/StyleResolver.cpp:
+        (WebCore::StyleResolver::applyProperty):
+        (WebCore::StyleResolver::styleImage):
+
 2013-09-30  Vani Hegde  <vani.hegde@samsung.com>
 
         user-select: none cursor turns to I-beam on mouse dragging
index 2f13510..290f562 100644 (file)
@@ -60,11 +60,11 @@ PassRefPtr<Image> CSSGradientValue::image(RenderElement* renderer, const IntSize
 
     RefPtr<Gradient> gradient;
 
-    if (isLinearGradient())
-        gradient = static_cast<CSSLinearGradientValue*>(this)->createGradient(renderer, size);
+    if (isLinearGradientValue())
+        gradient = toCSSLinearGradientValue(this)->createGradient(renderer, size);
     else {
-        ASSERT(isRadialGradient());
-        gradient = static_cast<CSSRadialGradientValue*>(this)->createGradient(renderer, size);
+        ASSERT(isRadialGradientValue());
+        gradient = toCSSRadialGradientValue(this)->createGradient(renderer, size);
     }
 
     RefPtr<GradientImage> newImage = GradientImage::create(gradient, size);
@@ -117,10 +117,10 @@ PassRefPtr<CSSGradientValue> CSSGradientValue::gradientWithStylesResolved(StyleR
     RefPtr<CSSGradientValue> result;
     if (!derived)
         result = this;
-    else if (isLinearGradient())
-        result = static_cast<CSSLinearGradientValue*>(this)->clone();
-    else if (isRadialGradient())
-        result = static_cast<CSSRadialGradientValue*>(this)->clone();
+    else if (isLinearGradientValue())
+        result = toCSSLinearGradientValue(this)->clone();
+    else if (isRadialGradientValue())
+        result = toCSSRadialGradientValue(this)->clone();
     else {
         ASSERT_NOT_REACHED();
         return 0;
@@ -165,9 +165,9 @@ void CSSGradientValue::addStops(Gradient* gradient, RenderElement* renderer, Ren
 
     FloatPoint gradientStart = gradient->p0();
     FloatPoint gradientEnd;
-    if (isLinearGradient())
+    if (isLinearGradientValue())
         gradientEnd = gradient->p1();
-    else if (isRadialGradient())
+    else if (isRadialGradientValue())
         gradientEnd = gradientStart + FloatSize(gradient->endRadius(), 0);
 
     for (size_t i = 0; i < numStops; ++i) {
@@ -268,7 +268,7 @@ void CSSGradientValue::addStops(Gradient* gradient, RenderElement* renderer, Ren
 
             // Radial gradients may need to extend further than the endpoints, because they have
             // to repeat out to the corners of the box.
-            if (isRadialGradient()) {
+            if (isRadialGradientValue()) {
                 if (!computedGradientLength) {
                     FloatSize gradientSize(gradientStart - gradientEnd);
                     gradientLength = gradientSize.diagonalLength();
@@ -326,7 +326,7 @@ void CSSGradientValue::addStops(Gradient* gradient, RenderElement* renderer, Ren
 
     // If the gradient goes outside the 0-1 range, normalize it by moving the endpoints, and adjusting the stops.
     if (numStops > 1 && (stops[0].offset < 0 || stops[numStops - 1].offset > 1)) {
-        if (isLinearGradient()) {
+        if (isLinearGradientValue()) {
             float firstOffset = stops[0].offset;
             float lastOffset = stops[numStops - 1].offset;
             if (firstOffset != lastOffset) {
@@ -344,7 +344,7 @@ void CSSGradientValue::addStops(Gradient* gradient, RenderElement* renderer, Ren
                 for (size_t i = 0; i < numStops; ++i)
                     stops[i].offset = 1;
             }
-        } else if (isRadialGradient()) {
+        } else if (isRadialGradientValue()) {
             // Rather than scaling the points < 0, we truncate them, so only scale according to the largest point.
             float firstOffset = 0;
             float lastOffset = stops[numStops - 1].offset;
index 962d8dd..7e8a430 100644 (file)
@@ -74,9 +74,6 @@ public:
 
     void sortStopsIfNeeded();
 
-    bool isLinearGradient() const { return classType() == LinearGradientClass; }
-    bool isRadialGradient() const { return classType() == RadialGradientClass; }
-
     bool isRepeating() const { return m_repeating; }
 
     CSSGradientType gradientType() const { return m_gradientType; }
@@ -133,6 +130,7 @@ protected:
     bool m_repeating;
 };
 
+CSS_VALUE_TYPE_CASTS(GradientValue)
 
 class CSSLinearGradientValue : public CSSGradientValue {
 public:
@@ -171,6 +169,8 @@ private:
     RefPtr<CSSPrimitiveValue> m_angle; // may be null.
 };
 
+CSS_VALUE_TYPE_CASTS(LinearGradientValue)
+
 class CSSRadialGradientValue : public CSSGradientValue {
 public:
     static PassRefPtr<CSSRadialGradientValue> create(CSSGradientRepeat repeat, CSSGradientType gradientType = CSSRadialGradient)
@@ -232,6 +232,8 @@ private:
     RefPtr<CSSPrimitiveValue> m_endVerticalSize;
 };
 
+CSS_VALUE_TYPE_CASTS(RadialGradientValue)
+
 } // namespace WebCore
 
 #endif // CSSGradientValue_h
index 7015b7b..785f4ce 100644 (file)
@@ -116,9 +116,9 @@ PassRefPtr<Image> CSSImageGeneratorValue::image(RenderElement* renderer, const I
         return toCSSFilterImageValue(this)->image(renderer, size);
 #endif
     case LinearGradientClass:
-        return static_cast<CSSLinearGradientValue*>(this)->image(renderer, size);
+        return toCSSLinearGradientValue(this)->image(renderer, size);
     case RadialGradientClass:
-        return static_cast<CSSRadialGradientValue*>(this)->image(renderer, size);
+        return toCSSRadialGradientValue(this)->image(renderer, size);
     default:
         ASSERT_NOT_REACHED();
     }
@@ -158,9 +158,9 @@ IntSize CSSImageGeneratorValue::fixedSize(const RenderElement* renderer)
         return toCSSFilterImageValue(this)->fixedSize(renderer);
 #endif
     case LinearGradientClass:
-        return static_cast<CSSLinearGradientValue*>(this)->fixedSize(renderer);
+        return toCSSLinearGradientValue(this)->fixedSize(renderer);
     case RadialGradientClass:
-        return static_cast<CSSRadialGradientValue*>(this)->fixedSize(renderer);
+        return toCSSRadialGradientValue(this)->fixedSize(renderer);
     default:
         ASSERT_NOT_REACHED();
     }
@@ -224,10 +224,10 @@ void CSSImageGeneratorValue::loadSubimages(CachedResourceLoader* cachedResourceL
         break;
 #endif
     case LinearGradientClass:
-        static_cast<CSSLinearGradientValue*>(this)->loadSubimages(cachedResourceLoader);
+        toCSSLinearGradientValue(this)->loadSubimages(cachedResourceLoader);
         break;
     case RadialGradientClass:
-        static_cast<CSSRadialGradientValue*>(this)->loadSubimages(cachedResourceLoader);
+        toCSSRadialGradientValue(this)->loadSubimages(cachedResourceLoader);
         break;
     default:
         ASSERT_NOT_REACHED();
index 34a6186..152cf45 100644 (file)
@@ -7502,7 +7502,7 @@ bool CSSParser::parseDeprecatedGradient(CSSParserValueList* valueList, RefPtr<CS
         a = args->next();
         if (!a || a->unit != CSSPrimitiveValue::CSS_NUMBER)
             return false;
-        static_cast<CSSRadialGradientValue*>(result.get())->setFirstRadius(createPrimitiveNumericValue(a));
+        toCSSRadialGradientValue(result.get())->setFirstRadius(createPrimitiveNumericValue(a));
 
         // Comma after the first radius.
         a = args->next();
@@ -7539,7 +7539,7 @@ bool CSSParser::parseDeprecatedGradient(CSSParserValueList* valueList, RefPtr<CS
         a = args->next();
         if (!a || a->unit != CSSPrimitiveValue::CSS_NUMBER)
             return false;
-        static_cast<CSSRadialGradientValue*>(result.get())->setSecondRadius(createPrimitiveNumericValue(a));
+        toCSSRadialGradientValue(result.get())->setSecondRadius(createPrimitiveNumericValue(a));
     }
 
     // We now will accept any number of stops (0 or more).
index cb2de23..e0188c3 100644 (file)
@@ -407,10 +407,10 @@ void CSSValue::destroy()
         delete static_cast<CSSFunctionValue*>(this);
         return;
     case LinearGradientClass:
-        delete static_cast<CSSLinearGradientValue*>(this);
+        delete toCSSLinearGradientValue(this);
         return;
     case RadialGradientClass:
-        delete static_cast<CSSRadialGradientValue*>(this);
+        delete toCSSRadialGradientValue(this);
         return;
     case CrossfadeClass:
         delete toCSSCrossfadeValue(this);
index 5fc2479..be077f4 100644 (file)
@@ -85,6 +85,8 @@ public:
     bool isImplicitInitialValue() const;
     bool isInheritedValue() const { return m_classType == InheritedClass; }
     bool isInitialValue() const { return m_classType == InitialClass; }
+    bool isLinearGradientValue() const { return m_classType == LinearGradientClass; }
+    bool isRadialGradientValue() const { return m_classType == RadialGradientClass; }
     bool isReflectValue() const { return m_classType == ReflectClass; }
     bool isShadowValue() const { return m_classType == ShadowClass; }
     bool isCubicBezierTimingFunctionValue() const { return m_classType == CubicBezierTimingFunctionClass; }
index 75aa988..36c926b 100644 (file)
@@ -2160,7 +2160,7 @@ void StyleResolver::applyProperty(CSSPropertyID id, CSSValue* value)
                 CSSValue* item = i.value();
                 if (item->isImageGeneratorValue()) {
                     if (item->isGradientValue())
-                        state.style()->setContent(StyleGeneratedImage::create(static_cast<CSSGradientValue*>(item)->gradientWithStylesResolved(this).get()), didSet);
+                        state.style()->setContent(StyleGeneratedImage::create(toCSSGradientValue(item)->gradientWithStylesResolved(this).get()), didSet);
                     else
                         state.style()->setContent(StyleGeneratedImage::create(static_cast<CSSImageGeneratorValue*>(item)), didSet);
                     didSet = true;
@@ -3096,7 +3096,7 @@ PassRefPtr<StyleImage> StyleResolver::styleImage(CSSPropertyID property, CSSValu
 
     if (value->isImageGeneratorValue()) {
         if (value->isGradientValue())
-            return generatedOrPendingFromValue(property, static_cast<CSSGradientValue*>(value)->gradientWithStylesResolved(this).get());
+            return generatedOrPendingFromValue(property, toCSSGradientValue(value)->gradientWithStylesResolved(this).get());
         return generatedOrPendingFromValue(property, static_cast<CSSImageGeneratorValue*>(value));
     }