| 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. |
| 4 * All rights reserved. |
| 4 * Copyright (C) 2011 Research In Motion Limited. All rights reserved. | 5 * Copyright (C) 2011 Research In Motion Limited. All rights reserved. |
| 5 * Copyright (C) 2013 Intel Corporation. All rights reserved. | 6 * Copyright (C) 2013 Intel Corporation. All rights reserved. |
| 6 * | 7 * |
| 7 * This library is free software; you can redistribute it and/or | 8 * This library is free software; you can redistribute it and/or |
| 8 * modify it under the terms of the GNU Library General Public | 9 * modify it under the terms of the GNU Library General Public |
| 9 * License as published by the Free Software Foundation; either | 10 * License as published by the Free Software Foundation; either |
| 10 * version 2 of the License, or (at your option) any later version. | 11 * version 2 of the License, or (at your option) any later version. |
| 11 * | 12 * |
| 12 * This library is distributed in the hope that it will be useful, | 13 * This library is distributed in the hope that it will be useful, |
| 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 Member<const CSSValue>* valueArray = | 88 Member<const CSSValue>* valueArray = |
| 88 const_cast<Member<const CSSValue>*>(this->valueArray()); | 89 const_cast<Member<const CSSValue>*>(this->valueArray()); |
| 89 for (unsigned i = 0; i < m_arraySize; ++i) { | 90 for (unsigned i = 0; i < m_arraySize; ++i) { |
| 90 metadataArray[i] = properties[i].metadata(); | 91 metadataArray[i] = properties[i].metadata(); |
| 91 valueArray[i] = properties[i].value(); | 92 valueArray[i] = properties[i].value(); |
| 92 } | 93 } |
| 93 } | 94 } |
| 94 | 95 |
| 95 ImmutableStylePropertySet::~ImmutableStylePropertySet() {} | 96 ImmutableStylePropertySet::~ImmutableStylePropertySet() {} |
| 96 | 97 |
| 97 // Convert property into an uint16_t for comparison with metadata's m_propertyID
to avoid | 98 // Convert property into an uint16_t for comparison with metadata's m_propertyID |
| 98 // the compiler converting it to an int multiple times in a loop. | 99 // to avoid the compiler converting it to an int multiple times in a loop. |
| 99 static uint16_t getConvertedCSSPropertyID(CSSPropertyID propertyID) { | 100 static uint16_t getConvertedCSSPropertyID(CSSPropertyID propertyID) { |
| 100 return static_cast<uint16_t>(propertyID); | 101 return static_cast<uint16_t>(propertyID); |
| 101 } | 102 } |
| 102 | 103 |
| 103 static uint16_t getConvertedCSSPropertyID(const AtomicString&) { | 104 static uint16_t getConvertedCSSPropertyID(const AtomicString&) { |
| 104 return static_cast<uint16_t>(CSSPropertyVariable); | 105 return static_cast<uint16_t>(CSSPropertyVariable); |
| 105 } | 106 } |
| 106 | 107 |
| 107 static bool isPropertyMatch(const StylePropertyMetadata& metadata, | 108 static bool isPropertyMatch(const StylePropertyMetadata& metadata, |
| 108 const CSSValue&, | 109 const CSSValue&, |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 return propertyAt(foundPropertyIndex).isImplicit(); | 296 return propertyAt(foundPropertyIndex).isImplicit(); |
| 296 } | 297 } |
| 297 | 298 |
| 298 bool MutableStylePropertySet::setProperty( | 299 bool MutableStylePropertySet::setProperty( |
| 299 CSSPropertyID unresolvedProperty, | 300 CSSPropertyID unresolvedProperty, |
| 300 const String& value, | 301 const String& value, |
| 301 bool important, | 302 bool important, |
| 302 StyleSheetContents* contextStyleSheet) { | 303 StyleSheetContents* contextStyleSheet) { |
| 303 DCHECK_GE(unresolvedProperty, firstCSSProperty); | 304 DCHECK_GE(unresolvedProperty, firstCSSProperty); |
| 304 | 305 |
| 305 // Setting the value to an empty string just removes the property in both IE a
nd Gecko. | 306 // Setting the value to an empty string just removes the property in both IE |
| 306 // Setting it to null seems to produce less consistent results, but we treat i
t just the same. | 307 // and Gecko. Setting it to null seems to produce less consistent results, but |
| 308 // we treat it just the same. |
| 307 if (value.isEmpty()) | 309 if (value.isEmpty()) |
| 308 return removeProperty(resolveCSSPropertyID(unresolvedProperty)); | 310 return removeProperty(resolveCSSPropertyID(unresolvedProperty)); |
| 309 | 311 |
| 310 // When replacing an existing property value, this moves the property to the e
nd of the list. | 312 // When replacing an existing property value, this moves the property to the |
| 311 // Firefox preserves the position, and MSIE moves the property to the beginnin
g. | 313 // end of the list. Firefox preserves the position, and MSIE moves the |
| 314 // property to the beginning. |
| 312 return CSSParser::parseValue(this, unresolvedProperty, value, important, | 315 return CSSParser::parseValue(this, unresolvedProperty, value, important, |
| 313 contextStyleSheet); | 316 contextStyleSheet); |
| 314 } | 317 } |
| 315 | 318 |
| 316 bool MutableStylePropertySet::setProperty( | 319 bool MutableStylePropertySet::setProperty( |
| 317 const AtomicString& customPropertyName, | 320 const AtomicString& customPropertyName, |
| 318 const String& value, | 321 const String& value, |
| 319 bool important, | 322 bool important, |
| 320 StyleSheetContents* contextStyleSheet) { | 323 StyleSheetContents* contextStyleSheet) { |
| 321 if (value.isEmpty()) | 324 if (value.isEmpty()) |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 446 if (m_propertyVector.isEmpty()) | 449 if (m_propertyVector.isEmpty()) |
| 447 return false; | 450 return false; |
| 448 | 451 |
| 449 CSSProperty* properties = m_propertyVector.data(); | 452 CSSProperty* properties = m_propertyVector.data(); |
| 450 unsigned oldSize = m_propertyVector.size(); | 453 unsigned oldSize = m_propertyVector.size(); |
| 451 unsigned newIndex = 0; | 454 unsigned newIndex = 0; |
| 452 for (unsigned oldIndex = 0; oldIndex < oldSize; ++oldIndex) { | 455 for (unsigned oldIndex = 0; oldIndex < oldSize; ++oldIndex) { |
| 453 const CSSProperty& property = properties[oldIndex]; | 456 const CSSProperty& property = properties[oldIndex]; |
| 454 if (containsId(set, length, property.id())) | 457 if (containsId(set, length, property.id())) |
| 455 continue; | 458 continue; |
| 456 // Modify m_propertyVector in-place since this method is performance-sensiti
ve. | 459 // Modify m_propertyVector in-place since this method is |
| 460 // performance-sensitive. |
| 457 properties[newIndex++] = properties[oldIndex]; | 461 properties[newIndex++] = properties[oldIndex]; |
| 458 } | 462 } |
| 459 if (newIndex != oldSize) { | 463 if (newIndex != oldSize) { |
| 460 m_propertyVector.shrink(newIndex); | 464 m_propertyVector.shrink(newIndex); |
| 461 return true; | 465 return true; |
| 462 } | 466 } |
| 463 return false; | 467 return false; |
| 464 } | 468 } |
| 465 | 469 |
| 466 CSSProperty* MutableStylePropertySet::findCSSPropertyWithID( | 470 CSSProperty* MutableStylePropertySet::findCSSPropertyWithID( |
| 467 CSSPropertyID propertyID, | 471 CSSPropertyID propertyID, |
| 468 const AtomicString& customPropertyName) { | 472 const AtomicString& customPropertyName) { |
| 469 int foundPropertyIndex = -1; | 473 int foundPropertyIndex = -1; |
| 470 if (propertyID == CSSPropertyVariable && !customPropertyName.isNull()) { | 474 if (propertyID == CSSPropertyVariable && !customPropertyName.isNull()) { |
| 471 // TODO(shanestephens): fix call sites so we always have a customPropertyNam
e | 475 // TODO(shanestephens): fix call sites so we always have a |
| 472 // here. | 476 // customPropertyName here. |
| 473 foundPropertyIndex = findPropertyIndex(customPropertyName); | 477 foundPropertyIndex = findPropertyIndex(customPropertyName); |
| 474 } else { | 478 } else { |
| 475 ASSERT(customPropertyName.isNull()); | 479 ASSERT(customPropertyName.isNull()); |
| 476 foundPropertyIndex = findPropertyIndex(propertyID); | 480 foundPropertyIndex = findPropertyIndex(propertyID); |
| 477 } | 481 } |
| 478 if (foundPropertyIndex == -1) | 482 if (foundPropertyIndex == -1) |
| 479 return nullptr; | 483 return nullptr; |
| 480 return &m_propertyVector.at(foundPropertyIndex); | 484 return &m_propertyVector.at(foundPropertyIndex); |
| 481 } | 485 } |
| 482 | 486 |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 565 template CORE_EXPORT int MutableStylePropertySet::findPropertyIndex( | 569 template CORE_EXPORT int MutableStylePropertySet::findPropertyIndex( |
| 566 AtomicString) const; | 570 AtomicString) const; |
| 567 | 571 |
| 568 DEFINE_TRACE_AFTER_DISPATCH(MutableStylePropertySet) { | 572 DEFINE_TRACE_AFTER_DISPATCH(MutableStylePropertySet) { |
| 569 visitor->trace(m_cssomWrapper); | 573 visitor->trace(m_cssomWrapper); |
| 570 visitor->trace(m_propertyVector); | 574 visitor->trace(m_propertyVector); |
| 571 StylePropertySet::traceAfterDispatch(visitor); | 575 StylePropertySet::traceAfterDispatch(visitor); |
| 572 } | 576 } |
| 573 | 577 |
| 574 unsigned StylePropertySet::averageSizeInBytes() { | 578 unsigned StylePropertySet::averageSizeInBytes() { |
| 575 // Please update this if the storage scheme changes so that this longer reflec
ts the actual size. | 579 // Please update this if the storage scheme changes so that this longer |
| 580 // reflects the actual size. |
| 576 return sizeForImmutableStylePropertySetWithPropertyCount(4); | 581 return sizeForImmutableStylePropertySetWithPropertyCount(4); |
| 577 } | 582 } |
| 578 | 583 |
| 579 // See the function above if you need to update this. | 584 // See the function above if you need to update this. |
| 580 struct SameSizeAsStylePropertySet | 585 struct SameSizeAsStylePropertySet |
| 581 : public GarbageCollectedFinalized<SameSizeAsStylePropertySet> { | 586 : public GarbageCollectedFinalized<SameSizeAsStylePropertySet> { |
| 582 unsigned bitfield; | 587 unsigned bitfield; |
| 583 }; | 588 }; |
| 584 static_assert(sizeof(StylePropertySet) == sizeof(SameSizeAsStylePropertySet), | 589 static_assert(sizeof(StylePropertySet) == sizeof(SameSizeAsStylePropertySet), |
| 585 "StylePropertySet should stay small"); | 590 "StylePropertySet should stay small"); |
| 586 | 591 |
| 587 #ifndef NDEBUG | 592 #ifndef NDEBUG |
| 588 void StylePropertySet::showStyle() { | 593 void StylePropertySet::showStyle() { |
| 589 fprintf(stderr, "%s\n", asText().ascii().data()); | 594 fprintf(stderr, "%s\n", asText().ascii().data()); |
| 590 } | 595 } |
| 591 #endif | 596 #endif |
| 592 | 597 |
| 593 MutableStylePropertySet* MutableStylePropertySet::create( | 598 MutableStylePropertySet* MutableStylePropertySet::create( |
| 594 CSSParserMode cssParserMode) { | 599 CSSParserMode cssParserMode) { |
| 595 return new MutableStylePropertySet(cssParserMode); | 600 return new MutableStylePropertySet(cssParserMode); |
| 596 } | 601 } |
| 597 | 602 |
| 598 MutableStylePropertySet* MutableStylePropertySet::create( | 603 MutableStylePropertySet* MutableStylePropertySet::create( |
| 599 const CSSProperty* properties, | 604 const CSSProperty* properties, |
| 600 unsigned count) { | 605 unsigned count) { |
| 601 return new MutableStylePropertySet(properties, count); | 606 return new MutableStylePropertySet(properties, count); |
| 602 } | 607 } |
| 603 | 608 |
| 604 } // namespace blink | 609 } // namespace blink |
| OLD | NEW |