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

Unified Diff: third_party/WebKit/Source/core/css/cssom/CSSTokenStreamValue.cpp

Issue 2122193003: [Typed-OM] Add CSSTokenStreamValue (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add test for CSSTokenStreamValue Created 4 years, 5 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/cssom/CSSTokenStreamValue.cpp
diff --git a/third_party/WebKit/Source/core/css/cssom/CSSTokenStreamValue.cpp b/third_party/WebKit/Source/core/css/cssom/CSSTokenStreamValue.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..9331c5e7c87045d72786f81ef48157b42a656145
--- /dev/null
+++ b/third_party/WebKit/Source/core/css/cssom/CSSTokenStreamValue.cpp
@@ -0,0 +1,62 @@
+// Copyright 2016 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 "core/css/cssom/CSSTokenStreamValue.h"
+
+#include "core/css/CSSVariableReferenceValue.h"
+#include "core/css/parser/CSSTokenizer.h"
+#include "wtf/text/StringBuilder.h"
+
+namespace blink {
+
+namespace {
+
+class TokenStreamValueIterationSource final : public ValueIterable<String>::IterationSource {
+public:
+ explicit TokenStreamValueIterationSource(CSSTokenStreamValue* tokenStreamValue)
+ : m_tokenStreamValue(tokenStreamValue)
+ {
+ }
+
+ bool next(ScriptState*, String& value, ExceptionState&) override
+ {
+ if (m_index >= m_tokenStreamValue->size())
+ return false;
+ value = m_tokenStreamValue->fragmentAtIndex(m_index);
+ return true;
+ }
+
+ DEFINE_INLINE_VIRTUAL_TRACE()
+ {
+ visitor->trace(m_tokenStreamValue);
+ ValueIterable<String>::IterationSource::trace(visitor);
+ }
+
+private:
+ const Member<CSSTokenStreamValue> m_tokenStreamValue;
+};
+
+} // namespace
+
+ValueIterable<String>::IterationSource* CSSTokenStreamValue::startIteration(ScriptState*, ExceptionState&)
+{
+ return new TokenStreamValueIterationSource(this);
+}
+
+CSSValue* CSSTokenStreamValue::toCSSValue() const
+{
+ StringBuilder tokens;
+
+ for (unsigned i = 0; i < m_fragments.size(); i++) {
+ if (i)
+ tokens.append("/**/");
+ tokens.append(m_fragments[i]);
+ }
+
+ CSSTokenizer::Scope scope(tokens.toString());
+
+ return CSSVariableReferenceValue::create(CSSVariableData::create(scope.tokenRange()));
+}
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698