Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(478)

Unified Diff: Source/core/css/CSSVariableData.cpp

Issue 1192983003: CSS Custom Properties (Variables) (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: ToTed Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..3bfbfc67965fb889927dae8352da7e3af0f86a48
--- /dev/null
+++ b/Source/core/css/CSSVariableData.cpp
@@ -0,0 +1,47 @@
+// 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"
+#include "wtf/text/StringBuilder.h"
+
+namespace blink {
+
+template<typename CharacterType> void CSSVariableData::consumeAndUpdateTokens(const CSSParserTokenRange& range)
+{
+ StringBuilder stringBuilder;
+ CSSParserTokenRange localRange = range;
+ const CharacterType* currentOffset = nullptr;
+
+ while (!localRange.atEnd()) {
+ CSSParserToken token = localRange.consume();
Timothy Loh 2015/08/25 09:21:09 const CSSParserToken&
+ const CharacterType* tokenLocation = static_cast<const CharacterType*>(token.m_valueDataCharRaw);
Timothy Loh 2015/08/25 09:21:09 We should check the token type is string-y (probab
+ stringBuilder.append(tokenLocation, token.m_valueLength);
+ currentOffset += token.m_valueLength;
Timothy Loh 2015/08/25 09:21:09 Not used? Just define the variable below when it's
+ m_tokens.append(token);
+ }
+ m_string = stringBuilder.toString();
+ currentOffset = m_string.getCharacters<CharacterType>();
+ for (auto&& token : m_tokens) {
+ token.m_valueDataCharRaw = currentOffset;
+ currentOffset += token.m_valueLength;
+ }
+ ASSERT(currentOffset == m_string.getCharacters<CharacterType>() + m_string.length());
+}
+
+CSSVariableData::CSSVariableData(const CSSParserTokenRange& range, bool needsVariableResolution)
+ : m_needsVariableResolution(needsVariableResolution)
+{
+ ASSERT(!range.atEnd());
+ // TODO(leviw): We probably can't assume that the first value being 8bit guarantees
Timothy Loh 2015/08/25 09:21:09 It doesn't; just fix up the function above to call
+ // that all are.
+ if (range.peek().valueIs8Bit())
+ consumeAndUpdateTokens<LChar>(range);
+ else
+ consumeAndUpdateTokens<UChar>(range);
+}
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698