summaryrefslogtreecommitdiffstats
path: root/chromium/third_party/WebKit/Source/core/css/StylePropertySet.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/third_party/WebKit/Source/core/css/StylePropertySet.cpp')
-rw-r--r--chromium/third_party/WebKit/Source/core/css/StylePropertySet.cpp318
1 files changed, 111 insertions, 207 deletions
diff --git a/chromium/third_party/WebKit/Source/core/css/StylePropertySet.cpp b/chromium/third_party/WebKit/Source/core/css/StylePropertySet.cpp
index c7e0ae63811..2581c01e911 100644
--- a/chromium/third_party/WebKit/Source/core/css/StylePropertySet.cpp
+++ b/chromium/third_party/WebKit/Source/core/css/StylePropertySet.cpp
@@ -23,14 +23,14 @@
#include "config.h"
#include "core/css/StylePropertySet.h"
-#include "RuntimeEnabledFeatures.h"
-#include "StylePropertyShorthand.h"
-#include "core/css/CSSParser.h"
+#include "core/StylePropertyShorthand.h"
+#include "core/css/parser/BisonCSSParser.h"
#include "core/css/CSSValuePool.h"
-#include "core/css/CSSVariableValue.h"
#include "core/css/RuntimeCSSEnabled.h"
#include "core/css/StylePropertySerializer.h"
#include "core/css/StyleSheetContents.h"
+#include "core/frame/UseCounter.h"
+#include "platform/RuntimeEnabledFeatures.h"
#include "wtf/text/StringBuilder.h"
#ifndef NDEBUG
@@ -38,8 +38,6 @@
#include <stdio.h>
#endif
-using namespace std;
-
namespace WebCore {
static size_t sizeForImmutableStylePropertySetWithPropertyCount(unsigned count)
@@ -50,8 +48,12 @@ static size_t sizeForImmutableStylePropertySetWithPropertyCount(unsigned count)
PassRefPtr<ImmutableStylePropertySet> ImmutableStylePropertySet::create(const CSSProperty* properties, unsigned count, CSSParserMode cssParserMode)
{
ASSERT(count <= MaxArraySize);
+#if ENABLE(OILPAN)
+ void* slot = Heap::allocate<StylePropertySet>(sizeForImmutableStylePropertySetWithPropertyCount(count));
+#else
void* slot = WTF::fastMalloc(sizeForImmutableStylePropertySetWithPropertyCount(count));
- return adoptRef(new (slot) ImmutableStylePropertySet(properties, count, cssParserMode));
+#endif // ENABLE(OILPAN)
+ return adoptRefWillBeRefCountedGarbageCollected(new (slot) ImmutableStylePropertySet(properties, count, cssParserMode));
}
PassRefPtr<ImmutableStylePropertySet> StylePropertySet::immutableCopyIfNeeded() const
@@ -79,19 +81,47 @@ ImmutableStylePropertySet::ImmutableStylePropertySet(const CSSProperty* properti
: StylePropertySet(cssParserMode, length)
{
StylePropertyMetadata* metadataArray = const_cast<StylePropertyMetadata*>(this->metadataArray());
- CSSValue** valueArray = const_cast<CSSValue**>(this->valueArray());
+ RawPtrWillBeMember<CSSValue>* valueArray = const_cast<RawPtrWillBeMember<CSSValue>*>(this->valueArray());
for (unsigned i = 0; i < m_arraySize; ++i) {
metadataArray[i] = properties[i].metadata();
valueArray[i] = properties[i].value();
+#if !ENABLE(OILPAN)
valueArray[i]->ref();
+#endif
}
}
ImmutableStylePropertySet::~ImmutableStylePropertySet()
{
- CSSValue** valueArray = const_cast<CSSValue**>(this->valueArray());
+#if !ENABLE(OILPAN)
+ RawPtrWillBeMember<CSSValue>* valueArray = const_cast<RawPtrWillBeMember<CSSValue>*>(this->valueArray());
for (unsigned i = 0; i < m_arraySize; ++i)
valueArray[i]->deref();
+#endif
+}
+
+int ImmutableStylePropertySet::findPropertyIndex(CSSPropertyID propertyID) const
+{
+ // Convert here propertyID into an uint16_t to compare it with the metadata's m_propertyID to avoid
+ // the compiler converting it to an int multiple times in the loop.
+ uint16_t id = static_cast<uint16_t>(propertyID);
+ for (int n = m_arraySize - 1 ; n >= 0; --n) {
+ if (metadataArray()[n].m_propertyID == id) {
+ // Only enabled or internal properties should be part of the style.
+ ASSERT(RuntimeCSSEnabled::isCSSPropertyEnabled(propertyID) || isInternalProperty(propertyID));
+ return n;
+ }
+ }
+
+ return -1;
+}
+
+void ImmutableStylePropertySet::traceAfterDispatch(Visitor* visitor)
+{
+ const RawPtrWillBeMember<CSSValue>* values = valueArray();
+ for (unsigned i = 0; i < m_arraySize; i++)
+ visitor->trace(values[i]);
+ StylePropertySet::traceAfterDispatch(visitor);
}
MutableStylePropertySet::MutableStylePropertySet(const StylePropertySet& other)
@@ -108,40 +138,38 @@ MutableStylePropertySet::MutableStylePropertySet(const StylePropertySet& other)
String StylePropertySet::getPropertyValue(CSSPropertyID propertyID) const
{
- RefPtr<CSSValue> value = getPropertyCSSValue(propertyID);
+ RefPtrWillBeRawPtr<CSSValue> value = getPropertyCSSValue(propertyID);
if (value)
return value->cssText();
return StylePropertySerializer(*this).getPropertyValue(propertyID);
}
-PassRefPtr<CSSValue> StylePropertySet::getPropertyCSSValue(CSSPropertyID propertyID) const
+PassRefPtrWillBeRawPtr<CSSValue> StylePropertySet::getPropertyCSSValue(CSSPropertyID propertyID) const
{
int foundPropertyIndex = findPropertyIndex(propertyID);
if (foundPropertyIndex == -1)
- return 0;
+ return nullptr;
return propertyAt(foundPropertyIndex).value();
}
-unsigned StylePropertySet::variableCount() const
+void StylePropertySet::trace(Visitor* visitor)
{
- ASSERT(RuntimeEnabledFeatures::cssVariablesEnabled());
- unsigned count = 0;
- for (unsigned i = 0; i < propertyCount(); ++i) {
- if (propertyAt(i).id() == CSSPropertyVariable)
- count++;
- }
- return count;
+ if (m_isMutable)
+ toMutableStylePropertySet(this)->traceAfterDispatch(visitor);
+ else
+ toImmutableStylePropertySet(this)->traceAfterDispatch(visitor);
}
-String StylePropertySet::variableValue(const AtomicString& name) const
+#if ENABLE(OILPAN)
+void StylePropertySet::finalizeGarbageCollectedObject()
{
- ASSERT(RuntimeEnabledFeatures::cssVariablesEnabled());
- size_t index = findVariableIndex(name);
- if (index == kNotFound)
- return String();
- return toCSSVariableValue(propertyAt(index).value())->value();
+ if (m_isMutable)
+ toMutableStylePropertySet(this)->~MutableStylePropertySet();
+ else
+ toImmutableStylePropertySet(this)->~ImmutableStylePropertySet();
}
+#endif
bool MutableStylePropertySet::removeShorthandProperty(CSSPropertyID propertyID)
{
@@ -237,10 +265,10 @@ bool MutableStylePropertySet::setProperty(CSSPropertyID propertyID, const String
// When replacing an existing property value, this moves the property to the end of the list.
// Firefox preserves the position, and MSIE moves the property to the beginning.
- return CSSParser::parseValue(this, propertyID, value, important, cssParserMode(), contextStyleSheet);
+ return BisonCSSParser::parseValue(this, propertyID, value, important, cssParserMode(), contextStyleSheet);
}
-void MutableStylePropertySet::setProperty(CSSPropertyID propertyID, PassRefPtr<CSSValue> prpValue, bool important)
+void MutableStylePropertySet::setProperty(CSSPropertyID propertyID, PassRefPtrWillBeRawPtr<CSSValue> prpValue, bool important)
{
StylePropertyShorthand shorthand = shorthandForProperty(propertyID);
if (!shorthand.length()) {
@@ -250,7 +278,7 @@ void MutableStylePropertySet::setProperty(CSSPropertyID propertyID, PassRefPtr<C
removePropertiesInSet(shorthand.properties(), shorthand.length());
- RefPtr<CSSValue> value = prpValue;
+ RefPtrWillBeRawPtr<CSSValue> value = prpValue;
for (unsigned i = 0; i < shorthand.length(); ++i)
m_propertyVector.append(CSSProperty(shorthand.properties()[i], value, important));
}
@@ -279,28 +307,6 @@ unsigned getIndexInShorthandVectorForPrefixingVariant(const CSSProperty& propert
return indexOfShorthandForLonghand(prefixedShorthand, shorthands);
}
-bool MutableStylePropertySet::setVariableValue(const AtomicString& name, const String& value, bool important)
-{
- ASSERT(RuntimeEnabledFeatures::cssVariablesEnabled());
- if (value.isEmpty())
- return removeVariable(name);
-
- size_t index = findVariableIndex(name);
- if (index != kNotFound) {
- const CSSValue* cssValue = m_propertyVector.at(index).value();
- if (toCSSVariableValue(cssValue)->value() == value)
- return false;
- }
-
- CSSProperty property(CSSPropertyVariable, CSSVariableValue::create(name, value), important);
- if (index == kNotFound) {
- m_propertyVector.append(property);
- return true;
- }
- m_propertyVector.at(index) = property;
- return false;
-}
-
void MutableStylePropertySet::appendPrefixingVariantProperty(const CSSProperty& property)
{
m_propertyVector.append(property);
@@ -335,17 +341,17 @@ void MutableStylePropertySet::parseDeclaration(const String& styleDeclaration, S
{
m_propertyVector.clear();
- CSSParserContext context(cssParserMode());
+ CSSParserContext context(cssParserMode(), UseCounter::getFrom(contextStyleSheet));
if (contextStyleSheet) {
context = contextStyleSheet->parserContext();
context.setMode(cssParserMode());
}
- CSSParser parser(context, UseCounter::getFrom(contextStyleSheet));
+ BisonCSSParser parser(context);
parser.parseDeclaration(this, styleDeclaration, 0, contextStyleSheet);
}
-void MutableStylePropertySet::addParsedProperties(const Vector<CSSProperty, 256>& properties)
+void MutableStylePropertySet::addParsedProperties(const WillBeHeapVector<CSSProperty, 256>& properties)
{
m_propertyVector.reserveCapacity(m_propertyVector.size() + properties.size());
for (unsigned i = 0; i < properties.size(); ++i)
@@ -364,11 +370,6 @@ String StylePropertySet::asText() const
return StylePropertySerializer(*this).asText();
}
-bool StylePropertySet::hasCSSOMWrapper() const
-{
- return m_isMutable && toMutableStylePropertySet(this)->m_cssomWrapper;
-}
-
void MutableStylePropertySet::mergeAndOverrideOnConflict(const StylePropertySet* other)
{
unsigned size = other->propertyCount();
@@ -382,13 +383,6 @@ void MutableStylePropertySet::mergeAndOverrideOnConflict(const StylePropertySet*
}
}
-void StylePropertySet::addSubresourceStyleURLs(ListHashSet<KURL>& urls, StyleSheetContents* contextStyleSheet) const
-{
- unsigned size = propertyCount();
- for (unsigned i = 0; i < size; ++i)
- propertyAt(i).value()->addSubresourceStyleURLs(urls, contextStyleSheet);
-}
-
bool StylePropertySet::hasFailedOrCanceledSubresources() const
{
unsigned size = propertyCount();
@@ -417,9 +411,6 @@ static const CSSPropertyID staticBlockProperties[] = {
CSSPropertyPageBreakAfter,
CSSPropertyPageBreakBefore,
CSSPropertyPageBreakInside,
- CSSPropertyWebkitRegionBreakAfter,
- CSSPropertyWebkitRegionBreakBefore,
- CSSPropertyWebkitRegionBreakInside,
CSSPropertyTextAlign,
CSSPropertyTextAlignLast,
CSSPropertyTextIndent,
@@ -440,7 +431,7 @@ void MutableStylePropertySet::clear()
m_propertyVector.clear();
}
-PassRefPtr<MutableStylePropertySet> StylePropertySet::copyBlockProperties() const
+PassRefPtrWillBeRawPtr<MutableStylePropertySet> StylePropertySet::copyBlockProperties() const
{
return copyPropertiesInSet(blockProperties());
}
@@ -450,59 +441,35 @@ void MutableStylePropertySet::removeBlockProperties()
removePropertiesInSet(blockProperties().data(), blockProperties().size());
}
+inline bool containsId(const CSSPropertyID* set, unsigned length, CSSPropertyID id)
+{
+ for (unsigned i = 0; i < length; ++i) {
+ if (set[i] == id)
+ return true;
+ }
+ return false;
+}
+
bool MutableStylePropertySet::removePropertiesInSet(const CSSPropertyID* set, unsigned length)
{
if (m_propertyVector.isEmpty())
return false;
- // FIXME: This is always used with static sets and in that case constructing the hash repeatedly is pretty pointless.
- HashSet<CSSPropertyID> toRemove;
- for (unsigned i = 0; i < length; ++i)
- toRemove.add(set[i]);
-
- Vector<CSSProperty> newProperties;
+ WillBeHeapVector<CSSProperty> newProperties;
newProperties.reserveInitialCapacity(m_propertyVector.size());
- unsigned size = m_propertyVector.size();
- for (unsigned n = 0; n < size; ++n) {
- const CSSProperty& property = m_propertyVector.at(n);
+ unsigned initialSize = m_propertyVector.size();
+ const CSSProperty* properties = m_propertyVector.data();
+ for (unsigned n = 0; n < initialSize; ++n) {
+ const CSSProperty& property = properties[n];
// Not quite sure if the isImportant test is needed but it matches the existing behavior.
- if (!property.isImportant()) {
- if (toRemove.contains(property.id()))
- continue;
- }
+ if (!property.isImportant() && containsId(set, length, property.id()))
+ continue;
newProperties.append(property);
}
- bool changed = newProperties.size() != m_propertyVector.size();
m_propertyVector = newProperties;
- return changed;
-}
-
-int StylePropertySet::findPropertyIndex(CSSPropertyID propertyID) const
-{
- // Convert here propertyID into an uint16_t to compare it with the metadata's m_propertyID to avoid
- // the compiler converting it to an int multiple times in the loop.
- uint16_t id = static_cast<uint16_t>(propertyID);
- for (int n = propertyCount() - 1 ; n >= 0; --n) {
- if (id == propertyAt(n).propertyMetadata().m_propertyID) {
- // Only enabled or internal properties should be part of the style.
- ASSERT(RuntimeCSSEnabled::isCSSPropertyEnabled(propertyID) || isInternalProperty(propertyID));
- return n;
- }
- }
- return -1;
-}
-
-size_t StylePropertySet::findVariableIndex(const AtomicString& name) const
-{
- ASSERT(RuntimeEnabledFeatures::cssVariablesEnabled());
- for (int i = propertyCount() - 1; i >= 0; --i) {
- const PropertyReference& property = propertyAt(i);
- if (property.id() == CSSPropertyVariable && toCSSVariableValue(property.value())->name() == name)
- return i;
- }
- return kNotFound;
+ return initialSize != m_propertyVector.size();
}
CSSProperty* MutableStylePropertySet::findCSSPropertyWithID(CSSPropertyID propertyID)
@@ -549,116 +516,58 @@ void MutableStylePropertySet::removeEquivalentProperties(const CSSStyleDeclarati
removeProperty(propertiesToRemove[i]);
}
-bool MutableStylePropertySet::removeVariable(const AtomicString& name)
-{
- ASSERT(RuntimeEnabledFeatures::cssVariablesEnabled());
- size_t index = findVariableIndex(name);
- if (index == kNotFound)
- return false;
- m_propertyVector.remove(index);
- return true;
-}
-
-bool MutableStylePropertySet::clearVariables()
-{
- ASSERT(RuntimeEnabledFeatures::cssVariablesEnabled());
- CSSPropertyID variablesId = CSSPropertyVariable;
- return removePropertiesInSet(&variablesId, 1);
-}
-
-PassRefPtr<MutableStylePropertySet::VariablesIterator> MutableStylePropertySet::VariablesIterator::create(MutableStylePropertySet* propertySet)
-{
- ASSERT(RuntimeEnabledFeatures::cssVariablesEnabled());
- const size_t propertyCount = propertySet->propertyCount();
- size_t variableCount = 0;
- Vector<AtomicString> remainingNames(propertyCount);
- for (int i = propertyCount; i--; ) {
- const PropertyReference& property = propertySet->propertyAt(i);
- if (property.id() == CSSPropertyVariable)
- remainingNames[variableCount++] = toCSSVariableValue(property.value())->name();
- }
- remainingNames.shrink(variableCount);
-
- RefPtr<VariablesIterator> iterator = adoptRef(new VariablesIterator(propertySet));
- // FIXME: Make use of the Vector move constructor when rvalues are supported on all platforms.
- iterator->takeRemainingNames(remainingNames);
- return iterator.release();
-}
-
-void MutableStylePropertySet::VariablesIterator::addedVariable(const AtomicString& name)
-{
- ASSERT(!m_remainingNames.contains(name));
- ASSERT(!m_newNames.contains(name));
- m_newNames.append(name);
-}
-
-void MutableStylePropertySet::VariablesIterator::removedVariable(const AtomicString& name)
-{
- size_t index = m_remainingNames.find(name);
- if (index != kNotFound)
- m_remainingNames.remove(index);
- index = m_newNames.find(name);
- if (index != kNotFound)
- m_newNames.remove(index);
-}
-
-void MutableStylePropertySet::VariablesIterator::clearedVariables()
-{
- m_remainingNames.clear();
- m_newNames.clear();
-}
-
-void MutableStylePropertySet::VariablesIterator::advance()
-{
- if (!atEnd())
- m_remainingNames.removeLast();
- if (!m_newNames.isEmpty()) {
- m_remainingNames.appendVector(m_newNames);
- m_newNames.clear();
- }
-}
-
-PassRefPtr<MutableStylePropertySet> StylePropertySet::mutableCopy() const
+PassRefPtrWillBeRawPtr<MutableStylePropertySet> StylePropertySet::mutableCopy() const
{
- return adoptRef(new MutableStylePropertySet(*this));
+ return adoptRefWillBeRefCountedGarbageCollected(new MutableStylePropertySet(*this));
}
-PassRefPtr<MutableStylePropertySet> StylePropertySet::copyPropertiesInSet(const Vector<CSSPropertyID>& properties) const
+PassRefPtrWillBeRawPtr<MutableStylePropertySet> StylePropertySet::copyPropertiesInSet(const Vector<CSSPropertyID>& properties) const
{
- Vector<CSSProperty, 256> list;
+ WillBeHeapVector<CSSProperty, 256> list;
list.reserveInitialCapacity(properties.size());
for (unsigned i = 0; i < properties.size(); ++i) {
- RefPtr<CSSValue> value = getPropertyCSSValue(properties[i]);
+ RefPtrWillBeRawPtr<CSSValue> value = getPropertyCSSValue(properties[i]);
if (value)
list.append(CSSProperty(properties[i], value.release(), false));
}
return MutableStylePropertySet::create(list.data(), list.size());
}
-PropertySetCSSStyleDeclaration* MutableStylePropertySet::cssStyleDeclaration()
-{
- return m_cssomWrapper.get();
-}
-
CSSStyleDeclaration* MutableStylePropertySet::ensureCSSStyleDeclaration()
{
+ // FIXME: get rid of this weirdness of a CSSStyleDeclaration inside of a
+ // style property set.
if (m_cssomWrapper) {
ASSERT(!static_cast<CSSStyleDeclaration*>(m_cssomWrapper.get())->parentRule());
ASSERT(!m_cssomWrapper->parentElement());
return m_cssomWrapper.get();
}
- m_cssomWrapper = adoptPtr(new PropertySetCSSStyleDeclaration(this));
+ m_cssomWrapper = adoptPtrWillBeNoop(new PropertySetCSSStyleDeclaration(*this));
return m_cssomWrapper.get();
}
-CSSStyleDeclaration* MutableStylePropertySet::ensureInlineCSSStyleDeclaration(Element* parentElement)
+int MutableStylePropertySet::findPropertyIndex(CSSPropertyID propertyID) const
{
- if (m_cssomWrapper) {
- ASSERT(m_cssomWrapper->parentElement() == parentElement);
- return m_cssomWrapper.get();
+ // Convert here propertyID into an uint16_t to compare it with the metadata's m_propertyID to avoid
+ // the compiler converting it to an int multiple times in the loop.
+ uint16_t id = static_cast<uint16_t>(propertyID);
+ const CSSProperty* properties = m_propertyVector.data();
+ for (int n = m_propertyVector.size() - 1 ; n >= 0; --n) {
+ if (properties[n].metadata().m_propertyID == id) {
+ // Only enabled or internal properties should be part of the style.
+ ASSERT(RuntimeCSSEnabled::isCSSPropertyEnabled(propertyID) || isInternalProperty(propertyID));
+ return n;
+ }
}
- m_cssomWrapper = adoptPtr(new InlineCSSStyleDeclaration(this, parentElement));
- return m_cssomWrapper.get();
+
+ return -1;
+}
+
+void MutableStylePropertySet::traceAfterDispatch(Visitor* visitor)
+{
+ visitor->trace(m_cssomWrapper);
+ visitor->trace(m_propertyVector);
+ StylePropertySet::traceAfterDispatch(visitor);
}
unsigned StylePropertySet::averageSizeInBytes()
@@ -668,7 +577,7 @@ unsigned StylePropertySet::averageSizeInBytes()
}
// See the function above if you need to update this.
-struct SameSizeAsStylePropertySet : public RefCounted<SameSizeAsStylePropertySet> {
+struct SameSizeAsStylePropertySet : public RefCountedWillBeRefCountedGarbageCollected<SameSizeAsStylePropertySet> {
unsigned bitfield;
};
COMPILE_ASSERT(sizeof(StylePropertySet) == sizeof(SameSizeAsStylePropertySet), style_property_set_should_stay_small);
@@ -680,23 +589,18 @@ void StylePropertySet::showStyle()
}
#endif
-PassRefPtr<MutableStylePropertySet> MutableStylePropertySet::create(CSSParserMode cssParserMode)
+PassRefPtrWillBeRawPtr<MutableStylePropertySet> MutableStylePropertySet::create(CSSParserMode cssParserMode)
{
- return adoptRef(new MutableStylePropertySet(cssParserMode));
+ return adoptRefWillBeRefCountedGarbageCollected(new MutableStylePropertySet(cssParserMode));
}
-PassRefPtr<MutableStylePropertySet> MutableStylePropertySet::create(const CSSProperty* properties, unsigned count)
+PassRefPtrWillBeRawPtr<MutableStylePropertySet> MutableStylePropertySet::create(const CSSProperty* properties, unsigned count)
{
- return adoptRef(new MutableStylePropertySet(properties, count));
+ return adoptRefWillBeRefCountedGarbageCollected(new MutableStylePropertySet(properties, count));
}
String StylePropertySet::PropertyReference::cssName() const
{
- if (id() == CSSPropertyVariable) {
- if (!propertyValue()->isVariableValue())
- return emptyString(); // Should not happen, but if it does, avoid a bad cast.
- return "var-" + toCSSVariableValue(propertyValue())->name();
- }
return getPropertyNameString(id());
}