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

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

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