summaryrefslogtreecommitdiffstats
path: root/chromium/third_party/WebKit/Source/core/css/PropertySetCSSStyleDeclaration.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/third_party/WebKit/Source/core/css/PropertySetCSSStyleDeclaration.cpp')
-rw-r--r--chromium/third_party/WebKit/Source/core/css/PropertySetCSSStyleDeclaration.cpp234
1 files changed, 114 insertions, 120 deletions
diff --git a/chromium/third_party/WebKit/Source/core/css/PropertySetCSSStyleDeclaration.cpp b/chromium/third_party/WebKit/Source/core/css/PropertySetCSSStyleDeclaration.cpp
index e30610ab3a2..b6d0f6eed1f 100644
--- a/chromium/third_party/WebKit/Source/core/css/PropertySetCSSStyleDeclaration.cpp
+++ b/chromium/third_party/WebKit/Source/core/css/PropertySetCSSStyleDeclaration.cpp
@@ -22,18 +22,16 @@
#include "config.h"
#include "core/css/PropertySetCSSStyleDeclaration.h"
-#include "HTMLNames.h"
-#include "RuntimeEnabledFeatures.h"
#include "bindings/v8/ExceptionState.h"
-#include "core/css/CSSParser.h"
+#include "core/HTMLNames.h"
+#include "core/css/parser/BisonCSSParser.h"
#include "core/css/CSSStyleSheet.h"
#include "core/css/StylePropertySet.h"
#include "core/dom/Element.h"
#include "core/dom/MutationObserverInterestGroup.h"
#include "core/dom/MutationRecord.h"
#include "core/inspector/InspectorInstrumentation.h"
-
-using namespace std;
+#include "platform/RuntimeEnabledFeatures.h"
namespace WebCore {
@@ -41,8 +39,9 @@ namespace {
class StyleAttributeMutationScope {
WTF_MAKE_NONCOPYABLE(StyleAttributeMutationScope);
+ STACK_ALLOCATED();
public:
- StyleAttributeMutationScope(PropertySetCSSStyleDeclaration* decl)
+ StyleAttributeMutationScope(AbstractPropertySetCSSStyleDeclaration* decl)
{
InspectorInstrumentation::willMutateStyle(decl);
++s_scopeCount;
@@ -86,7 +85,7 @@ public:
s_shouldDeliver = false;
// We have to clear internal state before calling Inspector's code.
- PropertySetCSSStyleDeclaration* localCopyStyleDecl = s_currentDecl;
+ AbstractPropertySetCSSStyleDeclaration* localCopyStyleDecl = s_currentDecl;
s_currentDecl = 0;
InspectorInstrumentation::didMutateStyle(localCopyStyleDecl, localCopyStyleDecl->parentElement());
@@ -110,21 +109,22 @@ public:
private:
static unsigned s_scopeCount;
- static PropertySetCSSStyleDeclaration* s_currentDecl;
+ static AbstractPropertySetCSSStyleDeclaration* s_currentDecl;
static bool s_shouldNotifyInspector;
static bool s_shouldDeliver;
- OwnPtr<MutationObserverInterestGroup> m_mutationRecipients;
- RefPtr<MutationRecord> m_mutation;
+ OwnPtrWillBeMember<MutationObserverInterestGroup> m_mutationRecipients;
+ RefPtrWillBeMember<MutationRecord> m_mutation;
};
unsigned StyleAttributeMutationScope::s_scopeCount = 0;
-PropertySetCSSStyleDeclaration* StyleAttributeMutationScope::s_currentDecl = 0;
+AbstractPropertySetCSSStyleDeclaration* StyleAttributeMutationScope::s_currentDecl = 0;
bool StyleAttributeMutationScope::s_shouldNotifyInspector = false;
bool StyleAttributeMutationScope::s_shouldDeliver = false;
} // namespace
+#if !ENABLE(OILPAN)
void PropertySetCSSStyleDeclaration::ref()
{
m_propertySet->ref();
@@ -134,103 +134,101 @@ void PropertySetCSSStyleDeclaration::deref()
{
m_propertySet->deref();
}
+#endif
-unsigned PropertySetCSSStyleDeclaration::length() const
+void PropertySetCSSStyleDeclaration::trace(Visitor* visitor)
{
- return m_propertySet->propertyCount();
+ visitor->trace(m_propertySet);
+ AbstractPropertySetCSSStyleDeclaration::trace(visitor);
}
-String PropertySetCSSStyleDeclaration::item(unsigned i) const
+unsigned AbstractPropertySetCSSStyleDeclaration::length() const
{
- if (i >= m_propertySet->propertyCount())
+ return propertySet().propertyCount();
+}
+
+String AbstractPropertySetCSSStyleDeclaration::item(unsigned i) const
+{
+ if (i >= propertySet().propertyCount())
return "";
- return m_propertySet->propertyAt(i).cssName();
+ return propertySet().propertyAt(i).cssName();
}
-String PropertySetCSSStyleDeclaration::cssText() const
+String AbstractPropertySetCSSStyleDeclaration::cssText() const
{
- return m_propertySet->asText();
+ return propertySet().asText();
}
-void PropertySetCSSStyleDeclaration::setCSSText(const String& text, ExceptionState& exceptionState)
+void AbstractPropertySetCSSStyleDeclaration::setCSSText(const String& text, ExceptionState& exceptionState)
{
StyleAttributeMutationScope mutationScope(this);
willMutate();
// FIXME: Detect syntax errors and set exceptionState.
- m_propertySet->parseDeclaration(text, contextStyleSheet());
+ propertySet().parseDeclaration(text, contextStyleSheet());
didMutate(PropertyChanged);
mutationScope.enqueueMutationRecord();
}
-PassRefPtr<CSSValue> PropertySetCSSStyleDeclaration::getPropertyCSSValue(const String& propertyName)
+PassRefPtrWillBeRawPtr<CSSValue> AbstractPropertySetCSSStyleDeclaration::getPropertyCSSValue(const String& propertyName)
{
CSSPropertyID propertyID = cssPropertyID(propertyName);
if (!propertyID)
- return 0;
- return cloneAndCacheForCSSOM(m_propertySet->getPropertyCSSValue(propertyID).get());
+ return nullptr;
+ return cloneAndCacheForCSSOM(propertySet().getPropertyCSSValue(propertyID).get());
}
-String PropertySetCSSStyleDeclaration::getPropertyValue(const String &propertyName)
+String AbstractPropertySetCSSStyleDeclaration::getPropertyValue(const String &propertyName)
{
CSSPropertyID propertyID = cssPropertyID(propertyName);
if (!propertyID)
return String();
- return m_propertySet->getPropertyValue(propertyID);
+ return propertySet().getPropertyValue(propertyID);
}
-String PropertySetCSSStyleDeclaration::getPropertyPriority(const String& propertyName)
+String AbstractPropertySetCSSStyleDeclaration::getPropertyPriority(const String& propertyName)
{
CSSPropertyID propertyID = cssPropertyID(propertyName);
if (!propertyID)
return String();
- return m_propertySet->propertyIsImportant(propertyID) ? "important" : "";
+ return propertySet().propertyIsImportant(propertyID) ? "important" : "";
}
-String PropertySetCSSStyleDeclaration::getPropertyShorthand(const String& propertyName)
+String AbstractPropertySetCSSStyleDeclaration::getPropertyShorthand(const String& propertyName)
{
CSSPropertyID propertyID = cssPropertyID(propertyName);
if (!propertyID)
return String();
- CSSPropertyID shorthandID = m_propertySet->getPropertyShorthand(propertyID);
+ CSSPropertyID shorthandID = propertySet().getPropertyShorthand(propertyID);
if (!shorthandID)
return String();
return getPropertyNameString(shorthandID);
}
-bool PropertySetCSSStyleDeclaration::isPropertyImplicit(const String& propertyName)
+bool AbstractPropertySetCSSStyleDeclaration::isPropertyImplicit(const String& propertyName)
{
CSSPropertyID propertyID = cssPropertyID(propertyName);
if (!propertyID)
return false;
- return m_propertySet->isPropertyImplicit(propertyID);
+ return propertySet().isPropertyImplicit(propertyID);
}
-void PropertySetCSSStyleDeclaration::setProperty(const String& propertyName, const String& value, const String& priority, ExceptionState& exceptionState)
+void AbstractPropertySetCSSStyleDeclaration::setProperty(const String& propertyName, const String& value, const String& priority, ExceptionState& exceptionState)
{
- StyleAttributeMutationScope mutationScope(this);
CSSPropertyID propertyID = cssPropertyID(propertyName);
if (!propertyID)
return;
- bool important = priority.find("important", 0, false) != kNotFound;
-
- willMutate();
-
- bool changed = m_propertySet->setProperty(propertyID, value, important, contextStyleSheet());
-
- didMutate(changed ? PropertyChanged : NoChanges);
+ bool important = equalIgnoringCase(priority, "important");
+ if (!important && !priority.isEmpty())
+ return;
- if (changed) {
- // CSS DOM requires raising SyntaxError of parsing failed, but this is too dangerous for compatibility,
- // see <http://bugs.webkit.org/show_bug.cgi?id=7296>.
- mutationScope.enqueueMutationRecord();
- }
+ setPropertyInternal(propertyID, value, important, exceptionState);
}
-String PropertySetCSSStyleDeclaration::removeProperty(const String& propertyName, ExceptionState& exceptionState)
+String AbstractPropertySetCSSStyleDeclaration::removeProperty(const String& propertyName, ExceptionState& exceptionState)
{
StyleAttributeMutationScope mutationScope(this);
CSSPropertyID propertyID = cssPropertyID(propertyName);
@@ -240,7 +238,7 @@ String PropertySetCSSStyleDeclaration::removeProperty(const String& propertyName
willMutate();
String result;
- bool changed = m_propertySet->removeProperty(propertyID, &result);
+ bool changed = propertySet().removeProperty(propertyID, &result);
didMutate(changed ? PropertyChanged : NoChanges);
@@ -249,22 +247,22 @@ String PropertySetCSSStyleDeclaration::removeProperty(const String& propertyName
return result;
}
-PassRefPtr<CSSValue> PropertySetCSSStyleDeclaration::getPropertyCSSValueInternal(CSSPropertyID propertyID)
+PassRefPtrWillBeRawPtr<CSSValue> AbstractPropertySetCSSStyleDeclaration::getPropertyCSSValueInternal(CSSPropertyID propertyID)
{
- return m_propertySet->getPropertyCSSValue(propertyID);
+ return propertySet().getPropertyCSSValue(propertyID);
}
-String PropertySetCSSStyleDeclaration::getPropertyValueInternal(CSSPropertyID propertyID)
+String AbstractPropertySetCSSStyleDeclaration::getPropertyValueInternal(CSSPropertyID propertyID)
{
- return m_propertySet->getPropertyValue(propertyID);
+ return propertySet().getPropertyValue(propertyID);
}
-void PropertySetCSSStyleDeclaration::setPropertyInternal(CSSPropertyID propertyID, const String& value, bool important, ExceptionState&)
+void AbstractPropertySetCSSStyleDeclaration::setPropertyInternal(CSSPropertyID propertyID, const String& value, bool important, ExceptionState&)
{
StyleAttributeMutationScope mutationScope(this);
willMutate();
- bool changed = m_propertySet->setProperty(propertyID, value, important, contextStyleSheet());
+ bool changed = propertySet().setProperty(propertyID, value, important, contextStyleSheet());
didMutate(changed ? PropertyChanged : NoChanges);
@@ -272,60 +270,7 @@ void PropertySetCSSStyleDeclaration::setPropertyInternal(CSSPropertyID propertyI
mutationScope.enqueueMutationRecord();
}
-unsigned PropertySetCSSStyleDeclaration::variableCount() const
-{
- ASSERT(RuntimeEnabledFeatures::cssVariablesEnabled());
- return m_propertySet->variableCount();
-}
-
-String PropertySetCSSStyleDeclaration::variableValue(const AtomicString& name) const
-{
- ASSERT(RuntimeEnabledFeatures::cssVariablesEnabled());
- return m_propertySet->variableValue(name);
-}
-
-bool PropertySetCSSStyleDeclaration::setVariableValue(const AtomicString& name, const String& value, ExceptionState&)
-{
- ASSERT(RuntimeEnabledFeatures::cssVariablesEnabled());
- StyleAttributeMutationScope mutationScope(this);
- willMutate();
- bool changed = m_propertySet->setVariableValue(name, value);
- didMutate(changed ? PropertyChanged : NoChanges);
- if (changed)
- mutationScope.enqueueMutationRecord();
- return changed;
-}
-
-bool PropertySetCSSStyleDeclaration::removeVariable(const AtomicString& name)
-{
- ASSERT(RuntimeEnabledFeatures::cssVariablesEnabled());
- StyleAttributeMutationScope mutationScope(this);
- willMutate();
- bool changed = m_propertySet->removeVariable(name);
- didMutate(changed ? PropertyChanged : NoChanges);
- if (changed)
- mutationScope.enqueueMutationRecord();
- return changed;
-}
-
-bool PropertySetCSSStyleDeclaration::clearVariables(ExceptionState&)
-{
- ASSERT(RuntimeEnabledFeatures::cssVariablesEnabled());
- StyleAttributeMutationScope mutationScope(this);
- willMutate();
- bool changed = m_propertySet->clearVariables();
- didMutate(changed ? PropertyChanged : NoChanges);
- if (changed)
- mutationScope.enqueueMutationRecord();
- return changed;
-}
-
-PassRefPtr<CSSVariablesIterator> PropertySetCSSStyleDeclaration::variablesIterator() const
-{
- return m_propertySet->variablesIterator();
-}
-
-CSSValue* PropertySetCSSStyleDeclaration::cloneAndCacheForCSSOM(CSSValue* internalValue)
+CSSValue* AbstractPropertySetCSSStyleDeclaration::cloneAndCacheForCSSOM(CSSValue* internalValue)
{
if (!internalValue)
return 0;
@@ -333,43 +278,58 @@ CSSValue* PropertySetCSSStyleDeclaration::cloneAndCacheForCSSOM(CSSValue* intern
// 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<CSSValue*, RefPtr<CSSValue> >);
+ m_cssomCSSValueClones = adoptPtrWillBeNoop(new WillBeHeapHashMap<RawPtrWillBeMember<CSSValue>, RefPtrWillBeMember<CSSValue> >);
- RefPtr<CSSValue>& clonedValue = m_cssomCSSValueClones->add(internalValue, RefPtr<CSSValue>()).iterator->value;
+ RefPtrWillBeMember<CSSValue>& clonedValue = m_cssomCSSValueClones->add(internalValue, RefPtrWillBeMember<CSSValue>()).storedValue->value;
if (!clonedValue)
clonedValue = internalValue->cloneForCSSOM();
return clonedValue.get();
}
-StyleSheetContents* PropertySetCSSStyleDeclaration::contextStyleSheet() const
+StyleSheetContents* AbstractPropertySetCSSStyleDeclaration::contextStyleSheet() const
{
CSSStyleSheet* cssStyleSheet = parentStyleSheet();
return cssStyleSheet ? cssStyleSheet->contents() : 0;
}
-PassRefPtr<MutableStylePropertySet> PropertySetCSSStyleDeclaration::copyProperties() const
+PassRefPtrWillBeRawPtr<MutableStylePropertySet> AbstractPropertySetCSSStyleDeclaration::copyProperties() const
+{
+ return propertySet().mutableCopy();
+}
+
+bool AbstractPropertySetCSSStyleDeclaration::cssPropertyMatches(CSSPropertyID propertyID, const CSSValue* propertyValue) const
{
- return m_propertySet->mutableCopy();
+ return propertySet().propertyMatches(propertyID, propertyValue);
}
-bool PropertySetCSSStyleDeclaration::cssPropertyMatches(CSSPropertyID propertyID, const CSSValue* propertyValue) const
+void AbstractPropertySetCSSStyleDeclaration::trace(Visitor* visitor)
{
- return m_propertySet->propertyMatches(propertyID, propertyValue);
+#if ENABLE(OILPAN)
+ visitor->trace(m_cssomCSSValueClones);
+#endif
+ CSSStyleDeclaration::trace(visitor);
}
-StyleRuleCSSStyleDeclaration::StyleRuleCSSStyleDeclaration(MutableStylePropertySet* propertySet, CSSRule* parentRule)
- : PropertySetCSSStyleDeclaration(propertySet)
+StyleRuleCSSStyleDeclaration::StyleRuleCSSStyleDeclaration(MutableStylePropertySet& propertySetArg, CSSRule* parentRule)
+ : PropertySetCSSStyleDeclaration(propertySetArg)
+#if !ENABLE(OILPAN)
, m_refCount(1)
+#endif
, m_parentRule(parentRule)
{
+#if !ENABLE(OILPAN)
m_propertySet->ref();
+#endif
}
StyleRuleCSSStyleDeclaration::~StyleRuleCSSStyleDeclaration()
{
+#if !ENABLE(OILPAN)
m_propertySet->deref();
+#endif
}
+#if !ENABLE(OILPAN)
void StyleRuleCSSStyleDeclaration::ref()
{
++m_refCount;
@@ -381,6 +341,7 @@ void StyleRuleCSSStyleDeclaration::deref()
if (!--m_refCount)
delete this;
}
+#endif
void StyleRuleCSSStyleDeclaration::willMutate()
{
@@ -403,12 +364,26 @@ CSSStyleSheet* StyleRuleCSSStyleDeclaration::parentStyleSheet() const
return m_parentRule ? m_parentRule->parentStyleSheet() : 0;
}
-void StyleRuleCSSStyleDeclaration::reattach(MutableStylePropertySet* propertySet)
+void StyleRuleCSSStyleDeclaration::reattach(MutableStylePropertySet& propertySet)
{
- ASSERT(propertySet);
+#if !ENABLE(OILPAN)
m_propertySet->deref();
- m_propertySet = propertySet;
+#endif
+ m_propertySet = &propertySet;
+#if !ENABLE(OILPAN)
m_propertySet->ref();
+#endif
+}
+
+void StyleRuleCSSStyleDeclaration::trace(Visitor* visitor)
+{
+ visitor->trace(m_parentRule);
+ PropertySetCSSStyleDeclaration::trace(visitor);
+}
+
+MutableStylePropertySet& InlineCSSStyleDeclaration::propertySet() const
+{
+ return m_parentElement->ensureMutableInlineStyle();
}
void InlineCSSStyleDeclaration::didMutate(MutationType type)
@@ -421,6 +396,7 @@ void InlineCSSStyleDeclaration::didMutate(MutationType type)
if (!m_parentElement)
return;
+ m_parentElement->clearMutableInlineStyleIfEmpty();
m_parentElement->setNeedsStyleRecalc(LocalStyleChange);
m_parentElement->invalidateStyleAttribute();
StyleAttributeMutationScope(this).didInvalidateStyleAttr();
@@ -428,7 +404,25 @@ void InlineCSSStyleDeclaration::didMutate(MutationType type)
CSSStyleSheet* InlineCSSStyleDeclaration::parentStyleSheet() const
{
- return m_parentElement ? m_parentElement->document().elementSheet() : 0;
+ return m_parentElement ? &m_parentElement->document().elementSheet() : 0;
+}
+
+#if !ENABLE(OILPAN)
+void InlineCSSStyleDeclaration::ref()
+{
+ m_parentElement->ref();
+}
+
+void InlineCSSStyleDeclaration::deref()
+{
+ m_parentElement->deref();
+}
+#endif
+
+void InlineCSSStyleDeclaration::trace(Visitor* visitor)
+{
+ visitor->trace(m_parentElement);
+ AbstractPropertySetCSSStyleDeclaration::trace(visitor);
}
} // namespace WebCore