| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/CSSVariableData.h" | 5 #include "core/css/CSSVariableData.h" |
| 6 | 6 |
| 7 #include "core/css/CSSSyntaxDescriptor.h" | 7 #include "core/css/CSSSyntaxDescriptor.h" |
| 8 #include "core/css/parser/CSSParser.h" | 8 #include "core/css/parser/CSSParser.h" |
| 9 #include "core/css/parser/CSSParserTokenRange.h" | 9 #include "core/css/parser/CSSParserTokenRange.h" |
| 10 #include "wtf/text/StringBuilder.h" | 10 #include "wtf/text/StringBuilder.h" |
| 11 #include "wtf/text/StringView.h" | 11 #include "wtf/text/StringView.h" |
| 12 | 12 |
| 13 namespace blink { | 13 namespace blink { |
| 14 | 14 |
| 15 StylePropertySet* CSSVariableData::propertySet() { | 15 StylePropertySet* CSSVariableData::propertySet() { |
| 16 ASSERT(!m_needsVariableResolution); | 16 DCHECK(!m_needsVariableResolution); |
| 17 if (!m_cachedPropertySet) { | 17 if (!m_cachedPropertySet) { |
| 18 m_propertySet = CSSParser::parseCustomPropertySet(m_tokens); | 18 m_propertySet = CSSParser::parseCustomPropertySet(m_tokens); |
| 19 m_cachedPropertySet = true; | 19 m_cachedPropertySet = true; |
| 20 } | 20 } |
| 21 return m_propertySet.get(); | 21 return m_propertySet.get(); |
| 22 } | 22 } |
| 23 | 23 |
| 24 template <typename CharacterType> | 24 template <typename CharacterType> |
| 25 void CSSVariableData::updateTokens(const CSSParserTokenRange& range) { | 25 void CSSVariableData::updateTokens(const CSSParserTokenRange& range) { |
| 26 const CharacterType* currentOffset = | 26 const CharacterType* currentOffset = |
| 27 m_backingString.getCharacters<CharacterType>(); | 27 m_backingString.getCharacters<CharacterType>(); |
| 28 for (const CSSParserToken& token : range) { | 28 for (const CSSParserToken& token : range) { |
| 29 if (token.hasStringBacking()) { | 29 if (token.hasStringBacking()) { |
| 30 unsigned length = token.value().length(); | 30 unsigned length = token.value().length(); |
| 31 StringView string(currentOffset, length); | 31 StringView string(currentOffset, length); |
| 32 m_tokens.push_back(token.copyWithUpdatedString(string)); | 32 m_tokens.push_back(token.copyWithUpdatedString(string)); |
| 33 currentOffset += length; | 33 currentOffset += length; |
| 34 } else { | 34 } else { |
| 35 m_tokens.push_back(token); | 35 m_tokens.push_back(token); |
| 36 } | 36 } |
| 37 } | 37 } |
| 38 ASSERT(currentOffset == | 38 DCHECK(currentOffset == |
| 39 m_backingString.getCharacters<CharacterType>() + | 39 m_backingString.getCharacters<CharacterType>() + |
| 40 m_backingString.length()); | 40 m_backingString.length()); |
| 41 } | 41 } |
| 42 | 42 |
| 43 bool CSSVariableData::operator==(const CSSVariableData& other) const { | 43 bool CSSVariableData::operator==(const CSSVariableData& other) const { |
| 44 return tokens() == other.tokens(); | 44 return tokens() == other.tokens(); |
| 45 } | 45 } |
| 46 | 46 |
| 47 void CSSVariableData::consumeAndUpdateTokens(const CSSParserTokenRange& range) { | 47 void CSSVariableData::consumeAndUpdateTokens(const CSSParserTokenRange& range) { |
| 48 StringBuilder stringBuilder; | 48 StringBuilder stringBuilder; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 59 else | 59 else |
| 60 updateTokens<UChar>(range); | 60 updateTokens<UChar>(range); |
| 61 } | 61 } |
| 62 | 62 |
| 63 CSSVariableData::CSSVariableData(const CSSParserTokenRange& range, | 63 CSSVariableData::CSSVariableData(const CSSParserTokenRange& range, |
| 64 bool isAnimationTainted, | 64 bool isAnimationTainted, |
| 65 bool needsVariableResolution) | 65 bool needsVariableResolution) |
| 66 : m_isAnimationTainted(isAnimationTainted), | 66 : m_isAnimationTainted(isAnimationTainted), |
| 67 m_needsVariableResolution(needsVariableResolution), | 67 m_needsVariableResolution(needsVariableResolution), |
| 68 m_cachedPropertySet(false) { | 68 m_cachedPropertySet(false) { |
| 69 ASSERT(!range.atEnd()); | 69 DCHECK(!range.atEnd()); |
| 70 consumeAndUpdateTokens(range); | 70 consumeAndUpdateTokens(range); |
| 71 } | 71 } |
| 72 | 72 |
| 73 const CSSValue* CSSVariableData::parseForSyntax( | 73 const CSSValue* CSSVariableData::parseForSyntax( |
| 74 const CSSSyntaxDescriptor& syntax) const { | 74 const CSSSyntaxDescriptor& syntax) const { |
| 75 DCHECK(!needsVariableResolution()); | 75 DCHECK(!needsVariableResolution()); |
| 76 // TODO(timloh): This probably needs a proper parser context for | 76 // TODO(timloh): This probably needs a proper parser context for |
| 77 // relative URL resolution. | 77 // relative URL resolution. |
| 78 return syntax.parse(tokenRange(), strictCSSParserContext(), | 78 return syntax.parse(tokenRange(), strictCSSParserContext(), |
| 79 m_isAnimationTainted); | 79 m_isAnimationTainted); |
| 80 } | 80 } |
| 81 | 81 |
| 82 } // namespace blink | 82 } // namespace blink |
| OLD | NEW |