| 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/CSSCustomIdentValue.h" | 9 #include "core/css/CSSCustomIdentValue.h" |
| 10 #include "core/css/CSSCustomPropertyDeclaration.h" | 10 #include "core/css/CSSCustomPropertyDeclaration.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 { | 43 { |
| 44 const CSSValue* cssValue = m_ownerElement->ensureMutableInlineStyle().getPro
pertyCSSValue(customPropertyName); | 44 const CSSValue* cssValue = m_ownerElement->ensureMutableInlineStyle().getPro
pertyCSSValue(customPropertyName); |
| 45 if (!cssValue) | 45 if (!cssValue) |
| 46 return CSSStyleValueVector(); | 46 return CSSStyleValueVector(); |
| 47 | 47 |
| 48 return StyleValueFactory::cssValueToStyleValueVector(CSSPropertyInvalid, *cs
sValue); | 48 return StyleValueFactory::cssValueToStyleValueVector(CSSPropertyInvalid, *cs
sValue); |
| 49 } | 49 } |
| 50 | 50 |
| 51 Vector<String> InlineStylePropertyMap::getProperties() | 51 Vector<String> InlineStylePropertyMap::getProperties() |
| 52 { | 52 { |
| 53 DEFINE_STATIC_LOCAL(const String, kAtApply, ("@apply")); |
| 53 Vector<String> result; | 54 Vector<String> result; |
| 55 bool containsAtApply = false; |
| 54 StylePropertySet& inlineStyleSet = m_ownerElement->ensureMutableInlineStyle(
); | 56 StylePropertySet& inlineStyleSet = m_ownerElement->ensureMutableInlineStyle(
); |
| 55 for (unsigned i = 0; i < inlineStyleSet.propertyCount(); i++) { | 57 for (unsigned i = 0; i < inlineStyleSet.propertyCount(); i++) { |
| 56 CSSPropertyID propertyID = inlineStyleSet.propertyAt(i).id(); | 58 CSSPropertyID propertyID = inlineStyleSet.propertyAt(i).id(); |
| 57 result.append(getPropertyNameString(propertyID)); | 59 if (propertyID == CSSPropertyVariable) { |
| 60 StylePropertySet::PropertyReference propertyReference = inlineStyleS
et.propertyAt(i); |
| 61 const CSSCustomPropertyDeclaration& customDeclaration = toCSSCustomP
ropertyDeclaration(propertyReference.value()); |
| 62 result.append(customDeclaration.name()); |
| 63 } else if (propertyID == CSSPropertyApplyAtRule) { |
| 64 if (!containsAtApply) { |
| 65 result.append(kAtApply); |
| 66 containsAtApply = true; |
| 67 } |
| 68 } else { |
| 69 result.append(getPropertyNameString(propertyID)); |
| 70 } |
| 58 } | 71 } |
| 59 return result; | 72 return result; |
| 60 } | 73 } |
| 61 | 74 |
| 62 void InlineStylePropertyMap::set(CSSPropertyID propertyID, CSSStyleValueOrCSSSty
leValueSequenceOrString& item, ExceptionState& exceptionState) | 75 void InlineStylePropertyMap::set(CSSPropertyID propertyID, CSSStyleValueOrCSSSty
leValueSequenceOrString& item, ExceptionState& exceptionState) |
| 63 { | 76 { |
| 64 if (item.isCSSStyleValue()) { | 77 if (item.isCSSStyleValue()) { |
| 65 const CSSValue* cssValue = styleValueToCSSValue(propertyID, *item.getAsC
SSStyleValue()); | 78 const CSSValue* cssValue = styleValueToCSSValue(propertyID, *item.getAsC
SSStyleValue()); |
| 66 if (!cssValue) { | 79 if (!cssValue) { |
| 67 exceptionState.throwTypeError("Invalid type for property"); | 80 exceptionState.throwTypeError("Invalid type for property"); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 m_ownerElement->setInlineStyleProperty(propertyID, cssValueList); | 152 m_ownerElement->setInlineStyleProperty(propertyID, cssValueList); |
| 140 } | 153 } |
| 141 | 154 |
| 142 void InlineStylePropertyMap::remove(CSSPropertyID propertyID, ExceptionState& ex
ceptionState) | 155 void InlineStylePropertyMap::remove(CSSPropertyID propertyID, ExceptionState& ex
ceptionState) |
| 143 { | 156 { |
| 144 m_ownerElement->removeInlineStyleProperty(propertyID); | 157 m_ownerElement->removeInlineStyleProperty(propertyID); |
| 145 } | 158 } |
| 146 | 159 |
| 147 HeapVector<StylePropertyMap::StylePropertyMapEntry> InlineStylePropertyMap::getI
terationEntries() | 160 HeapVector<StylePropertyMap::StylePropertyMapEntry> InlineStylePropertyMap::getI
terationEntries() |
| 148 { | 161 { |
| 162 DEFINE_STATIC_LOCAL(const String, kAtApply, ("@apply")); |
| 149 HeapVector<StylePropertyMap::StylePropertyMapEntry> result; | 163 HeapVector<StylePropertyMap::StylePropertyMapEntry> result; |
| 150 StylePropertySet& inlineStyleSet = m_ownerElement->ensureMutableInlineStyle(
); | 164 StylePropertySet& inlineStyleSet = m_ownerElement->ensureMutableInlineStyle(
); |
| 151 for (unsigned i = 0; i < inlineStyleSet.propertyCount(); i++) { | 165 for (unsigned i = 0; i < inlineStyleSet.propertyCount(); i++) { |
| 152 StylePropertySet::PropertyReference propertyReference = inlineStyleSet.p
ropertyAt(i); | 166 StylePropertySet::PropertyReference propertyReference = inlineStyleSet.p
ropertyAt(i); |
| 153 CSSPropertyID propertyID = propertyReference.id(); | 167 CSSPropertyID propertyID = propertyReference.id(); |
| 154 String name; | 168 String name; |
| 155 CSSStyleValueOrCSSStyleValueSequence value; | 169 CSSStyleValueOrCSSStyleValueSequence value; |
| 156 if (propertyID == CSSPropertyVariable) { | 170 if (propertyID == CSSPropertyVariable) { |
| 157 const CSSCustomPropertyDeclaration& customDeclaration = toCSSCustomP
ropertyDeclaration(propertyReference.value()); | 171 const CSSCustomPropertyDeclaration& customDeclaration = toCSSCustomP
ropertyDeclaration(propertyReference.value()); |
| 158 name = customDeclaration.name(); | 172 name = customDeclaration.name(); |
| 159 // TODO(meade): Eventually custom properties will support other type
s, so actually return them instead of always returning a CSSUnsupportedStyleValu
e. | 173 // TODO(meade): Eventually custom properties will support other type
s, so actually return them instead of always returning a CSSUnsupportedStyleValu
e. |
| 160 value.setCSSStyleValue(CSSUnsupportedStyleValue::create(customDeclar
ation.customCSSText())); | 174 value.setCSSStyleValue(CSSUnsupportedStyleValue::create(customDeclar
ation.customCSSText())); |
| 161 } else if (propertyID == CSSPropertyApplyAtRule) { | 175 } else if (propertyID == CSSPropertyApplyAtRule) { |
| 162 name = "@apply"; | 176 name = kAtApply; |
| 163 value.setCSSStyleValue(CSSUnsupportedStyleValue::create(toCSSCustomI
dentValue(propertyReference.value()).value())); | 177 value.setCSSStyleValue(CSSUnsupportedStyleValue::create(toCSSCustomI
dentValue(propertyReference.value()).value())); |
| 164 } else { | 178 } else { |
| 165 name = getPropertyNameString(propertyID); | 179 name = getPropertyNameString(propertyID); |
| 166 CSSStyleValueVector styleValueVector = StyleValueFactory::cssValueTo
StyleValueVector(propertyID, propertyReference.value()); | 180 CSSStyleValueVector styleValueVector = StyleValueFactory::cssValueTo
StyleValueVector(propertyID, propertyReference.value()); |
| 167 if (styleValueVector.size() == 1) | 181 if (styleValueVector.size() == 1) |
| 168 value.setCSSStyleValue(styleValueVector[0]); | 182 value.setCSSStyleValue(styleValueVector[0]); |
| 169 else | 183 else |
| 170 value.setCSSStyleValueSequence(styleValueVector); | 184 value.setCSSStyleValueSequence(styleValueVector); |
| 171 } | 185 } |
| 172 result.append(std::make_pair(name, value)); | 186 result.append(std::make_pair(name, value)); |
| 173 } | 187 } |
| 174 return result; | 188 return result; |
| 175 } | 189 } |
| 176 | 190 |
| 177 } // namespace blink | 191 } // namespace blink |
| 178 | 192 |
| OLD | NEW |