Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/cssom/CSSStyleVariableReferenceValue.h" | |
| 16 #include "core/css/parser/CSSPropertyParser.h" | 17 #include "core/css/parser/CSSPropertyParser.h" |
| 17 #include "core/css/parser/CSSTokenizer.h" | 18 #include "core/css/parser/CSSTokenizer.h" |
| 18 #include "core/dom/ExceptionCode.h" | 19 #include "core/dom/ExceptionCode.h" |
| 19 #include "platform/heap/HeapAllocator.h" | 20 #include "platform/heap/HeapAllocator.h" |
| 20 #include "wtf/text/StringBuilder.h" | 21 #include "wtf/text/StringBuilder.h" |
| 21 | 22 |
| 22 | 23 |
| 23 namespace blink { | 24 namespace blink { |
| 24 | 25 |
| 25 namespace { | 26 namespace { |
| 26 | 27 |
| 27 class TokenStreamValueIterationSource final : public ValueIterable<String>::Iter ationSource { | 28 class TokenStreamValueIterationSource final : public ValueIterable<StringOrCSSVa riableReferenceValue>::IterationSource { |
| 28 public: | 29 public: |
| 29 explicit TokenStreamValueIterationSource(CSSTokenStreamValue* tokenStreamVal ue) | 30 explicit TokenStreamValueIterationSource(CSSTokenStreamValue* tokenStreamVal ue) |
| 30 : m_tokenStreamValue(tokenStreamValue) | 31 : m_tokenStreamValue(tokenStreamValue) |
| 31 { | 32 { |
| 32 } | 33 } |
| 33 | 34 |
| 34 bool next(ScriptState* scriptState, String& value, ExceptionState& exception State) override | 35 bool next(ScriptState* scriptState, StringOrCSSVariableReferenceValue& value , ExceptionState& exceptionState) override |
| 35 { | 36 { |
| 36 if (m_index >= m_tokenStreamValue->size()) | 37 if (m_index >= m_tokenStreamValue->size()) |
| 37 return false; | 38 return false; |
| 38 value = m_tokenStreamValue->referenceAtIndex(m_index); | 39 value = m_tokenStreamValue->referenceAtIndex(m_index); |
| 39 return true; | 40 return true; |
| 40 } | 41 } |
| 41 | 42 |
| 42 DEFINE_INLINE_VIRTUAL_TRACE() | 43 DEFINE_INLINE_VIRTUAL_TRACE() |
| 43 { | 44 { |
| 44 visitor->trace(m_tokenStreamValue); | 45 visitor->trace(m_tokenStreamValue); |
| 45 ValueIterable<String>::IterationSource::trace(visitor); | 46 ValueIterable<StringOrCSSVariableReferenceValue>::IterationSource::trace (visitor); |
| 46 } | 47 } |
| 47 | 48 |
| 48 private: | 49 private: |
| 49 const Member<CSSTokenStreamValue> m_tokenStreamValue; | 50 const Member<CSSTokenStreamValue> m_tokenStreamValue; |
| 50 }; | 51 }; |
| 51 | 52 |
| 52 } // namespace | 53 } // namespace |
| 53 | 54 |
| 54 ValueIterable<String>::IterationSource* CSSTokenStreamValue::startIteration(Scri ptState*, ExceptionState&) | 55 ValueIterable<StringOrCSSVariableReferenceValue>::IterationSource* CSSTokenStrea mValue::startIteration(ScriptState*, ExceptionState&) |
| 55 { | 56 { |
| 56 return new TokenStreamValueIterationSource(this); | 57 return new TokenStreamValueIterationSource(this); |
| 57 } | 58 } |
| 58 | 59 |
| 59 CSSValue* CSSTokenStreamValue::toCSSValue() const | 60 CSSValue* CSSTokenStreamValue::toCSSValue() const |
| 60 { | 61 { |
| 61 StringBuilder tokens; | 62 StringBuilder tokens; |
| 62 | 63 |
| 63 for (unsigned i = 0; i < m_listOfReferences.size(); ++i) { | 64 for (unsigned i = 0; i < m_listOfReferences.size(); i++) { |
| 64 if (i) | 65 if (i) |
| 65 tokens.append("/**/"); | 66 tokens.append("/**/"); |
| 66 tokens.append(m_listOfReferences[i]); | 67 if (m_listOfReferences[i].isString()) |
| 68 tokens.append(m_listOfReferences[i].getAsString()); | |
| 69 else | |
| 70 tokens.append(m_listOfReferences[i].getAsCSSVariableReferenceValue() ->variable()); | |
|
meade_UTC10
2016/07/18 06:21:38
Theoretically it could still be null, how about th
| |
| 67 } | 71 } |
| 68 | 72 |
| 69 CSSTokenizer::Scope scope(tokens.toString()); | 73 CSSTokenizer::Scope scope(tokens.toString()); |
| 70 | 74 |
| 71 return CSSVariableReferenceValue::create(CSSVariableData::create(scope.token Range())); | 75 return CSSVariableReferenceValue::create(CSSVariableData::create(scope.token Range())); |
| 72 } | 76 } |
| 73 | 77 |
| 74 } // namespace blink | 78 } // namespace blink |
| OLD | NEW |