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 1590193002: Partial implementation of inline StylePropertyMap. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@maps
Patch Set: Fix windows maybe Created 4 years, 10 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
(Empty)
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
3 // found in the LICENSE fil
4
5 #include "core/css/cssom/InlineStylePropertyMap.h"
6
7 #include "core/CSSPropertyNames.h"
8 #include "core/css/CSSPrimitiveValue.h"
9 #include "core/css/CSSValueList.h"
10 #include "core/css/StylePropertySet.h"
11 #include "core/css/cssom/CSSOMTypes.h"
12 #include "core/css/cssom/SimpleLength.h"
13
14 namespace blink {
15
16 StyleValue* InlineStylePropertyMap::get(CSSPropertyID propertyID)
17 {
18 ASSERT(propertyID != CSSPropertyInvalid);
19
20 updatePropertyIfNeeded(propertyID);
21
22 if (!m_styles.contains(propertyID)) {
23 return nullptr;
24 }
25 StyleValueVector& styleVector = ensurePropertyList(propertyID);
26 if (styleVector.isEmpty()) {
27 return nullptr;
28 }
29 return styleVector.at(0);
30 }
31
32 StyleValueVector InlineStylePropertyMap::getAll(CSSPropertyID propertyID)
33 {
34 ASSERT(propertyID != CSSPropertyInvalid);
35
36 updatePropertyIfNeeded(propertyID);
37
38 if (!m_styles.contains(propertyID))
39 return StyleValueVector();
40
41 return ensurePropertyList(propertyID);
42 }
43
44 bool InlineStylePropertyMap::has(CSSPropertyID propertyID)
45 {
46 ASSERT(propertyID != CSSPropertyInvalid);
47 return m_styles.contains(propertyID) && (!ensurePropertyList(propertyID).isE mpty());
48 }
49
50 Vector<String> InlineStylePropertyMap::getProperties()
51 {
52 Vector<String> result;
53 StylePropertySet& inlineStyleSet = m_ownerElement->ensureMutableInlineStyle( );
54 for (unsigned i = 0; i < inlineStyleSet.propertyCount(); i++) {
55 CSSPropertyID cssPropertyID = inlineStyleSet.propertyAt(i).id();
56 // TODO(meade): Consider whether this is necessary here.
57 updatePropertyIfNeeded(cssPropertyID);
58 result.append(getPropertyNameString(cssPropertyID));
59 }
60 return result;
61 }
62
63 void InlineStylePropertyMap::set(CSSPropertyID propertyID, StyleValueOrStyleValu eSequenceOrString& item, ExceptionState& exceptionState)
64 {
65 ASSERT(propertyID != CSSPropertyInvalid);
66 if (!item.isNull()) {
67 m_styles.remove(propertyID);
68 append(propertyID, item, exceptionState);
69 } else {
70 // Clear it.
71 remove(propertyID, exceptionState);
72 }
73 }
74
75 void InlineStylePropertyMap::append(CSSPropertyID propertyID, StyleValueOrStyleV alueSequenceOrString& item, ExceptionState& exceptionState)
76 {
77 ASSERT(propertyID != CSSPropertyInvalid);
78
79 StyleValueVector& values = ensurePropertyList(propertyID);
80 bool supportsMultiple = CSSOMTypes::propertySupportsMultiple(propertyID);
81
82 if (item.isStyleValue()) {
83 // Setting a single value.
84 StyleValue* value = item.getAsStyleValue();
85 if (!CSSOMTypes::propertyCanTake(propertyID, *value)) {
86 exceptionState.throwTypeError("Invalid type for property");
87 return;
88 }
89 if (!values.isEmpty() && !supportsMultiple) {
90 exceptionState.throwTypeError("Property does not support multiple va lues");
91 return;
92 }
93 values.append(value);
94
95 } else if (item.isStyleValueSequence()) {
96 if (!CSSOMTypes::propertySupportsMultiple(propertyID)) {
97 exceptionState.throwTypeError("Property does not support multiple va lues");
98 }
99 // Check all the values in the sequence to make sure they're valid.
100 const StyleValueVector specifiedValues = item.getAsStyleValueSequence();
101 for (const Member<StyleValue> value : specifiedValues) {
102 if (!CSSOMTypes::propertyCanTake(propertyID, *value)) {
103 exceptionState.throwTypeError("Invalid type for property");
104 return;
105 }
106 }
107 values.appendVector(specifiedValues);
108
109 } else if (item.isNull()) {
110 // No-op
111 return;
112 } else if (item.isString()) {
113 // Parse it.
114 // TODO(meade): Implement this.
115 exceptionState.throwTypeError("Not implemented yet");
116 return;
117 }
118
119 if (supportsMultiple) {
120 RefPtrWillBeRawPtr<CSSValueList> valueList = CSSValueList::createSpaceSe parated();
121 for (const Member<StyleValue> value : values) {
122 valueList->append(value->toCSSValue());
123 }
124 m_ownerElement->setInlineStyleProperty(propertyID, valueList);
125 } else {
126 m_ownerElement->setInlineStyleProperty(propertyID, values[0]->toCSSValue ());
127 }
128 m_cleanStyles.set(propertyID, true);
129 }
130
131 void InlineStylePropertyMap::remove(CSSPropertyID propertyID, ExceptionState& ex ceptionState)
132 {
133 ASSERT(propertyID != CSSPropertyInvalid);
134
135 const StyleVectorMap::iterator& iterator = m_styles.find(propertyID);
136 if (iterator == m_styles.end())
137 return;
138
139 m_styles.remove(iterator);
140 m_ownerElement->removeInlineStyleProperty(propertyID);
141 m_cleanStyles.set(propertyID, true);
142 }
143
144 void InlineStylePropertyMap::updatePropertyIfNeeded(CSSPropertyID propertyID)
145 {
146 if (m_cleanStyles.contains(propertyID) && m_cleanStyles.get(propertyID)) {
147 return;
148 }
149
150 RefPtrWillBeRawPtr<CSSValue> cssValue = m_ownerElement->ensureMutableInlineS tyle().getPropertyCSSValue(propertyID);
151 if (!cssValue) {
152 m_styles.remove(propertyID);
153 m_cleanStyles.set(propertyID, true);
154 return;
155 }
156
157 StyleValueVector& values = ensurePropertyList(propertyID);
158 values.clear();
159
160 if (!cssValue->isValueList()) {
161 StyleValue* styleValue = StyleValue::create(*cssValue);
162 if (styleValue) {
163 values.append(*styleValue);
164 }
165 }
166
167 if (values.isEmpty())
168 m_styles.remove(propertyID);
169
170 // TODO(meade) implement the other cases.
171
172 m_cleanStyles.set(propertyID, true);
173 }
174
175 void InlineStylePropertyMap::updateCustomProperty(const String& propertyName, Pa ssRefPtrWillBeRawPtr<CSSValue> cssValue)
176 {
177 // TODO(meade): Implement.
178 }
179
180 StyleValueVector& InlineStylePropertyMap::ensurePropertyList(CSSPropertyID prope rtyID)
181 {
182 if (!m_styles.contains(propertyID)) {
183 m_styles.set(propertyID, StyleValueVector());
184 }
185 // Note: If you write return m_style.get(propertyID) here, you get a copy.
186 return m_styles.find(propertyID)->value;
187 }
188
189 } // namespace blink
190
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698