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 { | |
| 20 | |
| 21 CSSValue* styleValueToCSSValue(CSSPropertyID propertyID, const CSSStyleValue& st yleValue) | |
| 22 { | |
| 23 if (!CSSOMTypes::propertyCanTake(propertyID, styleValue)) | |
| 24 return nullptr; | |
| 25 return styleValue.toCSSValueWithProperty(propertyID); | |
| 26 } | |
| 27 | |
| 28 } // namespace | |
| 29 | |
| 19 CSSStyleValueVector InlineStylePropertyMap::getAll(CSSPropertyID propertyID) | 30 CSSStyleValueVector InlineStylePropertyMap::getAll(CSSPropertyID propertyID) |
| 20 { | 31 { |
| 21 CSSValue* cssValue = m_ownerElement->ensureMutableInlineStyle().getPropertyC SSValue(propertyID); | 32 CSSValue* cssValue = m_ownerElement->ensureMutableInlineStyle().getPropertyC SSValue(propertyID); |
| 22 if (!cssValue) | 33 if (!cssValue) |
| 23 return CSSStyleValueVector(); | 34 return CSSStyleValueVector(); |
| 24 | 35 |
| 25 return StyleValueFactory::cssValueToStyleValueVector(propertyID, *cssValue); | 36 return StyleValueFactory::cssValueToStyleValueVector(propertyID, *cssValue); |
| 26 } | 37 } |
| 27 | 38 |
| 28 Vector<String> InlineStylePropertyMap::getProperties() | 39 Vector<String> InlineStylePropertyMap::getProperties() |
| 29 { | 40 { |
| 30 Vector<String> result; | 41 Vector<String> result; |
| 31 StylePropertySet& inlineStyleSet = m_ownerElement->ensureMutableInlineStyle( ); | 42 StylePropertySet& inlineStyleSet = m_ownerElement->ensureMutableInlineStyle( ); |
| 32 for (unsigned i = 0; i < inlineStyleSet.propertyCount(); i++) { | 43 for (unsigned i = 0; i < inlineStyleSet.propertyCount(); i++) { |
| 33 CSSPropertyID propertyID = inlineStyleSet.propertyAt(i).id(); | 44 CSSPropertyID propertyID = inlineStyleSet.propertyAt(i).id(); |
| 34 result.append(getPropertyNameString(propertyID)); | 45 result.append(getPropertyNameString(propertyID)); |
| 35 } | 46 } |
| 36 return result; | 47 return result; |
| 37 } | 48 } |
| 38 | 49 |
| 39 void InlineStylePropertyMap::set(CSSPropertyID propertyID, CSSStyleValueOrCSSSty leValueSequenceOrString& item, ExceptionState& exceptionState) | 50 void InlineStylePropertyMap::set(CSSPropertyID propertyID, CSSStyleValueOrCSSSty leValueSequenceOrString& item, ExceptionState& exceptionState) |
| 40 { | 51 { |
| 41 if (item.isCSSStyleValue()) { | 52 if (item.isCSSStyleValue()) { |
| 42 CSSStyleValue* styleValue = item.getAsCSSStyleValue(); | 53 CSSValue* cssValue = styleValueToCSSValue(propertyID, *item.getAsCSSStyl eValue()); |
| 43 if (!CSSOMTypes::propertyCanTake(propertyID, *styleValue)) { | 54 if (!cssValue) { |
| 44 exceptionState.throwTypeError("Invalid type for property"); | 55 exceptionState.throwTypeError("Invalid type for property"); |
| 45 return; | 56 return; |
| 46 } | 57 } |
| 47 m_ownerElement->setInlineStyleProperty(propertyID, styleValue->toCSSValu e()); | 58 m_ownerElement->setInlineStyleProperty(propertyID, cssValue); |
| 48 } else if (item.isCSSStyleValueSequence()) { | 59 } else if (item.isCSSStyleValueSequence()) { |
| 49 if (!CSSPropertyMetadata::propertySupportsMultiple(propertyID)) { | 60 if (!CSSPropertyMetadata::propertySupportsMultiple(propertyID)) { |
| 50 exceptionState.throwTypeError("Property does not support multiple va lues"); | 61 exceptionState.throwTypeError("Property does not support multiple va lues"); |
| 51 return; | 62 return; |
| 52 } | 63 } |
| 53 | 64 |
| 54 // TODO(meade): This won't always work. Figure out what kind of CSSValue List to create properly. | 65 // TODO(meade): This won't always work. Figure out what kind of CSSValue List to create properly. |
| 55 CSSValueList* valueList = CSSValueList::createSpaceSeparated(); | 66 CSSValueList* valueList = CSSValueList::createSpaceSeparated(); |
| 56 CSSStyleValueVector styleValueVector = item.getAsCSSStyleValueSequence() ; | 67 CSSStyleValueVector styleValueVector = item.getAsCSSStyleValueSequence() ; |
| 57 for (const Member<CSSStyleValue> value : styleValueVector) { | 68 for (const Member<CSSStyleValue> value : styleValueVector) { |
| 58 if (!CSSOMTypes::propertyCanTake(propertyID, *value)) { | 69 CSSValue* cssValue = styleValueToCSSValue(propertyID, *value); |
| 70 if (!cssValue) { | |
| 59 exceptionState.throwTypeError("Invalid type for property"); | 71 exceptionState.throwTypeError("Invalid type for property"); |
| 60 return; | 72 return; |
| 61 } | 73 } |
| 62 valueList->append(*value->toCSSValue()); | 74 // TODO: Use a builder instead of appending like this. |
|
Timothy Loh
2016/06/09 07:22:24
Not sure what you're after here, this is just how
meade_UTC10
2016/06/09 07:50:53
Misplaced comment from a discussion with Sasha...
| |
| 75 valueList->append(*cssValue); | |
| 63 } | 76 } |
| 64 | 77 |
| 65 m_ownerElement->setInlineStyleProperty(propertyID, valueList); | 78 m_ownerElement->setInlineStyleProperty(propertyID, valueList); |
| 66 } else { | 79 } else { |
| 67 // Parse it. | 80 // Parse it. |
| 68 ASSERT(item.isString()); | 81 DCHECK(item.isString()); |
| 69 // TODO(meade): Implement this. | 82 // TODO(meade): Implement this. |
| 70 exceptionState.throwTypeError("Not implemented yet"); | 83 exceptionState.throwTypeError("Not implemented yet"); |
| 71 } | 84 } |
| 72 } | 85 } |
| 73 | 86 |
| 74 void InlineStylePropertyMap::append(CSSPropertyID propertyID, CSSStyleValueOrCSS StyleValueSequenceOrString& item, ExceptionState& exceptionState) | 87 void InlineStylePropertyMap::append(CSSPropertyID propertyID, CSSStyleValueOrCSS StyleValueSequenceOrString& item, ExceptionState& exceptionState) |
| 75 { | 88 { |
| 76 if (!CSSPropertyMetadata::propertySupportsMultiple(propertyID)) { | 89 if (!CSSPropertyMetadata::propertySupportsMultiple(propertyID)) { |
| 77 exceptionState.throwTypeError("Property does not support multiple values "); | 90 exceptionState.throwTypeError("Property does not support multiple values "); |
| 78 return; | 91 return; |
| 79 } | 92 } |
| 80 | 93 |
| 81 CSSValue* cssValue = m_ownerElement->ensureMutableInlineStyle().getPropertyC SSValue(propertyID); | 94 CSSValue* cssValue = m_ownerElement->ensureMutableInlineStyle().getPropertyC SSValue(propertyID); |
| 82 CSSValueList* cssValueList = nullptr; | 95 CSSValueList* cssValueList = nullptr; |
| 83 if (cssValue->isValueList()) { | 96 if (cssValue->isValueList()) { |
| 84 cssValueList = toCSSValueList(cssValue); | 97 cssValueList = toCSSValueList(cssValue); |
| 85 } else { | 98 } else { |
| 86 // TODO(meade): Figure out what the correct behaviour here is. | 99 // TODO(meade): Figure out what the correct behaviour here is. |
| 87 exceptionState.throwTypeError("Property is not already list valued"); | 100 exceptionState.throwTypeError("Property is not already list valued"); |
| 88 return; | 101 return; |
| 89 } | 102 } |
| 90 | 103 |
| 91 if (item.isCSSStyleValue()) { | 104 if (item.isCSSStyleValue()) { |
| 92 CSSStyleValue* styleValue = item.getAsCSSStyleValue(); | 105 CSSValue* cssValue = styleValueToCSSValue(propertyID, *item.getAsCSSStyl eValue()); |
| 93 if (!CSSOMTypes::propertyCanTake(propertyID, *styleValue)) { | 106 if (!cssValue) { |
| 94 exceptionState.throwTypeError("Invalid type for property"); | 107 exceptionState.throwTypeError("Invalid type for property"); |
| 95 return; | 108 return; |
| 96 } | 109 } |
| 97 cssValueList->append(*item.getAsCSSStyleValue()->toCSSValue()); | 110 cssValueList->append(*cssValue); |
| 98 } else if (item.isCSSStyleValueSequence()) { | 111 } else if (item.isCSSStyleValueSequence()) { |
| 99 for (CSSStyleValue* styleValue : item.getAsCSSStyleValueSequence()) { | 112 for (CSSStyleValue* styleValue : item.getAsCSSStyleValueSequence()) { |
| 100 if (!CSSOMTypes::propertyCanTake(propertyID, *styleValue)) { | 113 CSSValue* cssValue = styleValueToCSSValue(propertyID, *styleValue); |
| 114 if (!cssValue) { | |
| 101 exceptionState.throwTypeError("Invalid type for property"); | 115 exceptionState.throwTypeError("Invalid type for property"); |
| 102 return; | 116 return; |
| 103 } | 117 } |
| 104 cssValueList->append(*styleValue->toCSSValue()); | 118 cssValueList->append(*cssValue); |
| 105 } | 119 } |
| 106 } else { | 120 } else { |
| 107 // Parse it. | 121 // Parse it. |
| 108 ASSERT(item.isString()); | 122 DCHECK(item.isString()); |
| 109 // TODO(meade): Implement this. | 123 // TODO(meade): Implement this. |
| 110 exceptionState.throwTypeError("Not implemented yet"); | 124 exceptionState.throwTypeError("Not implemented yet"); |
| 111 return; | 125 return; |
| 112 } | 126 } |
| 113 | 127 |
| 114 m_ownerElement->setInlineStyleProperty(propertyID, cssValueList); | 128 m_ownerElement->setInlineStyleProperty(propertyID, cssValueList); |
| 115 } | 129 } |
| 116 | 130 |
| 117 void InlineStylePropertyMap::remove(CSSPropertyID propertyID, ExceptionState& ex ceptionState) | 131 void InlineStylePropertyMap::remove(CSSPropertyID propertyID, ExceptionState& ex ceptionState) |
| 118 { | 132 { |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 132 value.setCSSStyleValue(styleValueVector[0]); | 146 value.setCSSStyleValue(styleValueVector[0]); |
| 133 else | 147 else |
| 134 value.setCSSStyleValueSequence(styleValueVector); | 148 value.setCSSStyleValueSequence(styleValueVector); |
| 135 result.append(std::make_pair(getPropertyNameString(propertyID), value)); | 149 result.append(std::make_pair(getPropertyNameString(propertyID), value)); |
| 136 } | 150 } |
| 137 return result; | 151 return result; |
| 138 } | 152 } |
| 139 | 153 |
| 140 } // namespace blink | 154 } // namespace blink |
| 141 | 155 |
| OLD | NEW |