Changeset 91336 in webkit


Ignore:
Timestamp:
Jul 19, 2011 10:41:16 PM (13 years ago)
Author:
macpherson@chromium.org
Message:

Implement CSSPropertyCounterIncrement and CounterReset in CSSStyleApplyProperty.
https://bugs.webkit.org/show_bug.cgi?id=64846

Reviewed by Dimitri Glazkov.

No new tests / refactoring only.

  • css/CSSStyleApplyProperty.cpp:

(WebCore::ApplyPropertyCounter
Added class to handle counter properties.
(WebCore::CSSStyleApplyProperty::CSSStyleApplyProperty):
Initialize counter property handlers.

  • css/CSSStyleSelector.cpp:

(WebCore::CSSStyleSelector::applyProperty):
Remove old handlers.

Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r91333 r91336  
     12011-07-19  Luke Macpherson   <macpherson@chromium.org>
     2
     3        Implement CSSPropertyCounterIncrement and CounterReset in CSSStyleApplyProperty.
     4        https://bugs.webkit.org/show_bug.cgi?id=64846
     5
     6        Reviewed by Dimitri Glazkov.
     7
     8        No new tests / refactoring only.
     9
     10        * css/CSSStyleApplyProperty.cpp:
     11        (WebCore::ApplyPropertyCounter
     12        Added class to handle counter properties.
     13        (WebCore::CSSStyleApplyProperty::CSSStyleApplyProperty):
     14        Initialize counter property handlers.
     15        * css/CSSStyleSelector.cpp:
     16        (WebCore::CSSStyleSelector::applyProperty):
     17        Remove old handlers.
     18
    1192011-07-19  Kent Tamura  <tkent@chromium.org>
    220
  • trunk/Source/WebCore/css/CSSStyleApplyProperty.cpp

    r91283 r91336  
    506506    }
    507507};
     508
     509enum CounterBehavior {Increment = 0, Reset};
     510template <CounterBehavior counterBehavior>
     511class ApplyPropertyCounter : public ApplyPropertyBase {
     512private:
     513    virtual void applyInheritValue(CSSStyleSelector*) const { }
     514    virtual void applyInitialValue(CSSStyleSelector*) const { }
     515
     516    virtual void applyValue(CSSStyleSelector* selector, CSSValue* value) const
     517    {
     518        if (!value->isValueList())
     519            return;
     520
     521        CSSValueList* list = static_cast<CSSValueList*>(value);
     522
     523        CounterDirectiveMap& map = selector->style()->accessCounterDirectives();
     524        typedef CounterDirectiveMap::iterator Iterator;
     525
     526        Iterator end = map.end();
     527        for (Iterator it = map.begin(); it != end; ++it)
     528            if (counterBehavior)
     529                it->second.m_reset = false;
     530            else
     531                it->second.m_increment = false;
     532
     533        int length = list ? list->length() : 0;
     534        for (int i = 0; i < length; ++i) {
     535            CSSValue* currValue = list->itemWithoutBoundsCheck(i);
     536            if (!currValue->isPrimitiveValue())
     537                continue;
     538
     539            Pair* pair = static_cast<CSSPrimitiveValue*>(currValue)->getPairValue();
     540            if (!pair || !pair->first() || !pair->second())
     541                continue;
     542
     543            AtomicString identifier = static_cast<CSSPrimitiveValue*>(pair->first())->getStringValue();
     544            // FIXME: What about overflow?
     545            int value = static_cast<CSSPrimitiveValue*>(pair->second())->getIntValue();
     546            CounterDirectives& directives = map.add(identifier.impl(), CounterDirectives()).first->second;
     547            if (counterBehavior) {
     548                directives.m_reset = true;
     549                directives.m_resetValue = value;
     550            } else {
     551                if (directives.m_increment)
     552                    directives.m_incrementValue += value;
     553                else {
     554                    directives.m_increment = true;
     555                    directives.m_incrementValue = value;
     556                }
     557            }
     558        }
     559    }
     560};
     561
    508562
    509563class ApplyPropertyCursor : public ApplyPropertyBase {
     
    669723    setPropertyHandler(CSSPropertyCursor, new ApplyPropertyCursor());
    670724
     725    setPropertyHandler(CSSPropertyCounterIncrement, new ApplyPropertyCounter<Increment>());
     726    setPropertyHandler(CSSPropertyCounterReset, new ApplyPropertyCounter<Reset>());
     727
    671728    setPropertyHandler(CSSPropertyFontStyle, new ApplyPropertyFont<FontItalic>(&FontDescription::italic, &FontDescription::setItalic, FontItalicOff));
    672729    setPropertyHandler(CSSPropertyFontVariant, new ApplyPropertyFont<FontSmallCaps>(&FontDescription::smallCaps, &FontDescription::setSmallCaps, FontSmallCapsOff));
  • trunk/Source/WebCore/css/CSSStyleSelector.cpp

    r91286 r91336  
    35633563}
    35643564
    3565 static void applyCounterList(RenderStyle* style, CSSValueList* list, bool isReset)
    3566 {
    3567     CounterDirectiveMap& map = style->accessCounterDirectives();
    3568     typedef CounterDirectiveMap::iterator Iterator;
    3569 
    3570     Iterator end = map.end();
    3571     for (Iterator it = map.begin(); it != end; ++it)
    3572         if (isReset)
    3573             it->second.m_reset = false;
    3574         else
    3575             it->second.m_increment = false;
    3576 
    3577     int length = list ? list->length() : 0;
    3578     for (int i = 0; i < length; ++i) {
    3579         CSSValue* currValue = list->itemWithoutBoundsCheck(i);
    3580         if (!currValue->isPrimitiveValue())
    3581             continue;
    3582 
    3583         Pair* pair = static_cast<CSSPrimitiveValue*>(currValue)->getPairValue();
    3584         if (!pair || !pair->first() || !pair->second())
    3585             continue;
    3586 
    3587         AtomicString identifier = static_cast<CSSPrimitiveValue*>(pair->first())->getStringValue();
    3588         // FIXME: What about overflow?
    3589         int value = static_cast<CSSPrimitiveValue*>(pair->second())->getIntValue();
    3590         CounterDirectives& directives = map.add(identifier.impl(), CounterDirectives()).first->second;
    3591         if (isReset) {
    3592             directives.m_reset = true;
    3593             directives.m_resetValue = value;
    3594         } else {
    3595             if (directives.m_increment)
    3596                 directives.m_incrementValue += value;
    3597             else {
    3598                 directives.m_increment = true;
    3599                 directives.m_incrementValue = value;
    3600             }
    3601         }
    3602     }
    3603 }
    3604 
    36053565void CSSStyleSelector::applyPropertyToStyle(int id, CSSValue *value, RenderStyle* style)
    36063566{
     
    41884148        }
    41894149        return;
    4190 
    4191     case CSSPropertyCounterIncrement:
    4192         applyCounterList(style(), value->isValueList() ? static_cast<CSSValueList*>(value) : 0, false);
    4193         return;
    4194     case CSSPropertyCounterReset:
    4195         applyCounterList(style(), value->isValueList() ? static_cast<CSSValueList*>(value) : 0, true);
    4196         return;
    4197 
    41984150    case CSSPropertyFontFamily: {
    41994151        // list of strings and ids
     
    53345286    case CSSPropertyWebkitBorderHorizontalSpacing:
    53355287    case CSSPropertyWebkitBorderVerticalSpacing:
     5288    case CSSPropertyCounterIncrement:
     5289    case CSSPropertyCounterReset:
    53365290    case CSSPropertyLetterSpacing:
    53375291    case CSSPropertyWordSpacing:
Note: See TracChangeset for help on using the changeset viewer.