| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "core/css/parser/CSSParserImpl.h" | 5 #include "core/css/parser/CSSParserImpl.h" |
| 6 | 6 |
| 7 #include "core/css/CSSCustomIdentValue.h" | 7 #include "core/css/CSSCustomIdentValue.h" |
| 8 #include "core/css/CSSCustomPropertyDeclaration.h" | 8 #include "core/css/CSSCustomPropertyDeclaration.h" |
| 9 #include "core/css/CSSKeyframesRule.h" | 9 #include "core/css/CSSKeyframesRule.h" |
| 10 #include "core/css/CSSStyleSheet.h" | 10 #include "core/css/CSSStyleSheet.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #include "core/css/parser/CSSSelectorParser.h" | 21 #include "core/css/parser/CSSSelectorParser.h" |
| 22 #include "core/css/parser/CSSSupportsParser.h" | 22 #include "core/css/parser/CSSSupportsParser.h" |
| 23 #include "core/css/parser/CSSTokenizer.h" | 23 #include "core/css/parser/CSSTokenizer.h" |
| 24 #include "core/css/parser/CSSVariableParser.h" | 24 #include "core/css/parser/CSSVariableParser.h" |
| 25 #include "core/css/parser/MediaQueryParser.h" | 25 #include "core/css/parser/MediaQueryParser.h" |
| 26 #include "core/dom/Document.h" | 26 #include "core/dom/Document.h" |
| 27 #include "core/dom/Element.h" | 27 #include "core/dom/Element.h" |
| 28 #include "core/frame/Deprecation.h" | 28 #include "core/frame/Deprecation.h" |
| 29 #include "core/frame/UseCounter.h" | 29 #include "core/frame/UseCounter.h" |
| 30 #include "platform/TraceEvent.h" | 30 #include "platform/TraceEvent.h" |
| 31 #include "wtf/PtrUtil.h" |
| 31 #include <bitset> | 32 #include <bitset> |
| 33 #include <memory> |
| 32 | 34 |
| 33 namespace blink { | 35 namespace blink { |
| 34 | 36 |
| 35 CSSParserImpl::CSSParserImpl(const CSSParserContext& context, StyleSheetContents
* styleSheet) | 37 CSSParserImpl::CSSParserImpl(const CSSParserContext& context, StyleSheetContents
* styleSheet) |
| 36 : m_context(context) | 38 : m_context(context) |
| 37 , m_styleSheet(styleSheet) | 39 , m_styleSheet(styleSheet) |
| 38 , m_observerWrapper(nullptr) | 40 , m_observerWrapper(nullptr) |
| 39 { | 41 { |
| 40 } | 42 } |
| 41 | 43 |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 range.consume(); | 199 range.consume(); |
| 198 if (range.peek().type() != IdentToken) | 200 if (range.peek().type() != IdentToken) |
| 199 return CSSSelectorList(); | 201 return CSSSelectorList(); |
| 200 pseudo = range.consume().value().toAtomicString(); | 202 pseudo = range.consume().value().toAtomicString(); |
| 201 } | 203 } |
| 202 | 204 |
| 203 range.consumeWhitespace(); | 205 range.consumeWhitespace(); |
| 204 if (!range.atEnd()) | 206 if (!range.atEnd()) |
| 205 return CSSSelectorList(); // Parse error; extra tokens in @page selector | 207 return CSSSelectorList(); // Parse error; extra tokens in @page selector |
| 206 | 208 |
| 207 OwnPtr<CSSParserSelector> selector; | 209 std::unique_ptr<CSSParserSelector> selector; |
| 208 if (!typeSelector.isNull() && pseudo.isNull()) { | 210 if (!typeSelector.isNull() && pseudo.isNull()) { |
| 209 selector = CSSParserSelector::create(QualifiedName(nullAtom, typeSelecto
r, styleSheet->defaultNamespace())); | 211 selector = CSSParserSelector::create(QualifiedName(nullAtom, typeSelecto
r, styleSheet->defaultNamespace())); |
| 210 } else { | 212 } else { |
| 211 selector = CSSParserSelector::create(); | 213 selector = CSSParserSelector::create(); |
| 212 if (!pseudo.isNull()) { | 214 if (!pseudo.isNull()) { |
| 213 selector->setMatch(CSSSelector::PagePseudoClass); | 215 selector->setMatch(CSSSelector::PagePseudoClass); |
| 214 selector->updatePseudoType(pseudo.lower()); | 216 selector->updatePseudoType(pseudo.lower()); |
| 215 if (selector->pseudoType() == CSSSelector::PseudoUnknown) | 217 if (selector->pseudoType() == CSSSelector::PseudoUnknown) |
| 216 return CSSSelectorList(); | 218 return CSSSelectorList(); |
| 217 } | 219 } |
| 218 if (!typeSelector.isNull()) { | 220 if (!typeSelector.isNull()) { |
| 219 selector->prependTagSelector(QualifiedName(nullAtom, typeSelector, s
tyleSheet->defaultNamespace())); | 221 selector->prependTagSelector(QualifiedName(nullAtom, typeSelector, s
tyleSheet->defaultNamespace())); |
| 220 } | 222 } |
| 221 } | 223 } |
| 222 | 224 |
| 223 selector->setForPage(); | 225 selector->setForPage(); |
| 224 Vector<OwnPtr<CSSParserSelector>> selectorVector; | 226 Vector<std::unique_ptr<CSSParserSelector>> selectorVector; |
| 225 selectorVector.append(std::move(selector)); | 227 selectorVector.append(std::move(selector)); |
| 226 CSSSelectorList selectorList = CSSSelectorList::adoptSelectorVector(selector
Vector); | 228 CSSSelectorList selectorList = CSSSelectorList::adoptSelectorVector(selector
Vector); |
| 227 return selectorList; | 229 return selectorList; |
| 228 } | 230 } |
| 229 | 231 |
| 230 ImmutableStylePropertySet* CSSParserImpl::parseCustomPropertySet(CSSParserTokenR
ange range) | 232 ImmutableStylePropertySet* CSSParserImpl::parseCustomPropertySet(CSSParserTokenR
ange range) |
| 231 { | 233 { |
| 232 range.consumeWhitespace(); | 234 range.consumeWhitespace(); |
| 233 if (range.peek().type() != LeftBraceToken) | 235 if (range.peek().type() != LeftBraceToken) |
| 234 return nullptr; | 236 return nullptr; |
| 235 CSSParserTokenRange block = range.consumeBlock(); | 237 CSSParserTokenRange block = range.consumeBlock(); |
| 236 range.consumeWhitespace(); | 238 range.consumeWhitespace(); |
| 237 if (!range.atEnd()) | 239 if (!range.atEnd()) |
| 238 return nullptr; | 240 return nullptr; |
| 239 CSSParserImpl parser(strictCSSParserContext()); | 241 CSSParserImpl parser(strictCSSParserContext()); |
| 240 parser.consumeDeclarationList(block, StyleRule::Style); | 242 parser.consumeDeclarationList(block, StyleRule::Style); |
| 241 | 243 |
| 242 // Drop nested @apply rules. Seems nicer to do this here instead of making | 244 // Drop nested @apply rules. Seems nicer to do this here instead of making |
| 243 // a different StyleRule type | 245 // a different StyleRule type |
| 244 for (size_t i = parser.m_parsedProperties.size(); i--; ) { | 246 for (size_t i = parser.m_parsedProperties.size(); i--; ) { |
| 245 if (parser.m_parsedProperties[i].id() == CSSPropertyApplyAtRule) | 247 if (parser.m_parsedProperties[i].id() == CSSPropertyApplyAtRule) |
| 246 parser.m_parsedProperties.remove(i); | 248 parser.m_parsedProperties.remove(i); |
| 247 } | 249 } |
| 248 | 250 |
| 249 return createStylePropertySet(parser.m_parsedProperties, HTMLStandardMode); | 251 return createStylePropertySet(parser.m_parsedProperties, HTMLStandardMode); |
| 250 } | 252 } |
| 251 | 253 |
| 252 PassOwnPtr<Vector<double>> CSSParserImpl::parseKeyframeKeyList(const String& key
List) | 254 std::unique_ptr<Vector<double>> CSSParserImpl::parseKeyframeKeyList(const String
& keyList) |
| 253 { | 255 { |
| 254 return consumeKeyframeKeyList(CSSTokenizer::Scope(keyList).tokenRange()); | 256 return consumeKeyframeKeyList(CSSTokenizer::Scope(keyList).tokenRange()); |
| 255 } | 257 } |
| 256 | 258 |
| 257 bool CSSParserImpl::supportsDeclaration(CSSParserTokenRange& range) | 259 bool CSSParserImpl::supportsDeclaration(CSSParserTokenRange& range) |
| 258 { | 260 { |
| 259 ASSERT(m_parsedProperties.isEmpty()); | 261 ASSERT(m_parsedProperties.isEmpty()); |
| 260 consumeDeclaration(range, StyleRule::Style); | 262 consumeDeclaration(range, StyleRule::Style); |
| 261 bool result = !m_parsedProperties.isEmpty(); | 263 bool result = !m_parsedProperties.isEmpty(); |
| 262 m_parsedProperties.clear(); | 264 m_parsedProperties.clear(); |
| (...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 639 const CSSParserToken& ident = prelude.consumeIncludingWhitespace(); | 641 const CSSParserToken& ident = prelude.consumeIncludingWhitespace(); |
| 640 if (!prelude.atEnd() || !CSSVariableParser::isValidVariableName(ident)) | 642 if (!prelude.atEnd() || !CSSVariableParser::isValidVariableName(ident)) |
| 641 return; // Parse error, expected a single custom property name | 643 return; // Parse error, expected a single custom property name |
| 642 m_parsedProperties.append(CSSProperty( | 644 m_parsedProperties.append(CSSProperty( |
| 643 CSSPropertyApplyAtRule, | 645 CSSPropertyApplyAtRule, |
| 644 *CSSCustomIdentValue::create(ident.value().toString()))); | 646 *CSSCustomIdentValue::create(ident.value().toString()))); |
| 645 } | 647 } |
| 646 | 648 |
| 647 StyleRuleKeyframe* CSSParserImpl::consumeKeyframeStyleRule(CSSParserTokenRange p
relude, CSSParserTokenRange block) | 649 StyleRuleKeyframe* CSSParserImpl::consumeKeyframeStyleRule(CSSParserTokenRange p
relude, CSSParserTokenRange block) |
| 648 { | 650 { |
| 649 OwnPtr<Vector<double>> keyList = consumeKeyframeKeyList(prelude); | 651 std::unique_ptr<Vector<double>> keyList = consumeKeyframeKeyList(prelude); |
| 650 if (!keyList) | 652 if (!keyList) |
| 651 return nullptr; | 653 return nullptr; |
| 652 | 654 |
| 653 if (m_observerWrapper) { | 655 if (m_observerWrapper) { |
| 654 m_observerWrapper->observer().startRuleHeader(StyleRule::Keyframe, m_obs
erverWrapper->startOffset(prelude)); | 656 m_observerWrapper->observer().startRuleHeader(StyleRule::Keyframe, m_obs
erverWrapper->startOffset(prelude)); |
| 655 m_observerWrapper->observer().endRuleHeader(m_observerWrapper->endOffset
(prelude)); | 657 m_observerWrapper->observer().endRuleHeader(m_observerWrapper->endOffset
(prelude)); |
| 656 } | 658 } |
| 657 | 659 |
| 658 consumeDeclarationList(block, StyleRule::Keyframe); | 660 consumeDeclarationList(block, StyleRule::Keyframe); |
| 659 return StyleRuleKeyframe::create(std::move(keyList), createStylePropertySet(
m_parsedProperties, m_context.mode())); | 661 return StyleRuleKeyframe::create(std::move(keyList), createStylePropertySet(
m_parsedProperties, m_context.mode())); |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 796 { | 798 { |
| 797 if (CSSCustomPropertyDeclaration* value = CSSVariableParser::parseDeclaratio
nValue(variableName, range)) | 799 if (CSSCustomPropertyDeclaration* value = CSSVariableParser::parseDeclaratio
nValue(variableName, range)) |
| 798 m_parsedProperties.append(CSSProperty(CSSPropertyVariable, *value, impor
tant)); | 800 m_parsedProperties.append(CSSProperty(CSSPropertyVariable, *value, impor
tant)); |
| 799 } | 801 } |
| 800 | 802 |
| 801 void CSSParserImpl::consumeDeclarationValue(CSSParserTokenRange range, CSSProper
tyID unresolvedProperty, bool important, StyleRule::RuleType ruleType) | 803 void CSSParserImpl::consumeDeclarationValue(CSSParserTokenRange range, CSSProper
tyID unresolvedProperty, bool important, StyleRule::RuleType ruleType) |
| 802 { | 804 { |
| 803 CSSPropertyParser::parseValue(unresolvedProperty, important, range, m_contex
t, m_parsedProperties, ruleType); | 805 CSSPropertyParser::parseValue(unresolvedProperty, important, range, m_contex
t, m_parsedProperties, ruleType); |
| 804 } | 806 } |
| 805 | 807 |
| 806 PassOwnPtr<Vector<double>> CSSParserImpl::consumeKeyframeKeyList(CSSParserTokenR
ange range) | 808 std::unique_ptr<Vector<double>> CSSParserImpl::consumeKeyframeKeyList(CSSParserT
okenRange range) |
| 807 { | 809 { |
| 808 OwnPtr<Vector<double>> result = adoptPtr(new Vector<double>); | 810 std::unique_ptr<Vector<double>> result = wrapUnique(new Vector<double>); |
| 809 while (true) { | 811 while (true) { |
| 810 range.consumeWhitespace(); | 812 range.consumeWhitespace(); |
| 811 const CSSParserToken& token = range.consumeIncludingWhitespace(); | 813 const CSSParserToken& token = range.consumeIncludingWhitespace(); |
| 812 if (token.type() == PercentageToken && token.numericValue() >= 0 && toke
n.numericValue() <= 100) | 814 if (token.type() == PercentageToken && token.numericValue() >= 0 && toke
n.numericValue() <= 100) |
| 813 result->append(token.numericValue() / 100); | 815 result->append(token.numericValue() / 100); |
| 814 else if (token.type() == IdentToken && token.valueEqualsIgnoringASCIICas
e("from")) | 816 else if (token.type() == IdentToken && token.valueEqualsIgnoringASCIICas
e("from")) |
| 815 result->append(0); | 817 result->append(0); |
| 816 else if (token.type() == IdentToken && token.valueEqualsIgnoringASCIICas
e("to")) | 818 else if (token.type() == IdentToken && token.valueEqualsIgnoringASCIICas
e("to")) |
| 817 result->append(1); | 819 result->append(1); |
| 818 else | 820 else |
| 819 return nullptr; // Parser error, invalid value in keyframe selector | 821 return nullptr; // Parser error, invalid value in keyframe selector |
| 820 if (range.atEnd()) | 822 if (range.atEnd()) |
| 821 return result; | 823 return result; |
| 822 if (range.consume().type() != CommaToken) | 824 if (range.consume().type() != CommaToken) |
| 823 return nullptr; // Parser error | 825 return nullptr; // Parser error |
| 824 } | 826 } |
| 825 } | 827 } |
| 826 | 828 |
| 827 } // namespace blink | 829 } // namespace blink |
| OLD | NEW |