Commit 241a650f authored by antti@apple.com's avatar antti@apple.com
Browse files

Eliminate CSSElementStyleDeclaration

https://bugs.webkit.org/show_bug.cgi?id=76848

Reviewed by Andreas Kling.

CSSElementStyleDeclaration has little functionality. It can merge with CSSMutableStyleDeclaration simplifying the code.
        
Having an element parent is mutually exclusive with having a css rule parent. We can keep them in a union. This also
shrinks all inline style declarations by one pointer.

* CMakeLists.txt:
* GNUmakefile.list.am:
* Target.pri:
* WebCore.gypi:
* WebCore.vcproj/WebCore.vcproj:
* WebCore.xcodeproj/project.pbxproj:
* bindings/js/JSDOMBinding.h:
(WebCore::root):
* css/CSSAllInOne.cpp:
* css/CSSElementStyleDeclaration.cpp: Removed.
* css/CSSElementStyleDeclaration.h: Removed.
* css/CSSMutableStyleDeclaration.cpp:
(WebCore::CSSMutableStyleDeclaration::setNeedsStyleRecalc):
* css/CSSMutableStyleDeclaration.h:
(WebCore::CSSMutableStyleDeclaration::createInline):
(WebCore::CSSMutableStyleDeclaration::createForSVGFontFaceElement):
(WebCore::CSSMutableStyleDeclaration::CSSMutableStyleDeclaration):
* css/CSSStyleDeclaration.cpp:
(WebCore::CSSStyleDeclaration::CSSStyleDeclaration):
(WebCore::CSSStyleDeclaration::parentStyleSheet):
        
    Merge the CSSElementStyleDeclaration::styleSheet() logic here.
        
* css/CSSStyleDeclaration.h:
(WebCore::CSSStyleDeclaration::parentRule):
(WebCore::CSSStyleDeclaration::clearParentRule):
(WebCore::CSSStyleDeclaration::parentElement):
(WebCore::CSSStyleDeclaration::clearParentElement):
* css/CSSStyleRule.cpp:
(WebCore::CSSStyleRule::setSelectorText):
        
    CSSStyleRule's style declaration can't have isElementStyleDeclaration set, the dead code can be removed.
    This is asserted in setDeclaration() and again implicitly in the destructor (by clearParentRule()).
        
* dom/StyledElement.cpp:
(WebCore::StyledElement::createInlineStyleDecl):
(WebCore::StyledElement::destroyInlineStyleDecl):
(WebCore::StyledElement::ensureInlineStyleDecl):
(WebCore::StyledElement::copyNonAttributeProperties):
* dom/StyledElement.h:
(WebCore::StyledElement::inlineStyleDecl):
* editing/ApplyStyleCommand.cpp:
(WebCore::ApplyStyleCommand::applyRelativeFontStyleChange):
(WebCore::ApplyStyleCommand::addInlineStyleIfNeeded):
* editing/DeleteButtonController.cpp:
(WebCore::DeleteButtonController::createDeletionUI):
* html/ValidationMessage.cpp:
(WebCore::adjustBubblePosition):
* html/shadow/MediaControlElements.cpp:
(WebCore::MediaControlPanelElement::setPosition):
(WebCore::MediaControlPanelElement::resetPosition):
(WebCore::MediaControlPanelElement::makeOpaque):
(WebCore::MediaControlPanelElement::makeTransparent):
* html/shadow/SliderThumbElement.cpp:
(WebCore::TrackLimiterElement::create):
* svg/SVGFontFaceElement.cpp:
(WebCore::SVGFontFaceElement::SVGFontFaceElement):



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@105642 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 2436e67e
......@@ -434,7 +434,6 @@ SET(WebCore_SOURCES
css/CSSComputedStyleDeclaration.cpp
css/CSSCrossfadeValue.cpp
css/CSSCursorImageValue.cpp
css/CSSElementStyleDeclaration.cpp
css/CSSFlexValue.cpp
css/CSSFontFace.cpp
css/CSSFontFaceRule.cpp
......
2012-01-23 Antti Koivisto <antti@apple.com>
Eliminate CSSElementStyleDeclaration
https://bugs.webkit.org/show_bug.cgi?id=76848
Reviewed by Andreas Kling.
CSSElementStyleDeclaration has little functionality. It can merge with CSSMutableStyleDeclaration simplifying the code.
Having an element parent is mutually exclusive with having a css rule parent. We can keep them in a union. This also
shrinks all inline style declarations by one pointer.
* CMakeLists.txt:
* GNUmakefile.list.am:
* Target.pri:
* WebCore.gypi:
* WebCore.vcproj/WebCore.vcproj:
* WebCore.xcodeproj/project.pbxproj:
* bindings/js/JSDOMBinding.h:
(WebCore::root):
* css/CSSAllInOne.cpp:
* css/CSSElementStyleDeclaration.cpp: Removed.
* css/CSSElementStyleDeclaration.h: Removed.
* css/CSSMutableStyleDeclaration.cpp:
(WebCore::CSSMutableStyleDeclaration::setNeedsStyleRecalc):
* css/CSSMutableStyleDeclaration.h:
(WebCore::CSSMutableStyleDeclaration::createInline):
(WebCore::CSSMutableStyleDeclaration::createForSVGFontFaceElement):
(WebCore::CSSMutableStyleDeclaration::CSSMutableStyleDeclaration):
* css/CSSStyleDeclaration.cpp:
(WebCore::CSSStyleDeclaration::CSSStyleDeclaration):
(WebCore::CSSStyleDeclaration::parentStyleSheet):
Merge the CSSElementStyleDeclaration::styleSheet() logic here.
* css/CSSStyleDeclaration.h:
(WebCore::CSSStyleDeclaration::parentRule):
(WebCore::CSSStyleDeclaration::clearParentRule):
(WebCore::CSSStyleDeclaration::parentElement):
(WebCore::CSSStyleDeclaration::clearParentElement):
* css/CSSStyleRule.cpp:
(WebCore::CSSStyleRule::setSelectorText):
CSSStyleRule's style declaration can't have isElementStyleDeclaration set, the dead code can be removed.
This is asserted in setDeclaration() and again implicitly in the destructor (by clearParentRule()).
* dom/StyledElement.cpp:
(WebCore::StyledElement::createInlineStyleDecl):
(WebCore::StyledElement::destroyInlineStyleDecl):
(WebCore::StyledElement::ensureInlineStyleDecl):
(WebCore::StyledElement::copyNonAttributeProperties):
* dom/StyledElement.h:
(WebCore::StyledElement::inlineStyleDecl):
* editing/ApplyStyleCommand.cpp:
(WebCore::ApplyStyleCommand::applyRelativeFontStyleChange):
(WebCore::ApplyStyleCommand::addInlineStyleIfNeeded):
* editing/DeleteButtonController.cpp:
(WebCore::DeleteButtonController::createDeletionUI):
* html/ValidationMessage.cpp:
(WebCore::adjustBubblePosition):
* html/shadow/MediaControlElements.cpp:
(WebCore::MediaControlPanelElement::setPosition):
(WebCore::MediaControlPanelElement::resetPosition):
(WebCore::MediaControlPanelElement::makeOpaque):
(WebCore::MediaControlPanelElement::makeTransparent):
* html/shadow/SliderThumbElement.cpp:
(WebCore::TrackLimiterElement::create):
* svg/SVGFontFaceElement.cpp:
(WebCore::SVGFontFaceElement::SVGFontFaceElement):
2012-01-23 Benjamin Poulain <bpoulain@apple.com>
 
Use OVERRIDE for PopupMenuClient's implementations
......@@ -1288,8 +1288,6 @@ webcore_sources += \
Source/WebCore/css/CSSCrossfadeValue.h \
Source/WebCore/css/CSSCursorImageValue.cpp \
Source/WebCore/css/CSSCursorImageValue.h \
Source/WebCore/css/CSSElementStyleDeclaration.cpp \
Source/WebCore/css/CSSElementStyleDeclaration.h \
Source/WebCore/css/CSSFlexValue.cpp \
Source/WebCore/css/CSSFlexValue.h \
Source/WebCore/css/CSSFontFace.cpp \
......
......@@ -400,7 +400,6 @@ SOURCES += \
css/CSSComputedStyleDeclaration.cpp \
css/CSSCrossfadeValue.cpp \
css/CSSCursorImageValue.cpp \
css/CSSElementStyleDeclaration.cpp \
css/CSSFlexValue.cpp \
css/CSSFontFace.cpp \
css/CSSFontFaceRule.cpp \
......@@ -1512,7 +1511,6 @@ HEADERS += \
css/CSSComputedStyleDeclaration.h \
css/CSSCrossfadeValue.h \
css/CSSCursorImageValue.h \
css/CSSElementStyleDeclaration.h \
css/CSSFlexValue.h \
css/CSSFontFace.h \
css/CSSFontFaceRule.h \
......
......@@ -487,7 +487,6 @@
'bridge/runtime_root.h',
'css/CSSComputedStyleDeclaration.h',
'css/CSSCursorImageValue.h',
'css/CSSElementStyleDeclaration.h',
'css/CSSHelper.h',
'css/CSSImageGeneratorValue.h',
'css/CSSImageValue.h',
......@@ -2390,7 +2389,6 @@
'css/CSSCrossfadeValue.cpp',
'css/CSSCrossfadeValue.h',
'css/CSSCursorImageValue.cpp',
'css/CSSElementStyleDeclaration.cpp',
'css/CSSFlexValue.cpp',
'css/CSSFlexValue.h',
'css/CSSFontFace.cpp',
......
......@@ -32965,62 +32965,6 @@
RelativePath="..\css\CSSCursorImageValue.h"
>
</File>
<File
RelativePath="..\css\CSSElementStyleDeclaration.cpp"
>
<FileConfiguration
Name="Debug|Win32"
ExcludedFromBuild="true"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
ExcludedFromBuild="true"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
<FileConfiguration
Name="Debug_Cairo_CFLite|Win32"
ExcludedFromBuild="true"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
<FileConfiguration
Name="Release_Cairo_CFLite|Win32"
ExcludedFromBuild="true"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
<FileConfiguration
Name="Debug_All|Win32"
ExcludedFromBuild="true"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
<FileConfiguration
Name="Production|Win32"
ExcludedFromBuild="true"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
</File>
<File
RelativePath="..\css\CSSElementStyleDeclaration.h"
>
</File>
<File
RelativePath="..\css\CSSFlexValue.cpp"
>
......@@ -3005,8 +3005,6 @@
8C0E334D138A92C7008DA94F /* LevelDBTransaction.h in Headers */ = {isa = PBXBuildFile; fileRef = 8C0E3349138A92C7008DA94F /* LevelDBTransaction.h */; };
8C0E334E138A92C7008DA94F /* LevelDBWriteBatch.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8C0E334A138A92C7008DA94F /* LevelDBWriteBatch.cpp */; };
8C0E334F138A92C7008DA94F /* LevelDBWriteBatch.h in Headers */ = {isa = PBXBuildFile; fileRef = 8C0E334B138A92C7008DA94F /* LevelDBWriteBatch.h */; };
8C1091981494FB1200B5D3FE /* CSSElementStyleDeclaration.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8C1091961494FB1200B5D3FE /* CSSElementStyleDeclaration.cpp */; };
8C1091991494FB1200B5D3FE /* CSSElementStyleDeclaration.h in Headers */ = {isa = PBXBuildFile; fileRef = 8C1091971494FB1200B5D3FE /* CSSElementStyleDeclaration.h */; settings = {ATTRIBUTES = (Private, ); }; };
8C6EA61911EF7E0400FD8EE3 /* RuntimeEnabledFeatures.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8C6EA61711EF7E0400FD8EE3 /* RuntimeEnabledFeatures.cpp */; };
8C6EA61A11EF7E0400FD8EE3 /* RuntimeEnabledFeatures.h in Headers */ = {isa = PBXBuildFile; fileRef = 8C6EA61811EF7E0400FD8EE3 /* RuntimeEnabledFeatures.h */; };
8CADF2A9135C7B36009EF43F /* LevelDBComparator.h in Headers */ = {isa = PBXBuildFile; fileRef = 8CADF2A3135C7B36009EF43F /* LevelDBComparator.h */; };
......@@ -9828,8 +9826,6 @@
8C0E3349138A92C7008DA94F /* LevelDBTransaction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LevelDBTransaction.h; sourceTree = "<group>"; };
8C0E334A138A92C7008DA94F /* LevelDBWriteBatch.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LevelDBWriteBatch.cpp; sourceTree = "<group>"; };
8C0E334B138A92C7008DA94F /* LevelDBWriteBatch.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LevelDBWriteBatch.h; sourceTree = "<group>"; };
8C1091961494FB1200B5D3FE /* CSSElementStyleDeclaration.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CSSElementStyleDeclaration.cpp; sourceTree = "<group>"; };
8C1091971494FB1200B5D3FE /* CSSElementStyleDeclaration.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CSSElementStyleDeclaration.h; sourceTree = "<group>"; };
8C6EA61711EF7E0400FD8EE3 /* RuntimeEnabledFeatures.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = RuntimeEnabledFeatures.cpp; path = generic/RuntimeEnabledFeatures.cpp; sourceTree = "<group>"; };
8C6EA61811EF7E0400FD8EE3 /* RuntimeEnabledFeatures.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RuntimeEnabledFeatures.h; path = generic/RuntimeEnabledFeatures.h; sourceTree = "<group>"; };
8CADF2A3135C7B36009EF43F /* LevelDBComparator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LevelDBComparator.h; sourceTree = "<group>"; };
......@@ -19896,8 +19892,6 @@
2D8FEBDB143E3EF70072502B /* CSSCrossfadeValue.h */,
AA0978ED0ABAA6E100874480 /* CSSCursorImageValue.cpp */,
AA0978EE0ABAA6E100874480 /* CSSCursorImageValue.h */,
8C1091961494FB1200B5D3FE /* CSSElementStyleDeclaration.cpp */,
8C1091971494FB1200B5D3FE /* CSSElementStyleDeclaration.h */,
5325E4D513A6C88B00404A36 /* CSSFlexValue.cpp */,
5325E4D613A6C88B00404A36 /* CSSFlexValue.h */,
BC64B4CD0CB4298A005F2B62 /* CSSFontFace.cpp */,
......@@ -21215,7 +21209,6 @@
BCEA4790097CAAC80094C9E4 /* CSSComputedStyleDeclaration.h in Headers */,
2D8FEBDD143E3EF70072502B /* CSSCrossfadeValue.h in Headers */,
AA21ECCD0ABF0FC6002B834C /* CSSCursorImageValue.h in Headers */,
8C1091991494FB1200B5D3FE /* CSSElementStyleDeclaration.h in Headers */,
5325E4D813A6C88B00404A36 /* CSSFlexValue.h in Headers */,
BC64B4D60CB4298A005F2B62 /* CSSFontFace.h in Headers */,
A80E6CFD0A1989CA007FB8C5 /* CSSFontFaceRule.h in Headers */,
......@@ -24615,7 +24608,6 @@
BCEA478F097CAAC80094C9E4 /* CSSComputedStyleDeclaration.cpp in Sources */,
2D8FEBDC143E3EF70072502B /* CSSCrossfadeValue.cpp in Sources */,
AA21ECCA0ABF0FBA002B834C /* CSSCursorImageValue.cpp in Sources */,
8C1091981494FB1200B5D3FE /* CSSElementStyleDeclaration.cpp in Sources */,
5325E4D713A6C88B00404A36 /* CSSFlexValue.cpp in Sources */,
BC64B4D50CB4298A005F2B62 /* CSSFontFace.cpp in Sources */,
A80E6CE70A1989CA007FB8C5 /* CSSFontFaceRule.cpp in Sources */,
......@@ -22,8 +22,8 @@
#ifndef JSDOMBinding_h
#define JSDOMBinding_h
#include "CSSElementStyleDeclaration.h"
#include "CSSImportRule.h"
#include "CSSMutableStyleDeclaration.h"
#include "CSSStyleSheet.h"
#include "JSDOMGlobalObject.h"
#include "JSDOMWrapper.h"
......@@ -210,7 +210,7 @@ enum ParameterMissingPolicy {
if (CSSStyleSheet* styleSheet = style->parentStyleSheet())
return root(styleSheet);
// A style declaration with an associated element should've returned a style sheet above.
ASSERT(!style->isElementStyleDeclaration() || !static_cast<CSSElementStyleDeclaration*>(style)->element());
ASSERT(!style->isElementStyleDeclaration() || !static_cast<CSSMutableStyleDeclaration*>(style)->parentElement());
return style;
}
......
......@@ -33,7 +33,6 @@
#include "CSSComputedStyleDeclaration.cpp"
#include "CSSCrossfadeValue.cpp"
#include "CSSCursorImageValue.cpp"
#include "CSSElementStyleDeclaration.cpp"
#include "CSSFlexValue.cpp"
#include "CSSFontFace.cpp"
#include "CSSFontFaceRule.cpp"
......
/*
* Copyright (C) 2011 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#include "CSSElementStyleDeclaration.h"
#include "StyledElement.h"
namespace WebCore {
CSSStyleSheet* CSSElementStyleDeclaration::styleSheet() const
{
if (!m_element)
return 0;
Document* document = m_element->document();
if (!document)
return 0;
// If this is not an inline declaration then it is an SVG font face declaration.
return m_isInlineStyleDeclaration ? document->elementSheet() : document->mappedElementSheet();
}
} // namespace WebCore
/*
* Copyright (C) 2011 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef CSSElementStyleDeclaration_h
#define CSSElementStyleDeclaration_h
#include "CSSMutableStyleDeclaration.h"
#include <wtf/RefPtr.h>
namespace WebCore {
class SVGFontFaceElement;
class StyledElement;
class CSSElementStyleDeclaration : public CSSMutableStyleDeclaration {
public:
static PassRefPtr<CSSElementStyleDeclaration> createInline(StyledElement* element) { return adoptRef(new CSSElementStyleDeclaration(element, true)); }
static PassRefPtr<CSSElementStyleDeclaration> createForSVGFontFaceElement(StyledElement* element) { return adoptRef(new CSSElementStyleDeclaration(element, false)); }
StyledElement* element() const { return m_element; }
void clearElement() { m_element = 0; }
virtual CSSStyleSheet* styleSheet() const;
private:
CSSElementStyleDeclaration(StyledElement* element, bool isInline)
: CSSMutableStyleDeclaration()
, m_element(element)
{
m_isElementStyleDeclaration = true;
m_isInlineStyleDeclaration = isInline;
}
virtual ~CSSElementStyleDeclaration() { }
private:
StyledElement* m_element;
};
inline CSSElementStyleDeclaration* toCSSElementStyleDeclaration(CSSMutableStyleDeclaration* decl)
{
ASSERT(!decl || decl->isElementStyleDeclaration());
return static_cast<CSSElementStyleDeclaration*>(decl);
}
} // namespace WebCore
#endif // CSSElementStyleDeclaration_h
......@@ -33,7 +33,8 @@ CSSFontFaceRule::CSSFontFaceRule(CSSStyleSheet* parent)
CSSFontFaceRule::~CSSFontFaceRule()
{
if (m_style)
// FIXME: SVGFontFaceElement's style declaration should probably be parented to the rule too.
if (m_style && !m_style->isElementStyleDeclaration())
m_style->clearParentRule();
}
......
......@@ -22,7 +22,6 @@
#include "config.h"
#include "CSSMutableStyleDeclaration.h"
#include "CSSElementStyleDeclaration.h"
#include "CSSImageValue.h"
#include "CSSParser.h"
#include "CSSPropertyLonghand.h"
......@@ -66,11 +65,8 @@ public:
#if ENABLE(MUTATION_OBSERVERS)
if (!s_currentDecl->isInlineStyleDeclaration())
return;
CSSElementStyleDeclaration* inlineDecl = toCSSElementStyleDeclaration(s_currentDecl);
if (!inlineDecl->element())
if (!s_currentDecl->element())
return;
m_mutationRecipients = MutationObserverInterestGroup::createForAttributesMutation(inlineDecl->element(), HTMLNames::styleAttr);
if (!m_mutationRecipients)
return;
......@@ -91,17 +87,14 @@ public:
m_mutationRecipients->enqueueMutationRecord(m_mutation);
s_shouldDeliver = false;
#endif
if (!s_shouldNotifyInspector) {
s_currentDecl = 0;
return;
}
CSSElementStyleDeclaration* inlineDecl = toCSSElementStyleDeclaration(s_currentDecl);
if (s_currentDecl->isInlineStyleDeclaration() && s_currentDecl->parentElement() && s_currentDecl->parentElement()->document())
InspectorInstrumentation::didInvalidateStyleAttr(s_currentDecl->parentElement()->document(), s_currentDecl->parentElement());
s_currentDecl = 0;
s_shouldNotifyInspector = false;
if (inlineDecl->element() && inlineDecl->element()->document())
InspectorInstrumentation::didInvalidateStyleAttr(inlineDecl->element()->document(), inlineDecl->element());
}
#if ENABLE(MUTATION_OBSERVERS)
......@@ -180,6 +173,11 @@ CSSMutableStyleDeclaration::CSSMutableStyleDeclaration(CSSRule* parent, const CS
}
}
CSSMutableStyleDeclaration::CSSMutableStyleDeclaration(StyledElement* element, bool isInline)
: CSSStyleDeclaration(element, isInline)
{
}
CSSMutableStyleDeclaration::~CSSMutableStyleDeclaration()
{
}
......@@ -646,8 +644,8 @@ String CSSMutableStyleDeclaration::removeProperty(int propertyID, bool notifyCha
void CSSMutableStyleDeclaration::setNeedsStyleRecalc()
{
if (isElementStyleDeclaration() && static_cast<CSSElementStyleDeclaration*>(this)->element()) {
StyledElement* element = static_cast<CSSElementStyleDeclaration*>(this)->element();
if (isElementStyleDeclaration() && parentElement()) {
StyledElement* element = parentElement();
if (!isInlineStyleDeclaration())
element->setNeedsStyleRecalc(FullStyleChange);
else {
......
......@@ -31,6 +31,8 @@
namespace WebCore {
class StyledElement;
class CSSMutableStyleDeclarationConstIterator {
public:
CSSMutableStyleDeclarationConstIterator(const CSSMutableStyleDeclaration* decl, CSSProperty* current);
......@@ -73,6 +75,14 @@ public:
{
return adoptRef(new CSSMutableStyleDeclaration(0, properties));
}
static PassRefPtr<CSSMutableStyleDeclaration> createInline(StyledElement* element)
{
return adoptRef(new CSSMutableStyleDeclaration(element, true));
}
static PassRefPtr<CSSMutableStyleDeclaration> createForSVGFontFaceElement(StyledElement* element)
{
return adoptRef(new CSSMutableStyleDeclaration(element, false));
}
// Used by StyledElement::copyNonAttributeProperties().
void copyPropertiesFrom(const CSSMutableStyleDeclaration&);
......@@ -128,15 +138,16 @@ public:
void addSubresourceStyleURLs(ListHashSet<KURL>&);
protected:
CSSMutableStyleDeclaration(CSSRule* parentRule);
CSSMutableStyleDeclaration();
void setPropertyInternal(const CSSProperty&, CSSProperty* slot = 0);
String removeProperty(int propertyID, bool notifyChanged, bool returnText);
private:
CSSMutableStyleDeclaration(CSSRule* parentRule);
CSSMutableStyleDeclaration(CSSRule* parentRule, const Vector<CSSProperty>&);
CSSMutableStyleDeclaration(CSSRule* parentRule, const CSSProperty* const *, int numProperties);
CSSMutableStyleDeclaration(StyledElement*, bool isInline);
virtual PassRefPtr<CSSMutableStyleDeclaration> makeMutable();
......
......@@ -21,7 +21,6 @@
#include "config.h"
#include "CSSStyleDeclaration.h"
#include "CSSElementStyleDeclaration.h"
#include "CSSMutableStyleDeclaration.h"
#include "CSSParser.h"
#include "CSSProperty.h"
......@@ -39,24 +38,42 @@ using namespace WTF;
namespace WebCore {
CSSStyleDeclaration::CSSStyleDeclaration(CSSRule* parent)
: m_strictParsing(!parent || parent->useStrictParsing())
CSSStyleDeclaration::CSSStyleDeclaration(CSSRule* parentRule)
: m_strictParsing(!parentRule || parentRule->useStrictParsing())
#ifndef NDEBUG
, m_iteratorCount(0)
#endif
, m_isElementStyleDeclaration(false)
, m_isInlineStyleDeclaration(false)
, m_parentRule(parent)
, m_parent(parentRule)
{
}
CSSStyleDeclaration::CSSStyleDeclaration(StyledElement* parentElement, bool isInline)
: m_strictParsing(false)
#ifndef NDEBUG
, m_iteratorCount(0)
#endif
, m_isElementStyleDeclaration(true)
, m_isInlineStyleDeclaration(isInline)
, m_parent(parentElement)
{
}
CSSStyleSheet* CSSStyleDeclaration::parentStyleSheet() const
{
if (parentRule())
return parentRule()->parentStyleSheet();
if (isElementStyleDeclaration())
return static_cast<const CSSElementStyleDeclaration*>(this)->styleSheet();
return 0;
if (m_isElementStyleDeclaration) {
if (!m_parent.element)
return 0;
Document* document = m_parent.element->document();
if (!document)
return 0;
// If this is not an inline declaration then it is an SVG font face declaration.
return m_isInlineStyleDeclaration ? document->elementSheet() : document->mappedElementSheet();
}
if (!m_parent.rule)
return 0;
return m_parent.rule->parentStyleSheet();
}
PassRefPtr<CSSValue> CSSStyleDeclaration::getPropertyCSSValue(const String& propertyName)
......
......@@ -30,6 +30,7 @@ class CSSMutableStyleDeclaration;
class CSSProperty;
class CSSStyleSheet;
class CSSValue;
class StyledElement;
typedef int ExceptionCode;
......@@ -40,8 +41,11 @@ public:
static bool isPropertyName(const String&);
CSSRule* parentRule() const { return m_parentRule; }
void clearParentRule() { m_parentRule = 0; }
CSSRule* parentRule() const { return m_isElementStyleDeclaration ? 0 : m_parent.rule; }
void clearParentRule() { ASSERT(!m_isElementStyleDeclaration); m_parent.rule = 0; }
StyledElement* parentElement() const { ASSERT(m_isElementStyleDeclaration); return m_parent.element; }
void clearParentElement() { ASSERT(m_isElementStyleDeclaration); m_parent.element = 0; }
CSSStyleSheet* parentStyleSheet() const;
......@@ -86,6 +90,7 @@ public:
protected:
CSSStyleDeclaration(CSSRule* parentRule = 0);
CSSStyleDeclaration(StyledElement* parentElement, bool isInline);
virtual bool cssPropertyMatches(const CSSProperty*) const;
......@@ -97,13 +102,16 @@ protected:
#ifndef NDEBUG
unsigned m_iteratorCount : 4;
#endif
// CSSElementStyleDeclaration bits:
bool m_isElementStyleDeclaration : 1;
bool m_isInlineStyleDeclaration : 1;
private:
CSSRule* m_parentRule;
union Parent {
Parent(CSSRule* rule) : rule(rule) { }
Parent(StyledElement* element) : element(element) { }
CSSRule* rule;
StyledElement* element;
} m_parent;
};
} // namespace WebCore
......
......@@ -98,15 +98,8 @@ String CSSStyleRule::selectorText() const
void CSSStyleRule::setSelectorText(const String& selectorText)
{
Document* doc = 0;
if (CSSStyleSheet* styleSheet = m_style->parentStyleSheet())
doc = styleSheet->findDocument();
if (!doc && m_style->isElementStyleDeclaration()) {
if (StyledElement* element = static_cast<CSSElementStyleDeclaration*>(m_style.get())->element())
doc = element->document();
}