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 { |
| 67 } |
| 68 |
71 MutableStylePropertySet::MutableStylePropertySet(const CSSProperty* properties,
unsigned length) | 69 MutableStylePropertySet::MutableStylePropertySet(const CSSProperty* properties,
unsigned length) |
72 : StylePropertySet(CSSStrictMode) | 70 : StylePropertySet(CSSStrictMode) |
73 { | 71 { |
74 m_propertyVector.reserveInitialCapacity(length); | 72 m_propertyVector.reserveInitialCapacity(length); |
75 for (unsigned i = 0; i < length; ++i) | 73 for (unsigned i = 0; i < length; ++i) |
76 m_propertyVector.uncheckedAppend(properties[i]); | 74 m_propertyVector.uncheckedAppend(properties[i]); |
77 } | 75 } |
78 | 76 |
79 ImmutableStylePropertySet::ImmutableStylePropertySet(const CSSProperty* properti
es, unsigned length, CSSParserMode cssParserMode) | 77 ImmutableStylePropertySet::ImmutableStylePropertySet(const CSSProperty* properti
es, unsigned length, CSSParserMode cssParserMode) |
80 : StylePropertySet(cssParserMode, length) | 78 : StylePropertySet(cssParserMode, length) |
(...skipping 19 matching lines...) Expand all Loading... |
100 { | 98 { |
101 if (other.isMutable()) | 99 if (other.isMutable()) |
102 m_propertyVector = static_cast<const MutableStylePropertySet&>(other).m_
propertyVector; | 100 m_propertyVector = static_cast<const MutableStylePropertySet&>(other).m_
propertyVector; |
103 else { | 101 else { |
104 m_propertyVector.reserveInitialCapacity(other.propertyCount()); | 102 m_propertyVector.reserveInitialCapacity(other.propertyCount()); |
105 for (unsigned i = 0; i < other.propertyCount(); ++i) | 103 for (unsigned i = 0; i < other.propertyCount(); ++i) |
106 m_propertyVector.uncheckedAppend(other.propertyAt(i).toCSSProperty()
); | 104 m_propertyVector.uncheckedAppend(other.propertyAt(i).toCSSProperty()
); |
107 } | 105 } |
108 } | 106 } |
109 | 107 |
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 | 108 String StylePropertySet::getPropertyValue(CSSPropertyID propertyID) const |
118 { | 109 { |
119 RefPtr<CSSValue> value = getPropertyCSSValue(propertyID); | 110 RefPtr<CSSValue> value = getPropertyCSSValue(propertyID); |
120 if (value) | 111 if (value) |
121 return value->cssText(); | 112 return value->cssText(); |
122 | 113 |
123 return StylePropertySerializer(*this).getPropertyValue(propertyID); | 114 return StylePropertySerializer(*this).getPropertyValue(propertyID); |
124 } | 115 } |
125 | 116 |
126 PassRefPtr<CSSValue> StylePropertySet::getPropertyCSSValue(CSSPropertyID propert
yID) const | 117 PassRefPtr<CSSValue> StylePropertySet::getPropertyCSSValue(CSSPropertyID propert
yID) const |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 // Only add properties that have no !important counterpart present | 312 // Only add properties that have no !important counterpart present |
322 if (!propertyIsImportant(property.id()) || property.isImportant()) | 313 if (!propertyIsImportant(property.id()) || property.isImportant()) |
323 setProperty(property); | 314 setProperty(property); |
324 } | 315 } |
325 | 316 |
326 String StylePropertySet::asText() const | 317 String StylePropertySet::asText() const |
327 { | 318 { |
328 return StylePropertySerializer(*this).asText(); | 319 return StylePropertySerializer(*this).asText(); |
329 } | 320 } |
330 | 321 |
| 322 bool StylePropertySet::hasCSSOMWrapper() const |
| 323 { |
| 324 return m_isMutable && static_cast<const MutableStylePropertySet*>(this)->m_c
ssomWrapper; |
| 325 } |
| 326 |
331 void MutableStylePropertySet::mergeAndOverrideOnConflict(const StylePropertySet*
other) | 327 void MutableStylePropertySet::mergeAndOverrideOnConflict(const StylePropertySet*
other) |
332 { | 328 { |
333 ASSERT(isMutable()); | 329 ASSERT(isMutable()); |
334 unsigned size = other->propertyCount(); | 330 unsigned size = other->propertyCount(); |
335 for (unsigned n = 0; n < size; ++n) { | 331 for (unsigned n = 0; n < size; ++n) { |
336 PropertyReference toMerge = other->propertyAt(n); | 332 PropertyReference toMerge = other->propertyAt(n); |
337 CSSProperty* old = findCSSPropertyWithID(toMerge.id()); | 333 CSSProperty* old = findCSSPropertyWithID(toMerge.id()); |
338 if (old) | 334 if (old) |
339 setProperty(toMerge.toCSSProperty(), old); | 335 setProperty(toMerge.toCSSProperty(), old); |
340 else | 336 else |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
508 for (unsigned i = 0; i < properties.size(); ++i) { | 504 for (unsigned i = 0; i < properties.size(); ++i) { |
509 RefPtr<CSSValue> value = getPropertyCSSValue(properties[i]); | 505 RefPtr<CSSValue> value = getPropertyCSSValue(properties[i]); |
510 if (value) | 506 if (value) |
511 list.append(CSSProperty(properties[i], value.release(), false)); | 507 list.append(CSSProperty(properties[i], value.release(), false)); |
512 } | 508 } |
513 return MutableStylePropertySet::create(list.data(), list.size()); | 509 return MutableStylePropertySet::create(list.data(), list.size()); |
514 } | 510 } |
515 | 511 |
516 PropertySetCSSStyleDeclaration* MutableStylePropertySet::cssStyleDeclaration() | 512 PropertySetCSSStyleDeclaration* MutableStylePropertySet::cssStyleDeclaration() |
517 { | 513 { |
518 if (!m_ownsCSSOMWrapper) | 514 return m_cssomWrapper.get(); |
519 return 0; | |
520 return propertySetCSSOMWrapperMap().get(this); | |
521 } | 515 } |
522 | 516 |
523 CSSStyleDeclaration* MutableStylePropertySet::ensureCSSStyleDeclaration() | 517 CSSStyleDeclaration* MutableStylePropertySet::ensureCSSStyleDeclaration() |
524 { | 518 { |
525 if (m_ownsCSSOMWrapper) { | 519 if (m_cssomWrapper) { |
526 ASSERT(!static_cast<CSSStyleDeclaration*>(propertySetCSSOMWrapperMap().g
et(this))->parentRule()); | 520 ASSERT(!static_cast<CSSStyleDeclaration*>(m_cssomWrapper.get())->parentR
ule()); |
527 ASSERT(!propertySetCSSOMWrapperMap().get(this)->parentElement()); | 521 ASSERT(!m_cssomWrapper->parentElement()); |
528 return propertySetCSSOMWrapperMap().get(this); | 522 return m_cssomWrapper.get(); |
529 } | 523 } |
530 m_ownsCSSOMWrapper = true; | 524 m_cssomWrapper = adoptPtr(new PropertySetCSSStyleDeclaration(this)); |
531 PropertySetCSSStyleDeclaration* cssomWrapper = new PropertySetCSSStyleDeclar
ation(this); | 525 return m_cssomWrapper.get(); |
532 propertySetCSSOMWrapperMap().add(this, adoptPtr(cssomWrapper)); | |
533 return cssomWrapper; | |
534 } | 526 } |
535 | 527 |
536 CSSStyleDeclaration* MutableStylePropertySet::ensureInlineCSSStyleDeclaration(El
ement* parentElement) | 528 CSSStyleDeclaration* MutableStylePropertySet::ensureInlineCSSStyleDeclaration(El
ement* parentElement) |
537 { | 529 { |
538 if (m_ownsCSSOMWrapper) { | 530 if (m_cssomWrapper) { |
539 ASSERT(propertySetCSSOMWrapperMap().get(this)->parentElement() == parent
Element); | 531 ASSERT(m_cssomWrapper->parentElement() == parentElement); |
540 return propertySetCSSOMWrapperMap().get(this); | 532 return m_cssomWrapper.get(); |
541 } | 533 } |
542 m_ownsCSSOMWrapper = true; | 534 m_cssomWrapper = adoptPtr(new InlineCSSStyleDeclaration(this, parentElement)
); |
543 PropertySetCSSStyleDeclaration* cssomWrapper = new InlineCSSStyleDeclaration
(this, parentElement); | 535 return m_cssomWrapper.get(); |
544 propertySetCSSOMWrapperMap().add(this, adoptPtr(cssomWrapper)); | |
545 return cssomWrapper; | |
546 } | 536 } |
547 | 537 |
548 unsigned StylePropertySet::averageSizeInBytes() | 538 unsigned StylePropertySet::averageSizeInBytes() |
549 { | 539 { |
550 // Please update this if the storage scheme changes so that this longer refl
ects the actual size. | 540 // Please update this if the storage scheme changes so that this longer refl
ects the actual size. |
551 return sizeForImmutableStylePropertySetWithPropertyCount(4); | 541 return sizeForImmutableStylePropertySetWithPropertyCount(4); |
552 } | 542 } |
553 | 543 |
554 void StylePropertySet::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) con
st | 544 void StylePropertySet::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) con
st |
555 { | 545 { |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
604 result.appendLiteral(": "); | 594 result.appendLiteral(": "); |
605 result.append(propertyValue()->cssText()); | 595 result.append(propertyValue()->cssText()); |
606 if (isImportant()) | 596 if (isImportant()) |
607 result.appendLiteral(" !important"); | 597 result.appendLiteral(" !important"); |
608 result.append(';'); | 598 result.append(';'); |
609 return result.toString(); | 599 return result.toString(); |
610 } | 600 } |
611 | 601 |
612 | 602 |
613 } // namespace WebCore | 603 } // namespace WebCore |
OLD | NEW |