Source/WebCore/ChangeLog

 12011-07-27 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 NOBODY (OOPS!).
 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 class definition.
 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::CSSValueListIterator::length):
 35 Return the size of the underlying list.
 36 (WebCore::CSSValueListExpander::first):
 37 Return the first item in the list.
 38 (WebCore::CSSValueListExpander::second):
 39 Return the second item in the list.
 40 (WebCore::CSSValueListExpander::length):
 41 Return the size of the underlying list.
 42
1432011-07-27 Fady Samuel <fsamuel@chromium.org>
244
345 Popups on Chromium now check the minimum row height set through the Chromium WebKit API when
91897

Source/WebCore/css/CSSPrimitiveValue.h

@@public:
119119 static bool isUnitTypeLength(int type) { return (type > CSSPrimitiveValue::CSS_PERCENTAGE && type < CSSPrimitiveValue::CSS_DEG) ||
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)); }
124126 static PassRefPtr<CSSPrimitiveValue> create(double value, UnitTypes type) { return adoptRef(new CSSPrimitiveValue(value, type)); }
91897

Source/WebCore/css/CSSStyleSelector.cpp

@@AnimationList* list = m_style->accessAni
191191size_t childIndex = 0; \
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 } \
201200} else { \

@@AnimationList* list = m_style->accessTra
241240size_t childIndex = 0; \
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 } \
251249} else { \

@@void CSSStyleSelector::applyProperty(int
40184016 if (!value->isValueList())
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 CSSValueListExpander expander = value;
 4021 if (expander.length() == 1 && expander.first()->isPrimitiveValue()) {
 4022 CSSPrimitiveValue* contentValue = static_cast<CSSPrimitiveValue*>(expander->first());
40274023 if (contentValue->primitiveType() == CSSPrimitiveValue::CSS_FROM_FLOW) {
40284024 m_style->setRegionThread(contentValue->getStringValue().impl());
40294025 return;

@@void CSSStyleSelector::applyProperty(int
40324028#endif
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);
40394035 didSet = true;

@@void CSSStyleSelector::applyProperty(int
41164112 }
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));
41324127 } else if (primitiveValue) {

@@void CSSStyleSelector::applyProperty(int
41624157 if (!value->isValueList())
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;
41784171 CSSPrimitiveValue* contentValue = static_cast<CSSPrimitiveValue*>(item);

@@void CSSStyleSelector::applyProperty(int
42484241 } else {
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;
42584249 primitiveValue = static_cast<CSSPrimitiveValue*>(item);

@@void CSSStyleSelector::applyProperty(int
44534444 if (!value->isValueList())
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);
44654454 int blur = item->blur ? item->blur->computeLength<int>(style(), m_rootElementStyle, zoomFactor) : 0;

@@void CSSStyleSelector::applyProperty(int
44704459 color = getColorFromPrimitiveValue(item->color.get());
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;
44784467 }

@@void CSSStyleSelector::applyProperty(int
52855274void CSSStyleSelector::applyPageSizeProperty(CSSValue* value)
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 CSSValueListExpander expander = value;
 5281 switch (expander.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 (!expander.first()->isPrimitiveValue() || !expander.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*>(expander.first());
 5288 CSSPrimitiveValue* second = static_cast<CSSPrimitiveValue*>(expander.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 }
53165301 break;
53175302 }
53185303 case 1: {
53195304 // <length> | auto | <page-size> | [ portrait | landscape]
5320  if (!valueList->item(0)->isPrimitiveValue())
 5305 if (!expander.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*>(expander.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()) {
53325316 case CSSValueAuto:

@@bool CSSStyleSelector::createTransformOp
62806264
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;
62936275
91897

Source/WebCore/css/CSSValueList.cpp

@@CSSValueList::~CSSValueList()
4646{
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{
5851 return CSS_VALUE_LIST;

@@PassRefPtr<CSSValueList> CSSValueList::c
9891{
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}
10497
91897

Source/WebCore/css/CSSValueList.h

@@public:
4747 virtual ~CSSValueList();
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>);
5454 void prepend(PassRefPtr<CSSValue>);

@@private:
7373 bool m_isSpaceSeparated;
7474};
7575
 76// Wrapper that can be used to iterate over any CSSValue. Non-list values and 0 behave as zero-length lists.
 77class CSSValueListIterator {
 78public:
 79 CSSValueListIterator(CSSValue* value) : m_position(0) { m_list = (value && value->isValueList()) ? static_cast<CSSValueList*>(value) : 0; }
 80 bool hasMore() const { return m_position < length(); }
 81 CSSValue* value() const { ASSERT(hasMore()); return m_list->itemWithoutBoundsCheck(m_position); }
 82 void advance() { m_position++; ASSERT(m_position <= length());}
 83 size_t index() const { return m_position; }
 84 size_t length() const { return m_list ? m_list->length() : 0; }
 85private:
 86 CSSValueList* m_list;
 87 size_t m_position;
 88};
 89
 90class CSSValueListExpander {
 91public:
 92 CSSValueListExpander(CSSValue* value) { m_list = (value && value->isValueList()) ? static_cast<CSSValueList*>(value) : 0; }
 93 CSSValue* first() const { ASSERT(length() > 0); return m_list->itemWithoutBoundsCheck(0); }
 94 CSSValue* second() const { ASSERT(length() > 1); return m_list->itemWithoutBoundsCheck(1); }
 95 size_t length() const { return m_list ? m_list->length() : 0; }
 96private:
 97 CSSValueList* m_list;
 98};
7699} // namespace WebCore
77100
78101#endif // CSSValueList_h
91897