OLD | NEW |
---|---|
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/properties/CSSPropertyAlignmentUtils.h" | 5 #include "core/css/properties/CSSPropertyAlignmentUtils.h" |
6 | 6 |
7 #include "core/css/CSSContentDistributionValue.h" | 7 #include "core/css/CSSContentDistributionValue.h" |
8 #include "core/css/CSSValuePair.h" | 8 #include "core/css/CSSValuePair.h" |
9 #include "core/css/parser/CSSPropertyParserHelpers.h" | 9 #include "core/css/parser/CSSPropertyParserHelpers.h" |
10 | 10 |
(...skipping 26 matching lines...) Expand all Loading... | |
37 bool isOverflowKeyword(CSSValueID id) { | 37 bool isOverflowKeyword(CSSValueID id) { |
38 return CSSPropertyParserHelpers::identMatches<CSSValueUnsafe, CSSValueSafe>( | 38 return CSSPropertyParserHelpers::identMatches<CSSValueUnsafe, CSSValueSafe>( |
39 id); | 39 id); |
40 } | 40 } |
41 | 41 |
42 bool isBaselineKeyword(CSSValueID id) { | 42 bool isBaselineKeyword(CSSValueID id) { |
43 return CSSPropertyParserHelpers::identMatches<CSSValueFirst, CSSValueLast, | 43 return CSSPropertyParserHelpers::identMatches<CSSValueFirst, CSSValueLast, |
44 CSSValueBaseline>(id); | 44 CSSValueBaseline>(id); |
45 } | 45 } |
46 | 46 |
47 CSSValueID getBaselineKeyword(CSSValue& value) { | |
48 if (!value.isValuePair()) { | |
49 DCHECK(toCSSIdentifierValue(value).getValueID() == CSSValueBaseline); | |
50 return CSSValueBaseline; | |
51 } | |
52 | |
53 DCHECK(toCSSIdentifierValue(toCSSValuePair(value).second()).getValueID() == | |
54 CSSValueBaseline); | |
55 if (toCSSIdentifierValue(toCSSValuePair(value).first()).getValueID() == | |
56 CSSValueLast) { | |
57 return CSSValueLastBaseline; | |
58 } | |
59 DCHECK(toCSSIdentifierValue(toCSSValuePair(value).first()).getValueID() == | |
60 CSSValueFirst); | |
61 return CSSValueFirstBaseline; | |
62 } | |
63 | |
47 CSSValue* consumeBaselineKeyword(CSSParserTokenRange& range) { | 64 CSSValue* consumeBaselineKeyword(CSSParserTokenRange& range) { |
48 CSSValueID id = range.peek().id(); | 65 CSSValueID id = range.peek().id(); |
49 if (CSSPropertyParserHelpers::identMatches<CSSValueBaseline>(id)) | 66 if (CSSPropertyParserHelpers::identMatches<CSSValueBaseline>(id)) |
50 return CSSPropertyParserHelpers::consumeIdent(range); | 67 return CSSPropertyParserHelpers::consumeIdent(range); |
51 | 68 |
52 if (CSSIdentifierValue* preference = | 69 if (CSSIdentifierValue* preference = |
53 CSSPropertyParserHelpers::consumeIdent<CSSValueFirst, CSSValueLast>( | 70 CSSPropertyParserHelpers::consumeIdent<CSSValueFirst, CSSValueLast>( |
54 range)) { | 71 range)) { |
55 if (range.peek().id() == CSSValueBaseline) { | 72 if (range.peek().id() == CSSValueBaseline) { |
56 return CSSValuePair::create(preference, | 73 return CSSValuePair::create(preference, |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
97 if (CSSPropertyParserHelpers::identMatches<CSSValueNormal>(id)) { | 114 if (CSSPropertyParserHelpers::identMatches<CSSValueNormal>(id)) { |
98 return CSSContentDistributionValue::create( | 115 return CSSContentDistributionValue::create( |
99 CSSValueInvalid, range.consumeIncludingWhitespace().id(), | 116 CSSValueInvalid, range.consumeIncludingWhitespace().id(), |
100 CSSValueInvalid); | 117 CSSValueInvalid); |
101 } | 118 } |
102 | 119 |
103 if (isBaselineKeyword(id)) { | 120 if (isBaselineKeyword(id)) { |
104 CSSValue* baseline = consumeBaselineKeyword(range); | 121 CSSValue* baseline = consumeBaselineKeyword(range); |
105 if (!baseline) | 122 if (!baseline) |
106 return nullptr; | 123 return nullptr; |
107 CSSValueID baselineID = CSSValueBaseline; | 124 return CSSContentDistributionValue::create( |
108 if (baseline->isValuePair()) { | 125 CSSValueInvalid, getBaselineKeyword(*baseline), CSSValueInvalid); |
109 if (toCSSIdentifierValue(toCSSValuePair(baseline)->first()) | |
110 .getValueID() == CSSValueLast) { | |
111 baselineID = CSSValueLastBaseline; | |
112 } else { | |
113 baselineID = CSSValueFirstBaseline; | |
114 } | |
115 } | |
116 return CSSContentDistributionValue::create(CSSValueInvalid, baselineID, | |
117 CSSValueInvalid); | |
118 } | 126 } |
119 | 127 |
120 CSSValueID distribution = CSSValueInvalid; | 128 CSSValueID distribution = CSSValueInvalid; |
121 CSSValueID position = CSSValueInvalid; | 129 CSSValueID position = CSSValueInvalid; |
122 CSSValueID overflow = CSSValueInvalid; | 130 CSSValueID overflow = CSSValueInvalid; |
123 do { | 131 do { |
124 if (isContentDistributionKeyword(id)) { | 132 if (isContentDistributionKeyword(id)) { |
125 if (distribution != CSSValueInvalid) | 133 if (distribution != CSSValueInvalid) |
126 return nullptr; | 134 return nullptr; |
127 distribution = id; | 135 distribution = id; |
(...skipping 18 matching lines...) Expand all Loading... | |
146 return nullptr; | 154 return nullptr; |
147 | 155 |
148 // The grammar states that <overflow-position> must be associated to | 156 // The grammar states that <overflow-position> must be associated to |
149 // <content-position>. | 157 // <content-position>. |
150 if (overflow != CSSValueInvalid && position == CSSValueInvalid) | 158 if (overflow != CSSValueInvalid && position == CSSValueInvalid) |
151 return nullptr; | 159 return nullptr; |
152 | 160 |
153 return CSSContentDistributionValue::create(distribution, position, overflow); | 161 return CSSContentDistributionValue::create(distribution, position, overflow); |
154 } | 162 } |
155 | 163 |
164 CSSValue* CSSPropertyAlignmentUtils::consumeSimplifiedContentPosition( | |
165 CSSParserTokenRange& range) { | |
166 CSSValueID id = range.peek().id(); | |
167 if (CSSPropertyParserHelpers::identMatches<CSSValueNormal>(id) || | |
Bugs Nash
2017/03/29 21:52:11
Didn't you say you were going to keep CSSValueLast
jfernandez
2017/03/29 22:03:51
Probably I didn't explain it properly. I thought y
| |
168 isContentPositionKeyword(id)) { | |
169 return CSSContentDistributionValue::create( | |
170 CSSValueInvalid, range.consumeIncludingWhitespace().id(), | |
171 CSSValueInvalid); | |
172 } | |
173 | |
174 if (isBaselineKeyword(id)) { | |
175 CSSValue* baseline = consumeBaselineKeyword(range); | |
176 if (!baseline) | |
177 return nullptr; | |
178 return CSSContentDistributionValue::create( | |
179 CSSValueInvalid, getBaselineKeyword(*baseline), CSSValueInvalid); | |
180 } | |
181 | |
182 if (isContentDistributionKeyword(id)) { | |
183 return CSSContentDistributionValue::create( | |
184 range.consumeIncludingWhitespace().id(), CSSValueInvalid, | |
185 CSSValueInvalid); | |
186 } | |
187 return nullptr; | |
188 } | |
189 | |
156 } // namespace blink | 190 } // namespace blink |
OLD | NEW |