| 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..f44d8108dd87a5311e48a0e2310098be5feb159d
|
| --- /dev/null
|
| +++ b/Source/core/css/CSSVariableData.cpp
|
| @@ -0,0 +1,72 @@
|
| +// 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)
|
| +{
|
| + CSSParserTokenRange localRange = range;
|
| + String baseString = localRange.scope()->string();
|
| + 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() == '!') {
|
| + lastTokenWasExclamation = true;
|
| + exclamationOffset = m_tokens.size();
|
| + } else if (lastTokenWasExclamation) {
|
| + if (token.type() == IdentToken && token.valueEqualsIgnoringCase("important")) {
|
| + m_important = true;
|
| + 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, bool needsVariableResolution)
|
| + : m_needsVariableResolution(needsVariableResolution)
|
| +{
|
| + if (range.scope()->string().is8Bit())
|
| + consumeAndUpdateTokens<LChar>(range);
|
| + else
|
| + consumeAndUpdateTokens<UChar>(range);
|
| +}
|
| +
|
| +} // namespace blink
|
|
|