| OLD | NEW |
| 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 11 matching lines...) Expand all Loading... |
| 22 | 22 |
| 23 #include "core/css/StylePropertySet.h" | 23 #include "core/css/StylePropertySet.h" |
| 24 | 24 |
| 25 #include "core/StylePropertyShorthand.h" | 25 #include "core/StylePropertyShorthand.h" |
| 26 #include "core/css/CSSCustomPropertyDeclaration.h" | 26 #include "core/css/CSSCustomPropertyDeclaration.h" |
| 27 #include "core/css/CSSPropertyMetadata.h" | 27 #include "core/css/CSSPropertyMetadata.h" |
| 28 #include "core/css/CSSValuePool.h" | 28 #include "core/css/CSSValuePool.h" |
| 29 #include "core/css/StylePropertySerializer.h" | 29 #include "core/css/StylePropertySerializer.h" |
| 30 #include "core/css/StyleSheetContents.h" | 30 #include "core/css/StyleSheetContents.h" |
| 31 #include "core/css/parser/CSSParser.h" | 31 #include "core/css/parser/CSSParser.h" |
| 32 #include "core/css/serializer/CSSDeserializeStream.h" |
| 33 #include "core/css/serializer/CSSSerializeStream.h" |
| 32 #include "core/frame/UseCounter.h" | 34 #include "core/frame/UseCounter.h" |
| 33 #include "platform/RuntimeEnabledFeatures.h" | 35 #include "platform/RuntimeEnabledFeatures.h" |
| 34 #include "wtf/text/StringBuilder.h" | 36 #include "wtf/text/StringBuilder.h" |
| 35 | 37 |
| 36 #ifndef NDEBUG | 38 #ifndef NDEBUG |
| 37 #include "wtf/text/CString.h" | 39 #include "wtf/text/CString.h" |
| 38 #include <stdio.h> | 40 #include <stdio.h> |
| 39 #endif | 41 #endif |
| 40 | 42 |
| 41 namespace blink { | 43 namespace blink { |
| 42 | 44 |
| 43 static size_t sizeForImmutableStylePropertySetWithPropertyCount(unsigned count) | 45 static size_t sizeForImmutableStylePropertySetWithPropertyCount(unsigned count) |
| 44 { | 46 { |
| 45 return sizeof(ImmutableStylePropertySet) - sizeof(void*) + sizeof(RawPtrWill
BeMember<CSSValue>) * count + sizeof(StylePropertyMetadata) * count; | 47 return sizeof(ImmutableStylePropertySet) - sizeof(void*) + sizeof(RawPtrWill
BeMember<CSSValue>) * count + sizeof(StylePropertyMetadata) * count; |
| 46 } | 48 } |
| 47 | 49 |
| 48 PassRefPtrWillBeRawPtr<ImmutableStylePropertySet> ImmutableStylePropertySet::cre
ate(const CSSProperty* properties, unsigned count, CSSParserMode cssParserMode) | 50 PassRefPtrWillBeRawPtr<ImmutableStylePropertySet> ImmutableStylePropertySet::cre
ate(const CSSProperty* properties, unsigned count, CSSParserMode cssParserMode) |
| 49 { | 51 { |
| 50 ASSERT(count <= MaxArraySize); | 52 ASSERT(count <= MaxArraySize); |
| 51 #if ENABLE(OILPAN) | 53 #if ENABLE(OILPAN) |
| 52 void* slot = Heap::allocate<StylePropertySet>(sizeForImmutableStylePropertyS
etWithPropertyCount(count)); | 54 void* slot = Heap::allocate<StylePropertySet>(sizeForImmutableStylePropertyS
etWithPropertyCount(count)); |
| 53 #else | 55 #else |
| 54 void* slot = WTF::Partitions::fastMalloc(sizeForImmutableStylePropertySetWit
hPropertyCount(count), "blink::ImmutableStylePropertySet"); | 56 void* slot = WTF::Partitions::fastMalloc(sizeForImmutableStylePropertySetWit
hPropertyCount(count), "blink::ImmutableStylePropertySet"); |
| 55 #endif // ENABLE(OILPAN) | 57 #endif // ENABLE(OILPAN) |
| 56 return adoptRefWillBeNoop(new (slot) ImmutableStylePropertySet(properties, c
ount, cssParserMode)); | 58 return adoptRefWillBeNoop(new (slot) ImmutableStylePropertySet(properties, c
ount, cssParserMode)); |
| 57 } | 59 } |
| 58 | 60 |
| 61 PassRefPtrWillBeRawPtr<ImmutableStylePropertySet> ImmutableStylePropertySet::des
erialize(CSSDeserializeStream* stream) |
| 62 { |
| 63 unsigned count = stream->readUnsigned(); |
| 64 CSSParserMode cssParserMode = HTMLStandardMode; // FIXME!!! |
| 65 CSDEBUG("ImmutableStylePropertySet::deserialize count: %u\n", count); |
| 66 |
| 67 ASSERT(count <= MaxArraySize); |
| 68 #if ENABLE(OILPAN) |
| 69 void* slot = Heap::allocate<StylePropertySet>(sizeForImmutableStylePropertyS
etWithPropertyCount(count)); |
| 70 #else |
| 71 void* slot = WTF::Partitions::fastMalloc(sizeForImmutableStylePropertySetWit
hPropertyCount(count), "blink::ImmutableStylePropertySet"); |
| 72 #endif // ENABLE(OILPAN) |
| 73 return adoptRefWillBeNoop(new (slot) ImmutableStylePropertySet(stream, count
, cssParserMode)); |
| 74 } |
| 75 |
| 59 PassRefPtrWillBeRawPtr<ImmutableStylePropertySet> StylePropertySet::immutableCop
yIfNeeded() const | 76 PassRefPtrWillBeRawPtr<ImmutableStylePropertySet> StylePropertySet::immutableCop
yIfNeeded() const |
| 60 { | 77 { |
| 61 if (!isMutable()) | 78 if (!isMutable()) |
| 62 return toImmutableStylePropertySet(const_cast<StylePropertySet*>(this)); | 79 return toImmutableStylePropertySet(const_cast<StylePropertySet*>(this)); |
| 63 const MutableStylePropertySet* mutableThis = toMutableStylePropertySet(this)
; | 80 const MutableStylePropertySet* mutableThis = toMutableStylePropertySet(this)
; |
| 64 return ImmutableStylePropertySet::create(mutableThis->m_propertyVector.data(
), mutableThis->m_propertyVector.size(), cssParserMode()); | 81 return ImmutableStylePropertySet::create(mutableThis->m_propertyVector.data(
), mutableThis->m_propertyVector.size(), cssParserMode()); |
| 65 } | 82 } |
| 66 | 83 |
| 67 MutableStylePropertySet::MutableStylePropertySet(CSSParserMode cssParserMode) | 84 MutableStylePropertySet::MutableStylePropertySet(CSSParserMode cssParserMode) |
| 68 : StylePropertySet(cssParserMode) | 85 : StylePropertySet(cssParserMode) |
| (...skipping 15 matching lines...) Expand all Loading... |
| 84 RawPtrWillBeMember<CSSValue>* valueArray = const_cast<RawPtrWillBeMember<CSS
Value>*>(this->valueArray()); | 101 RawPtrWillBeMember<CSSValue>* valueArray = const_cast<RawPtrWillBeMember<CSS
Value>*>(this->valueArray()); |
| 85 for (unsigned i = 0; i < m_arraySize; ++i) { | 102 for (unsigned i = 0; i < m_arraySize; ++i) { |
| 86 metadataArray[i] = properties[i].metadata(); | 103 metadataArray[i] = properties[i].metadata(); |
| 87 valueArray[i] = properties[i].value(); | 104 valueArray[i] = properties[i].value(); |
| 88 #if !ENABLE(OILPAN) | 105 #if !ENABLE(OILPAN) |
| 89 valueArray[i]->ref(); | 106 valueArray[i]->ref(); |
| 90 #endif | 107 #endif |
| 91 } | 108 } |
| 92 } | 109 } |
| 93 | 110 |
| 111 ImmutableStylePropertySet::ImmutableStylePropertySet(CSSDeserializeStream* strea
m, unsigned length, CSSParserMode cssParserMode) |
| 112 : StylePropertySet(cssParserMode, length) |
| 113 { |
| 114 StylePropertyMetadata* metadataArray = const_cast<StylePropertyMetadata*>(th
is->metadataArray()); |
| 115 RawPtrWillBeMember<CSSValue>* valueArray = const_cast<RawPtrWillBeMember<CSS
Value>*>(this->valueArray()); |
| 116 for (unsigned i = 0; i < m_arraySize; ++i) { |
| 117 metadataArray[i] = stream->readStylePropertyMetadata(); |
| 118 } |
| 119 for (unsigned i = 0; i < m_arraySize; ++i) { |
| 120 valueArray[i] = CSSValue::deserialize(stream).leakRef(); |
| 121 #if !ENABLE(OILPAN) |
| 122 valueArray[i]->ref(); // FIXME: maybe not needed as above "leaks" |
| 123 #endif |
| 124 } |
| 125 } |
| 126 |
| 94 ImmutableStylePropertySet::~ImmutableStylePropertySet() | 127 ImmutableStylePropertySet::~ImmutableStylePropertySet() |
| 95 { | 128 { |
| 96 #if !ENABLE(OILPAN) | 129 #if !ENABLE(OILPAN) |
| 97 RawPtrWillBeMember<CSSValue>* valueArray = const_cast<RawPtrWillBeMember<CSS
Value>*>(this->valueArray()); | 130 RawPtrWillBeMember<CSSValue>* valueArray = const_cast<RawPtrWillBeMember<CSS
Value>*>(this->valueArray()); |
| 98 for (unsigned i = 0; i < m_arraySize; ++i) { | 131 for (unsigned i = 0; i < m_arraySize; ++i) { |
| 99 // Checking for nullptr here is a workaround to prevent crashing. http:
//crbug.com/449032 | 132 // Checking for nullptr here is a workaround to prevent crashing. http:
//crbug.com/449032 |
| 100 if (valueArray[i]) | 133 if (valueArray[i]) |
| 101 valueArray[i]->deref(); | 134 valueArray[i]->deref(); |
| 102 } | 135 } |
| 103 #endif | 136 #endif |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 for (int n = m_arraySize - 1 ; n >= 0; --n) { | 171 for (int n = m_arraySize - 1 ; n >= 0; --n) { |
| 139 if (isPropertyMatch(metadataArray()[n], *valueArray()[n], id, property)) | 172 if (isPropertyMatch(metadataArray()[n], *valueArray()[n], id, property)) |
| 140 return n; | 173 return n; |
| 141 } | 174 } |
| 142 | 175 |
| 143 return -1; | 176 return -1; |
| 144 } | 177 } |
| 145 template CORE_EXPORT int ImmutableStylePropertySet::findPropertyIndex(CSSPropert
yID) const; | 178 template CORE_EXPORT int ImmutableStylePropertySet::findPropertyIndex(CSSPropert
yID) const; |
| 146 template CORE_EXPORT int ImmutableStylePropertySet::findPropertyIndex(AtomicStri
ng) const; | 179 template CORE_EXPORT int ImmutableStylePropertySet::findPropertyIndex(AtomicStri
ng) const; |
| 147 | 180 |
| 181 void ImmutableStylePropertySet::serializeAfterDispatch(CSSSerializeStream* strea
m) const |
| 182 { |
| 183 // FIXME: handle CSSParserMode |
| 184 stream->writeUnsigned(m_arraySize); |
| 185 CSDEBUG("ImmutableStylePropertySet::serializeAfterDispatch count: %u\n", m_a
rraySize); |
| 186 |
| 187 auto metadatas = metadataArray(); |
| 188 for (unsigned i = 0; i < m_arraySize; i++) { |
| 189 stream->writeStylePropertyMetadata(metadatas[i]); |
| 190 } |
| 191 |
| 192 const RawPtrWillBeMember<CSSValue>* values = valueArray(); |
| 193 for (unsigned i = 0; i < m_arraySize; i++) { |
| 194 values[i]->serialize(stream); |
| 195 } |
| 196 } |
| 197 |
| 148 DEFINE_TRACE_AFTER_DISPATCH(ImmutableStylePropertySet) | 198 DEFINE_TRACE_AFTER_DISPATCH(ImmutableStylePropertySet) |
| 149 { | 199 { |
| 150 const RawPtrWillBeMember<CSSValue>* values = valueArray(); | 200 const RawPtrWillBeMember<CSSValue>* values = valueArray(); |
| 151 for (unsigned i = 0; i < m_arraySize; i++) | 201 for (unsigned i = 0; i < m_arraySize; i++) |
| 152 visitor->trace(values[i]); | 202 visitor->trace(values[i]); |
| 153 StylePropertySet::traceAfterDispatch(visitor); | 203 StylePropertySet::traceAfterDispatch(visitor); |
| 154 } | 204 } |
| 155 | 205 |
| 156 MutableStylePropertySet::MutableStylePropertySet(const StylePropertySet& other) | 206 MutableStylePropertySet::MutableStylePropertySet(const StylePropertySet& other) |
| 157 : StylePropertySet(other.cssParserMode()) | 207 : StylePropertySet(other.cssParserMode()) |
| (...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 554 | 604 |
| 555 DEFINE_TRACE_AFTER_DISPATCH(MutableStylePropertySet) | 605 DEFINE_TRACE_AFTER_DISPATCH(MutableStylePropertySet) |
| 556 { | 606 { |
| 557 #if ENABLE(OILPAN) | 607 #if ENABLE(OILPAN) |
| 558 visitor->trace(m_cssomWrapper); | 608 visitor->trace(m_cssomWrapper); |
| 559 visitor->trace(m_propertyVector); | 609 visitor->trace(m_propertyVector); |
| 560 #endif | 610 #endif |
| 561 StylePropertySet::traceAfterDispatch(visitor); | 611 StylePropertySet::traceAfterDispatch(visitor); |
| 562 } | 612 } |
| 563 | 613 |
| 614 void StylePropertySet::serialize(CSSSerializeStream* stream) const |
| 615 { |
| 616 CSDEBUG("StylePropertySet::serialize\n"); |
| 617 |
| 618 ASSERT(!m_isMutable); |
| 619 toImmutableStylePropertySet(this)->serializeAfterDispatch(stream); |
| 620 } |
| 621 |
| 564 unsigned StylePropertySet::averageSizeInBytes() | 622 unsigned StylePropertySet::averageSizeInBytes() |
| 565 { | 623 { |
| 566 // Please update this if the storage scheme changes so that this longer refl
ects the actual size. | 624 // Please update this if the storage scheme changes so that this longer refl
ects the actual size. |
| 567 return sizeForImmutableStylePropertySetWithPropertyCount(4); | 625 return sizeForImmutableStylePropertySetWithPropertyCount(4); |
| 568 } | 626 } |
| 569 | 627 |
| 570 // See the function above if you need to update this. | 628 // See the function above if you need to update this. |
| 571 struct SameSizeAsStylePropertySet : public RefCountedWillBeGarbageCollectedFinal
ized<SameSizeAsStylePropertySet> { | 629 struct SameSizeAsStylePropertySet : public RefCountedWillBeGarbageCollectedFinal
ized<SameSizeAsStylePropertySet> { |
| 572 unsigned bitfield; | 630 unsigned bitfield; |
| 573 }; | 631 }; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 584 { | 642 { |
| 585 return adoptRefWillBeNoop(new MutableStylePropertySet(cssParserMode)); | 643 return adoptRefWillBeNoop(new MutableStylePropertySet(cssParserMode)); |
| 586 } | 644 } |
| 587 | 645 |
| 588 PassRefPtrWillBeRawPtr<MutableStylePropertySet> MutableStylePropertySet::create(
const CSSProperty* properties, unsigned count) | 646 PassRefPtrWillBeRawPtr<MutableStylePropertySet> MutableStylePropertySet::create(
const CSSProperty* properties, unsigned count) |
| 589 { | 647 { |
| 590 return adoptRefWillBeNoop(new MutableStylePropertySet(properties, count)); | 648 return adoptRefWillBeNoop(new MutableStylePropertySet(properties, count)); |
| 591 } | 649 } |
| 592 | 650 |
| 593 } // namespace blink | 651 } // namespace blink |
| OLD | NEW |