Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(635)

Side by Side Diff: third_party/WebKit/Source/core/css/StylePropertySerializer.cpp

Issue 2228313002: Make a function to query whether a CSSPropertyID is valid and whether it has a name. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@asan
Patch Set: Revert incorrect changes Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * (C) 1999-2003 Lars Knoll (knoll@kde.org) 2 * (C) 1999-2003 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012 Apple Inc. All r ights reserved. 3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012 Apple Inc. All r ights reserved.
4 * Copyright (C) 2011 Research In Motion Limited. All rights reserved. 4 * Copyright (C) 2011 Research In Motion Limited. All rights reserved.
5 * Copyright (C) 2013 Intel Corporation. All rights reserved. 5 * Copyright (C) 2013 Intel Corporation. All rights reserved.
6 * 6 *
7 * This library is free software; you can redistribute it and/or 7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public 8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either 9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version. 10 * version 2 of the License, or (at your option) any later version.
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 if (CSSProperty::isAffectedByAllProperty(property.id())) { 48 if (CSSProperty::isAffectedByAllProperty(property.id())) {
49 if (allProperty.isImportant() && !property.isImportant()) 49 if (allProperty.isImportant() && !property.isImportant())
50 continue; 50 continue;
51 if (static_cast<unsigned>(m_allIndex) >= i) 51 if (static_cast<unsigned>(m_allIndex) >= i)
52 continue; 52 continue;
53 if (property.value().equals(allProperty.value()) 53 if (property.value().equals(allProperty.value())
54 && property.isImportant() == allProperty.isImportant()) 54 && property.isImportant() == allProperty.isImportant())
55 continue; 55 continue;
56 m_needToExpandAll = true; 56 m_needToExpandAll = true;
57 } 57 }
58 if (property.id() < firstCSSProperty || property.id() > lastCSSProperty) 58 if (!isPropertyIDWithName(property.id()))
59 continue; 59 continue;
60 m_longhandPropertyUsed.set(property.id() - firstCSSProperty); 60 m_longhandPropertyUsed.set(property.id() - firstCSSProperty);
61 } 61 }
62 } 62 }
63 63
64 DEFINE_TRACE(StylePropertySerializer::StylePropertySetForSerializer) 64 DEFINE_TRACE(StylePropertySerializer::StylePropertySetForSerializer)
65 { 65 {
66 visitor->trace(m_propertySet); 66 visitor->trace(m_propertySet);
67 } 67 }
68 68
69 unsigned StylePropertySerializer::StylePropertySetForSerializer::propertyCount() const 69 unsigned StylePropertySerializer::StylePropertySetForSerializer::propertyCount() const
70 { 70 {
71 if (!hasExpandedAllProperty()) 71 if (!hasExpandedAllProperty())
72 return m_propertySet->propertyCount(); 72 return m_propertySet->propertyCount();
73 return lastCSSProperty - firstCSSProperty + 1; 73 return lastCSSProperty - firstCSSProperty + 1;
74 } 74 }
75 75
76 StylePropertySerializer::PropertyValueForSerializer StylePropertySerializer::Sty lePropertySetForSerializer::propertyAt(unsigned index) const 76 StylePropertySerializer::PropertyValueForSerializer StylePropertySerializer::Sty lePropertySetForSerializer::propertyAt(unsigned index) const
77 { 77 {
78 if (!hasExpandedAllProperty()) 78 if (!hasExpandedAllProperty())
79 return StylePropertySerializer::PropertyValueForSerializer(m_propertySet ->propertyAt(index)); 79 return StylePropertySerializer::PropertyValueForSerializer(m_propertySet ->propertyAt(index));
80 80
81 CSSPropertyID propertyID = static_cast<CSSPropertyID>(index + firstCSSProper ty); 81 CSSPropertyID propertyID = static_cast<CSSPropertyID>(index + firstCSSProper ty);
82 ASSERT(firstCSSProperty <= propertyID && propertyID <= lastCSSProperty); 82 DCHECK(isPropertyIDWithName(propertyID));
83 if (m_longhandPropertyUsed.test(index)) { 83 if (m_longhandPropertyUsed.test(index)) {
84 int index = m_propertySet->findPropertyIndex(propertyID); 84 int index = m_propertySet->findPropertyIndex(propertyID);
85 ASSERT(index != -1); 85 DCHECK_NE(index, -1);
86 return StylePropertySerializer::PropertyValueForSerializer(m_propertySet ->propertyAt(index)); 86 return StylePropertySerializer::PropertyValueForSerializer(m_propertySet ->propertyAt(index));
87 } 87 }
88 88
89 StylePropertySet::PropertyReference property = m_propertySet->propertyAt(m_a llIndex); 89 StylePropertySet::PropertyReference property = m_propertySet->propertyAt(m_a llIndex);
90 return StylePropertySerializer::PropertyValueForSerializer(propertyID, &prop erty.value(), property.isImportant()); 90 return StylePropertySerializer::PropertyValueForSerializer(propertyID, &prop erty.value(), property.isImportant());
91 } 91 }
92 92
93 bool StylePropertySerializer::StylePropertySetForSerializer::shouldProcessProper tyAt(unsigned index) const 93 bool StylePropertySerializer::StylePropertySetForSerializer::shouldProcessProper tyAt(unsigned index) const
94 { 94 {
95 // StylePropertySet has all valid longhands. We should process. 95 // StylePropertySet has all valid longhands. We should process.
96 if (!hasAllProperty()) 96 if (!hasAllProperty())
97 return true; 97 return true;
98 98
99 // If all is not expanded, we need to process "all" and properties which 99 // If all is not expanded, we need to process "all" and properties which
100 // are not overwritten by "all". 100 // are not overwritten by "all".
101 if (!m_needToExpandAll) { 101 if (!m_needToExpandAll) {
102 StylePropertySet::PropertyReference property = m_propertySet->propertyAt (index); 102 StylePropertySet::PropertyReference property = m_propertySet->propertyAt (index);
103 if (property.id() == CSSPropertyAll || !CSSProperty::isAffectedByAllProp erty(property.id())) 103 if (property.id() == CSSPropertyAll || !CSSProperty::isAffectedByAllProp erty(property.id()))
104 return true; 104 return true;
105 if (property.id() < firstCSSProperty || property.id() > lastCSSProperty) 105 if (!isPropertyIDWithName(property.id()))
106 return false; 106 return false;
107 return m_longhandPropertyUsed.test(property.id() - firstCSSProperty); 107 return m_longhandPropertyUsed.test(property.id() - firstCSSProperty);
108 } 108 }
109 109
110 CSSPropertyID propertyID = static_cast<CSSPropertyID>(index + firstCSSProper ty); 110 CSSPropertyID propertyID = static_cast<CSSPropertyID>(index + firstCSSProper ty);
111 ASSERT(firstCSSProperty <= propertyID && propertyID <= lastCSSProperty); 111 DCHECK(isPropertyIDWithName(propertyID));
112 112
113 // Since "all" is expanded, we don't need to process "all". 113 // Since "all" is expanded, we don't need to process "all".
114 // We should not process expanded shorthands (e.g. font, background, 114 // We should not process expanded shorthands (e.g. font, background,
115 // and so on) either. 115 // and so on) either.
116 if (isShorthandProperty(propertyID) || propertyID == CSSPropertyAll) 116 if (isShorthandProperty(propertyID) || propertyID == CSSPropertyAll)
117 return false; 117 return false;
118 118
119 // The all property is a shorthand that resets all CSS properties except 119 // The all property is a shorthand that resets all CSS properties except
120 // direction and unicode-bidi. It only accepts the CSS-wide keywords. 120 // direction and unicode-bidi. It only accepts the CSS-wide keywords.
121 // c.f. http://dev.w3.org/csswg/css-cascade/#all-shorthand 121 // c.f. http://dev.w3.org/csswg/css-cascade/#all-shorthand
(...skipping 28 matching lines...) Expand all
150 return value.isImplicit(); 150 return value.isImplicit();
151 } 151 }
152 152
153 StylePropertySerializer::StylePropertySerializer(const StylePropertySet& propert ies) 153 StylePropertySerializer::StylePropertySerializer(const StylePropertySet& propert ies)
154 : m_propertySet(properties) 154 : m_propertySet(properties)
155 { 155 {
156 } 156 }
157 157
158 String StylePropertySerializer::getCustomPropertyText(const PropertyValueForSeri alizer& property, bool isNotFirstDecl) const 158 String StylePropertySerializer::getCustomPropertyText(const PropertyValueForSeri alizer& property, bool isNotFirstDecl) const
159 { 159 {
160 ASSERT(property.id() == CSSPropertyVariable); 160 DCHECK_EQ(property.id(), CSSPropertyVariable);
161 StringBuilder result; 161 StringBuilder result;
162 if (isNotFirstDecl) 162 if (isNotFirstDecl)
163 result.append(' '); 163 result.append(' ');
164 const CSSCustomPropertyDeclaration* value = toCSSCustomPropertyDeclaration(p roperty.value()); 164 const CSSCustomPropertyDeclaration* value = toCSSCustomPropertyDeclaration(p roperty.value());
165 result.append(value->name()); 165 result.append(value->name());
166 result.append(':'); 166 result.append(':');
167 if (!value->value()) 167 if (!value->value())
168 result.append(' '); 168 result.append(' ');
169 result.append(value->customCSSText()); 169 result.append(value->customCSSText());
170 if (property.isImportant()) 170 if (property.isImportant())
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 207
208 unsigned size = m_propertySet.propertyCount(); 208 unsigned size = m_propertySet.propertyCount();
209 unsigned numDecls = 0; 209 unsigned numDecls = 0;
210 for (unsigned n = 0; n < size; ++n) { 210 for (unsigned n = 0; n < size; ++n) {
211 if (!m_propertySet.shouldProcessPropertyAt(n)) 211 if (!m_propertySet.shouldProcessPropertyAt(n))
212 continue; 212 continue;
213 213
214 StylePropertySerializer::PropertyValueForSerializer property = m_propert ySet.propertyAt(n); 214 StylePropertySerializer::PropertyValueForSerializer property = m_propert ySet.propertyAt(n);
215 CSSPropertyID propertyID = property.id(); 215 CSSPropertyID propertyID = property.id();
216 // Only enabled properties should be part of the style. 216 // Only enabled properties should be part of the style.
217 ASSERT(CSSPropertyMetadata::isEnabledProperty(propertyID)); 217 DCHECK(CSSPropertyMetadata::isEnabledProperty(propertyID));
218 // Shorthands with variable references are not expanded at parse time 218 // Shorthands with variable references are not expanded at parse time
219 // and hence may still be observed during serialization. 219 // and hence may still be observed during serialization.
220 ASSERT(!isShorthandProperty(propertyID) || property.value()->isVariableR eferenceValue()); 220 DCHECK(!isShorthandProperty(propertyID) || property.value()->isVariableR eferenceValue());
221 221
222 switch (propertyID) { 222 switch (propertyID) {
223 case CSSPropertyVariable: 223 case CSSPropertyVariable:
224 result.append(getCustomPropertyText(property, numDecls++)); 224 result.append(getCustomPropertyText(property, numDecls++));
225 continue; 225 continue;
226 case CSSPropertyAll: 226 case CSSPropertyAll:
227 result.append(getPropertyText(propertyID, property.value()->cssText( ), property.isImportant(), numDecls++)); 227 result.append(getPropertyText(propertyID, property.value()->cssText( ), property.isImportant(), numDecls++));
228 continue; 228 continue;
229 case CSSPropertyApplyAtRule: 229 case CSSPropertyApplyAtRule:
230 result.append(getApplyAtRuleText(property.value(), numDecls++)); 230 result.append(getApplyAtRuleText(property.value(), numDecls++));
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 longhandSerialized.set(shorthand.properties()[i] - firstCSSPrope rty); 276 longhandSerialized.set(shorthand.properties()[i] - firstCSSPrope rty);
277 break; 277 break;
278 } 278 }
279 279
280 if (serializedAsShorthand) 280 if (serializedAsShorthand)
281 continue; 281 continue;
282 282
283 result.append(getPropertyText(propertyID, property.value()->cssText(), p roperty.isImportant(), numDecls++)); 283 result.append(getPropertyText(propertyID, property.value()->cssText(), p roperty.isImportant(), numDecls++));
284 } 284 }
285 285
286 ASSERT(!numDecls ^ !result.isEmpty()); 286 DCHECK(!numDecls ^ !result.isEmpty());
287 return result.toString(); 287 return result.toString();
288 } 288 }
289 289
290 // As per css-cascade, shorthands do not expand longhands to the value 290 // As per css-cascade, shorthands do not expand longhands to the value
291 // "initial", except when the shorthand is set to "initial", instead 291 // "initial", except when the shorthand is set to "initial", instead
292 // setting "missing" sub-properties to their initial values. This means 292 // setting "missing" sub-properties to their initial values. This means
293 // that a shorthand can never represent a list of subproperties where 293 // that a shorthand can never represent a list of subproperties where
294 // some are "initial" and some are not, and so serialization should 294 // some are "initial" and some are not, and so serialization should
295 // always fail in these cases (as per cssom). However we currently use 295 // always fail in these cases (as per cssom). However we currently use
296 // "initial" instead of the initial values for certain shorthands, so 296 // "initial" instead of the initial values for certain shorthands, so
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 String horizontalValueCSSText = horizontalValue->cssText(); 498 String horizontalValueCSSText = horizontalValue->cssText();
499 String verticalValueCSSText = verticalValue->cssText(); 499 String verticalValueCSSText = verticalValue->cssText();
500 if (horizontalValueCSSText == verticalValueCSSText) 500 if (horizontalValueCSSText == verticalValueCSSText)
501 return horizontalValueCSSText; 501 return horizontalValueCSSText;
502 return horizontalValueCSSText + ' ' + verticalValueCSSText; 502 return horizontalValueCSSText + ' ' + verticalValueCSSText;
503 } 503 }
504 504
505 void StylePropertySerializer::appendFontLonghandValueIfNotNormal(CSSPropertyID p ropertyID, StringBuilder& result) const 505 void StylePropertySerializer::appendFontLonghandValueIfNotNormal(CSSPropertyID p ropertyID, StringBuilder& result) const
506 { 506 {
507 int foundPropertyIndex = m_propertySet.findPropertyIndex(propertyID); 507 int foundPropertyIndex = m_propertySet.findPropertyIndex(propertyID);
508 ASSERT(foundPropertyIndex != -1); 508 DCHECK_NE(foundPropertyIndex, -1);
509 509
510 const CSSValue* val = m_propertySet.propertyAt(foundPropertyIndex).value(); 510 const CSSValue* val = m_propertySet.propertyAt(foundPropertyIndex).value();
511 if (val->isPrimitiveValue() && toCSSPrimitiveValue(val)->getValueID() == CSS ValueNormal) 511 if (val->isPrimitiveValue() && toCSSPrimitiveValue(val)->getValueID() == CSS ValueNormal)
512 return; 512 return;
513 513
514 char prefix = '\0'; 514 char prefix = '\0';
515 switch (propertyID) { 515 switch (propertyID) {
516 case CSSPropertyFontStyle: 516 case CSSPropertyFontStyle:
517 break; // No prefix. 517 break; // No prefix.
518 case CSSPropertyFontFamily: 518 case CSSPropertyFontFamily:
519 case CSSPropertyFontStretch: 519 case CSSPropertyFontStretch:
520 case CSSPropertyFontVariantCaps: 520 case CSSPropertyFontVariantCaps:
521 case CSSPropertyFontVariantLigatures: 521 case CSSPropertyFontVariantLigatures:
522 case CSSPropertyFontVariantNumeric: 522 case CSSPropertyFontVariantNumeric:
523 case CSSPropertyFontWeight: 523 case CSSPropertyFontWeight:
524 prefix = ' '; 524 prefix = ' ';
525 break; 525 break;
526 case CSSPropertyLineHeight: 526 case CSSPropertyLineHeight:
527 prefix = '/'; 527 prefix = '/';
528 break; 528 break;
529 default: 529 default:
530 ASSERT_NOT_REACHED(); 530 NOTREACHED();
531 } 531 }
532 532
533 if (prefix && !result.isEmpty()) 533 if (prefix && !result.isEmpty())
534 result.append(prefix); 534 result.append(prefix);
535 535
536 String value; 536 String value;
537 // In the font-variant shorthand a "none" ligatures value needs to be expand ed. 537 // In the font-variant shorthand a "none" ligatures value needs to be expand ed.
538 if (propertyID == CSSPropertyFontVariantLigatures 538 if (propertyID == CSSPropertyFontVariantLigatures
539 && val->isPrimitiveValue() 539 && val->isPrimitiveValue()
540 && toCSSPrimitiveValue(val)->getValueID() == CSSValueNone) { 540 && toCSSPrimitiveValue(val)->getValueID() == CSSValueNone) {
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
697 // Background color belongs in the last layer. 697 // Background color belongs in the last layer.
698 value = values[propertyIndex]; 698 value = values[propertyIndex];
699 } 699 }
700 // No point proceeding if there's not a value to look at. 700 // No point proceeding if there's not a value to look at.
701 if (!value) 701 if (!value)
702 continue; 702 continue;
703 703
704 // Special case for background-repeat. 704 // Special case for background-repeat.
705 if ((propertyIndex < size - 1 && m_propertySet.isPropertyImplicit(pr operty)) 705 if ((propertyIndex < size - 1 && m_propertySet.isPropertyImplicit(pr operty))
706 && (property == CSSPropertyBackgroundRepeatX || property == CSSP ropertyWebkitMaskRepeatX)) { 706 && (property == CSSPropertyBackgroundRepeatX || property == CSSP ropertyWebkitMaskRepeatX)) {
707 ASSERT(shorthand.properties()[propertyIndex + 1] == CSSPropertyB ackgroundRepeatY 707 DCHECK(shorthand.properties()[propertyIndex + 1] == CSSPropertyB ackgroundRepeatY
708 || shorthand.properties()[propertyIndex + 1] == CSSPropertyW ebkitMaskRepeatY); 708 || shorthand.properties()[propertyIndex + 1] == CSSPropertyW ebkitMaskRepeatY);
709 const CSSValue& yValue = values[propertyIndex + 1]->isValueList( ) ? 709 const CSSValue& yValue = values[propertyIndex + 1]->isValueList( ) ?
710 toCSSValueList(values[propertyIndex + 1])->item(layer) : *va lues[propertyIndex + 1]; 710 toCSSValueList(values[propertyIndex + 1])->item(layer) : *va lues[propertyIndex + 1];
711 711
712 712
713 // FIXME: At some point we need to fix this code to avoid return ing an invalid shorthand, 713 // FIXME: At some point we need to fix this code to avoid return ing an invalid shorthand,
714 // since some longhand combinations are not serializable into a single shorthand. 714 // since some longhand combinations are not serializable into a single shorthand.
715 if (!value->isPrimitiveValue() || !yValue.isPrimitiveValue()) 715 if (!value->isPrimitiveValue() || !yValue.isPrimitiveValue())
716 continue; 716 continue;
717 717
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
870 builder.append(", "); 870 builder.append(", ");
871 871
872 const CSSValue& xValue = repeatXList ? repeatXList->item(i % repeatXList ->length()) : repeatX; 872 const CSSValue& xValue = repeatXList ? repeatXList->item(i % repeatXList ->length()) : repeatX;
873 const CSSValue& yValue = repeatYList ? repeatYList->item(i % repeatYList ->length()) : repeatY; 873 const CSSValue& yValue = repeatYList ? repeatYList->item(i % repeatYList ->length()) : repeatY;
874 appendBackgroundRepeatValue(builder, xValue, yValue); 874 appendBackgroundRepeatValue(builder, xValue, yValue);
875 } 875 }
876 return builder.toString(); 876 return builder.toString();
877 } 877 }
878 878
879 } // namespace blink 879 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698