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/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); | |
|
esprehn
2016/08/10 04:01:06
Hmm, I also wonder if we're supposed to add the na
meade_UTC10
2016/08/10 04:22:32
The spec doesn't say anything at all about @apply
| |
| 66 containsAtApply = true; | |
| 67 } | |
| 68 } else { | |
| 69 DCHECK(propertyID >= firstCSSProperty && propertyID <= lastUnresolve dCSSProperty); | |
|
esprehn
2016/08/10 04:01:06
getPropertyNameString actually contains this asser
meade_UTC10
2016/08/10 04:22:32
Removed.
| |
| 70 result.append(getPropertyNameString(propertyID)); | |
| 71 } | |
| 58 } | 72 } |
| 59 return result; | 73 return result; |
| 60 } | 74 } |
| 61 | 75 |
| 62 void InlineStylePropertyMap::set(CSSPropertyID propertyID, CSSStyleValueOrCSSSty leValueSequenceOrString& item, ExceptionState& exceptionState) | 76 void InlineStylePropertyMap::set(CSSPropertyID propertyID, CSSStyleValueOrCSSSty leValueSequenceOrString& item, ExceptionState& exceptionState) |
| 63 { | 77 { |
| 64 if (item.isCSSStyleValue()) { | 78 if (item.isCSSStyleValue()) { |
| 65 const CSSValue* cssValue = styleValueToCSSValue(propertyID, *item.getAsC SSStyleValue()); | 79 const CSSValue* cssValue = styleValueToCSSValue(propertyID, *item.getAsC SSStyleValue()); |
| 66 if (!cssValue) { | 80 if (!cssValue) { |
| 67 exceptionState.throwTypeError("Invalid type for property"); | 81 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); | 153 m_ownerElement->setInlineStyleProperty(propertyID, cssValueList); |
| 140 } | 154 } |
| 141 | 155 |
| 142 void InlineStylePropertyMap::remove(CSSPropertyID propertyID, ExceptionState& ex ceptionState) | 156 void InlineStylePropertyMap::remove(CSSPropertyID propertyID, ExceptionState& ex ceptionState) |
| 143 { | 157 { |
| 144 m_ownerElement->removeInlineStyleProperty(propertyID); | 158 m_ownerElement->removeInlineStyleProperty(propertyID); |
| 145 } | 159 } |
| 146 | 160 |
| 147 HeapVector<StylePropertyMap::StylePropertyMapEntry> InlineStylePropertyMap::getI terationEntries() | 161 HeapVector<StylePropertyMap::StylePropertyMapEntry> InlineStylePropertyMap::getI terationEntries() |
| 148 { | 162 { |
| 163 DEFINE_STATIC_LOCAL(const String, kAtApply, "@apply"); | |
| 149 HeapVector<StylePropertyMap::StylePropertyMapEntry> result; | 164 HeapVector<StylePropertyMap::StylePropertyMapEntry> result; |
| 150 StylePropertySet& inlineStyleSet = m_ownerElement->ensureMutableInlineStyle( ); | 165 StylePropertySet& inlineStyleSet = m_ownerElement->ensureMutableInlineStyle( ); |
| 151 for (unsigned i = 0; i < inlineStyleSet.propertyCount(); i++) { | 166 for (unsigned i = 0; i < inlineStyleSet.propertyCount(); i++) { |
| 152 StylePropertySet::PropertyReference propertyReference = inlineStyleSet.p ropertyAt(i); | 167 StylePropertySet::PropertyReference propertyReference = inlineStyleSet.p ropertyAt(i); |
| 153 CSSPropertyID propertyID = propertyReference.id(); | 168 CSSPropertyID propertyID = propertyReference.id(); |
| 154 String name; | 169 String name; |
| 155 CSSStyleValueOrCSSStyleValueSequence value; | 170 CSSStyleValueOrCSSStyleValueSequence value; |
| 156 if (propertyID == CSSPropertyVariable) { | 171 if (propertyID == CSSPropertyVariable) { |
| 157 const CSSCustomPropertyDeclaration& customDeclaration = toCSSCustomP ropertyDeclaration(propertyReference.value()); | 172 const CSSCustomPropertyDeclaration& customDeclaration = toCSSCustomP ropertyDeclaration(propertyReference.value()); |
| 158 name = customDeclaration.name(); | 173 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. | 174 // 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())); | 175 value.setCSSStyleValue(CSSUnsupportedStyleValue::create(customDeclar ation.customCSSText())); |
| 161 } else if (propertyID == CSSPropertyApplyAtRule) { | 176 } else if (propertyID == CSSPropertyApplyAtRule) { |
| 162 name = "@apply"; | 177 name = kAtApply; |
| 163 value.setCSSStyleValue(CSSUnsupportedStyleValue::create(toCSSCustomI dentValue(propertyReference.value()).value())); | 178 value.setCSSStyleValue(CSSUnsupportedStyleValue::create(toCSSCustomI dentValue(propertyReference.value()).value())); |
| 164 } else { | 179 } else { |
| 165 name = getPropertyNameString(propertyID); | 180 name = getPropertyNameString(propertyID); |
| 166 CSSStyleValueVector styleValueVector = StyleValueFactory::cssValueTo StyleValueVector(propertyID, propertyReference.value()); | 181 CSSStyleValueVector styleValueVector = StyleValueFactory::cssValueTo StyleValueVector(propertyID, propertyReference.value()); |
| 167 if (styleValueVector.size() == 1) | 182 if (styleValueVector.size() == 1) |
| 168 value.setCSSStyleValue(styleValueVector[0]); | 183 value.setCSSStyleValue(styleValueVector[0]); |
| 169 else | 184 else |
| 170 value.setCSSStyleValueSequence(styleValueVector); | 185 value.setCSSStyleValueSequence(styleValueVector); |
| 171 } | 186 } |
| 172 result.append(std::make_pair(name, value)); | 187 result.append(std::make_pair(name, value)); |
| 173 } | 188 } |
| 174 return result; | 189 return result; |
| 175 } | 190 } |
| 176 | 191 |
| 177 } // namespace blink | 192 } // namespace blink |
| 178 | 193 |
| OLD | NEW |