Changeset 92106 in webkit
- Timestamp:
- Aug 1, 2011, 1:31:43 AM (15 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 5 edited
-
ChangeLog (modified) (1 diff)
-
css/CSSPrimitiveValue.h (modified) (1 diff)
-
css/CSSStyleSelector.cpp (modified) (12 diffs)
-
css/CSSValueList.cpp (modified) (2 diffs)
-
css/CSSValueList.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r92105 r92106 1 2011-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 1 43 2011-08-01 Pavel Feldman <pfeldman@google.com> 2 44 -
trunk/Source/WebCore/css/CSSPrimitiveValue.h
r91969 r92106 120 120 type == CSSPrimitiveValue::CSS_REMS; } 121 121 122 bool isLength() const { return isUnitTypeLength(m_type); } 123 122 124 static PassRefPtr<CSSPrimitiveValue> createIdentifier(int identifier) { return adoptRef(new CSSPrimitiveValue(identifier)); } 123 125 static PassRefPtr<CSSPrimitiveValue> createColor(unsigned rgbValue) { return adoptRef(new CSSPrimitiveValue(rgbValue)); } -
trunk/Source/WebCore/css/CSSStyleSelector.cpp
r91969 r92106 192 192 if (value->isValueList()) { \ 193 193 /* 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()) { \ 196 195 if (childIndex <= list->size()) \ 197 196 list->append(Animation::create()); \ 198 mapAnimation##Prop(list->animation(childIndex), valueList->itemWithoutBoundsCheck(i)); \197 mapAnimation##Prop(list->animation(childIndex), i.value()); \ 199 198 ++childIndex; \ 200 199 } \ … … 242 241 if (value->isValueList()) { \ 243 242 /* 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()) { \ 246 244 if (childIndex <= list->size()) \ 247 245 list->append(Animation::create()); \ 248 mapAnimation##Prop(list->animation(childIndex), valueList->itemWithoutBoundsCheck(i)); \246 mapAnimation##Prop(list->animation(childIndex), i.value()); \ 249 247 ++childIndex; \ 250 248 } \ … … 4019 4017 return; 4020 4018 4021 CSSValueList* list = static_cast<CSSValueList*>(value);4022 int len = list->length();4023 4024 4019 #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()); 4027 4023 if (contentValue->primitiveType() == CSSPrimitiveValue::CSS_FROM_FLOW) { 4028 4024 m_style->setRegionThread(contentValue->getStringValue().impl()); … … 4033 4029 4034 4030 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(); 4037 4033 if (item->isImageGeneratorValue()) { 4038 4034 m_style->setContent(static_cast<CSSImageGeneratorValue*>(item)->generatedImage(), didSet); … … 4117 4113 if (value->isValueList()) { 4118 4114 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()); 4121 4116 if (!data) 4122 4117 return; // Out of memory 4123 4118 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(); 4126 4121 ASSERT(item->isPrimitiveValue()); 4127 4122 primitiveValue = static_cast<CSSPrimitiveValue*>(item); 4128 4123 ASSERT(primitiveValue->primitiveType() == CSSPrimitiveValue::CSS_STRING); 4129 quotes[i ] = primitiveValue->getStringValue();4124 quotes[i.index()] = primitiveValue->getStringValue(); 4130 4125 } 4131 4126 m_style->setQuotes(adoptRef(data)); … … 4163 4158 return; 4164 4159 FontDescription fontDescription = m_style->fontDescription(); 4165 CSSValueList* list = static_cast<CSSValueList*>(value);4166 int len = list->length();4167 4160 FontFamily& firstFamily = fontDescription.firstFamily(); 4168 4161 FontFamily* currFamily = 0; 4169 4162 4170 4163 // Before mapping in a new font-family property, we should reset the generic family. 4171 4164 bool oldFamilyUsedFixedDefaultSize = fontDescription.useFixedDefaultSize(); 4172 4165 fontDescription.setGenericFamily(FontDescription::NoFamily); 4173 4166 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(); 4176 4169 if (!item->isPrimitiveValue()) 4177 4170 continue; … … 4249 4242 if (!value->isValueList()) 4250 4243 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()) 4254 4245 { 4255 CSSValue *item = list->itemWithoutBoundsCheck(i);4246 CSSValue* item = i.value(); 4256 4247 if (!item->isPrimitiveValue()) 4257 4248 continue; … … 4454 4445 return; 4455 4446 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(); 4460 4449 if (!currValue->isShadowValue()) 4461 4450 continue; 4462 ShadowValue* item = static_cast<ShadowValue*>( list->itemWithoutBoundsCheck(i));4451 ShadowValue* item = static_cast<ShadowValue*>(currValue); 4463 4452 int x = item->x->computeLength<int>(style(), m_rootElementStyle, zoomFactor); 4464 4453 int y = item->y->computeLength<int>(style(), m_rootElementStyle, zoomFactor); … … 4471 4460 OwnPtr<ShadowData> shadowData = adoptPtr(new ShadowData(x, y, blur, spread, shadowStyle, id == CSSPropertyWebkitBoxShadow, color.isValid() ? color : Color::transparent)); 4472 4461 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 4474 4463 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 4476 4465 } 4477 4466 return; … … 5286 5275 { 5287 5276 m_style->resetPageSizeType(); 5288 if (!value->isValueList())5289 return;5290 CSSValueList* valueList = static_cast<CSSValueList*>(value);5291 5277 Length width; 5292 5278 Length height; 5293 5279 PageSizeType pageSizeType = PAGE_SIZE_AUTO; 5294 switch (valueList->length()) { 5280 CSSValueListInspector inspector = value; 5281 switch (inspector.length()) { 5295 5282 case 2: { 5296 5283 // <length>{2} | <page-size> <orientation> 5297 5284 pageSizeType = PAGE_SIZE_RESOLVED; 5298 if (! valueList->item(0)->isPrimitiveValue() || !valueList->item(1)->isPrimitiveValue())5285 if (!inspector.first()->isPrimitiveValue() || !inspector.second()->isPrimitiveValue()) 5299 5286 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()) { 5305 5290 // <length>{2} 5306 if (! CSSPrimitiveValue::isUnitTypeLength(type1))5291 if (!second->isLength()) 5307 5292 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); 5310 5295 } else { 5311 5296 // <page-size> <orientation> 5312 5297 // The value order is guaranteed. See CSSParser::parseSizeParameter. 5313 if (!pageSizeFromName( primitiveValue0, primitiveValue1, width, height))5298 if (!pageSizeFromName(first, second, width, height)) 5314 5299 return; 5315 5300 } … … 5318 5303 case 1: { 5319 5304 // <length> | auto | <page-size> | [ portrait | landscape] 5320 if (! valueList->item(0)->isPrimitiveValue())5305 if (!inspector.first()->isPrimitiveValue()) 5321 5306 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()) { 5325 5309 // <length> 5326 5310 pageSizeType = PAGE_SIZE_RESOLVED; 5327 5311 width = height = primitiveValue->computeLength<Length>(style(), m_rootElementStyle); 5328 5312 } else { 5329 if ( type!= CSSPrimitiveValue::CSS_IDENT)5313 if (primitiveValue->primitiveType() != CSSPrimitiveValue::CSS_IDENT) 5330 5314 return; 5331 5315 switch (primitiveValue->getIdent()) { … … 6281 6265 float zoomFactor = style ? style->effectiveZoom() : 1; 6282 6266 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(); 6287 6269 if (!currValue->isWebKitCSSTransformValue()) 6288 6270 continue; 6289 6271 6290 WebKitCSSTransformValue* transformValue = static_cast<WebKitCSSTransformValue*>( list->itemWithoutBoundsCheck(i));6272 WebKitCSSTransformValue* transformValue = static_cast<WebKitCSSTransformValue*>(i.value()); 6291 6273 if (!transformValue->length()) 6292 6274 continue; -
trunk/Source/WebCore/css/CSSValueList.cpp
r76966 r92106 47 47 } 48 48 49 CSSValue* CSSValueList::item(unsigned index)50 {51 if (index >= m_values.size())52 return 0;53 return m_values[index].get();54 }55 56 49 unsigned short CSSValueList::cssValueType() const 57 50 { … … 99 92 PassRefPtr<CSSValueList> newList = m_isSpaceSeparated ? createSpaceSeparated() : createCommaSeparated(); 100 93 for (size_t index = 0; index < m_values.size(); index++) 101 newList->append( item(index));94 newList->append(m_values[index]); 102 95 return newList; 103 96 } -
trunk/Source/WebCore/css/CSSValueList.h
r76966 r92106 48 48 49 49 size_t length() const { return m_values.size(); } 50 CSSValue* item( unsigned);51 CSSValue* itemWithoutBoundsCheck( unsignedindex) { 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(); } 52 52 53 53 void append(PassRefPtr<CSSValue>); … … 74 74 }; 75 75 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. 78 class CSSValueListInspector { 79 public: 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; } 85 private: 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. 92 class CSSValueListIterator { 93 public: 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; } 99 private: 100 CSSValueListInspector m_inspector; 101 size_t m_position; 102 }; 76 103 } // namespace WebCore 77 104
Note:
See TracChangeset
for help on using the changeset viewer.