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

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

Issue 1164573002: CSSValue Immediates: Change CSSValue to an object instead of a pointer (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebase Created 5 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 unified diff | Download patch
« no previous file with comments | « Source/core/css/StylePropertySet.h ('k') | Source/core/css/parser/CSSParser.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 { 74 {
75 m_propertyVector.reserveInitialCapacity(length); 75 m_propertyVector.reserveInitialCapacity(length);
76 for (unsigned i = 0; i < length; ++i) 76 for (unsigned i = 0; i < length; ++i)
77 m_propertyVector.uncheckedAppend(properties[i]); 77 m_propertyVector.uncheckedAppend(properties[i]);
78 } 78 }
79 79
80 ImmutableStylePropertySet::ImmutableStylePropertySet(const CSSProperty* properti es, unsigned length, CSSParserMode cssParserMode) 80 ImmutableStylePropertySet::ImmutableStylePropertySet(const CSSProperty* properti es, unsigned length, CSSParserMode cssParserMode)
81 : StylePropertySet(cssParserMode, length) 81 : StylePropertySet(cssParserMode, length)
82 { 82 {
83 StylePropertyMetadata* metadataArray = const_cast<StylePropertyMetadata*>(th is->metadataArray()); 83 StylePropertyMetadata* metadataArray = const_cast<StylePropertyMetadata*>(th is->metadataArray());
84 RawPtrWillBeMember<CSSValue>* valueArray = const_cast<RawPtrWillBeMember<CSS Value>*>(this->valueArray()); 84 CSSValue* valueArray = const_cast<CSSValue*>(this->valueArray());
85 for (unsigned i = 0; i < m_arraySize; ++i) { 85 for (unsigned i = 0; i < m_arraySize; ++i) {
86 metadataArray[i] = properties[i].metadata(); 86 metadataArray[i] = properties[i].metadata();
87 valueArray[i] = properties[i].value(); 87 // Can't use operator= here since valueArray[i] is an invalid CSSValue.
88 #if !ENABLE(OILPAN) 88 new(&valueArray[i]) CSSValue(properties[i].value());
89 valueArray[i]->ref();
90 #endif
91 } 89 }
92 } 90 }
93 91
94 ImmutableStylePropertySet::~ImmutableStylePropertySet() 92 ImmutableStylePropertySet::~ImmutableStylePropertySet()
95 { 93 {
96 #if !ENABLE(OILPAN) 94 #if !ENABLE(OILPAN)
97 RawPtrWillBeMember<CSSValue>* valueArray = const_cast<RawPtrWillBeMember<CSS Value>*>(this->valueArray()); 95 CSSValue* valueArray = const_cast<CSSValue*>(this->valueArray());
98 for (unsigned i = 0; i < m_arraySize; ++i) { 96 for (unsigned i = 0; i < m_arraySize; ++i) {
99 // Checking for nullptr here is a workaround to prevent crashing. http: //crbug.com/449032 97 valueArray[i].~CSSValue();
100 if (valueArray[i])
101 valueArray[i]->deref();
102 } 98 }
103 #endif 99 #endif
104 } 100 }
105 101
106 int ImmutableStylePropertySet::findPropertyIndex(CSSPropertyID propertyID) const 102 int ImmutableStylePropertySet::findPropertyIndex(CSSPropertyID propertyID) const
107 { 103 {
108 // Convert here propertyID into an uint16_t to compare it with the metadata' s m_propertyID to avoid 104 // Convert here propertyID into an uint16_t to compare it with the metadata' s m_propertyID to avoid
109 // the compiler converting it to an int multiple times in the loop. 105 // the compiler converting it to an int multiple times in the loop.
110 uint16_t id = static_cast<uint16_t>(propertyID); 106 uint16_t id = static_cast<uint16_t>(propertyID);
111 for (int n = m_arraySize - 1 ; n >= 0; --n) { 107 for (int n = m_arraySize - 1 ; n >= 0; --n) {
112 if (metadataArray()[n].m_propertyID == id) { 108 if (metadataArray()[n].m_propertyID == id) {
113 // Only enabled properties should be part of the style. 109 // Only enabled properties should be part of the style.
114 ASSERT(CSSPropertyMetadata::isEnabledProperty(propertyID)); 110 ASSERT(CSSPropertyMetadata::isEnabledProperty(propertyID));
115 return n; 111 return n;
116 } 112 }
117 } 113 }
118 114
119 return -1; 115 return -1;
120 } 116 }
121 117
122 DEFINE_TRACE_AFTER_DISPATCH(ImmutableStylePropertySet) 118 DEFINE_TRACE_AFTER_DISPATCH(ImmutableStylePropertySet)
123 { 119 {
124 const RawPtrWillBeMember<CSSValue>* values = valueArray(); 120 const CSSValue* values = valueArray();
125 for (unsigned i = 0; i < m_arraySize; i++) 121 for (unsigned i = 0; i < m_arraySize; i++)
126 visitor->trace(values[i]); 122 visitor->trace(values[i]);
127 StylePropertySet::traceAfterDispatch(visitor); 123 StylePropertySet::traceAfterDispatch(visitor);
128 } 124 }
129 125
130 MutableStylePropertySet::MutableStylePropertySet(const StylePropertySet& other) 126 MutableStylePropertySet::MutableStylePropertySet(const StylePropertySet& other)
131 : StylePropertySet(other.cssParserMode()) 127 : StylePropertySet(other.cssParserMode())
132 { 128 {
133 if (other.isMutable()) { 129 if (other.isMutable()) {
134 m_propertyVector = toMutableStylePropertySet(other).m_propertyVector; 130 m_propertyVector = toMutableStylePropertySet(other).m_propertyVector;
135 } else { 131 } else {
136 m_propertyVector.reserveInitialCapacity(other.propertyCount()); 132 m_propertyVector.reserveInitialCapacity(other.propertyCount());
137 for (unsigned i = 0; i < other.propertyCount(); ++i) 133 for (unsigned i = 0; i < other.propertyCount(); ++i)
138 m_propertyVector.uncheckedAppend(other.propertyAt(i).toCSSProperty() ); 134 m_propertyVector.uncheckedAppend(other.propertyAt(i).toCSSProperty() );
139 } 135 }
140 } 136 }
141 137
142 String StylePropertySet::getPropertyValue(CSSPropertyID propertyID) const 138 String StylePropertySet::getPropertyValue(CSSPropertyID propertyID) const
143 { 139 {
144 RefPtrWillBeRawPtr<CSSValue> value = getPropertyCSSValue(propertyID); 140 NullableCSSValue value = getPropertyCSSValue(propertyID);
145 if (value) 141 if (value)
146 return value->cssText(); 142 return value->cssText();
147 143
148 return StylePropertySerializer(*this).getPropertyValue(propertyID); 144 return StylePropertySerializer(*this).getPropertyValue(propertyID);
149 } 145 }
150 146
151 PassRefPtrWillBeRawPtr<CSSValue> StylePropertySet::getPropertyCSSValue(CSSProper tyID propertyID) const 147 NullableCSSValue StylePropertySet::getPropertyCSSValue(CSSPropertyID propertyID) const
152 { 148 {
153 int foundPropertyIndex = findPropertyIndex(propertyID); 149 int foundPropertyIndex = findPropertyIndex(propertyID);
154 if (foundPropertyIndex == -1) 150 if (foundPropertyIndex == -1)
155 return nullptr; 151 return nullptr;
156 return propertyAt(foundPropertyIndex).value(); 152 return propertyAt(foundPropertyIndex).value();
157 } 153 }
158 154
159 DEFINE_TRACE(StylePropertySet) 155 DEFINE_TRACE(StylePropertySet)
160 { 156 {
161 if (m_isMutable) 157 if (m_isMutable)
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 } 189 }
194 190
195 int foundPropertyIndex = findPropertyIndex(propertyID); 191 int foundPropertyIndex = findPropertyIndex(propertyID);
196 if (foundPropertyIndex == -1) { 192 if (foundPropertyIndex == -1) {
197 if (returnText) 193 if (returnText)
198 *returnText = ""; 194 *returnText = "";
199 return false; 195 return false;
200 } 196 }
201 197
202 if (returnText) 198 if (returnText)
203 *returnText = propertyAt(foundPropertyIndex).value()->cssText(); 199 *returnText = propertyAt(foundPropertyIndex).value().cssText();
204 200
205 // A more efficient removal strategy would involve marking entries as empty 201 // A more efficient removal strategy would involve marking entries as empty
206 // and sweeping them when the vector grows too big. 202 // and sweeping them when the vector grows too big.
207 m_propertyVector.remove(foundPropertyIndex); 203 m_propertyVector.remove(foundPropertyIndex);
208 204
209 return true; 205 return true;
210 } 206 }
211 207
212 bool StylePropertySet::propertyIsImportant(CSSPropertyID propertyID) const 208 bool StylePropertySet::propertyIsImportant(CSSPropertyID propertyID) const
213 { 209 {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 // Setting the value to an empty string just removes the property in both IE and Gecko. 243 // 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. 244 // Setting it to null seems to produce less consistent results, but we treat it just the same.
249 if (value.isEmpty()) 245 if (value.isEmpty())
250 return removeProperty(resolveCSSPropertyID(unresolvedProperty)); 246 return removeProperty(resolveCSSPropertyID(unresolvedProperty));
251 247
252 // When replacing an existing property value, this moves the property to the end of the list. 248 // 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. 249 // Firefox preserves the position, and MSIE moves the property to the beginn ing.
254 return CSSParser::parseValue(this, unresolvedProperty, value, important, css ParserMode(), contextStyleSheet); 250 return CSSParser::parseValue(this, unresolvedProperty, value, important, css ParserMode(), contextStyleSheet);
255 } 251 }
256 252
257 void MutableStylePropertySet::setProperty(CSSPropertyID propertyID, PassRefPtrWi llBeRawPtr<CSSValue> prpValue, bool important) 253 void MutableStylePropertySet::setProperty(CSSPropertyID propertyID, CSSValue prp Value, bool important)
258 { 254 {
259 StylePropertyShorthand shorthand = shorthandForProperty(propertyID); 255 StylePropertyShorthand shorthand = shorthandForProperty(propertyID);
260 if (!shorthand.length()) { 256 if (!shorthand.length()) {
261 setProperty(CSSProperty(propertyID, prpValue, important)); 257 setProperty(CSSProperty(propertyID, prpValue, important));
262 return; 258 return;
263 } 259 }
264 260
265 removePropertiesInSet(shorthand.properties(), shorthand.length()); 261 removePropertiesInSet(shorthand.properties(), shorthand.length());
266 262
267 RefPtrWillBeRawPtr<CSSValue> value = prpValue; 263 CSSValue value = prpValue;
268 for (unsigned i = 0; i < shorthand.length(); ++i) 264 for (unsigned i = 0; i < shorthand.length(); ++i)
269 m_propertyVector.append(CSSProperty(shorthand.properties()[i], value, im portant)); 265 m_propertyVector.append(CSSProperty(shorthand.properties()[i], value, im portant));
270 } 266 }
271 267
272 bool MutableStylePropertySet::setProperty(const CSSProperty& property, CSSProper ty* slot) 268 bool MutableStylePropertySet::setProperty(const CSSProperty& property, CSSProper ty* slot)
273 { 269 {
274 if (!removeShorthandProperty(property.id())) { 270 if (!removeShorthandProperty(property.id())) {
275 CSSProperty* toReplace = slot ? slot : findCSSPropertyWithID(property.id ()); 271 CSSProperty* toReplace = slot ? slot : findCSSPropertyWithID(property.id ());
276 if (toReplace && *toReplace == property) 272 if (toReplace && *toReplace == property)
277 return false; 273 return false;
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 setProperty(toMerge.toCSSProperty(), old); 331 setProperty(toMerge.toCSSProperty(), old);
336 else 332 else
337 m_propertyVector.append(toMerge.toCSSProperty()); 333 m_propertyVector.append(toMerge.toCSSProperty());
338 } 334 }
339 } 335 }
340 336
341 bool StylePropertySet::hasFailedOrCanceledSubresources() const 337 bool StylePropertySet::hasFailedOrCanceledSubresources() const
342 { 338 {
343 unsigned size = propertyCount(); 339 unsigned size = propertyCount();
344 for (unsigned i = 0; i < size; ++i) { 340 for (unsigned i = 0; i < size; ++i) {
345 if (propertyAt(i).value()->hasFailedOrCanceledSubresources()) 341 if (propertyAt(i).value().hasFailedOrCanceledSubresources())
346 return true; 342 return true;
347 } 343 }
348 return false; 344 return false;
349 } 345 }
350 346
351 void MutableStylePropertySet::clear() 347 void MutableStylePropertySet::clear()
352 { 348 {
353 m_propertyVector.clear(); 349 m_propertyVector.clear();
354 } 350 }
355 351
(...skipping 29 matching lines...) Expand all
385 } 381 }
386 382
387 CSSProperty* MutableStylePropertySet::findCSSPropertyWithID(CSSPropertyID proper tyID) 383 CSSProperty* MutableStylePropertySet::findCSSPropertyWithID(CSSPropertyID proper tyID)
388 { 384 {
389 int foundPropertyIndex = findPropertyIndex(propertyID); 385 int foundPropertyIndex = findPropertyIndex(propertyID);
390 if (foundPropertyIndex == -1) 386 if (foundPropertyIndex == -1)
391 return 0; 387 return 0;
392 return &m_propertyVector.at(foundPropertyIndex); 388 return &m_propertyVector.at(foundPropertyIndex);
393 } 389 }
394 390
395 bool StylePropertySet::propertyMatches(CSSPropertyID propertyID, const CSSValue* propertyValue) const 391 bool StylePropertySet::propertyMatches(CSSPropertyID propertyID, const CSSValue propertyValue) const
396 { 392 {
397 int foundPropertyIndex = findPropertyIndex(propertyID); 393 int foundPropertyIndex = findPropertyIndex(propertyID);
398 if (foundPropertyIndex == -1) 394 if (foundPropertyIndex == -1)
399 return false; 395 return false;
400 return propertyAt(foundPropertyIndex).value()->equals(*propertyValue); 396 return propertyAt(foundPropertyIndex).value().equals(propertyValue);
401 } 397 }
402 398
403 void MutableStylePropertySet::removeEquivalentProperties(const StylePropertySet* style) 399 void MutableStylePropertySet::removeEquivalentProperties(const StylePropertySet* style)
404 { 400 {
405 Vector<CSSPropertyID> propertiesToRemove; 401 Vector<CSSPropertyID> propertiesToRemove;
406 unsigned size = m_propertyVector.size(); 402 unsigned size = m_propertyVector.size();
407 for (unsigned i = 0; i < size; ++i) { 403 for (unsigned i = 0; i < size; ++i) {
408 PropertyReference property = propertyAt(i); 404 PropertyReference property = propertyAt(i);
409 if (style->propertyMatches(property.id(), property.value())) 405 if (style->propertyMatches(property.id(), property.value()))
410 propertiesToRemove.append(property.id()); 406 propertiesToRemove.append(property.id());
(...skipping 20 matching lines...) Expand all
431 PassRefPtrWillBeRawPtr<MutableStylePropertySet> StylePropertySet::mutableCopy() const 427 PassRefPtrWillBeRawPtr<MutableStylePropertySet> StylePropertySet::mutableCopy() const
432 { 428 {
433 return adoptRefWillBeNoop(new MutableStylePropertySet(*this)); 429 return adoptRefWillBeNoop(new MutableStylePropertySet(*this));
434 } 430 }
435 431
436 PassRefPtrWillBeRawPtr<MutableStylePropertySet> StylePropertySet::copyProperties InSet(const Vector<CSSPropertyID>& properties) const 432 PassRefPtrWillBeRawPtr<MutableStylePropertySet> StylePropertySet::copyProperties InSet(const Vector<CSSPropertyID>& properties) const
437 { 433 {
438 WillBeHeapVector<CSSProperty, 256> list; 434 WillBeHeapVector<CSSProperty, 256> list;
439 list.reserveInitialCapacity(properties.size()); 435 list.reserveInitialCapacity(properties.size());
440 for (unsigned i = 0; i < properties.size(); ++i) { 436 for (unsigned i = 0; i < properties.size(); ++i) {
441 RefPtrWillBeRawPtr<CSSValue> value = getPropertyCSSValue(properties[i]); 437 NullableCSSValue value = getPropertyCSSValue(properties[i]);
442 if (value) 438 if (value)
443 list.append(CSSProperty(properties[i], value.release(), false)); 439 list.append(CSSProperty(properties[i], *value, false));
444 } 440 }
445 return MutableStylePropertySet::create(list.data(), list.size()); 441 return MutableStylePropertySet::create(list.data(), list.size());
446 } 442 }
447 443
448 CSSStyleDeclaration* MutableStylePropertySet::ensureCSSStyleDeclaration() 444 CSSStyleDeclaration* MutableStylePropertySet::ensureCSSStyleDeclaration()
449 { 445 {
450 // FIXME: get rid of this weirdness of a CSSStyleDeclaration inside of a 446 // FIXME: get rid of this weirdness of a CSSStyleDeclaration inside of a
451 // style property set. 447 // style property set.
452 if (m_cssomWrapper) { 448 if (m_cssomWrapper) {
453 ASSERT(!static_cast<CSSStyleDeclaration*>(m_cssomWrapper.get())->parentR ule()); 449 ASSERT(!static_cast<CSSStyleDeclaration*>(m_cssomWrapper.get())->parentR ule());
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
512 { 508 {
513 return adoptRefWillBeNoop(new MutableStylePropertySet(cssParserMode)); 509 return adoptRefWillBeNoop(new MutableStylePropertySet(cssParserMode));
514 } 510 }
515 511
516 PassRefPtrWillBeRawPtr<MutableStylePropertySet> MutableStylePropertySet::create( const CSSProperty* properties, unsigned count) 512 PassRefPtrWillBeRawPtr<MutableStylePropertySet> MutableStylePropertySet::create( const CSSProperty* properties, unsigned count)
517 { 513 {
518 return adoptRefWillBeNoop(new MutableStylePropertySet(properties, count)); 514 return adoptRefWillBeNoop(new MutableStylePropertySet(properties, count));
519 } 515 }
520 516
521 } // namespace blink 517 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/css/StylePropertySet.h ('k') | Source/core/css/parser/CSSParser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698