| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "core/css/cssom/InlineStylePropertyMap.h" |
| 6 |
| 7 #include "core/CSSPropertyNames.h" |
| 8 #include "core/css/CSSPrimitiveValue.h" |
| 9 #include "core/css/CSSPropertyMetadata.h" |
| 10 #include "core/css/CSSValueList.h" |
| 11 #include "core/css/StylePropertySet.h" |
| 12 #include "core/css/cssom/CSSOMTypes.h" |
| 13 #include "core/css/cssom/SimpleLength.h" |
| 14 #include "core/css/cssom/StyleValueFactory.h" |
| 15 |
| 16 namespace blink { |
| 17 |
| 18 StyleValue* InlineStylePropertyMap::get(CSSPropertyID propertyID) |
| 19 { |
| 20 StyleValueVector styleVector = getAll(propertyID); |
| 21 if (styleVector.isEmpty()) |
| 22 return nullptr; |
| 23 |
| 24 return styleVector.at(0); |
| 25 } |
| 26 |
| 27 StyleValueVector InlineStylePropertyMap::getAll(CSSPropertyID propertyID) |
| 28 { |
| 29 CSSValue* cssValue = m_ownerElement->ensureMutableInlineStyle().getPropertyC
SSValue(propertyID); |
| 30 if (!cssValue) |
| 31 return StyleValueVector(); |
| 32 |
| 33 StyleValueVector styleValueVector; |
| 34 |
| 35 if (!cssValue->isValueList()) { |
| 36 StyleValue* styleValue = StyleValueFactory::create(propertyID, *cssValue
); |
| 37 if (styleValue) |
| 38 styleValueVector.append(styleValue); |
| 39 return styleValueVector; |
| 40 } |
| 41 |
| 42 for (CSSValue* value : *toCSSValueList(cssValue)) { |
| 43 StyleValue* styleValue = StyleValueFactory::create(propertyID, *value); |
| 44 if (!styleValue) { |
| 45 return StyleValueVector(); |
| 46 } |
| 47 styleValueVector.append(styleValue); |
| 48 } |
| 49 return styleValueVector; |
| 50 } |
| 51 |
| 52 bool InlineStylePropertyMap::has(CSSPropertyID propertyID) |
| 53 { |
| 54 return !getAll(propertyID).isEmpty(); |
| 55 } |
| 56 |
| 57 Vector<String> InlineStylePropertyMap::getProperties() |
| 58 { |
| 59 Vector<String> result; |
| 60 StylePropertySet& inlineStyleSet = m_ownerElement->ensureMutableInlineStyle(
); |
| 61 for (unsigned i = 0; i < inlineStyleSet.propertyCount(); i++) { |
| 62 CSSPropertyID propertyID = inlineStyleSet.propertyAt(i).id(); |
| 63 result.append(getPropertyNameString(propertyID)); |
| 64 } |
| 65 return result; |
| 66 } |
| 67 |
| 68 void InlineStylePropertyMap::set(CSSPropertyID propertyID, StyleValueOrStyleValu
eSequenceOrString& item, ExceptionState& exceptionState) |
| 69 { |
| 70 if (item.isStyleValue()) { |
| 71 StyleValue* styleValue = item.getAsStyleValue(); |
| 72 if (!CSSOMTypes::propertyCanTake(propertyID, *styleValue)) { |
| 73 exceptionState.throwTypeError("Invalid type for property"); |
| 74 return; |
| 75 } |
| 76 m_ownerElement->setInlineStyleProperty(propertyID, styleValue->toCSSValu
e()); |
| 77 } else if (item.isStyleValueSequence()) { |
| 78 if (!CSSPropertyMetadata::propertySupportsMultiple(propertyID)) { |
| 79 exceptionState.throwTypeError("Property does not support multiple va
lues"); |
| 80 return; |
| 81 } |
| 82 |
| 83 // TODO(meade): This won't always work. Figure out what kind of CSSValue
List to create properly. |
| 84 CSSValueList* valueList = CSSValueList::createSpaceSeparated(); |
| 85 StyleValueVector styleValueVector = item.getAsStyleValueSequence(); |
| 86 for (const Member<StyleValue> value : styleValueVector) { |
| 87 if (!CSSOMTypes::propertyCanTake(propertyID, *value)) { |
| 88 exceptionState.throwTypeError("Invalid type for property"); |
| 89 return; |
| 90 } |
| 91 valueList->append(value->toCSSValue()); |
| 92 } |
| 93 |
| 94 m_ownerElement->setInlineStyleProperty(propertyID, valueList); |
| 95 } else { |
| 96 // Parse it. |
| 97 ASSERT(item.isString()); |
| 98 // TODO(meade): Implement this. |
| 99 exceptionState.throwTypeError("Not implemented yet"); |
| 100 } |
| 101 } |
| 102 |
| 103 void InlineStylePropertyMap::append(CSSPropertyID propertyID, StyleValueOrStyleV
alueSequenceOrString& item, ExceptionState& exceptionState) |
| 104 { |
| 105 if (!CSSPropertyMetadata::propertySupportsMultiple(propertyID)) { |
| 106 exceptionState.throwTypeError("Property does not support multiple values
"); |
| 107 return; |
| 108 } |
| 109 |
| 110 CSSValue* cssValue = m_ownerElement->ensureMutableInlineStyle().getPropertyC
SSValue(propertyID); |
| 111 CSSValueList* cssValueList = nullptr; |
| 112 if (cssValue->isValueList()) { |
| 113 cssValueList = toCSSValueList(cssValue); |
| 114 } else { |
| 115 // TODO(meade): Figure out what the correct behaviour here is. |
| 116 exceptionState.throwTypeError("Property is not already list valued"); |
| 117 return; |
| 118 } |
| 119 |
| 120 if (item.isStyleValue()) { |
| 121 StyleValue* styleValue = item.getAsStyleValue(); |
| 122 if (!CSSOMTypes::propertyCanTake(propertyID, *styleValue)) { |
| 123 exceptionState.throwTypeError("Invalid type for property"); |
| 124 return; |
| 125 } |
| 126 cssValueList->append(item.getAsStyleValue()->toCSSValue()); |
| 127 } else if (item.isStyleValueSequence()) { |
| 128 for (StyleValue* styleValue : item.getAsStyleValueSequence()) { |
| 129 if (!CSSOMTypes::propertyCanTake(propertyID, *styleValue)) { |
| 130 exceptionState.throwTypeError("Invalid type for property"); |
| 131 return; |
| 132 } |
| 133 cssValueList->append(styleValue->toCSSValue()); |
| 134 } |
| 135 } else { |
| 136 // Parse it. |
| 137 ASSERT(item.isString()); |
| 138 // TODO(meade): Implement this. |
| 139 exceptionState.throwTypeError("Not implemented yet"); |
| 140 return; |
| 141 } |
| 142 |
| 143 m_ownerElement->setInlineStyleProperty(propertyID, cssValueList); |
| 144 } |
| 145 |
| 146 void InlineStylePropertyMap::remove(CSSPropertyID propertyID, ExceptionState& ex
ceptionState) |
| 147 { |
| 148 m_ownerElement->removeInlineStyleProperty(propertyID); |
| 149 } |
| 150 |
| 151 } // namespace blink |
| 152 |
| OLD | NEW |