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

Side by Side Diff: Source/core/css/parser/CSSPropertyParser.cpp

Issue 1096963002: Make UseCounters work on aliased properties (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 8 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
« no previous file with comments | « Source/core/css/parser/CSSPropertyParser.h ('k') | Source/core/frame/UseCounter.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2003 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 2003 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2005 Allan Sandfeld Jensen (kde@carewolf.com) 3 * Copyright (C) 2005 Allan Sandfeld Jensen (kde@carewolf.com)
4 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights reserved. 4 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights reserved.
5 * Copyright (C) 2007 Nicholas Shanks <webkit@nickshanks.com> 5 * Copyright (C) 2007 Nicholas Shanks <webkit@nickshanks.com>
6 * Copyright (C) 2008 Eric Seidel <eric@webkit.org> 6 * Copyright (C) 2008 Eric Seidel <eric@webkit.org>
7 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmo bile.com/) 7 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmo bile.com/)
8 * Copyright (C) 2012 Adobe Systems Incorporated. All rights reserved. 8 * Copyright (C) 2012 Adobe Systems Incorporated. All rights reserved.
9 * Copyright (C) 2012 Intel Corporation. All rights reserved. 9 * Copyright (C) 2012 Intel Corporation. All rights reserved.
10 * 10 *
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 , m_context(context) 91 , m_context(context)
92 , m_inViewport(inViewport) 92 , m_inViewport(inViewport)
93 , m_parsedProperties(parsedProperties) 93 , m_parsedProperties(parsedProperties)
94 , m_ruleType(ruleType) 94 , m_ruleType(ruleType)
95 , m_inParseShorthand(0) 95 , m_inParseShorthand(0)
96 , m_currentShorthand(CSSPropertyInvalid) 96 , m_currentShorthand(CSSPropertyInvalid)
97 , m_implicitShorthand(false) 97 , m_implicitShorthand(false)
98 { 98 {
99 } 99 }
100 100
101 bool CSSPropertyParser::parseValue(CSSPropertyID property, bool important, 101 bool CSSPropertyParser::parseValue(CSSPropertyID unresolvedProperty, bool import ant,
102 CSSParserValueList* valueList, const CSSParserContext& context, bool inViewp ort, 102 CSSParserValueList* valueList, const CSSParserContext& context, bool inViewp ort,
103 WillBeHeapVector<CSSProperty, 256>& parsedProperties, StyleRule::Type ruleTy pe) 103 WillBeHeapVector<CSSProperty, 256>& parsedProperties, StyleRule::Type ruleTy pe)
104 { 104 {
105 int parsedPropertiesSize = parsedProperties.size(); 105 int parsedPropertiesSize = parsedProperties.size();
106 106
107 CSSPropertyParser parser(valueList, context, inViewport, parsedProperties, r uleType); 107 CSSPropertyParser parser(valueList, context, inViewport, parsedProperties, r uleType);
108 bool parseSuccess = parser.parseValue(property, important); 108 bool parseSuccess = parser.parseValue(unresolvedProperty, important);
109 109
110 // This doesn't count UA style sheets 110 // This doesn't count UA style sheets
111 if (parseSuccess && context.useCounter()) 111 if (parseSuccess && context.useCounter())
112 context.useCounter()->count(context, property); 112 context.useCounter()->count(context, unresolvedProperty);
113 113
114 if (!parseSuccess) 114 if (!parseSuccess)
115 parser.rollbackLastProperties(parsedProperties.size() - parsedProperties Size); 115 parser.rollbackLastProperties(parsedProperties.size() - parsedProperties Size);
116 116
117 return parseSuccess; 117 return parseSuccess;
118 } 118 }
119 119
120 void CSSPropertyParser::addPropertyWithPrefixingVariant(CSSPropertyID propId, Pa ssRefPtrWillBeRawPtr<CSSValue> value, bool important, bool implicit) 120 void CSSPropertyParser::addPropertyWithPrefixingVariant(CSSPropertyID propId, Pa ssRefPtrWillBeRawPtr<CSSValue> value, bool important, bool implicit)
121 { 121 {
122 RefPtrWillBeRawPtr<CSSValue> val = value.get(); 122 RefPtrWillBeRawPtr<CSSValue> val = value.get();
123 addProperty(propId, value, important, implicit); 123 addProperty(propId, value, important, implicit);
124 124
125 CSSPropertyID prefixingVariant = prefixingVariantForPropertyId(propId); 125 CSSPropertyID prefixingVariant = prefixingVariantForPropertyId(propId);
126 if (prefixingVariant == propId) 126 if (prefixingVariant == propId)
127 return; 127 return;
128 128
129 if (m_currentShorthand) { 129 if (m_currentShorthand) {
130 // We can't use ShorthandScope here as we can already be inside one (e.g we are parsing CSSTransition). 130 // We can't use ShorthandScope here as we can already be inside one (e.g we are parsing CSSTransition).
131 m_currentShorthand = prefixingVariantForPropertyId(m_currentShorthand); 131 m_currentShorthand = prefixingVariantForPropertyId(m_currentShorthand);
132 addProperty(prefixingVariant, val.release(), important, implicit); 132 addProperty(prefixingVariant, val.release(), important, implicit);
133 m_currentShorthand = prefixingVariantForPropertyId(m_currentShorthand); 133 m_currentShorthand = prefixingVariantForPropertyId(m_currentShorthand);
134 } else { 134 } else {
135 addProperty(prefixingVariant, val.release(), important, implicit); 135 addProperty(prefixingVariant, val.release(), important, implicit);
136 } 136 }
137 } 137 }
138 138
139 void CSSPropertyParser::addProperty(CSSPropertyID propId, PassRefPtrWillBeRawPtr <CSSValue> value, bool important, bool implicit) 139 void CSSPropertyParser::addProperty(CSSPropertyID propId, PassRefPtrWillBeRawPtr <CSSValue> value, bool important, bool implicit)
140 { 140 {
141 ASSERT(!isPropertyAlias(propId));
142
141 int shorthandIndex = 0; 143 int shorthandIndex = 0;
142 bool setFromShorthand = false; 144 bool setFromShorthand = false;
143 145
144 if (m_currentShorthand) { 146 if (m_currentShorthand) {
145 Vector<StylePropertyShorthand, 4> shorthands; 147 Vector<StylePropertyShorthand, 4> shorthands;
146 getMatchingShorthandsForLonghand(propId, &shorthands); 148 getMatchingShorthandsForLonghand(propId, &shorthands);
147 // Viewport descriptors have width and height as shorthands, but it does n't 149 // Viewport descriptors have width and height as shorthands, but it does n't
148 // make sense for CSSProperties.in to consider them as such. The shortha nd 150 // make sense for CSSProperties.in to consider them as such. The shortha nd
149 // index is only used by the inspector and doesn't affect viewport 151 // index is only used by the inspector and doesn't affect viewport
150 // descriptors. 152 // descriptors.
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 return; 417 return;
416 } 418 }
417 419
418 RefPtrWillBeRawPtr<CSSValue> value = prpValue; 420 RefPtrWillBeRawPtr<CSSValue> value = prpValue;
419 ShorthandScope scope(this, propId); 421 ShorthandScope scope(this, propId);
420 const CSSPropertyID* longhands = shorthand.properties(); 422 const CSSPropertyID* longhands = shorthand.properties();
421 for (unsigned i = 0; i < shorthandLength; ++i) 423 for (unsigned i = 0; i < shorthandLength; ++i)
422 addPropertyWithPrefixingVariant(longhands[i], value, important); 424 addPropertyWithPrefixingVariant(longhands[i], value, important);
423 } 425 }
424 426
425 bool CSSPropertyParser::parseValue(CSSPropertyID propId, bool important) 427 bool CSSPropertyParser::parseValue(CSSPropertyID unresolvedProperty, bool import ant)
426 { 428 {
429 CSSPropertyID propId = resolveCSSPropertyID(unresolvedProperty);
430
427 if (!m_valueList) 431 if (!m_valueList)
428 return false; 432 return false;
429 433
430 CSSParserValue* value = m_valueList->current(); 434 CSSParserValue* value = m_valueList->current();
431 435
432 if (!value) 436 if (!value)
433 return false; 437 return false;
434 438
435 if (inViewport()) { 439 if (inViewport()) {
436 // Allow @viewport rules from UA stylesheets even if the feature is disa bled. 440 // Allow @viewport rules from UA stylesheets even if the feature is disa bled.
(...skipping 2574 matching lines...) Expand 10 before | Expand all | Expand 10 after
3011 PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseAnimationProperty() 3015 PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseAnimationProperty()
3012 { 3016 {
3013 CSSParserValue* value = m_valueList->current(); 3017 CSSParserValue* value = m_valueList->current();
3014 if (value->unit != CSSPrimitiveValue::CSS_IDENT) 3018 if (value->unit != CSSPrimitiveValue::CSS_IDENT)
3015 return nullptr; 3019 return nullptr;
3016 // Since all is valid css property keyword, cssPropertyID for all 3020 // Since all is valid css property keyword, cssPropertyID for all
3017 // returns non-null value. We need to check "all" before 3021 // returns non-null value. We need to check "all" before
3018 // cssPropertyID check. 3022 // cssPropertyID check.
3019 if (value->id == CSSValueAll) 3023 if (value->id == CSSValueAll)
3020 return cssValuePool().createIdentifierValue(CSSValueAll); 3024 return cssValuePool().createIdentifierValue(CSSValueAll);
3021 CSSPropertyID property = cssPropertyID(value->string); 3025 CSSPropertyID property = unresolvedCSSPropertyID(value->string);
3022 if (property) { 3026 if (property) {
3023 ASSERT(CSSPropertyMetadata::isEnabledProperty(property)); 3027 ASSERT(CSSPropertyMetadata::isEnabledProperty(property));
3024 return cssValuePool().createIdentifierValue(property); 3028 return cssValuePool().createIdentifierValue(property);
3025 } 3029 }
3026 if (value->id == CSSValueNone) 3030 if (value->id == CSSValueNone)
3027 return cssValuePool().createIdentifierValue(CSSValueNone); 3031 return cssValuePool().createIdentifierValue(CSSValueNone);
3028 if (value->id == CSSValueInitial || value->id == CSSValueInherit) 3032 if (value->id == CSSValueInitial || value->id == CSSValueInherit)
3029 return nullptr; 3033 return nullptr;
3030 return createPrimitiveCustomIdentValue(value); 3034 return createPrimitiveCustomIdentValue(value);
3031 } 3035 }
(...skipping 4124 matching lines...) Expand 10 before | Expand all | Expand 10 after
7156 return values.release(); 7160 return values.release();
7157 } 7161 }
7158 7162
7159 // Every comma-separated list of CSS_IDENTs is a valid will-change value, 7163 // Every comma-separated list of CSS_IDENTs is a valid will-change value,
7160 // unless the list includes an explicitly disallowed CSS_IDENT. 7164 // unless the list includes an explicitly disallowed CSS_IDENT.
7161 while (true) { 7165 while (true) {
7162 CSSParserValue* currentValue = m_valueList->current(); 7166 CSSParserValue* currentValue = m_valueList->current();
7163 if (!currentValue || currentValue->unit != CSSPrimitiveValue::CSS_IDENT) 7167 if (!currentValue || currentValue->unit != CSSPrimitiveValue::CSS_IDENT)
7164 return nullptr; 7168 return nullptr;
7165 7169
7166 CSSPropertyID property = cssPropertyID(currentValue->string); 7170 CSSPropertyID unresolvedProperty = unresolvedCSSPropertyID(currentValue- >string);
7167 if (property) { 7171 if (unresolvedProperty) {
7168 ASSERT(CSSPropertyMetadata::isEnabledProperty(property)); 7172 ASSERT(CSSPropertyMetadata::isEnabledProperty(unresolvedProperty));
7169 // Now "all" is used by both CSSValue and CSSPropertyValue. 7173 // Now "all" is used by both CSSValue and CSSPropertyValue.
7170 // Need to return nullptr when currentValue is CSSPropertyAll. 7174 // Need to return nullptr when currentValue is CSSPropertyAll.
7171 if (property == CSSPropertyWillChange || property == CSSPropertyAll) 7175 if (unresolvedProperty == CSSPropertyWillChange || unresolvedPropert y == CSSPropertyAll)
7172 return nullptr; 7176 return nullptr;
7173 values->append(cssValuePool().createIdentifierValue(property)); 7177 values->append(cssValuePool().createIdentifierValue(unresolvedProper ty));
7174 } else { 7178 } else {
7175 switch (currentValue->id) { 7179 switch (currentValue->id) {
7176 case CSSValueNone: 7180 case CSSValueNone:
7177 case CSSValueAll: 7181 case CSSValueAll:
7178 case CSSValueAuto: 7182 case CSSValueAuto:
7179 case CSSValueDefault: 7183 case CSSValueDefault:
7180 case CSSValueInitial: 7184 case CSSValueInitial:
7181 case CSSValueInherit: 7185 case CSSValueInherit:
7182 return nullptr; 7186 return nullptr;
7183 case CSSValueContents: 7187 case CSSValueContents:
(...skipping 618 matching lines...) Expand 10 before | Expand all | Expand 10 after
7802 7806
7803 // If just one value is supplied, the second value 7807 // If just one value is supplied, the second value
7804 // is implicitly initialized with the first value. 7808 // is implicitly initialized with the first value.
7805 if (numValues == 1) 7809 if (numValues == 1)
7806 m_valueList->previous(); 7810 m_valueList->previous();
7807 7811
7808 return parseViewportProperty(second, important); 7812 return parseViewportProperty(second, important);
7809 } 7813 }
7810 7814
7811 template <typename CharacterType> 7815 template <typename CharacterType>
7812 static CSSPropertyID cssPropertyID(const CharacterType* propertyName, unsigned l ength) 7816 static CSSPropertyID unresolvedCSSPropertyID(const CharacterType* propertyName, unsigned length)
7813 { 7817 {
7814 char buffer[maxCSSPropertyNameLength + 1]; // 1 for null character 7818 char buffer[maxCSSPropertyNameLength + 1]; // 1 for null character
7815 7819
7816 for (unsigned i = 0; i != length; ++i) { 7820 for (unsigned i = 0; i != length; ++i) {
7817 CharacterType c = propertyName[i]; 7821 CharacterType c = propertyName[i];
7818 if (c == 0 || c >= 0x7F) 7822 if (c == 0 || c >= 0x7F)
7819 return CSSPropertyInvalid; // illegal character 7823 return CSSPropertyInvalid; // illegal character
7820 buffer[i] = toASCIILower(c); 7824 buffer[i] = toASCIILower(c);
7821 } 7825 }
7822 buffer[length] = '\0'; 7826 buffer[length] = '\0';
7823 7827
7824 const char* name = buffer; 7828 const char* name = buffer;
7825 const Property* hashTableEntry = findProperty(name, length); 7829 const Property* hashTableEntry = findProperty(name, length);
7826 if (!hashTableEntry) 7830 if (!hashTableEntry)
7827 return CSSPropertyInvalid; 7831 return CSSPropertyInvalid;
7828 CSSPropertyID property = static_cast<CSSPropertyID>(hashTableEntry->id); 7832 CSSPropertyID property = static_cast<CSSPropertyID>(hashTableEntry->id);
7829 if (!CSSPropertyMetadata::isEnabledProperty(property)) 7833 if (!CSSPropertyMetadata::isEnabledProperty(property))
7830 return CSSPropertyInvalid; 7834 return CSSPropertyInvalid;
7831 return property; 7835 return property;
7832 } 7836 }
7833 7837
7834 CSSPropertyID cssPropertyID(const String& string) 7838 CSSPropertyID unresolvedCSSPropertyID(const String& string)
7835 { 7839 {
7836 unsigned length = string.length(); 7840 unsigned length = string.length();
7837 7841
7838 if (!length) 7842 if (!length)
7839 return CSSPropertyInvalid; 7843 return CSSPropertyInvalid;
7840 if (length > maxCSSPropertyNameLength) 7844 if (length > maxCSSPropertyNameLength)
7841 return CSSPropertyInvalid; 7845 return CSSPropertyInvalid;
7842 7846
7843 return string.is8Bit() ? cssPropertyID(string.characters8(), length) : cssPr opertyID(string.characters16(), length); 7847 return string.is8Bit() ? unresolvedCSSPropertyID(string.characters8(), lengt h) : unresolvedCSSPropertyID(string.characters16(), length);
7844 } 7848 }
7845 7849
7846 CSSPropertyID cssPropertyID(const CSSParserString& string) 7850 CSSPropertyID cssPropertyID(const String& string)
7851 {
7852 return resolveCSSPropertyID(unresolvedCSSPropertyID(string));
7853 }
7854
7855 CSSPropertyID unresolvedCSSPropertyID(const CSSParserString& string)
7847 { 7856 {
7848 unsigned length = string.length(); 7857 unsigned length = string.length();
7849 7858
7850 if (!length) 7859 if (!length)
7851 return CSSPropertyInvalid; 7860 return CSSPropertyInvalid;
7852 if (length > maxCSSPropertyNameLength) 7861 if (length > maxCSSPropertyNameLength)
7853 return CSSPropertyInvalid; 7862 return CSSPropertyInvalid;
7854 7863
7855 return string.is8Bit() ? cssPropertyID(string.characters8(), length) : cssPr opertyID(string.characters16(), length); 7864 return string.is8Bit() ? unresolvedCSSPropertyID(string.characters8(), lengt h) : unresolvedCSSPropertyID(string.characters16(), length);
7856 } 7865 }
7857 7866
7858 template <typename CharacterType> 7867 template <typename CharacterType>
7859 static CSSValueID cssValueKeywordID(const CharacterType* valueKeyword, unsigned length) 7868 static CSSValueID cssValueKeywordID(const CharacterType* valueKeyword, unsigned length)
7860 { 7869 {
7861 char buffer[maxCSSValueKeywordLength + 1]; // 1 for null character 7870 char buffer[maxCSSValueKeywordLength + 1]; // 1 for null character
7862 7871
7863 for (unsigned i = 0; i != length; ++i) { 7872 for (unsigned i = 0; i != length; ++i) {
7864 CharacterType c = valueKeyword[i]; 7873 CharacterType c = valueKeyword[i];
7865 if (c == 0 || c >= 0x7F) 7874 if (c == 0 || c >= 0x7F)
(...skipping 619 matching lines...) Expand 10 before | Expand all | Expand 10 after
8485 } 8494 }
8486 } 8495 }
8487 8496
8488 if (!list->length()) 8497 if (!list->length())
8489 return nullptr; 8498 return nullptr;
8490 8499
8491 return list.release(); 8500 return list.release();
8492 } 8501 }
8493 8502
8494 } // namespace blink 8503 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/css/parser/CSSPropertyParser.h ('k') | Source/core/frame/UseCounter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698