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

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

Issue 2038773002: [Typed OM] Add an "UnsupportedStyleValue" in C++ that just has a string for unknown types (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@stylevaue
Patch Set: Address comments about comments Created 4 years, 6 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/CSSPrimitiveValue.h" 9 #include "core/css/CSSPrimitiveValue.h"
10 #include "core/css/CSSPropertyMetadata.h" 10 #include "core/css/CSSPropertyMetadata.h"
11 #include "core/css/CSSValueList.h" 11 #include "core/css/CSSValueList.h"
12 #include "core/css/StylePropertySet.h" 12 #include "core/css/StylePropertySet.h"
13 #include "core/css/cssom/CSSOMTypes.h" 13 #include "core/css/cssom/CSSOMTypes.h"
14 #include "core/css/cssom/CSSSimpleLength.h" 14 #include "core/css/cssom/CSSSimpleLength.h"
15 #include "core/css/cssom/StyleValueFactory.h" 15 #include "core/css/cssom/StyleValueFactory.h"
16 16
17 namespace blink { 17 namespace blink {
18 18
19 namespace {
20
21 CSSValue* styleValueToCSSValue(CSSPropertyID propertyID, const CSSStyleValue& st yleValue)
22 {
23 if (!CSSOMTypes::propertyCanTake(propertyID, styleValue))
24 return nullptr;
25 return styleValue.toCSSValueWithProperty(propertyID);
26 }
27
28 } // namespace
29
19 CSSStyleValueVector InlineStylePropertyMap::getAll(CSSPropertyID propertyID) 30 CSSStyleValueVector InlineStylePropertyMap::getAll(CSSPropertyID propertyID)
20 { 31 {
21 CSSValue* cssValue = m_ownerElement->ensureMutableInlineStyle().getPropertyC SSValue(propertyID); 32 CSSValue* cssValue = m_ownerElement->ensureMutableInlineStyle().getPropertyC SSValue(propertyID);
22 if (!cssValue) 33 if (!cssValue)
23 return CSSStyleValueVector(); 34 return CSSStyleValueVector();
24 35
25 return StyleValueFactory::cssValueToStyleValueVector(propertyID, *cssValue); 36 return StyleValueFactory::cssValueToStyleValueVector(propertyID, *cssValue);
26 } 37 }
27 38
28 Vector<String> InlineStylePropertyMap::getProperties() 39 Vector<String> InlineStylePropertyMap::getProperties()
29 { 40 {
30 Vector<String> result; 41 Vector<String> result;
31 StylePropertySet& inlineStyleSet = m_ownerElement->ensureMutableInlineStyle( ); 42 StylePropertySet& inlineStyleSet = m_ownerElement->ensureMutableInlineStyle( );
32 for (unsigned i = 0; i < inlineStyleSet.propertyCount(); i++) { 43 for (unsigned i = 0; i < inlineStyleSet.propertyCount(); i++) {
33 CSSPropertyID propertyID = inlineStyleSet.propertyAt(i).id(); 44 CSSPropertyID propertyID = inlineStyleSet.propertyAt(i).id();
34 result.append(getPropertyNameString(propertyID)); 45 result.append(getPropertyNameString(propertyID));
35 } 46 }
36 return result; 47 return result;
37 } 48 }
38 49
39 void InlineStylePropertyMap::set(CSSPropertyID propertyID, CSSStyleValueOrCSSSty leValueSequenceOrString& item, ExceptionState& exceptionState) 50 void InlineStylePropertyMap::set(CSSPropertyID propertyID, CSSStyleValueOrCSSSty leValueSequenceOrString& item, ExceptionState& exceptionState)
40 { 51 {
41 if (item.isCSSStyleValue()) { 52 if (item.isCSSStyleValue()) {
42 CSSStyleValue* styleValue = item.getAsCSSStyleValue(); 53 CSSValue* cssValue = styleValueToCSSValue(propertyID, *item.getAsCSSStyl eValue());
43 if (!CSSOMTypes::propertyCanTake(propertyID, *styleValue)) { 54 if (!cssValue) {
44 exceptionState.throwTypeError("Invalid type for property"); 55 exceptionState.throwTypeError("Invalid type for property");
45 return; 56 return;
46 } 57 }
47 m_ownerElement->setInlineStyleProperty(propertyID, styleValue->toCSSValu e()); 58 m_ownerElement->setInlineStyleProperty(propertyID, cssValue);
48 } else if (item.isCSSStyleValueSequence()) { 59 } else if (item.isCSSStyleValueSequence()) {
49 if (!CSSPropertyMetadata::propertySupportsMultiple(propertyID)) { 60 if (!CSSPropertyMetadata::propertySupportsMultiple(propertyID)) {
50 exceptionState.throwTypeError("Property does not support multiple va lues"); 61 exceptionState.throwTypeError("Property does not support multiple va lues");
51 return; 62 return;
52 } 63 }
53 64
54 // TODO(meade): This won't always work. Figure out what kind of CSSValue List to create properly. 65 // TODO(meade): This won't always work. Figure out what kind of CSSValue List to create properly.
55 CSSValueList* valueList = CSSValueList::createSpaceSeparated(); 66 CSSValueList* valueList = CSSValueList::createSpaceSeparated();
56 CSSStyleValueVector styleValueVector = item.getAsCSSStyleValueSequence() ; 67 CSSStyleValueVector styleValueVector = item.getAsCSSStyleValueSequence() ;
57 for (const Member<CSSStyleValue> value : styleValueVector) { 68 for (const Member<CSSStyleValue> value : styleValueVector) {
58 if (!CSSOMTypes::propertyCanTake(propertyID, *value)) { 69 CSSValue* cssValue = styleValueToCSSValue(propertyID, *value);
70 if (!cssValue) {
59 exceptionState.throwTypeError("Invalid type for property"); 71 exceptionState.throwTypeError("Invalid type for property");
60 return; 72 return;
61 } 73 }
62 valueList->append(*value->toCSSValue()); 74 valueList->append(*cssValue);
63 } 75 }
64 76
65 m_ownerElement->setInlineStyleProperty(propertyID, valueList); 77 m_ownerElement->setInlineStyleProperty(propertyID, valueList);
66 } else { 78 } else {
67 // Parse it. 79 // Parse it.
68 ASSERT(item.isString()); 80 DCHECK(item.isString());
69 // TODO(meade): Implement this. 81 // TODO(meade): Implement this.
70 exceptionState.throwTypeError("Not implemented yet"); 82 exceptionState.throwTypeError("Not implemented yet");
71 } 83 }
72 } 84 }
73 85
74 void InlineStylePropertyMap::append(CSSPropertyID propertyID, CSSStyleValueOrCSS StyleValueSequenceOrString& item, ExceptionState& exceptionState) 86 void InlineStylePropertyMap::append(CSSPropertyID propertyID, CSSStyleValueOrCSS StyleValueSequenceOrString& item, ExceptionState& exceptionState)
75 { 87 {
76 if (!CSSPropertyMetadata::propertySupportsMultiple(propertyID)) { 88 if (!CSSPropertyMetadata::propertySupportsMultiple(propertyID)) {
77 exceptionState.throwTypeError("Property does not support multiple values "); 89 exceptionState.throwTypeError("Property does not support multiple values ");
78 return; 90 return;
79 } 91 }
80 92
81 CSSValue* cssValue = m_ownerElement->ensureMutableInlineStyle().getPropertyC SSValue(propertyID); 93 CSSValue* cssValue = m_ownerElement->ensureMutableInlineStyle().getPropertyC SSValue(propertyID);
82 CSSValueList* cssValueList = nullptr; 94 CSSValueList* cssValueList = nullptr;
83 if (cssValue->isValueList()) { 95 if (cssValue->isValueList()) {
84 cssValueList = toCSSValueList(cssValue); 96 cssValueList = toCSSValueList(cssValue);
85 } else { 97 } else {
86 // TODO(meade): Figure out what the correct behaviour here is. 98 // TODO(meade): Figure out what the correct behaviour here is.
87 exceptionState.throwTypeError("Property is not already list valued"); 99 exceptionState.throwTypeError("Property is not already list valued");
88 return; 100 return;
89 } 101 }
90 102
91 if (item.isCSSStyleValue()) { 103 if (item.isCSSStyleValue()) {
92 CSSStyleValue* styleValue = item.getAsCSSStyleValue(); 104 CSSValue* cssValue = styleValueToCSSValue(propertyID, *item.getAsCSSStyl eValue());
93 if (!CSSOMTypes::propertyCanTake(propertyID, *styleValue)) { 105 if (!cssValue) {
94 exceptionState.throwTypeError("Invalid type for property"); 106 exceptionState.throwTypeError("Invalid type for property");
95 return; 107 return;
96 } 108 }
97 cssValueList->append(*item.getAsCSSStyleValue()->toCSSValue()); 109 cssValueList->append(*cssValue);
98 } else if (item.isCSSStyleValueSequence()) { 110 } else if (item.isCSSStyleValueSequence()) {
99 for (CSSStyleValue* styleValue : item.getAsCSSStyleValueSequence()) { 111 for (CSSStyleValue* styleValue : item.getAsCSSStyleValueSequence()) {
100 if (!CSSOMTypes::propertyCanTake(propertyID, *styleValue)) { 112 CSSValue* cssValue = styleValueToCSSValue(propertyID, *styleValue);
113 if (!cssValue) {
101 exceptionState.throwTypeError("Invalid type for property"); 114 exceptionState.throwTypeError("Invalid type for property");
102 return; 115 return;
103 } 116 }
104 cssValueList->append(*styleValue->toCSSValue()); 117 cssValueList->append(*cssValue);
105 } 118 }
106 } else { 119 } else {
107 // Parse it. 120 // Parse it.
108 ASSERT(item.isString()); 121 DCHECK(item.isString());
109 // TODO(meade): Implement this. 122 // TODO(meade): Implement this.
110 exceptionState.throwTypeError("Not implemented yet"); 123 exceptionState.throwTypeError("Not implemented yet");
111 return; 124 return;
112 } 125 }
113 126
114 m_ownerElement->setInlineStyleProperty(propertyID, cssValueList); 127 m_ownerElement->setInlineStyleProperty(propertyID, cssValueList);
115 } 128 }
116 129
117 void InlineStylePropertyMap::remove(CSSPropertyID propertyID, ExceptionState& ex ceptionState) 130 void InlineStylePropertyMap::remove(CSSPropertyID propertyID, ExceptionState& ex ceptionState)
118 { 131 {
(...skipping 13 matching lines...) Expand all
132 value.setCSSStyleValue(styleValueVector[0]); 145 value.setCSSStyleValue(styleValueVector[0]);
133 else 146 else
134 value.setCSSStyleValueSequence(styleValueVector); 147 value.setCSSStyleValueSequence(styleValueVector);
135 result.append(std::make_pair(getPropertyNameString(propertyID), value)); 148 result.append(std::make_pair(getPropertyNameString(propertyID), value));
136 } 149 }
137 return result; 150 return result;
138 } 151 }
139 152
140 } // namespace blink 153 } // namespace blink
141 154
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698