Move the context invalidation code out from StylePropertySet
authorantti@apple.com <antti@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 16 Feb 2012 07:39:17 +0000 (07:39 +0000)
committerantti@apple.com <antti@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 16 Feb 2012 07:39:17 +0000 (07:39 +0000)
https://bugs.webkit.org/show_bug.cgi?id=78589

Reviewed by Ryosuke Niwa.

StylePropertySet should be independent of its context so that they can in the future
be shared between documents. The context invalidation code should move to the CSSOM wrapper.

Parent rule and parent element pointers move to the CSSOM wrapper classes.

The wrapper is responsible of invalidating the element or document style on mutation.
In case of internal mutation of style attribute, StyledElement takes care of the
invalidation.

The StylePropertySet will still have a pointer to the context stylesheet so the patch
doesn't actually reduce memory usage. That pointer will be factored out later.

* css/CSSFontFaceRule.cpp:
(WebCore::CSSFontFaceRule::~CSSFontFaceRule):
* css/CSSFontFaceRule.h:
(WebCore::CSSFontFaceRule::style):
* css/CSSPageRule.cpp:
(WebCore::CSSPageRule::~CSSPageRule):
* css/CSSPageRule.h:
(WebCore::CSSPageRule::style):
(WebCore::CSSPageRule::setDeclaration):
* css/CSSParser.cpp:
(WebCore::CSSParser::createStyleRule):
(WebCore::CSSParser::createFontFaceRule):
(WebCore::CSSParser::createPageRule):
(WebCore::CSSParser::createKeyframeRule):
* css/CSSStyleRule.cpp:
(WebCore::CSSStyleRule::~CSSStyleRule):
* css/CSSStyleRule.h:
(WebCore::CSSStyleRule::style):
(WebCore::CSSStyleRule::setDeclaration):
* css/StylePropertySet.cpp:
(PropertySetCSSStyleDeclaration):
(WebCore::PropertySetCSSStyleDeclaration::parentElement):
(WebCore::PropertySetCSSStyleDeclaration::clearParentRule):
(WebCore::PropertySetCSSStyleDeclaration::clearParentElement):
(WebCore::PropertySetCSSStyleDeclaration::setNeedsStyleRecalc):
(RuleCSSStyleDeclaration):
(WebCore::RuleCSSStyleDeclaration::RuleCSSStyleDeclaration):
(WebCore::RuleCSSStyleDeclaration::parentRule):
(WebCore::RuleCSSStyleDeclaration::clearParentRule):
(WebCore):
(InlineCSSStyleDeclaration):
(WebCore::InlineCSSStyleDeclaration::InlineCSSStyleDeclaration):
(WebCore::InlineCSSStyleDeclaration::parentElement):
(WebCore::InlineCSSStyleDeclaration::clearParentElement):
(WebCore::StylePropertySet::StylePropertySet):
(WebCore::StylePropertySet::removeShorthandProperty):
(WebCore::StylePropertySet::removeProperty):
(WebCore::StylePropertySet::setProperty):
(WebCore::StylePropertySet::parseDeclaration):
(WebCore::StylePropertySet::addParsedProperties):
(WebCore::StylePropertySet::addParsedProperty):
(WebCore::StylePropertySet::merge):
(WebCore::StylePropertySet::removePropertiesInSet):
(WebCore::StylePropertySet::copy):
(WebCore::StylePropertySet::ensureCSSStyleDeclaration):
(WebCore::StylePropertySet::ensureRuleCSSStyleDeclaration):
(WebCore::StylePropertySet::ensureInlineCSSStyleDeclaration):
(WebCore::StylePropertySet::clearParentRule):
(WebCore::StylePropertySet::clearParentElement):
(WebCore::PropertySetCSSStyleDeclaration::setCssText):
(WebCore::PropertySetCSSStyleDeclaration::setProperty):
(WebCore::PropertySetCSSStyleDeclaration::removeProperty):
(WebCore::PropertySetCSSStyleDeclaration::setPropertyInternal):
(WebCore::RuleCSSStyleDeclaration::setNeedsStyleRecalc):
(WebCore::InlineCSSStyleDeclaration::setNeedsStyleRecalc):
* css/StylePropertySet.h:
(WebCore::StylePropertySet::create):
(StylePropertySet):
(WebCore::StylePropertySet::useStrictParsing):
(WebCore::StylePropertySet::contextStyleSheet):
(WebCore::StylePropertySet::setContextStyleSheet):
* css/WebKitCSSKeyframeRule.cpp:
(WebCore::WebKitCSSKeyframeRule::~WebKitCSSKeyframeRule):
(WebCore::WebKitCSSKeyframeRule::setDeclaration):
* css/WebKitCSSKeyframeRule.h:
(WebCore::WebKitCSSKeyframeRule::style):
* dom/ElementAttributeData.cpp:
(WebCore::ElementAttributeData::ensureInlineStyleDecl):
(WebCore::ElementAttributeData::destroyInlineStyleDecl):
* dom/ElementAttributeData.h:
(ElementAttributeData):
* dom/StyledElement.cpp:
(WebCore::StyledElement::insertedIntoDocument):
(WebCore):
(WebCore::StyledElement::removedFromDocument):
(WebCore::StyledElement::parseAttribute):
(WebCore::StyledElement::inlineStyleChanged):
(WebCore::StyledElement::setInlineStyleProperty):
(WebCore::StyledElement::removeInlineStyleProperty):
(WebCore::StyledElement::updateAttributeStyle):
* dom/StyledElement.h:
(StyledElement):
(WebCore::StyledElement::destroyInlineStyleDecl):
* editing/ApplyStyleCommand.cpp:
(WebCore::ApplyStyleCommand::applyRelativeFontStyleChange):
* editing/DeleteButtonController.cpp:
(WebCore::DeleteButtonController::createDeletionUI):
(WebCore::DeleteButtonController::show):
(WebCore::DeleteButtonController::hide):
* editing/Editor.cpp:
(WebCore::Editor::applyEditingStyleToElement):
* editing/RemoveCSSPropertyCommand.cpp:
(WebCore::RemoveCSSPropertyCommand::doApply):
(WebCore::RemoveCSSPropertyCommand::doUnapply):
* editing/ReplaceSelectionCommand.cpp:
(WebCore::ReplaceSelectionCommand::removeRedundantStylesAndKeepStyleSpanInline):
* html/ColorInputType.cpp:
(WebCore::ColorInputType::updateColorSwatch):
* html/HTMLTextFormControlElement.cpp:
(WebCore::HTMLTextFormControlElement::updatePlaceholderVisibility):
* html/ImageDocument.cpp:
(WebCore::ImageDocument::resizeImageToFit):
(WebCore::ImageDocument::restoreImageSize):
(WebCore::ImageDocument::windowSizeChanged):
* html/ValidationMessage.cpp:
(WebCore::adjustBubblePosition):
(WebCore::ValidationMessage::buildBubbleTree):
* html/shadow/MediaControlElements.cpp:
(WebCore::MediaControlElement::show):
(WebCore::MediaControlElement::hide):
(WebCore::MediaControlPanelElement::setPosition):
(WebCore::MediaControlPanelElement::resetPosition):
(WebCore::MediaControlPanelElement::makeOpaque):
(WebCore::MediaControlPanelElement::makeTransparent):
(WebCore::MediaControlInputElement::show):
(WebCore::MediaControlInputElement::hide):
(WebCore::MediaControlTextTrackContainerElement::updateSizes):
* html/shadow/MeterShadowElement.cpp:
(WebCore::MeterValueElement::setWidthPercentage):
* html/shadow/ProgressShadowElement.cpp:
(WebCore::ProgressValueElement::setWidthPercentage):
* html/shadow/SliderThumbElement.cpp:
(WebCore::TrackLimiterElement::create):
* rendering/RenderLayer.cpp:
(WebCore::RenderLayer::resize):
* rendering/RenderTextControlSingleLine.cpp:
(WebCore::RenderTextControlSingleLine::styleDidChange):
* svg/SVGFontFaceElement.cpp:
(WebCore::SVGFontFaceElement::SVGFontFaceElement):
(WebCore::SVGFontFaceElement::insertedIntoDocument):
(WebCore::SVGFontFaceElement::removeFromMappedElementSheet):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@107899 268f45cc-cd09-0410-ab3c-d52691b4dbfc

32 files changed:
Source/WebCore/ChangeLog
Source/WebCore/css/CSSFontFaceRule.cpp
Source/WebCore/css/CSSFontFaceRule.h
Source/WebCore/css/CSSPageRule.cpp
Source/WebCore/css/CSSPageRule.h
Source/WebCore/css/CSSParser.cpp
Source/WebCore/css/CSSStyleRule.cpp
Source/WebCore/css/CSSStyleRule.h
Source/WebCore/css/StylePropertySet.cpp
Source/WebCore/css/StylePropertySet.h
Source/WebCore/css/WebKitCSSKeyframeRule.cpp
Source/WebCore/css/WebKitCSSKeyframeRule.h
Source/WebCore/dom/ElementAttributeData.cpp
Source/WebCore/dom/ElementAttributeData.h
Source/WebCore/dom/StyledElement.cpp
Source/WebCore/dom/StyledElement.h
Source/WebCore/editing/ApplyStyleCommand.cpp
Source/WebCore/editing/DeleteButtonController.cpp
Source/WebCore/editing/Editor.cpp
Source/WebCore/editing/RemoveCSSPropertyCommand.cpp
Source/WebCore/editing/ReplaceSelectionCommand.cpp
Source/WebCore/html/ColorInputType.cpp
Source/WebCore/html/HTMLTextFormControlElement.cpp
Source/WebCore/html/ImageDocument.cpp
Source/WebCore/html/ValidationMessage.cpp
Source/WebCore/html/shadow/MediaControlElements.cpp
Source/WebCore/html/shadow/MeterShadowElement.cpp
Source/WebCore/html/shadow/ProgressShadowElement.cpp
Source/WebCore/html/shadow/SliderThumbElement.cpp
Source/WebCore/rendering/RenderLayer.cpp
Source/WebCore/rendering/RenderTextControlSingleLine.cpp
Source/WebCore/svg/SVGFontFaceElement.cpp

index 9a1bf3f..58d157d 100644 (file)
@@ -1,3 +1,154 @@
+2012-02-15  Antti Koivisto  <antti@apple.com>
+
+        Move the context invalidation code out from StylePropertySet
+        https://bugs.webkit.org/show_bug.cgi?id=78589
+
+        Reviewed by Ryosuke Niwa.
+
+        StylePropertySet should be independent of its context so that they can in the future
+        be shared between documents. The context invalidation code should move to the CSSOM wrapper.
+        
+        Parent rule and parent element pointers move to the CSSOM wrapper classes. 
+        
+        The wrapper is responsible of invalidating the element or document style on mutation.
+        In case of internal mutation of style attribute, StyledElement takes care of the 
+        invalidation.
+        
+        The StylePropertySet will still have a pointer to the context stylesheet so the patch
+        doesn't actually reduce memory usage. That pointer will be factored out later.
+
+        * css/CSSFontFaceRule.cpp:
+        (WebCore::CSSFontFaceRule::~CSSFontFaceRule):
+        * css/CSSFontFaceRule.h:
+        (WebCore::CSSFontFaceRule::style):
+        * css/CSSPageRule.cpp:
+        (WebCore::CSSPageRule::~CSSPageRule):
+        * css/CSSPageRule.h:
+        (WebCore::CSSPageRule::style):
+        (WebCore::CSSPageRule::setDeclaration):
+        * css/CSSParser.cpp:
+        (WebCore::CSSParser::createStyleRule):
+        (WebCore::CSSParser::createFontFaceRule):
+        (WebCore::CSSParser::createPageRule):
+        (WebCore::CSSParser::createKeyframeRule):
+        * css/CSSStyleRule.cpp:
+        (WebCore::CSSStyleRule::~CSSStyleRule):
+        * css/CSSStyleRule.h:
+        (WebCore::CSSStyleRule::style):
+        (WebCore::CSSStyleRule::setDeclaration):
+        * css/StylePropertySet.cpp:
+        (PropertySetCSSStyleDeclaration):
+        (WebCore::PropertySetCSSStyleDeclaration::parentElement):
+        (WebCore::PropertySetCSSStyleDeclaration::clearParentRule):
+        (WebCore::PropertySetCSSStyleDeclaration::clearParentElement):
+        (WebCore::PropertySetCSSStyleDeclaration::setNeedsStyleRecalc):
+        (RuleCSSStyleDeclaration):
+        (WebCore::RuleCSSStyleDeclaration::RuleCSSStyleDeclaration):
+        (WebCore::RuleCSSStyleDeclaration::parentRule):
+        (WebCore::RuleCSSStyleDeclaration::clearParentRule):
+        (WebCore):
+        (InlineCSSStyleDeclaration):
+        (WebCore::InlineCSSStyleDeclaration::InlineCSSStyleDeclaration):
+        (WebCore::InlineCSSStyleDeclaration::parentElement):
+        (WebCore::InlineCSSStyleDeclaration::clearParentElement):
+        (WebCore::StylePropertySet::StylePropertySet):
+        (WebCore::StylePropertySet::removeShorthandProperty):
+        (WebCore::StylePropertySet::removeProperty):
+        (WebCore::StylePropertySet::setProperty):
+        (WebCore::StylePropertySet::parseDeclaration):
+        (WebCore::StylePropertySet::addParsedProperties):
+        (WebCore::StylePropertySet::addParsedProperty):
+        (WebCore::StylePropertySet::merge):
+        (WebCore::StylePropertySet::removePropertiesInSet):
+        (WebCore::StylePropertySet::copy):
+        (WebCore::StylePropertySet::ensureCSSStyleDeclaration):
+        (WebCore::StylePropertySet::ensureRuleCSSStyleDeclaration):
+        (WebCore::StylePropertySet::ensureInlineCSSStyleDeclaration):
+        (WebCore::StylePropertySet::clearParentRule):
+        (WebCore::StylePropertySet::clearParentElement):
+        (WebCore::PropertySetCSSStyleDeclaration::setCssText):
+        (WebCore::PropertySetCSSStyleDeclaration::setProperty):
+        (WebCore::PropertySetCSSStyleDeclaration::removeProperty):
+        (WebCore::PropertySetCSSStyleDeclaration::setPropertyInternal):
+        (WebCore::RuleCSSStyleDeclaration::setNeedsStyleRecalc):
+        (WebCore::InlineCSSStyleDeclaration::setNeedsStyleRecalc):
+        * css/StylePropertySet.h:
+        (WebCore::StylePropertySet::create):
+        (StylePropertySet):
+        (WebCore::StylePropertySet::useStrictParsing):
+        (WebCore::StylePropertySet::contextStyleSheet):
+        (WebCore::StylePropertySet::setContextStyleSheet):
+        * css/WebKitCSSKeyframeRule.cpp:
+        (WebCore::WebKitCSSKeyframeRule::~WebKitCSSKeyframeRule):
+        (WebCore::WebKitCSSKeyframeRule::setDeclaration):
+        * css/WebKitCSSKeyframeRule.h:
+        (WebCore::WebKitCSSKeyframeRule::style):
+        * dom/ElementAttributeData.cpp:
+        (WebCore::ElementAttributeData::ensureInlineStyleDecl):
+        (WebCore::ElementAttributeData::destroyInlineStyleDecl):
+        * dom/ElementAttributeData.h:
+        (ElementAttributeData):
+        * dom/StyledElement.cpp:
+        (WebCore::StyledElement::insertedIntoDocument):
+        (WebCore):
+        (WebCore::StyledElement::removedFromDocument):
+        (WebCore::StyledElement::parseAttribute):
+        (WebCore::StyledElement::inlineStyleChanged):
+        (WebCore::StyledElement::setInlineStyleProperty):
+        (WebCore::StyledElement::removeInlineStyleProperty):
+        (WebCore::StyledElement::updateAttributeStyle):
+        * dom/StyledElement.h:
+        (StyledElement):
+        (WebCore::StyledElement::destroyInlineStyleDecl):
+        * editing/ApplyStyleCommand.cpp:
+        (WebCore::ApplyStyleCommand::applyRelativeFontStyleChange):
+        * editing/DeleteButtonController.cpp:
+        (WebCore::DeleteButtonController::createDeletionUI):
+        (WebCore::DeleteButtonController::show):
+        (WebCore::DeleteButtonController::hide):
+        * editing/Editor.cpp:
+        (WebCore::Editor::applyEditingStyleToElement):
+        * editing/RemoveCSSPropertyCommand.cpp:
+        (WebCore::RemoveCSSPropertyCommand::doApply):
+        (WebCore::RemoveCSSPropertyCommand::doUnapply):
+        * editing/ReplaceSelectionCommand.cpp:
+        (WebCore::ReplaceSelectionCommand::removeRedundantStylesAndKeepStyleSpanInline):
+        * html/ColorInputType.cpp:
+        (WebCore::ColorInputType::updateColorSwatch):
+        * html/HTMLTextFormControlElement.cpp:
+        (WebCore::HTMLTextFormControlElement::updatePlaceholderVisibility):
+        * html/ImageDocument.cpp:
+        (WebCore::ImageDocument::resizeImageToFit):
+        (WebCore::ImageDocument::restoreImageSize):
+        (WebCore::ImageDocument::windowSizeChanged):
+        * html/ValidationMessage.cpp:
+        (WebCore::adjustBubblePosition):
+        (WebCore::ValidationMessage::buildBubbleTree):
+        * html/shadow/MediaControlElements.cpp:
+        (WebCore::MediaControlElement::show):
+        (WebCore::MediaControlElement::hide):
+        (WebCore::MediaControlPanelElement::setPosition):
+        (WebCore::MediaControlPanelElement::resetPosition):
+        (WebCore::MediaControlPanelElement::makeOpaque):
+        (WebCore::MediaControlPanelElement::makeTransparent):
+        (WebCore::MediaControlInputElement::show):
+        (WebCore::MediaControlInputElement::hide):
+        (WebCore::MediaControlTextTrackContainerElement::updateSizes):
+        * html/shadow/MeterShadowElement.cpp:
+        (WebCore::MeterValueElement::setWidthPercentage):
+        * html/shadow/ProgressShadowElement.cpp:
+        (WebCore::ProgressValueElement::setWidthPercentage):
+        * html/shadow/SliderThumbElement.cpp:
+        (WebCore::TrackLimiterElement::create):
+        * rendering/RenderLayer.cpp:
+        (WebCore::RenderLayer::resize):
+        * rendering/RenderTextControlSingleLine.cpp:
+        (WebCore::RenderTextControlSingleLine::styleDidChange):
+        * svg/SVGFontFaceElement.cpp:
+        (WebCore::SVGFontFaceElement::SVGFontFaceElement):
+        (WebCore::SVGFontFaceElement::insertedIntoDocument):
+        (WebCore::SVGFontFaceElement::removeFromMappedElementSheet):
+
 2012-02-15  Daniel Cheng  <dcheng@chromium.org>
 
         dataTransfer.types (HTML5 drag & drop) should return DOMStringList
index 8f50c26..54aa2b4 100644 (file)
@@ -34,7 +34,7 @@ CSSFontFaceRule::CSSFontFaceRule(CSSStyleSheet* parent)
 CSSFontFaceRule::~CSSFontFaceRule()
 {
     if (m_style)
-        m_style->clearParentRule();
+        m_style->clearParentRule(this);
 }
 
 String CSSFontFaceRule::cssText() const
index 2ca0a10..ab858f2 100644 (file)
@@ -42,7 +42,7 @@ public:
 
     ~CSSFontFaceRule();
 
-    CSSStyleDeclaration* style() const { return m_style->ensureCSSStyleDeclaration(); }
+    CSSStyleDeclaration* style() const { return m_style->ensureRuleCSSStyleDeclaration(this); }
 
     String cssText() const;
 
index 7d99a45..d067e46 100644 (file)
@@ -38,6 +38,7 @@ CSSPageRule::CSSPageRule(CSSStyleSheet* parent, int sourceLine)
 
 CSSPageRule::~CSSPageRule()
 {
+    m_style->clearParentRule(this);
 }
 
 String CSSPageRule::selectorText() const
index af0b80d..7b09665 100644 (file)
@@ -41,7 +41,7 @@ public:
     }
     ~CSSPageRule();
 
-    CSSStyleDeclaration* style() const { return m_style->ensureCSSStyleDeclaration(); }
+    CSSStyleDeclaration* style() const { return m_style->ensureRuleCSSStyleDeclaration(this); }
 
     String selectorText() const;
     void setSelectorText(const String&);
@@ -52,7 +52,7 @@ public:
     StylePropertySet* properties() const { return m_style.get(); }
     
     void adoptSelectorVector(Vector<OwnPtr<CSSParserSelector> >& selectors) { m_selectorList.adoptSelectorVector(selectors); }
-    void setDeclaration(PassRefPtr<StylePropertySet> style) { ASSERT(style->parentRuleInternal() == this); m_style = style; }
+    void setDeclaration(PassRefPtr<StylePropertySet> style) { m_style = style; }
 
 private:
     CSSPageRule(CSSStyleSheet* parent, int sourceLine);
index 844fbf4..7acfbb0 100644 (file)
@@ -8768,7 +8768,7 @@ CSSRule* CSSParser::createStyleRule(Vector<OwnPtr<CSSParserSelector> >* selector
         rule->adoptSelectorVector(*selectors);
         if (m_hasFontFaceOnlyValues)
             deleteFontFaceOnlyValues();
-        rule->setDeclaration(StylePropertySet::create(rule.get(), m_parsedProperties, m_numParsedProperties));
+        rule->setDeclaration(StylePropertySet::create(m_styleSheet, m_parsedProperties, m_numParsedProperties));
         result = rule.get();
         m_parsedRules.append(rule.release());
         if (m_ruleRangeMap) {
@@ -8807,7 +8807,7 @@ CSSRule* CSSParser::createFontFaceRule()
         }
     }
     RefPtr<CSSFontFaceRule> rule = CSSFontFaceRule::create(m_styleSheet);
-    rule->setDeclaration(StylePropertySet::create(rule.get(), m_parsedProperties, m_numParsedProperties));
+    rule->setDeclaration(StylePropertySet::create(m_styleSheet, m_parsedProperties, m_numParsedProperties));
     clearProperties();
     CSSFontFaceRule* result = rule.get();
     m_parsedRules.append(rule.release());
@@ -8878,7 +8878,7 @@ CSSRule* CSSParser::createPageRule(PassOwnPtr<CSSParserSelector> pageSelector)
         Vector<OwnPtr<CSSParserSelector> > selectorVector;
         selectorVector.append(pageSelector);
         rule->adoptSelectorVector(selectorVector);
-        rule->setDeclaration(StylePropertySet::create(rule.get(), m_parsedProperties, m_numParsedProperties));
+        rule->setDeclaration(StylePropertySet::create(m_styleSheet, m_parsedProperties, m_numParsedProperties));
         pageRule = rule.get();
         m_parsedRules.append(rule.release());
     }
@@ -8962,7 +8962,7 @@ WebKitCSSKeyframeRule* CSSParser::createKeyframeRule(CSSParserValueList* keys)
 
     RefPtr<WebKitCSSKeyframeRule> keyframe = WebKitCSSKeyframeRule::create(m_styleSheet);
     keyframe->setKeyText(keyString);
-    keyframe->setDeclaration(StylePropertySet::create(keyframe.get(), m_parsedProperties, m_numParsedProperties));
+    keyframe->setDeclaration(StylePropertySet::create(m_styleSheet, m_parsedProperties, m_numParsedProperties));
 
     clearProperties();
 
index afa7bcb..fc4ba7e 100644 (file)
@@ -47,7 +47,7 @@ CSSStyleRule::CSSStyleRule(CSSStyleSheet* parent, int line)
 CSSStyleRule::~CSSStyleRule()
 {
     if (m_style)
-        m_style->clearParentRule();
+        m_style->clearParentRule(this);
     cleanup();
 }
 
index 6e7deaf..f70b9b2 100644 (file)
@@ -43,12 +43,12 @@ public:
     String selectorText() const;
     void setSelectorText(const String&);
 
-    CSSStyleDeclaration* style() const { return m_style->ensureCSSStyleDeclaration(); }
+    CSSStyleDeclaration* style() const { return m_style->ensureRuleCSSStyleDeclaration(this); }
 
     String cssText() const;
 
     void adoptSelectorVector(Vector<OwnPtr<CSSParserSelector> >& selectors) { m_selectorList.adoptSelectorVector(selectors); }
-    void setDeclaration(PassRefPtr<StylePropertySet> style) { ASSERT(style->parentRuleInternal() == this); m_style = style; }
+    void setDeclaration(PassRefPtr<StylePropertySet> style) { m_style = style; }
 
     const CSSSelectorList& selectorList() const { return m_selectorList; }
     StylePropertySet* declaration() const { return m_style.get(); }
index fdc0e74..d2d540d 100644 (file)
@@ -56,12 +56,16 @@ static PropertySetCSSOMWrapperMap& propertySetCSSOMWrapperMap()
 class PropertySetCSSStyleDeclaration : public CSSStyleDeclaration {
 public:
     PropertySetCSSStyleDeclaration(StylePropertySet* propertySet) : m_propertySet(propertySet) { }
+    
+    virtual StyledElement* parentElement() const { return 0; }
+    virtual void clearParentRule() { ASSERT_NOT_REACHED(); }
+    virtual void clearParentElement() { ASSERT_NOT_REACHED(); }
 
 private:
     virtual void ref() OVERRIDE { m_propertySet->ref(); }
     virtual void deref() OVERRIDE { m_propertySet->deref(); }
 
-    virtual CSSRule* parentRule() const OVERRIDE;
+    virtual CSSRule* parentRule() const OVERRIDE { return 0; };
     virtual unsigned length() const OVERRIDE;
     virtual String item(unsigned index) const OVERRIDE;
     virtual PassRefPtr<CSSValue> getPropertyCSSValue(const String& propertyName) OVERRIDE;
@@ -81,16 +85,52 @@ private:
     virtual CSSStyleSheet* parentStyleSheet() const OVERRIDE;
     virtual PassRefPtr<StylePropertySet> copy() const OVERRIDE;
     virtual PassRefPtr<StylePropertySet> makeMutable() OVERRIDE;
-    
+    virtual void setNeedsStyleRecalc() { };
+
+protected:
     StylePropertySet* m_propertySet;
 };
 
+class RuleCSSStyleDeclaration : public PropertySetCSSStyleDeclaration
+{
+public:
+    RuleCSSStyleDeclaration(StylePropertySet* propertySet, CSSRule* parentRule)
+        : PropertySetCSSStyleDeclaration(propertySet)
+        , m_parentRule(parentRule) 
+    {
+    }
+
+private:    
+    virtual CSSRule* parentRule() const { return m_parentRule; };
+    virtual void clearParentRule() { m_parentRule = 0; }
+    virtual void setNeedsStyleRecalc();
+    
+    CSSRule* m_parentRule;
+};
+
+class InlineCSSStyleDeclaration : public PropertySetCSSStyleDeclaration
+{
+public:
+    InlineCSSStyleDeclaration(StylePropertySet* propertySet, StyledElement* parentElement)
+        : PropertySetCSSStyleDeclaration(propertySet)
+        , m_parentElement(parentElement) 
+    {
+    }
+
+private:
+    virtual StyledElement* parentElement() const { return m_parentElement; }
+    virtual void clearParentElement() { m_parentElement = 0; }
+    virtual void setNeedsStyleRecalc();
+
+    StyledElement* m_parentElement;
+};
+
 namespace {
 
 class StyleAttributeMutationScope {
     WTF_MAKE_NONCOPYABLE(StyleAttributeMutationScope);
 public:
-    StyleAttributeMutationScope(StylePropertySet* decl)
+    StyleAttributeMutationScope(PropertySetCSSStyleDeclaration* decl)
     {
         ++s_scopeCount;
 
@@ -103,8 +143,6 @@ public:
         s_currentDecl = decl;
 
 #if ENABLE(MUTATION_OBSERVERS)
-        if (!s_currentDecl->isInlineStyleDeclaration())
-            return;
         if (!s_currentDecl->parentElement())
             return;
         m_mutationRecipients = MutationObserverInterestGroup::createForAttributesMutation(s_currentDecl->parentElement(), HTMLNames::styleAttr);
@@ -132,10 +170,10 @@ public:
             return;
         }
         // We have to clear internal state before calling Inspector's code.
-        StylePropertySet* localCopyStyleDecl = s_currentDecl;
+        PropertySetCSSStyleDeclaration* localCopyStyleDecl = s_currentDecl;
         s_currentDecl = 0;
         s_shouldNotifyInspector = false;
-        if (localCopyStyleDecl->isInlineStyleDeclaration() && localCopyStyleDecl->parentElement() && localCopyStyleDecl->parentElement()->document())
+        if (localCopyStyleDecl->parentElement() && localCopyStyleDecl->parentElement()->document())
             InspectorInstrumentation::didInvalidateStyleAttr(localCopyStyleDecl->parentElement()->document(), localCopyStyleDecl->parentElement());
     }
 
@@ -148,13 +186,12 @@ public:
 
     void didInvalidateStyleAttr()
     {
-        ASSERT(s_currentDecl->isInlineStyleDeclaration());
         s_shouldNotifyInspector = true;
     }
 
 private:
     static unsigned s_scopeCount;
-    static StylePropertySet* s_currentDecl;
+    static PropertySetCSSStyleDeclaration* s_currentDecl;
     static bool s_shouldNotifyInspector;
 #if ENABLE(MUTATION_OBSERVERS)
     static bool s_shouldDeliver;
@@ -165,7 +202,7 @@ private:
 };
 
 unsigned StyleAttributeMutationScope::s_scopeCount = 0;
-StylePropertySet* StyleAttributeMutationScope::s_currentDecl = 0;
+PropertySetCSSStyleDeclaration* StyleAttributeMutationScope::s_currentDecl = 0;
 bool StyleAttributeMutationScope::s_shouldNotifyInspector = false;
 #if ENABLE(MUTATION_OBSERVERS)
 bool StyleAttributeMutationScope::s_shouldDeliver = false;
@@ -175,39 +212,31 @@ bool StyleAttributeMutationScope::s_shouldDeliver = false;
 
 StylePropertySet::StylePropertySet()
     : m_strictParsing(false)
-    , m_parentIsElement(false)
-    , m_isInlineStyleDeclaration(false)
     , m_hasCSSOMWrapper(false)
-    , m_parent(static_cast<CSSRule*>(0))
+    , m_contextStyleSheet(0)
 {
 }
 
-StylePropertySet::StylePropertySet(CSSRule* parentRule)
-    : m_strictParsing(!parentRule || parentRule->useStrictParsing())
-    , m_parentIsElement(false)
-    , m_isInlineStyleDeclaration(false)
+StylePropertySet::StylePropertySet(const Vector<CSSProperty>& properties)
+    : m_properties(properties)
+    , m_strictParsing(true)
     , m_hasCSSOMWrapper(false)
-    , m_parent(parentRule)
+    , m_contextStyleSheet(0)
 {
+    m_properties.shrinkToFit();
 }
 
-StylePropertySet::StylePropertySet(CSSRule* parentRule, const Vector<CSSProperty>& properties)
-    : m_properties(properties)
-    , m_strictParsing(!parentRule || parentRule->useStrictParsing())
-    , m_parentIsElement(false)
-    , m_isInlineStyleDeclaration(false)
+StylePropertySet::StylePropertySet(CSSStyleSheet* contextStyleSheet)
+    : m_strictParsing(!contextStyleSheet || contextStyleSheet->useStrictParsing())
     , m_hasCSSOMWrapper(false)
-    , m_parent(parentRule)
+    , m_contextStyleSheet(contextStyleSheet)
 {
-    m_properties.shrinkToFit();
 }
 
-StylePropertySet::StylePropertySet(CSSRule* parentRule, const CSSProperty* const * properties, int numProperties)
-    : m_strictParsing(!parentRule || parentRule->useStrictParsing())
-    , m_parentIsElement(false)
-    , m_isInlineStyleDeclaration(false)
+StylePropertySet::StylePropertySet(CSSStyleSheet* contextStyleSheet, const CSSProperty* const * properties, int numProperties)
+    : m_strictParsing(!contextStyleSheet || contextStyleSheet->useStrictParsing())
     , m_hasCSSOMWrapper(false)
-    , m_parent(parentRule)
+    , m_contextStyleSheet(contextStyleSheet)
 {
     m_properties.reserveInitialCapacity(numProperties);
     HashMap<int, bool> candidates;
@@ -220,7 +249,7 @@ StylePropertySet::StylePropertySet(CSSRule* parentRule, const CSSProperty* const
         if (it != candidates.end()) {
             if (!important && it->second)
                 continue;
-            removeProperty(property->id(), false, false);
+            removeProperty(property->id());
         }
 
         m_properties.append(*property);
@@ -228,15 +257,6 @@ StylePropertySet::StylePropertySet(CSSRule* parentRule, const CSSProperty* const
     }
 }
 
-StylePropertySet::StylePropertySet(StyledElement* parentElement, bool isInlineStyle)
-    : m_strictParsing(false)
-    , m_parentIsElement(true)
-    , m_isInlineStyleDeclaration(isInlineStyle)
-    , m_hasCSSOMWrapper(false)
-    , m_parent(parentElement)
-{
-}
-
 StylePropertySet::~StylePropertySet()
 {
     ASSERT(!m_hasCSSOMWrapper || propertySetCSSOMWrapperMap().contains(this));
@@ -244,15 +264,6 @@ StylePropertySet::~StylePropertySet()
         propertySetCSSOMWrapperMap().remove(this);
 }
 
-CSSStyleSheet* StylePropertySet::contextStyleSheet() const
-{
-    if (m_parentIsElement) {
-        Document* document = m_parent.element ? m_parent.element->document() : 0;
-        return document ? document->elementSheet() : 0;
-    }
-    return m_parent.rule ? m_parent.rule->parentStyleSheet() : 0;
-}
-
 void StylePropertySet::copyPropertiesFrom(const StylePropertySet& other)
 {
     m_properties = other.m_properties;
@@ -671,68 +682,38 @@ PassRefPtr<CSSValue> StylePropertySet::getPropertyCSSValue(int propertyID) const
     return property ? property->value() : 0;
 }
 
-bool StylePropertySet::removeShorthandProperty(int propertyID, bool notifyChanged)
+bool StylePropertySet::removeShorthandProperty(int propertyID)
 {
     CSSPropertyLonghand longhand = longhandForProperty(propertyID);
     if (!longhand.length())
         return false;
-    return removePropertiesInSet(longhand.properties(), longhand.length(), notifyChanged);
+    return removePropertiesInSet(longhand.properties(), longhand.length());
 }
 
-String StylePropertySet::removeProperty(int propertyID, bool notifyChanged, bool returnText)
+bool StylePropertySet::removeProperty(int propertyID, String* returnText)
 {
-#if ENABLE(MUTATION_OBSERVERS)
-    StyleAttributeMutationScope mutationScope(this);
-#endif
-
-    if (removeShorthandProperty(propertyID, notifyChanged)) {
+    if (removeShorthandProperty(propertyID)) {
         // FIXME: Return an equivalent shorthand when possible.
-        return String();
+        if (returnText)
+            *returnText = "";
+        return true;
     }
 
     CSSProperty* foundProperty = findPropertyWithId(propertyID);
-    if (!foundProperty)
-        return String();
+    if (!foundProperty) {
+        if (returnText)
+            *returnText = "";
+        return false;
+    }
 
-    String value = returnText ? foundProperty->value()->cssText() : String();
+    if (returnText)
+        *returnText = foundProperty->value()->cssText();
 
     // A more efficient removal strategy would involve marking entries as empty
     // and sweeping them when the vector grows too big.
     m_properties.remove(foundProperty - m_properties.data());
-
-#if ENABLE(MUTATION_OBSERVERS)
-    mutationScope.enqueueMutationRecord();
-#endif
-
-    if (notifyChanged)
-        setNeedsStyleRecalc();
-
-    return value;
-}
-
-void StylePropertySet::setNeedsStyleRecalc()
-{
-    if (m_parentIsElement) {
-        StyledElement* element = parentElement();
-        if (!element)
-            return;
-
-        if (!m_isInlineStyleDeclaration) {
-            // If this is not an inline style, it's an attribute style, and we shouldn't mark the element for style recalc
-            // as that is handled by StyledElement::attributeChanged().
-            return;
-        }
-
-        element->setNeedsStyleRecalc(InlineStyleChange);
-        element->invalidateStyleAttribute();
-        StyleAttributeMutationScope(this).didInvalidateStyleAttr();
-        return;
-    }
-
-    if (CSSStyleSheet* styleSheet = contextStyleSheet()) {
-        if (Document* document = styleSheet->findDocument())
-            document->styleSelectorChanged(DeferRecalcStyle);
-    }
+    
+    return true;
 }
 
 bool StylePropertySet::propertyIsImportant(int propertyID) const
@@ -764,45 +745,23 @@ bool StylePropertySet::isPropertyImplicit(int propertyID) const
     return property ? property->isImplicit() : false;
 }
 
-bool StylePropertySet::setProperty(int propertyID, const String& value, bool important, bool notifyChanged)
+bool StylePropertySet::setProperty(int propertyID, const String& value, bool important)
 {
-#if ENABLE(MUTATION_OBSERVERS)
-    StyleAttributeMutationScope mutationScope(this);
-#endif
-
     // Setting the value to an empty string just removes the property in both IE and Gecko.
     // Setting it to null seems to produce less consistent results, but we treat it just the same.
     if (value.isEmpty()) {
-        removeProperty(propertyID, notifyChanged, false);
+        removeProperty(propertyID);
         return true;
     }
 
     // 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.
-    bool success = CSSParser::parseValue(this, propertyID, value, important, useStrictParsing());
-    if (!success) {
-        // CSS DOM requires raising SYNTAX_ERR here, but this is too dangerous for compatibility,
-        // see <http://bugs.webkit.org/show_bug.cgi?id=7296>.
-        return false;
-    }
-
-#if ENABLE(MUTATION_OBSERVERS)
-    mutationScope.enqueueMutationRecord();
-#endif
-
-    if (notifyChanged)
-        setNeedsStyleRecalc();
-
-    return true;
+    return CSSParser::parseValue(this, propertyID, value, important, useStrictParsing());
 }
 
 void StylePropertySet::setProperty(const CSSProperty& property, CSSProperty* slot)
 {
-#if ENABLE(MUTATION_OBSERVERS)
-    StyleAttributeMutationScope mutationScope(this);
-#endif
-
-    if (!removeShorthandProperty(property.id(), false)) {
+    if (!removeShorthandProperty(property.id())) {
         CSSProperty* toReplace = slot ? slot : findPropertyWithId(property.id());
         if (toReplace) {
             *toReplace = property;
@@ -810,85 +769,48 @@ void StylePropertySet::setProperty(const CSSProperty& property, CSSProperty* slo
         }
     }
     m_properties.append(property);
-
-#if ENABLE(MUTATION_OBSERVERS)
-    mutationScope.enqueueMutationRecord();
-#endif
 }
 
-bool StylePropertySet::setProperty(int propertyID, int identifier, bool important, bool notifyChanged)
+bool StylePropertySet::setProperty(int propertyID, int identifier, bool important)
 {
-    RefPtr<CSSPrimitiveValue> value;
-    if (m_parentIsElement && parentElement() && parentElement()->document())
-        value = parentElement()->document()->cssValuePool()->createIdentifierValue(identifier);
+    RefPtr<CSSPrimitiveValue> value;    
+    if (Document* document = m_contextStyleSheet ? m_contextStyleSheet->findDocument() : 0)
+        value = document->cssValuePool()->createIdentifierValue(identifier);
     else
         value = CSSPrimitiveValue::createIdentifier(identifier);
 
     setProperty(CSSProperty(propertyID, value.release(), important));
-    if (notifyChanged)
-        setNeedsStyleRecalc();
     return true;
 }
 
-bool StylePropertySet::setProperty(int propertyID, double value, CSSPrimitiveValue::UnitTypes unit, bool important, bool notifyChanged)
+bool StylePropertySet::setProperty(int propertyID, double value, CSSPrimitiveValue::UnitTypes unit, bool important)
 {
     CSSProperty property(propertyID, CSSPrimitiveValue::create(value, unit), important);
     setProperty(property);
-    if (notifyChanged)
-        setNeedsStyleRecalc();
     return true;
 }
 
 void StylePropertySet::parseDeclaration(const String& styleDeclaration)
 {
-#if ENABLE(MUTATION_OBSERVERS)
-    StyleAttributeMutationScope mutationScope(this);
-#endif
-
     m_properties.clear();
     CSSParser parser(useStrictParsing());
     parser.parseDeclaration(this, styleDeclaration);
-
-#if ENABLE(MUTATION_OBSERVERS)
-    mutationScope.enqueueMutationRecord();
-#endif
-
-    setNeedsStyleRecalc();
 }
 
 void StylePropertySet::addParsedProperties(const CSSProperty* const* properties, int numProperties)
 {
-#if ENABLE(MUTATION_OBSERVERS)
-    StyleAttributeMutationScope mutationScope(this);
-#endif
-
     m_properties.reserveCapacity(numProperties);
     for (int i = 0; i < numProperties; ++i)
         addParsedProperty(*properties[i]);
-
-#if ENABLE(MUTATION_OBSERVERS)
-    mutationScope.enqueueMutationRecord();
-#endif
-
-    // FIXME: This probably should have a call to setNeedsStyleRecalc() if something changed. We may also wish to add
-    // a notifyChanged argument to this function to follow the model of other functions in this class.
 }
 
 void StylePropertySet::addParsedProperty(const CSSProperty& property)
 {
-#if ENABLE(MUTATION_OBSERVERS)
-    StyleAttributeMutationScope mutationScope(this);
-#endif
-
     // Only add properties that have no !important counterpart present
     if (!propertyIsImportant(property.id()) || property.isImportant()) {
-        removeProperty(property.id(), false, false);
+        removeProperty(property.id());
         m_properties.append(property);
     }
-
-#if ENABLE(MUTATION_OBSERVERS)
-    mutationScope.enqueueMutationRecord();
-#endif
 }
 
 String StylePropertySet::asText() const
@@ -955,10 +877,6 @@ String StylePropertySet::asText() const
 
 void StylePropertySet::merge(const StylePropertySet* other, bool argOverridesOnConflict)
 {
-#if ENABLE(MUTATION_OBSERVERS)
-    StyleAttributeMutationScope mutationScope(this);
-#endif
-
     unsigned size = other->m_properties.size();
     for (unsigned n = 0; n < size; ++n) {
         const CSSProperty& toMerge = other->m_properties[n];
@@ -970,13 +888,6 @@ void StylePropertySet::merge(const StylePropertySet* other, bool argOverridesOnC
         } else
             m_properties.append(toMerge);
     }
-
-#if ENABLE(MUTATION_OBSERVERS)
-    mutationScope.enqueueMutationRecord();
-#endif
-
-    // FIXME: This probably should have a call to setNeedsStyleRecalc() if something changed. We may also wish to add
-    // a notifyChanged argument to this function to follow the model of other functions in this class.
 }
 
 void StylePropertySet::addSubresourceStyleURLs(ListHashSet<KURL>& urls)
@@ -1025,15 +936,11 @@ void StylePropertySet::removeBlockProperties()
     removePropertiesInSet(blockProperties, numBlockProperties);
 }
 
-bool StylePropertySet::removePropertiesInSet(const int* set, unsigned length, bool notifyChanged)
+bool StylePropertySet::removePropertiesInSet(const int* set, unsigned length)
 {
     if (m_properties.isEmpty())
         return false;
 
-#if ENABLE(MUTATION_OBSERVERS)
-    StyleAttributeMutationScope mutationScope(this);
-#endif
-
     // FIXME: This is always used with static sets and in that case constructing the hash repeatedly is pretty pointless.
     HashSet<int> toRemove;
     for (unsigned i = 0; i < length; ++i)
@@ -1055,14 +962,6 @@ bool StylePropertySet::removePropertiesInSet(const int* set, unsigned length, bo
 
     bool changed = newProperties.size() != m_properties.size();
     m_properties = newProperties;
-
-    if (notifyChanged) {
-#if ENABLE(MUTATION_OBSERVERS)
-        mutationScope.enqueueMutationRecord();
-#endif
-        setNeedsStyleRecalc();
-    }
-
     return changed;
 }
 
@@ -1120,7 +1019,7 @@ void StylePropertySet::removeEquivalentProperties(const CSSStyleDeclaration* sty
 
 PassRefPtr<StylePropertySet> StylePropertySet::copy() const
 {
-    return adoptRef(new StylePropertySet(0, m_properties));
+    return adoptRef(new StylePropertySet(m_properties));
 }
 
 PassRefPtr<StylePropertySet> StylePropertySet::copyPropertiesInSet(const int* set, unsigned length) const
@@ -1137,14 +1036,59 @@ PassRefPtr<StylePropertySet> StylePropertySet::copyPropertiesInSet(const int* se
 
 CSSStyleDeclaration* StylePropertySet::ensureCSSStyleDeclaration() const
 {
-    if (m_hasCSSOMWrapper)
+    if (m_hasCSSOMWrapper) {
+        ASSERT(!static_cast<CSSStyleDeclaration*>(propertySetCSSOMWrapperMap().get(this))->parentRule());
+        ASSERT(!propertySetCSSOMWrapperMap().get(this)->parentElement());
         return propertySetCSSOMWrapperMap().get(this);
+    }
     m_hasCSSOMWrapper = true;
     PropertySetCSSStyleDeclaration* cssomWrapper = new PropertySetCSSStyleDeclaration(const_cast<StylePropertySet*>(this));
     propertySetCSSOMWrapperMap().add(this, adoptPtr(cssomWrapper));
     return cssomWrapper;
 }
 
+CSSStyleDeclaration* StylePropertySet::ensureRuleCSSStyleDeclaration(const CSSRule* parentRule) const
+{
+    if (m_hasCSSOMWrapper) {
+        ASSERT(static_cast<CSSStyleDeclaration*>(propertySetCSSOMWrapperMap().get(this))->parentRule() == parentRule);
+        return propertySetCSSOMWrapperMap().get(this);
+    }
+    m_hasCSSOMWrapper = true;
+    PropertySetCSSStyleDeclaration* cssomWrapper = new RuleCSSStyleDeclaration(const_cast<StylePropertySet*>(this), const_cast<CSSRule*>(parentRule));
+    propertySetCSSOMWrapperMap().add(this, adoptPtr(cssomWrapper));
+    return cssomWrapper;
+}
+
+CSSStyleDeclaration* StylePropertySet::ensureInlineCSSStyleDeclaration(const StyledElement* parentElement) const
+{
+    if (m_hasCSSOMWrapper) {
+        ASSERT(propertySetCSSOMWrapperMap().get(this)->parentElement() == parentElement);
+        return propertySetCSSOMWrapperMap().get(this);
+    }
+    m_hasCSSOMWrapper = true;
+    PropertySetCSSStyleDeclaration* cssomWrapper = new InlineCSSStyleDeclaration(const_cast<StylePropertySet*>(this), const_cast<StyledElement*>(parentElement));
+    propertySetCSSOMWrapperMap().add(this, adoptPtr(cssomWrapper));
+    return cssomWrapper;
+}
+
+void StylePropertySet::clearParentRule(CSSRule* rule)
+{
+    m_contextStyleSheet = 0;
+    if (!m_hasCSSOMWrapper)
+        return;
+    ASSERT_UNUSED(rule, static_cast<CSSStyleDeclaration*>(propertySetCSSOMWrapperMap().get(this))->parentRule() == rule);
+    propertySetCSSOMWrapperMap().get(this)->clearParentRule();
+}
+
+void StylePropertySet::clearParentElement(StyledElement* element)
+{
+    m_contextStyleSheet = 0;
+    if (!m_hasCSSOMWrapper)
+        return;
+    ASSERT_UNUSED(element, propertySetCSSOMWrapperMap().get(this)->parentElement() == element);
+    propertySetCSSOMWrapperMap().get(this)->clearParentElement();
+}
+
 unsigned PropertySetCSSStyleDeclaration::length() const
 {
     return m_propertySet->propertyCount();
@@ -1157,11 +1101,6 @@ String PropertySetCSSStyleDeclaration::item(unsigned i) const
     return getPropertyName(static_cast<CSSPropertyID>(m_propertySet->propertyAt(i).id()));
 }
 
-CSSRule* PropertySetCSSStyleDeclaration::parentRule() const
-{
-    return m_propertySet->parentRuleInternal();
-}
-
 String PropertySetCSSStyleDeclaration::cssText() const
 {
     return m_propertySet->asText();
@@ -1169,9 +1108,17 @@ String PropertySetCSSStyleDeclaration::cssText() const
     
 void PropertySetCSSStyleDeclaration::setCssText(const String& text, ExceptionCode& ec)
 {
+#if ENABLE(MUTATION_OBSERVERS)
+    StyleAttributeMutationScope mutationScope(this);
+#endif
     ec = 0;
     // FIXME: Detect syntax errors and set ec.
     m_propertySet->parseDeclaration(text);
+
+    setNeedsStyleRecalc();
+#if ENABLE(MUTATION_OBSERVERS)
+    mutationScope.enqueueMutationRecord();    
+#endif
 }
 
 PassRefPtr<CSSValue> PropertySetCSSStyleDeclaration::getPropertyCSSValue(const String& propertyName)
@@ -1219,21 +1166,43 @@ bool PropertySetCSSStyleDeclaration::isPropertyImplicit(const String& propertyNa
 
 void PropertySetCSSStyleDeclaration::setProperty(const String& propertyName, const String& value, const String& priority, ExceptionCode& ec)
 {
+#if ENABLE(MUTATION_OBSERVERS)
+    StyleAttributeMutationScope mutationScope(this);
+#endif
     int propertyID = cssPropertyID(propertyName);
     if (!propertyID)
         return;
     bool important = priority.find("important", 0, false) != notFound;
     ec = 0;
-    m_propertySet->setProperty(propertyID, value, important, true);
+    bool changed = m_propertySet->setProperty(propertyID, value, important);
+    if (changed) {
+        // CSS DOM requires raising SYNTAX_ERR of parsing failed, but this is too dangerous for compatibility,
+        // see <http://bugs.webkit.org/show_bug.cgi?id=7296>.
+        setNeedsStyleRecalc();
+#if ENABLE(MUTATION_OBSERVERS)
+        mutationScope.enqueueMutationRecord();
+#endif
+    }
 }
 
 String PropertySetCSSStyleDeclaration::removeProperty(const String& propertyName, ExceptionCode& ec)
 {
+#if ENABLE(MUTATION_OBSERVERS)
+    StyleAttributeMutationScope mutationScope(this);
+#endif
     int propertyID = cssPropertyID(propertyName);
     if (!propertyID)
         return String();
     ec = 0;
-    return m_propertySet->removeProperty(propertyID, true, true);
+    String result;
+    bool changes = m_propertySet->removeProperty(propertyID, &result);
+    if (changes) {
+        setNeedsStyleRecalc();
+#if ENABLE(MUTATION_OBSERVERS)
+        mutationScope.enqueueMutationRecord();
+#endif
+    }
+    return result;
 }
 
 PassRefPtr<CSSValue> PropertySetCSSStyleDeclaration::getPropertyCSSValueInternal(CSSPropertyID propertyID)
@@ -1248,8 +1217,17 @@ String PropertySetCSSStyleDeclaration::getPropertyValueInternal(CSSPropertyID pr
 
 void PropertySetCSSStyleDeclaration::setPropertyInternal(CSSPropertyID propertyID, const String& value, bool important, ExceptionCode& ec)
 { 
+#if ENABLE(MUTATION_OBSERVERS)
+    StyleAttributeMutationScope mutationScope(this);
+#endif
     ec = 0;
-    m_propertySet->setProperty(propertyID, value, important, true);
+    bool changed = m_propertySet->setProperty(propertyID, value, important);
+    if (changed) {
+        setNeedsStyleRecalc();
+#if ENABLE(MUTATION_OBSERVERS)
+        mutationScope.enqueueMutationRecord();
+#endif
+    }
 }
 
 CSSStyleSheet* PropertySetCSSStyleDeclaration::parentStyleSheet() const
@@ -1272,6 +1250,24 @@ bool PropertySetCSSStyleDeclaration::cssPropertyMatches(const CSSProperty* prope
     return m_propertySet->propertyMatches(property);
 }
 
+void RuleCSSStyleDeclaration::setNeedsStyleRecalc()
+{
+    if (CSSStyleSheet* styleSheet = m_propertySet->contextStyleSheet()) {
+        if (Document* document = styleSheet->findDocument())
+            document->styleSelectorChanged(DeferRecalcStyle);
+    }
+}
+
+void InlineCSSStyleDeclaration::setNeedsStyleRecalc()
+{
+    if (!m_parentElement)
+        return;
+    m_parentElement->setNeedsStyleRecalc(InlineStyleChange);
+    m_parentElement->invalidateStyleAttribute();
+    StyleAttributeMutationScope(this).didInvalidateStyleAttr();
+    return;
+}
+
 class SameSizeAsStylePropertySet : public RefCounted<SameSizeAsStylePropertySet> {
     Vector<CSSProperty, 4> properties;
     unsigned bitfield;
index b9580e3..96db5d2 100644 (file)
@@ -42,25 +42,17 @@ public:
     {
         return adoptRef(new StylePropertySet);
     }
-    static PassRefPtr<StylePropertySet> create(CSSRule* parentRule)
+    static PassRefPtr<StylePropertySet> create(CSSStyleSheet* contextStyleSheet)
     {
-        return adoptRef(new StylePropertySet(parentRule));
+        return adoptRef(new StylePropertySet(contextStyleSheet));
     }
-    static PassRefPtr<StylePropertySet> create(CSSRule* parentRule, const CSSProperty* const* properties, int numProperties)
+    static PassRefPtr<StylePropertySet> create(CSSStyleSheet* contextStyleSheet, const CSSProperty* const* properties, int numProperties)
     {
-        return adoptRef(new StylePropertySet(parentRule, properties, numProperties));
+        return adoptRef(new StylePropertySet(contextStyleSheet, properties, numProperties));
     }
     static PassRefPtr<StylePropertySet> create(const Vector<CSSProperty>& properties)
     {
-        return adoptRef(new StylePropertySet(0, properties));
-    }
-    static PassRefPtr<StylePropertySet> createInline(StyledElement* element)
-    {
-        return adoptRef(new StylePropertySet(element, /*isInlineStyle*/ true));
-    }
-    static PassRefPtr<StylePropertySet> createAttributeStyle(StyledElement* element)
-    {
-        return adoptRef(new StylePropertySet(element, /*isInlineStyle*/ false));
+        return adoptRef(new StylePropertySet(properties));
     }
 
     unsigned propertyCount() const { return m_properties.size(); }
@@ -73,13 +65,12 @@ public:
     int getPropertyShorthand(int propertyID) const;
     bool isPropertyImplicit(int propertyID) const;
 
-    bool setProperty(int propertyID, int value, bool important = false) { return setProperty(propertyID, value, important, true); }
-    bool setProperty(int propertyId, double value, CSSPrimitiveValue::UnitTypes unit, bool important = false) { return setProperty(propertyId, value, unit, important, true); }
-    bool setProperty(int propertyID, const String& value, bool important = false) { return setProperty(propertyID, value, important, true); }
+    bool setProperty(int propertyID, int value, bool important = false);
+    bool setProperty(int propertyId, double value, CSSPrimitiveValue::UnitTypes unit, bool important = false);
+    bool setProperty(int propertyID, const String& value, bool important = false);
     void setProperty(const CSSProperty&, CSSProperty* slot = 0);
     
-    void removeProperty(int propertyID) { removeProperty(propertyID, true, false); }
-    String removeProperty(int propertyID, bool notifyChanged, bool returnText);
+    bool removeProperty(int propertyID, String* returnText = 0);
 
     // The following parses an entire new style declaration.
     void parseDeclaration(const String& styleDeclaration);
@@ -92,13 +83,12 @@ public:
 
     PassRefPtr<StylePropertySet> copyBlockProperties() const;
     void removeBlockProperties();
-    void removePropertiesInSet(const int* set, unsigned length) { removePropertiesInSet(set, length, true); }
+    bool removePropertiesInSet(const int* set, unsigned length);
 
     void merge(const StylePropertySet*, bool argOverridesOnConflict = true);
 
     void setStrictParsing(bool b) { m_strictParsing = b; }
     bool useStrictParsing() const { return m_strictParsing; }
-    bool isInlineStyleDeclaration() const { return m_isInlineStyleDeclaration; }
 
     void addSubresourceStyleURLs(ListHashSet<KURL>&);
 
@@ -111,24 +101,23 @@ public:
 
     PassRefPtr<StylePropertySet> copyPropertiesInSet(const int* set, unsigned length) const;
 
-    CSSRule* parentRuleInternal() const { return m_parentIsElement ? 0 : m_parent.rule; }
-    void clearParentRule() { ASSERT(!m_parentIsElement); m_parent.rule = 0; }
-
-    StyledElement* parentElement() const { ASSERT(m_parentIsElement); return m_parent.element; }
-    void clearParentElement() { ASSERT(m_parentIsElement); m_parent.element = 0; }
-
-    CSSStyleSheet* contextStyleSheet() const;
+    CSSStyleSheet* contextStyleSheet() const { return m_contextStyleSheet; }
+    void setContextStyleSheet(CSSStyleSheet* styleSheet) { m_contextStyleSheet = styleSheet; }
     
     String asText() const;
     
+    void clearParentRule(CSSRule* rule);
+    void clearParentElement(StyledElement* element);
+
     CSSStyleDeclaration* ensureCSSStyleDeclaration() const;
+    CSSStyleDeclaration* ensureRuleCSSStyleDeclaration(const CSSRule* parentRule) const;
+    CSSStyleDeclaration* ensureInlineCSSStyleDeclaration(const StyledElement* parentElement) const;
 
 private:
     StylePropertySet();
-    StylePropertySet(CSSRule* parentRule);
-    StylePropertySet(CSSRule* parentRule, const Vector<CSSProperty>&);
-    StylePropertySet(CSSRule* parentRule, const CSSProperty* const *, int numProperties);
-    StylePropertySet(StyledElement*, bool isInlineStyle);
+    StylePropertySet(const Vector<CSSProperty>&);
+    StylePropertySet(CSSStyleSheet* parentStyleSheet);
+    StylePropertySet(CSSStyleSheet* parentStyleSheet, const CSSProperty* const *, int numProperties);
 
     void setNeedsStyleRecalc();
 
@@ -144,11 +133,7 @@ private:
     template<size_t size> String getCommonValue(const int (&properties)[size]) const { return getCommonValue(properties, size); }
     template<size_t size> String getLayeredShorthandValue(const int (&properties)[size]) const { return getLayeredShorthandValue(properties, size); }
 
-    bool setProperty(int propertyID, int value, bool important, bool notifyChanged);
-    bool setProperty(int propertyId, double value, CSSPrimitiveValue::UnitTypes, bool important, bool notifyChanged);
-    bool setProperty(int propertyID, const String& value, bool important, bool notifyChanged);
-    bool removeShorthandProperty(int propertyID, bool notifyChanged);
-    bool removePropertiesInSet(const int* set, unsigned length, bool notifyChanged);
+    bool removeShorthandProperty(int propertyID);
     bool propertyMatches(const CSSProperty*) const;
 
     const CSSProperty* findPropertyWithId(int propertyId) const;
@@ -157,16 +142,9 @@ private:
     Vector<CSSProperty, 4> m_properties;
 
     bool m_strictParsing : 1;
-    bool m_parentIsElement : 1;
-    bool m_isInlineStyleDeclaration : 1;
     mutable bool m_hasCSSOMWrapper : 1;
 
-    union Parent {
-        Parent(CSSRule* rule) : rule(rule) { }
-        Parent(StyledElement* element) : element(element) { }
-        CSSRule* rule;
-        StyledElement* element;
-    } m_parent;
+    CSSStyleSheet* m_contextStyleSheet;
     
     friend class PropertySetCSSStyleDeclaration;
 };
index 36742a9..59f650f 100644 (file)
@@ -38,7 +38,7 @@ WebKitCSSKeyframeRule::WebKitCSSKeyframeRule(CSSStyleSheet* parent)
 WebKitCSSKeyframeRule::~WebKitCSSKeyframeRule()
 {
     if (m_style)
-        m_style->clearParentRule();
+        m_style->clearParentRule(this);
 }
 
 String WebKitCSSKeyframeRule::cssText() const
@@ -54,7 +54,6 @@ String WebKitCSSKeyframeRule::cssText() const
 
 void WebKitCSSKeyframeRule::setDeclaration(PassRefPtr<StylePropertySet> style)
 {
-    ASSERT(style->parentRuleInternal() == this);
     m_style = style;
 }
 
index a3d3a26..4a98573 100644 (file)
@@ -53,7 +53,7 @@ public:
 
     void getKeys(Vector<float>& keys) const   { parseKeyString(m_key, keys); }
 
-    CSSStyleDeclaration* style() const { return m_style ? m_style->ensureCSSStyleDeclaration() : 0; }
+    CSSStyleDeclaration* style() const { return m_style ? m_style->ensureRuleCSSStyleDeclaration(this) : 0; }
 
     String cssText() const;
 
index dc2799f..cb000a9 100644 (file)
@@ -45,17 +45,17 @@ StylePropertySet* ElementAttributeData::ensureInlineStyleDecl(StyledElement* ele
 {
     if (!m_inlineStyleDecl) {
         ASSERT(element->isStyledElement());
-        m_inlineStyleDecl = StylePropertySet::createInline(static_cast<StyledElement*>(element));
+        m_inlineStyleDecl = StylePropertySet::create(element->document()->elementSheet());
         m_inlineStyleDecl->setStrictParsing(element->isHTMLElement() && !element->document()->inQuirksMode());
     }
     return m_inlineStyleDecl.get();
 }
 
-void ElementAttributeData::destroyInlineStyleDecl()
+void ElementAttributeData::destroyInlineStyleDecl(StyledElement* element)
 {
     if (!m_inlineStyleDecl)
         return;
-    m_inlineStyleDecl->clearParentElement();
+    m_inlineStyleDecl->clearParentElement(element);
     m_inlineStyleDecl = 0;
 }
 
index 76d96fd..33e4ceb 100644 (file)
@@ -48,7 +48,7 @@ public:
 
     StylePropertySet* inlineStyleDecl() { return m_inlineStyleDecl.get(); }
     StylePropertySet* ensureInlineStyleDecl(StyledElement*);
-    void destroyInlineStyleDecl();
+    void destroyInlineStyleDecl(StyledElement* element);
 
     StylePropertySet* attributeStyle() const { return m_attributeStyle.get(); }
     void setAttributeStyle(PassRefPtr<StylePropertySet> style) { m_attributeStyle = style; }
index 7af98b2..277725b 100644 (file)
@@ -61,6 +61,26 @@ StyledElement::~StyledElement()
     destroyInlineStyleDecl();
 }
 
+void StyledElement::insertedIntoDocument()
+{
+    Element::insertedIntoDocument();
+
+    if (StylePropertySet* inlineStyle = inlineStyleDecl())
+        inlineStyle->setContextStyleSheet(document()->elementSheet());
+    if (StylePropertySet* attributeStyle = attributeData() ? attributeData()->attributeStyle() : 0)
+        attributeStyle->setContextStyleSheet(document()->elementSheet());
+}
+
+void StyledElement::removedFromDocument()
+{
+    Element::removedFromDocument();
+
+    if (StylePropertySet* inlineStyle = inlineStyleDecl())
+        inlineStyle->setContextStyleSheet(0);
+    if (StylePropertySet* attributeStyle = attributeData() ? attributeData()->attributeStyle() : 0)
+        attributeStyle->setContextStyleSheet(0);
+}
+
 void StyledElement::attributeChanged(Attribute* attr)
 {
     if (!(attr->name() == styleAttr && isSynchronizingStyleAttribute()))
@@ -106,9 +126,49 @@ void StyledElement::parseAttribute(Attribute* attr)
             ensureInlineStyleDecl()->parseDeclaration(attr->value());
         setIsStyleAttributeValid();
         setNeedsStyleRecalc();
+        InspectorInstrumentation::didInvalidateStyleAttr(document(), this);
     }
 }
 
+void StyledElement::inlineStyleChanged()
+{
+    setNeedsStyleRecalc(InlineStyleChange);
+    setIsStyleAttributeValid(false);
+    InspectorInstrumentation::didInvalidateStyleAttr(document(), this);
+}
+    
+bool StyledElement::setInlineStyleProperty(int propertyID, int value, bool important)
+{
+    bool changes = ensureInlineStyleDecl()->setProperty(propertyID, value, important);
+    if (changes)
+        inlineStyleChanged();
+    return changes;
+}
+
+bool StyledElement::setInlineStyleProperty(int propertyID, double value, CSSPrimitiveValue::UnitTypes unit, bool important)
+{
+    bool changes = ensureInlineStyleDecl()->setProperty(propertyID, value, unit, important);
+    if (changes)
+        inlineStyleChanged();
+    return changes;
+}
+
+bool StyledElement::setInlineStyleProperty(int propertyID, const String& value, bool important)
+{
+    bool changes = ensureInlineStyleDecl()->setProperty(propertyID, value, important);
+    if (changes)
+        inlineStyleChanged();
+    return changes;
+}
+
+bool StyledElement::removeInlineStyleProperty(int propertyID)
+{
+    bool changes = ensureInlineStyleDecl()->removeProperty(propertyID);
+    if (changes)
+        inlineStyleChanged();
+    return changes;
+}
+
 void StyledElement::addSubresourceAttributeURLs(ListHashSet<KURL>& urls) const
 {
     if (StylePropertySet* inlineStyle = inlineStyleDecl())
@@ -117,7 +177,7 @@ void StyledElement::addSubresourceAttributeURLs(ListHashSet<KURL>& urls) const
 
 void StyledElement::updateAttributeStyle()
 {
-    RefPtr<StylePropertySet> style = StylePropertySet::createAttributeStyle(this);
+    RefPtr<StylePropertySet> style = StylePropertySet::create(document()->elementSheet());
     for (unsigned i = 0; i < attributeCount(); ++i) {
         Attribute* attribute = attributeItem(i);
         collectStyleForAttribute(attribute, style.get());
index 7a76a5f..17bdf71 100644 (file)
@@ -41,7 +41,14 @@ public:
 
     StylePropertySet* inlineStyleDecl() const { return attributeData() ? attributeData()->inlineStyleDecl() : 0; }
     StylePropertySet* ensureInlineStyleDecl() { return ensureAttributeData()->ensureInlineStyleDecl(this); }
-    virtual CSSStyleDeclaration* style() OVERRIDE { return ensureInlineStyleDecl()->ensureCSSStyleDeclaration(); }
+    
+    // Unlike StylePropertySet setters, these implement invalidation.
+    bool setInlineStyleProperty(int propertyID, int value, bool important = false);
+    bool setInlineStyleProperty(int propertyID, double value, CSSPrimitiveValue::UnitTypes unit, bool important = false);
+    bool setInlineStyleProperty(int propertyID, const String& value, bool important = false);
+    bool removeInlineStyleProperty(int propertyID);
+    
+    virtual CSSStyleDeclaration* style() OVERRIDE { return ensureInlineStyleDecl()->ensureInlineCSSStyleDeclaration(this); }
 
     StylePropertySet* attributeStyle();
 
@@ -66,16 +73,20 @@ protected:
     // parseAttribute (called via setAttribute()) and
     // svgAttributeChanged (called when element.className.baseValue is set)
     void classAttributeChanged(const AtomicString& newClassString);
+    
+    virtual void insertedIntoDocument();
+    virtual void removedFromDocument();
 
 private:
     virtual void updateStyleAttribute() const;
+    void inlineStyleChanged();
 
     void updateAttributeStyle();
 
     void destroyInlineStyleDecl()
     {
         if (attributeData())
-            attributeData()->destroyInlineStyleDecl();
+            attributeData()->destroyInlineStyleDecl(this);
     }
 };
 
index 8bed54d..25444bb 100644 (file)
@@ -387,7 +387,7 @@ void ApplyStyleCommand::applyRelativeFontStyleChange(EditingStyle* style)
         float desiredFontSize = max(MinimumFontSize, startingFontSizes.get(node) + style->fontSizeDelta());
         RefPtr<CSSValue> value = inlineStyleDecl->getPropertyCSSValue(CSSPropertyFontSize);
         if (value) {
-            inlineStyleDecl->removeProperty(CSSPropertyFontSize);
+            element->removeInlineStyleProperty(CSSPropertyFontSize);
             currentFontSize = computedFontSize(node);
         }
         if (currentFontSize != desiredFontSize) {
index 2a3005e..e8b05ec 100644 (file)
@@ -205,17 +205,16 @@ void DeleteButtonController::createDeletionUI()
     RefPtr<HTMLDivElement> container = HTMLDivElement::create(m_target->document());
     container->setIdAttribute(containerElementIdentifier);
 
-    StylePropertySet* style = container->ensureInlineStyleDecl();
-    style->setProperty(CSSPropertyWebkitUserDrag, CSSValueNone);
-    style->setProperty(CSSPropertyWebkitUserSelect, CSSValueNone);
-    style->setProperty(CSSPropertyWebkitUserModify, CSSValueReadOnly);
-    style->setProperty(CSSPropertyVisibility, CSSValueHidden);
-    style->setProperty(CSSPropertyPosition, CSSValueAbsolute);
-    style->setProperty(CSSPropertyCursor, CSSValueDefault);
-    style->setProperty(CSSPropertyTop, "0");
-    style->setProperty(CSSPropertyRight, "0");
-    style->setProperty(CSSPropertyBottom, "0");
-    style->setProperty(CSSPropertyLeft, "0");
+    container->setInlineStyleProperty(CSSPropertyWebkitUserDrag, CSSValueNone);
+    container->setInlineStyleProperty(CSSPropertyWebkitUserSelect, CSSValueNone);
+    container->setInlineStyleProperty(CSSPropertyWebkitUserModify, CSSValueReadOnly);
+    container->setInlineStyleProperty(CSSPropertyVisibility, CSSValueHidden);
+    container->setInlineStyleProperty(CSSPropertyPosition, CSSValueAbsolute);
+    container->setInlineStyleProperty(CSSPropertyCursor, CSSValueDefault);
+    container->setInlineStyleProperty(CSSPropertyTop, "0");
+    container->setInlineStyleProperty(CSSPropertyRight, "0");
+    container->setInlineStyleProperty(CSSPropertyBottom, "0");
+    container->setInlineStyleProperty(CSSPropertyLeft, "0");
 
     RefPtr<HTMLDivElement> outline = HTMLDivElement::create(m_target->document());
     outline->setIdAttribute(outlineElementIdentifier);
@@ -223,16 +222,15 @@ void DeleteButtonController::createDeletionUI()
     const int borderWidth = 4;
     const int borderRadius = 6;
 
-    style = outline->ensureInlineStyleDecl();
-    style->setProperty(CSSPropertyPosition, CSSValueAbsolute);
-    style->setProperty(CSSPropertyZIndex, String::number(-1000000));
-    style->setProperty(CSSPropertyTop, String::number(-borderWidth - m_target->renderBox()->borderTop()) + "px");
-    style->setProperty(CSSPropertyRight, String::number(-borderWidth - m_target->renderBox()->borderRight()) + "px");
-    style->setProperty(CSSPropertyBottom, String::number(-borderWidth - m_target->renderBox()->borderBottom()) + "px");
-    style->setProperty(CSSPropertyLeft, String::number(-borderWidth - m_target->renderBox()->borderLeft()) + "px");
-    style->setProperty(CSSPropertyBorder, String::number(borderWidth) + "px solid rgba(0, 0, 0, 0.6)");
-    style->setProperty(CSSPropertyWebkitBorderRadius, String::number(borderRadius) + "px");
-    style->setProperty(CSSPropertyVisibility, CSSValueVisible);
+    outline->setInlineStyleProperty(CSSPropertyPosition, CSSValueAbsolute);
+    outline->setInlineStyleProperty(CSSPropertyZIndex, String::number(-1000000));
+    outline->setInlineStyleProperty(CSSPropertyTop, String::number(-borderWidth - m_target->renderBox()->borderTop()) + "px");
+    outline->setInlineStyleProperty(CSSPropertyRight, String::number(-borderWidth - m_target->renderBox()->borderRight()) + "px");
+    outline->setInlineStyleProperty(CSSPropertyBottom, String::number(-borderWidth - m_target->renderBox()->borderBottom()) + "px");
+    outline->setInlineStyleProperty(CSSPropertyLeft, String::number(-borderWidth - m_target->renderBox()->borderLeft()) + "px");
+    outline->setInlineStyleProperty(CSSPropertyBorder, String::number(borderWidth) + "px solid rgba(0, 0, 0, 0.6)");
+    outline->setInlineStyleProperty(CSSPropertyWebkitBorderRadius, String::number(borderRadius) + "px");
+    outline->setInlineStyleProperty(CSSPropertyVisibility, CSSValueVisible);
 
     ExceptionCode ec = 0;
     container->appendChild(outline.get(), ec);
@@ -247,14 +245,13 @@ void DeleteButtonController::createDeletionUI()
     const int buttonHeight = 30;
     const int buttonBottomShadowOffset = 2;
 
-    style = button->ensureInlineStyleDecl();
-    style->setProperty(CSSPropertyPosition, CSSValueAbsolute);
-    style->setProperty(CSSPropertyZIndex, String::number(1000000));
-    style->setProperty(CSSPropertyTop, String::number((-buttonHeight / 2) - m_target->renderBox()->borderTop() - (borderWidth / 2) + buttonBottomShadowOffset) + "px");
-    style->setProperty(CSSPropertyLeft, String::number((-buttonWidth / 2) - m_target->renderBox()->borderLeft() - (borderWidth / 2)) + "px");
-    style->setProperty(CSSPropertyWidth, String::number(buttonWidth) + "px");
-    style->setProperty(CSSPropertyHeight, String::number(buttonHeight) + "px");
-    style->setProperty(CSSPropertyVisibility, CSSValueVisible);
+    button->setInlineStyleProperty(CSSPropertyPosition, CSSValueAbsolute);
+    button->setInlineStyleProperty(CSSPropertyZIndex, String::number(1000000));
+    button->setInlineStyleProperty(CSSPropertyTop, String::number((-buttonHeight / 2) - m_target->renderBox()->borderTop() - (borderWidth / 2) + buttonBottomShadowOffset) + "px");
+    button->setInlineStyleProperty(CSSPropertyLeft, String::number((-buttonWidth / 2) - m_target->renderBox()->borderLeft() - (borderWidth / 2)) + "px");
+    button->setInlineStyleProperty(CSSPropertyWidth, String::number(buttonWidth) + "px");
+    button->setInlineStyleProperty(CSSPropertyHeight, String::number(buttonHeight) + "px");
+    button->setInlineStyleProperty(CSSPropertyVisibility, CSSValueVisible);
 
     float deviceScaleFactor = WebCore::deviceScaleFactor(m_frame);
     RefPtr<Image> buttonImage;
@@ -310,12 +307,12 @@ void DeleteButtonController::show(HTMLElement* element)
     }
 
     if (m_target->renderer()->style()->position() == StaticPosition) {
-        m_target->ensureInlineStyleDecl()->setProperty(CSSPropertyPosition, CSSValueRelative);
+        m_target->setInlineStyleProperty(CSSPropertyPosition, CSSValueRelative);
         m_wasStaticPositioned = true;
     }
 
     if (m_target->renderer()->style()->hasAutoZIndex()) {
-        m_target->ensureInlineStyleDecl()->setProperty(CSSPropertyZIndex, "0");
+        m_target->setInlineStyleProperty(CSSPropertyZIndex, "0");
         m_wasAutoZIndex = true;
     }
 }
@@ -331,9 +328,9 @@ void DeleteButtonController::hide()
 
     if (m_target) {
         if (m_wasStaticPositioned)
-            m_target->ensureInlineStyleDecl()->setProperty(CSSPropertyPosition, CSSValueStatic);
+            m_target->setInlineStyleProperty(CSSPropertyPosition, CSSValueStatic);
         if (m_wasAutoZIndex)
-            m_target->ensureInlineStyleDecl()->setProperty(CSSPropertyZIndex, CSSValueAuto);
+            m_target->setInlineStyleProperty(CSSPropertyZIndex, CSSValueAuto);
     }
 
     m_wasStaticPositioned = false;
index dfc9c99..3164d1f 100644 (file)
@@ -2745,10 +2745,13 @@ void Editor::applyEditingStyleToElement(Element* element) const
     ASSERT(element->isStyledElement());
     if (!element->isStyledElement())
         return;
-    StylePropertySet* style = static_cast<StyledElement*>(element)->ensureInlineStyleDecl();
-    style->setProperty(CSSPropertyWordWrap, "break-word", false);
-    style->setProperty(CSSPropertyWebkitNbspMode, "space", false);
-    style->setProperty(CSSPropertyWebkitLineBreak, "after-white-space", false);
+
+    // Mutate using the CSSOM wrapper so we get the same event behavior as a script.
+    CSSStyleDeclaration* style = static_cast<StyledElement*>(element)->style();
+    ExceptionCode ec;
+    style->setPropertyInternal(CSSPropertyWordWrap, "break-word", false, ec);
+    style->setPropertyInternal(CSSPropertyWebkitNbspMode, "space", false, ec);
+    style->setPropertyInternal(CSSPropertyWebkitLineBreak, "after-white-space", false, ec);
 }
 
 // Searches from the beginning of the document if nothing is selected.
index cbbba52..b85f97c 100644 (file)
@@ -45,13 +45,17 @@ void RemoveCSSPropertyCommand::doApply()
     StylePropertySet* style = m_element->inlineStyleDecl();
     m_oldValue = style->getPropertyValue(m_property);
     m_important = style->propertyIsImportant(m_property);
-    style->removeProperty(m_property);
+
+    // Mutate using the CSSOM wrapper so we get the same event behavior as a script.
+    ExceptionCode ec;
+    // Setting to null string removes the property. We don't have internal version of removeProperty.
+    m_element->style()->setPropertyInternal(m_property, String(), false, ec);
 }
 
 void RemoveCSSPropertyCommand::doUnapply()
 {
-    StylePropertySet* style = m_element->inlineStyleDecl();
-    style->setProperty(m_property, m_oldValue, m_important);
+    ExceptionCode ec;
+    m_element->style()->setPropertyInternal(m_property, m_oldValue, m_important, ec);
 }
 
 #ifndef NDEBUG
index b9f305e..ef8033c 100644 (file)
@@ -531,10 +531,13 @@ void ReplaceSelectionCommand::removeRedundantStylesAndKeepStyleSpanInline(Insert
             // FIXME: Hyatt is concerned that selectively using display:inline will give inconsistent
             // results. We already know one issue because td elements ignore their display property
             // in quirks mode (which Mail.app is always in). We should look for an alternative.
+            
+            // Mutate using the CSSOM wrapper so we get the same event behavior as a script.
+            ExceptionCode ec;
             if (isBlock(element))
-                element->ensureInlineStyleDecl()->setProperty(CSSPropertyDisplay, CSSValueInline);
+                element->style()->setPropertyInternal(CSSPropertyDisplay, "inline", false, ec);
             if (element->renderer() && element->renderer()->style()->isFloating())
-                element->ensureInlineStyleDecl()->setProperty(CSSPropertyFloat, CSSValueNone);
+                element->style()->setPropertyInternal(CSSPropertyFloat, "none", false, ec);
         }
     }
 }
index beabee8..631ebe0 100644 (file)
@@ -180,7 +180,7 @@ void ColorInputType::updateColorSwatch()
     if (!colorSwatch)
         return;
 
-    colorSwatch->ensureInlineStyleDecl()->setProperty(CSSPropertyBackgroundColor, element()->value(), false);
+    colorSwatch->setInlineStyleProperty(CSSPropertyBackgroundColor, element()->value(), false);
 }
 
 HTMLElement* ColorInputType::shadowColorSwatch() const
index a5a3c73..fcfd967 100644 (file)
@@ -153,7 +153,7 @@ void HTMLTextFormControlElement::updatePlaceholderVisibility(bool placeholderVal
     if (!placeholder)
         return;
     ExceptionCode ec = 0;
-    placeholder->ensureInlineStyleDecl()->setProperty(CSSPropertyVisibility, placeholderShouldBeVisible() ? "visible" : "hidden", ec);
+    placeholder->setInlineStyleProperty(CSSPropertyVisibility, placeholderShouldBeVisible() ? "visible" : "hidden", ec);
     ASSERT(!ec);
 }
 
index dc95a0d..eb8e821 100644 (file)
@@ -253,7 +253,7 @@ void ImageDocument::resizeImageToFit()
     m_imageElement->setWidth(static_cast<int>(imageSize.width() * scale));
     m_imageElement->setHeight(static_cast<int>(imageSize.height() * scale));
     
-    m_imageElement->ensureInlineStyleDecl()->setProperty(CSSPropertyCursor, "-webkit-zoom-in", false);
+    m_imageElement->setInlineStyleProperty(CSSPropertyCursor, "-webkit-zoom-in", false);
 }
 
 void ImageDocument::imageClicked(int x, int y)
@@ -307,9 +307,9 @@ void ImageDocument::restoreImageSize()
     m_imageElement->setHeight(imageSize.height());
     
     if (imageFitsInWindow())
-        m_imageElement->ensureInlineStyleDecl()->removeProperty(CSSPropertyCursor);
+        m_imageElement->removeInlineStyleProperty(CSSPropertyCursor);
     else
-        m_imageElement->ensureInlineStyleDecl()->setProperty(CSSPropertyCursor, "-webkit-zoom-out", false);
+        m_imageElement->setInlineStyleProperty(CSSPropertyCursor, "-webkit-zoom-out", false);
         
     m_didShrinkImage = false;
 }
@@ -340,9 +340,9 @@ void ImageDocument::windowSizeChanged()
     // and set it to a zoom out cursor if the image doesn't fit
     if (!m_shouldShrinkImage) {
         if (fitsInWindow)
-            m_imageElement->ensureInlineStyleDecl()->removeProperty(CSSPropertyCursor);
+            m_imageElement->removeInlineStyleProperty(CSSPropertyCursor);
         else
-            m_imageElement->ensureInlineStyleDecl()->setProperty(CSSPropertyCursor, "-webkit-zoom-out", false);
+            m_imageElement->setInlineStyleProperty(CSSPropertyCursor, "-webkit-zoom-out", false);
         return;
     }
     
index bb8a195..7653951 100644 (file)
@@ -120,14 +120,13 @@ static void adjustBubblePosition(const LayoutRect& hostRect, HTMLElement* bubble
         hostY -= containerLocation.y() + container->borderTop();
     }
 
-    StylePropertySet* style = bubble->ensureInlineStyleDecl();
-    style->setProperty(CSSPropertyTop, hostY + hostRect.height(), CSSPrimitiveValue::CSS_PX);
+    bubble->setInlineStyleProperty(CSSPropertyTop, hostY + hostRect.height(), CSSPrimitiveValue::CSS_PX);
     // The 'left' value of ::-webkit-validation-bubble-arrow.
     const int bubbleArrowTopOffset = 32;
     double bubbleX = hostX;
     if (hostRect.width() / 2 < bubbleArrowTopOffset)
         bubbleX = max(hostX + hostRect.width() / 2 - bubbleArrowTopOffset, 0.0);
-    style->setProperty(CSSPropertyLeft, bubbleX, CSSPrimitiveValue::CSS_PX);
+    bubble->setInlineStyleProperty(CSSPropertyLeft, bubbleX, CSSPrimitiveValue::CSS_PX);
 }
 
 void ValidationMessage::buildBubbleTree(Timer<ValidationMessage>*)
@@ -138,7 +137,7 @@ void ValidationMessage::buildBubbleTree(Timer<ValidationMessage>*)
     m_bubble->setShadowPseudoId("-webkit-validation-bubble");
     // Need to force position:absolute because RenderMenuList doesn't assume it
     // contains non-absolute or non-fixed renderers as children.
-    m_bubble->ensureInlineStyleDecl()->setProperty(CSSPropertyPosition, CSSValueAbsolute);
+    m_bubble->setInlineStyleProperty(CSSPropertyPosition, CSSValueAbsolute);
     ExceptionCode ec = 0;
     host->ensureShadowRoot()->appendChild(m_bubble.get(), ec);
     ASSERT(!ec);
index b6ec475..1f69e3c 100644 (file)
@@ -92,12 +92,12 @@ MediaControlElement::MediaControlElement(Document* document)
 
 void MediaControlElement::show()
 {
-    ensureInlineStyleDecl()->removeProperty(CSSPropertyDisplay);
+    removeInlineStyleProperty(CSSPropertyDisplay);
 }
 
 void MediaControlElement::hide()
 {
-    ensureInlineStyleDecl()->setProperty(CSSPropertyDisplay, CSSValueNone);
+    setInlineStyleProperty(CSSPropertyDisplay, CSSValueNone);
 }
 
 // ----------------------------
@@ -175,17 +175,15 @@ void MediaControlPanelElement::endDrag()
 
 void MediaControlPanelElement::setPosition(const LayoutPoint& position)
 {
-    StylePropertySet* style = ensureInlineStyleDecl();
-
     double left = position.x();
     double top = position.y();
 
     // Set the left and top to control the panel's position; this depends on it being absolute positioned.
     // Set the margin to zero since the position passed in will already include the effect of the margin.
-    style->setProperty(CSSPropertyLeft, left, CSSPrimitiveValue::CSS_PX);
-    style->setProperty(CSSPropertyTop, top, CSSPrimitiveValue::CSS_PX);
-    style->setProperty(CSSPropertyMarginLeft, 0.0, CSSPrimitiveValue::CSS_PX);
-    style->setProperty(CSSPropertyMarginTop, 0.0, CSSPrimitiveValue::CSS_PX);
+    setInlineStyleProperty(CSSPropertyLeft, left, CSSPrimitiveValue::CSS_PX);
+    setInlineStyleProperty(CSSPropertyTop, top, CSSPrimitiveValue::CSS_PX);
+    setInlineStyleProperty(CSSPropertyMarginLeft, 0.0, CSSPrimitiveValue::CSS_PX);
+    setInlineStyleProperty(CSSPropertyMarginTop, 0.0, CSSPrimitiveValue::CSS_PX);
 
     ExceptionCode ignored;
     classList()->add("dragged", ignored);
@@ -193,12 +191,10 @@ void MediaControlPanelElement::setPosition(const LayoutPoint& position)
 
 void MediaControlPanelElement::resetPosition()
 {
-    StylePropertySet* style = ensureInlineStyleDecl();
-
-    style->removeProperty(CSSPropertyLeft);
-    style->removeProperty(CSSPropertyTop);
-    style->removeProperty(CSSPropertyMarginLeft);
-    style->removeProperty(CSSPropertyMarginTop);
+    removeInlineStyleProperty(CSSPropertyLeft);
+    removeInlineStyleProperty(CSSPropertyTop);
+    removeInlineStyleProperty(CSSPropertyMarginLeft);
+    removeInlineStyleProperty(CSSPropertyMarginTop);
 
     ExceptionCode ignored;
     classList()->remove("dragged", ignored);
@@ -211,10 +207,9 @@ void MediaControlPanelElement::makeOpaque()
 
     double duration = document()->page() ? document()->page()->theme()->mediaControlsFadeInDuration() : 0;
 
-    StylePropertySet* style = ensureInlineStyleDecl();
-    style->setProperty(CSSPropertyWebkitTransitionProperty, CSSPropertyOpacity);
-    style->setProperty(CSSPropertyWebkitTransitionDuration, duration, CSSPrimitiveValue::CSS_S);
-    style->setProperty(CSSPropertyOpacity, 1.0, CSSPrimitiveValue::CSS_NUMBER);
+    setInlineStyleProperty(CSSPropertyWebkitTransitionProperty, CSSPropertyOpacity);
+    setInlineStyleProperty(CSSPropertyWebkitTransitionDuration, duration, CSSPrimitiveValue::CSS_S);
+    setInlineStyleProperty(CSSPropertyOpacity, 1.0, CSSPrimitiveValue::CSS_NUMBER);
 
     m_opaque = true;
 }
@@ -224,10 +219,9 @@ void MediaControlPanelElement::makeTransparent()
     if (!m_opaque)
         return;
 
-    StylePropertySet* style = ensureInlineStyleDecl();
-    style->setProperty(CSSPropertyWebkitTransitionProperty, CSSPropertyOpacity);
-    style->setProperty(CSSPropertyWebkitTransitionDuration, document()->page()->theme()->mediaControlsFadeOutDuration(), CSSPrimitiveValue::CSS_S);
-    style->setProperty(CSSPropertyOpacity, 0.0, CSSPrimitiveValue::CSS_NUMBER);
+    setInlineStyleProperty(CSSPropertyWebkitTransitionProperty, CSSPropertyOpacity);
+    setInlineStyleProperty(CSSPropertyWebkitTransitionDuration, document()->page()->theme()->mediaControlsFadeOutDuration(), CSSPrimitiveValue::CSS_S);
+    setInlineStyleProperty(CSSPropertyOpacity, 0.0, CSSPrimitiveValue::CSS_NUMBER);
 
     m_opaque = false;
 }
@@ -434,12 +428,12 @@ MediaControlInputElement::MediaControlInputElement(Document* document, MediaCont
 
 void MediaControlInputElement::show()
 {
-    ensureInlineStyleDecl()->removeProperty(CSSPropertyDisplay);
+    removeInlineStyleProperty(CSSPropertyDisplay);
 }
 
 void MediaControlInputElement::hide()
 {
-    ensureInlineStyleDecl()->setProperty(CSSPropertyDisplay, CSSValueNone);
+    setInlineStyleProperty(CSSPropertyDisplay, CSSValueNone);
 }
 
 
@@ -1211,13 +1205,13 @@ void MediaControlTextTrackContainerElement::updateSizes()
     float fontSize = m_videoDisplaySize.size().height() * videoHeightFontSizePercentage;
     if (fontSize != m_fontSize) {
         m_fontSize = fontSize;
-        ensureInlineStyleDecl()->setProperty(CSSPropertyFontSize, String::number(fontSize) + "px");
+        setInlineStyleProperty(CSSPropertyFontSize, String::number(fontSize) + "px");
     }
 
     LayoutUnit bottom = static_cast<LayoutUnit>(m_videoDisplaySize.y() + m_videoDisplaySize.height() - (m_videoDisplaySize.height() * trackBottomMultiplier));
     if (bottom != m_bottom) {
         m_bottom = bottom;
-        ensureInlineStyleDecl()->setProperty(CSSPropertyBottom, String::number(bottom) + "px");
+        setInlineStyleProperty(CSSPropertyBottom, String::number(bottom) + "px");
     }
 }
 
index 4105354..bc5ea62 100644 (file)
@@ -93,7 +93,7 @@ const AtomicString& MeterValueElement::shadowPseudoId() const
 
 void MeterValueElement::setWidthPercentage(double width)
 {
-    ensureInlineStyleDecl()->setProperty(CSSPropertyWidth, width, CSSPrimitiveValue::CSS_PERCENTAGE);
+    setInlineStyleProperty(CSSPropertyWidth, width, CSSPrimitiveValue::CSS_PERCENTAGE);
 }
 
 
index ecd3554..5485713 100644 (file)
@@ -73,7 +73,7 @@ const AtomicString& ProgressValueElement::shadowPseudoId() const
 
 void ProgressValueElement::setWidthPercentage(double width)
 {
-    ensureInlineStyleDecl()->setProperty(CSSPropertyWidth, width, CSSPrimitiveValue::CSS_PERCENTAGE);
+    setInlineStyleProperty(CSSPropertyWidth, width, CSSPrimitiveValue::CSS_PERCENTAGE);
 }
 
 }
index abf5b35..7558924 100644 (file)
@@ -335,9 +335,8 @@ PassRefPtr<TrackLimiterElement> TrackLimiterElement::create(Document* document)
 {
     RefPtr<TrackLimiterElement> element = adoptRef(new TrackLimiterElement(document));
 
-    StylePropertySet* style = element->ensureInlineStyleDecl();
-    style->setProperty(CSSPropertyVisibility, CSSValueHidden);
-    style->setProperty(CSSPropertyPosition, CSSValueStatic);
+    element->setInlineStyleProperty(CSSPropertyVisibility, CSSValueHidden);
+    element->setInlineStyleProperty(CSSPropertyPosition, CSSValueStatic);
 
     return element.release();
 }
index 02d23c3..1184cc0 100644 (file)
@@ -1738,29 +1738,29 @@ void RenderLayer::resize(const PlatformMouseEvent& evt, const LayoutSize& oldOff
     LayoutSize difference = (currentSize + newOffset - adjustedOldOffset).expandedTo(minimumSize) - currentSize;
 
     ASSERT(element->isStyledElement());
-    StylePropertySet* styleDeclaration = static_cast<StyledElement*>(element)->ensureInlineStyleDecl();
+    StyledElement* styledElement = static_cast<StyledElement*>(element);
     bool isBoxSizingBorder = renderer->style()->boxSizing() == BORDER_BOX;
 
     if (resize != RESIZE_VERTICAL && difference.width()) {
         if (element->isFormControlElement()) {
             // Make implicit margins from the theme explicit (see <http://bugs.webkit.org/show_bug.cgi?id=9547>).
-            styleDeclaration->setProperty(CSSPropertyMarginLeft, String::number(renderer->marginLeft() / zoomFactor) + "px", false);
-            styleDeclaration->setProperty(CSSPropertyMarginRight, String::number(renderer->marginRight() / zoomFactor) + "px", false);
+            styledElement->setInlineStyleProperty(CSSPropertyMarginLeft, String::number(renderer->marginLeft() / zoomFactor) + "px", false);
+            styledElement->setInlineStyleProperty(CSSPropertyMarginRight, String::number(renderer->marginRight() / zoomFactor) + "px", false);
         }
         LayoutUnit baseWidth = renderer->width() - (isBoxSizingBorder ? zeroLayoutUnit : renderer->borderAndPaddingWidth());
         baseWidth = baseWidth / zoomFactor;
-        styleDeclaration->setProperty(CSSPropertyWidth, String::number(baseWidth + difference.width()) + "px", false);
+        styledElement->setInlineStyleProperty(CSSPropertyWidth, String::number(baseWidth + difference.width()) + "px", false);
     }
 
     if (resize != RESIZE_HORIZONTAL && difference.height()) {
         if (element->isFormControlElement()) {
             // Make implicit margins from the theme explicit (see <http://bugs.webkit.org/show_bug.cgi?id=9547>).
-            styleDeclaration->setProperty(CSSPropertyMarginTop, String::number(renderer->marginTop() / zoomFactor) + "px", false);
-            styleDeclaration->setProperty(CSSPropertyMarginBottom, String::number(renderer->marginBottom() / zoomFactor) + "px", false);
+            styledElement->setInlineStyleProperty(CSSPropertyMarginTop, String::number(renderer->marginTop() / zoomFactor) + "px", false);
+            styledElement->setInlineStyleProperty(CSSPropertyMarginBottom, String::number(renderer->marginBottom() / zoomFactor) + "px", false);
         }
         LayoutUnit baseHeight = renderer->height() - (isBoxSizingBorder ? zeroLayoutUnit : renderer->borderAndPaddingHeight());
         baseHeight = baseHeight / zoomFactor;
-        styleDeclaration->setProperty(CSSPropertyHeight, String::number(baseHeight + difference.height()) + "px", false);
+        styledElement->setInlineStyleProperty(CSSPropertyHeight, String::number(baseHeight + difference.height()) + "px", false);
     }
 
     document->updateLayout();
index ef34670..7891a3f 100644 (file)
@@ -332,7 +332,7 @@ void RenderTextControlSingleLine::styleDidChange(StyleDifference diff, const Ren
         containerRenderer->style()->setWidth(Length());
     }
     if (HTMLElement* placeholder = inputElement()->placeholderElement())
-        placeholder->ensureInlineStyleDecl()->setProperty(CSSPropertyTextOverflow, textShouldBeTruncated() ? CSSValueEllipsis : CSSValueClip);
+        placeholder->setInlineStyleProperty(CSSPropertyTextOverflow, textShouldBeTruncated() ? CSSValueEllipsis : CSSValueClip);
     setHasOverflowClip(false);
 }
 
index 51fbc44..af78956 100644 (file)
@@ -51,7 +51,7 @@ inline SVGFontFaceElement::SVGFontFaceElement(const QualifiedName& tagName, Docu
     , m_fontFaceRule(CSSFontFaceRule::create())
 {
     ASSERT(hasTagName(font_faceTag));
-    RefPtr<StylePropertySet> styleDeclaration = StylePropertySet::create(m_fontFaceRule.get());
+    RefPtr<StylePropertySet> styleDeclaration = StylePropertySet::create();
     styleDeclaration->setStrictParsing(true);
     m_fontFaceRule->setDeclaration(styleDeclaration.release());
 }
@@ -321,6 +321,7 @@ void SVGFontFaceElement::insertedIntoDocument()
     SVGElement::insertedIntoDocument();
     document()->mappedElementSheet()->append(m_fontFaceRule);
     m_fontFaceRule->setParentStyleSheet(document()->mappedElementSheet());
+    m_fontFaceRule->declaration()->setContextStyleSheet(document()->mappedElementSheet());
     rebuildFontFace();
 }
 
@@ -348,6 +349,7 @@ void SVGFontFaceElement::removeFromMappedElementSheet()
             break;
         }
     }
+    m_fontFaceRule->declaration()->setContextStyleSheet(0);
     document()->styleSelectorChanged(DeferRecalcStyle);
 }