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

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: Some small fixes to (hopefully) fix some broken tests Created 5 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 /* 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 24 matching lines...) Expand all
35 35
36 #ifndef NDEBUG 36 #ifndef NDEBUG
37 #include "wtf/text/CString.h" 37 #include "wtf/text/CString.h"
38 #include <stdio.h> 38 #include <stdio.h>
39 #endif 39 #endif
40 40
41 namespace blink { 41 namespace blink {
42 42
43 static size_t sizeForImmutableStylePropertySetWithPropertyCount(unsigned count) 43 static size_t sizeForImmutableStylePropertySetWithPropertyCount(unsigned count)
44 { 44 {
45 return sizeof(ImmutableStylePropertySet) - sizeof(void*) + sizeof(CSSValue*) * count + sizeof(StylePropertyMetadata) * count; 45 return sizeof(ImmutableStylePropertySet) - sizeof(void*) + sizeof(CSSValue) * count + sizeof(StylePropertyMetadata) * count;
46 } 46 }
47 47
48 PassRefPtrWillBeRawPtr<ImmutableStylePropertySet> ImmutableStylePropertySet::cre ate(const CSSProperty* properties, unsigned count, CSSParserMode cssParserMode) 48 PassRefPtrWillBeRawPtr<ImmutableStylePropertySet> ImmutableStylePropertySet::cre ate(const CSSProperty* properties, unsigned count, CSSParserMode cssParserMode)
49 { 49 {
50 ASSERT(count <= MaxArraySize); 50 ASSERT(count <= MaxArraySize);
51 #if ENABLE(OILPAN) 51 #if ENABLE(OILPAN)
52 void* slot = Heap::allocate<StylePropertySet>(sizeForImmutableStylePropertyS etWithPropertyCount(count)); 52 void* slot = Heap::allocate<StylePropertySet>(sizeForImmutableStylePropertyS etWithPropertyCount(count));
53 #else 53 #else
54 void* slot = WTF::fastMalloc(sizeForImmutableStylePropertySetWithPropertyCou nt(count)); 54 void* slot = WTF::fastMalloc(sizeForImmutableStylePropertySetWithPropertyCou nt(count));
55 #endif // ENABLE(OILPAN) 55 #endif // ENABLE(OILPAN)
(...skipping 18 matching lines...) Expand all
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 new(&valueArray[i]) CSSValue(properties[i].value());
88 #if !ENABLE(OILPAN) 88 #if !ENABLE(OILPAN)
89 valueArray[i]->ref(); 89 valueArray[i].ref();
90 #endif 90 #endif
91 } 91 }
92 } 92 }
93 93
94 ImmutableStylePropertySet::~ImmutableStylePropertySet() 94 ImmutableStylePropertySet::~ImmutableStylePropertySet()
95 { 95 {
96 #if !ENABLE(OILPAN) 96 #if !ENABLE(OILPAN)
97 RawPtrWillBeMember<CSSValue>* valueArray = const_cast<RawPtrWillBeMember<CSS Value>*>(this->valueArray()); 97 CSSValue* valueArray = const_cast<CSSValue*>(this->valueArray());
98 for (unsigned i = 0; i < m_arraySize; ++i) { 98 for (unsigned i = 0; i < m_arraySize; ++i) {
99 // Checking for nullptr here is a workaround to prevent crashing. http: //crbug.com/449032 99 // TODO: Check if this fixes http://crbug.com/449032
100 if (valueArray[i]) 100 valueArray[i].deref();
101 valueArray[i]->deref();
102 } 101 }
103 #endif 102 #endif
104 } 103 }
105 104
106 int ImmutableStylePropertySet::findPropertyIndex(CSSPropertyID propertyID) const 105 int ImmutableStylePropertySet::findPropertyIndex(CSSPropertyID propertyID) const
107 { 106 {
108 // Convert here propertyID into an uint16_t to compare it with the metadata' s m_propertyID to avoid 107 // 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. 108 // the compiler converting it to an int multiple times in the loop.
110 uint16_t id = static_cast<uint16_t>(propertyID); 109 uint16_t id = static_cast<uint16_t>(propertyID);
111 for (int n = m_arraySize - 1 ; n >= 0; --n) { 110 for (int n = m_arraySize - 1 ; n >= 0; --n) {
112 if (metadataArray()[n].m_propertyID == id) { 111 if (metadataArray()[n].m_propertyID == id) {
113 // Only enabled properties should be part of the style. 112 // Only enabled properties should be part of the style.
114 ASSERT(CSSPropertyMetadata::isEnabledProperty(propertyID)); 113 ASSERT(CSSPropertyMetadata::isEnabledProperty(propertyID));
115 return n; 114 return n;
116 } 115 }
117 } 116 }
118 117
119 return -1; 118 return -1;
120 } 119 }
121 120
122 DEFINE_TRACE_AFTER_DISPATCH(ImmutableStylePropertySet) 121 DEFINE_TRACE_AFTER_DISPATCH(ImmutableStylePropertySet)
123 { 122 {
124 const RawPtrWillBeMember<CSSValue>* values = valueArray(); 123 const CSSValue* values = valueArray();
125 for (unsigned i = 0; i < m_arraySize; i++) 124 for (unsigned i = 0; i < m_arraySize; i++)
126 visitor->trace(values[i]); 125 visitor->trace(values[i]);
127 StylePropertySet::traceAfterDispatch(visitor); 126 StylePropertySet::traceAfterDispatch(visitor);
128 } 127 }
129 128
130 MutableStylePropertySet::MutableStylePropertySet(const StylePropertySet& other) 129 MutableStylePropertySet::MutableStylePropertySet(const StylePropertySet& other)
131 : StylePropertySet(other.cssParserMode()) 130 : StylePropertySet(other.cssParserMode())
132 { 131 {
133 if (other.isMutable()) { 132 if (other.isMutable()) {
134 m_propertyVector = toMutableStylePropertySet(other).m_propertyVector; 133 m_propertyVector = toMutableStylePropertySet(other).m_propertyVector;
135 } else { 134 } else {
136 m_propertyVector.reserveInitialCapacity(other.propertyCount()); 135 m_propertyVector.reserveInitialCapacity(other.propertyCount());
137 for (unsigned i = 0; i < other.propertyCount(); ++i) 136 for (unsigned i = 0; i < other.propertyCount(); ++i)
138 m_propertyVector.uncheckedAppend(other.propertyAt(i).toCSSProperty() ); 137 m_propertyVector.uncheckedAppend(other.propertyAt(i).toCSSProperty() );
139 } 138 }
140 } 139 }
141 140
142 String StylePropertySet::getPropertyValue(CSSPropertyID propertyID) const 141 String StylePropertySet::getPropertyValue(CSSPropertyID propertyID) const
143 { 142 {
144 RefPtrWillBeRawPtr<CSSValue> value = getPropertyCSSValue(propertyID); 143 NullableCSSValue value = getPropertyCSSValue(propertyID);
145 if (value) 144 if (value)
146 return value->cssText(); 145 return value->cssText();
147 146
148 return StylePropertySerializer(*this).getPropertyValue(propertyID); 147 return StylePropertySerializer(*this).getPropertyValue(propertyID);
149 } 148 }
150 149
151 PassRefPtrWillBeRawPtr<CSSValue> StylePropertySet::getPropertyCSSValue(CSSProper tyID propertyID) const 150 NullableCSSValue StylePropertySet::getPropertyCSSValue(CSSPropertyID propertyID) const
152 { 151 {
153 int foundPropertyIndex = findPropertyIndex(propertyID); 152 int foundPropertyIndex = findPropertyIndex(propertyID);
154 if (foundPropertyIndex == -1) 153 if (foundPropertyIndex == -1)
155 return nullptr; 154 return nullptr;
156 return propertyAt(foundPropertyIndex).value(); 155 return propertyAt(foundPropertyIndex).value();
157 } 156 }
158 157
159 DEFINE_TRACE(StylePropertySet) 158 DEFINE_TRACE(StylePropertySet)
160 { 159 {
161 if (m_isMutable) 160 if (m_isMutable)
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 } 192 }
194 193
195 int foundPropertyIndex = findPropertyIndex(propertyID); 194 int foundPropertyIndex = findPropertyIndex(propertyID);
196 if (foundPropertyIndex == -1) { 195 if (foundPropertyIndex == -1) {
197 if (returnText) 196 if (returnText)
198 *returnText = ""; 197 *returnText = "";
199 return false; 198 return false;
200 } 199 }
201 200
202 if (returnText) 201 if (returnText)
203 *returnText = propertyAt(foundPropertyIndex).value()->cssText(); 202 *returnText = propertyAt(foundPropertyIndex).value().cssText();
204 203
205 // A more efficient removal strategy would involve marking entries as empty 204 // A more efficient removal strategy would involve marking entries as empty
206 // and sweeping them when the vector grows too big. 205 // and sweeping them when the vector grows too big.
207 m_propertyVector.remove(foundPropertyIndex); 206 m_propertyVector.remove(foundPropertyIndex);
208 207
209 return true; 208 return true;
210 } 209 }
211 210
212 bool StylePropertySet::propertyIsImportant(CSSPropertyID propertyID) const 211 bool StylePropertySet::propertyIsImportant(CSSPropertyID propertyID) const
213 { 212 {
(...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. 246 // 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. 247 // Setting it to null seems to produce less consistent results, but we treat it just the same.
249 if (value.isEmpty()) 248 if (value.isEmpty())
250 return removeProperty(resolveCSSPropertyID(unresolvedProperty)); 249 return removeProperty(resolveCSSPropertyID(unresolvedProperty));
251 250
252 // When replacing an existing property value, this moves the property to the end of the list. 251 // 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. 252 // Firefox preserves the position, and MSIE moves the property to the beginn ing.
254 return CSSParser::parseValue(this, unresolvedProperty, value, important, css ParserMode(), contextStyleSheet); 253 return CSSParser::parseValue(this, unresolvedProperty, value, important, css ParserMode(), contextStyleSheet);
255 } 254 }
256 255
257 void MutableStylePropertySet::setProperty(CSSPropertyID propertyID, PassRefPtrWi llBeRawPtr<CSSValue> prpValue, bool important) 256 void MutableStylePropertySet::setProperty(CSSPropertyID propertyID, CSSValue prp Value, bool important)
258 { 257 {
259 StylePropertyShorthand shorthand = shorthandForProperty(propertyID); 258 StylePropertyShorthand shorthand = shorthandForProperty(propertyID);
260 if (!shorthand.length()) { 259 if (!shorthand.length()) {
261 setProperty(CSSProperty(propertyID, prpValue, important)); 260 setProperty(CSSProperty(propertyID, prpValue, important));
262 return; 261 return;
263 } 262 }
264 263
265 removePropertiesInSet(shorthand.properties(), shorthand.length()); 264 removePropertiesInSet(shorthand.properties(), shorthand.length());
266 265
267 RefPtrWillBeRawPtr<CSSValue> value = prpValue; 266 CSSValue value = prpValue;
268 for (unsigned i = 0; i < shorthand.length(); ++i) 267 for (unsigned i = 0; i < shorthand.length(); ++i)
269 m_propertyVector.append(CSSProperty(shorthand.properties()[i], value, im portant)); 268 m_propertyVector.append(CSSProperty(shorthand.properties()[i], value, im portant));
270 } 269 }
271 270
272 bool MutableStylePropertySet::setProperty(const CSSProperty& property, CSSProper ty* slot) 271 bool MutableStylePropertySet::setProperty(const CSSProperty& property, CSSProper ty* slot)
273 { 272 {
274 if (!removeShorthandProperty(property.id())) { 273 if (!removeShorthandProperty(property.id())) {
275 CSSProperty* toReplace = slot ? slot : findCSSPropertyWithID(property.id ()); 274 CSSProperty* toReplace = slot ? slot : findCSSPropertyWithID(property.id ());
276 if (toReplace && *toReplace == property) 275 if (toReplace && *toReplace == property)
277 return false; 276 return false;
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 setProperty(toMerge.toCSSProperty(), old); 334 setProperty(toMerge.toCSSProperty(), old);
336 else 335 else
337 m_propertyVector.append(toMerge.toCSSProperty()); 336 m_propertyVector.append(toMerge.toCSSProperty());
338 } 337 }
339 } 338 }
340 339
341 bool StylePropertySet::hasFailedOrCanceledSubresources() const 340 bool StylePropertySet::hasFailedOrCanceledSubresources() const
342 { 341 {
343 unsigned size = propertyCount(); 342 unsigned size = propertyCount();
344 for (unsigned i = 0; i < size; ++i) { 343 for (unsigned i = 0; i < size; ++i) {
345 if (propertyAt(i).value()->hasFailedOrCanceledSubresources()) 344 if (propertyAt(i).value().hasFailedOrCanceledSubresources())
346 return true; 345 return true;
347 } 346 }
348 return false; 347 return false;
349 } 348 }
350 349
351 // This is the list of properties we want to copy in the copyBlockProperties() f unction. 350 // This is the list of properties we want to copy in the copyBlockProperties() f unction.
352 // It is the list of CSS properties that apply specially to block-level elements . 351 // It is the list of CSS properties that apply specially to block-level elements .
353 static const CSSPropertyID staticBlockProperties[] = { 352 static const CSSPropertyID staticBlockProperties[] = {
354 CSSPropertyOrphans, 353 CSSPropertyOrphans,
355 CSSPropertyOverflow, // This can be also be applied to replaced elements 354 CSSPropertyOverflow, // This can be also be applied to replaced elements
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 } 426 }
428 427
429 CSSProperty* MutableStylePropertySet::findCSSPropertyWithID(CSSPropertyID proper tyID) 428 CSSProperty* MutableStylePropertySet::findCSSPropertyWithID(CSSPropertyID proper tyID)
430 { 429 {
431 int foundPropertyIndex = findPropertyIndex(propertyID); 430 int foundPropertyIndex = findPropertyIndex(propertyID);
432 if (foundPropertyIndex == -1) 431 if (foundPropertyIndex == -1)
433 return 0; 432 return 0;
434 return &m_propertyVector.at(foundPropertyIndex); 433 return &m_propertyVector.at(foundPropertyIndex);
435 } 434 }
436 435
437 bool StylePropertySet::propertyMatches(CSSPropertyID propertyID, const CSSValue* propertyValue) const 436 bool StylePropertySet::propertyMatches(CSSPropertyID propertyID, const CSSValue propertyValue) const
438 { 437 {
439 int foundPropertyIndex = findPropertyIndex(propertyID); 438 int foundPropertyIndex = findPropertyIndex(propertyID);
440 if (foundPropertyIndex == -1) 439 if (foundPropertyIndex == -1)
441 return false; 440 return false;
442 return propertyAt(foundPropertyIndex).value()->equals(*propertyValue); 441 return propertyAt(foundPropertyIndex).value().equals(propertyValue);
443 } 442 }
444 443
445 void MutableStylePropertySet::removeEquivalentProperties(const StylePropertySet* style) 444 void MutableStylePropertySet::removeEquivalentProperties(const StylePropertySet* style)
446 { 445 {
447 Vector<CSSPropertyID> propertiesToRemove; 446 Vector<CSSPropertyID> propertiesToRemove;
448 unsigned size = m_propertyVector.size(); 447 unsigned size = m_propertyVector.size();
449 for (unsigned i = 0; i < size; ++i) { 448 for (unsigned i = 0; i < size; ++i) {
450 PropertyReference property = propertyAt(i); 449 PropertyReference property = propertyAt(i);
451 if (style->propertyMatches(property.id(), property.value())) 450 if (style->propertyMatches(property.id(), property.value()))
452 propertiesToRemove.append(property.id()); 451 propertiesToRemove.append(property.id());
(...skipping 20 matching lines...) Expand all
473 PassRefPtrWillBeRawPtr<MutableStylePropertySet> StylePropertySet::mutableCopy() const 472 PassRefPtrWillBeRawPtr<MutableStylePropertySet> StylePropertySet::mutableCopy() const
474 { 473 {
475 return adoptRefWillBeNoop(new MutableStylePropertySet(*this)); 474 return adoptRefWillBeNoop(new MutableStylePropertySet(*this));
476 } 475 }
477 476
478 PassRefPtrWillBeRawPtr<MutableStylePropertySet> StylePropertySet::copyProperties InSet(const Vector<CSSPropertyID>& properties) const 477 PassRefPtrWillBeRawPtr<MutableStylePropertySet> StylePropertySet::copyProperties InSet(const Vector<CSSPropertyID>& properties) const
479 { 478 {
480 WillBeHeapVector<CSSProperty, 256> list; 479 WillBeHeapVector<CSSProperty, 256> list;
481 list.reserveInitialCapacity(properties.size()); 480 list.reserveInitialCapacity(properties.size());
482 for (unsigned i = 0; i < properties.size(); ++i) { 481 for (unsigned i = 0; i < properties.size(); ++i) {
483 RefPtrWillBeRawPtr<CSSValue> value = getPropertyCSSValue(properties[i]); 482 NullableCSSValue value = getPropertyCSSValue(properties[i]);
484 if (value) 483 if (value)
485 list.append(CSSProperty(properties[i], value.release(), false)); 484 list.append(CSSProperty(properties[i], *value, false));
486 } 485 }
487 return MutableStylePropertySet::create(list.data(), list.size()); 486 return MutableStylePropertySet::create(list.data(), list.size());
488 } 487 }
489 488
490 CSSStyleDeclaration* MutableStylePropertySet::ensureCSSStyleDeclaration() 489 CSSStyleDeclaration* MutableStylePropertySet::ensureCSSStyleDeclaration()
491 { 490 {
492 // FIXME: get rid of this weirdness of a CSSStyleDeclaration inside of a 491 // FIXME: get rid of this weirdness of a CSSStyleDeclaration inside of a
493 // style property set. 492 // style property set.
494 if (m_cssomWrapper) { 493 if (m_cssomWrapper) {
495 ASSERT(!static_cast<CSSStyleDeclaration*>(m_cssomWrapper.get())->parentR ule()); 494 ASSERT(!static_cast<CSSStyleDeclaration*>(m_cssomWrapper.get())->parentR ule());
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 { 548 {
550 return adoptRefWillBeNoop(new MutableStylePropertySet(cssParserMode)); 549 return adoptRefWillBeNoop(new MutableStylePropertySet(cssParserMode));
551 } 550 }
552 551
553 PassRefPtrWillBeRawPtr<MutableStylePropertySet> MutableStylePropertySet::create( const CSSProperty* properties, unsigned count) 552 PassRefPtrWillBeRawPtr<MutableStylePropertySet> MutableStylePropertySet::create( const CSSProperty* properties, unsigned count)
554 { 553 {
555 return adoptRefWillBeNoop(new MutableStylePropertySet(properties, count)); 554 return adoptRefWillBeNoop(new MutableStylePropertySet(properties, count));
556 } 555 }
557 556
558 } // namespace blink 557 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698