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

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

Issue 2160483002: Make CSSStyleValue::toCSSValue() return a const CSSValue* (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@_make_cssvaluepair_take_const
Patch Set: 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 unified diff | Download patch
OLDNEW
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"
11 #include "core/css/CSSPrimitiveValue.h" 11 #include "core/css/CSSPrimitiveValue.h"
12 #include "core/css/CSSPropertyMetadata.h" 12 #include "core/css/CSSPropertyMetadata.h"
13 #include "core/css/CSSValueList.h" 13 #include "core/css/CSSValueList.h"
14 #include "core/css/StylePropertySet.h" 14 #include "core/css/StylePropertySet.h"
15 #include "core/css/cssom/CSSOMTypes.h" 15 #include "core/css/cssom/CSSOMTypes.h"
16 #include "core/css/cssom/CSSSimpleLength.h" 16 #include "core/css/cssom/CSSSimpleLength.h"
17 #include "core/css/cssom/CSSUnsupportedStyleValue.h" 17 #include "core/css/cssom/CSSUnsupportedStyleValue.h"
18 #include "core/css/cssom/StyleValueFactory.h" 18 #include "core/css/cssom/StyleValueFactory.h"
19 19
20 namespace blink { 20 namespace blink {
21 21
22 namespace { 22 namespace {
23 23
24 CSSValue* styleValueToCSSValue(CSSPropertyID propertyID, const CSSStyleValue& st yleValue) 24 const CSSValue* styleValueToCSSValue(CSSPropertyID propertyID, const CSSStyleVal ue& styleValue)
25 { 25 {
26 if (!CSSOMTypes::propertyCanTake(propertyID, styleValue)) 26 if (!CSSOMTypes::propertyCanTake(propertyID, styleValue))
27 return nullptr; 27 return nullptr;
28 return styleValue.toCSSValueWithProperty(propertyID); 28 return styleValue.toCSSValueWithProperty(propertyID);
29 } 29 }
30 30
31 } // namespace 31 } // namespace
32 32
33 CSSStyleValueVector InlineStylePropertyMap::getAllInternal(CSSPropertyID propert yID) 33 CSSStyleValueVector InlineStylePropertyMap::getAllInternal(CSSPropertyID propert yID)
34 { 34 {
(...skipping 20 matching lines...) Expand all
55 for (unsigned i = 0; i < inlineStyleSet.propertyCount(); i++) { 55 for (unsigned i = 0; i < inlineStyleSet.propertyCount(); i++) {
56 CSSPropertyID propertyID = inlineStyleSet.propertyAt(i).id(); 56 CSSPropertyID propertyID = inlineStyleSet.propertyAt(i).id();
57 result.append(getPropertyNameString(propertyID)); 57 result.append(getPropertyNameString(propertyID));
58 } 58 }
59 return result; 59 return result;
60 } 60 }
61 61
62 void InlineStylePropertyMap::set(CSSPropertyID propertyID, CSSStyleValueOrCSSSty leValueSequenceOrString& item, ExceptionState& exceptionState) 62 void InlineStylePropertyMap::set(CSSPropertyID propertyID, CSSStyleValueOrCSSSty leValueSequenceOrString& item, ExceptionState& exceptionState)
63 { 63 {
64 if (item.isCSSStyleValue()) { 64 if (item.isCSSStyleValue()) {
65 CSSValue* cssValue = styleValueToCSSValue(propertyID, *item.getAsCSSStyl eValue()); 65 const CSSValue* cssValue = styleValueToCSSValue(propertyID, *item.getAsC SSStyleValue());
66 if (!cssValue) { 66 if (!cssValue) {
67 exceptionState.throwTypeError("Invalid type for property"); 67 exceptionState.throwTypeError("Invalid type for property");
68 return; 68 return;
69 } 69 }
70 m_ownerElement->setInlineStyleProperty(propertyID, cssValue); 70 m_ownerElement->setInlineStyleProperty(propertyID, cssValue);
71 } else if (item.isCSSStyleValueSequence()) { 71 } else if (item.isCSSStyleValueSequence()) {
72 if (!CSSPropertyMetadata::propertySupportsMultiple(propertyID)) { 72 if (!CSSPropertyMetadata::propertySupportsMultiple(propertyID)) {
73 exceptionState.throwTypeError("Property does not support multiple va lues"); 73 exceptionState.throwTypeError("Property does not support multiple va lues");
74 return; 74 return;
75 } 75 }
76 76
77 // TODO(meade): This won't always work. Figure out what kind of CSSValue List to create properly. 77 // TODO(meade): This won't always work. Figure out what kind of CSSValue List to create properly.
78 CSSValueList* valueList = CSSValueList::createSpaceSeparated(); 78 CSSValueList* valueList = CSSValueList::createSpaceSeparated();
79 CSSStyleValueVector styleValueVector = item.getAsCSSStyleValueSequence() ; 79 CSSStyleValueVector styleValueVector = item.getAsCSSStyleValueSequence() ;
80 for (const Member<CSSStyleValue> value : styleValueVector) { 80 for (const Member<CSSStyleValue> value : styleValueVector) {
81 CSSValue* cssValue = styleValueToCSSValue(propertyID, *value); 81 const CSSValue* cssValue = styleValueToCSSValue(propertyID, *value);
82 if (!cssValue) { 82 if (!cssValue) {
83 exceptionState.throwTypeError("Invalid type for property"); 83 exceptionState.throwTypeError("Invalid type for property");
84 return; 84 return;
85 } 85 }
86 valueList->append(*cssValue); 86 valueList->append(*cssValue);
87 } 87 }
88 88
89 m_ownerElement->setInlineStyleProperty(propertyID, valueList); 89 m_ownerElement->setInlineStyleProperty(propertyID, valueList);
90 } else { 90 } else {
91 // Parse it. 91 // Parse it.
(...skipping 14 matching lines...) Expand all
106 CSSValueList* cssValueList = nullptr; 106 CSSValueList* cssValueList = nullptr;
107 if (cssValue->isValueList()) { 107 if (cssValue->isValueList()) {
108 cssValueList = toCSSValueList(cssValue)->copy(); 108 cssValueList = toCSSValueList(cssValue)->copy();
109 } else { 109 } else {
110 // TODO(meade): Figure out what the correct behaviour here is. 110 // TODO(meade): Figure out what the correct behaviour here is.
111 exceptionState.throwTypeError("Property is not already list valued"); 111 exceptionState.throwTypeError("Property is not already list valued");
112 return; 112 return;
113 } 113 }
114 114
115 if (item.isCSSStyleValue()) { 115 if (item.isCSSStyleValue()) {
116 CSSValue* cssValue = styleValueToCSSValue(propertyID, *item.getAsCSSStyl eValue()); 116 const CSSValue* cssValue = styleValueToCSSValue(propertyID, *item.getAsC SSStyleValue());
117 if (!cssValue) { 117 if (!cssValue) {
118 exceptionState.throwTypeError("Invalid type for property"); 118 exceptionState.throwTypeError("Invalid type for property");
119 return; 119 return;
120 } 120 }
121 cssValueList->append(*cssValue); 121 cssValueList->append(*cssValue);
122 } else if (item.isCSSStyleValueSequence()) { 122 } else if (item.isCSSStyleValueSequence()) {
123 for (CSSStyleValue* styleValue : item.getAsCSSStyleValueSequence()) { 123 for (CSSStyleValue* styleValue : item.getAsCSSStyleValueSequence()) {
124 CSSValue* cssValue = styleValueToCSSValue(propertyID, *styleValue); 124 const CSSValue* cssValue = styleValueToCSSValue(propertyID, *styleVa lue);
125 if (!cssValue) { 125 if (!cssValue) {
126 exceptionState.throwTypeError("Invalid type for property"); 126 exceptionState.throwTypeError("Invalid type for property");
127 return; 127 return;
128 } 128 }
129 cssValueList->append(*cssValue); 129 cssValueList->append(*cssValue);
130 } 130 }
131 } else { 131 } else {
132 // Parse it. 132 // Parse it.
133 DCHECK(item.isString()); 133 DCHECK(item.isString());
134 // TODO(meade): Implement this. 134 // TODO(meade): Implement this.
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 else 169 else
170 value.setCSSStyleValueSequence(styleValueVector); 170 value.setCSSStyleValueSequence(styleValueVector);
171 } 171 }
172 result.append(std::make_pair(name, value)); 172 result.append(std::make_pair(name, value));
173 } 173 }
174 return result; 174 return result;
175 } 175 }
176 176
177 } // namespace blink 177 } // namespace blink
178 178
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/css/cssom/CSSUnsupportedStyleValue.cpp ('k') | third_party/WebKit/Source/core/dom/Element.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698