OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "core/css/CSSSyntaxDescriptor.h" |
| 6 |
| 7 #include "core/css/CSSCustomPropertyDeclaration.h" |
| 8 #include "core/css/CSSURIValue.h" |
| 9 #include "core/css/CSSValueList.h" |
| 10 #include "core/css/CSSVariableReferenceValue.h" |
| 11 #include "core/css/parser/CSSPropertyParserHelpers.h" |
| 12 #include "core/css/parser/CSSTokenizer.h" |
| 13 #include "core/css/parser/CSSVariableParser.h" |
| 14 |
| 15 namespace blink { |
| 16 |
| 17 CSSSyntaxDescriptor::CSSSyntaxDescriptor(String input) |
| 18 { |
| 19 // TODO(timloh): Implement proper parsing |
| 20 if (input.contains('*')) |
| 21 m_syntaxComponents.append(CSSSyntaxComponent(CSSSyntaxType::TokenStream)
); |
| 22 else |
| 23 m_syntaxComponents.append(CSSSyntaxComponent(CSSSyntaxType::Length)); |
| 24 } |
| 25 |
| 26 const CSSValue* consumeSingleType(const CSSSyntaxComponent& syntax, CSSParserTok
enRange& range) |
| 27 { |
| 28 using namespace CSSPropertyParserHelpers; |
| 29 |
| 30 // TODO(timloh): Calc values need to be normalized |
| 31 switch (syntax.m_type) { |
| 32 case CSSSyntaxType::Length: |
| 33 return consumeLength(range, HTMLStandardMode, ValueRange::ValueRangeAll)
; |
| 34 default: |
| 35 NOTREACHED(); |
| 36 return nullptr; |
| 37 } |
| 38 } |
| 39 |
| 40 const CSSValue* consumeSyntaxComponent(const CSSSyntaxComponent& syntax, CSSPars
erTokenRange range) |
| 41 { |
| 42 // CSS-wide keywords are already handled by the CSSPropertyParser |
| 43 const CSSValue* result = consumeSingleType(syntax, range); |
| 44 if (!range.atEnd()) |
| 45 return nullptr; |
| 46 return result; |
| 47 } |
| 48 |
| 49 const CSSValue* CSSSyntaxDescriptor::parse(const String& value) const |
| 50 { |
| 51 CSSTokenizer::Scope scope(value); |
| 52 return parse(scope.tokenRange()); |
| 53 } |
| 54 |
| 55 const CSSValue* CSSSyntaxDescriptor::parse(CSSParserTokenRange range) const |
| 56 { |
| 57 if (isTokenStream()) |
| 58 return CSSVariableParser::parseRegisteredPropertyValue(range, false); |
| 59 range.consumeWhitespace(); |
| 60 for (const CSSSyntaxComponent& component : m_syntaxComponents) { |
| 61 if (const CSSValue* result = consumeSyntaxComponent(component, range)) |
| 62 return result; |
| 63 } |
| 64 return CSSVariableParser::parseRegisteredPropertyValue(range, true); |
| 65 } |
| 66 |
| 67 } // namespace blink |
OLD | NEW |