Title: [91800] trunk/Source/WebCore
Revision
91800
Author
[email protected]
Date
2011-07-26 17:14:34 -0700 (Tue, 26 Jul 2011)

Log Message

Handle CSS Properties that can be either auto or a primitive value in CSSStyleApplyProperty
https://bugs.webkit.org/show_bug.cgi?id=65164

Reviewed by Dimitri Glazkov.

No new tests / refactoring only.

* css/CSSPrimitiveValueMappings.h:
Add casts to/from various numeric types.
(WebCore::CSSPrimitiveValue::operator short):
(WebCore::CSSPrimitiveValue::CSSPrimitiveValue):
(WebCore::CSSPrimitiveValue::operator unsigned short):
(WebCore::CSSPrimitiveValue::operator int):
(WebCore::CSSPrimitiveValue::operator float):
* css/CSSStyleApplyProperty.cpp:
Add class to handle properties that set an "auto" boolean on RenderStyle.
(WebCore::ApplyPropertyAuto::ApplyPropertyAuto):
(WebCore::ApplyPropertyAuto::applyInheritValue):
(WebCore::ApplyPropertyAuto::applyInitialValue):
(WebCore::ApplyPropertyAuto::applyValue):
(WebCore::ApplyPropertyAuto::hasAuto):
(WebCore::ApplyPropertyAuto::setAuto):
(WebCore::CSSStyleApplyProperty::CSSStyleApplyProperty):
* css/CSSStyleSelector.cpp:
Remove existing implementations.
(WebCore::CSSStyleSelector::applyProperty):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (91799 => 91800)


--- trunk/Source/WebCore/ChangeLog	2011-07-26 23:43:15 UTC (rev 91799)
+++ trunk/Source/WebCore/ChangeLog	2011-07-27 00:14:34 UTC (rev 91800)
@@ -1,3 +1,32 @@
+2011-07-26  Luke Macpherson   <[email protected]>
+
+        Handle CSS Properties that can be either auto or a primitive value in CSSStyleApplyProperty
+        https://bugs.webkit.org/show_bug.cgi?id=65164
+
+        Reviewed by Dimitri Glazkov.
+
+        No new tests / refactoring only.
+
+        * css/CSSPrimitiveValueMappings.h:
+        Add casts to/from various numeric types.
+        (WebCore::CSSPrimitiveValue::operator short):
+        (WebCore::CSSPrimitiveValue::CSSPrimitiveValue):
+        (WebCore::CSSPrimitiveValue::operator unsigned short):
+        (WebCore::CSSPrimitiveValue::operator int):
+        (WebCore::CSSPrimitiveValue::operator float):
+        * css/CSSStyleApplyProperty.cpp:
+        Add class to handle properties that set an "auto" boolean on RenderStyle.
+        (WebCore::ApplyPropertyAuto::ApplyPropertyAuto):
+        (WebCore::ApplyPropertyAuto::applyInheritValue):
+        (WebCore::ApplyPropertyAuto::applyInitialValue):
+        (WebCore::ApplyPropertyAuto::applyValue):
+        (WebCore::ApplyPropertyAuto::hasAuto):
+        (WebCore::ApplyPropertyAuto::setAuto):
+        (WebCore::CSSStyleApplyProperty::CSSStyleApplyProperty):
+        * css/CSSStyleSelector.cpp:
+        Remove existing implementations.
+        (WebCore::CSSStyleSelector::applyProperty):
+
 2011-07-26  Pratik Solanki  <[email protected]>
 
         Add protection space authentication callback code to CFNetwork loader on Mac

Modified: trunk/Source/WebCore/css/CSSPrimitiveValueMappings.h (91799 => 91800)


--- trunk/Source/WebCore/css/CSSPrimitiveValueMappings.h	2011-07-26 23:43:15 UTC (rev 91799)
+++ trunk/Source/WebCore/css/CSSPrimitiveValueMappings.h	2011-07-27 00:14:34 UTC (rev 91800)
@@ -45,6 +45,8 @@
 #include "ThemeTypes.h"
 #include "UnicodeBidi.h"
 
+#include <wtf/MathExtras.h>
+
 namespace WebCore {
 
 template<> inline CSSPrimitiveValue::CSSPrimitiveValue(short i)
@@ -57,12 +59,60 @@
 template<> inline CSSPrimitiveValue::operator short() const
 {
     if (m_type == CSS_NUMBER)
-        return static_cast<short>(m_value.num);
+        return clampTo<short>(m_value.num);
 
     ASSERT_NOT_REACHED();
     return 0;
 }
 
+template<> inline CSSPrimitiveValue::CSSPrimitiveValue(unsigned short i)
+    : m_type(CSS_NUMBER)
+    , m_hasCachedCSSText(false)
+{
+    m_value.num = static_cast<double>(i);
+}
+
+template<> inline CSSPrimitiveValue::operator unsigned short() const
+{
+    if (m_type == CSS_NUMBER)
+        return clampTo<unsigned short>(m_value.num);
+
+    ASSERT_NOT_REACHED();
+    return 0;
+}
+
+template<> inline CSSPrimitiveValue::CSSPrimitiveValue(int i)
+    : m_type(CSS_NUMBER)
+    , m_hasCachedCSSText(false)
+{
+    m_value.num = static_cast<double>(i);
+}
+
+template<> inline CSSPrimitiveValue::operator int() const
+{
+    if (m_type == CSS_NUMBER)
+        return clampTo<int>(m_value.num);
+
+    ASSERT_NOT_REACHED();
+    return 0;
+}
+
+template<> inline CSSPrimitiveValue::CSSPrimitiveValue(float i)
+    : m_type(CSS_NUMBER)
+    , m_hasCachedCSSText(false)
+{
+    m_value.num = static_cast<double>(i);
+}
+
+template<> inline CSSPrimitiveValue::operator float() const
+{
+    if (m_type == CSS_NUMBER)
+        return clampTo<float>(m_value.num);
+
+    ASSERT_NOT_REACHED();
+    return 0.0f;
+}
+
 template<> inline CSSPrimitiveValue::CSSPrimitiveValue(EBorderStyle e)
     : m_type(CSS_IDENT)
     , m_hasCachedCSSText(false)

Modified: trunk/Source/WebCore/css/CSSStyleApplyProperty.cpp (91799 => 91800)


--- trunk/Source/WebCore/css/CSSStyleApplyProperty.cpp	2011-07-26 23:43:15 UTC (rev 91799)
+++ trunk/Source/WebCore/css/CSSStyleApplyProperty.cpp	2011-07-27 00:14:34 UTC (rev 91800)
@@ -142,6 +142,62 @@
     }
 };
 
+enum AutoValueType {Number = 0, ComputeLength};
+template <typename T, AutoValueType valueType = Number, int autoIdentity = CSSValueAuto>
+class ApplyPropertyAuto : public ApplyPropertyDefaultBase<T> {
+public:
+    typedef bool (RenderStyle::*HasAutoFunction)() const;
+    typedef void (RenderStyle::*SetAutoFunction)();
+
+    ApplyPropertyAuto(typename ApplyPropertyDefaultBase<T>::GetterFunction getter, typename ApplyPropertyDefaultBase<T>::SetterFunction setter, HasAutoFunction hasAuto, SetAutoFunction setAuto)
+        : ApplyPropertyDefaultBase<T>(getter, setter, 0)
+        , m_hasAuto(hasAuto)
+        , m_setAuto(setAuto)
+    {
+    }
+
+protected:
+    virtual void applyInheritValue(CSSStyleSelector* selector) const
+    {
+        if (hasAuto(selector->parentStyle()))
+            setAuto(selector->style());
+        else
+            ApplyPropertyDefaultBase<T>::setValue(selector->style(), ApplyPropertyDefaultBase<T>::value(selector->parentStyle()));
+    }
+
+    virtual void applyInitialValue(CSSStyleSelector* selector) const
+    {
+        setAuto(selector->style());
+    }
+
+    virtual void applyValue(CSSStyleSelector* selector, CSSValue* value) const
+    {
+        if (!value->isPrimitiveValue())
+            return;
+
+        CSSPrimitiveValue* primitiveValue = static_cast<CSSPrimitiveValue*>(value);
+        if (primitiveValue->getIdent() == autoIdentity)
+            setAuto(selector->style());
+        else if (valueType == Number)
+            ApplyPropertyDefaultBase<T>::setValue(selector->style(), *primitiveValue);
+        else if (valueType == ComputeLength)
+            ApplyPropertyDefaultBase<T>::setValue(selector->style(), primitiveValue->computeLength<T>(selector->style(), selector->rootElementStyle(), selector->style()->effectiveZoom()));
+    }
+
+    bool hasAuto(RenderStyle* style) const
+    {
+        return (style->*m_hasAuto)();
+    }
+
+    void setAuto(RenderStyle* style) const
+    {
+        (style->*m_setAuto)();
+    }
+
+    HasAutoFunction m_hasAuto;
+    SetAutoFunction m_setAuto;
+};
+
 enum ColorInherit {NoInheritFromParent = 0, InheritFromParent};
 template <ColorInherit inheritColorFromParent>
 class ApplyPropertyColor : public ApplyPropertyBase {
@@ -806,6 +862,11 @@
     setPropertyHandler(CSSPropertyWebkitTransformOriginY, new ApplyPropertyLength<>(&RenderStyle::transformOriginY, &RenderStyle::setTransformOriginY, &RenderStyle::initialTransformOriginY));
     setPropertyHandler(CSSPropertyWebkitTransformOriginZ, new ApplyPropertyComputeLength<float>(&RenderStyle::transformOriginZ, &RenderStyle::setTransformOriginZ, &RenderStyle::initialTransformOriginZ));
     setPropertyHandler(CSSPropertyWebkitTransformOrigin, new ApplyPropertyExpanding<SuppressValue>(propertyHandler(CSSPropertyWebkitTransformOriginX), propertyHandler(CSSPropertyWebkitTransformOriginY), propertyHandler(CSSPropertyWebkitTransformOriginZ)));
+
+    setPropertyHandler(CSSPropertyWebkitColumnCount, new ApplyPropertyAuto<unsigned short>(&RenderStyle::columnCount, &RenderStyle::setColumnCount, &RenderStyle::hasAutoColumnCount, &RenderStyle::setHasAutoColumnCount));
+    setPropertyHandler(CSSPropertyWebkitColumnGap, new ApplyPropertyAuto<float, ComputeLength, CSSValueNormal>(&RenderStyle::columnGap, &RenderStyle::setColumnGap, &RenderStyle::hasNormalColumnGap, &RenderStyle::setHasNormalColumnGap));
+    setPropertyHandler(CSSPropertyWebkitColumnWidth, new ApplyPropertyAuto<float, ComputeLength>(&RenderStyle::columnWidth, &RenderStyle::setColumnWidth, &RenderStyle::hasAutoColumnWidth, &RenderStyle::setHasAutoColumnWidth));
+    setPropertyHandler(CSSPropertyZIndex, new ApplyPropertyAuto<int>(&RenderStyle::zIndex, &RenderStyle::setZIndex, &RenderStyle::hasAutoZIndex, &RenderStyle::setHasAutoZIndex));
 }
 
 

Modified: trunk/Source/WebCore/css/CSSStyleSelector.cpp (91799 => 91800)


--- trunk/Source/WebCore/css/CSSStyleSelector.cpp	2011-07-26 23:43:15 UTC (rev 91799)
+++ trunk/Source/WebCore/css/CSSStyleSelector.cpp	2011-07-27 00:14:34 UTC (rev 91800)
@@ -3901,22 +3901,6 @@
         return;
     }
 
-    case CSSPropertyZIndex: {
-        if (isInherit) {
-            if (m_parentStyle->hasAutoZIndex())
-                m_style->setHasAutoZIndex();
-            else
-                m_style->setZIndex(m_parentStyle->zIndex());
-            return;
-        } else if (isInitial || primitiveValue->getIdent() == CSSValueAuto) {
-            m_style->setHasAutoZIndex();
-            return;
-        }
-        
-        // FIXME: Should clamp all sorts of other integer properties too.
-        m_style->setZIndex(clampToInteger(primitiveValue->getDoubleValue()));
-        return;
-    }
     case CSSPropertyWidows:
         HANDLE_INHERIT_AND_INITIAL_AND_PRIMITIVE(widows, Widows)
         return;
@@ -4575,53 +4559,11 @@
         else
             m_style->setBoxSizing(BORDER_BOX);
         return;
-    case CSSPropertyWebkitColumnCount: {
-        if (isInherit) {
-            if (m_parentStyle->hasAutoColumnCount())
-                m_style->setHasAutoColumnCount();
-            else
-                m_style->setColumnCount(m_parentStyle->columnCount());
-            return;
-        } else if (isInitial || primitiveValue->getIdent() == CSSValueAuto) {
-            m_style->setHasAutoColumnCount();
-            return;
-        }
-        m_style->setColumnCount(static_cast<unsigned short>(primitiveValue->getDoubleValue()));
-        return;
-    }
-    case CSSPropertyWebkitColumnGap: {
-        if (isInherit) {
-            if (m_parentStyle->hasNormalColumnGap())
-                m_style->setHasNormalColumnGap();
-            else
-                m_style->setColumnGap(m_parentStyle->columnGap());
-            return;
-        } else if (isInitial || primitiveValue->getIdent() == CSSValueNormal) {
-            m_style->setHasNormalColumnGap();
-            return;
-        }
-        m_style->setColumnGap(primitiveValue->computeLength<float>(style(), m_rootElementStyle, zoomFactor));
-        return;
-    }
     case CSSPropertyWebkitColumnSpan: {
         HANDLE_INHERIT_AND_INITIAL(columnSpan, ColumnSpan)
         m_style->setColumnSpan(primitiveValue->getIdent() == CSSValueAll);
         return;
     }
-    case CSSPropertyWebkitColumnWidth: {
-        if (isInherit) {
-            if (m_parentStyle->hasAutoColumnWidth())
-                m_style->setHasAutoColumnWidth();
-            else
-                m_style->setColumnWidth(m_parentStyle->columnWidth());
-            return;
-        } else if (isInitial || primitiveValue->getIdent() == CSSValueAuto) {
-            m_style->setHasAutoColumnWidth();
-            return;
-        }
-        m_style->setColumnWidth(primitiveValue->computeLength<float>(style(), m_rootElementStyle, zoomFactor));
-        return;
-    }
     case CSSPropertyWebkitColumnRuleStyle:
         HANDLE_INHERIT_AND_INITIAL_AND_PRIMITIVE_WITH_VALUE(columnRuleStyle, ColumnRuleStyle, BorderStyle)
         return;
@@ -5316,6 +5258,10 @@
     case CSSPropertyWebkitPerspectiveOriginY:
     case CSSPropertyWebkitPerspectiveOrigin:
     case CSSPropertyCursor:
+    case CSSPropertyWebkitColumnCount:
+    case CSSPropertyWebkitColumnGap:
+    case CSSPropertyWebkitColumnWidth:
+    case CSSPropertyZIndex:
         ASSERT_NOT_REACHED();
         return;
 #if ENABLE(SVG)
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to