⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 92106 in webkit


Ignore:
Timestamp:
Aug 1, 2011, 1:31:43 AM (15 years ago)
Author:
macpherson@chromium.org
Message:

Add iterator to CSSValueList
https://bugs.webkit.org/show_bug.cgi?id=65297

Reviewed by Darin Adler.

No new tests / refactoring only.

  • css/CSSPrimitiveValue.h:

(WebCore::CSSPrimitiveValue::isLength):
Add shorthand to determine if this primitive value is a length.

  • css/CSSStyleSelector.cpp:

Use CSSValueListIterator throughout.
(WebCore::CSSStyleSelector::applyProperty):
(WebCore::CSSStyleSelector::applyPageSizeProperty):
(WebCore::CSSStyleSelector::createTransformOperations):

  • css/CSSValueList.cpp:

(WebCore::CSSValueList::copy):
Use itemWithoutBoundsCheck() instead of item().

  • css/CSSValueList.h:

Add CSSValueListIterator and CSSValueListInspector class definitions.
(WebCore::CSSValueList::item)
Provide inline definition of item.
(WebCore::CSSValueListIterator::CSSValueListIterator):
(WebCore::CSSValueListIterator::hasMore):
Return true if there are more values to consume, including the current value.
(WebCore::CSSValueListIterator::value):
Return the value at the current position.
(WebCore::CSSValueListIterator::next):
Move the iterator forward to the next item.
(WebCore::CSSValueListIterator::index):
Return the current position in the list.
(WebCore::CSSValueListInspector::item):
Return the item at a given index.
(WebCore::CSSValueListInspector::first):
Return the first item in the list.
(WebCore::CSSValueListInspector::second):
Return the second item in the list.
(WebCore::CSSValueListInspector::length):
Return the size of the underlying list.

Location:
trunk/Source/WebCore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r92105 r92106  
     12011-08-01  Luke Macpherson   <macpherson@chromium.org>
     2
     3        Add iterator to CSSValueList
     4        https://bugs.webkit.org/show_bug.cgi?id=65297
     5
     6        Reviewed by Darin Adler.
     7
     8        No new tests / refactoring only.
     9
     10        * css/CSSPrimitiveValue.h:
     11        (WebCore::CSSPrimitiveValue::isLength):
     12        Add shorthand to determine if this primitive value is a length.
     13        * css/CSSStyleSelector.cpp:
     14        Use CSSValueListIterator throughout.
     15        (WebCore::CSSStyleSelector::applyProperty):
     16        (WebCore::CSSStyleSelector::applyPageSizeProperty):
     17        (WebCore::CSSStyleSelector::createTransformOperations):
     18        * css/CSSValueList.cpp:
     19        (WebCore::CSSValueList::copy):
     20        Use itemWithoutBoundsCheck() instead of item().
     21        * css/CSSValueList.h:
     22        Add CSSValueListIterator and CSSValueListInspector class definitions.
     23        (WebCore::CSSValueList::item)
     24        Provide inline definition of item.
     25        (WebCore::CSSValueListIterator::CSSValueListIterator):
     26        (WebCore::CSSValueListIterator::hasMore):
     27        Return true if there are more values to consume, including the current value.
     28        (WebCore::CSSValueListIterator::value):
     29        Return the value at the current position.
     30        (WebCore::CSSValueListIterator::next):
     31        Move the iterator forward to the next item.
     32        (WebCore::CSSValueListIterator::index):
     33        Return the current position in the list.
     34        (WebCore::CSSValueListInspector::item):
     35        Return the item at a given index.
     36        (WebCore::CSSValueListInspector::first):
     37        Return the first item in the list.
     38        (WebCore::CSSValueListInspector::second):
     39        Return the second item in the list.
     40        (WebCore::CSSValueListInspector::length):
     41        Return the size of the underlying list.
     42
    1432011-08-01  Pavel Feldman  <pfeldman@google.com>
    244
  • trunk/Source/WebCore/css/CSSPrimitiveValue.h

    r91969 r92106  
    120120                                                    type == CSSPrimitiveValue::CSS_REMS; }
    121121
     122    bool isLength() const { return isUnitTypeLength(m_type); }
     123
    122124    static PassRefPtr<CSSPrimitiveValue> createIdentifier(int identifier) { return adoptRef(new CSSPrimitiveValue(identifier)); }
    123125    static PassRefPtr<CSSPrimitiveValue> createColor(unsigned rgbValue) { return adoptRef(new CSSPrimitiveValue(rgbValue)); }
  • trunk/Source/WebCore/css/CSSStyleSelector.cpp

    r91969 r92106  
    192192if (value->isValueList()) { \
    193193    /* Walk each value and put it into an animation, creating new animations as needed. */ \
    194     CSSValueList* valueList = static_cast<CSSValueList*>(value); \
    195     for (unsigned int i = 0; i < valueList->length(); i++) { \
     194    for (CSSValueListIterator i = value; i.hasMore(); i.advance()) { \
    196195        if (childIndex <= list->size()) \
    197196            list->append(Animation::create()); \
    198         mapAnimation##Prop(list->animation(childIndex), valueList->itemWithoutBoundsCheck(i)); \
     197        mapAnimation##Prop(list->animation(childIndex), i.value()); \
    199198        ++childIndex; \
    200199    } \
     
    242241if (value->isValueList()) { \
    243242    /* Walk each value and put it into a transition, creating new animations as needed. */ \
    244     CSSValueList* valueList = static_cast<CSSValueList*>(value); \
    245     for (unsigned int i = 0; i < valueList->length(); i++) { \
     243    for (CSSValueListIterator i = value; i.hasMore(); i.advance()) { \
    246244        if (childIndex <= list->size()) \
    247245            list->append(Animation::create()); \
    248         mapAnimation##Prop(list->animation(childIndex), valueList->itemWithoutBoundsCheck(i)); \
     246        mapAnimation##Prop(list->animation(childIndex), i.value()); \
    249247        ++childIndex; \
    250248    } \
     
    40194017            return;
    40204018
    4021         CSSValueList* list = static_cast<CSSValueList*>(value);
    4022         int len = list->length();
    4023 
    40244019#if ENABLE(CSS_REGIONS)
    4025         if (len == 1 && list->itemWithoutBoundsCheck(0)->isPrimitiveValue()) {
    4026             CSSPrimitiveValue* contentValue = static_cast<CSSPrimitiveValue*>(list->itemWithoutBoundsCheck(0));
     4020        CSSValueListInspector inspector = value;
     4021        if (inspector.length() == 1 && inspector.first()->isPrimitiveValue()) {
     4022            CSSPrimitiveValue* contentValue = static_cast<CSSPrimitiveValue*>(inspector->first());
    40274023            if (contentValue->primitiveType() == CSSPrimitiveValue::CSS_FROM_FLOW) {
    40284024                m_style->setRegionThread(contentValue->getStringValue().impl());
     
    40334029
    40344030        bool didSet = false;
    4035         for (int i = 0; i < len; i++) {
    4036             CSSValue* item = list->itemWithoutBoundsCheck(i);
     4031        for (CSSValueListIterator i = value; i.hasMore(); i.advance()) {
     4032            CSSValue* item = i.value();
    40374033            if (item->isImageGeneratorValue()) {
    40384034                m_style->setContent(static_cast<CSSImageGeneratorValue*>(item)->generatedImage(), didSet);
     
    41174113        if (value->isValueList()) {
    41184114            CSSValueList* list = static_cast<CSSValueList*>(value);
    4119             size_t length = list->length();
    4120             QuotesData* data = QuotesData::create(length);
     4115            QuotesData* data = QuotesData::create(list->length());
    41214116            if (!data)
    41224117                return; // Out of memory
    41234118            String* quotes = data->data();
    4124             for (size_t i = 0; i < length; i++) {
    4125                 CSSValue* item = list->itemWithoutBoundsCheck(i);
     4119            for (CSSValueListIterator i = list; i.hasMore(); i.advance()) {
     4120                CSSValue* item = i.value();
    41264121                ASSERT(item->isPrimitiveValue());
    41274122                primitiveValue = static_cast<CSSPrimitiveValue*>(item);
    41284123                ASSERT(primitiveValue->primitiveType() == CSSPrimitiveValue::CSS_STRING);
    4129                 quotes[i] = primitiveValue->getStringValue();
     4124                quotes[i.index()] = primitiveValue->getStringValue();
    41304125            }
    41314126            m_style->setQuotes(adoptRef(data));
     
    41634158            return;
    41644159        FontDescription fontDescription = m_style->fontDescription();
    4165         CSSValueList* list = static_cast<CSSValueList*>(value);
    4166         int len = list->length();
    41674160        FontFamily& firstFamily = fontDescription.firstFamily();
    41684161        FontFamily* currFamily = 0;
    4169        
     4162
    41704163        // Before mapping in a new font-family property, we should reset the generic family.
    41714164        bool oldFamilyUsedFixedDefaultSize = fontDescription.useFixedDefaultSize();
    41724165        fontDescription.setGenericFamily(FontDescription::NoFamily);
    41734166
    4174         for (int i = 0; i < len; i++) {
    4175             CSSValue* item = list->itemWithoutBoundsCheck(i);
     4167        for (CSSValueListIterator i = value; i.hasMore(); i.advance()) {
     4168            CSSValue* item = i.value();
    41764169            if (!item->isPrimitiveValue())
    41774170                continue;
     
    42494242            if (!value->isValueList())
    42504243                return;
    4251             CSSValueList *list = static_cast<CSSValueList*>(value);
    4252             int len = list->length();
    4253             for (int i = 0; i < len; i++)
     4244            for (CSSValueListIterator i = value; i.hasMore(); i.advance())
    42544245            {
    4255                 CSSValue *item = list->itemWithoutBoundsCheck(i);
     4246                CSSValue* item = i.value();
    42564247                if (!item->isPrimitiveValue())
    42574248                    continue;
     
    44544445            return;
    44554446
    4456         CSSValueList *list = static_cast<CSSValueList*>(value);
    4457         int len = list->length();
    4458         for (int i = 0; i < len; i++) {
    4459             CSSValue* currValue = list->itemWithoutBoundsCheck(i);
     4447        for (CSSValueListIterator i = value; i.hasMore(); i.advance()) {
     4448            CSSValue* currValue = i.value();
    44604449            if (!currValue->isShadowValue())
    44614450                continue;
    4462             ShadowValue* item = static_cast<ShadowValue*>(list->itemWithoutBoundsCheck(i));
     4451            ShadowValue* item = static_cast<ShadowValue*>(currValue);
    44634452            int x = item->x->computeLength<int>(style(), m_rootElementStyle, zoomFactor);
    44644453            int y = item->y->computeLength<int>(style(), m_rootElementStyle, zoomFactor);
     
    44714460            OwnPtr<ShadowData> shadowData = adoptPtr(new ShadowData(x, y, blur, spread, shadowStyle, id == CSSPropertyWebkitBoxShadow, color.isValid() ? color : Color::transparent));
    44724461            if (id == CSSPropertyTextShadow)
    4473                 m_style->setTextShadow(shadowData.release(), i /* add to the list if this is not the firsty entry */);
     4462                m_style->setTextShadow(shadowData.release(), i.index()); // add to the list if this is not the first entry
    44744463            else
    4475                 m_style->setBoxShadow(shadowData.release(), i /* add to the list if this is not the firsty entry */);
     4464                m_style->setBoxShadow(shadowData.release(), i.index()); // add to the list if this is not the first entry
    44764465        }
    44774466        return;
     
    52865275{
    52875276    m_style->resetPageSizeType();
    5288     if (!value->isValueList())
    5289         return;
    5290     CSSValueList* valueList = static_cast<CSSValueList*>(value);
    52915277    Length width;
    52925278    Length height;
    52935279    PageSizeType pageSizeType = PAGE_SIZE_AUTO;
    5294     switch (valueList->length()) {
     5280    CSSValueListInspector inspector = value;
     5281    switch (inspector.length()) {
    52955282    case 2: {
    52965283        // <length>{2} | <page-size> <orientation>
    52975284        pageSizeType = PAGE_SIZE_RESOLVED;
    5298         if (!valueList->item(0)->isPrimitiveValue() || !valueList->item(1)->isPrimitiveValue())
     5285        if (!inspector.first()->isPrimitiveValue() || !inspector.second()->isPrimitiveValue())
    52995286            return;
    5300         CSSPrimitiveValue* primitiveValue0 = static_cast<CSSPrimitiveValue*>(valueList->item(0));
    5301         CSSPrimitiveValue* primitiveValue1 = static_cast<CSSPrimitiveValue*>(valueList->item(1));
    5302         int type0 = primitiveValue0->primitiveType();
    5303         int type1 = primitiveValue1->primitiveType();
    5304         if (CSSPrimitiveValue::isUnitTypeLength(type0)) {
     5287        CSSPrimitiveValue* first = static_cast<CSSPrimitiveValue*>(inspector.first());
     5288        CSSPrimitiveValue* second = static_cast<CSSPrimitiveValue*>(inspector.second());
     5289        if (first->isLength()) {
    53055290            // <length>{2}
    5306             if (!CSSPrimitiveValue::isUnitTypeLength(type1))
     5291            if (!second->isLength())
    53075292                return;
    5308             width = primitiveValue0->computeLength<Length>(style(), m_rootElementStyle);
    5309             height = primitiveValue1->computeLength<Length>(style(), m_rootElementStyle);
     5293            width = first->computeLength<Length>(style(), m_rootElementStyle);
     5294            height = second->computeLength<Length>(style(), m_rootElementStyle);
    53105295        } else {
    53115296            // <page-size> <orientation>
    53125297            // The value order is guaranteed. See CSSParser::parseSizeParameter.
    5313             if (!pageSizeFromName(primitiveValue0, primitiveValue1, width, height))
     5298            if (!pageSizeFromName(first, second, width, height))
    53145299                return;
    53155300        }
     
    53185303    case 1: {
    53195304        // <length> | auto | <page-size> | [ portrait | landscape]
    5320         if (!valueList->item(0)->isPrimitiveValue())
     5305        if (!inspector.first()->isPrimitiveValue())
    53215306            return;
    5322         CSSPrimitiveValue* primitiveValue = static_cast<CSSPrimitiveValue*>(valueList->item(0));
    5323         int type = primitiveValue->primitiveType();
    5324         if (CSSPrimitiveValue::isUnitTypeLength(type)) {
     5307        CSSPrimitiveValue* primitiveValue = static_cast<CSSPrimitiveValue*>(inspector.first());
     5308        if (primitiveValue->isLength()) {
    53255309            // <length>
    53265310            pageSizeType = PAGE_SIZE_RESOLVED;
    53275311            width = height = primitiveValue->computeLength<Length>(style(), m_rootElementStyle);
    53285312        } else {
    5329             if (type != CSSPrimitiveValue::CSS_IDENT)
     5313            if (primitiveValue->primitiveType() != CSSPrimitiveValue::CSS_IDENT)
    53305314                return;
    53315315            switch (primitiveValue->getIdent()) {
     
    62816265    float zoomFactor = style ? style->effectiveZoom() : 1;
    62826266    TransformOperations operations;
    6283     CSSValueList* list = static_cast<CSSValueList*>(inValue);
    6284     unsigned size = list->length();
    6285     for (unsigned i = 0; i < size; i++) {
    6286         CSSValue* currValue = list->itemWithoutBoundsCheck(i);
     6267    for (CSSValueListIterator i = inValue; i.hasMore(); i.advance()) {
     6268        CSSValue* currValue = i.value();
    62876269        if (!currValue->isWebKitCSSTransformValue())
    62886270            continue;
    62896271
    6290         WebKitCSSTransformValue* transformValue = static_cast<WebKitCSSTransformValue*>(list->itemWithoutBoundsCheck(i));
     6272        WebKitCSSTransformValue* transformValue = static_cast<WebKitCSSTransformValue*>(i.value());
    62916273        if (!transformValue->length())
    62926274            continue;
  • trunk/Source/WebCore/css/CSSValueList.cpp

    r76966 r92106  
    4747}
    4848
    49 CSSValue* CSSValueList::item(unsigned index)
    50 {
    51     if (index >= m_values.size())
    52         return 0;
    53     return m_values[index].get();
    54 }
    55 
    5649unsigned short CSSValueList::cssValueType() const
    5750{
     
    9992    PassRefPtr<CSSValueList> newList = m_isSpaceSeparated ? createSpaceSeparated() : createCommaSeparated();
    10093    for (size_t index = 0; index < m_values.size(); index++)
    101         newList->append(item(index));
     94        newList->append(m_values[index]);
    10295    return newList;
    10396}
  • trunk/Source/WebCore/css/CSSValueList.h

    r76966 r92106  
    4848
    4949    size_t length() const { return m_values.size(); }
    50     CSSValue* item(unsigned);
    51     CSSValue* itemWithoutBoundsCheck(unsigned index) { return m_values[index].get(); }
     50    CSSValue* item(size_t index) { return index < m_values.size() ? m_values[index].get() : 0; }
     51    CSSValue* itemWithoutBoundsCheck(size_t index) { return m_values[index].get(); }
    5252
    5353    void append(PassRefPtr<CSSValue>);
     
    7474};
    7575
     76// Objects of this class are intended to be stack-allocated and scoped to a single function.
     77// Please take care not to pass these around as they do hold onto a raw pointer.
     78class CSSValueListInspector {
     79public:
     80    CSSValueListInspector(CSSValue* value) : m_list((value && value->isValueList()) ? static_cast<CSSValueList*>(value) : 0) { }
     81    CSSValue* item(size_t index) const { ASSERT(index < length()); return m_list->itemWithoutBoundsCheck(index); }
     82    CSSValue* first() const { return item(0); }
     83    CSSValue* second() const { return item(1); }
     84    size_t length() const { return m_list ? m_list->length() : 0; }
     85private:
     86    CSSValueList* m_list;
     87};
     88
     89// Wrapper that can be used to iterate over any CSSValue. Non-list values and 0 behave as zero-length lists.
     90// Objects of this class are intended to be stack-allocated and scoped to a single function.
     91// Please take care not to pass these around as they do hold onto a raw pointer.
     92class CSSValueListIterator {
     93public:
     94    CSSValueListIterator(CSSValue* value) : m_inspector(value), m_position(0) { }
     95    bool hasMore() const { return m_position < m_inspector.length(); }
     96    CSSValue* value() const { return m_inspector.item(m_position); }
     97    void advance() { m_position++; ASSERT(m_position <= m_inspector.length());}
     98    size_t index() const { return m_position; }
     99private:
     100    CSSValueListInspector m_inspector;
     101    size_t m_position;
     102};
    76103} // namespace WebCore
    77104
Note: See TracChangeset for help on using the changeset viewer.