Chromium Code Reviews| 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/CSSPrimitiveValue.h" | 9 #include "core/css/CSSPrimitiveValue.h" |
| 10 #include "core/css/CSSPropertyMetadata.h" | 10 #include "core/css/CSSPropertyMetadata.h" |
| 11 #include "core/css/CSSValueList.h" | 11 #include "core/css/CSSValueList.h" |
| 12 #include "core/css/StylePropertySet.h" | 12 #include "core/css/StylePropertySet.h" |
| 13 #include "core/css/cssom/CSSOMTypes.h" | 13 #include "core/css/cssom/CSSOMTypes.h" |
| 14 #include "core/css/cssom/CSSSimpleLength.h" | 14 #include "core/css/cssom/CSSSimpleLength.h" |
| 15 #include "core/css/cssom/StyleValueFactory.h" | 15 #include "core/css/cssom/StyleValueFactory.h" |
| 16 | 16 |
| 17 namespace blink { | 17 namespace blink { |
| 18 | 18 |
| 19 namespace { | 19 namespace { |
| 20 | 20 |
| 21 CSSValue* styleValueToCSSValue(CSSPropertyID propertyID, const CSSStyleValue& st yleValue) | 21 CSSValue* styleValueToCSSValue(CSSPropertyID propertyID, const CSSStyleValue& st yleValue) |
| 22 { | 22 { |
| 23 if (!CSSOMTypes::propertyCanTake(propertyID, styleValue)) | 23 if (!CSSOMTypes::propertyCanTake(propertyID, styleValue)) |
| 24 return nullptr; | 24 return nullptr; |
| 25 return styleValue.toCSSValueWithProperty(propertyID); | 25 return styleValue.toCSSValueWithProperty(propertyID); |
| 26 } | 26 } |
| 27 | 27 |
| 28 CSSValue* singleStyleValueAsCSSValue(CSSPropertyID propertyID, const CSSStyleVal ue& styleValue) | |
| 29 { | |
| 30 if (!CSSPropertyMetadata::propertySupportsMultiple(propertyID)) | |
| 31 return styleValueToCSSValue(propertyID, styleValue); | |
| 32 | |
| 33 CSSValue* cssValue = styleValueToCSSValue(propertyID, styleValue); | |
| 34 if (!cssValue) | |
| 35 return nullptr; | |
| 36 | |
| 37 // TODO(meade): This won't always work. Figure out what kind of CSSValueList to create properly. | |
| 38 CSSValueList* valueList = CSSValueList::createSpaceSeparated(); | |
| 39 valueList->append(*cssValue); | |
| 40 return valueList; | |
| 41 } | |
| 42 | |
| 43 CSSValueList* asCSSValueList(CSSPropertyID propertyID, const CSSStyleValueVector & styleValueVector) | |
| 44 { | |
| 45 // TODO(meade): This won't always work. Figure out what kind of CSSValueList to create properly. | |
| 46 CSSValueList* valueList = CSSValueList::createSpaceSeparated(); | |
| 47 for (const CSSStyleValue* value : styleValueVector) { | |
| 48 CSSValue* cssValue = styleValueToCSSValue(propertyID, *value); | |
| 49 if (!cssValue) { | |
| 50 return nullptr; | |
| 51 } | |
| 52 valueList->append(*cssValue); | |
| 53 } | |
| 54 return valueList; | |
| 55 } | |
| 56 | |
| 28 } // namespace | 57 } // namespace |
| 29 | 58 |
| 30 CSSStyleValueVector InlineStylePropertyMap::getAllInternal(CSSPropertyID propert yID) | 59 CSSStyleValueVector InlineStylePropertyMap::getAllInternal(CSSPropertyID propert yID) |
| 31 { | 60 { |
| 32 CSSValue* cssValue = m_ownerElement->ensureMutableInlineStyle().getPropertyC SSValue(propertyID); | 61 CSSValue* cssValue = m_ownerElement->ensureMutableInlineStyle().getPropertyC SSValue(propertyID); |
| 33 if (!cssValue) | 62 if (!cssValue) |
| 34 return CSSStyleValueVector(); | 63 return CSSStyleValueVector(); |
| 35 | 64 |
| 36 return StyleValueFactory::cssValueToStyleValueVector(propertyID, *cssValue); | 65 return StyleValueFactory::cssValueToStyleValueVector(propertyID, *cssValue); |
| 37 } | 66 } |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 51 StylePropertySet& inlineStyleSet = m_ownerElement->ensureMutableInlineStyle( ); | 80 StylePropertySet& inlineStyleSet = m_ownerElement->ensureMutableInlineStyle( ); |
| 52 for (unsigned i = 0; i < inlineStyleSet.propertyCount(); i++) { | 81 for (unsigned i = 0; i < inlineStyleSet.propertyCount(); i++) { |
| 53 CSSPropertyID propertyID = inlineStyleSet.propertyAt(i).id(); | 82 CSSPropertyID propertyID = inlineStyleSet.propertyAt(i).id(); |
| 54 result.append(getPropertyNameString(propertyID)); | 83 result.append(getPropertyNameString(propertyID)); |
| 55 } | 84 } |
| 56 return result; | 85 return result; |
| 57 } | 86 } |
| 58 | 87 |
| 59 void InlineStylePropertyMap::set(CSSPropertyID propertyID, CSSStyleValueOrCSSSty leValueSequenceOrString& item, ExceptionState& exceptionState) | 88 void InlineStylePropertyMap::set(CSSPropertyID propertyID, CSSStyleValueOrCSSSty leValueSequenceOrString& item, ExceptionState& exceptionState) |
| 60 { | 89 { |
| 90 CSSValue* cssValue = nullptr; | |
| 61 if (item.isCSSStyleValue()) { | 91 if (item.isCSSStyleValue()) { |
| 62 CSSValue* cssValue = styleValueToCSSValue(propertyID, *item.getAsCSSStyl eValue()); | 92 cssValue = singleStyleValueAsCSSValue(propertyID, *item.getAsCSSStyleVal ue()); |
| 63 if (!cssValue) { | |
| 64 exceptionState.throwTypeError("Invalid type for property"); | |
| 65 return; | |
| 66 } | |
| 67 m_ownerElement->setInlineStyleProperty(propertyID, cssValue); | |
| 68 } else if (item.isCSSStyleValueSequence()) { | 93 } else if (item.isCSSStyleValueSequence()) { |
| 69 if (!CSSPropertyMetadata::propertySupportsMultiple(propertyID)) { | 94 if (!CSSPropertyMetadata::propertySupportsMultiple(propertyID)) { |
| 70 exceptionState.throwTypeError("Property does not support multiple va lues"); | 95 exceptionState.throwTypeError("Property does not support multiple va lues"); |
| 71 return; | 96 return; |
| 72 } | 97 } |
| 73 | 98 cssValue = asCSSValueList(propertyID, item.getAsCSSStyleValueSequence()) ; |
| 74 // TODO(meade): This won't always work. Figure out what kind of CSSValue List to create properly. | |
| 75 CSSValueList* valueList = CSSValueList::createSpaceSeparated(); | |
| 76 CSSStyleValueVector styleValueVector = item.getAsCSSStyleValueSequence() ; | |
| 77 for (const Member<CSSStyleValue> value : styleValueVector) { | |
| 78 CSSValue* cssValue = styleValueToCSSValue(propertyID, *value); | |
| 79 if (!cssValue) { | |
| 80 exceptionState.throwTypeError("Invalid type for property"); | |
| 81 return; | |
| 82 } | |
| 83 valueList->append(*cssValue); | |
| 84 } | |
| 85 | |
| 86 m_ownerElement->setInlineStyleProperty(propertyID, valueList); | |
| 87 } else { | 99 } else { |
| 88 // Parse it. | 100 // Parse it. |
| 89 DCHECK(item.isString()); | 101 DCHECK(item.isString()); |
| 90 // TODO(meade): Implement this. | 102 // TODO(meade): Implement this. |
| 91 exceptionState.throwTypeError("Not implemented yet"); | 103 exceptionState.throwTypeError("Not implemented yet"); |
| 104 return; | |
| 92 } | 105 } |
| 106 if (!cssValue) { | |
| 107 exceptionState.throwTypeError("Invalid type for property"); | |
| 108 return; | |
| 109 } | |
| 110 m_ownerElement->setInlineStyleProperty(propertyID, cssValue); | |
| 93 } | 111 } |
| 94 | 112 |
| 95 void InlineStylePropertyMap::append(CSSPropertyID propertyID, CSSStyleValueOrCSS StyleValueSequenceOrString& item, ExceptionState& exceptionState) | 113 void InlineStylePropertyMap::append(CSSPropertyID propertyID, CSSStyleValueOrCSS StyleValueSequenceOrString& item, ExceptionState& exceptionState) |
| 96 { | 114 { |
| 97 if (!CSSPropertyMetadata::propertySupportsMultiple(propertyID)) { | 115 if (!CSSPropertyMetadata::propertySupportsMultiple(propertyID)) { |
| 98 exceptionState.throwTypeError("Property does not support multiple values "); | 116 exceptionState.throwTypeError("Property does not support multiple values "); |
| 99 return; | 117 return; |
| 100 } | 118 } |
| 101 | 119 |
| 102 const CSSValue* cssValue = m_ownerElement->ensureMutableInlineStyle().getPro pertyCSSValue(propertyID); | 120 const CSSValue* cssValue = m_ownerElement->ensureMutableInlineStyle().getPro pertyCSSValue(propertyID); |
| 103 CSSValueList* cssValueList = nullptr; | 121 CSSValueList* cssValueList = nullptr; |
| 104 if (cssValue->isValueList()) { | 122 if (!cssValue) { |
| 123 // TODO(meade): Figure out the correct separator. | |
|
sashab
2016/07/11 23:47:22
There's a lot of these TODOs to figure out the cor
meade_UTC10
2016/07/27 07:14:29
So these are interesting - we don't check the sepa
sashab
2016/07/27 23:23:57
Ok, that sounds good, but I would make the TODO mo
meade_UTC10
2016/08/03 03:26:44
Done.
| |
| 124 cssValueList = CSSValueList::createSpaceSeparated(); | |
| 125 } else if (cssValue->isValueList()) { | |
| 105 cssValueList = toCSSValueList(cssValue)->copy(); | 126 cssValueList = toCSSValueList(cssValue)->copy(); |
| 106 } else { | 127 } else { |
| 107 // TODO(meade): Figure out what the correct behaviour here is. | 128 // TODO(meade): Figure out what the correct behaviour here is. |
| 108 exceptionState.throwTypeError("Property is not already list valued"); | 129 exceptionState.throwTypeError("Property is not already list valued"); |
| 109 return; | 130 return; |
| 110 } | 131 } |
| 111 | 132 |
| 112 if (item.isCSSStyleValue()) { | 133 if (item.isCSSStyleValue()) { |
| 113 CSSValue* cssValue = styleValueToCSSValue(propertyID, *item.getAsCSSStyl eValue()); | 134 CSSValue* cssValue = styleValueToCSSValue(propertyID, *item.getAsCSSStyl eValue()); |
| 114 if (!cssValue) { | 135 if (!cssValue) { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 154 value.setCSSStyleValue(styleValueVector[0]); | 175 value.setCSSStyleValue(styleValueVector[0]); |
| 155 else | 176 else |
| 156 value.setCSSStyleValueSequence(styleValueVector); | 177 value.setCSSStyleValueSequence(styleValueVector); |
| 157 result.append(std::make_pair(getPropertyNameString(propertyID), value)); | 178 result.append(std::make_pair(getPropertyNameString(propertyID), value)); |
| 158 } | 179 } |
| 159 return result; | 180 return result; |
| 160 } | 181 } |
| 161 | 182 |
| 162 } // namespace blink | 183 } // namespace blink |
| 163 | 184 |
| OLD | NEW |