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

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

Issue 2251663002: [Typed-OM] Get CSSTokenStreamValue from StyleMap (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add layouttest Created 4 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 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 "core/css/CSSVariableReferenceValue.h" 7 #include "core/css/CSSVariableReferenceValue.h"
8 #include "core/css/cssom/CSSStyleVariableReferenceValue.h" 8 #include "core/css/cssom/CSSStyleVariableReferenceValue.h"
9 #include "core/css/parser/CSSTokenizer.h" 9 #include "core/css/parser/CSSTokenizer.h"
10 #include "wtf/text/StringBuilder.h" 10 #include "wtf/text/StringBuilder.h"
(...skipping 27 matching lines...) Expand all
38 const Member<CSSTokenStreamValue> m_tokenStreamValue; 38 const Member<CSSTokenStreamValue> m_tokenStreamValue;
39 }; 39 };
40 40
41 } // namespace 41 } // namespace
42 42
43 ValueIterable<StringOrCSSVariableReferenceValue>::IterationSource* CSSTokenStrea mValue::startIteration(ScriptState*, ExceptionState&) 43 ValueIterable<StringOrCSSVariableReferenceValue>::IterationSource* CSSTokenStrea mValue::startIteration(ScriptState*, ExceptionState&)
44 { 44 {
45 return new TokenStreamValueIterationSource(this); 45 return new TokenStreamValueIterationSource(this);
46 } 46 }
47 47
48 CSSTokenStreamValue* CSSTokenStreamValue::fromCSSValue(const CSSValue& cssValue)
meade_UTC10 2016/08/19 08:43:51 It'd be more correct to take a CSSVariableReferenc
anthonyhkf 2016/08/22 03:19:21 Done.
49 {
50 StringBuilder builder;
51 return CSSTokenStreamValue::fromParserTokenRange(toCSSVariableReferenceValue (cssValue).variableDataValue()->tokenRange(), builder, false);
52 }
53
54 void parseTokenRangeToFragments(CSSParserTokenRange range, HeapVector<StringOrCS SVariableReferenceValue>& fragments, StringBuilder& builder, bool isInsideVariab le)
meade_UTC10 2016/08/19 08:43:51 Put this helper function up in the anonymous names
anthonyhkf 2016/08/22 03:19:21 Done.
55 {
56 StringView variable;
meade_UTC10 2016/08/19 08:43:52 This variable needs a more descriptive name - I do
anthonyhkf 2016/08/22 03:19:20 Done.
57 while (!range.atEnd()) {
58 if (range.peek().getBlockType() == CSSParserToken::BlockStart) {
59 if (range.peek().functionId() == CSSValueVar) {
60 fragments.append(StringOrCSSVariableReferenceValue::fromString(b uilder.toString()));
61 builder.clear();
62 CSSTokenStreamValue* tokenStreamValue = CSSTokenStreamValue::fro mParserTokenRange(range.consumeBlock(), builder, true);
meade_UTC10 2016/08/19 08:43:51 It would be clearer if you split out the creation
anthonyhkf 2016/08/22 03:19:21 Done.
63 CSSStyleVariableReferenceValue* variableReferenceValue = CSSStyl eVariableReferenceValue::create(builder.toString(), tokenStreamValue);
64 fragments.append(StringOrCSSVariableReferenceValue::fromCSSVaria bleReferenceValue(variableReferenceValue));
65 builder.clear();
66 } else {
67 range.peek().serialize(builder);
68 parseTokenRangeToFragments(range.consumeBlock(), fragments, buil der, false);
meade_UTC10 2016/08/19 08:43:51 Should you be both serializing the first token, an
anthonyhkf 2016/08/22 03:19:21 I think the consumeBlock() will only return the pa
meade_UTC10 2016/08/22 07:55:47 In that case it might be clearer to do builder.a
69 builder.append(')');
70 }
71 } else {
72 if (range.peek().type() == CSSParserTokenType::CommaToken) {
73 if (!isInsideVariable)
74 builder.append(',');
75 } else if (range.peek().type() == CSSParserTokenType::IdentToken) {
76 variable = range.peek().value();
77 } else {
78 range.peek().serialize(builder);
79 }
80 range.consume();
meade_UTC10 2016/08/19 08:43:51 You should be able simplify these type of calls by
anthonyhkf 2016/08/22 03:19:21 Done.
81 }
82 }
83 if (isInsideVariable) {
84 if (!builder.isEmpty()) {
85 fragments.append(StringOrCSSVariableReferenceValue::fromString(build er.toString()));
86 builder.clear();
87 }
88 builder.append(variable);
89 }
90 }
91
92 CSSTokenStreamValue* CSSTokenStreamValue::fromParserTokenRange(CSSParserTokenRan ge range, StringBuilder& builder, bool isInsideVariable)
93 {
94 HeapVector<StringOrCSSVariableReferenceValue> fragments;
95 parseTokenRangeToFragments(range, fragments, builder, isInsideVariable);
96 if (!builder.isEmpty() && !isInsideVariable) {
97 fragments.append(StringOrCSSVariableReferenceValue::fromString(builder.t oString()));
meade_UTC10 2016/08/19 08:43:51 Can this be moved up into parseTokenFragments? It'
anthonyhkf 2016/08/22 03:19:21 Done.
98 }
99 if (fragments.size() == 0)
100 return nullptr;
meade_UTC10 2016/08/19 08:43:51 If this is a private function, you can DCHECK this
anthonyhkf 2016/08/22 03:19:21 It is possible to happen. This one is for the case
101 return CSSTokenStreamValue::create(fragments);
102 }
103
48 CSSValue* CSSTokenStreamValue::toCSSValue() const 104 CSSValue* CSSTokenStreamValue::toCSSValue() const
49 { 105 {
50 StringBuilder tokens; 106 StringBuilder tokens;
51 107
52 for (unsigned i = 0; i < m_fragments.size(); i++) { 108 for (unsigned i = 0; i < m_fragments.size(); i++) {
53 if (i) 109 if (i)
54 tokens.append("/**/"); 110 tokens.append("/**/");
55 if (m_fragments[i].isString()) 111 if (m_fragments[i].isString())
56 tokens.append(m_fragments[i].getAsString()); 112 tokens.append(m_fragments[i].getAsString());
57 else if (m_fragments[i].isCSSVariableReferenceValue()) 113 else if (m_fragments[i].isCSSVariableReferenceValue())
58 tokens.append(m_fragments[i].getAsCSSVariableReferenceValue()->varia ble()); 114 tokens.append(m_fragments[i].getAsCSSVariableReferenceValue()->varia ble());
59 else 115 else
60 NOTREACHED(); 116 NOTREACHED();
61 } 117 }
62 118
63 CSSTokenizer::Scope scope(tokens.toString()); 119 CSSTokenizer::Scope scope(tokens.toString());
64 120
65 return CSSVariableReferenceValue::create(CSSVariableData::create(scope.token Range())); 121 return CSSVariableReferenceValue::create(CSSVariableData::create(scope.token Range()));
66 } 122 }
67 123
68 } // namespace blink 124 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698