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 * | 5 * |
6 * This library is free software; you can redistribute it and/or | 6 * This library is free software; you can redistribute it and/or |
7 * modify it under the terms of the GNU Library General Public | 7 * modify it under the terms of the GNU Library General Public |
8 * License as published by the Free Software Foundation; either | 8 * License as published by the Free Software Foundation; either |
9 * version 2 of the License, or (at your option) any later version. | 9 * version 2 of the License, or (at your option) any later version. |
10 * | 10 * |
(...skipping 24 matching lines...) Expand all Loading... | |
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 using namespace std; | 41 using namespace std; |
42 | 42 |
43 namespace WebCore { | 43 namespace WebCore { |
44 | 44 |
45 typedef HashMap<MutableStylePropertySet*, OwnPtr<PropertySetCSSStyleDeclaration> > PropertySetCSSOMWrapperMap; | |
46 static PropertySetCSSOMWrapperMap& propertySetCSSOMWrapperMap() | |
47 { | |
48 DEFINE_STATIC_LOCAL(PropertySetCSSOMWrapperMap, propertySetCSSOMWrapperMapIn stance, ()); | |
49 return propertySetCSSOMWrapperMapInstance; | |
50 } | |
51 | |
52 static size_t sizeForImmutableStylePropertySetWithPropertyCount(unsigned count) | 45 static size_t sizeForImmutableStylePropertySetWithPropertyCount(unsigned count) |
53 { | 46 { |
54 return sizeof(ImmutableStylePropertySet) - sizeof(void*) + sizeof(CSSValue*) * count + sizeof(StylePropertyMetadata) * count; | 47 return sizeof(ImmutableStylePropertySet) - sizeof(void*) + sizeof(CSSValue*) * count + sizeof(StylePropertyMetadata) * count; |
55 } | 48 } |
56 | 49 |
57 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) |
58 { | 51 { |
59 void* slot = WTF::fastMalloc(sizeForImmutableStylePropertySetWithPropertyCou nt(count)); | 52 void* slot = WTF::fastMalloc(sizeForImmutableStylePropertySetWithPropertyCou nt(count)); |
60 return adoptRef(new (slot) ImmutableStylePropertySet(properties, count, cssP arserMode)); | 53 return adoptRef(new (slot) ImmutableStylePropertySet(properties, count, cssP arserMode)); |
61 } | 54 } |
62 | 55 |
63 PassRefPtr<ImmutableStylePropertySet> StylePropertySet::immutableCopyIfNeeded() const | 56 PassRefPtr<ImmutableStylePropertySet> StylePropertySet::immutableCopyIfNeeded() const |
64 { | 57 { |
65 if (!isMutable()) | 58 if (!isMutable()) |
66 return static_cast<ImmutableStylePropertySet*>(const_cast<StylePropertyS et*>(this)); | 59 return static_cast<ImmutableStylePropertySet*>(const_cast<StylePropertyS et*>(this)); |
67 const MutableStylePropertySet* mutableThis = static_cast<const MutableStyleP ropertySet*>(this); | 60 const MutableStylePropertySet* mutableThis = static_cast<const MutableStyleP ropertySet*>(this); |
68 return ImmutableStylePropertySet::create(mutableThis->m_propertyVector.data( ), mutableThis->m_propertyVector.size(), cssParserMode()); | 61 return ImmutableStylePropertySet::create(mutableThis->m_propertyVector.data( ), mutableThis->m_propertyVector.size(), cssParserMode()); |
69 } | 62 } |
70 | 63 |
64 MutableStylePropertySet::MutableStylePropertySet(CSSParserMode cssParserMode) | |
65 : StylePropertySet(cssParserMode) | |
66 { } | |
abarth-chromium
2013/07/03 18:25:42
Please put each brace on it's own line.
Mads Ager (chromium)
2013/07/04 06:05:47
Done.
| |
67 | |
71 MutableStylePropertySet::MutableStylePropertySet(const CSSProperty* properties, unsigned length) | 68 MutableStylePropertySet::MutableStylePropertySet(const CSSProperty* properties, unsigned length) |
72 : StylePropertySet(CSSStrictMode) | 69 : StylePropertySet(CSSStrictMode) |
73 { | 70 { |
74 m_propertyVector.reserveInitialCapacity(length); | 71 m_propertyVector.reserveInitialCapacity(length); |
75 for (unsigned i = 0; i < length; ++i) | 72 for (unsigned i = 0; i < length; ++i) |
76 m_propertyVector.uncheckedAppend(properties[i]); | 73 m_propertyVector.uncheckedAppend(properties[i]); |
77 } | 74 } |
78 | 75 |
79 ImmutableStylePropertySet::ImmutableStylePropertySet(const CSSProperty* properti es, unsigned length, CSSParserMode cssParserMode) | 76 ImmutableStylePropertySet::ImmutableStylePropertySet(const CSSProperty* properti es, unsigned length, CSSParserMode cssParserMode) |
80 : StylePropertySet(cssParserMode, length) | 77 : StylePropertySet(cssParserMode, length) |
(...skipping 19 matching lines...) Expand all Loading... | |
100 { | 97 { |
101 if (other.isMutable()) | 98 if (other.isMutable()) |
102 m_propertyVector = static_cast<const MutableStylePropertySet&>(other).m_ propertyVector; | 99 m_propertyVector = static_cast<const MutableStylePropertySet&>(other).m_ propertyVector; |
103 else { | 100 else { |
104 m_propertyVector.reserveInitialCapacity(other.propertyCount()); | 101 m_propertyVector.reserveInitialCapacity(other.propertyCount()); |
105 for (unsigned i = 0; i < other.propertyCount(); ++i) | 102 for (unsigned i = 0; i < other.propertyCount(); ++i) |
106 m_propertyVector.uncheckedAppend(other.propertyAt(i).toCSSProperty() ); | 103 m_propertyVector.uncheckedAppend(other.propertyAt(i).toCSSProperty() ); |
107 } | 104 } |
108 } | 105 } |
109 | 106 |
110 MutableStylePropertySet::~MutableStylePropertySet() | |
111 { | |
112 ASSERT(!m_ownsCSSOMWrapper || propertySetCSSOMWrapperMap().contains(this)); | |
113 if (m_ownsCSSOMWrapper) | |
114 propertySetCSSOMWrapperMap().remove(this); | |
115 } | |
116 | |
117 String StylePropertySet::getPropertyValue(CSSPropertyID propertyID) const | 107 String StylePropertySet::getPropertyValue(CSSPropertyID propertyID) const |
118 { | 108 { |
119 RefPtr<CSSValue> value = getPropertyCSSValue(propertyID); | 109 RefPtr<CSSValue> value = getPropertyCSSValue(propertyID); |
120 if (value) | 110 if (value) |
121 return value->cssText(); | 111 return value->cssText(); |
122 | 112 |
123 return StylePropertySerializer(*this).getPropertyValue(propertyID); | 113 return StylePropertySerializer(*this).getPropertyValue(propertyID); |
124 } | 114 } |
125 | 115 |
126 PassRefPtr<CSSValue> StylePropertySet::getPropertyCSSValue(CSSPropertyID propert yID) const | 116 PassRefPtr<CSSValue> StylePropertySet::getPropertyCSSValue(CSSPropertyID propert yID) const |
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
508 for (unsigned i = 0; i < properties.size(); ++i) { | 498 for (unsigned i = 0; i < properties.size(); ++i) { |
509 RefPtr<CSSValue> value = getPropertyCSSValue(properties[i]); | 499 RefPtr<CSSValue> value = getPropertyCSSValue(properties[i]); |
510 if (value) | 500 if (value) |
511 list.append(CSSProperty(properties[i], value.release(), false)); | 501 list.append(CSSProperty(properties[i], value.release(), false)); |
512 } | 502 } |
513 return MutableStylePropertySet::create(list.data(), list.size()); | 503 return MutableStylePropertySet::create(list.data(), list.size()); |
514 } | 504 } |
515 | 505 |
516 PropertySetCSSStyleDeclaration* MutableStylePropertySet::cssStyleDeclaration() | 506 PropertySetCSSStyleDeclaration* MutableStylePropertySet::cssStyleDeclaration() |
517 { | 507 { |
518 if (!m_ownsCSSOMWrapper) | 508 return m_cssomWrapper.get(); |
519 return 0; | |
520 return propertySetCSSOMWrapperMap().get(this); | |
521 } | 509 } |
522 | 510 |
523 CSSStyleDeclaration* MutableStylePropertySet::ensureCSSStyleDeclaration() | 511 CSSStyleDeclaration* MutableStylePropertySet::ensureCSSStyleDeclaration() |
524 { | 512 { |
525 if (m_ownsCSSOMWrapper) { | 513 if (m_ownsCSSOMWrapper) { |
abarth-chromium
2013/07/03 18:25:42
It seems like we can just check whether m_cssomWra
Mads Ager (chromium)
2013/07/04 06:05:47
We can do that. The only complication is that Styl
| |
526 ASSERT(!static_cast<CSSStyleDeclaration*>(propertySetCSSOMWrapperMap().g et(this))->parentRule()); | 514 ASSERT(!static_cast<CSSStyleDeclaration*>(m_cssomWrapper.get())->parentR ule()); |
527 ASSERT(!propertySetCSSOMWrapperMap().get(this)->parentElement()); | 515 ASSERT(!m_cssomWrapper->parentElement()); |
528 return propertySetCSSOMWrapperMap().get(this); | 516 return m_cssomWrapper.get(); |
529 } | 517 } |
530 m_ownsCSSOMWrapper = true; | 518 m_ownsCSSOMWrapper = true; |
531 PropertySetCSSStyleDeclaration* cssomWrapper = new PropertySetCSSStyleDeclar ation(this); | 519 m_cssomWrapper = adoptPtr(new PropertySetCSSStyleDeclaration(this)); |
532 propertySetCSSOMWrapperMap().add(this, adoptPtr(cssomWrapper)); | 520 return m_cssomWrapper.get(); |
533 return cssomWrapper; | |
534 } | 521 } |
535 | 522 |
536 CSSStyleDeclaration* MutableStylePropertySet::ensureInlineCSSStyleDeclaration(El ement* parentElement) | 523 CSSStyleDeclaration* MutableStylePropertySet::ensureInlineCSSStyleDeclaration(El ement* parentElement) |
537 { | 524 { |
538 if (m_ownsCSSOMWrapper) { | 525 if (m_ownsCSSOMWrapper) { |
539 ASSERT(propertySetCSSOMWrapperMap().get(this)->parentElement() == parent Element); | 526 ASSERT(m_cssomWrapper->parentElement() == parentElement); |
540 return propertySetCSSOMWrapperMap().get(this); | 527 return m_cssomWrapper.get(); |
541 } | 528 } |
542 m_ownsCSSOMWrapper = true; | 529 m_ownsCSSOMWrapper = true; |
543 PropertySetCSSStyleDeclaration* cssomWrapper = new InlineCSSStyleDeclaration (this, parentElement); | 530 m_cssomWrapper = adoptPtr(new InlineCSSStyleDeclaration(this, parentElement) ); |
544 propertySetCSSOMWrapperMap().add(this, adoptPtr(cssomWrapper)); | 531 return m_cssomWrapper.get(); |
545 return cssomWrapper; | |
546 } | 532 } |
547 | 533 |
548 unsigned StylePropertySet::averageSizeInBytes() | 534 unsigned StylePropertySet::averageSizeInBytes() |
549 { | 535 { |
550 // Please update this if the storage scheme changes so that this longer refl ects the actual size. | 536 // Please update this if the storage scheme changes so that this longer refl ects the actual size. |
551 return sizeForImmutableStylePropertySetWithPropertyCount(4); | 537 return sizeForImmutableStylePropertySetWithPropertyCount(4); |
552 } | 538 } |
553 | 539 |
554 void StylePropertySet::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) con st | 540 void StylePropertySet::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) con st |
555 { | 541 { |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
604 result.appendLiteral(": "); | 590 result.appendLiteral(": "); |
605 result.append(propertyValue()->cssText()); | 591 result.append(propertyValue()->cssText()); |
606 if (isImportant()) | 592 if (isImportant()) |
607 result.appendLiteral(" !important"); | 593 result.appendLiteral(" !important"); |
608 result.append(';'); | 594 result.append(';'); |
609 return result.toString(); | 595 return result.toString(); |
610 } | 596 } |
611 | 597 |
612 | 598 |
613 } // namespace WebCore | 599 } // namespace WebCore |
OLD | NEW |