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

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

Issue 1405293012: [Variables] Enable get/setProperty and similar APIs from the CSSOM (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix for realz Created 5 years, 1 month 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 /* 1 /*
2 * (C) 1999-2003 Lars Knoll (knoll@kde.org) 2 * (C) 1999-2003 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012, 2013 Apple Inc. All rights reserved. 3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012, 2013 Apple Inc. All rights reserved.
4 * Copyright (C) 2011 Research In Motion Limited. All rights reserved. 4 * Copyright (C) 2011 Research In Motion Limited. All rights reserved.
5 * Copyright (C) 2013 Intel Corporation. All rights reserved. 5 * Copyright (C) 2013 Intel Corporation. All rights reserved.
6 * 6 *
7 * This library is free software; you can redistribute it and/or 7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public 8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either 9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version. 10 * version 2 of the License, or (at your option) any later version.
11 * 11 *
12 * This library is distributed in the hope that it will be useful, 12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details. 15 * Library General Public License for more details.
16 * 16 *
17 * You should have received a copy of the GNU Library General Public License 17 * You should have received a copy of the GNU Library General Public License
18 * along with this library; see the file COPYING.LIB. If not, write to 18 * along with this library; see the file COPYING.LIB. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301, USA. 20 * Boston, MA 02110-1301, USA.
21 */ 21 */
22 22
23 #include "config.h" 23 #include "config.h"
24 #include "core/css/StylePropertySet.h" 24 #include "core/css/StylePropertySet.h"
25 25
26 #include "core/StylePropertyShorthand.h" 26 #include "core/StylePropertyShorthand.h"
27 #include "core/css/CSSCustomPropertyDeclaration.h"
27 #include "core/css/CSSPropertyMetadata.h" 28 #include "core/css/CSSPropertyMetadata.h"
28 #include "core/css/CSSValuePool.h" 29 #include "core/css/CSSValuePool.h"
29 #include "core/css/StylePropertySerializer.h" 30 #include "core/css/StylePropertySerializer.h"
30 #include "core/css/StyleSheetContents.h" 31 #include "core/css/StyleSheetContents.h"
31 #include "core/css/parser/CSSParser.h" 32 #include "core/css/parser/CSSParser.h"
32 #include "core/frame/UseCounter.h" 33 #include "core/frame/UseCounter.h"
33 #include "platform/RuntimeEnabledFeatures.h" 34 #include "platform/RuntimeEnabledFeatures.h"
34 #include "wtf/text/StringBuilder.h" 35 #include "wtf/text/StringBuilder.h"
35 36
36 #ifndef NDEBUG 37 #ifndef NDEBUG
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 #if !ENABLE(OILPAN) 97 #if !ENABLE(OILPAN)
97 RawPtrWillBeMember<CSSValue>* valueArray = const_cast<RawPtrWillBeMember<CSS Value>*>(this->valueArray()); 98 RawPtrWillBeMember<CSSValue>* valueArray = const_cast<RawPtrWillBeMember<CSS Value>*>(this->valueArray());
98 for (unsigned i = 0; i < m_arraySize; ++i) { 99 for (unsigned i = 0; i < m_arraySize; ++i) {
99 // Checking for nullptr here is a workaround to prevent crashing. http: //crbug.com/449032 100 // Checking for nullptr here is a workaround to prevent crashing. http: //crbug.com/449032
100 if (valueArray[i]) 101 if (valueArray[i])
101 valueArray[i]->deref(); 102 valueArray[i]->deref();
102 } 103 }
103 #endif 104 #endif
104 } 105 }
105 106
106 int ImmutableStylePropertySet::findPropertyIndex(CSSPropertyID propertyID) const 107 // Convert property into an uint16_t for comparison with metadata's m_propertyID to avoid
108 // the compiler converting it to an int multiple times in a loop.
109 static uint16_t getConvertedCSSPropertyID(CSSPropertyID propertyID)
107 { 110 {
108 // Convert here propertyID into an uint16_t to compare it with the metadata' s m_propertyID to avoid 111 return static_cast<uint16_t>(propertyID);
109 // the compiler converting it to an int multiple times in the loop. 112 }
110 uint16_t id = static_cast<uint16_t>(propertyID); 113
114 static uint16_t getConvertedCSSPropertyID(const AtomicString&)
115 {
116 return static_cast<uint16_t>(CSSPropertyVariable);
117 }
118
119 static bool isPropertyMatch(const StylePropertyMetadata& metadata, const CSSValu e&, uint16_t id, CSSPropertyID propertyID)
120 {
121 ASSERT(id == propertyID);
122 bool result = metadata.m_propertyID == id;
123 // Only enabled properties should be part of the style.
124 ASSERT(!result || CSSPropertyMetadata::isEnabledProperty(propertyID));
125 return result;
126 }
127
128 static bool isPropertyMatch(const StylePropertyMetadata& metadata, const CSSValu e& value, uint16_t id, const AtomicString& customPropertyName)
129 {
130 ASSERT(id == CSSPropertyVariable);
131 return metadata.m_propertyID == id
132 && toCSSCustomPropertyDeclaration(value).name() == customPropertyName;
133 }
134
135 template<typename T>
136 int ImmutableStylePropertySet::findPropertyIndex(T property) const
137 {
138 uint16_t id = getConvertedCSSPropertyID(property);
111 for (int n = m_arraySize - 1 ; n >= 0; --n) { 139 for (int n = m_arraySize - 1 ; n >= 0; --n) {
112 if (metadataArray()[n].m_propertyID == id) { 140 if (isPropertyMatch(metadataArray()[n], *valueArray()[n], id, property))
113 // Only enabled properties should be part of the style.
114 ASSERT(CSSPropertyMetadata::isEnabledProperty(propertyID));
115 return n; 141 return n;
116 }
117 } 142 }
118 143
119 return -1; 144 return -1;
120 } 145 }
146 template CORE_EXPORT int ImmutableStylePropertySet::findPropertyIndex(CSSPropert yID) const;
147 template CORE_EXPORT int ImmutableStylePropertySet::findPropertyIndex(AtomicStri ng) const;
121 148
122 DEFINE_TRACE_AFTER_DISPATCH(ImmutableStylePropertySet) 149 DEFINE_TRACE_AFTER_DISPATCH(ImmutableStylePropertySet)
123 { 150 {
124 const RawPtrWillBeMember<CSSValue>* values = valueArray(); 151 const RawPtrWillBeMember<CSSValue>* values = valueArray();
125 for (unsigned i = 0; i < m_arraySize; i++) 152 for (unsigned i = 0; i < m_arraySize; i++)
126 visitor->trace(values[i]); 153 visitor->trace(values[i]);
127 StylePropertySet::traceAfterDispatch(visitor); 154 StylePropertySet::traceAfterDispatch(visitor);
128 } 155 }
129 156
130 MutableStylePropertySet::MutableStylePropertySet(const StylePropertySet& other) 157 MutableStylePropertySet::MutableStylePropertySet(const StylePropertySet& other)
131 : StylePropertySet(other.cssParserMode()) 158 : StylePropertySet(other.cssParserMode())
132 { 159 {
133 if (other.isMutable()) { 160 if (other.isMutable()) {
134 m_propertyVector = toMutableStylePropertySet(other).m_propertyVector; 161 m_propertyVector = toMutableStylePropertySet(other).m_propertyVector;
135 } else { 162 } else {
136 m_propertyVector.reserveInitialCapacity(other.propertyCount()); 163 m_propertyVector.reserveInitialCapacity(other.propertyCount());
137 for (unsigned i = 0; i < other.propertyCount(); ++i) 164 for (unsigned i = 0; i < other.propertyCount(); ++i)
138 m_propertyVector.uncheckedAppend(other.propertyAt(i).toCSSProperty() ); 165 m_propertyVector.uncheckedAppend(other.propertyAt(i).toCSSProperty() );
139 } 166 }
140 } 167 }
141 168
142 String StylePropertySet::getPropertyValue(CSSPropertyID propertyID) const 169 static String serializeShorthand(const StylePropertySet& propertySet, CSSPropert yID propertyID)
143 { 170 {
144 RefPtrWillBeRawPtr<CSSValue> value = getPropertyCSSValue(propertyID); 171 return StylePropertySerializer(propertySet).getPropertyValue(propertyID);
172 }
173
174 static String serializeShorthand(const StylePropertySet&, const AtomicString& cu stomPropertyName)
175 {
176 // Custom properties are never shorthands.
177 return "";
178 }
179
180 template<typename T>
181 String StylePropertySet::getPropertyValue(T property) const
182 {
183 RefPtrWillBeRawPtr<CSSValue> value = getPropertyCSSValue(property);
145 if (value) 184 if (value)
146 return value->cssText(); 185 return value->cssText();
186 return serializeShorthand(*this, property);
187 }
188 template CORE_EXPORT String StylePropertySet::getPropertyValue<CSSPropertyID>(CS SPropertyID) const;
189 template CORE_EXPORT String StylePropertySet::getPropertyValue<AtomicString>(Ato micString) const;
147 190
148 return StylePropertySerializer(*this).getPropertyValue(propertyID); 191 template<typename T>
149 } 192 PassRefPtrWillBeRawPtr<CSSValue> StylePropertySet::getPropertyCSSValue(T propert y) const
150
151 PassRefPtrWillBeRawPtr<CSSValue> StylePropertySet::getPropertyCSSValue(CSSProper tyID propertyID) const
152 { 193 {
153 int foundPropertyIndex = findPropertyIndex(propertyID); 194 int foundPropertyIndex = findPropertyIndex(property);
154 if (foundPropertyIndex == -1) 195 if (foundPropertyIndex == -1)
155 return nullptr; 196 return nullptr;
156 return propertyAt(foundPropertyIndex).value(); 197 return propertyAt(foundPropertyIndex).value();
157 } 198 }
199 template CORE_EXPORT PassRefPtrWillBeRawPtr<CSSValue> StylePropertySet::getPrope rtyCSSValue<CSSPropertyID>(CSSPropertyID) const;
200 template CORE_EXPORT PassRefPtrWillBeRawPtr<CSSValue> StylePropertySet::getPrope rtyCSSValue<AtomicString>(AtomicString) const;
alancutter (OOO until 2018) 2015/11/23 05:23:59 Which build configuration requires CORE_EXPORT?
158 201
159 DEFINE_TRACE(StylePropertySet) 202 DEFINE_TRACE(StylePropertySet)
160 { 203 {
161 if (m_isMutable) 204 if (m_isMutable)
162 toMutableStylePropertySet(this)->traceAfterDispatch(visitor); 205 toMutableStylePropertySet(this)->traceAfterDispatch(visitor);
163 else 206 else
164 toImmutableStylePropertySet(this)->traceAfterDispatch(visitor); 207 toImmutableStylePropertySet(this)->traceAfterDispatch(visitor);
165 } 208 }
166 209
167 #if ENABLE(OILPAN) 210 #if ENABLE(OILPAN)
168 void StylePropertySet::finalizeGarbageCollectedObject() 211 void StylePropertySet::finalizeGarbageCollectedObject()
169 { 212 {
170 if (m_isMutable) 213 if (m_isMutable)
171 toMutableStylePropertySet(this)->~MutableStylePropertySet(); 214 toMutableStylePropertySet(this)->~MutableStylePropertySet();
172 else 215 else
173 toImmutableStylePropertySet(this)->~ImmutableStylePropertySet(); 216 toImmutableStylePropertySet(this)->~ImmutableStylePropertySet();
174 } 217 }
175 #endif 218 #endif
176 219
177 bool MutableStylePropertySet::removeShorthandProperty(CSSPropertyID propertyID) 220 bool MutableStylePropertySet::removeShorthandProperty(CSSPropertyID propertyID)
178 { 221 {
179 StylePropertyShorthand shorthand = shorthandForProperty(propertyID); 222 StylePropertyShorthand shorthand = shorthandForProperty(propertyID);
180 if (!shorthand.length()) 223 if (!shorthand.length())
181 return false; 224 return false;
182 225
183 return removePropertiesInSet(shorthand.properties(), shorthand.length()); 226 return removePropertiesInSet(shorthand.properties(), shorthand.length());
184 } 227 }
185 228
186 bool MutableStylePropertySet::removeProperty(CSSPropertyID propertyID, String* r eturnText) 229 bool MutableStylePropertySet::removePropertyAtIndex(int propertyIndex, String* r eturnText)
187 { 230 {
188 if (removeShorthandProperty(propertyID)) { 231 if (propertyIndex == -1) {
232 if (returnText)
233 *returnText = "";
234 return false;
235 }
236
237 if (returnText)
238 *returnText = propertyAt(propertyIndex).value()->cssText();
239
240 // A more efficient removal strategy would involve marking entries as empty
241 // and sweeping them when the vector grows too big.
242 m_propertyVector.remove(propertyIndex);
243
244 return true;
245 }
246
247 template<typename T>
248 bool MutableStylePropertySet::removeProperty(T property, String* returnText)
249 {
250 if (removeShorthandProperty(property)) {
189 // FIXME: Return an equivalent shorthand when possible. 251 // FIXME: Return an equivalent shorthand when possible.
190 if (returnText) 252 if (returnText)
191 *returnText = ""; 253 *returnText = "";
192 return true; 254 return true;
193 } 255 }
194 256
195 int foundPropertyIndex = findPropertyIndex(propertyID); 257 int foundPropertyIndex = findPropertyIndex(property);
196 if (foundPropertyIndex == -1) { 258 return removePropertyAtIndex(foundPropertyIndex, returnText);
197 if (returnText) 259 }
198 *returnText = ""; 260 template CORE_EXPORT bool MutableStylePropertySet::removeProperty(CSSPropertyID, String*);
199 return false; 261 template CORE_EXPORT bool MutableStylePropertySet::removeProperty(AtomicString, String*);
200 }
201 262
202 if (returnText) 263 template<typename T>
203 *returnText = propertyAt(foundPropertyIndex).value()->cssText(); 264 bool StylePropertySet::propertyIsImportant(T property) const
204
205 // A more efficient removal strategy would involve marking entries as empty
206 // and sweeping them when the vector grows too big.
207 m_propertyVector.remove(foundPropertyIndex);
208
209 return true;
210 }
211
212 bool StylePropertySet::propertyIsImportant(CSSPropertyID propertyID) const
213 { 265 {
214 int foundPropertyIndex = findPropertyIndex(propertyID); 266 int foundPropertyIndex = findPropertyIndex(property);
215 if (foundPropertyIndex != -1) 267 if (foundPropertyIndex != -1)
216 return propertyAt(foundPropertyIndex).isImportant(); 268 return propertyAt(foundPropertyIndex).isImportant();
269 return shorthandIsImportant(property);
270 }
271 template bool StylePropertySet::propertyIsImportant<CSSPropertyID>(CSSPropertyID ) const;
272 template bool StylePropertySet::propertyIsImportant<AtomicString>(AtomicString) const;
217 273
274 bool StylePropertySet::shorthandIsImportant(CSSPropertyID propertyID) const
275 {
218 StylePropertyShorthand shorthand = shorthandForProperty(propertyID); 276 StylePropertyShorthand shorthand = shorthandForProperty(propertyID);
219 if (!shorthand.length()) 277 if (!shorthand.length())
220 return false; 278 return false;
221 279
222 for (unsigned i = 0; i < shorthand.length(); ++i) { 280 for (unsigned i = 0; i < shorthand.length(); ++i) {
223 if (!propertyIsImportant(shorthand.properties()[i])) 281 if (!propertyIsImportant(shorthand.properties()[i]))
224 return false; 282 return false;
225 } 283 }
226 return true; 284 return true;
227 } 285 }
228 286
287 bool StylePropertySet::shorthandIsImportant(AtomicString customPropertyName) con st
288 {
289 // Custom properties are never shorthands.
290 return false;
291 }
292
229 CSSPropertyID StylePropertySet::getPropertyShorthand(CSSPropertyID propertyID) c onst 293 CSSPropertyID StylePropertySet::getPropertyShorthand(CSSPropertyID propertyID) c onst
230 { 294 {
231 int foundPropertyIndex = findPropertyIndex(propertyID); 295 int foundPropertyIndex = findPropertyIndex(propertyID);
232 if (foundPropertyIndex == -1) 296 if (foundPropertyIndex == -1)
233 return CSSPropertyInvalid; 297 return CSSPropertyInvalid;
234 return propertyAt(foundPropertyIndex).shorthandID(); 298 return propertyAt(foundPropertyIndex).shorthandID();
235 } 299 }
236 300
237 bool StylePropertySet::isPropertyImplicit(CSSPropertyID propertyID) const 301 bool StylePropertySet::isPropertyImplicit(CSSPropertyID propertyID) const
238 { 302 {
239 int foundPropertyIndex = findPropertyIndex(propertyID); 303 int foundPropertyIndex = findPropertyIndex(propertyID);
240 if (foundPropertyIndex == -1) 304 if (foundPropertyIndex == -1)
241 return false; 305 return false;
242 return propertyAt(foundPropertyIndex).isImplicit(); 306 return propertyAt(foundPropertyIndex).isImplicit();
243 } 307 }
244 308
245 bool MutableStylePropertySet::setProperty(CSSPropertyID unresolvedProperty, cons t String& value, bool important, StyleSheetContents* contextStyleSheet) 309 bool MutableStylePropertySet::setProperty(CSSPropertyID unresolvedProperty, cons t String& value, bool important, StyleSheetContents* contextStyleSheet)
246 { 310 {
247 // Setting the value to an empty string just removes the property in both IE and Gecko. 311 // Setting the value to an empty string just removes the property in both IE and Gecko.
248 // Setting it to null seems to produce less consistent results, but we treat it just the same. 312 // Setting it to null seems to produce less consistent results, but we treat it just the same.
249 if (value.isEmpty()) 313 if (value.isEmpty())
250 return removeProperty(resolveCSSPropertyID(unresolvedProperty)); 314 return removeProperty(resolveCSSPropertyID(unresolvedProperty));
251 315
252 // When replacing an existing property value, this moves the property to the end of the list. 316 // When replacing an existing property value, this moves the property to the end of the list.
253 // Firefox preserves the position, and MSIE moves the property to the beginn ing. 317 // Firefox preserves the position, and MSIE moves the property to the beginn ing.
254 return CSSParser::parseValue(this, unresolvedProperty, value, important, con textStyleSheet); 318 return CSSParser::parseValue(this, unresolvedProperty, value, important, con textStyleSheet);
255 } 319 }
256 320
321 bool MutableStylePropertySet::setProperty(const AtomicString& customPropertyName , const String& value, bool important, StyleSheetContents* contextStyleSheet)
322 {
323 if (value.isEmpty())
324 return removeProperty(customPropertyName);
325 return CSSParser::parseValueForCustomProperty(this, customPropertyName, valu e, important, contextStyleSheet);
326 }
327
257 void MutableStylePropertySet::setProperty(CSSPropertyID propertyID, PassRefPtrWi llBeRawPtr<CSSValue> prpValue, bool important) 328 void MutableStylePropertySet::setProperty(CSSPropertyID propertyID, PassRefPtrWi llBeRawPtr<CSSValue> prpValue, bool important)
258 { 329 {
259 StylePropertyShorthand shorthand = shorthandForProperty(propertyID); 330 StylePropertyShorthand shorthand = shorthandForProperty(propertyID);
260 if (!shorthand.length()) { 331 if (!shorthand.length()) {
261 setProperty(CSSProperty(propertyID, prpValue, important)); 332 setProperty(CSSProperty(propertyID, prpValue, important));
262 return; 333 return;
263 } 334 }
264 335
265 removePropertiesInSet(shorthand.properties(), shorthand.length()); 336 removePropertiesInSet(shorthand.properties(), shorthand.length());
266 337
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 String StylePropertySet::asText() const 394 String StylePropertySet::asText() const
324 { 395 {
325 return StylePropertySerializer(*this).asText(); 396 return StylePropertySerializer(*this).asText();
326 } 397 }
327 398
328 void MutableStylePropertySet::mergeAndOverrideOnConflict(const StylePropertySet* other) 399 void MutableStylePropertySet::mergeAndOverrideOnConflict(const StylePropertySet* other)
329 { 400 {
330 unsigned size = other->propertyCount(); 401 unsigned size = other->propertyCount();
331 for (unsigned n = 0; n < size; ++n) { 402 for (unsigned n = 0; n < size; ++n) {
332 PropertyReference toMerge = other->propertyAt(n); 403 PropertyReference toMerge = other->propertyAt(n);
404 // TODO(leviw): This probably doesn't work correctly with Custom Propert ies
333 CSSProperty* old = findCSSPropertyWithID(toMerge.id()); 405 CSSProperty* old = findCSSPropertyWithID(toMerge.id());
334 if (old) 406 if (old)
335 setProperty(toMerge.toCSSProperty(), old); 407 setProperty(toMerge.toCSSProperty(), old);
336 else 408 else
337 m_propertyVector.append(toMerge.toCSSProperty()); 409 m_propertyVector.append(toMerge.toCSSProperty());
338 } 410 }
339 } 411 }
340 412
341 bool StylePropertySet::hasFailedOrCanceledSubresources() const 413 bool StylePropertySet::hasFailedOrCanceledSubresources() const
342 { 414 {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 } 451 }
380 if (newIndex != oldSize) { 452 if (newIndex != oldSize) {
381 m_propertyVector.shrink(newIndex); 453 m_propertyVector.shrink(newIndex);
382 return true; 454 return true;
383 } 455 }
384 return false; 456 return false;
385 } 457 }
386 458
387 CSSProperty* MutableStylePropertySet::findCSSPropertyWithID(CSSPropertyID proper tyID) 459 CSSProperty* MutableStylePropertySet::findCSSPropertyWithID(CSSPropertyID proper tyID)
388 { 460 {
461 // TODO(leviw): Calling this with a custom property should probably assert, or this
462 // method should alternatively take a string used for custom properties and check it
463 // in that case.
464 if (propertyID == CSSPropertyVariable)
465 return nullptr;
466
389 int foundPropertyIndex = findPropertyIndex(propertyID); 467 int foundPropertyIndex = findPropertyIndex(propertyID);
390 if (foundPropertyIndex == -1) 468 if (foundPropertyIndex == -1)
391 return nullptr; 469 return nullptr;
392 return &m_propertyVector.at(foundPropertyIndex); 470 return &m_propertyVector.at(foundPropertyIndex);
393 } 471 }
394 472
395 bool StylePropertySet::propertyMatches(CSSPropertyID propertyID, const CSSValue* propertyValue) const 473 bool StylePropertySet::propertyMatches(CSSPropertyID propertyID, const CSSValue* propertyValue) const
396 { 474 {
397 int foundPropertyIndex = findPropertyIndex(propertyID); 475 int foundPropertyIndex = findPropertyIndex(propertyID);
398 if (foundPropertyIndex == -1) 476 if (foundPropertyIndex == -1)
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 // style property set. 529 // style property set.
452 if (m_cssomWrapper) { 530 if (m_cssomWrapper) {
453 ASSERT(!static_cast<CSSStyleDeclaration*>(m_cssomWrapper.get())->parentR ule()); 531 ASSERT(!static_cast<CSSStyleDeclaration*>(m_cssomWrapper.get())->parentR ule());
454 ASSERT(!m_cssomWrapper->parentElement()); 532 ASSERT(!m_cssomWrapper->parentElement());
455 return m_cssomWrapper.get(); 533 return m_cssomWrapper.get();
456 } 534 }
457 m_cssomWrapper = adoptPtrWillBeNoop(new PropertySetCSSStyleDeclaration(*this )); 535 m_cssomWrapper = adoptPtrWillBeNoop(new PropertySetCSSStyleDeclaration(*this ));
458 return m_cssomWrapper.get(); 536 return m_cssomWrapper.get();
459 } 537 }
460 538
461 int MutableStylePropertySet::findPropertyIndex(CSSPropertyID propertyID) const 539 template<typename T>
540 int MutableStylePropertySet::findPropertyIndex(T property) const
462 { 541 {
463 const CSSProperty* begin = m_propertyVector.data(); 542 const CSSProperty* begin = m_propertyVector.data();
464 const CSSProperty* end = begin + m_propertyVector.size(); 543 const CSSProperty* end = begin + m_propertyVector.size();
465 // Convert here propertyID into an uint16_t to compare it with the metadata' s m_propertyID to avoid
466 // the compiler converting it to an int multiple times in the loop.
467 uint16_t id = static_cast<uint16_t>(propertyID);
468 544
469 auto compare = [propertyID, id](const CSSProperty& property) -> bool { 545 uint16_t id = getConvertedCSSPropertyID(property);
470 if (property.metadata().m_propertyID == id) {
471 // Only enabled properties should be part of the style.
472 ASSERT(CSSPropertyMetadata::isEnabledProperty(propertyID));
473 return true;
474 }
475 return false;
476 };
477 546
478 const CSSProperty* it = std::find_if(begin, end, compare); 547 const CSSProperty* it = std::find_if(begin, end, [property, id](const CSSPro perty& cssProperty) -> bool {
548 return isPropertyMatch(cssProperty.metadata(), *cssProperty.value(), id, property);
549 });
479 550
480 return (it == end) ? -1 : it - begin; 551 return (it == end) ? -1 : it - begin;
481 } 552 }
553 template CORE_EXPORT int MutableStylePropertySet::findPropertyIndex(CSSPropertyI D) const;
554 template CORE_EXPORT int MutableStylePropertySet::findPropertyIndex(AtomicString ) const;
482 555
483 DEFINE_TRACE_AFTER_DISPATCH(MutableStylePropertySet) 556 DEFINE_TRACE_AFTER_DISPATCH(MutableStylePropertySet)
484 { 557 {
485 #if ENABLE(OILPAN) 558 #if ENABLE(OILPAN)
486 visitor->trace(m_cssomWrapper); 559 visitor->trace(m_cssomWrapper);
487 visitor->trace(m_propertyVector); 560 visitor->trace(m_propertyVector);
488 #endif 561 #endif
489 StylePropertySet::traceAfterDispatch(visitor); 562 StylePropertySet::traceAfterDispatch(visitor);
490 } 563 }
491 564
(...skipping 20 matching lines...) Expand all
512 { 585 {
513 return adoptRefWillBeNoop(new MutableStylePropertySet(cssParserMode)); 586 return adoptRefWillBeNoop(new MutableStylePropertySet(cssParserMode));
514 } 587 }
515 588
516 PassRefPtrWillBeRawPtr<MutableStylePropertySet> MutableStylePropertySet::create( const CSSProperty* properties, unsigned count) 589 PassRefPtrWillBeRawPtr<MutableStylePropertySet> MutableStylePropertySet::create( const CSSProperty* properties, unsigned count)
517 { 590 {
518 return adoptRefWillBeNoop(new MutableStylePropertySet(properties, count)); 591 return adoptRefWillBeNoop(new MutableStylePropertySet(properties, count));
519 } 592 }
520 593
521 } // namespace blink 594 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698