| 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" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 | 21 |
| 22 namespace { | 22 namespace { |
| 23 | 23 |
| 24 const CSSValue* styleValueToCSSValue(CSSPropertyID propertyID, const CSSStyleVal
ue& styleValue) | 24 const CSSValue* styleValueToCSSValue(CSSPropertyID propertyID, const CSSStyleVal
ue& styleValue) |
| 25 { | 25 { |
| 26 if (!CSSOMTypes::propertyCanTake(propertyID, styleValue)) | 26 if (!CSSOMTypes::propertyCanTake(propertyID, styleValue)) |
| 27 return nullptr; | 27 return nullptr; |
| 28 return styleValue.toCSSValueWithProperty(propertyID); | 28 return styleValue.toCSSValueWithProperty(propertyID); |
| 29 } | 29 } |
| 30 | 30 |
| 31 const CSSValue* singleStyleValueAsCSSValue(CSSPropertyID propertyID, const CSSSt
yleValue& styleValue) |
| 32 { |
| 33 if (!CSSPropertyMetadata::propertySupportsMultiple(propertyID)) |
| 34 return styleValueToCSSValue(propertyID, styleValue); |
| 35 |
| 36 const CSSValue* cssValue = styleValueToCSSValue(propertyID, styleValue); |
| 37 if (!cssValue) |
| 38 return nullptr; |
| 39 |
| 40 // TODO(meade): Determine the correct separator for each property. |
| 41 CSSValueList* valueList = CSSValueList::createSpaceSeparated(); |
| 42 valueList->append(*cssValue); |
| 43 return valueList; |
| 44 } |
| 45 |
| 46 CSSValueList* asCSSValueList(CSSPropertyID propertyID, const CSSStyleValueVector
& styleValueVector) |
| 47 { |
| 48 // TODO(meade): Determine the correct separator for each property. |
| 49 CSSValueList* valueList = CSSValueList::createSpaceSeparated(); |
| 50 for (const CSSStyleValue* value : styleValueVector) { |
| 51 const CSSValue* cssValue = styleValueToCSSValue(propertyID, *value); |
| 52 if (!cssValue) { |
| 53 return nullptr; |
| 54 } |
| 55 valueList->append(*cssValue); |
| 56 } |
| 57 return valueList; |
| 58 } |
| 59 |
| 31 } // namespace | 60 } // namespace |
| 32 | 61 |
| 33 CSSStyleValueVector InlineStylePropertyMap::getAllInternal(CSSPropertyID propert
yID) | 62 CSSStyleValueVector InlineStylePropertyMap::getAllInternal(CSSPropertyID propert
yID) |
| 34 { | 63 { |
| 35 const CSSValue* cssValue = m_ownerElement->ensureMutableInlineStyle().getPro
pertyCSSValue(propertyID); | 64 const CSSValue* cssValue = m_ownerElement->ensureMutableInlineStyle().getPro
pertyCSSValue(propertyID); |
| 36 if (!cssValue) | 65 if (!cssValue) |
| 37 return CSSStyleValueVector(); | 66 return CSSStyleValueVector(); |
| 38 | 67 |
| 39 return StyleValueFactory::cssValueToStyleValueVector(propertyID, *cssValue); | 68 return StyleValueFactory::cssValueToStyleValueVector(propertyID, *cssValue); |
| 40 } | 69 } |
| (...skipping 26 matching lines...) Expand all Loading... |
| 67 } | 96 } |
| 68 } else { | 97 } else { |
| 69 result.append(getPropertyNameString(propertyID)); | 98 result.append(getPropertyNameString(propertyID)); |
| 70 } | 99 } |
| 71 } | 100 } |
| 72 return result; | 101 return result; |
| 73 } | 102 } |
| 74 | 103 |
| 75 void InlineStylePropertyMap::set(CSSPropertyID propertyID, CSSStyleValueOrCSSSty
leValueSequenceOrString& item, ExceptionState& exceptionState) | 104 void InlineStylePropertyMap::set(CSSPropertyID propertyID, CSSStyleValueOrCSSSty
leValueSequenceOrString& item, ExceptionState& exceptionState) |
| 76 { | 105 { |
| 106 const CSSValue* cssValue = nullptr; |
| 77 if (item.isCSSStyleValue()) { | 107 if (item.isCSSStyleValue()) { |
| 78 const CSSValue* cssValue = styleValueToCSSValue(propertyID, *item.getAsC
SSStyleValue()); | 108 cssValue = singleStyleValueAsCSSValue(propertyID, *item.getAsCSSStyleVal
ue()); |
| 79 if (!cssValue) { | |
| 80 exceptionState.throwTypeError("Invalid type for property"); | |
| 81 return; | |
| 82 } | |
| 83 m_ownerElement->setInlineStyleProperty(propertyID, cssValue); | |
| 84 } else if (item.isCSSStyleValueSequence()) { | 109 } else if (item.isCSSStyleValueSequence()) { |
| 85 if (!CSSPropertyMetadata::propertySupportsMultiple(propertyID)) { | 110 if (!CSSPropertyMetadata::propertySupportsMultiple(propertyID)) { |
| 86 exceptionState.throwTypeError("Property does not support multiple va
lues"); | 111 exceptionState.throwTypeError("Property does not support multiple va
lues"); |
| 87 return; | 112 return; |
| 88 } | 113 } |
| 89 | 114 cssValue = asCSSValueList(propertyID, item.getAsCSSStyleValueSequence())
; |
| 90 // TODO(meade): This won't always work. Figure out what kind of CSSValue
List to create properly. | |
| 91 CSSValueList* valueList = CSSValueList::createSpaceSeparated(); | |
| 92 CSSStyleValueVector styleValueVector = item.getAsCSSStyleValueSequence()
; | |
| 93 for (const Member<CSSStyleValue> value : styleValueVector) { | |
| 94 const CSSValue* cssValue = styleValueToCSSValue(propertyID, *value); | |
| 95 if (!cssValue) { | |
| 96 exceptionState.throwTypeError("Invalid type for property"); | |
| 97 return; | |
| 98 } | |
| 99 valueList->append(*cssValue); | |
| 100 } | |
| 101 | |
| 102 m_ownerElement->setInlineStyleProperty(propertyID, valueList); | |
| 103 } else { | 115 } else { |
| 104 // Parse it. | 116 // Parse it. |
| 105 DCHECK(item.isString()); | 117 DCHECK(item.isString()); |
| 106 // TODO(meade): Implement this. | 118 // TODO(meade): Implement this. |
| 107 exceptionState.throwTypeError("Not implemented yet"); | 119 exceptionState.throwTypeError("Not implemented yet"); |
| 120 return; |
| 108 } | 121 } |
| 122 if (!cssValue) { |
| 123 exceptionState.throwTypeError("Invalid type for property"); |
| 124 return; |
| 125 } |
| 126 m_ownerElement->setInlineStyleProperty(propertyID, cssValue); |
| 109 } | 127 } |
| 110 | 128 |
| 111 void InlineStylePropertyMap::append(CSSPropertyID propertyID, CSSStyleValueOrCSS
StyleValueSequenceOrString& item, ExceptionState& exceptionState) | 129 void InlineStylePropertyMap::append(CSSPropertyID propertyID, CSSStyleValueOrCSS
StyleValueSequenceOrString& item, ExceptionState& exceptionState) |
| 112 { | 130 { |
| 113 if (!CSSPropertyMetadata::propertySupportsMultiple(propertyID)) { | 131 if (!CSSPropertyMetadata::propertySupportsMultiple(propertyID)) { |
| 114 exceptionState.throwTypeError("Property does not support multiple values
"); | 132 exceptionState.throwTypeError("Property does not support multiple values
"); |
| 115 return; | 133 return; |
| 116 } | 134 } |
| 117 | 135 |
| 118 const CSSValue* cssValue = m_ownerElement->ensureMutableInlineStyle().getPro
pertyCSSValue(propertyID); | 136 const CSSValue* cssValue = m_ownerElement->ensureMutableInlineStyle().getPro
pertyCSSValue(propertyID); |
| 119 CSSValueList* cssValueList = nullptr; | 137 CSSValueList* cssValueList = nullptr; |
| 120 if (cssValue->isValueList()) { | 138 if (!cssValue) { |
| 139 // TODO(meade): Determine the correct separator for each property. |
| 140 cssValueList = CSSValueList::createSpaceSeparated(); |
| 141 } else if (cssValue->isValueList()) { |
| 121 cssValueList = toCSSValueList(cssValue)->copy(); | 142 cssValueList = toCSSValueList(cssValue)->copy(); |
| 122 } else { | 143 } else { |
| 123 // TODO(meade): Figure out what the correct behaviour here is. | 144 // TODO(meade): Figure out what the correct behaviour here is. |
| 124 exceptionState.throwTypeError("Property is not already list valued"); | 145 exceptionState.throwTypeError("Property is not already list valued"); |
| 125 return; | 146 return; |
| 126 } | 147 } |
| 127 | 148 |
| 128 if (item.isCSSStyleValue()) { | 149 if (item.isCSSStyleValue()) { |
| 129 const CSSValue* cssValue = styleValueToCSSValue(propertyID, *item.getAsC
SSStyleValue()); | 150 const CSSValue* cssValue = styleValueToCSSValue(propertyID, *item.getAsC
SSStyleValue()); |
| 130 if (!cssValue) { | 151 if (!cssValue) { |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 else | 204 else |
| 184 value.setCSSStyleValueSequence(styleValueVector); | 205 value.setCSSStyleValueSequence(styleValueVector); |
| 185 } | 206 } |
| 186 result.append(std::make_pair(name, value)); | 207 result.append(std::make_pair(name, value)); |
| 187 } | 208 } |
| 188 return result; | 209 return result; |
| 189 } | 210 } |
| 190 | 211 |
| 191 } // namespace blink | 212 } // namespace blink |
| 192 | 213 |
| OLD | NEW |