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

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

Issue 184313004: Move all RefPtr's to CSSValue to oilpan transition types, except for the one in CSSCursorImageValue. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Fix comment Created 6 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « Source/core/css/StylePropertySet.h ('k') | Source/core/css/parser/BisonCSSParser.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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 namespace WebCore { 43 namespace WebCore {
44 44
45 static size_t sizeForImmutableStylePropertySetWithPropertyCount(unsigned count) 45 static size_t sizeForImmutableStylePropertySetWithPropertyCount(unsigned count)
46 { 46 {
47 return sizeof(ImmutableStylePropertySet) - sizeof(void*) + sizeof(CSSValue*) * count + sizeof(StylePropertyMetadata) * count; 47 return sizeof(ImmutableStylePropertySet) - sizeof(void*) + sizeof(CSSValue*) * count + sizeof(StylePropertyMetadata) * count;
48 } 48 }
49 49
50 PassRefPtr<ImmutableStylePropertySet> ImmutableStylePropertySet::create(const CS SProperty* properties, unsigned count, CSSParserMode cssParserMode) 50 PassRefPtr<ImmutableStylePropertySet> ImmutableStylePropertySet::create(const CS SProperty* properties, unsigned count, CSSParserMode cssParserMode)
51 { 51 {
52 ASSERT(count <= MaxArraySize); 52 ASSERT(count <= MaxArraySize);
53 #if ENABLE(OILPAN)
54 void* slot = Heap::allocate<StylePropertySet>(sizeForImmutableStylePropertyS etWithPropertyCount(count));
55 #else
53 void* slot = WTF::fastMalloc(sizeForImmutableStylePropertySetWithPropertyCou nt(count)); 56 void* slot = WTF::fastMalloc(sizeForImmutableStylePropertySetWithPropertyCou nt(count));
54 return adoptRef(new (slot) ImmutableStylePropertySet(properties, count, cssP arserMode)); 57 #endif // ENABLE(OILPAN)
58 return adoptRefWillBeRefCountedGarbageCollected(new (slot) ImmutableStylePro pertySet(properties, count, cssParserMode));
55 } 59 }
56 60
57 PassRefPtr<ImmutableStylePropertySet> StylePropertySet::immutableCopyIfNeeded() const 61 PassRefPtr<ImmutableStylePropertySet> StylePropertySet::immutableCopyIfNeeded() const
58 { 62 {
59 if (!isMutable()) 63 if (!isMutable())
60 return toImmutableStylePropertySet(const_cast<StylePropertySet*>(this)); 64 return toImmutableStylePropertySet(const_cast<StylePropertySet*>(this));
61 const MutableStylePropertySet* mutableThis = toMutableStylePropertySet(this) ; 65 const MutableStylePropertySet* mutableThis = toMutableStylePropertySet(this) ;
62 return ImmutableStylePropertySet::create(mutableThis->m_propertyVector.data( ), mutableThis->m_propertyVector.size(), cssParserMode()); 66 return ImmutableStylePropertySet::create(mutableThis->m_propertyVector.data( ), mutableThis->m_propertyVector.size(), cssParserMode());
63 } 67 }
64 68
65 MutableStylePropertySet::MutableStylePropertySet(CSSParserMode cssParserMode) 69 MutableStylePropertySet::MutableStylePropertySet(CSSParserMode cssParserMode)
66 : StylePropertySet(cssParserMode) 70 : StylePropertySet(cssParserMode)
67 { 71 {
68 } 72 }
69 73
70 MutableStylePropertySet::MutableStylePropertySet(const CSSProperty* properties, unsigned length) 74 MutableStylePropertySet::MutableStylePropertySet(const CSSProperty* properties, unsigned length)
71 : StylePropertySet(HTMLStandardMode) 75 : StylePropertySet(HTMLStandardMode)
72 { 76 {
73 m_propertyVector.reserveInitialCapacity(length); 77 m_propertyVector.reserveInitialCapacity(length);
74 for (unsigned i = 0; i < length; ++i) 78 for (unsigned i = 0; i < length; ++i)
75 m_propertyVector.uncheckedAppend(properties[i]); 79 m_propertyVector.uncheckedAppend(properties[i]);
76 } 80 }
77 81
78 ImmutableStylePropertySet::ImmutableStylePropertySet(const CSSProperty* properti es, unsigned length, CSSParserMode cssParserMode) 82 ImmutableStylePropertySet::ImmutableStylePropertySet(const CSSProperty* properti es, unsigned length, CSSParserMode cssParserMode)
79 : StylePropertySet(cssParserMode, length) 83 : StylePropertySet(cssParserMode, length)
80 { 84 {
81 StylePropertyMetadata* metadataArray = const_cast<StylePropertyMetadata*>(th is->metadataArray()); 85 StylePropertyMetadata* metadataArray = const_cast<StylePropertyMetadata*>(th is->metadataArray());
82 CSSValue** valueArray = const_cast<CSSValue**>(this->valueArray()); 86 RawPtrWillBeMember<CSSValue>* valueArray = const_cast<RawPtrWillBeMember<CSS Value>*>(this->valueArray());
83 for (unsigned i = 0; i < m_arraySize; ++i) { 87 for (unsigned i = 0; i < m_arraySize; ++i) {
84 metadataArray[i] = properties[i].metadata(); 88 metadataArray[i] = properties[i].metadata();
85 valueArray[i] = properties[i].value(); 89 valueArray[i] = properties[i].value();
86 valueArray[i]->ref(); 90 valueArray[i]->ref();
87 } 91 }
88 } 92 }
89 93
90 ImmutableStylePropertySet::~ImmutableStylePropertySet() 94 ImmutableStylePropertySet::~ImmutableStylePropertySet()
91 { 95 {
92 CSSValue** valueArray = const_cast<CSSValue**>(this->valueArray()); 96 #if !ENABLE(OILPAN)
97 RawPtrWillBeMember<CSSValue>* valueArray = const_cast<RawPtrWillBeMember<CSS Value>*>(this->valueArray());
93 for (unsigned i = 0; i < m_arraySize; ++i) 98 for (unsigned i = 0; i < m_arraySize; ++i)
94 valueArray[i]->deref(); 99 valueArray[i]->deref();
100 #endif
95 } 101 }
96 102
97 int ImmutableStylePropertySet::findPropertyIndex(CSSPropertyID propertyID) const 103 int ImmutableStylePropertySet::findPropertyIndex(CSSPropertyID propertyID) const
98 { 104 {
99 // Convert here propertyID into an uint16_t to compare it with the metadata' s m_propertyID to avoid 105 // Convert here propertyID into an uint16_t to compare it with the metadata' s m_propertyID to avoid
100 // the compiler converting it to an int multiple times in the loop. 106 // the compiler converting it to an int multiple times in the loop.
101 uint16_t id = static_cast<uint16_t>(propertyID); 107 uint16_t id = static_cast<uint16_t>(propertyID);
102 for (int n = m_arraySize - 1 ; n >= 0; --n) { 108 for (int n = m_arraySize - 1 ; n >= 0; --n) {
103 if (metadataArray()[n].m_propertyID == id) { 109 if (metadataArray()[n].m_propertyID == id) {
104 // Only enabled or internal properties should be part of the style. 110 // Only enabled or internal properties should be part of the style.
105 ASSERT(RuntimeCSSEnabled::isCSSPropertyEnabled(propertyID) || isInte rnalProperty(propertyID)); 111 ASSERT(RuntimeCSSEnabled::isCSSPropertyEnabled(propertyID) || isInte rnalProperty(propertyID));
106 return n; 112 return n;
107 } 113 }
108 } 114 }
109 115
110 return -1; 116 return -1;
111 } 117 }
112 118
119 void ImmutableStylePropertySet::traceAfterDispatch(Visitor* visitor)
120 {
121 const RawPtrWillBeMember<CSSValue>* values = valueArray();
122 for (unsigned i = 0; i < m_arraySize; i++)
123 visitor->trace(values[i]);
124 StylePropertySet::traceAfterDispatch(visitor);
125 }
126
113 MutableStylePropertySet::MutableStylePropertySet(const StylePropertySet& other) 127 MutableStylePropertySet::MutableStylePropertySet(const StylePropertySet& other)
114 : StylePropertySet(other.cssParserMode()) 128 : StylePropertySet(other.cssParserMode())
115 { 129 {
116 if (other.isMutable()) { 130 if (other.isMutable()) {
117 m_propertyVector = toMutableStylePropertySet(other).m_propertyVector; 131 m_propertyVector = toMutableStylePropertySet(other).m_propertyVector;
118 } else { 132 } else {
119 m_propertyVector.reserveInitialCapacity(other.propertyCount()); 133 m_propertyVector.reserveInitialCapacity(other.propertyCount());
120 for (unsigned i = 0; i < other.propertyCount(); ++i) 134 for (unsigned i = 0; i < other.propertyCount(); ++i)
121 m_propertyVector.uncheckedAppend(other.propertyAt(i).toCSSProperty() ); 135 m_propertyVector.uncheckedAppend(other.propertyAt(i).toCSSProperty() );
122 } 136 }
123 } 137 }
124 138
125 String StylePropertySet::getPropertyValue(CSSPropertyID propertyID) const 139 String StylePropertySet::getPropertyValue(CSSPropertyID propertyID) const
126 { 140 {
127 RefPtrWillBeRawPtr<CSSValue> value = getPropertyCSSValue(propertyID); 141 RefPtrWillBeRawPtr<CSSValue> value = getPropertyCSSValue(propertyID);
128 if (value) 142 if (value)
129 return value->cssText(); 143 return value->cssText();
130 144
131 return StylePropertySerializer(*this).getPropertyValue(propertyID); 145 return StylePropertySerializer(*this).getPropertyValue(propertyID);
132 } 146 }
133 147
134 PassRefPtrWillBeRawPtr<CSSValue> StylePropertySet::getPropertyCSSValue(CSSProper tyID propertyID) const 148 PassRefPtrWillBeRawPtr<CSSValue> StylePropertySet::getPropertyCSSValue(CSSProper tyID propertyID) const
135 { 149 {
136 int foundPropertyIndex = findPropertyIndex(propertyID); 150 int foundPropertyIndex = findPropertyIndex(propertyID);
137 if (foundPropertyIndex == -1) 151 if (foundPropertyIndex == -1)
138 return nullptr; 152 return nullptr;
139 return propertyAt(foundPropertyIndex).value(); 153 return propertyAt(foundPropertyIndex).value();
140 } 154 }
141 155
156 void StylePropertySet::trace(Visitor* visitor)
157 {
158 if (m_isMutable)
159 toMutableStylePropertySet(this)->traceAfterDispatch(visitor);
160 else
161 toImmutableStylePropertySet(this)->traceAfterDispatch(visitor);
162 }
163
164 void StylePropertySet::finalize()
165 {
166 if (m_isMutable)
167 toMutableStylePropertySet(this)->~MutableStylePropertySet();
168 else
169 toImmutableStylePropertySet(this)->~ImmutableStylePropertySet();
170 }
171
142 bool MutableStylePropertySet::removeShorthandProperty(CSSPropertyID propertyID) 172 bool MutableStylePropertySet::removeShorthandProperty(CSSPropertyID propertyID)
143 { 173 {
144 StylePropertyShorthand shorthand = shorthandForProperty(propertyID); 174 StylePropertyShorthand shorthand = shorthandForProperty(propertyID);
145 if (!shorthand.length()) 175 if (!shorthand.length())
146 return false; 176 return false;
147 177
148 bool ret = removePropertiesInSet(shorthand.properties(), shorthand.length()) ; 178 bool ret = removePropertiesInSet(shorthand.properties(), shorthand.length()) ;
149 179
150 CSSPropertyID prefixingVariant = prefixingVariantForPropertyId(propertyID); 180 CSSPropertyID prefixingVariant = prefixingVariantForPropertyId(propertyID);
151 if (prefixingVariant == propertyID) 181 if (prefixingVariant == propertyID)
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 CSSParserContext context(cssParserMode(), UseCounter::getFrom(contextStyleSh eet)); 342 CSSParserContext context(cssParserMode(), UseCounter::getFrom(contextStyleSh eet));
313 if (contextStyleSheet) { 343 if (contextStyleSheet) {
314 context = contextStyleSheet->parserContext(); 344 context = contextStyleSheet->parserContext();
315 context.setMode(cssParserMode()); 345 context.setMode(cssParserMode());
316 } 346 }
317 347
318 BisonCSSParser parser(context); 348 BisonCSSParser parser(context);
319 parser.parseDeclaration(this, styleDeclaration, 0, contextStyleSheet); 349 parser.parseDeclaration(this, styleDeclaration, 0, contextStyleSheet);
320 } 350 }
321 351
322 void MutableStylePropertySet::addParsedProperties(const Vector<CSSProperty, 256> & properties) 352 void MutableStylePropertySet::addParsedProperties(const WillBeHeapVector<CSSProp erty, 256>& properties)
323 { 353 {
324 m_propertyVector.reserveCapacity(m_propertyVector.size() + properties.size() ); 354 m_propertyVector.reserveCapacity(m_propertyVector.size() + properties.size() );
325 for (unsigned i = 0; i < properties.size(); ++i) 355 for (unsigned i = 0; i < properties.size(); ++i)
326 addParsedProperty(properties[i]); 356 addParsedProperty(properties[i]);
327 } 357 }
328 358
329 void MutableStylePropertySet::addParsedProperty(const CSSProperty& property) 359 void MutableStylePropertySet::addParsedProperty(const CSSProperty& property)
330 { 360 {
331 // Only add properties that have no !important counterpart present 361 // Only add properties that have no !important counterpart present
332 if (!propertyIsImportant(property.id()) || property.isImportant()) 362 if (!propertyIsImportant(property.id()) || property.isImportant())
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 bool MutableStylePropertySet::removePropertiesInSet(const CSSPropertyID* set, un signed length) 442 bool MutableStylePropertySet::removePropertiesInSet(const CSSPropertyID* set, un signed length)
413 { 443 {
414 if (m_propertyVector.isEmpty()) 444 if (m_propertyVector.isEmpty())
415 return false; 445 return false;
416 446
417 // FIXME: This is always used with static sets and in that case constructing the hash repeatedly is pretty pointless. 447 // FIXME: This is always used with static sets and in that case constructing the hash repeatedly is pretty pointless.
418 HashSet<CSSPropertyID> toRemove; 448 HashSet<CSSPropertyID> toRemove;
419 for (unsigned i = 0; i < length; ++i) 449 for (unsigned i = 0; i < length; ++i)
420 toRemove.add(set[i]); 450 toRemove.add(set[i]);
421 451
422 Vector<CSSProperty> newProperties; 452 WillBeHeapVector<CSSProperty> newProperties;
423 newProperties.reserveInitialCapacity(m_propertyVector.size()); 453 newProperties.reserveInitialCapacity(m_propertyVector.size());
424 454
425 unsigned size = m_propertyVector.size(); 455 unsigned size = m_propertyVector.size();
426 for (unsigned n = 0; n < size; ++n) { 456 for (unsigned n = 0; n < size; ++n) {
427 const CSSProperty& property = m_propertyVector.at(n); 457 const CSSProperty& property = m_propertyVector.at(n);
428 // Not quite sure if the isImportant test is needed but it matches the e xisting behavior. 458 // Not quite sure if the isImportant test is needed but it matches the e xisting behavior.
429 if (!property.isImportant()) { 459 if (!property.isImportant()) {
430 if (toRemove.contains(property.id())) 460 if (toRemove.contains(property.id()))
431 continue; 461 continue;
432 } 462 }
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 if (style->cssPropertyMatches(property.id(), property.value())) 507 if (style->cssPropertyMatches(property.id(), property.value()))
478 propertiesToRemove.append(property.id()); 508 propertiesToRemove.append(property.id());
479 } 509 }
480 // FIXME: This should use mass removal. 510 // FIXME: This should use mass removal.
481 for (unsigned i = 0; i < propertiesToRemove.size(); ++i) 511 for (unsigned i = 0; i < propertiesToRemove.size(); ++i)
482 removeProperty(propertiesToRemove[i]); 512 removeProperty(propertiesToRemove[i]);
483 } 513 }
484 514
485 PassRefPtr<MutableStylePropertySet> StylePropertySet::mutableCopy() const 515 PassRefPtr<MutableStylePropertySet> StylePropertySet::mutableCopy() const
486 { 516 {
487 return adoptRef(new MutableStylePropertySet(*this)); 517 return adoptRefWillBeRefCountedGarbageCollected(new MutableStylePropertySet( *this));
488 } 518 }
489 519
490 PassRefPtr<MutableStylePropertySet> StylePropertySet::copyPropertiesInSet(const Vector<CSSPropertyID>& properties) const 520 PassRefPtr<MutableStylePropertySet> StylePropertySet::copyPropertiesInSet(const Vector<CSSPropertyID>& properties) const
491 { 521 {
492 Vector<CSSProperty, 256> list; 522 WillBeHeapVector<CSSProperty, 256> list;
493 list.reserveInitialCapacity(properties.size()); 523 list.reserveInitialCapacity(properties.size());
494 for (unsigned i = 0; i < properties.size(); ++i) { 524 for (unsigned i = 0; i < properties.size(); ++i) {
495 RefPtrWillBeRawPtr<CSSValue> value = getPropertyCSSValue(properties[i]); 525 RefPtrWillBeRawPtr<CSSValue> value = getPropertyCSSValue(properties[i]);
496 if (value) 526 if (value)
497 list.append(CSSProperty(properties[i], value.release(), false)); 527 list.append(CSSProperty(properties[i], value.release(), false));
498 } 528 }
499 return MutableStylePropertySet::create(list.data(), list.size()); 529 return MutableStylePropertySet::create(list.data(), list.size());
500 } 530 }
501 531
502 CSSStyleDeclaration* MutableStylePropertySet::ensureCSSStyleDeclaration() 532 CSSStyleDeclaration* MutableStylePropertySet::ensureCSSStyleDeclaration()
(...skipping 18 matching lines...) Expand all
521 if (m_propertyVector.at(n).metadata().m_propertyID == id) { 551 if (m_propertyVector.at(n).metadata().m_propertyID == id) {
522 // Only enabled or internal properties should be part of the style. 552 // Only enabled or internal properties should be part of the style.
523 ASSERT(RuntimeCSSEnabled::isCSSPropertyEnabled(propertyID) || isInte rnalProperty(propertyID)); 553 ASSERT(RuntimeCSSEnabled::isCSSPropertyEnabled(propertyID) || isInte rnalProperty(propertyID));
524 return n; 554 return n;
525 } 555 }
526 } 556 }
527 557
528 return -1; 558 return -1;
529 } 559 }
530 560
561 void MutableStylePropertySet::traceAfterDispatch(Visitor* visitor)
562 {
563 visitor->trace(m_propertyVector);
564 StylePropertySet::traceAfterDispatch(visitor);
565 }
566
531 unsigned StylePropertySet::averageSizeInBytes() 567 unsigned StylePropertySet::averageSizeInBytes()
532 { 568 {
533 // Please update this if the storage scheme changes so that this longer refl ects the actual size. 569 // Please update this if the storage scheme changes so that this longer refl ects the actual size.
534 return sizeForImmutableStylePropertySetWithPropertyCount(4); 570 return sizeForImmutableStylePropertySetWithPropertyCount(4);
535 } 571 }
536 572
537 // See the function above if you need to update this. 573 // See the function above if you need to update this.
538 struct SameSizeAsStylePropertySet : public RefCounted<SameSizeAsStylePropertySet > { 574 struct SameSizeAsStylePropertySet : public RefCountedWillBeRefCountedGarbageColl ected<SameSizeAsStylePropertySet> {
539 unsigned bitfield; 575 unsigned bitfield;
540 }; 576 };
541 COMPILE_ASSERT(sizeof(StylePropertySet) == sizeof(SameSizeAsStylePropertySet), s tyle_property_set_should_stay_small); 577 COMPILE_ASSERT(sizeof(StylePropertySet) == sizeof(SameSizeAsStylePropertySet), s tyle_property_set_should_stay_small);
542 578
543 #ifndef NDEBUG 579 #ifndef NDEBUG
544 void StylePropertySet::showStyle() 580 void StylePropertySet::showStyle()
545 { 581 {
546 fprintf(stderr, "%s\n", asText().ascii().data()); 582 fprintf(stderr, "%s\n", asText().ascii().data());
547 } 583 }
548 #endif 584 #endif
549 585
550 PassRefPtr<MutableStylePropertySet> MutableStylePropertySet::create(CSSParserMod e cssParserMode) 586 PassRefPtr<MutableStylePropertySet> MutableStylePropertySet::create(CSSParserMod e cssParserMode)
551 { 587 {
552 return adoptRef(new MutableStylePropertySet(cssParserMode)); 588 return adoptRefWillBeRefCountedGarbageCollected(new MutableStylePropertySet( cssParserMode));
553 } 589 }
554 590
555 PassRefPtr<MutableStylePropertySet> MutableStylePropertySet::create(const CSSPro perty* properties, unsigned count) 591 PassRefPtr<MutableStylePropertySet> MutableStylePropertySet::create(const CSSPro perty* properties, unsigned count)
556 { 592 {
557 return adoptRef(new MutableStylePropertySet(properties, count)); 593 return adoptRefWillBeRefCountedGarbageCollected(new MutableStylePropertySet( properties, count));
558 } 594 }
559 595
560 String StylePropertySet::PropertyReference::cssName() const 596 String StylePropertySet::PropertyReference::cssName() const
561 { 597 {
562 return getPropertyNameString(id()); 598 return getPropertyNameString(id());
563 } 599 }
564 600
565 String StylePropertySet::PropertyReference::cssText() const 601 String StylePropertySet::PropertyReference::cssText() const
566 { 602 {
567 StringBuilder result; 603 StringBuilder result;
568 result.append(cssName()); 604 result.append(cssName());
569 result.appendLiteral(": "); 605 result.appendLiteral(": ");
570 result.append(propertyValue()->cssText()); 606 result.append(propertyValue()->cssText());
571 if (isImportant()) 607 if (isImportant())
572 result.appendLiteral(" !important"); 608 result.appendLiteral(" !important");
573 result.append(';'); 609 result.append(';');
574 return result.toString(); 610 return result.toString();
575 } 611 }
576 612
577 613
578 } // namespace WebCore 614 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/css/StylePropertySet.h ('k') | Source/core/css/parser/BisonCSSParser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698