| 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 | 16 |
| 16 namespace blink { | 17 namespace blink { |
| 17 | 18 |
| 18 StylePropertyMap::StyleValueVector InlineStylePropertyMap::getAll(CSSPropertyID
propertyID) | 19 CSSStyleValueVector InlineStylePropertyMap::getAll(CSSPropertyID propertyID) |
| 19 { | 20 { |
| 20 CSSValue* cssValue = m_ownerElement->ensureMutableInlineStyle().getPropertyC
SSValue(propertyID); | 21 CSSValue* cssValue = m_ownerElement->ensureMutableInlineStyle().getPropertyC
SSValue(propertyID); |
| 21 if (!cssValue) | 22 if (!cssValue) |
| 22 return StyleValueVector(); | 23 return CSSStyleValueVector(); |
| 23 | 24 |
| 24 return cssValueToStyleValueVector(propertyID, *cssValue); | 25 return StyleValueFactory::cssValueToStyleValueVector(propertyID, *cssValue); |
| 25 } | 26 } |
| 26 | 27 |
| 27 Vector<String> InlineStylePropertyMap::getProperties() | 28 Vector<String> InlineStylePropertyMap::getProperties() |
| 28 { | 29 { |
| 29 Vector<String> result; | 30 Vector<String> result; |
| 30 StylePropertySet& inlineStyleSet = m_ownerElement->ensureMutableInlineStyle(
); | 31 StylePropertySet& inlineStyleSet = m_ownerElement->ensureMutableInlineStyle(
); |
| 31 for (unsigned i = 0; i < inlineStyleSet.propertyCount(); i++) { | 32 for (unsigned i = 0; i < inlineStyleSet.propertyCount(); i++) { |
| 32 CSSPropertyID propertyID = inlineStyleSet.propertyAt(i).id(); | 33 CSSPropertyID propertyID = inlineStyleSet.propertyAt(i).id(); |
| 33 result.append(getPropertyNameString(propertyID)); | 34 result.append(getPropertyNameString(propertyID)); |
| 34 } | 35 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 45 } | 46 } |
| 46 m_ownerElement->setInlineStyleProperty(propertyID, styleValue->toCSSValu
e()); | 47 m_ownerElement->setInlineStyleProperty(propertyID, styleValue->toCSSValu
e()); |
| 47 } else if (item.isCSSStyleValueSequence()) { | 48 } else if (item.isCSSStyleValueSequence()) { |
| 48 if (!CSSPropertyMetadata::propertySupportsMultiple(propertyID)) { | 49 if (!CSSPropertyMetadata::propertySupportsMultiple(propertyID)) { |
| 49 exceptionState.throwTypeError("Property does not support multiple va
lues"); | 50 exceptionState.throwTypeError("Property does not support multiple va
lues"); |
| 50 return; | 51 return; |
| 51 } | 52 } |
| 52 | 53 |
| 53 // TODO(meade): This won't always work. Figure out what kind of CSSValue
List to create properly. | 54 // TODO(meade): This won't always work. Figure out what kind of CSSValue
List to create properly. |
| 54 CSSValueList* valueList = CSSValueList::createSpaceSeparated(); | 55 CSSValueList* valueList = CSSValueList::createSpaceSeparated(); |
| 55 StyleValueVector styleValueVector = item.getAsCSSStyleValueSequence(); | 56 CSSStyleValueVector styleValueVector = item.getAsCSSStyleValueSequence()
; |
| 56 for (const Member<CSSStyleValue> value : styleValueVector) { | 57 for (const Member<CSSStyleValue> value : styleValueVector) { |
| 57 if (!CSSOMTypes::propertyCanTake(propertyID, *value)) { | 58 if (!CSSOMTypes::propertyCanTake(propertyID, *value)) { |
| 58 exceptionState.throwTypeError("Invalid type for property"); | 59 exceptionState.throwTypeError("Invalid type for property"); |
| 59 return; | 60 return; |
| 60 } | 61 } |
| 61 valueList->append(value->toCSSValue()); | 62 valueList->append(value->toCSSValue()); |
| 62 } | 63 } |
| 63 | 64 |
| 64 m_ownerElement->setInlineStyleProperty(propertyID, valueList); | 65 m_ownerElement->setInlineStyleProperty(propertyID, valueList); |
| 65 } else { | 66 } else { |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 m_ownerElement->removeInlineStyleProperty(propertyID); | 119 m_ownerElement->removeInlineStyleProperty(propertyID); |
| 119 } | 120 } |
| 120 | 121 |
| 121 HeapVector<StylePropertyMap::StylePropertyMapEntry> InlineStylePropertyMap::getI
terationEntries() | 122 HeapVector<StylePropertyMap::StylePropertyMapEntry> InlineStylePropertyMap::getI
terationEntries() |
| 122 { | 123 { |
| 123 HeapVector<StylePropertyMap::StylePropertyMapEntry> result; | 124 HeapVector<StylePropertyMap::StylePropertyMapEntry> result; |
| 124 StylePropertySet& inlineStyleSet = m_ownerElement->ensureMutableInlineStyle(
); | 125 StylePropertySet& inlineStyleSet = m_ownerElement->ensureMutableInlineStyle(
); |
| 125 for (unsigned i = 0; i < inlineStyleSet.propertyCount(); i++) { | 126 for (unsigned i = 0; i < inlineStyleSet.propertyCount(); i++) { |
| 126 StylePropertySet::PropertyReference propertyReference = inlineStyleSet.p
ropertyAt(i); | 127 StylePropertySet::PropertyReference propertyReference = inlineStyleSet.p
ropertyAt(i); |
| 127 CSSPropertyID propertyID = propertyReference.id(); | 128 CSSPropertyID propertyID = propertyReference.id(); |
| 128 StyleValueVector styleValueVector = cssValueToStyleValueVector(propertyI
D, *propertyReference.value()); | 129 CSSStyleValueVector styleValueVector = StyleValueFactory::cssValueToStyl
eValueVector(propertyID, *propertyReference.value()); |
| 129 CSSStyleValueOrCSSStyleValueSequence value; | 130 CSSStyleValueOrCSSStyleValueSequence value; |
| 130 if (styleValueVector.size() == 1) | 131 if (styleValueVector.size() == 1) |
| 131 value.setCSSStyleValue(styleValueVector[0]); | 132 value.setCSSStyleValue(styleValueVector[0]); |
| 132 else | 133 else |
| 133 value.setCSSStyleValueSequence(styleValueVector); | 134 value.setCSSStyleValueSequence(styleValueVector); |
| 134 result.append(std::make_pair(getPropertyNameString(propertyID), value)); | 135 result.append(std::make_pair(getPropertyNameString(propertyID), value)); |
| 135 } | 136 } |
| 136 return result; | 137 return result; |
| 137 } | 138 } |
| 138 | 139 |
| 139 } // namespace blink | 140 } // namespace blink |
| 140 | 141 |
| OLD | NEW |