CSSStyleSelector: Clean up getColorFromPrimitiveValue().
authorkling@webkit.org <kling@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 18 Dec 2011 03:00:43 +0000 (03:00 +0000)
committerkling@webkit.org <kling@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 18 Dec 2011 03:00:43 +0000 (03:00 +0000)
<http://webkit.org/b/74789>

Reviewed by Antti Koivisto.

Rename getColorFromPrimitiveValue() to colorFromPrimitiveValue() and rework
it to be a bit more readable.

* css/CSSGradientValue.cpp:
(WebCore::CSSGradientValue::addStops):
* css/CSSStyleApplyProperty.cpp:
(WebCore::ApplyPropertyColor::applyValue):
* css/CSSStyleSelector.cpp:
(WebCore::CSSStyleSelector::applyProperty):
(WebCore::CSSStyleSelector::colorFromPrimitiveValue):
(WebCore::CSSStyleSelector::createFilterOperations):
* css/CSSStyleSelector.h:
* css/SVGCSSStyleSelector.cpp:
(WebCore::CSSStyleSelector::applySVGProperty):

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

Source/WebCore/ChangeLog
Source/WebCore/css/CSSGradientValue.cpp
Source/WebCore/css/CSSStyleApplyProperty.cpp
Source/WebCore/css/CSSStyleSelector.cpp
Source/WebCore/css/CSSStyleSelector.h
Source/WebCore/css/SVGCSSStyleSelector.cpp

index 8878e06..3a1cff7 100644 (file)
@@ -1,3 +1,25 @@
+2011-12-17  Andreas Kling  <kling@webkit.org>
+
+        CSSStyleSelector: Clean up getColorFromPrimitiveValue().
+        <http://webkit.org/b/74789>
+
+        Reviewed by Antti Koivisto.
+
+        Rename getColorFromPrimitiveValue() to colorFromPrimitiveValue() and rework
+        it to be a bit more readable.
+
+        * css/CSSGradientValue.cpp:
+        (WebCore::CSSGradientValue::addStops):
+        * css/CSSStyleApplyProperty.cpp:
+        (WebCore::ApplyPropertyColor::applyValue):
+        * css/CSSStyleSelector.cpp:
+        (WebCore::CSSStyleSelector::applyProperty):
+        (WebCore::CSSStyleSelector::colorFromPrimitiveValue):
+        (WebCore::CSSStyleSelector::createFilterOperations):
+        * css/CSSStyleSelector.h:
+        * css/SVGCSSStyleSelector.cpp:
+        (WebCore::CSSStyleSelector::applySVGProperty):
+
 2011-12-17  Kenichi Ishibashi  <bashi@chromium.org>
 
         Text dispappear when SVG font has no latin character
index e869542..41977fb 100644 (file)
@@ -114,7 +114,7 @@ void CSSGradientValue::addStops(Gradient* gradient, RenderObject* renderer, Rend
         // We have to resolve colors.
         for (unsigned i = 0; i < m_stops.size(); i++) {
             const CSSGradientColorStop& stop = m_stops[i];
-            Color color = renderer->document()->styleSelector()->getColorFromPrimitiveValue(stop.m_color.get());
+            Color color = renderer->document()->styleSelector()->colorFromPrimitiveValue(stop.m_color.get());
 
             float offset;
             if (stop.m_position->primitiveType() == CSSPrimitiveValue::CSS_PERCENTAGE)
@@ -147,7 +147,7 @@ void CSSGradientValue::addStops(Gradient* gradient, RenderObject* renderer, Rend
     for (size_t i = 0; i < numStops; ++i) {
         const CSSGradientColorStop& stop = m_stops[i];
 
-        stops[i].color = renderer->document()->styleSelector()->getColorFromPrimitiveValue(stop.m_color.get());
+        stops[i].color = renderer->document()->styleSelector()->colorFromPrimitiveValue(stop.m_color.get());
 
         if (stop.m_position) {
             int type = stop.m_position->primitiveType();
index 9841c14..47433d0 100644 (file)
@@ -245,9 +245,9 @@ public:
             applyInheritValue(selector);
         else {
             if (selector->applyPropertyToRegularStyle())
-                (selector->style()->*setterFunction)(selector->getColorFromPrimitiveValue(primitiveValue, false));
+                (selector->style()->*setterFunction)(selector->colorFromPrimitiveValue(primitiveValue));
             if (selector->applyPropertyToVisitedLinkStyle())
-                (selector->style()->*visitedLinkSetterFunction)(selector->getColorFromPrimitiveValue(primitiveValue, true));
+                (selector->style()->*visitedLinkSetterFunction)(selector->colorFromPrimitiveValue(primitiveValue, /* forVisitedLink */ true));
         }
     }
 
index f17ff03..2229b6c 100644 (file)
@@ -3179,7 +3179,7 @@ void CSSStyleSelector::applyProperty(int id, CSSValue *value)
             ShadowStyle shadowStyle = item->style && item->style->getIdent() == CSSValueInset ? Inset : Normal;
             Color color;
             if (item->color)
-                color = getColorFromPrimitiveValue(item->color.get());
+                color = colorFromPrimitiveValue(item->color.get());
             OwnPtr<ShadowData> shadowData = adoptPtr(new ShadowData(x, y, blur, spread, shadowStyle, id == CSSPropertyWebkitBoxShadow, color.isValid() ? color : Color::transparent));
             if (id == CSSPropertyTextShadow)
                 m_style->setTextShadow(shadowData.release(), i.index()); // add to the list if this is not the first entry
@@ -3552,7 +3552,7 @@ void CSSStyleSelector::applyProperty(int id, CSSValue *value)
         if (!primitiveValue)
             break;
 
-        Color col = getColorFromPrimitiveValue(primitiveValue);
+        Color col = colorFromPrimitiveValue(primitiveValue);
         m_style->setTapHighlightColor(col);
         return;
     }
@@ -4783,26 +4783,30 @@ static Color colorForCSSValue(int cssValueId)
     return RenderTheme::defaultTheme()->systemColor(cssValueId);
 }
 
-Color CSSStyleSelector::getColorFromPrimitiveValue(CSSPrimitiveValue* primitiveValue, bool forVisitedLink) const
-{
-    Color col;
-    int ident = primitiveValue->getIdent();
-    if (ident) {
-        if (ident == CSSValueWebkitText)
-            col = m_element->document()->textColor();
-        else if (ident == CSSValueWebkitLink)
-            col = (m_element->isLink() && forVisitedLink) ? m_element->document()->visitedLinkColor() : m_element->document()->linkColor();
-        else if (ident == CSSValueWebkitActivelink)
-            col = m_element->document()->activeLinkColor();
-        else if (ident == CSSValueWebkitFocusRingColor)
-            col = RenderTheme::focusRingColor();
-        else if (ident == CSSValueCurrentcolor)
-            col = m_style->color();
-        else
-            col = colorForCSSValue(ident);
-    } else if (primitiveValue->primitiveType() == CSSPrimitiveValue::CSS_RGBCOLOR)
-        col.setRGB(primitiveValue->getRGBA32Value());
-    return col;
+Color CSSStyleSelector::colorFromPrimitiveValue(CSSPrimitiveValue* value, bool forVisitedLink) const
+{
+    if (value->primitiveType() == CSSPrimitiveValue::CSS_RGBCOLOR)
+        return Color(value->getRGBA32Value());
+
+    if (value->primitiveType() != CSSPrimitiveValue::CSS_IDENT)
+        return Color();
+
+    int ident = value->getIdent();
+
+    switch (ident) {
+    case CSSValueWebkitText:
+        return m_element->document()->textColor();
+    case CSSValueWebkitLink:
+        return (m_element->isLink() && forVisitedLink) ? m_element->document()->visitedLinkColor() : m_element->document()->linkColor();
+    case CSSValueWebkitActivelink:
+        return m_element->document()->activeLinkColor();
+    case CSSValueWebkitFocusRingColor:
+        return RenderTheme::focusRingColor();
+    case CSSValueCurrentcolor:
+        return m_style->color();
+    default:
+        return colorForCSSValue(ident);
+    }
 }
 
 bool CSSStyleSelector::hasSelectorForAttribute(const AtomicString &attrname) const
@@ -5388,8 +5392,8 @@ bool CSSStyleSelector::createFilterOperations(CSSValue* inValue, RenderStyle* st
             int blur = item->blur ? item->blur->computeLength<int>(style, rootStyle, zoomFactor) : 0;
             Color color;
             if (item->color)
-                color = getColorFromPrimitiveValue(item->color.get());
-            
+                color = colorFromPrimitiveValue(item->color.get());
+
             operations.operations().append(DropShadowFilterOperation::create(x, y, blur, color.isValid() ? color : Color::transparent, operationType));
             break;
         }
index f819e05..655e3b0 100644 (file)
@@ -191,7 +191,7 @@ private:
 public:
     bool useSVGZoomRules();
 
-    Color getColorFromPrimitiveValue(CSSPrimitiveValue*, bool forVisitedLink = false) const;
+    Color colorFromPrimitiveValue(CSSPrimitiveValue*, bool forVisitedLink = false) const;
 
     bool hasSelectorForAttribute(const AtomicString&) const;
 
index 0285d26..318d72b 100644 (file)
@@ -576,7 +576,7 @@ void CSSStyleSelector::applySVGProperty(int id, CSSValue* value)
             int blur = item->blur ? item->blur->computeLength<int>(style(), m_rootElementStyle) : 0;
             Color color;
             if (item->color)
-                color = getColorFromPrimitiveValue(item->color.get());
+                color = colorFromPrimitiveValue(item->color.get());
 
             // -webkit-svg-shadow does should not have a spread or style
             ASSERT(!item->spread);