From 2cf6c8816a73e0132bd8fa3b509d62d7c51b6e47 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Mon, 7 May 2012 11:21:11 +0200 Subject: Imported WebKit commit 7e538425aa020340619e927792f3d895061fb54b (http://svn.webkit.org/repository/webkit/trunk@116286) --- .../WebCore/css/PropertySetCSSStyleDeclaration.cpp | 103 +++++++++++++++------ 1 file changed, 76 insertions(+), 27 deletions(-) (limited to 'Source/WebCore/css/PropertySetCSSStyleDeclaration.cpp') diff --git a/Source/WebCore/css/PropertySetCSSStyleDeclaration.cpp b/Source/WebCore/css/PropertySetCSSStyleDeclaration.cpp index 428f1957b..b3e6f1d93 100644 --- a/Source/WebCore/css/PropertySetCSSStyleDeclaration.cpp +++ b/Source/WebCore/css/PropertySetCSSStyleDeclaration.cpp @@ -23,6 +23,7 @@ #include "PropertySetCSSStyleDeclaration.h" #include "CSSParser.h" +#include "CSSStyleSheet.h" #include "HTMLNames.h" #include "InspectorInstrumentation.h" #include "MutationObserverInterestGroup.h" @@ -118,7 +119,7 @@ bool StyleAttributeMutationScope::s_shouldDeliver = false; #endif } // namespace - + void PropertySetCSSStyleDeclaration::ref() { m_propertySet->ref(); @@ -138,7 +139,7 @@ String PropertySetCSSStyleDeclaration::item(unsigned i) const { if (i >= m_propertySet->propertyCount()) return ""; - return getPropertyName(static_cast(m_propertySet->propertyAt(i).id())); + return getPropertyName(m_propertySet->propertyAt(i).id()); } String PropertySetCSSStyleDeclaration::cssText() const @@ -155,7 +156,7 @@ void PropertySetCSSStyleDeclaration::setCssText(const String& text, ExceptionCod // FIXME: Detect syntax errors and set ec. m_propertySet->parseDeclaration(text, contextStyleSheet()); - setNeedsStyleRecalc(); + didMutate(); #if ENABLE(MUTATION_OBSERVERS) mutationScope.enqueueMutationRecord(); #endif @@ -163,15 +164,15 @@ void PropertySetCSSStyleDeclaration::setCssText(const String& text, ExceptionCod PassRefPtr PropertySetCSSStyleDeclaration::getPropertyCSSValue(const String& propertyName) { - int propertyID = cssPropertyID(propertyName); + CSSPropertyID propertyID = cssPropertyID(propertyName); if (!propertyID) return 0; - return m_propertySet->getPropertyCSSValue(propertyID); + return cloneAndCacheForCSSOM(m_propertySet->getPropertyCSSValue(propertyID).get()); } String PropertySetCSSStyleDeclaration::getPropertyValue(const String &propertyName) { - int propertyID = cssPropertyID(propertyName); + CSSPropertyID propertyID = cssPropertyID(propertyName); if (!propertyID) return String(); return m_propertySet->getPropertyValue(propertyID); @@ -179,7 +180,7 @@ String PropertySetCSSStyleDeclaration::getPropertyValue(const String &propertyNa String PropertySetCSSStyleDeclaration::getPropertyPriority(const String& propertyName) { - int propertyID = cssPropertyID(propertyName); + CSSPropertyID propertyID = cssPropertyID(propertyName); if (!propertyID) return String(); return m_propertySet->propertyIsImportant(propertyID) ? "important" : ""; @@ -187,18 +188,18 @@ String PropertySetCSSStyleDeclaration::getPropertyPriority(const String& propert String PropertySetCSSStyleDeclaration::getPropertyShorthand(const String& propertyName) { - int propertyID = cssPropertyID(propertyName); + CSSPropertyID propertyID = cssPropertyID(propertyName); if (!propertyID) return String(); - int shorthandID = m_propertySet->getPropertyShorthand(propertyID); + CSSPropertyID shorthandID = m_propertySet->getPropertyShorthand(propertyID); if (!shorthandID) return String(); - return getPropertyName(static_cast(shorthandID)); + return getPropertyName(shorthandID); } bool PropertySetCSSStyleDeclaration::isPropertyImplicit(const String& propertyName) { - int propertyID = cssPropertyID(propertyName); + CSSPropertyID propertyID = cssPropertyID(propertyName); if (!propertyID) return false; return m_propertySet->isPropertyImplicit(propertyID); @@ -209,7 +210,7 @@ void PropertySetCSSStyleDeclaration::setProperty(const String& propertyName, con #if ENABLE(MUTATION_OBSERVERS) StyleAttributeMutationScope mutationScope(this); #endif - int propertyID = cssPropertyID(propertyName); + CSSPropertyID propertyID = cssPropertyID(propertyName); if (!propertyID) return; bool important = priority.find("important", 0, false) != notFound; @@ -218,7 +219,7 @@ void PropertySetCSSStyleDeclaration::setProperty(const String& propertyName, con if (changed) { // CSS DOM requires raising SYNTAX_ERR of parsing failed, but this is too dangerous for compatibility, // see . - setNeedsStyleRecalc(); + didMutate(); #if ENABLE(MUTATION_OBSERVERS) mutationScope.enqueueMutationRecord(); #endif @@ -230,14 +231,14 @@ String PropertySetCSSStyleDeclaration::removeProperty(const String& propertyName #if ENABLE(MUTATION_OBSERVERS) StyleAttributeMutationScope mutationScope(this); #endif - int propertyID = cssPropertyID(propertyName); + CSSPropertyID propertyID = cssPropertyID(propertyName); if (!propertyID) return String(); ec = 0; String result; bool changes = m_propertySet->removeProperty(propertyID, &result); if (changes) { - setNeedsStyleRecalc(); + didMutate(); #if ENABLE(MUTATION_OBSERVERS) mutationScope.enqueueMutationRecord(); #endif @@ -246,8 +247,8 @@ String PropertySetCSSStyleDeclaration::removeProperty(const String& propertyName } PassRefPtr PropertySetCSSStyleDeclaration::getPropertyCSSValueInternal(CSSPropertyID propertyID) -{ - return m_propertySet->getPropertyCSSValue(propertyID); +{ + return m_propertySet->getPropertyCSSValue(propertyID); } String PropertySetCSSStyleDeclaration::getPropertyValueInternal(CSSPropertyID propertyID) @@ -263,16 +264,39 @@ void PropertySetCSSStyleDeclaration::setPropertyInternal(CSSPropertyID propertyI ec = 0; bool changed = m_propertySet->setProperty(propertyID, value, important, contextStyleSheet()); if (changed) { - setNeedsStyleRecalc(); + didMutate(); #if ENABLE(MUTATION_OBSERVERS) mutationScope.enqueueMutationRecord(); #endif } } -CSSStyleSheet* PropertySetCSSStyleDeclaration::parentStyleSheet() const +void PropertySetCSSStyleDeclaration::didMutate() +{ + m_cssomCSSValueClones.clear(); + setNeedsStyleRecalc(); +} + +CSSValue* PropertySetCSSStyleDeclaration::cloneAndCacheForCSSOM(CSSValue* internalValue) +{ + if (!internalValue) + return 0; + + // The map is here to maintain the object identity of the CSSValues over multiple invocations. + // FIXME: It is likely that the identity is not important for web compatibility and this code should be removed. + if (!m_cssomCSSValueClones) + m_cssomCSSValueClones = adoptPtr(new HashMap >); + + RefPtr& clonedValue = m_cssomCSSValueClones->add(internalValue, RefPtr()).iterator->second; + if (!clonedValue) + clonedValue = internalValue->cloneForCSSOM(); + return clonedValue.get(); +} + +StyleSheetInternal* PropertySetCSSStyleDeclaration::contextStyleSheet() const { - return contextStyleSheet(); + CSSStyleSheet* cssStyleSheet = parentStyleSheet(); + return cssStyleSheet ? cssStyleSheet->internal() : 0; } PassRefPtr PropertySetCSSStyleDeclaration::copy() const @@ -289,16 +313,41 @@ bool PropertySetCSSStyleDeclaration::cssPropertyMatches(const CSSProperty* prope { return m_propertySet->propertyMatches(property); } + +StyleRuleCSSStyleDeclaration::StyleRuleCSSStyleDeclaration(StylePropertySet* propertySet, CSSRule* parentRule) + : PropertySetCSSStyleDeclaration(propertySet) + , m_refCount(1) + , m_parentRule(parentRule) +{ + m_propertySet->ref(); +} + +StyleRuleCSSStyleDeclaration::~StyleRuleCSSStyleDeclaration() +{ + m_propertySet->deref(); +} -void RuleCSSStyleDeclaration::setNeedsStyleRecalc() +void StyleRuleCSSStyleDeclaration::ref() +{ + ++m_refCount; +} + +void StyleRuleCSSStyleDeclaration::deref() +{ + ASSERT(m_refCount); + if (!--m_refCount) + delete this; +} + +void StyleRuleCSSStyleDeclaration::setNeedsStyleRecalc() { - if (CSSStyleSheet* styleSheet = contextStyleSheet()) { - if (Document* document = styleSheet->findDocument()) - document->styleSelectorChanged(DeferRecalcStyle); + if (CSSStyleSheet* styleSheet = parentStyleSheet()) { + if (Document* document = styleSheet->ownerDocument()) + document->styleResolverChanged(DeferRecalcStyle); } } - -CSSStyleSheet* RuleCSSStyleDeclaration::contextStyleSheet() const + +CSSStyleSheet* StyleRuleCSSStyleDeclaration::parentStyleSheet() const { return m_parentRule ? m_parentRule->parentStyleSheet() : 0; } @@ -313,7 +362,7 @@ void InlineCSSStyleDeclaration::setNeedsStyleRecalc() return; } -CSSStyleSheet* InlineCSSStyleDeclaration::contextStyleSheet() const +CSSStyleSheet* InlineCSSStyleDeclaration::parentStyleSheet() const { return m_parentElement ? m_parentElement->document()->elementSheet() : 0; } -- cgit v1.2.1