| OLD | NEW |
| 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 Loading... |
| 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 (!propertyHasName(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(propertyHasName(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 (!propertyHasName(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(propertyHasName(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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 return value.isImportant(); | 170 return value.isImportant(); |
| 171 } | 171 } |
| 172 | 172 |
| 173 StylePropertySerializer::StylePropertySerializer(const StylePropertySet& propert
ies) | 173 StylePropertySerializer::StylePropertySerializer(const StylePropertySet& propert
ies) |
| 174 : m_propertySet(properties) | 174 : m_propertySet(properties) |
| 175 { | 175 { |
| 176 } | 176 } |
| 177 | 177 |
| 178 String StylePropertySerializer::getCustomPropertyText(const PropertyValueForSeri
alizer& property, bool isNotFirstDecl) const | 178 String StylePropertySerializer::getCustomPropertyText(const PropertyValueForSeri
alizer& property, bool isNotFirstDecl) const |
| 179 { | 179 { |
| 180 ASSERT(property.id() == CSSPropertyVariable); | 180 DCHECK_EQ(property.id(), CSSPropertyVariable); |
| 181 StringBuilder result; | 181 StringBuilder result; |
| 182 if (isNotFirstDecl) | 182 if (isNotFirstDecl) |
| 183 result.append(' '); | 183 result.append(' '); |
| 184 const CSSCustomPropertyDeclaration* value = toCSSCustomPropertyDeclaration(p
roperty.value()); | 184 const CSSCustomPropertyDeclaration* value = toCSSCustomPropertyDeclaration(p
roperty.value()); |
| 185 result.append(value->name()); | 185 result.append(value->name()); |
| 186 result.append(':'); | 186 result.append(':'); |
| 187 if (!value->value()) | 187 if (!value->value()) |
| 188 result.append(' '); | 188 result.append(' '); |
| 189 result.append(value->customCSSText()); | 189 result.append(value->customCSSText()); |
| 190 if (property.isImportant()) | 190 if (property.isImportant()) |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 | 227 |
| 228 unsigned size = m_propertySet.propertyCount(); | 228 unsigned size = m_propertySet.propertyCount(); |
| 229 unsigned numDecls = 0; | 229 unsigned numDecls = 0; |
| 230 for (unsigned n = 0; n < size; ++n) { | 230 for (unsigned n = 0; n < size; ++n) { |
| 231 if (!m_propertySet.shouldProcessPropertyAt(n)) | 231 if (!m_propertySet.shouldProcessPropertyAt(n)) |
| 232 continue; | 232 continue; |
| 233 | 233 |
| 234 StylePropertySerializer::PropertyValueForSerializer property = m_propert
ySet.propertyAt(n); | 234 StylePropertySerializer::PropertyValueForSerializer property = m_propert
ySet.propertyAt(n); |
| 235 CSSPropertyID propertyID = property.id(); | 235 CSSPropertyID propertyID = property.id(); |
| 236 // Only enabled properties should be part of the style. | 236 // Only enabled properties should be part of the style. |
| 237 ASSERT(CSSPropertyMetadata::isEnabledProperty(propertyID)); | 237 DCHECK(CSSPropertyMetadata::isEnabledProperty(propertyID)); |
| 238 // Shorthands with variable references are not expanded at parse time | 238 // Shorthands with variable references are not expanded at parse time |
| 239 // and hence may still be observed during serialization. | 239 // and hence may still be observed during serialization. |
| 240 ASSERT(!isShorthandProperty(propertyID) || property.value()->isVariableR
eferenceValue()); | 240 DCHECK(!isShorthandProperty(propertyID) || property.value()->isVariableR
eferenceValue()); |
| 241 | 241 |
| 242 switch (propertyID) { | 242 switch (propertyID) { |
| 243 case CSSPropertyVariable: | 243 case CSSPropertyVariable: |
| 244 result.append(getCustomPropertyText(property, numDecls++)); | 244 result.append(getCustomPropertyText(property, numDecls++)); |
| 245 continue; | 245 continue; |
| 246 case CSSPropertyAll: | 246 case CSSPropertyAll: |
| 247 result.append(getPropertyText(propertyID, property.value()->cssText(
), property.isImportant(), numDecls++)); | 247 result.append(getPropertyText(propertyID, property.value()->cssText(
), property.isImportant(), numDecls++)); |
| 248 continue; | 248 continue; |
| 249 case CSSPropertyApplyAtRule: | 249 case CSSPropertyApplyAtRule: |
| 250 result.append(getApplyAtRuleText(property.value(), numDecls++)); | 250 result.append(getApplyAtRuleText(property.value(), numDecls++)); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 longhandSerialized.set(shorthand.properties()[i] - firstCSSPrope
rty); | 296 longhandSerialized.set(shorthand.properties()[i] - firstCSSPrope
rty); |
| 297 break; | 297 break; |
| 298 } | 298 } |
| 299 | 299 |
| 300 if (serializedAsShorthand) | 300 if (serializedAsShorthand) |
| 301 continue; | 301 continue; |
| 302 | 302 |
| 303 result.append(getPropertyText(propertyID, property.value()->cssText(), p
roperty.isImportant(), numDecls++)); | 303 result.append(getPropertyText(propertyID, property.value()->cssText(), p
roperty.isImportant(), numDecls++)); |
| 304 } | 304 } |
| 305 | 305 |
| 306 ASSERT(!numDecls ^ !result.isEmpty()); | 306 DCHECK(!numDecls ^ !result.isEmpty()); |
| 307 return result.toString(); | 307 return result.toString(); |
| 308 } | 308 } |
| 309 | 309 |
| 310 // As per css-cascade, shorthands do not expand longhands to the value | 310 // As per css-cascade, shorthands do not expand longhands to the value |
| 311 // "initial", except when the shorthand is set to "initial", instead | 311 // "initial", except when the shorthand is set to "initial", instead |
| 312 // setting "missing" sub-properties to their initial values. This means | 312 // setting "missing" sub-properties to their initial values. This means |
| 313 // that a shorthand can never represent a list of subproperties where | 313 // that a shorthand can never represent a list of subproperties where |
| 314 // some are "initial" and some are not, and so serialization should | 314 // some are "initial" and some are not, and so serialization should |
| 315 // always fail in these cases (as per cssom). However we currently use | 315 // always fail in these cases (as per cssom). However we currently use |
| 316 // "initial" instead of the initial values for certain shorthands, so | 316 // "initial" instead of the initial values for certain shorthands, so |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 518 String horizontalValueCSSText = horizontalValue->cssText(); | 518 String horizontalValueCSSText = horizontalValue->cssText(); |
| 519 String verticalValueCSSText = verticalValue->cssText(); | 519 String verticalValueCSSText = verticalValue->cssText(); |
| 520 if (horizontalValueCSSText == verticalValueCSSText) | 520 if (horizontalValueCSSText == verticalValueCSSText) |
| 521 return horizontalValueCSSText; | 521 return horizontalValueCSSText; |
| 522 return horizontalValueCSSText + ' ' + verticalValueCSSText; | 522 return horizontalValueCSSText + ' ' + verticalValueCSSText; |
| 523 } | 523 } |
| 524 | 524 |
| 525 void StylePropertySerializer::appendFontLonghandValueIfNotNormal(CSSPropertyID p
ropertyID, StringBuilder& result) const | 525 void StylePropertySerializer::appendFontLonghandValueIfNotNormal(CSSPropertyID p
ropertyID, StringBuilder& result) const |
| 526 { | 526 { |
| 527 int foundPropertyIndex = m_propertySet.findPropertyIndex(propertyID); | 527 int foundPropertyIndex = m_propertySet.findPropertyIndex(propertyID); |
| 528 ASSERT(foundPropertyIndex != -1); | 528 DCHECK_NE(foundPropertyIndex, -1); |
| 529 | 529 |
| 530 const CSSValue* val = m_propertySet.propertyAt(foundPropertyIndex).value(); | 530 const CSSValue* val = m_propertySet.propertyAt(foundPropertyIndex).value(); |
| 531 if (val->isPrimitiveValue() && toCSSPrimitiveValue(val)->getValueID() == CSS
ValueNormal) | 531 if (val->isPrimitiveValue() && toCSSPrimitiveValue(val)->getValueID() == CSS
ValueNormal) |
| 532 return; | 532 return; |
| 533 | 533 |
| 534 char prefix = '\0'; | 534 char prefix = '\0'; |
| 535 switch (propertyID) { | 535 switch (propertyID) { |
| 536 case CSSPropertyFontStyle: | 536 case CSSPropertyFontStyle: |
| 537 break; // No prefix. | 537 break; // No prefix. |
| 538 case CSSPropertyFontFamily: | 538 case CSSPropertyFontFamily: |
| 539 case CSSPropertyFontStretch: | 539 case CSSPropertyFontStretch: |
| 540 case CSSPropertyFontVariantCaps: | 540 case CSSPropertyFontVariantCaps: |
| 541 case CSSPropertyFontVariantLigatures: | 541 case CSSPropertyFontVariantLigatures: |
| 542 case CSSPropertyFontVariantNumeric: | 542 case CSSPropertyFontVariantNumeric: |
| 543 case CSSPropertyFontWeight: | 543 case CSSPropertyFontWeight: |
| 544 prefix = ' '; | 544 prefix = ' '; |
| 545 break; | 545 break; |
| 546 case CSSPropertyLineHeight: | 546 case CSSPropertyLineHeight: |
| 547 prefix = '/'; | 547 prefix = '/'; |
| 548 break; | 548 break; |
| 549 default: | 549 default: |
| 550 ASSERT_NOT_REACHED(); | 550 NOTREACHED(); |
| 551 } | 551 } |
| 552 | 552 |
| 553 if (prefix && !result.isEmpty()) | 553 if (prefix && !result.isEmpty()) |
| 554 result.append(prefix); | 554 result.append(prefix); |
| 555 | 555 |
| 556 String value; | 556 String value; |
| 557 // In the font-variant shorthand a "none" ligatures value needs to be expand
ed. | 557 // In the font-variant shorthand a "none" ligatures value needs to be expand
ed. |
| 558 if (propertyID == CSSPropertyFontVariantLigatures | 558 if (propertyID == CSSPropertyFontVariantLigatures |
| 559 && val->isPrimitiveValue() | 559 && val->isPrimitiveValue() |
| 560 && toCSSPrimitiveValue(val)->getValueID() == CSSValueNone) { | 560 && toCSSPrimitiveValue(val)->getValueID() == CSSValueNone) { |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 717 // Background color belongs in the last layer. | 717 // Background color belongs in the last layer. |
| 718 value = values[propertyIndex]; | 718 value = values[propertyIndex]; |
| 719 } | 719 } |
| 720 // No point proceeding if there's not a value to look at. | 720 // No point proceeding if there's not a value to look at. |
| 721 if (!value) | 721 if (!value) |
| 722 continue; | 722 continue; |
| 723 | 723 |
| 724 // Special case for background-repeat. | 724 // Special case for background-repeat. |
| 725 if ((propertyIndex < size - 1 && m_propertySet.isPropertyImplicit(pr
operty)) | 725 if ((propertyIndex < size - 1 && m_propertySet.isPropertyImplicit(pr
operty)) |
| 726 && (property == CSSPropertyBackgroundRepeatX || property == CSSP
ropertyWebkitMaskRepeatX)) { | 726 && (property == CSSPropertyBackgroundRepeatX || property == CSSP
ropertyWebkitMaskRepeatX)) { |
| 727 ASSERT(shorthand.properties()[propertyIndex + 1] == CSSPropertyB
ackgroundRepeatY | 727 DCHECK(shorthand.properties()[propertyIndex + 1] == CSSPropertyB
ackgroundRepeatY |
| 728 || shorthand.properties()[propertyIndex + 1] == CSSPropertyW
ebkitMaskRepeatY); | 728 || shorthand.properties()[propertyIndex + 1] == CSSPropertyW
ebkitMaskRepeatY); |
| 729 const CSSValue& yValue = values[propertyIndex + 1]->isValueList(
) ? | 729 const CSSValue& yValue = values[propertyIndex + 1]->isValueList(
) ? |
| 730 toCSSValueList(values[propertyIndex + 1])->item(layer) : *va
lues[propertyIndex + 1]; | 730 toCSSValueList(values[propertyIndex + 1])->item(layer) : *va
lues[propertyIndex + 1]; |
| 731 | 731 |
| 732 | 732 |
| 733 // FIXME: At some point we need to fix this code to avoid return
ing an invalid shorthand, | 733 // FIXME: At some point we need to fix this code to avoid return
ing an invalid shorthand, |
| 734 // since some longhand combinations are not serializable into a
single shorthand. | 734 // since some longhand combinations are not serializable into a
single shorthand. |
| 735 if (!value->isPrimitiveValue() || !yValue.isPrimitiveValue()) | 735 if (!value->isPrimitiveValue() || !yValue.isPrimitiveValue()) |
| 736 continue; | 736 continue; |
| 737 | 737 |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 890 builder.append(", "); | 890 builder.append(", "); |
| 891 | 891 |
| 892 const CSSValue& xValue = repeatXList ? repeatXList->item(i % repeatXList
->length()) : repeatX; | 892 const CSSValue& xValue = repeatXList ? repeatXList->item(i % repeatXList
->length()) : repeatX; |
| 893 const CSSValue& yValue = repeatYList ? repeatYList->item(i % repeatYList
->length()) : repeatY; | 893 const CSSValue& yValue = repeatYList ? repeatYList->item(i % repeatYList
->length()) : repeatY; |
| 894 appendBackgroundRepeatValue(builder, xValue, yValue); | 894 appendBackgroundRepeatValue(builder, xValue, yValue); |
| 895 } | 895 } |
| 896 return builder.toString(); | 896 return builder.toString(); |
| 897 } | 897 } |
| 898 | 898 |
| 899 } // namespace blink | 899 } // namespace blink |
| OLD | NEW |