Index: Source/core/css/CSSStyleSheet.cpp |
diff --git a/Source/core/css/CSSStyleSheet.cpp b/Source/core/css/CSSStyleSheet.cpp |
index 9737560190271c7ebc8e6aa57ef768b288dd7777..eb38213a3175df52af54160dfc2f6b23424244f8 100644 |
--- a/Source/core/css/CSSStyleSheet.cpp |
+++ b/Source/core/css/CSSStyleSheet.cpp |
@@ -28,6 +28,7 @@ |
#include "core/css/CSSImportRule.h" |
#include "core/css/CSSParser.h" |
#include "core/css/CSSRuleList.h" |
+#include "core/css/CSSStyleRule.h" |
#include "core/css/MediaList.h" |
#include "core/css/StyleRule.h" |
#include "core/css/StyleSheetContents.h" |
@@ -117,12 +118,38 @@ CSSStyleSheet::~CSSStyleSheet() |
if (m_childRuleCSSOMWrappers[i]) |
m_childRuleCSSOMWrappers[i]->setParentStyleSheet(0); |
} |
+ for (unsigned i = 0; i < m_extraChildRuleCSSOMWrappers.size(); ++i) { |
+ m_extraChildRuleCSSOMWrappers[i]->setParentStyleSheet(0); |
esprehn
2013/10/29 20:08:44
braces are not needed.
ojan
2013/10/29 20:35:15
Done.
|
+ } |
if (m_mediaCSSOMWrapper) |
m_mediaCSSOMWrapper->clearParentStyleSheet(); |
m_contents->unregisterClient(this); |
} |
+void CSSStyleSheet::extraCSSOMWrapperIndices(Vector<unsigned>& indices) |
+{ |
+ indices.grow(m_extraChildRuleCSSOMWrappers.size()); |
esprehn
2013/10/29 20:08:44
Instead you can make this function return a const
ojan
2013/10/29 20:35:15
As discussed offline, this doesn't work.
|
+ |
+ for (unsigned i = 0; i < m_extraChildRuleCSSOMWrappers.size(); ++i) { |
+ CSSRule* cssRule = m_extraChildRuleCSSOMWrappers[i].get(); |
+ ASSERT(cssRule->type() == CSSRule::STYLE_RULE); |
+ StyleRule* styleRule = toCSSStyleRule(cssRule)->styleRule(); |
+ |
+ bool didFindIndex = false; |
+ for (unsigned j = 0; j < m_contents->ruleCount(); ++j) { |
+ if (m_contents->ruleAt(j) == styleRule) { |
+ didFindIndex = true; |
+ indices[i] = j; |
+ break; |
+ } |
+ } |
+ ASSERT(didFindIndex); |
+ if (!didFindIndex) |
+ indices[i] = 0; |
+ } |
+} |
+ |
void CSSStyleSheet::willMutateRules() |
{ |
// If we are the only client it is safe to mutate. |
@@ -133,6 +160,9 @@ void CSSStyleSheet::willMutateRules() |
// Only cacheable stylesheets should have multiple clients. |
ASSERT(m_contents->isCacheable()); |
+ Vector<unsigned> indices; |
+ extraCSSOMWrapperIndices(indices); |
esprehn
2013/10/29 20:08:44
const Vector<unsigned>& indexes = cssomWrapperInde
|
+ |
// Copy-on-write. |
m_contents->unregisterClient(this); |
m_contents = m_contents->copy(); |
@@ -141,7 +171,7 @@ void CSSStyleSheet::willMutateRules() |
m_contents->setMutable(); |
// Any existing CSSOM wrappers need to be connected to the copied child rules. |
- reattachChildRuleCSSOMWrappers(); |
+ reattachChildRuleCSSOMWrappers(indices); |
} |
void CSSStyleSheet::didMutateRules() |
@@ -164,8 +194,18 @@ void CSSStyleSheet::didMutate(StyleSheetUpdateType updateType) |
owner->modifiedStyleSheet(this, RecalcStyleDeferred, updateMode); |
} |
-void CSSStyleSheet::reattachChildRuleCSSOMWrappers() |
+void CSSStyleSheet::registerExtraChildRuleCSSOMWrapper(PassRefPtr<CSSRule> rule) |
{ |
+ m_extraChildRuleCSSOMWrappers.append(rule); |
+} |
+ |
+void CSSStyleSheet::reattachChildRuleCSSOMWrappers(const Vector<unsigned>& extraCSSOMWrapperIndices) |
+{ |
+ ASSERT(extraCSSOMWrapperIndices.size() == m_extraChildRuleCSSOMWrappers.size()); |
+ for (unsigned i = 0; i < extraCSSOMWrapperIndices.size(); ++i) { |
+ m_extraChildRuleCSSOMWrappers[i]->reattach(m_contents->ruleAt(extraCSSOMWrapperIndices[i])); |
esprehn
2013/10/29 20:08:44
extra braces
ojan
2013/10/29 20:35:15
Done.
|
+ } |
+ |
for (unsigned i = 0; i < m_childRuleCSSOMWrappers.size(); ++i) { |
if (!m_childRuleCSSOMWrappers[i]) |
continue; |