Chromium Code Reviews| Index: Source/core/css/CSSVariableData.cpp |
| diff --git a/Source/core/css/CSSVariableData.cpp b/Source/core/css/CSSVariableData.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..39c112f9bcb05a5aee687cbcef66d801bf5b27e2 |
| --- /dev/null |
| +++ b/Source/core/css/CSSVariableData.cpp |
| @@ -0,0 +1,70 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "config.h" |
| +#include "core/css/CSSVariableData.h" |
| + |
| +#include "core/css/parser/CSSParserTokenRange.h" |
| + |
| +namespace blink { |
| + |
| +template<typename CharacterType> void CSSVariableData::consumeAndUpdateTokens(const CSSParserTokenRange& range, const String& baseString) |
| +{ |
| + CSSParserTokenRange localRange = range; |
| + const CharacterType* stringStart = baseString.getCharacters<CharacterType>(); |
| + const CharacterType* stringEnd = stringStart + baseString.length(); |
| + |
| + const CharacterType* maxOffset = nullptr; |
| + const CharacterType* minOffset = nullptr; |
| + |
| + bool lastTokenWasExclamation = false; |
| + unsigned exclamationOffset = 0; |
| + |
| + while (!localRange.atEnd()) { |
| + CSSParserToken token = localRange.consume(); |
| + const CharacterType* tokenLocation = static_cast<const CharacterType*>(token.m_valueDataCharRaw); |
| + if (tokenLocation > stringStart && tokenLocation < stringEnd) { |
| + if (!minOffset) |
| + minOffset = tokenLocation; |
| + maxOffset = tokenLocation + token.m_valueLength; |
| + } else { |
| + String escapedString(tokenLocation, token.m_valueLength); |
| + m_stringPool.append(escapedString); |
| + token.m_valueDataCharRaw = escapedString.getCharacters<CharacterType>(); |
| + } |
| + if (token.type() == DelimiterToken && token.delimiter() == '!') { |
|
Timothy Loh
2015/07/23 08:11:46
consumeDeclaration should handle !important
|
| + lastTokenWasExclamation = true; |
| + exclamationOffset = m_tokens.size(); |
| + } else if (lastTokenWasExclamation) { |
| + if (token.type() == IdentToken && token.valueEqualsIgnoringCase("important")) { |
| + m_tokens.remove(exclamationOffset, m_tokens.size() - exclamationOffset); |
| + lastTokenWasExclamation = false; |
| + continue; |
| + } |
| + if (token.type() != WhitespaceToken) |
| + lastTokenWasExclamation = false; |
| + } |
| + m_tokens.append(token); |
| + } |
| + if (minOffset) { |
| + m_string = String(minOffset, maxOffset - minOffset); |
| + const CharacterType* newStringStart = m_string.getCharacters<CharacterType>(); |
| + for (CSSParserToken& token : m_tokens) { |
| + const CharacterType* tokenLocation = static_cast<const CharacterType*>(token.m_valueDataCharRaw); |
| + if (tokenLocation > stringStart && tokenLocation < stringEnd) |
| + token.m_valueDataCharRaw = newStringStart + (tokenLocation - minOffset); |
| + } |
| + } |
| +} |
| + |
| +CSSVariableData::CSSVariableData(const CSSParserTokenRange& range, const String& baseString, bool needsVariableResolution) |
| + : m_needsVariableResolution(needsVariableResolution) |
| +{ |
| + if (baseString.is8Bit()) |
| + consumeAndUpdateTokens<LChar>(range, baseString); |
| + else |
| + consumeAndUpdateTokens<UChar>(range, baseString); |
| +} |
| + |
| +} // namespace blink |