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/CSSOMTypes.h" | 5 #include "core/css/cssom/CSSOMTypes.h" |
6 | 6 |
7 #include "core/css/CSSPropertyMetadata.h" | 7 #include "core/css/CSSPropertyMetadata.h" |
8 #include "core/css/cssom/CSSOMKeywords.h" | 8 #include "core/css/cssom/CSSOMKeywords.h" |
9 #include "core/css/cssom/CSSKeywordValue.h" | 9 #include "core/css/cssom/CSSKeywordValue.h" |
10 #include "core/css/cssom/CSSLengthValue.h" | 10 #include "core/css/cssom/CSSLengthValue.h" |
| 11 #include "core/css/cssom/CSSStyleValue.h" |
11 | 12 |
12 namespace blink { | 13 namespace blink { |
13 | 14 |
14 bool CSSOMTypes::propertyCanTake(CSSPropertyID id, const CSSStyleValue& styleVal
ue) | 15 bool CSSOMTypes::propertyCanTake(CSSPropertyID id, const CSSStyleValue& styleVal
ue) |
15 { | 16 { |
16 // Shortcut special case. | 17 // Shortcut special case. |
17 if (styleValue.type() == CSSStyleValue::SimpleLengthType || styleValue.type(
) == CSSStyleValue::CalcLengthType) { | 18 if (styleValue.type() == CSSStyleValue::SimpleLengthType || styleValue.type(
) == CSSStyleValue::CalcLengthType) { |
18 if (toCSSLengthValue(styleValue).containsPercent() && !CSSPropertyMetada
ta::propertySupportsPercentage(id)) { | 19 if (toCSSLengthValue(styleValue).containsPercent() && !CSSPropertyMetada
ta::propertySupportsPercentage(id)) { |
19 return false; | 20 return false; |
20 } | 21 } |
21 } else if (styleValue.type() == CSSStyleValue::KeywordType) { | 22 } else if (styleValue.type() == CSSStyleValue::KeywordType) { |
22 // Keywords are also handled differently. | 23 // Keywords are also handled differently. |
23 return CSSOMKeywords::validKeywordForProperty(id, toCSSKeywordValue(styl
eValue)); | 24 return CSSOMKeywords::validKeywordForProperty(id, toCSSKeywordValue(styl
eValue)); |
24 } else if (styleValue.type() == CSSStyleValue::Unknown) { | 25 } else if (styleValue.type() == CSSStyleValue::Unknown) { |
25 // The check happens later in this case. | 26 // The check happens later in this case. |
26 return true; | 27 return true; |
27 } | 28 } |
28 | 29 |
| 30 return CSSOMTypes::propertyCanTakeType(id, styleValue.type()); |
| 31 } |
| 32 |
| 33 bool CSSOMTypes::propertyCanTakeType(CSSPropertyID id, CSSStyleValue::StyleValue
Type type) |
| 34 { |
| 35 |
29 switch (id) { | 36 switch (id) { |
30 {% for property_id, property in properties.items() if property.typedom_types
%} | 37 {% for property_id, property in properties.items() if property.typedom_types
%} |
31 case {{property_id}}: | 38 case {{property_id}}: |
32 return ( | 39 return ( |
33 {% for type in property.typedom_types %} | 40 {% for type in property.typedom_types %} |
34 {{ "|| " if not loop.first }}styleValue.type() == CSSStyleValue::{{type}
}Type | 41 {{ "|| " if not loop.first }}type == CSSStyleValue::{{type}}Type |
35 {% endfor %} | 42 {% endfor %} |
36 ); | 43 ); |
37 {% endfor %} | 44 {% endfor %} |
38 default: | 45 default: |
39 return false; | 46 return false; |
40 } | 47 } |
41 } | 48 } |
42 | 49 |
43 } // namespace blink | 50 } // namespace blink |
OLD | NEW |