| 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 if (CSSProperty::isAffectedByAllProperty(property.id())) { | 50 if (CSSProperty::isAffectedByAllProperty(property.id())) { |
| 51 if (allProperty.isImportant() && !property.isImportant()) | 51 if (allProperty.isImportant() && !property.isImportant()) |
| 52 continue; | 52 continue; |
| 53 if (static_cast<unsigned>(m_allIndex) >= i) | 53 if (static_cast<unsigned>(m_allIndex) >= i) |
| 54 continue; | 54 continue; |
| 55 if (property.value().equals(allProperty.value()) && | 55 if (property.value().equals(allProperty.value()) && |
| 56 property.isImportant() == allProperty.isImportant()) | 56 property.isImportant() == allProperty.isImportant()) |
| 57 continue; | 57 continue; |
| 58 m_needToExpandAll = true; | 58 m_needToExpandAll = true; |
| 59 } | 59 } |
| 60 if (property.id() < firstCSSProperty || property.id() > lastCSSProperty) | 60 if (!isCSSPropertyIDWithName(property.id())) |
| 61 continue; | 61 continue; |
| 62 m_longhandPropertyUsed.set(property.id() - firstCSSProperty); | 62 m_longhandPropertyUsed.set(property.id() - firstCSSProperty); |
| 63 } | 63 } |
| 64 } | 64 } |
| 65 | 65 |
| 66 DEFINE_TRACE(StylePropertySerializer::StylePropertySetForSerializer) { | 66 DEFINE_TRACE(StylePropertySerializer::StylePropertySetForSerializer) { |
| 67 visitor->trace(m_propertySet); | 67 visitor->trace(m_propertySet); |
| 68 } | 68 } |
| 69 | 69 |
| 70 unsigned StylePropertySerializer::StylePropertySetForSerializer::propertyCount() | 70 unsigned StylePropertySerializer::StylePropertySetForSerializer::propertyCount() |
| 71 const { | 71 const { |
| 72 if (!hasExpandedAllProperty()) | 72 if (!hasExpandedAllProperty()) |
| 73 return m_propertySet->propertyCount(); | 73 return m_propertySet->propertyCount(); |
| 74 return lastCSSProperty - firstCSSProperty + 1; | 74 return lastCSSProperty - firstCSSProperty + 1; |
| 75 } | 75 } |
| 76 | 76 |
| 77 StylePropertySerializer::PropertyValueForSerializer | 77 StylePropertySerializer::PropertyValueForSerializer |
| 78 StylePropertySerializer::StylePropertySetForSerializer::propertyAt( | 78 StylePropertySerializer::StylePropertySetForSerializer::propertyAt( |
| 79 unsigned index) const { | 79 unsigned index) const { |
| 80 if (!hasExpandedAllProperty()) | 80 if (!hasExpandedAllProperty()) |
| 81 return StylePropertySerializer::PropertyValueForSerializer( | 81 return StylePropertySerializer::PropertyValueForSerializer( |
| 82 m_propertySet->propertyAt(index)); | 82 m_propertySet->propertyAt(index)); |
| 83 | 83 |
| 84 CSSPropertyID propertyID = | 84 CSSPropertyID propertyID = |
| 85 static_cast<CSSPropertyID>(index + firstCSSProperty); | 85 static_cast<CSSPropertyID>(index + firstCSSProperty); |
| 86 ASSERT(firstCSSProperty <= propertyID && propertyID <= lastCSSProperty); | 86 DCHECK(isCSSPropertyIDWithName(propertyID)); |
| 87 if (m_longhandPropertyUsed.test(index)) { | 87 if (m_longhandPropertyUsed.test(index)) { |
| 88 int index = m_propertySet->findPropertyIndex(propertyID); | 88 int index = m_propertySet->findPropertyIndex(propertyID); |
| 89 ASSERT(index != -1); | 89 DCHECK_NE(index, -1); |
| 90 return StylePropertySerializer::PropertyValueForSerializer( | 90 return StylePropertySerializer::PropertyValueForSerializer( |
| 91 m_propertySet->propertyAt(index)); | 91 m_propertySet->propertyAt(index)); |
| 92 } | 92 } |
| 93 | 93 |
| 94 StylePropertySet::PropertyReference property = | 94 StylePropertySet::PropertyReference property = |
| 95 m_propertySet->propertyAt(m_allIndex); | 95 m_propertySet->propertyAt(m_allIndex); |
| 96 return StylePropertySerializer::PropertyValueForSerializer( | 96 return StylePropertySerializer::PropertyValueForSerializer( |
| 97 propertyID, &property.value(), property.isImportant()); | 97 propertyID, &property.value(), property.isImportant()); |
| 98 } | 98 } |
| 99 | 99 |
| 100 bool StylePropertySerializer::StylePropertySetForSerializer:: | 100 bool StylePropertySerializer::StylePropertySetForSerializer:: |
| 101 shouldProcessPropertyAt(unsigned index) const { | 101 shouldProcessPropertyAt(unsigned index) const { |
| 102 // StylePropertySet has all valid longhands. We should process. | 102 // StylePropertySet has all valid longhands. We should process. |
| 103 if (!hasAllProperty()) | 103 if (!hasAllProperty()) |
| 104 return true; | 104 return true; |
| 105 | 105 |
| 106 // If all is not expanded, we need to process "all" and properties which | 106 // If all is not expanded, we need to process "all" and properties which |
| 107 // are not overwritten by "all". | 107 // are not overwritten by "all". |
| 108 if (!m_needToExpandAll) { | 108 if (!m_needToExpandAll) { |
| 109 StylePropertySet::PropertyReference property = | 109 StylePropertySet::PropertyReference property = |
| 110 m_propertySet->propertyAt(index); | 110 m_propertySet->propertyAt(index); |
| 111 if (property.id() == CSSPropertyAll || | 111 if (property.id() == CSSPropertyAll || |
| 112 !CSSProperty::isAffectedByAllProperty(property.id())) | 112 !CSSProperty::isAffectedByAllProperty(property.id())) |
| 113 return true; | 113 return true; |
| 114 if (property.id() < firstCSSProperty || property.id() > lastCSSProperty) | 114 if (!isCSSPropertyIDWithName(property.id())) |
| 115 return false; | 115 return false; |
| 116 return m_longhandPropertyUsed.test(property.id() - firstCSSProperty); | 116 return m_longhandPropertyUsed.test(property.id() - firstCSSProperty); |
| 117 } | 117 } |
| 118 | 118 |
| 119 CSSPropertyID propertyID = | 119 CSSPropertyID propertyID = |
| 120 static_cast<CSSPropertyID>(index + firstCSSProperty); | 120 static_cast<CSSPropertyID>(index + firstCSSProperty); |
| 121 ASSERT(firstCSSProperty <= propertyID && propertyID <= lastCSSProperty); | 121 DCHECK(isCSSPropertyIDWithName(propertyID)); |
| 122 | 122 |
| 123 // Since "all" is expanded, we don't need to process "all". | 123 // Since "all" is expanded, we don't need to process "all". |
| 124 // We should not process expanded shorthands (e.g. font, background, | 124 // We should not process expanded shorthands (e.g. font, background, |
| 125 // and so on) either. | 125 // and so on) either. |
| 126 if (isShorthandProperty(propertyID) || propertyID == CSSPropertyAll) | 126 if (isShorthandProperty(propertyID) || propertyID == CSSPropertyAll) |
| 127 return false; | 127 return false; |
| 128 | 128 |
| 129 // The all property is a shorthand that resets all CSS properties except | 129 // The all property is a shorthand that resets all CSS properties except |
| 130 // direction and unicode-bidi. It only accepts the CSS-wide keywords. | 130 // direction and unicode-bidi. It only accepts the CSS-wide keywords. |
| 131 // c.f. http://dev.w3.org/csswg/css-cascade/#all-shorthand | 131 // c.f. http://dev.w3.org/csswg/css-cascade/#all-shorthand |
| (...skipping 29 matching lines...) Expand all Loading... |
| 161 return value.isImplicit(); | 161 return value.isImplicit(); |
| 162 } | 162 } |
| 163 | 163 |
| 164 StylePropertySerializer::StylePropertySerializer( | 164 StylePropertySerializer::StylePropertySerializer( |
| 165 const StylePropertySet& properties) | 165 const StylePropertySet& properties) |
| 166 : m_propertySet(properties) {} | 166 : m_propertySet(properties) {} |
| 167 | 167 |
| 168 String StylePropertySerializer::getCustomPropertyText( | 168 String StylePropertySerializer::getCustomPropertyText( |
| 169 const PropertyValueForSerializer& property, | 169 const PropertyValueForSerializer& property, |
| 170 bool isNotFirstDecl) const { | 170 bool isNotFirstDecl) const { |
| 171 ASSERT(property.id() == CSSPropertyVariable); | 171 DCHECK_EQ(property.id(), CSSPropertyVariable); |
| 172 StringBuilder result; | 172 StringBuilder result; |
| 173 if (isNotFirstDecl) | 173 if (isNotFirstDecl) |
| 174 result.append(' '); | 174 result.append(' '); |
| 175 const CSSCustomPropertyDeclaration* value = | 175 const CSSCustomPropertyDeclaration* value = |
| 176 toCSSCustomPropertyDeclaration(property.value()); | 176 toCSSCustomPropertyDeclaration(property.value()); |
| 177 result.append(value->name()); | 177 result.append(value->name()); |
| 178 result.append(':'); | 178 result.append(':'); |
| 179 if (!value->value()) | 179 if (!value->value()) |
| 180 result.append(' '); | 180 result.append(' '); |
| 181 result.append(value->customCSSText()); | 181 result.append(value->customCSSText()); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 unsigned size = m_propertySet.propertyCount(); | 220 unsigned size = m_propertySet.propertyCount(); |
| 221 unsigned numDecls = 0; | 221 unsigned numDecls = 0; |
| 222 for (unsigned n = 0; n < size; ++n) { | 222 for (unsigned n = 0; n < size; ++n) { |
| 223 if (!m_propertySet.shouldProcessPropertyAt(n)) | 223 if (!m_propertySet.shouldProcessPropertyAt(n)) |
| 224 continue; | 224 continue; |
| 225 | 225 |
| 226 StylePropertySerializer::PropertyValueForSerializer property = | 226 StylePropertySerializer::PropertyValueForSerializer property = |
| 227 m_propertySet.propertyAt(n); | 227 m_propertySet.propertyAt(n); |
| 228 CSSPropertyID propertyID = property.id(); | 228 CSSPropertyID propertyID = property.id(); |
| 229 // Only enabled properties should be part of the style. | 229 // Only enabled properties should be part of the style. |
| 230 ASSERT(CSSPropertyMetadata::isEnabledProperty(propertyID)); | 230 DCHECK(CSSPropertyMetadata::isEnabledProperty(propertyID)); |
| 231 // Shorthands with variable references are not expanded at parse time | 231 // Shorthands with variable references are not expanded at parse time |
| 232 // and hence may still be observed during serialization. | 232 // and hence may still be observed during serialization. |
| 233 ASSERT(!isShorthandProperty(propertyID) || | 233 DCHECK(!isShorthandProperty(propertyID) || |
| 234 property.value()->isVariableReferenceValue()); | 234 property.value()->isVariableReferenceValue()); |
| 235 | 235 |
| 236 switch (propertyID) { | 236 switch (propertyID) { |
| 237 case CSSPropertyVariable: | 237 case CSSPropertyVariable: |
| 238 result.append(getCustomPropertyText(property, numDecls++)); | 238 result.append(getCustomPropertyText(property, numDecls++)); |
| 239 continue; | 239 continue; |
| 240 case CSSPropertyAll: | 240 case CSSPropertyAll: |
| 241 result.append(getPropertyText(propertyID, property.value()->cssText(), | 241 result.append(getPropertyText(propertyID, property.value()->cssText(), |
| 242 property.isImportant(), numDecls++)); | 242 property.isImportant(), numDecls++)); |
| 243 continue; | 243 continue; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 break; | 295 break; |
| 296 } | 296 } |
| 297 | 297 |
| 298 if (serializedAsShorthand) | 298 if (serializedAsShorthand) |
| 299 continue; | 299 continue; |
| 300 | 300 |
| 301 result.append(getPropertyText(propertyID, property.value()->cssText(), | 301 result.append(getPropertyText(propertyID, property.value()->cssText(), |
| 302 property.isImportant(), numDecls++)); | 302 property.isImportant(), numDecls++)); |
| 303 } | 303 } |
| 304 | 304 |
| 305 ASSERT(!numDecls ^ !result.isEmpty()); | 305 DCHECK(!numDecls ^ !result.isEmpty()); |
| 306 return result.toString(); | 306 return result.toString(); |
| 307 } | 307 } |
| 308 | 308 |
| 309 // As per css-cascade, shorthands do not expand longhands to the value | 309 // As per css-cascade, shorthands do not expand longhands to the value |
| 310 // "initial", except when the shorthand is set to "initial", instead | 310 // "initial", except when the shorthand is set to "initial", instead |
| 311 // setting "missing" sub-properties to their initial values. This means | 311 // setting "missing" sub-properties to their initial values. This means |
| 312 // that a shorthand can never represent a list of subproperties where | 312 // that a shorthand can never represent a list of subproperties where |
| 313 // some are "initial" and some are not, and so serialization should | 313 // some are "initial" and some are not, and so serialization should |
| 314 // always fail in these cases (as per cssom). However we currently use | 314 // always fail in these cases (as per cssom). However we currently use |
| 315 // "initial" instead of the initial values for certain shorthands, so | 315 // "initial" instead of the initial values for certain shorthands, so |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 525 String verticalValueCSSText = verticalValue->cssText(); | 525 String verticalValueCSSText = verticalValue->cssText(); |
| 526 if (horizontalValueCSSText == verticalValueCSSText) | 526 if (horizontalValueCSSText == verticalValueCSSText) |
| 527 return horizontalValueCSSText; | 527 return horizontalValueCSSText; |
| 528 return horizontalValueCSSText + ' ' + verticalValueCSSText; | 528 return horizontalValueCSSText + ' ' + verticalValueCSSText; |
| 529 } | 529 } |
| 530 | 530 |
| 531 void StylePropertySerializer::appendFontLonghandValueIfNotNormal( | 531 void StylePropertySerializer::appendFontLonghandValueIfNotNormal( |
| 532 CSSPropertyID propertyID, | 532 CSSPropertyID propertyID, |
| 533 StringBuilder& result) const { | 533 StringBuilder& result) const { |
| 534 int foundPropertyIndex = m_propertySet.findPropertyIndex(propertyID); | 534 int foundPropertyIndex = m_propertySet.findPropertyIndex(propertyID); |
| 535 ASSERT(foundPropertyIndex != -1); | 535 DCHECK_NE(foundPropertyIndex, -1); |
| 536 | 536 |
| 537 const CSSValue* val = m_propertySet.propertyAt(foundPropertyIndex).value(); | 537 const CSSValue* val = m_propertySet.propertyAt(foundPropertyIndex).value(); |
| 538 if (val->isIdentifierValue() && | 538 if (val->isIdentifierValue() && |
| 539 toCSSIdentifierValue(val)->getValueID() == CSSValueNormal) | 539 toCSSIdentifierValue(val)->getValueID() == CSSValueNormal) |
| 540 return; | 540 return; |
| 541 | 541 |
| 542 char prefix = '\0'; | 542 char prefix = '\0'; |
| 543 switch (propertyID) { | 543 switch (propertyID) { |
| 544 case CSSPropertyFontStyle: | 544 case CSSPropertyFontStyle: |
| 545 break; // No prefix. | 545 break; // No prefix. |
| 546 case CSSPropertyFontFamily: | 546 case CSSPropertyFontFamily: |
| 547 case CSSPropertyFontStretch: | 547 case CSSPropertyFontStretch: |
| 548 case CSSPropertyFontVariantCaps: | 548 case CSSPropertyFontVariantCaps: |
| 549 case CSSPropertyFontVariantLigatures: | 549 case CSSPropertyFontVariantLigatures: |
| 550 case CSSPropertyFontVariantNumeric: | 550 case CSSPropertyFontVariantNumeric: |
| 551 case CSSPropertyFontWeight: | 551 case CSSPropertyFontWeight: |
| 552 prefix = ' '; | 552 prefix = ' '; |
| 553 break; | 553 break; |
| 554 case CSSPropertyLineHeight: | 554 case CSSPropertyLineHeight: |
| 555 prefix = '/'; | 555 prefix = '/'; |
| 556 break; | 556 break; |
| 557 default: | 557 default: |
| 558 ASSERT_NOT_REACHED(); | 558 NOTREACHED(); |
| 559 } | 559 } |
| 560 | 560 |
| 561 if (prefix && !result.isEmpty()) | 561 if (prefix && !result.isEmpty()) |
| 562 result.append(prefix); | 562 result.append(prefix); |
| 563 | 563 |
| 564 String value; | 564 String value; |
| 565 // In the font-variant shorthand a "none" ligatures value needs to be expanded
. | 565 // In the font-variant shorthand a "none" ligatures value needs to be expanded
. |
| 566 if (propertyID == CSSPropertyFontVariantLigatures && | 566 if (propertyID == CSSPropertyFontVariantLigatures && |
| 567 val->isIdentifierValue() && | 567 val->isIdentifierValue() && |
| 568 toCSSIdentifierValue(val)->getValueID() == CSSValueNone) { | 568 toCSSIdentifierValue(val)->getValueID() == CSSValueNone) { |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 745 } | 745 } |
| 746 // No point proceeding if there's not a value to look at. | 746 // No point proceeding if there's not a value to look at. |
| 747 if (!value) | 747 if (!value) |
| 748 continue; | 748 continue; |
| 749 | 749 |
| 750 // Special case for background-repeat. | 750 // Special case for background-repeat. |
| 751 if ((propertyIndex < size - 1 && | 751 if ((propertyIndex < size - 1 && |
| 752 m_propertySet.isPropertyImplicit(property)) && | 752 m_propertySet.isPropertyImplicit(property)) && |
| 753 (property == CSSPropertyBackgroundRepeatX || | 753 (property == CSSPropertyBackgroundRepeatX || |
| 754 property == CSSPropertyWebkitMaskRepeatX)) { | 754 property == CSSPropertyWebkitMaskRepeatX)) { |
| 755 ASSERT(shorthand.properties()[propertyIndex + 1] == | 755 DCHECK(shorthand.properties()[propertyIndex + 1] == |
| 756 CSSPropertyBackgroundRepeatY || | 756 CSSPropertyBackgroundRepeatY || |
| 757 shorthand.properties()[propertyIndex + 1] == | 757 shorthand.properties()[propertyIndex + 1] == |
| 758 CSSPropertyWebkitMaskRepeatY); | 758 CSSPropertyWebkitMaskRepeatY); |
| 759 const CSSValue& yValue = | 759 const CSSValue& yValue = |
| 760 values[propertyIndex + 1]->isValueList() | 760 values[propertyIndex + 1]->isValueList() |
| 761 ? toCSSValueList(values[propertyIndex + 1])->item(layer) | 761 ? toCSSValueList(values[propertyIndex + 1])->item(layer) |
| 762 : *values[propertyIndex + 1]; | 762 : *values[propertyIndex + 1]; |
| 763 | 763 |
| 764 // FIXME: At some point we need to fix this code to avoid returning an i
nvalid shorthand, | 764 // FIXME: At some point we need to fix this code to avoid returning an i
nvalid shorthand, |
| 765 // since some longhand combinations are not serializable into a single s
horthand. | 765 // since some longhand combinations are not serializable into a single s
horthand. |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 939 const CSSValue& xValue = | 939 const CSSValue& xValue = |
| 940 repeatXList ? repeatXList->item(i % repeatXList->length()) : repeatX; | 940 repeatXList ? repeatXList->item(i % repeatXList->length()) : repeatX; |
| 941 const CSSValue& yValue = | 941 const CSSValue& yValue = |
| 942 repeatYList ? repeatYList->item(i % repeatYList->length()) : repeatY; | 942 repeatYList ? repeatYList->item(i % repeatYList->length()) : repeatY; |
| 943 appendBackgroundRepeatValue(builder, xValue, yValue); | 943 appendBackgroundRepeatValue(builder, xValue, yValue); |
| 944 } | 944 } |
| 945 return builder.toString(); | 945 return builder.toString(); |
| 946 } | 946 } |
| 947 | 947 |
| 948 } // namespace blink | 948 } // namespace blink |
| OLD | NEW |