Title: [92253] trunk/Source/WebCore
Revision
92253
Author
[email protected]
Date
2011-08-02 19:11:09 -0700 (Tue, 02 Aug 2011)

Log Message

Clean up value clampling in CSSStyleSelector and CSSPrimitiveValue.
https://bugs.webkit.org/show_bug.cgi?id=65441

Reviewed by Simon Fraser.

No new tests / refactoring only.

* css/CSSPrimitiveValue.h:
(WebCore::CSSPrimitiveValue::getFloatValue):
Implement in terms of the new templated getValue().
(WebCore::CSSPrimitiveValue::getIntValue):
Implement in terms of the new templated getValue().
(WebCore::CSSPrimitiveValue::getValue):
Templated getValue that works for all numeric types.

* css/CSSStyleSelector.cpp:
(WebCore::CSSStyleSelector::applyProperty):
Use getValue<short> instead of rolling-your-own clamp to short.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (92252 => 92253)


--- trunk/Source/WebCore/ChangeLog	2011-08-03 01:58:06 UTC (rev 92252)
+++ trunk/Source/WebCore/ChangeLog	2011-08-03 02:11:09 UTC (rev 92253)
@@ -1,3 +1,24 @@
+2011-08-02  Luke Macpherson   <[email protected]>
+
+        Clean up value clampling in CSSStyleSelector and CSSPrimitiveValue.
+        https://bugs.webkit.org/show_bug.cgi?id=65441
+
+        Reviewed by Simon Fraser.
+
+        No new tests / refactoring only.
+
+        * css/CSSPrimitiveValue.h:
+        (WebCore::CSSPrimitiveValue::getFloatValue):
+        Implement in terms of the new templated getValue().
+        (WebCore::CSSPrimitiveValue::getIntValue):
+        Implement in terms of the new templated getValue().
+        (WebCore::CSSPrimitiveValue::getValue):
+        Templated getValue that works for all numeric types.
+
+        * css/CSSStyleSelector.cpp:
+        (WebCore::CSSStyleSelector::applyProperty):
+        Use getValue<short> instead of rolling-your-own clamp to short.
+
 2011-08-02  Julien Chaffraix  <[email protected]>
 
         RenderObject::computeRectForRepaint and clippedOverflowRectForRepaint should be const

Modified: trunk/Source/WebCore/css/CSSPrimitiveValue.h (92252 => 92253)


--- trunk/Source/WebCore/css/CSSPrimitiveValue.h	2011-08-03 01:58:06 UTC (rev 92252)
+++ trunk/Source/WebCore/css/CSSPrimitiveValue.h	2011-08-03 02:11:09 UTC (rev 92253)
@@ -157,14 +157,18 @@
     double getDoubleValue() const { return m_value.num; }
 
     void setFloatValue(unsigned short unitType, double floatValue, ExceptionCode&);
-    float getFloatValue(unsigned short unitType, ExceptionCode& ec) const { return clampToFloat(getDoubleValue(unitType, ec)); }
-    float getFloatValue(unsigned short unitType) const { return clampToFloat(getDoubleValue(unitType)); }
-    float getFloatValue() const { return clampToFloat(m_value.num); }
+    float getFloatValue(unsigned short unitType, ExceptionCode& ec) const { return getValue<float>(unitType, ec); }
+    float getFloatValue(unsigned short unitType) const { return getValue<float>(unitType); }
+    float getFloatValue() const { return getValue<float>(); }
 
-    int getIntValue(unsigned short unitType, ExceptionCode& ec) const { return clampToInteger(getDoubleValue(unitType, ec)); }
-    int getIntValue(unsigned short unitType) const { return clampToInteger(getDoubleValue(unitType)); }
-    int getIntValue() const { return clampToInteger(m_value.num); }
+    int getIntValue(unsigned short unitType, ExceptionCode& ec) const { return getValue<int>(unitType, ec); }
+    int getIntValue(unsigned short unitType) const { return getValue<int>(unitType); }
+    int getIntValue() const { return getValue<int>(); }
 
+    template<typename T> inline T getValue(unsigned short unitType, ExceptionCode& ec) const { return clampTo<T>(getDoubleValue(unitType, ec)); }
+    template<typename T> inline T getValue(unsigned short unitType) const { return clampTo<T>(getDoubleValue(unitType)); }
+    template<typename T> inline T getValue() const { return clampTo<T>(m_value.num); }
+
     void setStringValue(unsigned short stringType, const String& stringValue, ExceptionCode&);
     String getStringValue(ExceptionCode&) const;
     String getStringValue() const;

Modified: trunk/Source/WebCore/css/CSSStyleSelector.cpp (92252 => 92253)


--- trunk/Source/WebCore/css/CSSStyleSelector.cpp	2011-08-03 01:58:06 UTC (rev 92252)
+++ trunk/Source/WebCore/css/CSSStyleSelector.cpp	2011-08-03 02:11:09 UTC (rev 92253)
@@ -4496,7 +4496,7 @@
         if (!primitiveValue || primitiveValue->primitiveType() != CSSPrimitiveValue::CSS_NUMBER)
             return; // Error case.
         // Clamp opacity to the range 0-1
-        m_style->setOpacity(min(1.0f, max(0.0f, primitiveValue->getFloatValue())));
+        m_style->setOpacity(clampTo<float>(primitiveValue->getDoubleValue(), 0, 1));
         return;
     case CSSPropertyWebkitBoxAlign:
         HANDLE_INHERIT_AND_INITIAL_AND_PRIMITIVE(boxAlign, BoxAlign)
@@ -4770,7 +4770,7 @@
         if (primitiveValue->getIdent() == CSSValueAuto)
             m_style->setHyphenationLimitAfter(-1);
         else
-            m_style->setHyphenationLimitAfter(min(primitiveValue->getIntValue(CSSPrimitiveValue::CSS_NUMBER), static_cast<int>(numeric_limits<short>::max())));
+            m_style->setHyphenationLimitAfter(primitiveValue->getValue<short>(CSSPrimitiveValue::CSS_NUMBER));
         return;
     }
     case CSSPropertyWebkitHyphenateLimitBefore: {
@@ -4778,7 +4778,7 @@
         if (primitiveValue->getIdent() == CSSValueAuto)
             m_style->setHyphenationLimitBefore(-1);
         else
-            m_style->setHyphenationLimitBefore(min(primitiveValue->getIntValue(CSSPrimitiveValue::CSS_NUMBER), static_cast<int>(numeric_limits<short>::max())));
+            m_style->setHyphenationLimitBefore(primitiveValue->getValue<short>(CSSPrimitiveValue::CSS_NUMBER));
         return;
     }
     case CSSPropertyWebkitLocale: {
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to