| 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/InlineStylePropertyMap.h" | 5 #include "core/css/cssom/InlineStylePropertyMap.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/Iterable.h" | 7 #include "bindings/core/v8/Iterable.h" |
| 8 #include "core/CSSPropertyNames.h" | 8 #include "core/CSSPropertyNames.h" |
| 9 #include "core/css/CSSCustomIdentValue.h" | 9 #include "core/css/CSSCustomIdentValue.h" |
| 10 #include "core/css/CSSCustomPropertyDeclaration.h" | 10 #include "core/css/CSSCustomPropertyDeclaration.h" |
| 11 #include "core/css/CSSPrimitiveValue.h" | 11 #include "core/css/CSSPrimitiveValue.h" |
| 12 #include "core/css/CSSPropertyMetadata.h" | 12 #include "core/css/CSSPropertyMetadata.h" |
| 13 #include "core/css/CSSValueList.h" | 13 #include "core/css/CSSValueList.h" |
| 14 #include "core/css/StylePropertySet.h" | 14 #include "core/css/StylePropertySet.h" |
| 15 #include "core/css/cssom/CSSOMTypes.h" | 15 #include "core/css/cssom/CSSOMTypes.h" |
| 16 #include "core/css/cssom/CSSSimpleLength.h" | 16 #include "core/css/cssom/CSSSimpleLength.h" |
| 17 #include "core/css/cssom/CSSUnsupportedStyleValue.h" | 17 #include "core/css/cssom/CSSUnsupportedStyleValue.h" |
| 18 #include "core/css/cssom/StyleValueFactory.h" | 18 #include "core/css/cssom/StyleValueFactory.h" |
| 19 | 19 |
| 20 namespace blink { | 20 namespace blink { |
| 21 | 21 |
| 22 namespace { | 22 namespace { |
| 23 | 23 |
| 24 CSSValueList* cssValueListForPropertyID(CSSPropertyID propertyID) { |
| 25 char separator = CSSPropertyMetadata::repetitionSeparator(propertyID); |
| 26 switch (separator) { |
| 27 case ' ': |
| 28 return CSSValueList::createSpaceSeparated(); |
| 29 case ',': |
| 30 return CSSValueList::createCommaSeparated(); |
| 31 case '/': |
| 32 return CSSValueList::createSlashSeparated(); |
| 33 default: |
| 34 NOTREACHED(); |
| 35 return nullptr; |
| 36 } |
| 37 } |
| 38 |
| 24 const CSSValue* styleValueToCSSValue(CSSPropertyID propertyID, | 39 const CSSValue* styleValueToCSSValue(CSSPropertyID propertyID, |
| 25 const CSSStyleValue& styleValue) { | 40 const CSSStyleValue& styleValue) { |
| 26 if (!CSSOMTypes::propertyCanTake(propertyID, styleValue)) | 41 if (!CSSOMTypes::propertyCanTake(propertyID, styleValue)) |
| 27 return nullptr; | 42 return nullptr; |
| 28 return styleValue.toCSSValueWithProperty(propertyID); | 43 return styleValue.toCSSValueWithProperty(propertyID); |
| 29 } | 44 } |
| 30 | 45 |
| 31 const CSSValue* singleStyleValueAsCSSValue(CSSPropertyID propertyID, | 46 const CSSValue* singleStyleValueAsCSSValue(CSSPropertyID propertyID, |
| 32 const CSSStyleValue& styleValue) { | 47 const CSSStyleValue& styleValue) { |
| 33 const CSSValue* cssValue = styleValueToCSSValue(propertyID, styleValue); | 48 const CSSValue* cssValue = styleValueToCSSValue(propertyID, styleValue); |
| 34 if (!cssValue) | 49 if (!cssValue) |
| 35 return nullptr; | 50 return nullptr; |
| 36 | 51 |
| 37 if (!CSSPropertyMetadata::propertyIsRepeated(propertyID) || | 52 if (!CSSPropertyMetadata::propertyIsRepeated(propertyID) || |
| 38 cssValue->isCSSWideKeyword()) | 53 cssValue->isCSSWideKeyword()) |
| 39 return cssValue; | 54 return cssValue; |
| 40 | 55 |
| 41 // TODO(meade): Determine the correct separator for each property. | 56 CSSValueList* valueList = cssValueListForPropertyID(propertyID); |
| 42 CSSValueList* valueList = CSSValueList::createSpaceSeparated(); | |
| 43 valueList->append(*cssValue); | 57 valueList->append(*cssValue); |
| 44 return valueList; | 58 return valueList; |
| 45 } | 59 } |
| 46 | 60 |
| 47 CSSValueList* asCSSValueList(CSSPropertyID propertyID, | 61 const CSSValueList* asCSSValueList( |
| 48 const CSSStyleValueVector& styleValueVector) { | 62 CSSPropertyID propertyID, |
| 49 // TODO(meade): Determine the correct separator for each property. | 63 const CSSStyleValueVector& styleValueVector) { |
| 50 CSSValueList* valueList = CSSValueList::createSpaceSeparated(); | 64 CSSValueList* valueList = cssValueListForPropertyID(propertyID); |
| 51 for (const CSSStyleValue* value : styleValueVector) { | 65 for (const CSSStyleValue* value : styleValueVector) { |
| 52 const CSSValue* cssValue = styleValueToCSSValue(propertyID, *value); | 66 const CSSValue* cssValue = styleValueToCSSValue(propertyID, *value); |
| 53 if (!cssValue) { | 67 if (!cssValue) { |
| 54 return nullptr; | 68 return nullptr; |
| 55 } | 69 } |
| 56 valueList->append(*cssValue); | 70 valueList->append(*cssValue); |
| 57 } | 71 } |
| 58 return valueList; | 72 return valueList; |
| 59 } | 73 } |
| 60 | 74 |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 if (!CSSPropertyMetadata::propertyIsRepeated(propertyID)) { | 158 if (!CSSPropertyMetadata::propertyIsRepeated(propertyID)) { |
| 145 exceptionState.throwTypeError("Property does not support multiple values"); | 159 exceptionState.throwTypeError("Property does not support multiple values"); |
| 146 return; | 160 return; |
| 147 } | 161 } |
| 148 | 162 |
| 149 const CSSValue* cssValue = | 163 const CSSValue* cssValue = |
| 150 m_ownerElement->ensureMutableInlineStyle().getPropertyCSSValue( | 164 m_ownerElement->ensureMutableInlineStyle().getPropertyCSSValue( |
| 151 propertyID); | 165 propertyID); |
| 152 CSSValueList* cssValueList = nullptr; | 166 CSSValueList* cssValueList = nullptr; |
| 153 if (!cssValue) { | 167 if (!cssValue) { |
| 154 // TODO(meade): Determine the correct separator for each property. | 168 cssValueList = cssValueListForPropertyID(propertyID); |
| 155 cssValueList = CSSValueList::createSpaceSeparated(); | |
| 156 } else if (cssValue->isValueList()) { | 169 } else if (cssValue->isValueList()) { |
| 157 cssValueList = toCSSValueList(cssValue)->copy(); | 170 cssValueList = toCSSValueList(cssValue)->copy(); |
| 158 } else { | 171 } else { |
| 159 // TODO(meade): Figure out what the correct behaviour here is. | 172 // TODO(meade): Figure out what the correct behaviour here is. |
| 160 exceptionState.throwTypeError("Property is not already list valued"); | 173 exceptionState.throwTypeError("Property is not already list valued"); |
| 161 return; | 174 return; |
| 162 } | 175 } |
| 163 | 176 |
| 164 if (item.isCSSStyleValue()) { | 177 if (item.isCSSStyleValue()) { |
| 165 const CSSValue* cssValue = | 178 const CSSValue* cssValue = |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 value.setCSSStyleValue(styleValueVector[0]); | 240 value.setCSSStyleValue(styleValueVector[0]); |
| 228 else | 241 else |
| 229 value.setCSSStyleValueSequence(styleValueVector); | 242 value.setCSSStyleValueSequence(styleValueVector); |
| 230 } | 243 } |
| 231 result.push_back(std::make_pair(name, value)); | 244 result.push_back(std::make_pair(name, value)); |
| 232 } | 245 } |
| 233 return result; | 246 return result; |
| 234 } | 247 } |
| 235 | 248 |
| 236 } // namespace blink | 249 } // namespace blink |
| OLD | NEW |