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

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

Issue 2140073002: [Typed-OM] Add compound type of CSSVariableReferenceValue and String with some tests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@CSSTokenStreamValue
Patch Set: Removed unrelated files 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "core/css/cssom/CSSTokenStreamValue.h" 5 #include "core/css/cssom/CSSTokenStreamValue.h"
6 6
7 #include "bindings/core/v8/ExceptionState.h" 7 #include "bindings/core/v8/ExceptionState.h"
8 #include "bindings/core/v8/Iterable.h" 8 #include "bindings/core/v8/Iterable.h"
9 #include "bindings/core/v8/ScriptWrappable.h" 9 #include "bindings/core/v8/ScriptWrappable.h"
10 #include "core/CoreExport.h" 10 #include "core/CoreExport.h"
11 #include "core/css/CSSCustomIdentValue.h" 11 #include "core/css/CSSCustomIdentValue.h"
12 #include "core/css/CSSPrimitiveValue.h" 12 #include "core/css/CSSPrimitiveValue.h"
13 #include "core/css/CSSValueList.h" 13 #include "core/css/CSSValueList.h"
14 #include "core/css/CSSVariableReferenceValue.h" 14 #include "core/css/CSSVariableReferenceValue.h"
15 #include "core/css/cssom/CSSStyleValue.h" 15 #include "core/css/cssom/CSSStyleValue.h"
16 #include "core/css/parser/CSSPropertyParser.h" 16 #include "core/css/parser/CSSPropertyParser.h"
17 #include "core/css/parser/CSSTokenizer.h" 17 #include "core/css/parser/CSSTokenizer.h"
18 #include "core/dom/ExceptionCode.h" 18 #include "core/dom/ExceptionCode.h"
19 #include "platform/heap/HeapAllocator.h" 19 #include "platform/heap/HeapAllocator.h"
20 #include "wtf/text/StringBuilder.h" 20 #include "wtf/text/StringBuilder.h"
21 21
22 22
23 namespace blink { 23 namespace blink {
24 24
25 namespace { 25 namespace {
26 26
27 class TokenStreamValueIterationSource final : public ValueIterable<String>::Iter ationSource { 27 class TokenStreamValueIterationSource final : public ValueIterable<StringOrCSSVa riableReferenceValue>::IterationSource {
28 public: 28 public:
29 explicit TokenStreamValueIterationSource(CSSTokenStreamValue* tokenStreamVal ue) 29 explicit TokenStreamValueIterationSource(CSSTokenStreamValue* tokenStreamVal ue)
30 : m_tokenStreamValue(tokenStreamValue) 30 : m_tokenStreamValue(tokenStreamValue)
31 { 31 {
32 } 32 }
33 33
34 bool next(ScriptState* scriptState, String& value, ExceptionState& exception State) override 34 bool next(ScriptState* scriptState, StringOrCSSVariableReferenceValue& value , ExceptionState& exceptionState) override
35 { 35 {
36 if (m_index >= m_tokenStreamValue->size()) 36 if (m_index >= m_tokenStreamValue->size())
37 return false; 37 return false;
38 value = m_tokenStreamValue->referenceAtIndex(m_index); 38 value = m_tokenStreamValue->referenceAtIndex(m_index);
39 return true; 39 return true;
40 } 40 }
41 41
42 DEFINE_INLINE_VIRTUAL_TRACE() 42 DEFINE_INLINE_VIRTUAL_TRACE()
43 { 43 {
44 visitor->trace(m_tokenStreamValue); 44 visitor->trace(m_tokenStreamValue);
45 ValueIterable<String>::IterationSource::trace(visitor); 45 ValueIterable<StringOrCSSVariableReferenceValue>::IterationSource::trace (visitor);
46 } 46 }
47 47
48 private: 48 private:
49 const Member<CSSTokenStreamValue> m_tokenStreamValue; 49 const Member<CSSTokenStreamValue> m_tokenStreamValue;
50 }; 50 };
51 51
52 } // namespace 52 } // namespace
53 53
54 ValueIterable<String>::IterationSource* CSSTokenStreamValue::startIteration(Scri ptState*, ExceptionState&) 54 ValueIterable<StringOrCSSVariableReferenceValue>::IterationSource* CSSTokenStrea mValue::startIteration(ScriptState*, ExceptionState&)
55 { 55 {
56 return new TokenStreamValueIterationSource(this); 56 return new TokenStreamValueIterationSource(this);
57 } 57 }
58 58
59 CSSValue* CSSTokenStreamValue::toCSSValue() const 59 CSSValue* CSSTokenStreamValue::toCSSValue() const
60 { 60 {
61 StringBuilder tokens; 61 StringBuilder tokens;
62 62
63 for (unsigned i = 0; i < m_listOfReferences.size(); ++i) { 63 for (unsigned i = 0; i < m_listOfReferences.size(); i++) {
64 if (i) 64 if (i)
65 tokens.append("/**/"); 65 tokens.append("/**/");
66 tokens.append(m_listOfReferences[i]); 66 tokens.append(m_listOfReferences[i].getAsString());
meade_UTC10 2016/07/14 00:59:30 You need to check m_listOfReferences[i].isString(
anthonyhkf 2016/07/15 11:58:43 Done.
67 } 67 }
68 68
69 CSSTokenizer::Scope scope(tokens.toString()); 69 CSSTokenizer::Scope scope(tokens.toString());
70 70
71 return CSSVariableReferenceValue::create(CSSVariableData::create(scope.token Range())); 71 return CSSVariableReferenceValue::create(CSSVariableData::create(scope.token Range()));
72 } 72 }
73 73
74 } // namespace blink 74 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698