| 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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 { | 74 { |
| 75 m_propertyVector.reserveInitialCapacity(length); | 75 m_propertyVector.reserveInitialCapacity(length); |
| 76 for (unsigned i = 0; i < length; ++i) | 76 for (unsigned i = 0; i < length; ++i) |
| 77 m_propertyVector.uncheckedAppend(properties[i]); | 77 m_propertyVector.uncheckedAppend(properties[i]); |
| 78 } | 78 } |
| 79 | 79 |
| 80 ImmutableStylePropertySet::ImmutableStylePropertySet(const CSSProperty* properti
es, unsigned length, CSSParserMode cssParserMode) | 80 ImmutableStylePropertySet::ImmutableStylePropertySet(const CSSProperty* properti
es, unsigned length, CSSParserMode cssParserMode) |
| 81 : StylePropertySet(cssParserMode, length) | 81 : StylePropertySet(cssParserMode, length) |
| 82 { | 82 { |
| 83 StylePropertyMetadata* metadataArray = const_cast<StylePropertyMetadata*>(th
is->metadataArray()); | 83 StylePropertyMetadata* metadataArray = const_cast<StylePropertyMetadata*>(th
is->metadataArray()); |
| 84 RawPtrWillBeMember<CSSValue>* valueArray = const_cast<RawPtrWillBeMember<CSS
Value>*>(this->valueArray()); | 84 RawPtr<CSSValue>* valueArray = const_cast<RawPtr<CSSValue>*>(this->valueArra
y()); |
| 85 for (unsigned i = 0; i < m_arraySize; ++i) { | 85 for (unsigned i = 0; i < m_arraySize; ++i) { |
| 86 metadataArray[i] = properties[i].metadata(); | 86 metadataArray[i] = properties[i].metadata(); |
| 87 valueArray[i] = properties[i].value(); | 87 valueArray[i] = properties[i].value(); |
| 88 #if !ENABLE(OILPAN) | |
| 89 valueArray[i]->ref(); | 88 valueArray[i]->ref(); |
| 90 #endif | |
| 91 } | 89 } |
| 92 } | 90 } |
| 93 | 91 |
| 94 ImmutableStylePropertySet::~ImmutableStylePropertySet() | 92 ImmutableStylePropertySet::~ImmutableStylePropertySet() |
| 95 { | 93 { |
| 96 #if !ENABLE(OILPAN) | 94 RawPtr<CSSValue>* valueArray = const_cast<RawPtr<CSSValue>*>(this->valueArra
y()); |
| 97 RawPtrWillBeMember<CSSValue>* valueArray = const_cast<RawPtrWillBeMember<CSS
Value>*>(this->valueArray()); | |
| 98 for (unsigned i = 0; i < m_arraySize; ++i) { | 95 for (unsigned i = 0; i < m_arraySize; ++i) { |
| 99 // Checking for nullptr here is a workaround to prevent crashing. http:
//crbug.com/449032 | 96 // Checking for nullptr here is a workaround to prevent crashing. http:
//crbug.com/449032 |
| 100 if (valueArray[i]) | 97 if (valueArray[i]) |
| 101 valueArray[i]->deref(); | 98 valueArray[i]->deref(); |
| 102 } | 99 } |
| 103 #endif | |
| 104 } | 100 } |
| 105 | 101 |
| 106 int ImmutableStylePropertySet::findPropertyIndex(CSSPropertyID propertyID) const | 102 int ImmutableStylePropertySet::findPropertyIndex(CSSPropertyID propertyID) const |
| 107 { | 103 { |
| 108 // Convert here propertyID into an uint16_t to compare it with the metadata'
s m_propertyID to avoid | 104 // Convert here propertyID into an uint16_t to compare it with the metadata'
s m_propertyID to avoid |
| 109 // the compiler converting it to an int multiple times in the loop. | 105 // the compiler converting it to an int multiple times in the loop. |
| 110 uint16_t id = static_cast<uint16_t>(propertyID); | 106 uint16_t id = static_cast<uint16_t>(propertyID); |
| 111 for (int n = m_arraySize - 1 ; n >= 0; --n) { | 107 for (int n = m_arraySize - 1 ; n >= 0; --n) { |
| 112 if (metadataArray()[n].m_propertyID == id) { | 108 if (metadataArray()[n].m_propertyID == id) { |
| 113 // Only enabled properties should be part of the style. | 109 // Only enabled properties should be part of the style. |
| 114 ASSERT(CSSPropertyMetadata::isEnabledProperty(propertyID)); | 110 ASSERT(CSSPropertyMetadata::isEnabledProperty(propertyID)); |
| 115 return n; | 111 return n; |
| 116 } | 112 } |
| 117 } | 113 } |
| 118 | 114 |
| 119 return -1; | 115 return -1; |
| 120 } | 116 } |
| 121 | 117 |
| 122 DEFINE_TRACE_AFTER_DISPATCH(ImmutableStylePropertySet) | 118 DEFINE_TRACE_AFTER_DISPATCH(ImmutableStylePropertySet) |
| 123 { | 119 { |
| 124 const RawPtrWillBeMember<CSSValue>* values = valueArray(); | |
| 125 for (unsigned i = 0; i < m_arraySize; i++) | |
| 126 visitor->trace(values[i]); | |
| 127 StylePropertySet::traceAfterDispatch(visitor); | 120 StylePropertySet::traceAfterDispatch(visitor); |
| 128 } | 121 } |
| 129 | 122 |
| 130 MutableStylePropertySet::MutableStylePropertySet(const StylePropertySet& other) | 123 MutableStylePropertySet::MutableStylePropertySet(const StylePropertySet& other) |
| 131 : StylePropertySet(other.cssParserMode()) | 124 : StylePropertySet(other.cssParserMode()) |
| 132 { | 125 { |
| 133 if (other.isMutable()) { | 126 if (other.isMutable()) { |
| 134 m_propertyVector = toMutableStylePropertySet(other).m_propertyVector; | 127 m_propertyVector = toMutableStylePropertySet(other).m_propertyVector; |
| 135 } else { | 128 } else { |
| 136 m_propertyVector.reserveInitialCapacity(other.propertyCount()); | 129 m_propertyVector.reserveInitialCapacity(other.propertyCount()); |
| 137 for (unsigned i = 0; i < other.propertyCount(); ++i) | 130 for (unsigned i = 0; i < other.propertyCount(); ++i) |
| 138 m_propertyVector.uncheckedAppend(other.propertyAt(i).toCSSProperty()
); | 131 m_propertyVector.uncheckedAppend(other.propertyAt(i).toCSSProperty()
); |
| 139 } | 132 } |
| 140 } | 133 } |
| 141 | 134 |
| 142 String StylePropertySet::getPropertyValue(CSSPropertyID propertyID) const | 135 String StylePropertySet::getPropertyValue(CSSPropertyID propertyID) const |
| 143 { | 136 { |
| 144 RefPtrWillBeRawPtr<CSSValue> value = getPropertyCSSValue(propertyID); | 137 RefPtr<CSSValue> value = getPropertyCSSValue(propertyID); |
| 145 if (value) | 138 if (value) |
| 146 return value->cssText(); | 139 return value->cssText(); |
| 147 | 140 |
| 148 return StylePropertySerializer(*this).getPropertyValue(propertyID); | 141 return StylePropertySerializer(*this).getPropertyValue(propertyID); |
| 149 } | 142 } |
| 150 | 143 |
| 151 PassRefPtrWillBeRawPtr<CSSValue> StylePropertySet::getPropertyCSSValue(CSSProper
tyID propertyID) const | 144 PassRefPtr<CSSValue> StylePropertySet::getPropertyCSSValue(CSSPropertyID propert
yID) const |
| 152 { | 145 { |
| 153 int foundPropertyIndex = findPropertyIndex(propertyID); | 146 int foundPropertyIndex = findPropertyIndex(propertyID); |
| 154 if (foundPropertyIndex == -1) | 147 if (foundPropertyIndex == -1) |
| 155 return nullptr; | 148 return nullptr; |
| 156 return propertyAt(foundPropertyIndex).value(); | 149 return propertyAt(foundPropertyIndex).value(); |
| 157 } | 150 } |
| 158 | 151 |
| 159 DEFINE_TRACE(StylePropertySet) | 152 DEFINE_TRACE(StylePropertySet) |
| 160 { | 153 { |
| 161 if (m_isMutable) | 154 if (m_isMutable) |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 // Setting the value to an empty string just removes the property in both IE
and Gecko. | 240 // Setting the value to an empty string just removes the property in both IE
and Gecko. |
| 248 // Setting it to null seems to produce less consistent results, but we treat
it just the same. | 241 // Setting it to null seems to produce less consistent results, but we treat
it just the same. |
| 249 if (value.isEmpty()) | 242 if (value.isEmpty()) |
| 250 return removeProperty(resolveCSSPropertyID(unresolvedProperty)); | 243 return removeProperty(resolveCSSPropertyID(unresolvedProperty)); |
| 251 | 244 |
| 252 // When replacing an existing property value, this moves the property to the
end of the list. | 245 // When replacing an existing property value, this moves the property to the
end of the list. |
| 253 // Firefox preserves the position, and MSIE moves the property to the beginn
ing. | 246 // Firefox preserves the position, and MSIE moves the property to the beginn
ing. |
| 254 return CSSParser::parseValue(this, unresolvedProperty, value, important, css
ParserMode(), contextStyleSheet); | 247 return CSSParser::parseValue(this, unresolvedProperty, value, important, css
ParserMode(), contextStyleSheet); |
| 255 } | 248 } |
| 256 | 249 |
| 257 void MutableStylePropertySet::setProperty(CSSPropertyID propertyID, PassRefPtrWi
llBeRawPtr<CSSValue> prpValue, bool important) | 250 void MutableStylePropertySet::setProperty(CSSPropertyID propertyID, PassRefPtr<C
SSValue> prpValue, bool important) |
| 258 { | 251 { |
| 259 StylePropertyShorthand shorthand = shorthandForProperty(propertyID); | 252 StylePropertyShorthand shorthand = shorthandForProperty(propertyID); |
| 260 if (!shorthand.length()) { | 253 if (!shorthand.length()) { |
| 261 setProperty(CSSProperty(propertyID, prpValue, important)); | 254 setProperty(CSSProperty(propertyID, prpValue, important)); |
| 262 return; | 255 return; |
| 263 } | 256 } |
| 264 | 257 |
| 265 removePropertiesInSet(shorthand.properties(), shorthand.length()); | 258 removePropertiesInSet(shorthand.properties(), shorthand.length()); |
| 266 | 259 |
| 267 RefPtrWillBeRawPtr<CSSValue> value = prpValue; | 260 RefPtr<CSSValue> value = prpValue; |
| 268 for (unsigned i = 0; i < shorthand.length(); ++i) | 261 for (unsigned i = 0; i < shorthand.length(); ++i) |
| 269 m_propertyVector.append(CSSProperty(shorthand.properties()[i], value, im
portant)); | 262 m_propertyVector.append(CSSProperty(shorthand.properties()[i], value, im
portant)); |
| 270 } | 263 } |
| 271 | 264 |
| 272 bool MutableStylePropertySet::setProperty(const CSSProperty& property, CSSProper
ty* slot) | 265 bool MutableStylePropertySet::setProperty(const CSSProperty& property, CSSProper
ty* slot) |
| 273 { | 266 { |
| 274 if (!removeShorthandProperty(property.id())) { | 267 if (!removeShorthandProperty(property.id())) { |
| 275 CSSProperty* toReplace = slot ? slot : findCSSPropertyWithID(property.id
()); | 268 CSSProperty* toReplace = slot ? slot : findCSSPropertyWithID(property.id
()); |
| 276 if (toReplace && *toReplace == property) | 269 if (toReplace && *toReplace == property) |
| 277 return false; | 270 return false; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 296 | 289 |
| 297 CSSParserContext context(cssParserMode(), UseCounter::getFrom(contextStyleSh
eet)); | 290 CSSParserContext context(cssParserMode(), UseCounter::getFrom(contextStyleSh
eet)); |
| 298 if (contextStyleSheet) { | 291 if (contextStyleSheet) { |
| 299 context = contextStyleSheet->parserContext(); | 292 context = contextStyleSheet->parserContext(); |
| 300 context.setMode(cssParserMode()); | 293 context.setMode(cssParserMode()); |
| 301 } | 294 } |
| 302 | 295 |
| 303 CSSParser::parseDeclarationList(context, this, styleDeclaration); | 296 CSSParser::parseDeclarationList(context, this, styleDeclaration); |
| 304 } | 297 } |
| 305 | 298 |
| 306 bool MutableStylePropertySet::addParsedProperties(const WillBeHeapVector<CSSProp
erty, 256>& properties) | 299 bool MutableStylePropertySet::addParsedProperties(const Vector<CSSProperty, 256>
& properties) |
| 307 { | 300 { |
| 308 bool changed = false; | 301 bool changed = false; |
| 309 m_propertyVector.reserveCapacity(m_propertyVector.size() + properties.size()
); | 302 m_propertyVector.reserveCapacity(m_propertyVector.size() + properties.size()
); |
| 310 for (unsigned i = 0; i < properties.size(); ++i) | 303 for (unsigned i = 0; i < properties.size(); ++i) |
| 311 changed |= setProperty(properties[i]); | 304 changed |= setProperty(properties[i]); |
| 312 return changed; | 305 return changed; |
| 313 } | 306 } |
| 314 | 307 |
| 315 bool MutableStylePropertySet::addRespectingCascade(const CSSProperty& property) | 308 bool MutableStylePropertySet::addRespectingCascade(const CSSProperty& property) |
| 316 { | 309 { |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 428 removeProperty(propertiesToRemove[i]); | 421 removeProperty(propertiesToRemove[i]); |
| 429 } | 422 } |
| 430 | 423 |
| 431 PassRefPtrWillBeRawPtr<MutableStylePropertySet> StylePropertySet::mutableCopy()
const | 424 PassRefPtrWillBeRawPtr<MutableStylePropertySet> StylePropertySet::mutableCopy()
const |
| 432 { | 425 { |
| 433 return adoptRefWillBeNoop(new MutableStylePropertySet(*this)); | 426 return adoptRefWillBeNoop(new MutableStylePropertySet(*this)); |
| 434 } | 427 } |
| 435 | 428 |
| 436 PassRefPtrWillBeRawPtr<MutableStylePropertySet> StylePropertySet::copyProperties
InSet(const Vector<CSSPropertyID>& properties) const | 429 PassRefPtrWillBeRawPtr<MutableStylePropertySet> StylePropertySet::copyProperties
InSet(const Vector<CSSPropertyID>& properties) const |
| 437 { | 430 { |
| 438 WillBeHeapVector<CSSProperty, 256> list; | 431 Vector<CSSProperty, 256> list; |
| 439 list.reserveInitialCapacity(properties.size()); | 432 list.reserveInitialCapacity(properties.size()); |
| 440 for (unsigned i = 0; i < properties.size(); ++i) { | 433 for (unsigned i = 0; i < properties.size(); ++i) { |
| 441 RefPtrWillBeRawPtr<CSSValue> value = getPropertyCSSValue(properties[i]); | 434 RefPtr<CSSValue> value = getPropertyCSSValue(properties[i]); |
| 442 if (value) | 435 if (value) |
| 443 list.append(CSSProperty(properties[i], value.release(), false)); | 436 list.append(CSSProperty(properties[i], value.release(), false)); |
| 444 } | 437 } |
| 445 return MutableStylePropertySet::create(list.data(), list.size()); | 438 return MutableStylePropertySet::create(list.data(), list.size()); |
| 446 } | 439 } |
| 447 | 440 |
| 448 CSSStyleDeclaration* MutableStylePropertySet::ensureCSSStyleDeclaration() | 441 CSSStyleDeclaration* MutableStylePropertySet::ensureCSSStyleDeclaration() |
| 449 { | 442 { |
| 450 // FIXME: get rid of this weirdness of a CSSStyleDeclaration inside of a | 443 // FIXME: get rid of this weirdness of a CSSStyleDeclaration inside of a |
| 451 // style property set. | 444 // style property set. |
| (...skipping 25 matching lines...) Expand all Loading... |
| 477 | 470 |
| 478 const CSSProperty* it = std::find_if(begin, end, compare); | 471 const CSSProperty* it = std::find_if(begin, end, compare); |
| 479 | 472 |
| 480 return (it == end) ? -1 : it - begin; | 473 return (it == end) ? -1 : it - begin; |
| 481 } | 474 } |
| 482 | 475 |
| 483 DEFINE_TRACE_AFTER_DISPATCH(MutableStylePropertySet) | 476 DEFINE_TRACE_AFTER_DISPATCH(MutableStylePropertySet) |
| 484 { | 477 { |
| 485 #if ENABLE(OILPAN) | 478 #if ENABLE(OILPAN) |
| 486 visitor->trace(m_cssomWrapper); | 479 visitor->trace(m_cssomWrapper); |
| 487 visitor->trace(m_propertyVector); | |
| 488 #endif | 480 #endif |
| 489 StylePropertySet::traceAfterDispatch(visitor); | 481 StylePropertySet::traceAfterDispatch(visitor); |
| 490 } | 482 } |
| 491 | 483 |
| 492 unsigned StylePropertySet::averageSizeInBytes() | 484 unsigned StylePropertySet::averageSizeInBytes() |
| 493 { | 485 { |
| 494 // Please update this if the storage scheme changes so that this longer refl
ects the actual size. | 486 // Please update this if the storage scheme changes so that this longer refl
ects the actual size. |
| 495 return sizeForImmutableStylePropertySetWithPropertyCount(4); | 487 return sizeForImmutableStylePropertySetWithPropertyCount(4); |
| 496 } | 488 } |
| 497 | 489 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 512 { | 504 { |
| 513 return adoptRefWillBeNoop(new MutableStylePropertySet(cssParserMode)); | 505 return adoptRefWillBeNoop(new MutableStylePropertySet(cssParserMode)); |
| 514 } | 506 } |
| 515 | 507 |
| 516 PassRefPtrWillBeRawPtr<MutableStylePropertySet> MutableStylePropertySet::create(
const CSSProperty* properties, unsigned count) | 508 PassRefPtrWillBeRawPtr<MutableStylePropertySet> MutableStylePropertySet::create(
const CSSProperty* properties, unsigned count) |
| 517 { | 509 { |
| 518 return adoptRefWillBeNoop(new MutableStylePropertySet(properties, count)); | 510 return adoptRefWillBeNoop(new MutableStylePropertySet(properties, count)); |
| 519 } | 511 } |
| 520 | 512 |
| 521 } // namespace blink | 513 } // namespace blink |
| OLD | NEW |