Diff
Modified: trunk/Source/WebCore/ChangeLog (115114 => 115115)
--- trunk/Source/WebCore/ChangeLog 2012-04-24 21:34:51 UTC (rev 115114)
+++ trunk/Source/WebCore/ChangeLog 2012-04-24 21:56:48 UTC (rev 115115)
@@ -1,3 +1,73 @@
+2012-04-24 Antti Koivisto <[email protected]>
+
+ Implement StyleRule copying
+ https://bugs.webkit.org/show_bug.cgi?id=84752
+
+ Reviewed by Andreas Kling.
+
+ We'll need this for copy-on-write when style sheet data is shared between documents.
+
+ Implement copy() and copy constructor for style rules their children as needed.
+
+ The code is not yet used.
+
+ * css/CSSSelectorList.cpp:
+ (WebCore::CSSSelectorList::CSSSelectorList):
+ (WebCore):
+ * css/CSSSelectorList.h:
+ (CSSSelectorList):
+ * css/MediaList.h:
+ (WebCore::MediaQuerySet::copy):
+ (MediaQuerySet):
+ * css/MediaQuery.cpp:
+ (WebCore::MediaQuery::MediaQuery):
+ (WebCore):
+ * css/MediaQuery.h:
+ (MediaQuery):
+ (WebCore::MediaQuery::copy):
+ * css/MediaQueryExp.h:
+ (WebCore::MediaQueryExp::copy):
+ (MediaQueryExp):
+ * css/StylePropertySet.cpp:
+ (WebCore::StylePropertySet::StylePropertySet):
+ (WebCore):
+ (WebCore::StylePropertySet::copy):
+ * css/StylePropertySet.h:
+
+ Make this copy parse mode too. As a result ElementAttributeData no longer needs to set it explicitly after copying.
+
+ (StylePropertySet):
+ * css/StyleRule.cpp:
+ (WebCore::StyleRuleBase::copy):
+ (WebCore):
+ (WebCore::StyleRule::StyleRule):
+ (WebCore::StyleRulePage::StyleRulePage):
+ (WebCore::StyleRuleFontFace::StyleRuleFontFace):
+ (WebCore::StyleRuleBlock::StyleRuleBlock):
+ (WebCore::StyleRuleMedia::StyleRuleMedia):
+ (WebCore::StyleRuleRegion::StyleRuleRegion):
+ * css/StyleRule.h:
+ (StyleRuleBase):
+ (WebCore::StyleRuleBase::StyleRuleBase):
+ (WebCore::StyleRule::copy):
+ (StyleRule):
+ (WebCore::StyleRuleFontFace::copy):
+ (StyleRuleFontFace):
+ (WebCore::StyleRulePage::copy):
+ (StyleRulePage):
+ (StyleRuleBlock):
+ (WebCore::StyleRuleMedia::copy):
+ (StyleRuleMedia):
+ (WebCore::StyleRuleRegion::copy):
+ (StyleRuleRegion):
+ * css/WebKitCSSKeyframesRule.cpp:
+ (WebCore):
+ (WebCore::StyleRuleKeyframes::StyleRuleKeyframes):
+ * css/WebKitCSSKeyframesRule.h:
+ (WebCore):
+ (WebCore::StyleRuleKeyframes::copy):
+ (StyleRuleKeyframes):
+
2012-04-24 Ryosuke Niwa <[email protected]>
Revert r115009; It doesn't make necessary changes to NodeRareData and Node.
Modified: trunk/Source/WebCore/css/CSSSelectorList.cpp (115114 => 115115)
--- trunk/Source/WebCore/css/CSSSelectorList.cpp 2012-04-24 21:34:51 UTC (rev 115114)
+++ trunk/Source/WebCore/css/CSSSelectorList.cpp 2012-04-24 21:56:48 UTC (rev 115115)
@@ -37,6 +37,16 @@
deleteSelectors();
}
+CSSSelectorList::CSSSelectorList(const CSSSelectorList& o)
+{
+ CSSSelector* current = o.m_selectorArray;
+ while (!current->isLastInSelectorList())
+ ++current;
+ unsigned length = (current - o.m_selectorArray) + 1;
+ m_selectorArray = reinterpret_cast<CSSSelector*>(fastMalloc(sizeof(CSSSelector) * length));
+ memcpy(m_selectorArray, o.m_selectorArray, sizeof(CSSSelector) * length);
+}
+
void CSSSelectorList::adopt(CSSSelectorList& list)
{
deleteSelectors();
Modified: trunk/Source/WebCore/css/CSSSelectorList.h (115114 => 115115)
--- trunk/Source/WebCore/css/CSSSelectorList.h 2012-04-24 21:34:51 UTC (rev 115114)
+++ trunk/Source/WebCore/css/CSSSelectorList.h 2012-04-24 21:56:48 UTC (rev 115115)
@@ -33,9 +33,11 @@
class CSSParserSelector;
class CSSSelectorList {
- WTF_MAKE_NONCOPYABLE(CSSSelectorList); WTF_MAKE_FAST_ALLOCATED;
+ WTF_MAKE_FAST_ALLOCATED;
public:
CSSSelectorList() : m_selectorArray(0) { }
+ CSSSelectorList(const CSSSelectorList&);
+
~CSSSelectorList();
void adopt(CSSSelectorList& list);
Modified: trunk/Source/WebCore/css/MediaList.cpp (115114 => 115115)
--- trunk/Source/WebCore/css/MediaList.cpp 2012-04-24 21:34:51 UTC (rev 115114)
+++ trunk/Source/WebCore/css/MediaList.cpp 2012-04-24 21:56:48 UTC (rev 115115)
@@ -82,6 +82,15 @@
parse("invalid");
}
+MediaQuerySet::MediaQuerySet(const MediaQuerySet& o)
+ : m_fallbackToDescriptor(o.m_fallbackToDescriptor)
+ , m_lastLine(o.m_lastLine)
+ , m_queries(o.m_queries.size())
+{
+ for (unsigned i = 0; i < m_queries.size(); ++i)
+ m_queries[i] = o.m_queries[i]->copy();
+}
+
MediaQuerySet::~MediaQuerySet()
{
}
Modified: trunk/Source/WebCore/css/MediaList.h (115114 => 115115)
--- trunk/Source/WebCore/css/MediaList.h 2012-04-24 21:34:51 UTC (rev 115114)
+++ trunk/Source/WebCore/css/MediaList.h 2012-04-24 21:56:48 UTC (rev 115115)
@@ -64,9 +64,12 @@
String mediaText() const;
+ PassRefPtr<MediaQuerySet> copy() const { return adoptRef(new MediaQuerySet(*this)); }
+
private:
MediaQuerySet();
MediaQuerySet(const String& mediaQuery, bool fallbackToDescription);
+ MediaQuerySet(const MediaQuerySet&);
unsigned m_fallbackToDescriptor : 1; // true if failed media query parsing should fallback to media description parsing.
signed m_lastLine : 31;
Modified: trunk/Source/WebCore/css/MediaQuery.cpp (115114 => 115115)
--- trunk/Source/WebCore/css/MediaQuery.cpp 2012-04-24 21:34:51 UTC (rev 115114)
+++ trunk/Source/WebCore/css/MediaQuery.cpp 2012-04-24 21:56:48 UTC (rev 115115)
@@ -103,6 +103,17 @@
}
}
+MediaQuery::MediaQuery(const MediaQuery& o)
+ : m_restrictor(o.m_restrictor)
+ , m_mediaType(o.m_mediaType)
+ , m_expressions(adoptPtr(new Vector<OwnPtr<MediaQueryExp> >(o.m_expressions->size())))
+ , m_ignored(o.m_ignored)
+ , m_serializationCache(o.m_serializationCache)
+{
+ for (unsigned i = 0; i < m_expressions->size(); ++i)
+ (*m_expressions)[i] = o.m_expressions->at(i)->copy();
+}
+
MediaQuery::~MediaQuery()
{
}
Modified: trunk/Source/WebCore/css/MediaQuery.h (115114 => 115115)
--- trunk/Source/WebCore/css/MediaQuery.h 2012-04-24 21:34:51 UTC (rev 115114)
+++ trunk/Source/WebCore/css/MediaQuery.h 2012-04-24 21:56:48 UTC (rev 115115)
@@ -38,7 +38,7 @@
class MediaQueryExp;
class MediaQuery {
- WTF_MAKE_NONCOPYABLE(MediaQuery); WTF_MAKE_FAST_ALLOCATED;
+ WTF_MAKE_FAST_ALLOCATED;
public:
enum Restrictor {
Only, Not, None
@@ -56,7 +56,11 @@
String cssText() const;
bool ignored() const { return m_ignored; }
+ PassOwnPtr<MediaQuery> copy() const { return adoptPtr(new MediaQuery(*this)); }
+
private:
+ MediaQuery(const MediaQuery&);
+
Restrictor m_restrictor;
String m_mediaType;
OwnPtr<ExpressionVector> m_expressions;
Modified: trunk/Source/WebCore/css/MediaQueryExp.h (115114 => 115115)
--- trunk/Source/WebCore/css/MediaQueryExp.h 2012-04-24 21:34:51 UTC (rev 115114)
+++ trunk/Source/WebCore/css/MediaQueryExp.h 2012-04-24 21:56:48 UTC (rev 115115)
@@ -70,6 +70,8 @@
String serialize() const;
+ PassOwnPtr<MediaQueryExp> copy() const { return adoptPtr(new MediaQueryExp(*this)); }
+
private:
MediaQueryExp(const AtomicString& mediaFeature, CSSParserValueList* values);
Modified: trunk/Source/WebCore/css/StylePropertySet.cpp (115114 => 115115)
--- trunk/Source/WebCore/css/StylePropertySet.cpp 2012-04-24 21:34:51 UTC (rev 115114)
+++ trunk/Source/WebCore/css/StylePropertySet.cpp 2012-04-24 21:56:48 UTC (rev 115115)
@@ -81,6 +81,13 @@
}
}
+StylePropertySet::StylePropertySet(const StylePropertySet& o)
+ : m_properties(o.m_properties)
+ , m_cssParserMode(o.m_cssParserMode)
+ , m_ownsCSSOMWrapper(false)
+{
+}
+
StylePropertySet::~StylePropertySet()
{
ASSERT(!m_ownsCSSOMWrapper || propertySetCSSOMWrapperMap().contains(this));
@@ -931,7 +938,7 @@
PassRefPtr<StylePropertySet> StylePropertySet::copy() const
{
- return adoptRef(new StylePropertySet(m_properties));
+ return adoptRef(new StylePropertySet(*this));
}
PassRefPtr<StylePropertySet> StylePropertySet::copyPropertiesInSet(const CSSPropertyID* set, unsigned length) const
Modified: trunk/Source/WebCore/css/StylePropertySet.h (115114 => 115115)
--- trunk/Source/WebCore/css/StylePropertySet.h 2012-04-24 21:34:51 UTC (rev 115114)
+++ trunk/Source/WebCore/css/StylePropertySet.h 2012-04-24 21:56:48 UTC (rev 115115)
@@ -113,10 +113,10 @@
// FIXME: Expand the concept of mutable/immutable StylePropertySet.
bool isMutable() const { return m_ownsCSSOMWrapper; }
-
private:
StylePropertySet(CSSParserMode);
StylePropertySet(const Vector<CSSProperty>&);
+ StylePropertySet(const StylePropertySet&);
StylePropertySet(const CSSProperty*, int numProperties, CSSParserMode);
void setNeedsStyleRecalc();
Modified: trunk/Source/WebCore/css/StyleRule.cpp (115114 => 115115)
--- trunk/Source/WebCore/css/StyleRule.cpp 2012-04-24 21:34:51 UTC (rev 115114)
+++ trunk/Source/WebCore/css/StyleRule.cpp 2012-04-24 21:56:48 UTC (rev 115115)
@@ -77,6 +77,35 @@
ASSERT_NOT_REACHED();
}
+PassRefPtr<StyleRuleBase> StyleRuleBase::copy() const
+{
+ switch (type()) {
+ case Style:
+ return static_cast<const StyleRule*>(this)->copy();
+ case Page:
+ return static_cast<const StyleRulePage*>(this)->copy();
+ case FontFace:
+ return static_cast<const StyleRuleFontFace*>(this)->copy();
+ case Media:
+ return static_cast<const StyleRuleMedia*>(this)->copy();
+ case Region:
+ return static_cast<const StyleRuleRegion*>(this)->copy();
+ case Import:
+ // FIXME: Copy import rules.
+ ASSERT_NOT_REACHED();
+ return 0;
+ case Keyframes:
+ return static_cast<const StyleRuleKeyframes*>(this)->copy();
+ case Unknown:
+ case Charset:
+ case Keyframe:
+ ASSERT_NOT_REACHED();
+ return 0;
+ }
+ ASSERT_NOT_REACHED();
+ return 0;
+}
+
PassRefPtr<CSSRule> StyleRuleBase::createCSSOMWrapper(CSSStyleSheet* parentSheet, CSSRule* parentRule) const
{
RefPtr<CSSRule> rule;
@@ -119,6 +148,13 @@
{
}
+StyleRule::StyleRule(const StyleRule& o)
+ : StyleRuleBase(o)
+ , m_properties(o.m_properties->copy())
+ , m_selectorList(o.m_selectorList)
+{
+}
+
StyleRule::~StyleRule()
{
}
@@ -133,6 +169,13 @@
{
}
+StyleRulePage::StyleRulePage(const StyleRulePage& o)
+ : StyleRuleBase(o)
+ , m_properties(o.m_properties->copy())
+ , m_selectorList(o.m_selectorList)
+{
+}
+
StyleRulePage::~StyleRulePage()
{
}
@@ -147,6 +190,12 @@
{
}
+StyleRuleFontFace::StyleRuleFontFace(const StyleRuleFontFace& o)
+ : StyleRuleBase(o)
+ , m_properties(o.m_properties->copy())
+{
+}
+
StyleRuleFontFace::~StyleRuleFontFace()
{
}
@@ -162,6 +211,14 @@
m_childRules.swap(adoptRule);
}
+StyleRuleBlock::StyleRuleBlock(const StyleRuleBlock& o)
+ : StyleRuleBase(o)
+ , m_childRules(o.m_childRules.size())
+{
+ for (unsigned i = 0; i < m_childRules.size(); ++i)
+ m_childRules[i] = o.m_childRules[i]->copy();
+}
+
void StyleRuleBlock::wrapperInsertRule(unsigned index, PassRefPtr<StyleRuleBase> rule)
{
m_childRules.insert(index, rule);
@@ -178,10 +235,22 @@
{
}
+StyleRuleMedia::StyleRuleMedia(const StyleRuleMedia& o)
+ : StyleRuleBlock(o)
+ , m_mediaQueries(o.m_mediaQueries->copy())
+{
+}
+
StyleRuleRegion::StyleRuleRegion(Vector<OwnPtr<CSSParserSelector> >* selectors, Vector<RefPtr<StyleRuleBase> >& adoptRules)
: StyleRuleBlock(Region, adoptRules)
{
m_selectorList.adoptSelectorVector(*selectors);
}
+StyleRuleRegion::StyleRuleRegion(const StyleRuleRegion& o)
+ : StyleRuleBlock(o)
+ , m_selectorList(o.m_selectorList)
+{
+}
+
} // namespace WebCore
Modified: trunk/Source/WebCore/css/StyleRule.h (115114 => 115115)
--- trunk/Source/WebCore/css/StyleRule.h 2012-04-24 21:34:51 UTC (rev 115114)
+++ trunk/Source/WebCore/css/StyleRule.h 2012-04-24 21:56:48 UTC (rev 115115)
@@ -57,7 +57,9 @@
bool isStyleRule() const { return type() == Style; }
bool isRegionRule() const { return type() == Region; }
bool isImportRule() const { return type() == Import; }
-
+
+ PassRefPtr<StyleRuleBase> copy() const;
+
int sourceLine() const { return m_sourceLine; }
void deref()
@@ -72,6 +74,8 @@
protected:
StyleRuleBase(Type type, signed sourceLine = 0) : m_type(type), m_sourceLine(sourceLine) { }
+ StyleRuleBase(const StyleRuleBase& o) : m_type(o.m_type), m_sourceLine(o.m_sourceLine) { }
+
~StyleRuleBase() { }
private:
@@ -96,8 +100,11 @@
void wrapperAdoptSelectorList(CSSSelectorList& selectors) { m_selectorList.adopt(selectors); }
void setProperties(PassRefPtr<StylePropertySet>);
+ PassRefPtr<StyleRule> copy() const { return adoptRef(new StyleRule(*this)); }
+
private:
StyleRule(int sourceLine);
+ StyleRule(const StyleRule&);
RefPtr<StylePropertySet> m_properties;
CSSSelectorList m_selectorList;
@@ -113,8 +120,11 @@
void setProperties(PassRefPtr<StylePropertySet>);
+ PassRefPtr<StyleRuleFontFace> copy() const { return adoptRef(new StyleRuleFontFace(*this)); }
+
private:
StyleRuleFontFace();
+ StyleRuleFontFace(const StyleRuleFontFace&);
RefPtr<StylePropertySet> m_properties;
};
@@ -132,8 +142,11 @@
void wrapperAdoptSelectorList(CSSSelectorList& selectors) { m_selectorList.adopt(selectors); }
void setProperties(PassRefPtr<StylePropertySet>);
+ PassRefPtr<StyleRulePage> copy() const { return adoptRef(new StyleRulePage(*this)); }
+
private:
StyleRulePage();
+ StyleRulePage(const StyleRulePage&);
RefPtr<StylePropertySet> m_properties;
CSSSelectorList m_selectorList;
@@ -148,6 +161,7 @@
protected:
StyleRuleBlock(Type, Vector<RefPtr<StyleRuleBase> >& adoptRule);
+ StyleRuleBlock(const StyleRuleBlock&);
private:
Vector<RefPtr<StyleRuleBase> > m_childRules;
@@ -162,8 +176,11 @@
MediaQuerySet* mediaQueries() const { return m_mediaQueries.get(); }
+ PassRefPtr<StyleRuleMedia> copy() const { return adoptRef(new StyleRuleMedia(*this)); }
+
private:
StyleRuleMedia(PassRefPtr<MediaQuerySet>, Vector<RefPtr<StyleRuleBase> >& adoptRules);
+ StyleRuleMedia(const StyleRuleMedia&);
RefPtr<MediaQuerySet> m_mediaQueries;
};
@@ -177,8 +194,11 @@
const CSSSelectorList& selectorList() const { return m_selectorList; }
+ PassRefPtr<StyleRuleRegion> copy() const { return adoptRef(new StyleRuleRegion(*this)); }
+
private:
StyleRuleRegion(Vector<OwnPtr<CSSParserSelector> >*, Vector<RefPtr<StyleRuleBase> >& adoptRules);
+ StyleRuleRegion(const StyleRuleRegion&);
CSSSelectorList m_selectorList;
};
Modified: trunk/Source/WebCore/css/WebKitCSSKeyframesRule.cpp (115114 => 115115)
--- trunk/Source/WebCore/css/WebKitCSSKeyframesRule.cpp 2012-04-24 21:34:51 UTC (rev 115114)
+++ trunk/Source/WebCore/css/WebKitCSSKeyframesRule.cpp 2012-04-24 21:56:48 UTC (rev 115115)
@@ -39,7 +39,14 @@
: StyleRuleBase(Keyframes, 0)
{
}
-
+
+StyleRuleKeyframes::StyleRuleKeyframes(const StyleRuleKeyframes& o)
+ : StyleRuleBase(o)
+ , m_keyframes(o.m_keyframes)
+ , m_name(o.m_name)
+{
+}
+
StyleRuleKeyframes::~StyleRuleKeyframes()
{
}
Modified: trunk/Source/WebCore/css/WebKitCSSKeyframesRule.h (115114 => 115115)
--- trunk/Source/WebCore/css/WebKitCSSKeyframesRule.h 2012-04-24 21:34:51 UTC (rev 115114)
+++ trunk/Source/WebCore/css/WebKitCSSKeyframesRule.h 2012-04-24 21:56:48 UTC (rev 115115)
@@ -27,6 +27,7 @@
#define WebKitCSSKeyframesRule_h
#include "CSSRule.h"
+#include "ExceptionCode.h"
#include "StyleRule.h"
#include <wtf/Forward.h>
#include <wtf/RefPtr.h>
@@ -38,8 +39,6 @@
class StyleKeyframe;
class WebKitCSSKeyframeRule;
-typedef int ExceptionCode;
-
class StyleRuleKeyframes : public StyleRuleBase {
public:
static PassRefPtr<StyleRuleKeyframes> create() { return adoptRef(new StyleRuleKeyframes()); }
@@ -57,9 +56,12 @@
int findKeyframeIndex(const String& key) const;
+ PassRefPtr<StyleRuleKeyframes> copy() const { return adoptRef(new StyleRuleKeyframes(*this)); }
+
private:
StyleRuleKeyframes();
-
+ StyleRuleKeyframes(const StyleRuleKeyframes&);
+
Vector<RefPtr<StyleKeyframe> > m_keyframes;
AtomicString m_name;
};
Modified: trunk/Source/WebCore/dom/ElementAttributeData.cpp (115114 => 115115)
--- trunk/Source/WebCore/dom/ElementAttributeData.cpp 2012-04-24 21:34:51 UTC (rev 115114)
+++ trunk/Source/WebCore/dom/ElementAttributeData.cpp 2012-04-24 21:56:48 UTC (rev 115115)
@@ -94,7 +94,6 @@
{
if (m_inlineStyleDecl && !m_inlineStyleDecl->isMutable()) {
m_inlineStyleDecl = m_inlineStyleDecl->copy();
- m_inlineStyleDecl->setCSSParserMode(strictToCSSParserMode(element->isHTMLElement() && !element->document()->inQuirksMode()));
return m_inlineStyleDecl.get();
}
return ensureInlineStyle(element);