Chromium Code Reviews| 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"); | |
|
Timothy Loh
2016/04/07 06:34:17
return; ? otherwise you'll get a null pointer dere
meade_UTC10
2016/04/07 07:15:36
whoops, done.
| |
| 117 } | |
| 118 | |
| 119 if (item.isStyleValue()) { | |
| 120 StyleValue* styleValue = item.getAsStyleValue(); | |
| 121 if (!CSSOMTypes::propertyCanTake(propertyID, *styleValue)) { | |
| 122 exceptionState.throwTypeError("Invalid type for property"); | |
| 123 return; | |
| 124 } | |
| 125 cssValueList->append(item.getAsStyleValue()->toCSSValue()); | |
| 126 } else if (item.isStyleValueSequence()) { | |
| 127 for (StyleValue* styleValue : item.getAsStyleValueSequence()) { | |
| 128 if (!CSSOMTypes::propertyCanTake(propertyID, *styleValue)) { | |
| 129 exceptionState.throwTypeError("Invalid type for property"); | |
| 130 return; | |
| 131 } | |
| 132 cssValueList->append(styleValue->toCSSValue()); | |
| 133 } | |
| 134 } else { | |
| 135 // Parse it. | |
| 136 ASSERT(item.isString()); | |
| 137 // TODO(meade): Implement this. | |
| 138 exceptionState.throwTypeError("Not implemented yet"); | |
| 139 return; | |
| 140 } | |
| 141 | |
| 142 m_ownerElement->setInlineStyleProperty(propertyID, cssValueList); | |
| 143 } | |
| 144 | |
| 145 void InlineStylePropertyMap::remove(CSSPropertyID propertyID, ExceptionState& ex ceptionState) | |
| 146 { | |
| 147 m_ownerElement->removeInlineStyleProperty(propertyID); | |
| 148 } | |
| 149 | |
| 150 } // namespace blink | |
| 151 | |
| OLD | NEW |