OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) | 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
4 * (C) 2001 Dirk Mueller (mueller@kde.org) | 4 * (C) 2001 Dirk Mueller (mueller@kde.org) |
5 * (C) 2006 Alexey Proskuryakov (ap@webkit.org) | 5 * (C) 2006 Alexey Proskuryakov (ap@webkit.org) |
6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2011, 2012 Apple Inc. All r
ights reserved. | 6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2011, 2012 Apple Inc. All r
ights reserved. |
7 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t
orchmobile.com/) | 7 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t
orchmobile.com/) |
8 * Copyright (C) 2008, 2009, 2011, 2012 Google Inc. All rights reserved. | 8 * Copyright (C) 2008, 2009, 2011, 2012 Google Inc. All rights reserved. |
9 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) | 9 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) |
10 * Copyright (C) Research In Motion Limited 2010-2011. All rights reserved. | 10 * Copyright (C) Research In Motion Limited 2010-2011. All rights reserved. |
(...skipping 52 matching lines...) Loading... |
63 , m_usesSiblingRulesOverride(false) | 63 , m_usesSiblingRulesOverride(false) |
64 , m_usesFirstLineRules(false) | 64 , m_usesFirstLineRules(false) |
65 , m_usesFirstLetterRules(false) | 65 , m_usesFirstLetterRules(false) |
66 , m_usesRemUnits(false) | 66 , m_usesRemUnits(false) |
67 , m_maxDirectAdjacentSelectors(0) | 67 , m_maxDirectAdjacentSelectors(0) |
68 { | 68 { |
69 } | 69 } |
70 | 70 |
71 StyleEngine::~StyleEngine() | 71 StyleEngine::~StyleEngine() |
72 { | 72 { |
73 if (m_pageUserSheet) | |
74 m_pageUserSheet->clearOwnerNode(); | |
75 for (unsigned i = 0; i < m_injectedAuthorStyleSheets.size(); ++i) | 73 for (unsigned i = 0; i < m_injectedAuthorStyleSheets.size(); ++i) |
76 m_injectedAuthorStyleSheets[i]->clearOwnerNode(); | 74 m_injectedAuthorStyleSheets[i]->clearOwnerNode(); |
77 for (unsigned i = 0; i < m_userStyleSheets.size(); ++i) | |
78 m_userStyleSheets[i]->clearOwnerNode(); | |
79 for (unsigned i = 0; i < m_authorStyleSheets.size(); ++i) | 75 for (unsigned i = 0; i < m_authorStyleSheets.size(); ++i) |
80 m_authorStyleSheets[i]->clearOwnerNode(); | 76 m_authorStyleSheets[i]->clearOwnerNode(); |
81 } | 77 } |
82 | 78 |
83 void StyleEngine::insertTreeScopeInDocumentOrder(TreeScopeSet& treeScopes, TreeS
cope* treeScope) | 79 void StyleEngine::insertTreeScopeInDocumentOrder(TreeScopeSet& treeScopes, TreeS
cope* treeScope) |
84 { | 80 { |
85 if (treeScopes.isEmpty()) { | 81 if (treeScopes.isEmpty()) { |
86 treeScopes.add(treeScope); | 82 treeScopes.add(treeScope); |
87 return; | 83 return; |
88 } | 84 } |
(...skipping 74 matching lines...) Loading... |
163 m_maxDirectAdjacentSelectors = max(m_maxDirectAdjacentSelectors, features.ma
xDirectAdjacentSelectors()); | 159 m_maxDirectAdjacentSelectors = max(m_maxDirectAdjacentSelectors, features.ma
xDirectAdjacentSelectors()); |
164 } | 160 } |
165 | 161 |
166 void StyleEngine::resetCSSFeatureFlags(const RuleFeatureSet& features) | 162 void StyleEngine::resetCSSFeatureFlags(const RuleFeatureSet& features) |
167 { | 163 { |
168 m_usesSiblingRules = features.usesSiblingRules(); | 164 m_usesSiblingRules = features.usesSiblingRules(); |
169 m_usesFirstLineRules = features.usesFirstLineRules(); | 165 m_usesFirstLineRules = features.usesFirstLineRules(); |
170 m_maxDirectAdjacentSelectors = features.maxDirectAdjacentSelectors(); | 166 m_maxDirectAdjacentSelectors = features.maxDirectAdjacentSelectors(); |
171 } | 167 } |
172 | 168 |
173 CSSStyleSheet* StyleEngine::pageUserSheet() | |
174 { | |
175 if (m_pageUserSheet) | |
176 return m_pageUserSheet.get(); | |
177 | |
178 Page* owningPage = m_document.page(); | |
179 if (!owningPage) | |
180 return 0; | |
181 | |
182 String userSheetText = owningPage->userStyleSheet(); | |
183 if (userSheetText.isEmpty()) | |
184 return 0; | |
185 | |
186 // Parse the sheet and cache it. | |
187 m_pageUserSheet = CSSStyleSheet::createInline(&m_document, m_document.settin
gs()->userStyleSheetLocation()); | |
188 m_pageUserSheet->contents()->setIsUserStyleSheet(true); | |
189 m_pageUserSheet->contents()->parseString(userSheetText); | |
190 return m_pageUserSheet.get(); | |
191 } | |
192 | |
193 void StyleEngine::clearPageUserSheet() | |
194 { | |
195 if (m_pageUserSheet) { | |
196 RefPtr<StyleSheet> removedSheet = m_pageUserSheet; | |
197 m_pageUserSheet = 0; | |
198 m_document.removedStyleSheet(removedSheet.get()); | |
199 } | |
200 } | |
201 | |
202 void StyleEngine::updatePageUserSheet() | |
203 { | |
204 clearPageUserSheet(); | |
205 // FIXME: Why is this immediately and not defer? | |
206 if (StyleSheet* addedSheet = pageUserSheet()) | |
207 m_document.addedStyleSheet(addedSheet, RecalcStyleImmediately); | |
208 } | |
209 | |
210 const Vector<RefPtr<CSSStyleSheet> >& StyleEngine::injectedAuthorStyleSheets() c
onst | 169 const Vector<RefPtr<CSSStyleSheet> >& StyleEngine::injectedAuthorStyleSheets() c
onst |
211 { | 170 { |
212 updateInjectedStyleSheetCache(); | 171 updateInjectedStyleSheetCache(); |
213 return m_injectedAuthorStyleSheets; | 172 return m_injectedAuthorStyleSheets; |
214 } | 173 } |
215 | 174 |
216 void StyleEngine::updateInjectedStyleSheetCache() const | 175 void StyleEngine::updateInjectedStyleSheetCache() const |
217 { | 176 { |
218 if (m_injectedStyleSheetCacheValid) | 177 if (m_injectedStyleSheetCacheValid) |
219 return; | 178 return; |
220 m_injectedStyleSheetCacheValid = true; | 179 m_injectedStyleSheetCacheValid = true; |
221 m_injectedAuthorStyleSheets.clear(); | 180 m_injectedAuthorStyleSheets.clear(); |
222 | 181 |
223 Page* owningPage = m_document.page(); | 182 Page* owningPage = m_document.page(); |
224 if (!owningPage) | 183 if (!owningPage) |
225 return; | 184 return; |
226 | 185 |
227 const PageGroup& pageGroup = owningPage->group(); | 186 const PageGroup& pageGroup = owningPage->group(); |
228 const InjectedStyleSheetVector& sheets = pageGroup.injectedStyleSheets(); | 187 const InjectedStyleSheetVector& sheets = pageGroup.injectedStyleSheets(); |
229 for (unsigned i = 0; i < sheets.size(); ++i) { | 188 for (unsigned i = 0; i < sheets.size(); ++i) { |
230 const InjectedStyleSheet* sheet = sheets[i].get(); | 189 const InjectedStyleSheet* sheet = sheets[i].get(); |
231 if (sheet->injectedFrames() == InjectStyleInTopFrameOnly && m_document.o
wnerElement()) | 190 if (sheet->injectedFrames() == InjectStyleInTopFrameOnly && m_document.o
wnerElement()) |
232 continue; | 191 continue; |
233 if (!URLPatternMatcher::matchesPatterns(m_document.url(), sheet->whiteli
st())) | 192 if (!URLPatternMatcher::matchesPatterns(m_document.url(), sheet->whiteli
st())) |
234 continue; | 193 continue; |
235 RefPtr<CSSStyleSheet> groupSheet = CSSStyleSheet::createInline(const_cas
t<Document*>(&m_document), KURL()); | 194 RefPtr<CSSStyleSheet> groupSheet = CSSStyleSheet::createInline(const_cas
t<Document*>(&m_document), KURL()); |
236 m_injectedAuthorStyleSheets.append(groupSheet); | 195 m_injectedAuthorStyleSheets.append(groupSheet); |
237 groupSheet->contents()->setIsUserStyleSheet(false); | |
238 groupSheet->contents()->parseString(sheet->source()); | 196 groupSheet->contents()->parseString(sheet->source()); |
239 } | 197 } |
240 } | 198 } |
241 | 199 |
242 void StyleEngine::invalidateInjectedStyleSheetCache() | 200 void StyleEngine::invalidateInjectedStyleSheetCache() |
243 { | 201 { |
244 m_injectedStyleSheetCacheValid = false; | 202 m_injectedStyleSheetCacheValid = false; |
245 m_needsDocumentStyleSheetsUpdate = true; | 203 m_needsDocumentStyleSheetsUpdate = true; |
246 // FIXME: updateInjectedStyleSheetCache is called inside StyleSheetCollectio
n::updateActiveStyleSheets | 204 // FIXME: updateInjectedStyleSheetCache is called inside StyleSheetCollectio
n::updateActiveStyleSheets |
247 // and batch updates lots of sheets so we can't call addedStyleSheet() or re
movedStyleSheet(). | 205 // and batch updates lots of sheets so we can't call addedStyleSheet() or re
movedStyleSheet(). |
248 m_document.styleResolverChanged(RecalcStyleDeferred); | 206 m_document.styleResolverChanged(RecalcStyleDeferred); |
249 } | 207 } |
250 | 208 |
251 void StyleEngine::addAuthorSheet(PassRefPtr<StyleSheetContents> authorSheet) | 209 void StyleEngine::addAuthorSheet(PassRefPtr<StyleSheetContents> authorSheet) |
252 { | 210 { |
253 ASSERT(!authorSheet->isUserStyleSheet()); | |
254 m_authorStyleSheets.append(CSSStyleSheet::create(authorSheet, &m_document)); | 211 m_authorStyleSheets.append(CSSStyleSheet::create(authorSheet, &m_document)); |
255 m_document.addedStyleSheet(m_authorStyleSheets.last().get(), RecalcStyleImme
diately); | 212 m_document.addedStyleSheet(m_authorStyleSheets.last().get(), RecalcStyleImme
diately); |
256 m_needsDocumentStyleSheetsUpdate = true; | 213 m_needsDocumentStyleSheetsUpdate = true; |
257 } | 214 } |
258 | 215 |
259 void StyleEngine::addUserSheet(PassRefPtr<StyleSheetContents> userSheet) | |
260 { | |
261 ASSERT(userSheet->isUserStyleSheet()); | |
262 m_userStyleSheets.append(CSSStyleSheet::create(userSheet, &m_document)); | |
263 m_document.addedStyleSheet(m_userStyleSheets.last().get(), RecalcStyleImmedi
ately); | |
264 m_needsDocumentStyleSheetsUpdate = true; | |
265 } | |
266 | |
267 // This method is called whenever a top-level stylesheet has finished loading. | 216 // This method is called whenever a top-level stylesheet has finished loading. |
268 void StyleEngine::removePendingSheet(Node* styleSheetCandidateNode, RemovePendin
gSheetNotificationType notification) | 217 void StyleEngine::removePendingSheet(Node* styleSheetCandidateNode, RemovePendin
gSheetNotificationType notification) |
269 { | 218 { |
270 // Make sure we knew this sheet was pending, and that our count isn't out of
sync. | 219 // Make sure we knew this sheet was pending, and that our count isn't out of
sync. |
271 ASSERT(m_pendingStylesheets > 0); | 220 ASSERT(m_pendingStylesheets > 0); |
272 | 221 |
273 m_pendingStylesheets--; | 222 m_pendingStylesheets--; |
274 | 223 |
275 TreeScope* treeScope = isHTMLStyleElement(styleSheetCandidateNode) ? &styleS
heetCandidateNode->treeScope() : &m_document; | 224 TreeScope* treeScope = isHTMLStyleElement(styleSheetCandidateNode) ? &styleS
heetCandidateNode->treeScope() : &m_document; |
276 if (treeScope == m_document) | 225 if (treeScope == m_document) |
(...skipping 184 matching lines...) Loading... |
461 if (StyleSheetCollection* collection = m_styleSheetCollectionMap.get(*it
)) { | 410 if (StyleSheetCollection* collection = m_styleSheetCollectionMap.get(*it
)) { |
462 styleResolver->setBuildScopedStyleTreeInDocumentOrder(!collection->s
copingNodesForStyleScoped()); | 411 styleResolver->setBuildScopedStyleTreeInDocumentOrder(!collection->s
copingNodesForStyleScoped()); |
463 styleResolver->appendAuthorStyleSheets(0, collection->activeAuthorSt
yleSheets()); | 412 styleResolver->appendAuthorStyleSheets(0, collection->activeAuthorSt
yleSheets()); |
464 } | 413 } |
465 } | 414 } |
466 styleResolver->finishAppendAuthorStyleSheets(); | 415 styleResolver->finishAppendAuthorStyleSheets(); |
467 styleResolver->setBuildScopedStyleTreeInDocumentOrder(false); | 416 styleResolver->setBuildScopedStyleTreeInDocumentOrder(false); |
468 } | 417 } |
469 | 418 |
470 } | 419 } |
OLD | NEW |