| 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 27 matching lines...) Expand all Loading... |
| 38 #include <stdio.h> | 38 #include <stdio.h> |
| 39 #endif | 39 #endif |
| 40 | 40 |
| 41 namespace blink { | 41 namespace blink { |
| 42 | 42 |
| 43 static size_t sizeForImmutableStylePropertySetWithPropertyCount(unsigned count) | 43 static size_t sizeForImmutableStylePropertySetWithPropertyCount(unsigned count) |
| 44 { | 44 { |
| 45 return sizeof(ImmutableStylePropertySet) - sizeof(void*) + sizeof(Member<CSS
Value>) * count + sizeof(StylePropertyMetadata) * count; | 45 return sizeof(ImmutableStylePropertySet) - sizeof(void*) + sizeof(Member<CSS
Value>) * count + sizeof(StylePropertyMetadata) * count; |
| 46 } | 46 } |
| 47 | 47 |
| 48 RawPtr<ImmutableStylePropertySet> ImmutableStylePropertySet::create(const CSSPro
perty* properties, unsigned count, CSSParserMode cssParserMode) | 48 ImmutableStylePropertySet* ImmutableStylePropertySet::create(const CSSProperty*
properties, unsigned count, CSSParserMode cssParserMode) |
| 49 { | 49 { |
| 50 ASSERT(count <= MaxArraySize); | 50 ASSERT(count <= MaxArraySize); |
| 51 void* slot = Heap::allocate<StylePropertySet>(sizeForImmutableStylePropertyS
etWithPropertyCount(count)); | 51 void* slot = Heap::allocate<StylePropertySet>(sizeForImmutableStylePropertyS
etWithPropertyCount(count)); |
| 52 return new (slot) ImmutableStylePropertySet(properties, count, cssParserMode
); | 52 return new (slot) ImmutableStylePropertySet(properties, count, cssParserMode
); |
| 53 } | 53 } |
| 54 | 54 |
| 55 RawPtr<ImmutableStylePropertySet> StylePropertySet::immutableCopyIfNeeded() cons
t | 55 ImmutableStylePropertySet* StylePropertySet::immutableCopyIfNeeded() const |
| 56 { | 56 { |
| 57 if (!isMutable()) | 57 if (!isMutable()) |
| 58 return toImmutableStylePropertySet(const_cast<StylePropertySet*>(this)); | 58 return toImmutableStylePropertySet(const_cast<StylePropertySet*>(this)); |
| 59 const MutableStylePropertySet* mutableThis = toMutableStylePropertySet(this)
; | 59 const MutableStylePropertySet* mutableThis = toMutableStylePropertySet(this)
; |
| 60 return ImmutableStylePropertySet::create(mutableThis->m_propertyVector.data(
), mutableThis->m_propertyVector.size(), cssParserMode()); | 60 return ImmutableStylePropertySet::create(mutableThis->m_propertyVector.data(
), mutableThis->m_propertyVector.size(), cssParserMode()); |
| 61 } | 61 } |
| 62 | 62 |
| 63 MutableStylePropertySet::MutableStylePropertySet(CSSParserMode cssParserMode) | 63 MutableStylePropertySet::MutableStylePropertySet(CSSParserMode cssParserMode) |
| 64 : StylePropertySet(cssParserMode) | 64 : StylePropertySet(cssParserMode) |
| 65 { | 65 { |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 | 168 |
| 169 static String serializeShorthand(const StylePropertySet&, const AtomicString& cu
stomPropertyName) | 169 static String serializeShorthand(const StylePropertySet&, const AtomicString& cu
stomPropertyName) |
| 170 { | 170 { |
| 171 // Custom properties are never shorthands. | 171 // Custom properties are never shorthands. |
| 172 return ""; | 172 return ""; |
| 173 } | 173 } |
| 174 | 174 |
| 175 template<typename T> | 175 template<typename T> |
| 176 String StylePropertySet::getPropertyValue(T property) const | 176 String StylePropertySet::getPropertyValue(T property) const |
| 177 { | 177 { |
| 178 RawPtr<CSSValue> value = getPropertyCSSValue(property); | 178 CSSValue* value = getPropertyCSSValue(property); |
| 179 if (value) | 179 if (value) |
| 180 return value->cssText(); | 180 return value->cssText(); |
| 181 return serializeShorthand(*this, property); | 181 return serializeShorthand(*this, property); |
| 182 } | 182 } |
| 183 template CORE_EXPORT String StylePropertySet::getPropertyValue<CSSPropertyID>(CS
SPropertyID) const; | 183 template CORE_EXPORT String StylePropertySet::getPropertyValue<CSSPropertyID>(CS
SPropertyID) const; |
| 184 template CORE_EXPORT String StylePropertySet::getPropertyValue<AtomicString>(Ato
micString) const; | 184 template CORE_EXPORT String StylePropertySet::getPropertyValue<AtomicString>(Ato
micString) const; |
| 185 | 185 |
| 186 template<typename T> | 186 template<typename T> |
| 187 RawPtr<CSSValue> StylePropertySet::getPropertyCSSValue(T property) const | 187 CSSValue* StylePropertySet::getPropertyCSSValue(T property) const |
| 188 { | 188 { |
| 189 int foundPropertyIndex = findPropertyIndex(property); | 189 int foundPropertyIndex = findPropertyIndex(property); |
| 190 if (foundPropertyIndex == -1) | 190 if (foundPropertyIndex == -1) |
| 191 return nullptr; | 191 return nullptr; |
| 192 return propertyAt(foundPropertyIndex).value(); | 192 return propertyAt(foundPropertyIndex).value(); |
| 193 } | 193 } |
| 194 template CORE_EXPORT RawPtr<CSSValue> StylePropertySet::getPropertyCSSValue<CSSP
ropertyID>(CSSPropertyID) const; | 194 template CORE_EXPORT CSSValue* StylePropertySet::getPropertyCSSValue<CSSProperty
ID>(CSSPropertyID) const; |
| 195 template CORE_EXPORT RawPtr<CSSValue> StylePropertySet::getPropertyCSSValue<Atom
icString>(AtomicString) const; | 195 template CORE_EXPORT CSSValue* StylePropertySet::getPropertyCSSValue<AtomicStrin
g>(AtomicString) const; |
| 196 | 196 |
| 197 DEFINE_TRACE(StylePropertySet) | 197 DEFINE_TRACE(StylePropertySet) |
| 198 { | 198 { |
| 199 if (m_isMutable) | 199 if (m_isMutable) |
| 200 toMutableStylePropertySet(this)->traceAfterDispatch(visitor); | 200 toMutableStylePropertySet(this)->traceAfterDispatch(visitor); |
| 201 else | 201 else |
| 202 toImmutableStylePropertySet(this)->traceAfterDispatch(visitor); | 202 toImmutableStylePropertySet(this)->traceAfterDispatch(visitor); |
| 203 } | 203 } |
| 204 | 204 |
| 205 #if ENABLE(OILPAN) | 205 #if ENABLE(OILPAN) |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 return CSSParser::parseValue(this, unresolvedProperty, value, important, con
textStyleSheet); | 313 return CSSParser::parseValue(this, unresolvedProperty, value, important, con
textStyleSheet); |
| 314 } | 314 } |
| 315 | 315 |
| 316 bool MutableStylePropertySet::setProperty(const AtomicString& customPropertyName
, const String& value, bool important, StyleSheetContents* contextStyleSheet) | 316 bool MutableStylePropertySet::setProperty(const AtomicString& customPropertyName
, const String& value, bool important, StyleSheetContents* contextStyleSheet) |
| 317 { | 317 { |
| 318 if (value.isEmpty()) | 318 if (value.isEmpty()) |
| 319 return removeProperty(customPropertyName); | 319 return removeProperty(customPropertyName); |
| 320 return CSSParser::parseValueForCustomProperty(this, customPropertyName, valu
e, important, contextStyleSheet); | 320 return CSSParser::parseValueForCustomProperty(this, customPropertyName, valu
e, important, contextStyleSheet); |
| 321 } | 321 } |
| 322 | 322 |
| 323 void MutableStylePropertySet::setProperty(CSSPropertyID propertyID, RawPtr<CSSVa
lue> prpValue, bool important) | 323 void MutableStylePropertySet::setProperty(CSSPropertyID propertyID, CSSValue* va
lue, bool important) |
| 324 { | 324 { |
| 325 StylePropertyShorthand shorthand = shorthandForProperty(propertyID); | 325 StylePropertyShorthand shorthand = shorthandForProperty(propertyID); |
| 326 if (!shorthand.length()) { | 326 if (!shorthand.length()) { |
| 327 setProperty(CSSProperty(propertyID, prpValue, important)); | 327 setProperty(CSSProperty(propertyID, value, important)); |
| 328 return; | 328 return; |
| 329 } | 329 } |
| 330 | 330 |
| 331 removePropertiesInSet(shorthand.properties(), shorthand.length()); | 331 removePropertiesInSet(shorthand.properties(), shorthand.length()); |
| 332 | 332 |
| 333 RawPtr<CSSValue> value = prpValue; | |
| 334 for (unsigned i = 0; i < shorthand.length(); ++i) | 333 for (unsigned i = 0; i < shorthand.length(); ++i) |
| 335 m_propertyVector.append(CSSProperty(shorthand.properties()[i], value, im
portant)); | 334 m_propertyVector.append(CSSProperty(shorthand.properties()[i], value, im
portant)); |
| 336 } | 335 } |
| 337 | 336 |
| 338 bool MutableStylePropertySet::setProperty(const CSSProperty& property, CSSProper
ty* slot) | 337 bool MutableStylePropertySet::setProperty(const CSSProperty& property, CSSProper
ty* slot) |
| 339 { | 338 { |
| 340 if (!removeShorthandProperty(property.id())) { | 339 if (!removeShorthandProperty(property.id())) { |
| 341 const AtomicString& name = (property.id() == CSSPropertyVariable) ? | 340 const AtomicString& name = (property.id() == CSSPropertyVariable) ? |
| 342 toCSSCustomPropertyDeclaration(property.value())->name() : nullAtom; | 341 toCSSCustomPropertyDeclaration(property.value())->name() : nullAtom; |
| 343 CSSProperty* toReplace = slot ? slot : findCSSPropertyWithID(property.id
(), name); | 342 CSSProperty* toReplace = slot ? slot : findCSSPropertyWithID(property.id
(), name); |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 498 for (unsigned i = 0; i < size; ++i) { | 497 for (unsigned i = 0; i < size; ++i) { |
| 499 PropertyReference property = propertyAt(i); | 498 PropertyReference property = propertyAt(i); |
| 500 if (style->cssPropertyMatches(property.id(), property.value())) | 499 if (style->cssPropertyMatches(property.id(), property.value())) |
| 501 propertiesToRemove.append(property.id()); | 500 propertiesToRemove.append(property.id()); |
| 502 } | 501 } |
| 503 // FIXME: This should use mass removal. | 502 // FIXME: This should use mass removal. |
| 504 for (unsigned i = 0; i < propertiesToRemove.size(); ++i) | 503 for (unsigned i = 0; i < propertiesToRemove.size(); ++i) |
| 505 removeProperty(propertiesToRemove[i]); | 504 removeProperty(propertiesToRemove[i]); |
| 506 } | 505 } |
| 507 | 506 |
| 508 RawPtr<MutableStylePropertySet> StylePropertySet::mutableCopy() const | 507 MutableStylePropertySet* StylePropertySet::mutableCopy() const |
| 509 { | 508 { |
| 510 return new MutableStylePropertySet(*this); | 509 return new MutableStylePropertySet(*this); |
| 511 } | 510 } |
| 512 | 511 |
| 513 RawPtr<MutableStylePropertySet> StylePropertySet::copyPropertiesInSet(const Vect
or<CSSPropertyID>& properties) const | 512 MutableStylePropertySet* StylePropertySet::copyPropertiesInSet(const Vector<CSSP
ropertyID>& properties) const |
| 514 { | 513 { |
| 515 HeapVector<CSSProperty, 256> list; | 514 HeapVector<CSSProperty, 256> list; |
| 516 list.reserveInitialCapacity(properties.size()); | 515 list.reserveInitialCapacity(properties.size()); |
| 517 for (unsigned i = 0; i < properties.size(); ++i) { | 516 for (unsigned i = 0; i < properties.size(); ++i) { |
| 518 RawPtr<CSSValue> value = getPropertyCSSValue(properties[i]); | 517 CSSValue* value = getPropertyCSSValue(properties[i]); |
| 519 if (value) | 518 if (value) |
| 520 list.append(CSSProperty(properties[i], value.release(), false)); | 519 list.append(CSSProperty(properties[i], value, false)); |
| 521 } | 520 } |
| 522 return MutableStylePropertySet::create(list.data(), list.size()); | 521 return MutableStylePropertySet::create(list.data(), list.size()); |
| 523 } | 522 } |
| 524 | 523 |
| 525 CSSStyleDeclaration* MutableStylePropertySet::ensureCSSStyleDeclaration() | 524 CSSStyleDeclaration* MutableStylePropertySet::ensureCSSStyleDeclaration() |
| 526 { | 525 { |
| 527 // FIXME: get rid of this weirdness of a CSSStyleDeclaration inside of a | 526 // FIXME: get rid of this weirdness of a CSSStyleDeclaration inside of a |
| 528 // style property set. | 527 // style property set. |
| 529 if (m_cssomWrapper) { | 528 if (m_cssomWrapper) { |
| 530 ASSERT(!static_cast<CSSStyleDeclaration*>(m_cssomWrapper.get())->parentR
ule()); | 529 ASSERT(!static_cast<CSSStyleDeclaration*>(m_cssomWrapper.get())->parentR
ule()); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 571 }; | 570 }; |
| 572 static_assert(sizeof(StylePropertySet) == sizeof(SameSizeAsStylePropertySet), "S
tylePropertySet should stay small"); | 571 static_assert(sizeof(StylePropertySet) == sizeof(SameSizeAsStylePropertySet), "S
tylePropertySet should stay small"); |
| 573 | 572 |
| 574 #ifndef NDEBUG | 573 #ifndef NDEBUG |
| 575 void StylePropertySet::showStyle() | 574 void StylePropertySet::showStyle() |
| 576 { | 575 { |
| 577 fprintf(stderr, "%s\n", asText().ascii().data()); | 576 fprintf(stderr, "%s\n", asText().ascii().data()); |
| 578 } | 577 } |
| 579 #endif | 578 #endif |
| 580 | 579 |
| 581 RawPtr<MutableStylePropertySet> MutableStylePropertySet::create(CSSParserMode cs
sParserMode) | 580 MutableStylePropertySet* MutableStylePropertySet::create(CSSParserMode cssParser
Mode) |
| 582 { | 581 { |
| 583 return new MutableStylePropertySet(cssParserMode); | 582 return new MutableStylePropertySet(cssParserMode); |
| 584 } | 583 } |
| 585 | 584 |
| 586 RawPtr<MutableStylePropertySet> MutableStylePropertySet::create(const CSSPropert
y* properties, unsigned count) | 585 MutableStylePropertySet* MutableStylePropertySet::create(const CSSProperty* prop
erties, unsigned count) |
| 587 { | 586 { |
| 588 return new MutableStylePropertySet(properties, count); | 587 return new MutableStylePropertySet(properties, count); |
| 589 } | 588 } |
| 590 | 589 |
| 591 } // namespace blink | 590 } // namespace blink |
| OLD | NEW |