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

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

Issue 1192983003: CSS Custom Properties (Variables) (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Post-merge Created 5 years, 3 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: third_party/WebKit/Source/core/css/CSSVariableData.cpp
diff --git a/third_party/WebKit/Source/core/css/CSSVariableData.cpp b/third_party/WebKit/Source/core/css/CSSVariableData.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..45df40376519d63b7fcf454b78c6433b5de32ab2
--- /dev/null
+++ b/third_party/WebKit/Source/core/css/CSSVariableData.cpp
@@ -0,0 +1,55 @@
+// 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::updateTokens()
+{
+ const CharacterType* currentOffset = m_string.getCharacters<CharacterType>();
+ for (auto&& token : m_tokens) {
+ if (!token.needsStringBacking())
+ continue;
+
+ token.m_valueDataCharRaw = currentOffset;
Timothy Loh 2015/09/30 02:09:27 How about building m_tokens in this function inste
+ currentOffset += token.m_valueLength;
+ }
+ ASSERT(currentOffset == m_string.getCharacters<CharacterType>() + m_string.length());
+}
+
+void CSSVariableData::consumeAndUpdateTokens(const CSSParserTokenRange& range)
+{
+ StringBuilder stringBuilder;
+ CSSParserTokenRange localRange = range;
+
+ while (!localRange.atEnd()) {
+ CSSParserToken token = localRange.consume();
+ if (token.needsStringBacking()) {
+ if (token.valueIs8Bit())
Timothy Loh 2015/09/30 02:09:27 Let's just get the string data off token.value() i
+ stringBuilder.append(static_cast<const LChar*>(token.m_valueDataCharRaw), token.m_valueLength);
+ else
+ stringBuilder.append(static_cast<const UChar*>(token.m_valueDataCharRaw), token.m_valueLength);
+ }
+ m_tokens.append(token);
+ }
+ m_string = stringBuilder.toString();
+ if (m_string.is8Bit())
+ updateTokens<LChar>();
+ else
+ updateTokens<UChar>();
+}
+
+CSSVariableData::CSSVariableData(const CSSParserTokenRange& range, bool needsVariableResolution)
+ : m_needsVariableResolution(needsVariableResolution)
+{
+ ASSERT(!range.atEnd());
+ consumeAndUpdateTokens(range);
+}
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698