Changeset 85289 in webkit


Ignore:
Timestamp:
Apr 28, 2011 7:25:12 PM (13 years ago)
Author:
commit-queue@webkit.org
Message:

2011-04-28 Luke Macpherson <macpherson@chromium.org>

Reviewed by Eric Seidel.

Implement CSS border width and related properties in CSSStyleApplyProperty.
https://bugs.webkit.org/show_bug.cgi?id=59414

No new tests as no functionality added.

  • css/CSSStyleApplyProperty.cpp: Separated ApplyPropertyDefault into parent and child so that other classes could inherit the applyInheritValue and applyInitialValue methods only. This was necessary to avoid casting from CSSPrimitiveValue to inappropriate types in ApplyPropertyDefault::applyValue().

Added ApplyPropertyWidth class for handling width based CSS properties.

  • css/CSSStyleSelector.cpp: Removed no-longer-required code for handling width based CSS properties.
  • css/CSSStyleSelector.h: Added a getter for m_rootElementStyle.
Location:
trunk/Source/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r85286 r85289  
     12011-04-28  Luke Macpherson   <macpherson@chromium.org>
     2
     3        Reviewed by Eric Seidel.
     4
     5        Implement CSS border width and related properties in CSSStyleApplyProperty.
     6        https://bugs.webkit.org/show_bug.cgi?id=59414
     7
     8        No new tests as no functionality added.
     9
     10        * css/CSSStyleApplyProperty.cpp:
     11        Separated ApplyPropertyDefault into parent and child so that other classes could inherit
     12        the applyInheritValue and applyInitialValue methods only.
     13        This was necessary to avoid casting from CSSPrimitiveValue to inappropriate types in ApplyPropertyDefault::applyValue().
     14       
     15        Added ApplyPropertyWidth class for handling width based CSS properties.
     16        * css/CSSStyleSelector.cpp:
     17        Removed no-longer-required code for handling width based CSS properties.
     18        * css/CSSStyleSelector.h:
     19        Added a getter for m_rootElementStyle.
     20
    1212011-04-28  Kent Tamura  <tkent@chromium.org>
    222
  • trunk/Source/WebCore/css/CSSStyleApplyProperty.cpp

    r85069 r85289  
    8383
    8484template <typename T>
    85 class ApplyPropertyDefault : public ApplyPropertyBase {
     85class ApplyPropertyDefaultBase : public ApplyPropertyBase {
    8686public:
    8787    typedef T (RenderStyle::*GetterFunction)() const;
     
    8989    typedef T (*InitialFunction)();
    9090
    91     ApplyPropertyDefault(GetterFunction getter, SetterFunction setter, InitialFunction initial)
     91    ApplyPropertyDefaultBase(GetterFunction getter, SetterFunction setter, InitialFunction initial)
    9292        : m_getter(getter)
    9393        , m_setter(setter)
     
    9696    }
    9797
     98private:
    9899    virtual void applyInheritValue(CSSStyleSelector* selector) const
    99100    {
     
    104105    {
    105106        (selector->style()->*m_setter)((*m_initial)());
    106     }
    107 
    108     virtual void applyValue(CSSStyleSelector* selector, CSSValue* value) const
    109     {
    110         if (value->isPrimitiveValue())
    111             (selector->style()->*m_setter)(*(static_cast<CSSPrimitiveValue*>(value)));
    112107    }
    113108
     
    118113};
    119114
    120 // CSSPropertyColor
     115
     116template <typename T>
     117class ApplyPropertyDefault : public ApplyPropertyDefaultBase<T> {
     118public:
     119    ApplyPropertyDefault(typename ApplyPropertyDefaultBase<T>::GetterFunction getter, typename ApplyPropertyDefaultBase<T>::SetterFunction setter, typename ApplyPropertyDefaultBase<T>::InitialFunction initial)
     120        : ApplyPropertyDefaultBase<T>(getter, setter, initial)
     121    {
     122    }
     123
     124protected:
     125    virtual void applyValue(CSSStyleSelector* selector, CSSValue* value) const
     126    {
     127        if (value->isPrimitiveValue())
     128            (selector->style()->*ApplyPropertyDefaultBase<T>::m_setter)(*static_cast<CSSPrimitiveValue*>(value));
     129    }
     130};
     131
    121132class ApplyPropertyColor : public ApplyPropertyBase {
    122133public:
     
    134145    }
    135146
     147private:
    136148    virtual void applyInheritValue(CSSStyleSelector* selector) const
    137149    {
     
    152164        if (!value->isPrimitiveValue())
    153165            return;
     166
    154167        CSSPrimitiveValue* primitiveValue = static_cast<CSSPrimitiveValue*>(value);
    155168        if (m_initial && primitiveValue->getIdent() == CSSValueCurrentcolor)
     
    159172    }
    160173
    161 private:
    162174    GetterFunction m_getter;
    163175    SetterFunction m_setter;
     
    169181class ApplyPropertyDirection : public ApplyPropertyDefault<TextDirection> {
    170182public:
    171     ApplyPropertyDirection(TextDirection (RenderStyle::*getter)() const, void (RenderStyle::*setter)(TextDirection), TextDirection (*initial)())
     183    ApplyPropertyDirection(GetterFunction getter, SetterFunction setter, InitialFunction initial)
    172184        : ApplyPropertyDefault<TextDirection>(getter, setter, initial)
    173185    {
    174186    }
    175187
     188private:
    176189    virtual void applyValue(CSSStyleSelector* selector, CSSValue* value) const
    177190    {
     
    203216    }
    204217
     218private:
    205219    virtual void applyInheritValue(CSSStyleSelector* selector) const
    206220    {
     
    276290};
    277291
     292class ApplyPropertyWidth : public ApplyPropertyDefaultBase<unsigned short> {
     293public:
     294    ApplyPropertyWidth(GetterFunction getter, SetterFunction setter, InitialFunction initial)
     295        : ApplyPropertyDefaultBase<unsigned short>(getter, setter, initial)
     296    {
     297    }
     298
     299private:
     300    virtual void applyValue(CSSStyleSelector* selector, CSSValue* value) const
     301    {
     302        if (!value->isPrimitiveValue())
     303            return;
     304
     305        CSSPrimitiveValue* primitiveValue = static_cast<CSSPrimitiveValue*>(value);
     306        short width;
     307        switch (primitiveValue->getIdent()) {
     308        case CSSValueThin:
     309            width = 1;
     310            break;
     311        case CSSValueMedium:
     312            width = 3;
     313            break;
     314        case CSSValueThick:
     315            width = 5;
     316            break;
     317        case CSSValueInvalid:
     318            width = primitiveValue->computeLengthShort(selector->style(), selector->rootElementStyle(), selector->style()->effectiveZoom());
     319            // CSS2 box model does not allow negative lengths for borders.
     320            if (width < 0)
     321                return;
     322            break;
     323        default:
     324            return;
     325        }
     326
     327        (selector->style()->*m_setter)(width);
     328    }
     329};
     330
    278331const CSSStyleApplyProperty& CSSStyleApplyProperty::sharedCSSStyleApplyProperty()
    279332{
     
    359412    setPropertyValue(CSSPropertyBorderLeftStyle, new ApplyPropertyDefault<EBorderStyle>(&RenderStyle::borderLeftStyle, &RenderStyle::setBorderLeftStyle, &RenderStyle::initialBorderStyle));
    360413
     414    setPropertyValue(CSSPropertyBorderTopWidth, new ApplyPropertyWidth(&RenderStyle::borderTopWidth, &RenderStyle::setBorderTopWidth, &RenderStyle::initialBorderWidth));
     415    setPropertyValue(CSSPropertyBorderRightWidth, new ApplyPropertyWidth(&RenderStyle::borderRightWidth, &RenderStyle::setBorderRightWidth, &RenderStyle::initialBorderWidth));
     416    setPropertyValue(CSSPropertyBorderBottomWidth, new ApplyPropertyWidth(&RenderStyle::borderBottomWidth, &RenderStyle::setBorderBottomWidth, &RenderStyle::initialBorderWidth));
     417    setPropertyValue(CSSPropertyBorderLeftWidth, new ApplyPropertyWidth(&RenderStyle::borderLeftWidth, &RenderStyle::setBorderLeftWidth, &RenderStyle::initialBorderWidth));
     418    setPropertyValue(CSSPropertyOutlineWidth, new ApplyPropertyWidth(&RenderStyle::outlineWidth, &RenderStyle::setOutlineWidth, &RenderStyle::initialBorderWidth));
     419    setPropertyValue(CSSPropertyWebkitColumnRuleWidth, new ApplyPropertyWidth(&RenderStyle::columnRuleWidth, &RenderStyle::setColumnRuleWidth, &RenderStyle::initialBorderWidth));
     420
    361421    setPropertyValue(CSSPropertyOutlineColor, new ApplyPropertyColor(&RenderStyle::outlineColor, &RenderStyle::setOutlineColor, &RenderStyle::color));
    362422
  • trunk/Source/WebCore/css/CSSStyleSelector.cpp

    r85267 r85289  
    38403840    }
    38413841
    3842 // length
    3843     case CSSPropertyBorderTopWidth:
    3844     case CSSPropertyBorderRightWidth:
    3845     case CSSPropertyBorderBottomWidth:
    3846     case CSSPropertyBorderLeftWidth:
    3847     case CSSPropertyOutlineWidth:
    3848     case CSSPropertyWebkitColumnRuleWidth:
    3849     {
    3850         if (isInherit) {
    3851             HANDLE_INHERIT_COND(CSSPropertyBorderTopWidth, borderTopWidth, BorderTopWidth)
    3852             HANDLE_INHERIT_COND(CSSPropertyBorderRightWidth, borderRightWidth, BorderRightWidth)
    3853             HANDLE_INHERIT_COND(CSSPropertyBorderBottomWidth, borderBottomWidth, BorderBottomWidth)
    3854             HANDLE_INHERIT_COND(CSSPropertyBorderLeftWidth, borderLeftWidth, BorderLeftWidth)
    3855             HANDLE_INHERIT_COND(CSSPropertyOutlineWidth, outlineWidth, OutlineWidth)
    3856             HANDLE_INHERIT_COND(CSSPropertyWebkitColumnRuleWidth, columnRuleWidth, ColumnRuleWidth)
    3857             return;
    3858         }
    3859         else if (isInitial) {
    3860             HANDLE_INITIAL_COND_WITH_VALUE(CSSPropertyBorderTopWidth, BorderTopWidth, BorderWidth)
    3861             HANDLE_INITIAL_COND_WITH_VALUE(CSSPropertyBorderRightWidth, BorderRightWidth, BorderWidth)
    3862             HANDLE_INITIAL_COND_WITH_VALUE(CSSPropertyBorderBottomWidth, BorderBottomWidth, BorderWidth)
    3863             HANDLE_INITIAL_COND_WITH_VALUE(CSSPropertyBorderLeftWidth, BorderLeftWidth, BorderWidth)
    3864             HANDLE_INITIAL_COND_WITH_VALUE(CSSPropertyOutlineWidth, OutlineWidth, BorderWidth)
    3865             HANDLE_INITIAL_COND_WITH_VALUE(CSSPropertyWebkitColumnRuleWidth, ColumnRuleWidth, BorderWidth)
    3866             return;
    3867         }
    3868 
    3869         if (!primitiveValue)
    3870             return;
    3871         short width = 3;
    3872         switch (primitiveValue->getIdent()) {
    3873         case CSSValueThin:
    3874             width = 1;
    3875             break;
    3876         case CSSValueMedium:
    3877             width = 3;
    3878             break;
    3879         case CSSValueThick:
    3880             width = 5;
    3881             break;
    3882         case CSSValueInvalid:
    3883             width = primitiveValue->computeLengthShort(style(), m_rootElementStyle, zoomFactor);
    3884             break;
    3885         default:
    3886             return;
    3887         }
    3888 
    3889         if (width < 0) return;
    3890         switch (id) {
    3891         case CSSPropertyBorderTopWidth:
    3892             m_style->setBorderTopWidth(width);
    3893             break;
    3894         case CSSPropertyBorderRightWidth:
    3895             m_style->setBorderRightWidth(width);
    3896             break;
    3897         case CSSPropertyBorderBottomWidth:
    3898             m_style->setBorderBottomWidth(width);
    3899             break;
    3900         case CSSPropertyBorderLeftWidth:
    3901             m_style->setBorderLeftWidth(width);
    3902             break;
    3903         case CSSPropertyOutlineWidth:
    3904             m_style->setOutlineWidth(width);
    3905             break;
    3906         case CSSPropertyWebkitColumnRuleWidth:
    3907             m_style->setColumnRuleWidth(width);
    3908             break;
    3909         default:
    3910             return;
    3911         }
    3912         return;
    3913     }
    3914 
    39153842    case CSSPropertyWebkitFontSmoothing: {
    39163843        FontDescription fontDescription = m_style->fontDescription();
     
    59975924    case CSSPropertyBorderBottomStyle:
    59985925    case CSSPropertyBorderLeftStyle:
     5926    case CSSPropertyBorderTopWidth:
     5927    case CSSPropertyBorderRightWidth:
     5928    case CSSPropertyBorderBottomWidth:
     5929    case CSSPropertyBorderLeftWidth:
     5930    case CSSPropertyOutlineWidth:
     5931    case CSSPropertyWebkitColumnRuleWidth:
    59995932    case CSSPropertyOutlineColor:
    60005933    case CSSPropertyWebkitColumnRuleColor:
  • trunk/Source/WebCore/css/CSSStyleSelector.h

    r84991 r85289  
    110110        RenderStyle* style() const { return m_style.get(); }
    111111        RenderStyle* parentStyle() const { return m_parentStyle; }
     112        RenderStyle* rootElementStyle() const { return m_rootElementStyle; }
    112113        Element* element() const { return m_element; }
    113114
Note: See TracChangeset for help on using the changeset viewer.