OLD | NEW |
---|---|
1 /* | 1 /* |
2 * (C) 1999-2003 Lars Knoll (knoll@kde.org) | 2 * (C) 1999-2003 Lars Knoll (knoll@kde.org) |
3 * Copyright (C) 2004, 2006, 2007, 2012 Apple Inc. All rights reserved. | 3 * Copyright (C) 2004, 2006, 2007, 2012 Apple Inc. All rights reserved. |
4 * | 4 * |
5 * This library is free software; you can redistribute it and/or | 5 * This library is free software; you can redistribute it and/or |
6 * modify it under the terms of the GNU Library General Public | 6 * modify it under the terms of the GNU Library General Public |
7 * License as published by the Free Software Foundation; either | 7 * License as published by the Free Software Foundation; either |
8 * version 2 of the License, or (at your option) any later version. | 8 * version 2 of the License, or (at your option) any later version. |
9 * | 9 * |
10 * This library is distributed in the hope that it will be useful, | 10 * This library is distributed in the hope that it will be useful, |
(...skipping 10 matching lines...) Expand all Loading... | |
21 #include "config.h" | 21 #include "config.h" |
22 #include "core/css/CSSStyleSheet.h" | 22 #include "core/css/CSSStyleSheet.h" |
23 | 23 |
24 #include "HTMLNames.h" | 24 #include "HTMLNames.h" |
25 #include "SVGNames.h" | 25 #include "SVGNames.h" |
26 #include "bindings/v8/ExceptionState.h" | 26 #include "bindings/v8/ExceptionState.h" |
27 #include "core/css/CSSCharsetRule.h" | 27 #include "core/css/CSSCharsetRule.h" |
28 #include "core/css/CSSImportRule.h" | 28 #include "core/css/CSSImportRule.h" |
29 #include "core/css/CSSParser.h" | 29 #include "core/css/CSSParser.h" |
30 #include "core/css/CSSRuleList.h" | 30 #include "core/css/CSSRuleList.h" |
31 #include "core/css/CSSStyleRule.h" | |
31 #include "core/css/MediaList.h" | 32 #include "core/css/MediaList.h" |
32 #include "core/css/StyleRule.h" | 33 #include "core/css/StyleRule.h" |
33 #include "core/css/StyleSheetContents.h" | 34 #include "core/css/StyleSheetContents.h" |
34 #include "core/dom/Document.h" | 35 #include "core/dom/Document.h" |
35 #include "core/dom/ExceptionCode.h" | 36 #include "core/dom/ExceptionCode.h" |
36 #include "core/dom/Node.h" | 37 #include "core/dom/Node.h" |
37 #include "weborigin/SecurityOrigin.h" | 38 #include "weborigin/SecurityOrigin.h" |
38 #include "wtf/text/StringBuilder.h" | 39 #include "wtf/text/StringBuilder.h" |
39 | 40 |
40 namespace WebCore { | 41 namespace WebCore { |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
110 | 111 |
111 CSSStyleSheet::~CSSStyleSheet() | 112 CSSStyleSheet::~CSSStyleSheet() |
112 { | 113 { |
113 // For style rules outside the document, .parentStyleSheet can become null e ven if the style rule | 114 // For style rules outside the document, .parentStyleSheet can become null e ven if the style rule |
114 // is still observable from JavaScript. This matches the behavior of .parent Node for nodes, but | 115 // is still observable from JavaScript. This matches the behavior of .parent Node for nodes, but |
115 // it's not ideal because it makes the CSSOM's behavior depend on the timing of garbage collection. | 116 // it's not ideal because it makes the CSSOM's behavior depend on the timing of garbage collection. |
116 for (unsigned i = 0; i < m_childRuleCSSOMWrappers.size(); ++i) { | 117 for (unsigned i = 0; i < m_childRuleCSSOMWrappers.size(); ++i) { |
117 if (m_childRuleCSSOMWrappers[i]) | 118 if (m_childRuleCSSOMWrappers[i]) |
118 m_childRuleCSSOMWrappers[i]->setParentStyleSheet(0); | 119 m_childRuleCSSOMWrappers[i]->setParentStyleSheet(0); |
119 } | 120 } |
121 for (unsigned i = 0; i < m_extraChildRuleCSSOMWrappers.size(); ++i) { | |
122 m_extraChildRuleCSSOMWrappers[i]->setParentStyleSheet(0); | |
esprehn
2013/10/29 20:08:44
braces are not needed.
ojan
2013/10/29 20:35:15
Done.
| |
123 } | |
120 if (m_mediaCSSOMWrapper) | 124 if (m_mediaCSSOMWrapper) |
121 m_mediaCSSOMWrapper->clearParentStyleSheet(); | 125 m_mediaCSSOMWrapper->clearParentStyleSheet(); |
122 | 126 |
123 m_contents->unregisterClient(this); | 127 m_contents->unregisterClient(this); |
124 } | 128 } |
125 | 129 |
130 void CSSStyleSheet::extraCSSOMWrapperIndices(Vector<unsigned>& indices) | |
131 { | |
132 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.
| |
133 | |
134 for (unsigned i = 0; i < m_extraChildRuleCSSOMWrappers.size(); ++i) { | |
135 CSSRule* cssRule = m_extraChildRuleCSSOMWrappers[i].get(); | |
136 ASSERT(cssRule->type() == CSSRule::STYLE_RULE); | |
137 StyleRule* styleRule = toCSSStyleRule(cssRule)->styleRule(); | |
138 | |
139 bool didFindIndex = false; | |
140 for (unsigned j = 0; j < m_contents->ruleCount(); ++j) { | |
141 if (m_contents->ruleAt(j) == styleRule) { | |
142 didFindIndex = true; | |
143 indices[i] = j; | |
144 break; | |
145 } | |
146 } | |
147 ASSERT(didFindIndex); | |
148 if (!didFindIndex) | |
149 indices[i] = 0; | |
150 } | |
151 } | |
152 | |
126 void CSSStyleSheet::willMutateRules() | 153 void CSSStyleSheet::willMutateRules() |
127 { | 154 { |
128 // If we are the only client it is safe to mutate. | 155 // If we are the only client it is safe to mutate. |
129 if (m_contents->hasOneClient() && !m_contents->isInMemoryCache()) { | 156 if (m_contents->hasOneClient() && !m_contents->isInMemoryCache()) { |
130 m_contents->setMutable(); | 157 m_contents->setMutable(); |
131 return; | 158 return; |
132 } | 159 } |
133 // Only cacheable stylesheets should have multiple clients. | 160 // Only cacheable stylesheets should have multiple clients. |
134 ASSERT(m_contents->isCacheable()); | 161 ASSERT(m_contents->isCacheable()); |
135 | 162 |
163 Vector<unsigned> indices; | |
164 extraCSSOMWrapperIndices(indices); | |
esprehn
2013/10/29 20:08:44
const Vector<unsigned>& indexes = cssomWrapperInde
| |
165 | |
136 // Copy-on-write. | 166 // Copy-on-write. |
137 m_contents->unregisterClient(this); | 167 m_contents->unregisterClient(this); |
138 m_contents = m_contents->copy(); | 168 m_contents = m_contents->copy(); |
139 m_contents->registerClient(this); | 169 m_contents->registerClient(this); |
140 | 170 |
141 m_contents->setMutable(); | 171 m_contents->setMutable(); |
142 | 172 |
143 // Any existing CSSOM wrappers need to be connected to the copied child rule s. | 173 // Any existing CSSOM wrappers need to be connected to the copied child rule s. |
144 reattachChildRuleCSSOMWrappers(); | 174 reattachChildRuleCSSOMWrappers(indices); |
145 } | 175 } |
146 | 176 |
147 void CSSStyleSheet::didMutateRules() | 177 void CSSStyleSheet::didMutateRules() |
148 { | 178 { |
149 ASSERT(m_contents->isMutable()); | 179 ASSERT(m_contents->isMutable()); |
150 ASSERT(m_contents->hasOneClient()); | 180 ASSERT(m_contents->hasOneClient()); |
151 | 181 |
152 didMutate(PartialRuleUpdate); | 182 didMutate(PartialRuleUpdate); |
153 } | 183 } |
154 | 184 |
155 void CSSStyleSheet::didMutate(StyleSheetUpdateType updateType) | 185 void CSSStyleSheet::didMutate(StyleSheetUpdateType updateType) |
156 { | 186 { |
157 Document* owner = ownerDocument(); | 187 Document* owner = ownerDocument(); |
158 if (!owner) | 188 if (!owner) |
159 return; | 189 return; |
160 | 190 |
161 // Need FullStyleUpdate when insertRule or deleteRule, | 191 // Need FullStyleUpdate when insertRule or deleteRule, |
162 // because StyleSheetCollection::analyzeStyleSheetChange cannot detect parti al rule update. | 192 // because StyleSheetCollection::analyzeStyleSheetChange cannot detect parti al rule update. |
163 StyleResolverUpdateMode updateMode = updateType != PartialRuleUpdate ? Analy zedStyleUpdate : FullStyleUpdate; | 193 StyleResolverUpdateMode updateMode = updateType != PartialRuleUpdate ? Analy zedStyleUpdate : FullStyleUpdate; |
164 owner->modifiedStyleSheet(this, RecalcStyleDeferred, updateMode); | 194 owner->modifiedStyleSheet(this, RecalcStyleDeferred, updateMode); |
165 } | 195 } |
166 | 196 |
167 void CSSStyleSheet::reattachChildRuleCSSOMWrappers() | 197 void CSSStyleSheet::registerExtraChildRuleCSSOMWrapper(PassRefPtr<CSSRule> rule) |
168 { | 198 { |
199 m_extraChildRuleCSSOMWrappers.append(rule); | |
200 } | |
201 | |
202 void CSSStyleSheet::reattachChildRuleCSSOMWrappers(const Vector<unsigned>& extra CSSOMWrapperIndices) | |
203 { | |
204 ASSERT(extraCSSOMWrapperIndices.size() == m_extraChildRuleCSSOMWrappers.size ()); | |
205 for (unsigned i = 0; i < extraCSSOMWrapperIndices.size(); ++i) { | |
206 m_extraChildRuleCSSOMWrappers[i]->reattach(m_contents->ruleAt(extraCSSOM WrapperIndices[i])); | |
esprehn
2013/10/29 20:08:44
extra braces
ojan
2013/10/29 20:35:15
Done.
| |
207 } | |
208 | |
169 for (unsigned i = 0; i < m_childRuleCSSOMWrappers.size(); ++i) { | 209 for (unsigned i = 0; i < m_childRuleCSSOMWrappers.size(); ++i) { |
170 if (!m_childRuleCSSOMWrappers[i]) | 210 if (!m_childRuleCSSOMWrappers[i]) |
171 continue; | 211 continue; |
172 m_childRuleCSSOMWrappers[i]->reattach(m_contents->ruleAt(i)); | 212 m_childRuleCSSOMWrappers[i]->reattach(m_contents->ruleAt(i)); |
173 } | 213 } |
174 } | 214 } |
175 | 215 |
176 void CSSStyleSheet::setDisabled(bool disabled) | 216 void CSSStyleSheet::setDisabled(bool disabled) |
177 { | 217 { |
178 if (disabled == m_isDisabled) | 218 if (disabled == m_isDisabled) |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
363 root = root->parentStyleSheet(); | 403 root = root->parentStyleSheet(); |
364 return root->ownerNode() ? &root->ownerNode()->document() : 0; | 404 return root->ownerNode() ? &root->ownerNode()->document() : 0; |
365 } | 405 } |
366 | 406 |
367 void CSSStyleSheet::clearChildRuleCSSOMWrappers() | 407 void CSSStyleSheet::clearChildRuleCSSOMWrappers() |
368 { | 408 { |
369 m_childRuleCSSOMWrappers.clear(); | 409 m_childRuleCSSOMWrappers.clear(); |
370 } | 410 } |
371 | 411 |
372 } | 412 } |
OLD | NEW |