Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(115)

Unified Diff: third_party/WebKit/Source/core/css/cssom/InlineStylePropertyMap.cpp

Issue 2096133002: [Typed OM] Add support for properties which take numbers in CSSProperties.in (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: sync to head Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/css/cssom/InlineStylePropertyMap.cpp
diff --git a/third_party/WebKit/Source/core/css/cssom/InlineStylePropertyMap.cpp b/third_party/WebKit/Source/core/css/cssom/InlineStylePropertyMap.cpp
index 215887e5eeffbbc952ce234576e62f4eddd24744..d9530f390c91b2b03fb0f38d1267cc9fcbb3391a 100644
--- a/third_party/WebKit/Source/core/css/cssom/InlineStylePropertyMap.cpp
+++ b/third_party/WebKit/Source/core/css/cssom/InlineStylePropertyMap.cpp
@@ -25,6 +25,35 @@ CSSValue* styleValueToCSSValue(CSSPropertyID propertyID, const CSSStyleValue& st
return styleValue.toCSSValueWithProperty(propertyID);
}
+CSSValue* singleStyleValueAsCSSValue(CSSPropertyID propertyID, const CSSStyleValue& styleValue)
+{
+ if (!CSSPropertyMetadata::propertySupportsMultiple(propertyID))
+ return styleValueToCSSValue(propertyID, styleValue);
+
+ CSSValue* cssValue = styleValueToCSSValue(propertyID, styleValue);
+ if (!cssValue)
+ return nullptr;
+
+ // TODO(meade): This won't always work. Figure out what kind of CSSValueList to create properly.
+ CSSValueList* valueList = CSSValueList::createSpaceSeparated();
+ valueList->append(*cssValue);
+ return valueList;
+}
+
+CSSValueList* asCSSValueList(CSSPropertyID propertyID, const CSSStyleValueVector& styleValueVector)
+{
+ // TODO(meade): This won't always work. Figure out what kind of CSSValueList to create properly.
+ CSSValueList* valueList = CSSValueList::createSpaceSeparated();
+ for (const Member<CSSStyleValue> value : styleValueVector) {
+ CSSValue* cssValue = styleValueToCSSValue(propertyID, *value);
+ if (!cssValue) {
+ return nullptr;
+ }
+ valueList->append(*cssValue);
+ }
+ return valueList;
+}
+
} // namespace
CSSStyleValueVector InlineStylePropertyMap::getAllInternal(CSSPropertyID propertyID)
@@ -58,38 +87,27 @@ Vector<String> InlineStylePropertyMap::getProperties()
void InlineStylePropertyMap::set(CSSPropertyID propertyID, CSSStyleValueOrCSSStyleValueSequenceOrString& item, ExceptionState& exceptionState)
{
+ CSSValue* cssValue = nullptr;
if (item.isCSSStyleValue()) {
- CSSValue* cssValue = styleValueToCSSValue(propertyID, *item.getAsCSSStyleValue());
- if (!cssValue) {
- exceptionState.throwTypeError("Invalid type for property");
- return;
- }
- m_ownerElement->setInlineStyleProperty(propertyID, cssValue);
+ cssValue = singleStyleValueAsCSSValue(propertyID, *item.getAsCSSStyleValue());
} else if (item.isCSSStyleValueSequence()) {
if (!CSSPropertyMetadata::propertySupportsMultiple(propertyID)) {
exceptionState.throwTypeError("Property does not support multiple values");
return;
}
-
- // TODO(meade): This won't always work. Figure out what kind of CSSValueList to create properly.
- CSSValueList* valueList = CSSValueList::createSpaceSeparated();
- CSSStyleValueVector styleValueVector = item.getAsCSSStyleValueSequence();
- for (const Member<CSSStyleValue> value : styleValueVector) {
- CSSValue* cssValue = styleValueToCSSValue(propertyID, *value);
- if (!cssValue) {
- exceptionState.throwTypeError("Invalid type for property");
- return;
- }
- valueList->append(*cssValue);
- }
-
- m_ownerElement->setInlineStyleProperty(propertyID, valueList);
+ cssValue = asCSSValueList(propertyID, item.getAsCSSStyleValueSequence());
} else {
// Parse it.
DCHECK(item.isString());
// TODO(meade): Implement this.
exceptionState.throwTypeError("Not implemented yet");
+ return;
+ }
+ if (!cssValue) {
+ exceptionState.throwTypeError("Invalid type for property");
+ return;
}
+ m_ownerElement->setInlineStyleProperty(propertyID, cssValue);
}
void InlineStylePropertyMap::append(CSSPropertyID propertyID, CSSStyleValueOrCSSStyleValueSequenceOrString& item, ExceptionState& exceptionState)
@@ -101,7 +119,9 @@ void InlineStylePropertyMap::append(CSSPropertyID propertyID, CSSStyleValueOrCSS
const CSSValue* cssValue = m_ownerElement->ensureMutableInlineStyle().getPropertyCSSValue(propertyID);
CSSValueList* cssValueList = nullptr;
- if (cssValue->isValueList()) {
+ if (!cssValue) {
+ cssValueList = CSSValueList::createSpaceSeparated();
+ } else if (cssValue->isValueList()) {
cssValueList = toCSSValueList(cssValue)->copy();
} else {
// TODO(meade): Figure out what the correct behaviour here is.
« no previous file with comments | « third_party/WebKit/Source/core/css/CSSProperties.in ('k') | third_party/WebKit/Source/core/css/cssom/StyleValueFactory.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698