| 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/CSSStyleValue.h" | 10 #include "core/css/cssom/CSSStyleValue.h" |
| 11 | 11 |
| 12 namespace blink { | 12 namespace blink { |
| 13 | 13 |
| 14 bool CSSOMTypes::PropertyCanTake(CSSPropertyID id, | 14 bool CSSOMTypes::PropertyCanTake(CSSPropertyID id, |
| 15 const CSSStyleValue& styleValue) { | 15 const CSSStyleValue& styleValue) { |
| 16 // Shortcut special case. | 16 if (styleValue.GetType() == CSSStyleValue::kKeywordType) { |
| 17 if (styleValue.GetType() == CSSStyleValue::kSimpleLengthType || | |
| 18 styleValue.GetType() == CSSStyleValue::kCalcLengthType) { | |
| 19 // TODO(meade): Rewrite this once the new length types are spec'd. | |
| 20 // if (ToCSSLengthValue(styleValue).ContainsPercent() && | |
| 21 // !CSSPropertyMetadata::PropertySupportsPercentage(id)) { | |
| 22 // return false; | |
| 23 // } | |
| 24 } else if (styleValue.GetType() == CSSStyleValue::kKeywordType) { | |
| 25 // Keywords are also handled differently. | |
| 26 return CSSOMKeywords::ValidKeywordForProperty( | 17 return CSSOMKeywords::ValidKeywordForProperty( |
| 27 id, ToCSSKeywordValue(styleValue)); | 18 id, ToCSSKeywordValue(styleValue)); |
| 28 } else if (styleValue.GetType() == CSSStyleValue::kUnknown) { | 19 } |
| 20 if (styleValue.ContainsPercent() && |
| 21 !CSSPropertyMetadata::PropertySupportsPercentage(id)) { |
| 22 return false; |
| 23 } |
| 24 if (styleValue.GetType() == CSSStyleValue::kUnknownType) { |
| 29 // The check happens later in this case. | 25 // The check happens later in this case. |
| 30 return true; | 26 return true; |
| 31 } | 27 } |
| 32 | 28 |
| 33 return CSSOMTypes::PropertyCanTakeType(id, styleValue.GetType()); | 29 return CSSOMTypes::PropertyCanTakeType(id, styleValue.GetType()); |
| 34 } | 30 } |
| 35 | 31 |
| 36 bool CSSOMTypes::PropertyCanTakeType(CSSPropertyID id, | 32 bool CSSOMTypes::PropertyCanTakeType(CSSPropertyID id, |
| 37 CSSStyleValue::StyleValueType type) { | 33 CSSStyleValue::StyleValueType type) { |
| 38 switch (id) { | 34 switch (id) { |
| 39 {% for property_id, property in properties.items() if property.typedom_types
%} | 35 {% for property_id, property in properties.items() if property.typedom_types
%} |
| 40 case {{property_id}}: | 36 case {{property_id}}: |
| 41 return ( | 37 return ( |
| 42 {% for type in property.typedom_types %} | 38 {% for type in property.typedom_types %} |
| 43 {{ "|| " if not loop.first }}type == CSSStyleValue::k{{type}}Type | 39 {{ "|| " if not loop.first }}type == CSSStyleValue::k{{type}}Type |
| 44 {% endfor %} | 40 {% endfor %} |
| 45 ); | 41 ); |
| 46 {% endfor %} | 42 {% endfor %} |
| 47 default: | 43 default: |
| 48 return false; | 44 return false; |
| 49 } | 45 } |
| 50 } | 46 } |
| 51 | 47 |
| 52 } // namespace blink | 48 } // namespace blink |
| OLD | NEW |