Changeset 92253 in webkit


Ignore:
Timestamp:
Aug 2, 2011 7:11:09 PM (13 years ago)
Author:
macpherson@chromium.org
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.

Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r92252 r92253  
     12011-08-02  Luke Macpherson   <macpherson@chromium.org>
     2
     3        Clean up value clampling in CSSStyleSelector and CSSPrimitiveValue.
     4        https://bugs.webkit.org/show_bug.cgi?id=65441
     5
     6        Reviewed by Simon Fraser.
     7
     8        No new tests / refactoring only.
     9
     10        * css/CSSPrimitiveValue.h:
     11        (WebCore::CSSPrimitiveValue::getFloatValue):
     12        Implement in terms of the new templated getValue().
     13        (WebCore::CSSPrimitiveValue::getIntValue):
     14        Implement in terms of the new templated getValue().
     15        (WebCore::CSSPrimitiveValue::getValue):
     16        Templated getValue that works for all numeric types.
     17
     18        * css/CSSStyleSelector.cpp:
     19        (WebCore::CSSStyleSelector::applyProperty):
     20        Use getValue<short> instead of rolling-your-own clamp to short.
     21
    1222011-08-02  Julien Chaffraix  <jchaffraix@webkit.org>
    223
  • trunk/Source/WebCore/css/CSSPrimitiveValue.h

    r92106 r92253  
    158158
    159159    void setFloatValue(unsigned short unitType, double floatValue, ExceptionCode&);
    160     float getFloatValue(unsigned short unitType, ExceptionCode& ec) const { return clampToFloat(getDoubleValue(unitType, ec)); }
    161     float getFloatValue(unsigned short unitType) const { return clampToFloat(getDoubleValue(unitType)); }
    162     float getFloatValue() const { return clampToFloat(m_value.num); }
    163 
    164     int getIntValue(unsigned short unitType, ExceptionCode& ec) const { return clampToInteger(getDoubleValue(unitType, ec)); }
    165     int getIntValue(unsigned short unitType) const { return clampToInteger(getDoubleValue(unitType)); }
    166     int getIntValue() const { return clampToInteger(m_value.num); }
     160    float getFloatValue(unsigned short unitType, ExceptionCode& ec) const { return getValue<float>(unitType, ec); }
     161    float getFloatValue(unsigned short unitType) const { return getValue<float>(unitType); }
     162    float getFloatValue() const { return getValue<float>(); }
     163
     164    int getIntValue(unsigned short unitType, ExceptionCode& ec) const { return getValue<int>(unitType, ec); }
     165    int getIntValue(unsigned short unitType) const { return getValue<int>(unitType); }
     166    int getIntValue() const { return getValue<int>(); }
     167
     168    template<typename T> inline T getValue(unsigned short unitType, ExceptionCode& ec) const { return clampTo<T>(getDoubleValue(unitType, ec)); }
     169    template<typename T> inline T getValue(unsigned short unitType) const { return clampTo<T>(getDoubleValue(unitType)); }
     170    template<typename T> inline T getValue() const { return clampTo<T>(m_value.num); }
    167171
    168172    void setStringValue(unsigned short stringType, const String& stringValue, ExceptionCode&);
  • trunk/Source/WebCore/css/CSSStyleSelector.cpp

    r92243 r92253  
    44974497            return; // Error case.
    44984498        // Clamp opacity to the range 0-1
    4499         m_style->setOpacity(min(1.0f, max(0.0f, primitiveValue->getFloatValue())));
     4499        m_style->setOpacity(clampTo<float>(primitiveValue->getDoubleValue(), 0, 1));
    45004500        return;
    45014501    case CSSPropertyWebkitBoxAlign:
     
    47714771            m_style->setHyphenationLimitAfter(-1);
    47724772        else
    4773             m_style->setHyphenationLimitAfter(min(primitiveValue->getIntValue(CSSPrimitiveValue::CSS_NUMBER), static_cast<int>(numeric_limits<short>::max())));
     4773            m_style->setHyphenationLimitAfter(primitiveValue->getValue<short>(CSSPrimitiveValue::CSS_NUMBER));
    47744774        return;
    47754775    }
     
    47794779            m_style->setHyphenationLimitBefore(-1);
    47804780        else
    4781             m_style->setHyphenationLimitBefore(min(primitiveValue->getIntValue(CSSPrimitiveValue::CSS_NUMBER), static_cast<int>(numeric_limits<short>::max())));
     4781            m_style->setHyphenationLimitBefore(primitiveValue->getValue<short>(CSSPrimitiveValue::CSS_NUMBER));
    47824782        return;
    47834783    }
Note: See TracChangeset for help on using the changeset viewer.