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

Side by Side Diff: third_party/WebKit/Source/core/css/properties/CSSPropertyAlignmentUtils.cpp

Issue 2762623002: [css-align] Adapt the place-content shorthand to the new baseline syntax (Closed)
Patch Set: Additional refactoring to deal with baseline value ID Created 3 years, 9 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 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
11 namespace blink { 11 namespace blink {
12 12
13 namespace { 13 CSSIdentifierValue* CSSPropertyAlignmentUtils::consumeSelfPositionKeyword(
14 14 CSSParserTokenRange& range) {
15 CSSIdentifierValue* consumeSelfPositionKeyword(CSSParserTokenRange& range) {
16 CSSValueID id = range.peek().id(); 15 CSSValueID id = range.peek().id();
17 if (id == CSSValueStart || id == CSSValueEnd || id == CSSValueCenter || 16 if (id == CSSValueStart || id == CSSValueEnd || id == CSSValueCenter ||
18 id == CSSValueSelfStart || id == CSSValueSelfEnd || 17 id == CSSValueSelfStart || id == CSSValueSelfEnd ||
19 id == CSSValueFlexStart || id == CSSValueFlexEnd || id == CSSValueLeft || 18 id == CSSValueFlexStart || id == CSSValueFlexEnd || id == CSSValueLeft ||
20 id == CSSValueRight) 19 id == CSSValueRight)
21 return CSSPropertyParserHelpers::consumeIdent(range); 20 return CSSPropertyParserHelpers::consumeIdent(range);
22 return nullptr; 21 return nullptr;
23 } 22 }
24 23
25 bool isContentDistributionKeyword(CSSValueID id) { 24 bool CSSPropertyAlignmentUtils::isContentDistributionKeyword(CSSValueID id) {
26 return CSSPropertyParserHelpers::identMatches< 25 return CSSPropertyParserHelpers::identMatches<
27 CSSValueSpaceBetween, CSSValueSpaceAround, CSSValueSpaceEvenly, 26 CSSValueSpaceBetween, CSSValueSpaceAround, CSSValueSpaceEvenly,
28 CSSValueStretch>(id); 27 CSSValueStretch>(id);
29 } 28 }
30 29
31 bool isContentPositionKeyword(CSSValueID id) { 30 bool CSSPropertyAlignmentUtils::isContentPositionKeyword(CSSValueID id) {
32 return CSSPropertyParserHelpers::identMatches< 31 return CSSPropertyParserHelpers::identMatches<
33 CSSValueStart, CSSValueEnd, CSSValueCenter, CSSValueFlexStart, 32 CSSValueStart, CSSValueEnd, CSSValueCenter, CSSValueFlexStart,
34 CSSValueFlexEnd, CSSValueLeft, CSSValueRight>(id); 33 CSSValueFlexEnd, CSSValueLeft, CSSValueRight>(id);
35 } 34 }
36 35
37 bool isOverflowKeyword(CSSValueID id) { 36 bool CSSPropertyAlignmentUtils::isOverflowKeyword(CSSValueID id) {
38 return CSSPropertyParserHelpers::identMatches<CSSValueUnsafe, CSSValueSafe>( 37 return CSSPropertyParserHelpers::identMatches<CSSValueUnsafe, CSSValueSafe>(
39 id); 38 id);
40 } 39 }
41 40
42 bool isBaselineKeyword(CSSValueID id) { 41 bool CSSPropertyAlignmentUtils::isBaselineKeyword(CSSValueID id) {
43 return CSSPropertyParserHelpers::identMatches<CSSValueFirst, CSSValueLast, 42 return CSSPropertyParserHelpers::identMatches<CSSValueFirst, CSSValueLast,
44 CSSValueBaseline>(id); 43 CSSValueBaseline>(id);
45 } 44 }
46 45
47 CSSValue* consumeBaselineKeyword(CSSParserTokenRange& range) { 46 CSSValueID CSSPropertyAlignmentUtils::getBaselineKeyword(CSSValue& value) {
47 if (!value.isValuePair()) {
48 DCHECK(toCSSIdentifierValue(value).getValueID() == CSSValueBaseline);
49 return CSSValueBaseline;
50 }
51
52 DCHECK(toCSSIdentifierValue(toCSSValuePair(value).second()).getValueID() ==
53 CSSValueBaseline);
54 if (toCSSIdentifierValue(toCSSValuePair(value).first()).getValueID() ==
55 CSSValueLast) {
56 return CSSValueLastBaseline;
57 }
58 DCHECK(toCSSIdentifierValue(toCSSValuePair(value).first()).getValueID() ==
59 CSSValueFirst);
60 return CSSValueFirstBaseline;
61 }
62
63 CSSValue* CSSPropertyAlignmentUtils::consumeBaselineKeyword(
64 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,
57 CSSPropertyParserHelpers::consumeIdent(range), 74 CSSPropertyParserHelpers::consumeIdent(range),
58 CSSValuePair::DropIdenticalValues); 75 CSSValuePair::DropIdenticalValues);
59 } 76 }
60 } 77 }
61 return nullptr; 78 return nullptr;
62 } 79 }
63 80
64 } // namespace
65
66 CSSValue* CSSPropertyAlignmentUtils::consumeSelfPositionOverflowPosition( 81 CSSValue* CSSPropertyAlignmentUtils::consumeSelfPositionOverflowPosition(
67 CSSParserTokenRange& range) { 82 CSSParserTokenRange& range) {
68 if (CSSPropertyParserHelpers::identMatches<CSSValueAuto, CSSValueNormal, 83 if (CSSPropertyParserHelpers::identMatches<CSSValueAuto, CSSValueNormal,
69 CSSValueStretch>( 84 CSSValueStretch>(
70 range.peek().id())) 85 range.peek().id()))
71 return CSSPropertyParserHelpers::consumeIdent(range); 86 return CSSPropertyParserHelpers::consumeIdent(range);
72 87
73 if (isBaselineKeyword(range.peek().id())) 88 if (isBaselineKeyword(range.peek().id()))
74 return consumeBaselineKeyword(range); 89 return consumeBaselineKeyword(range);
75 90
(...skipping 21 matching lines...) Expand all
97 if (CSSPropertyParserHelpers::identMatches<CSSValueNormal>(id)) { 112 if (CSSPropertyParserHelpers::identMatches<CSSValueNormal>(id)) {
98 return CSSContentDistributionValue::create( 113 return CSSContentDistributionValue::create(
99 CSSValueInvalid, range.consumeIncludingWhitespace().id(), 114 CSSValueInvalid, range.consumeIncludingWhitespace().id(),
100 CSSValueInvalid); 115 CSSValueInvalid);
101 } 116 }
102 117
103 if (isBaselineKeyword(id)) { 118 if (isBaselineKeyword(id)) {
104 CSSValue* baseline = consumeBaselineKeyword(range); 119 CSSValue* baseline = consumeBaselineKeyword(range);
105 if (!baseline) 120 if (!baseline)
106 return nullptr; 121 return nullptr;
107 CSSValueID baselineID = CSSValueBaseline; 122 return CSSContentDistributionValue::create(
108 if (baseline->isValuePair()) { 123 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 } 124 }
119 125
120 CSSValueID distribution = CSSValueInvalid; 126 CSSValueID distribution = CSSValueInvalid;
121 CSSValueID position = CSSValueInvalid; 127 CSSValueID position = CSSValueInvalid;
122 CSSValueID overflow = CSSValueInvalid; 128 CSSValueID overflow = CSSValueInvalid;
123 do { 129 do {
124 if (isContentDistributionKeyword(id)) { 130 if (isContentDistributionKeyword(id)) {
125 if (distribution != CSSValueInvalid) 131 if (distribution != CSSValueInvalid)
126 return nullptr; 132 return nullptr;
127 distribution = id; 133 distribution = id;
(...skipping 19 matching lines...) Expand all
147 153
148 // The grammar states that <overflow-position> must be associated to 154 // The grammar states that <overflow-position> must be associated to
149 // <content-position>. 155 // <content-position>.
150 if (overflow != CSSValueInvalid && position == CSSValueInvalid) 156 if (overflow != CSSValueInvalid && position == CSSValueInvalid)
151 return nullptr; 157 return nullptr;
152 158
153 return CSSContentDistributionValue::create(distribution, position, overflow); 159 return CSSContentDistributionValue::create(distribution, position, overflow);
154 } 160 }
155 161
156 } // namespace blink 162 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698