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

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

Issue 2274463002: [Typed OM] Add CSSValue -> CSSNumberValue conversion (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add test for computed style Created 4 years, 4 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 06b39b29952a36c3b2e4181cfbd765b9995f6465..b997c958923d94866a434cf045205fb824d9bf60 100644
--- a/third_party/WebKit/Source/core/css/cssom/InlineStylePropertyMap.cpp
+++ b/third_party/WebKit/Source/core/css/cssom/InlineStylePropertyMap.cpp
@@ -28,6 +28,35 @@ const CSSValue* styleValueToCSSValue(CSSPropertyID propertyID, const CSSStyleVal
return styleValue.toCSSValueWithProperty(propertyID);
}
+const CSSValue* singleStyleValueAsCSSValue(CSSPropertyID propertyID, const CSSStyleValue& styleValue)
+{
+ if (!CSSPropertyMetadata::propertySupportsMultiple(propertyID))
+ return styleValueToCSSValue(propertyID, styleValue);
+
+ const CSSValue* cssValue = styleValueToCSSValue(propertyID, styleValue);
+ if (!cssValue)
+ return nullptr;
+
+ // TODO(meade): Determine the correct separator for each property.
+ CSSValueList* valueList = CSSValueList::createSpaceSeparated();
+ valueList->append(*cssValue);
+ return valueList;
+}
+
+CSSValueList* asCSSValueList(CSSPropertyID propertyID, const CSSStyleValueVector& styleValueVector)
+{
+ // TODO(meade): Determine the correct separator for each property.
+ CSSValueList* valueList = CSSValueList::createSpaceSeparated();
+ for (const CSSStyleValue* value : styleValueVector) {
+ const CSSValue* cssValue = styleValueToCSSValue(propertyID, *value);
+ if (!cssValue) {
+ return nullptr;
+ }
+ valueList->append(*cssValue);
+ }
+ return valueList;
+}
+
} // namespace
CSSStyleValueVector InlineStylePropertyMap::getAllInternal(CSSPropertyID propertyID)
@@ -74,38 +103,27 @@ Vector<String> InlineStylePropertyMap::getProperties()
void InlineStylePropertyMap::set(CSSPropertyID propertyID, CSSStyleValueOrCSSStyleValueSequenceOrString& item, ExceptionState& exceptionState)
{
+ const CSSValue* cssValue = nullptr;
if (item.isCSSStyleValue()) {
- const 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) {
- const 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)
@@ -117,7 +135,10 @@ void InlineStylePropertyMap::append(CSSPropertyID propertyID, CSSStyleValueOrCSS
const CSSValue* cssValue = m_ownerElement->ensureMutableInlineStyle().getPropertyCSSValue(propertyID);
CSSValueList* cssValueList = nullptr;
- if (cssValue->isValueList()) {
+ if (!cssValue) {
+ // TODO(meade): Determine the correct separator for each property.
+ 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