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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 if (treeScopes.contains(treeScope)) | 90 if (treeScopes.contains(treeScope)) |
91 return; | 91 return; |
92 | 92 |
93 TreeScopeSet::iterator begin = treeScopes.begin(); | 93 TreeScopeSet::iterator begin = treeScopes.begin(); |
94 TreeScopeSet::iterator end = treeScopes.end(); | 94 TreeScopeSet::iterator end = treeScopes.end(); |
95 TreeScopeSet::iterator it = end; | 95 TreeScopeSet::iterator it = end; |
96 TreeScope* followingTreeScope = 0; | 96 TreeScope* followingTreeScope = 0; |
97 do { | 97 do { |
98 --it; | 98 --it; |
99 TreeScope* n = *it; | 99 TreeScope* n = *it; |
100 unsigned short position = n->comparePosition(*treeScope); | 100 unsigned short position = n->comparePosition(treeScope); |
101 if (position & Node::DOCUMENT_POSITION_FOLLOWING) { | 101 if (position & Node::DOCUMENT_POSITION_FOLLOWING) { |
102 treeScopes.insertBefore(followingTreeScope, treeScope); | 102 treeScopes.insertBefore(followingTreeScope, treeScope); |
103 return; | 103 return; |
104 } | 104 } |
105 followingTreeScope = n; | 105 followingTreeScope = n; |
106 } while (it != begin); | 106 } while (it != begin); |
107 | 107 |
108 treeScopes.insertBefore(followingTreeScope, treeScope); | 108 treeScopes.insertBefore(followingTreeScope, treeScope); |
109 } | 109 } |
110 | 110 |
111 StyleSheetCollection* StyleSheetCollections::ensureStyleSheetCollectionFor(TreeS
cope& treeScope) | 111 StyleSheetCollection* StyleSheetCollections::ensureStyleSheetCollectionFor(NonNu
llPtr<TreeScope> treeScope) |
112 { | 112 { |
113 if (&treeScope == &m_document) | 113 if (treeScope == &m_document) |
114 return &m_documentStyleSheetCollection; | 114 return &m_documentStyleSheetCollection; |
115 | 115 |
116 HashMap<TreeScope*, OwnPtr<StyleSheetCollection> >::AddResult result = m_sty
leSheetCollectionMap.add(&treeScope, nullptr); | 116 HashMap<TreeScope*, OwnPtr<StyleSheetCollection> >::AddResult result = m_sty
leSheetCollectionMap.add(treeScope.get(), nullptr); |
117 if (result.isNewEntry) | 117 if (result.isNewEntry) |
118 result.iterator->value = adoptPtr(new ShadowTreeStyleSheetCollection(toS
hadowRoot(treeScope))); | 118 result.iterator->value = adoptPtr(new ShadowTreeStyleSheetCollection(*to
ShadowRoot(treeScope.get()))); |
119 return result.iterator->value.get(); | 119 return result.iterator->value.get(); |
120 } | 120 } |
121 | 121 |
122 StyleSheetCollection* StyleSheetCollections::styleSheetCollectionFor(TreeScope&
treeScope) | 122 StyleSheetCollection* StyleSheetCollections::styleSheetCollectionFor(NonNullPtr<
TreeScope> treeScope) |
123 { | 123 { |
124 if (&treeScope == &m_document) | 124 if (treeScope == &m_document) |
125 return &m_documentStyleSheetCollection; | 125 return &m_documentStyleSheetCollection; |
126 | 126 |
127 HashMap<TreeScope*, OwnPtr<StyleSheetCollection> >::iterator it = m_styleShe
etCollectionMap.find(&treeScope); | 127 HashMap<TreeScope*, OwnPtr<StyleSheetCollection> >::iterator it = m_styleShe
etCollectionMap.find(treeScope.get()); |
128 if (it == m_styleSheetCollectionMap.end()) | 128 if (it == m_styleSheetCollectionMap.end()) |
129 return 0; | 129 return 0; |
130 return it->value.get(); | 130 return it->value.get(); |
131 } | 131 } |
132 | 132 |
133 const Vector<RefPtr<StyleSheet> >& StyleSheetCollections::styleSheetsForStyleShe
etList() | 133 const Vector<RefPtr<StyleSheet> >& StyleSheetCollections::styleSheetsForStyleShe
etList() |
134 { | 134 { |
135 return m_documentStyleSheetCollection.styleSheetsForStyleSheetList(); | 135 return m_documentStyleSheetCollection.styleSheetsForStyleSheetList(); |
136 } | 136 } |
137 | 137 |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 } | 272 } |
273 | 273 |
274 // This method is called whenever a top-level stylesheet has finished loading. | 274 // This method is called whenever a top-level stylesheet has finished loading. |
275 void StyleSheetCollections::removePendingSheet(Node* styleSheetCandidateNode, Re
movePendingSheetNotificationType notification) | 275 void StyleSheetCollections::removePendingSheet(Node* styleSheetCandidateNode, Re
movePendingSheetNotificationType notification) |
276 { | 276 { |
277 // Make sure we knew this sheet was pending, and that our count isn't out of
sync. | 277 // Make sure we knew this sheet was pending, and that our count isn't out of
sync. |
278 ASSERT(m_pendingStylesheets > 0); | 278 ASSERT(m_pendingStylesheets > 0); |
279 | 279 |
280 m_pendingStylesheets--; | 280 m_pendingStylesheets--; |
281 | 281 |
282 TreeScope* treeScope = isHTMLStyleElement(styleSheetCandidateNode) ? &styleS
heetCandidateNode->treeScope() : &m_document; | 282 NonNullPtr<TreeScope> treeScope = isHTMLStyleElement(styleSheetCandidateNode
) ? styleSheetCandidateNode->treeScope() : &m_document; |
283 if (treeScope == &m_document) | 283 if (treeScope == &m_document) |
284 m_needsDocumentStyleSheetsUpdate = true; | 284 m_needsDocumentStyleSheetsUpdate = true; |
285 else | 285 else |
286 m_dirtyTreeScopes.add(treeScope); | 286 m_dirtyTreeScopes.add(treeScope.get()); |
287 | 287 |
288 if (m_pendingStylesheets) | 288 if (m_pendingStylesheets) |
289 return; | 289 return; |
290 | 290 |
291 if (notification == RemovePendingSheetNotifyLater) { | 291 if (notification == RemovePendingSheetNotifyLater) { |
292 m_document.setNeedsNotifyRemoveAllPendingStylesheet(); | 292 m_document.setNeedsNotifyRemoveAllPendingStylesheet(); |
293 return; | 293 return; |
294 } | 294 } |
295 | 295 |
296 // FIXME: We can't call addedStyleSheet or removedStyleSheet here because we
don't know | 296 // FIXME: We can't call addedStyleSheet or removedStyleSheet here because we
don't know |
297 // what's new. We should track that to tell the style system what changed. | 297 // what's new. We should track that to tell the style system what changed. |
298 m_document.didRemoveAllPendingStylesheet(); | 298 m_document.didRemoveAllPendingStylesheet(); |
299 } | 299 } |
300 | 300 |
301 void StyleSheetCollections::addStyleSheetCandidateNode(Node* node, bool createdB
yParser) | 301 void StyleSheetCollections::addStyleSheetCandidateNode(Node* node, bool createdB
yParser) |
302 { | 302 { |
303 if (!node->inDocument()) | 303 if (!node->inDocument()) |
304 return; | 304 return; |
305 | 305 |
306 TreeScope& treeScope = isHTMLStyleElement(node) ? node->treeScope() : m_docu
ment; | 306 NonNullPtr<TreeScope> treeScope = isHTMLStyleElement(node) ? node->treeScope
() : &m_document; |
307 ASSERT(isHTMLStyleElement(node) || &treeScope == &m_document); | 307 ASSERT(isHTMLStyleElement(node) || treeScope == &m_document); |
308 | 308 |
309 StyleSheetCollection* collection = ensureStyleSheetCollectionFor(treeScope); | 309 StyleSheetCollection* collection = ensureStyleSheetCollectionFor(treeScope); |
310 ASSERT(collection); | 310 ASSERT(collection); |
311 collection->addStyleSheetCandidateNode(node, createdByParser); | 311 collection->addStyleSheetCandidateNode(node, createdByParser); |
312 | 312 |
313 if (&treeScope == &m_document) { | 313 if (treeScope == &m_document) { |
314 m_needsDocumentStyleSheetsUpdate = true; | 314 m_needsDocumentStyleSheetsUpdate = true; |
315 return; | 315 return; |
316 } | 316 } |
317 | 317 |
318 insertTreeScopeInDocumentOrder(m_activeTreeScopes, &treeScope); | 318 insertTreeScopeInDocumentOrder(m_activeTreeScopes, treeScope.get()); |
319 m_dirtyTreeScopes.add(&treeScope); | 319 m_dirtyTreeScopes.add(treeScope.get()); |
320 } | 320 } |
321 | 321 |
322 void StyleSheetCollections::removeStyleSheetCandidateNode(Node* node, ContainerN
ode* scopingNode) | 322 void StyleSheetCollections::removeStyleSheetCandidateNode(Node* node, ContainerN
ode* scopingNode) |
323 { | 323 { |
324 TreeScope& treeScope = scopingNode ? scopingNode->treeScope() : m_document; | 324 NonNullPtr<TreeScope> treeScope = scopingNode ? scopingNode->treeScope() : &
m_document; |
325 ASSERT(isHTMLStyleElement(node) || &treeScope == &m_document); | 325 ASSERT(isHTMLStyleElement(node) || treeScope == &m_document); |
326 | 326 |
327 StyleSheetCollection* collection = styleSheetCollectionFor(treeScope); | 327 StyleSheetCollection* collection = styleSheetCollectionFor(treeScope); |
328 ASSERT(collection); | 328 ASSERT(collection); |
329 collection->removeStyleSheetCandidateNode(node, scopingNode); | 329 collection->removeStyleSheetCandidateNode(node, scopingNode); |
330 | 330 |
331 if (&treeScope == &m_document) { | 331 if (treeScope == &m_document) { |
332 m_needsDocumentStyleSheetsUpdate = true; | 332 m_needsDocumentStyleSheetsUpdate = true; |
333 return; | 333 return; |
334 } | 334 } |
335 m_dirtyTreeScopes.add(&treeScope); | 335 m_dirtyTreeScopes.add(treeScope.get()); |
336 m_activeTreeScopes.remove(&treeScope); | 336 m_activeTreeScopes.remove(treeScope.get()); |
337 } | 337 } |
338 | 338 |
339 void StyleSheetCollections::modifiedStyleSheetCandidateNode(Node* node) | 339 void StyleSheetCollections::modifiedStyleSheetCandidateNode(Node* node) |
340 { | 340 { |
341 if (!node->inDocument()) | 341 if (!node->inDocument()) |
342 return; | 342 return; |
343 | 343 |
344 TreeScope& treeScope = isHTMLStyleElement(node) ? node->treeScope() : m_docu
ment; | 344 NonNullPtr<TreeScope> treeScope = isHTMLStyleElement(node) ? node->treeScope
() : &m_document; |
345 ASSERT(isHTMLStyleElement(node) || &treeScope == &m_document); | 345 ASSERT(isHTMLStyleElement(node) || treeScope == &m_document); |
346 if (&treeScope == &m_document) { | 346 if (treeScope == &m_document) { |
347 m_needsDocumentStyleSheetsUpdate = true; | 347 m_needsDocumentStyleSheetsUpdate = true; |
348 return; | 348 return; |
349 } | 349 } |
350 m_dirtyTreeScopes.add(&treeScope); | 350 m_dirtyTreeScopes.add(treeScope.get()); |
351 } | 351 } |
352 | 352 |
353 bool StyleSheetCollections::shouldUpdateShadowTreeStyleSheetCollection(StyleReso
lverUpdateMode updateMode) | 353 bool StyleSheetCollections::shouldUpdateShadowTreeStyleSheetCollection(StyleReso
lverUpdateMode updateMode) |
354 { | 354 { |
355 return !m_dirtyTreeScopes.isEmpty() || updateMode == FullStyleUpdate; | 355 return !m_dirtyTreeScopes.isEmpty() || updateMode == FullStyleUpdate; |
356 } | 356 } |
357 | 357 |
358 bool StyleSheetCollections::updateActiveStyleSheets(StyleResolverUpdateMode upda
teMode) | 358 bool StyleSheetCollections::updateActiveStyleSheets(StyleResolverUpdateMode upda
teMode) |
359 { | 359 { |
360 if (m_document.inStyleRecalc()) { | 360 if (m_document.inStyleRecalc()) { |
361 // SVG <use> element may manage to invalidate style selector in the midd
le of a style recalc. | 361 // SVG <use> element may manage to invalidate style selector in the midd
le of a style recalc. |
362 // https://bugs.webkit.org/show_bug.cgi?id=54344 | 362 // https://bugs.webkit.org/show_bug.cgi?id=54344 |
363 // FIXME: This should be fixed in SVG and the call site replaced by ASSE
RT(!m_inStyleRecalc). | 363 // FIXME: This should be fixed in SVG and the call site replaced by ASSE
RT(!m_inStyleRecalc). |
364 m_needsUpdateActiveStylesheetsOnStyleRecalc = true; | 364 m_needsUpdateActiveStylesheetsOnStyleRecalc = true; |
365 return false; | 365 return false; |
366 | 366 |
367 } | 367 } |
368 if (!m_document.renderer() || !m_document.attached()) | 368 if (!m_document.renderer() || !m_document.attached()) |
369 return false; | 369 return false; |
370 | 370 |
371 bool requiresFullStyleRecalc = false; | 371 bool requiresFullStyleRecalc = false; |
372 if (m_needsDocumentStyleSheetsUpdate || updateMode == FullStyleUpdate) | 372 if (m_needsDocumentStyleSheetsUpdate || updateMode == FullStyleUpdate) |
373 requiresFullStyleRecalc = m_documentStyleSheetCollection.updateActiveSty
leSheets(this, updateMode); | 373 requiresFullStyleRecalc = m_documentStyleSheetCollection.updateActiveSty
leSheets(this, updateMode); |
374 | 374 |
375 if (shouldUpdateShadowTreeStyleSheetCollection(updateMode)) { | 375 if (shouldUpdateShadowTreeStyleSheetCollection(updateMode)) { |
376 TreeScopeSet treeScopes = updateMode == FullStyleUpdate ? m_activeTreeSc
opes : m_dirtyTreeScopes; | 376 TreeScopeSet treeScopes = updateMode == FullStyleUpdate ? m_activeTreeSc
opes : m_dirtyTreeScopes; |
377 HashSet<TreeScope*> treeScopesRemoved; | 377 HashSet<TreeScope*> treeScopesRemoved; |
378 | 378 |
379 for (TreeScopeSet::iterator it = treeScopes.begin(); it != treeScopes.en
d(); ++it) { | 379 for (TreeScopeSet::iterator it = treeScopes.begin(); it != treeScopes.en
d(); ++it) { |
380 TreeScope* treeScope = *it; | 380 NonNullPtr<TreeScope> treeScope(*it); |
381 ASSERT(treeScope != &m_document); | 381 ASSERT(treeScope != &m_document); |
382 ShadowTreeStyleSheetCollection* collection = static_cast<ShadowTreeS
tyleSheetCollection*>(styleSheetCollectionFor(*treeScope)); | 382 ShadowTreeStyleSheetCollection* collection = static_cast<ShadowTreeS
tyleSheetCollection*>(styleSheetCollectionFor(treeScope)); |
383 ASSERT(collection); | 383 ASSERT(collection); |
384 collection->updateActiveStyleSheets(this, updateMode); | 384 collection->updateActiveStyleSheets(this, updateMode); |
385 if (!collection->hasStyleSheetCandidateNodes()) | 385 if (!collection->hasStyleSheetCandidateNodes()) |
386 treeScopesRemoved.add(treeScope); | 386 treeScopesRemoved.add(treeScope.get()); |
387 } | 387 } |
388 if (!treeScopesRemoved.isEmpty()) | 388 if (!treeScopesRemoved.isEmpty()) |
389 for (HashSet<TreeScope*>::iterator it = treeScopesRemoved.begin(); i
t != treeScopesRemoved.end(); ++it) | 389 for (HashSet<TreeScope*>::iterator it = treeScopesRemoved.begin(); i
t != treeScopesRemoved.end(); ++it) |
390 m_activeTreeScopes.remove(*it); | 390 m_activeTreeScopes.remove(*it); |
391 m_dirtyTreeScopes.clear(); | 391 m_dirtyTreeScopes.clear(); |
392 } | 392 } |
393 | 393 |
394 if (StyleResolver* styleResolver = m_document.styleResolverIfExists()) { | 394 if (StyleResolver* styleResolver = m_document.styleResolverIfExists()) { |
395 styleResolver->finishAppendAuthorStyleSheets(); | 395 styleResolver->finishAppendAuthorStyleSheets(); |
396 resetCSSFeatureFlags(styleResolver->ruleFeatureSet()); | 396 resetCSSFeatureFlags(styleResolver->ruleFeatureSet()); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
449 if (StyleSheetCollection* collection = m_styleSheetCollectionMap.get(*it
)) { | 449 if (StyleSheetCollection* collection = m_styleSheetCollectionMap.get(*it
)) { |
450 styleResolver->setBuildScopedStyleTreeInDocumentOrder(!collection->s
copingNodesForStyleScoped()); | 450 styleResolver->setBuildScopedStyleTreeInDocumentOrder(!collection->s
copingNodesForStyleScoped()); |
451 styleResolver->appendAuthorStyleSheets(0, collection->activeAuthorSt
yleSheets()); | 451 styleResolver->appendAuthorStyleSheets(0, collection->activeAuthorSt
yleSheets()); |
452 } | 452 } |
453 } | 453 } |
454 styleResolver->finishAppendAuthorStyleSheets(); | 454 styleResolver->finishAppendAuthorStyleSheets(); |
455 styleResolver->setBuildScopedStyleTreeInDocumentOrder(false); | 455 styleResolver->setBuildScopedStyleTreeInDocumentOrder(false); |
456 } | 456 } |
457 | 457 |
458 } | 458 } |
OLD | NEW |