| 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 #include "core/page/Page.h" | 45 #include "core/page/Page.h" |
| 46 #include "core/page/PageGroup.h" | 46 #include "core/page/PageGroup.h" |
| 47 #include "core/page/Settings.h" | 47 #include "core/page/Settings.h" |
| 48 #include "core/page/UserContentURLPattern.h" | 48 #include "core/page/UserContentURLPattern.h" |
| 49 #include "core/svg/SVGStyleElement.h" | 49 #include "core/svg/SVGStyleElement.h" |
| 50 | 50 |
| 51 namespace WebCore { | 51 namespace WebCore { |
| 52 | 52 |
| 53 using namespace HTMLNames; | 53 using namespace HTMLNames; |
| 54 | 54 |
| 55 StyleSheetCollections::StyleSheetCollections(Document* document) | 55 StyleSheetCollections::StyleSheetCollections(Document& document) |
| 56 : m_document(document) | 56 : m_document(document) |
| 57 , m_pendingStylesheets(0) | 57 , m_pendingStylesheets(0) |
| 58 , m_injectedStyleSheetCacheValid(false) | 58 , m_injectedStyleSheetCacheValid(false) |
| 59 , m_needsUpdateActiveStylesheetsOnStyleRecalc(false) | 59 , m_needsUpdateActiveStylesheetsOnStyleRecalc(false) |
| 60 , m_usesSiblingRules(false) | 60 , m_usesSiblingRules(false) |
| 61 , m_usesSiblingRulesOverride(false) | 61 , m_usesSiblingRulesOverride(false) |
| 62 , m_usesFirstLineRules(false) | 62 , m_usesFirstLineRules(false) |
| 63 , m_usesFirstLetterRules(false) | 63 , m_usesFirstLetterRules(false) |
| 64 , m_usesRemUnits(false) | 64 , m_usesRemUnits(false) |
| 65 , m_documentStyleSheetCollection(document) | 65 , m_documentStyleSheetCollection(document) |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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(TreeS
cope& 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, 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(toS
hadowRoot(treeScope))); |
| 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(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); |
| 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 { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 164 { | 164 { |
| 165 m_usesSiblingRules = features.usesSiblingRules(); | 165 m_usesSiblingRules = features.usesSiblingRules(); |
| 166 m_usesFirstLineRules = features.usesFirstLineRules(); | 166 m_usesFirstLineRules = features.usesFirstLineRules(); |
| 167 } | 167 } |
| 168 | 168 |
| 169 CSSStyleSheet* StyleSheetCollections::pageUserSheet() | 169 CSSStyleSheet* StyleSheetCollections::pageUserSheet() |
| 170 { | 170 { |
| 171 if (m_pageUserSheet) | 171 if (m_pageUserSheet) |
| 172 return m_pageUserSheet.get(); | 172 return m_pageUserSheet.get(); |
| 173 | 173 |
| 174 Page* owningPage = m_document->page(); | 174 Page* owningPage = m_document.page(); |
| 175 if (!owningPage) | 175 if (!owningPage) |
| 176 return 0; | 176 return 0; |
| 177 | 177 |
| 178 String userSheetText = owningPage->userStyleSheet(); | 178 String userSheetText = owningPage->userStyleSheet(); |
| 179 if (userSheetText.isEmpty()) | 179 if (userSheetText.isEmpty()) |
| 180 return 0; | 180 return 0; |
| 181 | 181 |
| 182 // Parse the sheet and cache it. | 182 // Parse the sheet and cache it. |
| 183 m_pageUserSheet = CSSStyleSheet::createInline(m_document, m_document->settin
gs()->userStyleSheetLocation()); | 183 m_pageUserSheet = CSSStyleSheet::createInline(&m_document, m_document.settin
gs()->userStyleSheetLocation()); |
| 184 m_pageUserSheet->contents()->setIsUserStyleSheet(true); | 184 m_pageUserSheet->contents()->setIsUserStyleSheet(true); |
| 185 m_pageUserSheet->contents()->parseString(userSheetText); | 185 m_pageUserSheet->contents()->parseString(userSheetText); |
| 186 return m_pageUserSheet.get(); | 186 return m_pageUserSheet.get(); |
| 187 } | 187 } |
| 188 | 188 |
| 189 void StyleSheetCollections::clearPageUserSheet() | 189 void StyleSheetCollections::clearPageUserSheet() |
| 190 { | 190 { |
| 191 if (m_pageUserSheet) { | 191 if (m_pageUserSheet) { |
| 192 RefPtr<StyleSheet> removedSheet = m_pageUserSheet; | 192 RefPtr<StyleSheet> removedSheet = m_pageUserSheet; |
| 193 m_pageUserSheet = 0; | 193 m_pageUserSheet = 0; |
| 194 m_document->removedStyleSheet(removedSheet.get()); | 194 m_document.removedStyleSheet(removedSheet.get()); |
| 195 } | 195 } |
| 196 } | 196 } |
| 197 | 197 |
| 198 void StyleSheetCollections::updatePageUserSheet() | 198 void StyleSheetCollections::updatePageUserSheet() |
| 199 { | 199 { |
| 200 clearPageUserSheet(); | 200 clearPageUserSheet(); |
| 201 // FIXME: Why is this immediately and not defer? | 201 // FIXME: Why is this immediately and not defer? |
| 202 if (StyleSheet* addedSheet = pageUserSheet()) | 202 if (StyleSheet* addedSheet = pageUserSheet()) |
| 203 m_document->addedStyleSheet(addedSheet, RecalcStyleImmediately); | 203 m_document.addedStyleSheet(addedSheet, RecalcStyleImmediately); |
| 204 } | 204 } |
| 205 | 205 |
| 206 const Vector<RefPtr<CSSStyleSheet> >& StyleSheetCollections::injectedUserStyleSh
eets() const | 206 const Vector<RefPtr<CSSStyleSheet> >& StyleSheetCollections::injectedUserStyleSh
eets() const |
| 207 { | 207 { |
| 208 updateInjectedStyleSheetCache(); | 208 updateInjectedStyleSheetCache(); |
| 209 return m_injectedUserStyleSheets; | 209 return m_injectedUserStyleSheets; |
| 210 } | 210 } |
| 211 | 211 |
| 212 const Vector<RefPtr<CSSStyleSheet> >& StyleSheetCollections::injectedAuthorStyle
Sheets() const | 212 const Vector<RefPtr<CSSStyleSheet> >& StyleSheetCollections::injectedAuthorStyle
Sheets() const |
| 213 { | 213 { |
| 214 updateInjectedStyleSheetCache(); | 214 updateInjectedStyleSheetCache(); |
| 215 return m_injectedAuthorStyleSheets; | 215 return m_injectedAuthorStyleSheets; |
| 216 } | 216 } |
| 217 | 217 |
| 218 void StyleSheetCollections::updateInjectedStyleSheetCache() const | 218 void StyleSheetCollections::updateInjectedStyleSheetCache() const |
| 219 { | 219 { |
| 220 if (m_injectedStyleSheetCacheValid) | 220 if (m_injectedStyleSheetCacheValid) |
| 221 return; | 221 return; |
| 222 m_injectedStyleSheetCacheValid = true; | 222 m_injectedStyleSheetCacheValid = true; |
| 223 m_injectedUserStyleSheets.clear(); | 223 m_injectedUserStyleSheets.clear(); |
| 224 m_injectedAuthorStyleSheets.clear(); | 224 m_injectedAuthorStyleSheets.clear(); |
| 225 | 225 |
| 226 Page* owningPage = m_document->page(); | 226 Page* owningPage = m_document.page(); |
| 227 if (!owningPage) | 227 if (!owningPage) |
| 228 return; | 228 return; |
| 229 | 229 |
| 230 const PageGroup& pageGroup = owningPage->group(); | 230 const PageGroup& pageGroup = owningPage->group(); |
| 231 const UserStyleSheetVector& sheets = pageGroup.userStyleSheets(); | 231 const UserStyleSheetVector& sheets = pageGroup.userStyleSheets(); |
| 232 for (unsigned i = 0; i < sheets.size(); ++i) { | 232 for (unsigned i = 0; i < sheets.size(); ++i) { |
| 233 const UserStyleSheet* sheet = sheets[i].get(); | 233 const UserStyleSheet* sheet = sheets[i].get(); |
| 234 if (sheet->injectedFrames() == InjectInTopFrameOnly && m_document->owner
Element()) | 234 if (sheet->injectedFrames() == InjectInTopFrameOnly && m_document.ownerE
lement()) |
| 235 continue; | 235 continue; |
| 236 if (!UserContentURLPattern::matchesPatterns(m_document->url(), sheet->wh
itelist(), sheet->blacklist())) | 236 if (!UserContentURLPattern::matchesPatterns(m_document.url(), sheet->whi
telist(), sheet->blacklist())) |
| 237 continue; | 237 continue; |
| 238 RefPtr<CSSStyleSheet> groupSheet = CSSStyleSheet::createInline(const_cas
t<Document*>(m_document), sheet->url()); | 238 RefPtr<CSSStyleSheet> groupSheet = CSSStyleSheet::createInline(const_cas
t<Document*>(&m_document), sheet->url()); |
| 239 bool isUserStyleSheet = sheet->level() == UserStyleUserLevel; | 239 bool isUserStyleSheet = sheet->level() == UserStyleUserLevel; |
| 240 if (isUserStyleSheet) | 240 if (isUserStyleSheet) |
| 241 m_injectedUserStyleSheets.append(groupSheet); | 241 m_injectedUserStyleSheets.append(groupSheet); |
| 242 else | 242 else |
| 243 m_injectedAuthorStyleSheets.append(groupSheet); | 243 m_injectedAuthorStyleSheets.append(groupSheet); |
| 244 groupSheet->contents()->setIsUserStyleSheet(isUserStyleSheet); | 244 groupSheet->contents()->setIsUserStyleSheet(isUserStyleSheet); |
| 245 groupSheet->contents()->parseString(sheet->source()); | 245 groupSheet->contents()->parseString(sheet->source()); |
| 246 } | 246 } |
| 247 } | 247 } |
| 248 | 248 |
| 249 void StyleSheetCollections::invalidateInjectedStyleSheetCache() | 249 void StyleSheetCollections::invalidateInjectedStyleSheetCache() |
| 250 { | 250 { |
| 251 m_injectedStyleSheetCacheValid = false; | 251 m_injectedStyleSheetCacheValid = false; |
| 252 m_needsDocumentStyleSheetsUpdate = true; | 252 m_needsDocumentStyleSheetsUpdate = true; |
| 253 // FIXME: updateInjectedStyleSheetCache is called inside StyleSheetCollectio
n::updateActiveStyleSheets | 253 // FIXME: updateInjectedStyleSheetCache is called inside StyleSheetCollectio
n::updateActiveStyleSheets |
| 254 // and batch updates lots of sheets so we can't call addedStyleSheet() or re
movedStyleSheet(). | 254 // and batch updates lots of sheets so we can't call addedStyleSheet() or re
movedStyleSheet(). |
| 255 m_document->styleResolverChanged(RecalcStyleDeferred); | 255 m_document.styleResolverChanged(RecalcStyleDeferred); |
| 256 } | 256 } |
| 257 | 257 |
| 258 void StyleSheetCollections::addAuthorSheet(PassRefPtr<StyleSheetContents> author
Sheet) | 258 void StyleSheetCollections::addAuthorSheet(PassRefPtr<StyleSheetContents> author
Sheet) |
| 259 { | 259 { |
| 260 ASSERT(!authorSheet->isUserStyleSheet()); | 260 ASSERT(!authorSheet->isUserStyleSheet()); |
| 261 m_authorStyleSheets.append(CSSStyleSheet::create(authorSheet, m_document)); | 261 m_authorStyleSheets.append(CSSStyleSheet::create(authorSheet, &m_document)); |
| 262 m_document->addedStyleSheet(m_authorStyleSheets.last().get(), RecalcStyleImm
ediately); | 262 m_document.addedStyleSheet(m_authorStyleSheets.last().get(), RecalcStyleImme
diately); |
| 263 m_needsDocumentStyleSheetsUpdate = true; | 263 m_needsDocumentStyleSheetsUpdate = true; |
| 264 } | 264 } |
| 265 | 265 |
| 266 void StyleSheetCollections::addUserSheet(PassRefPtr<StyleSheetContents> userShee
t) | 266 void StyleSheetCollections::addUserSheet(PassRefPtr<StyleSheetContents> userShee
t) |
| 267 { | 267 { |
| 268 ASSERT(userSheet->isUserStyleSheet()); | 268 ASSERT(userSheet->isUserStyleSheet()); |
| 269 m_userStyleSheets.append(CSSStyleSheet::create(userSheet, m_document)); | 269 m_userStyleSheets.append(CSSStyleSheet::create(userSheet, &m_document)); |
| 270 m_document->addedStyleSheet(m_userStyleSheets.last().get(), RecalcStyleImmed
iately); | 270 m_document.addedStyleSheet(m_userStyleSheets.last().get(), RecalcStyleImmedi
ately); |
| 271 m_needsDocumentStyleSheetsUpdate = true; | 271 m_needsDocumentStyleSheetsUpdate = true; |
| 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) ? styleSh
eetCandidateNode->treeScope() : m_document; | 282 TreeScope* treeScope = isHTMLStyleElement(styleSheetCandidateNode) ? styleSh
eetCandidateNode->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); |
| 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 TreeScope& treeScope = isHTMLStyleElement(node) ? *node->treeScope() : m_doc
ument; |
| 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); |
| 319 m_dirtyTreeScopes.add(treeScope); | 319 m_dirtyTreeScopes.add(&treeScope); |
| 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 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); |
| 336 m_activeTreeScopes.remove(treeScope); | 336 m_activeTreeScopes.remove(treeScope); |
| 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 TreeScope* treeScope = isHTMLStyleElement(node) ? node->treeScope() : &m_doc
ument; |
| 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); |
| 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 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); |
| 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()); |
| 397 } | 397 } |
| 398 | 398 |
| 399 m_needsUpdateActiveStylesheetsOnStyleRecalc = false; | 399 m_needsUpdateActiveStylesheetsOnStyleRecalc = false; |
| 400 activeStyleSheetsUpdatedForInspector(); | 400 activeStyleSheetsUpdatedForInspector(); |
| 401 m_usesRemUnits = m_documentStyleSheetCollection.usesRemUnits(); | 401 m_usesRemUnits = m_documentStyleSheetCollection.usesRemUnits(); |
| 402 | 402 |
| 403 if (m_needsDocumentStyleSheetsUpdate || updateMode == FullStyleUpdate) { | 403 if (m_needsDocumentStyleSheetsUpdate || updateMode == FullStyleUpdate) { |
| 404 m_document->notifySeamlessChildDocumentsOfStylesheetUpdate(); | 404 m_document.notifySeamlessChildDocumentsOfStylesheetUpdate(); |
| 405 m_needsDocumentStyleSheetsUpdate = false; | 405 m_needsDocumentStyleSheetsUpdate = false; |
| 406 } | 406 } |
| 407 | 407 |
| 408 return requiresFullStyleRecalc; | 408 return requiresFullStyleRecalc; |
| 409 } | 409 } |
| 410 | 410 |
| 411 void StyleSheetCollections::activeStyleSheetsUpdatedForInspector() | 411 void StyleSheetCollections::activeStyleSheetsUpdatedForInspector() |
| 412 { | 412 { |
| 413 if (m_activeTreeScopes.isEmpty()) { | 413 if (m_activeTreeScopes.isEmpty()) { |
| 414 InspectorInstrumentation::activeStyleSheetsUpdated(m_document, m_documen
tStyleSheetCollection.styleSheetsForStyleSheetList()); | 414 InspectorInstrumentation::activeStyleSheetsUpdated(&m_document, m_docume
ntStyleSheetCollection.styleSheetsForStyleSheetList()); |
| 415 return; | 415 return; |
| 416 } | 416 } |
| 417 Vector<RefPtr<StyleSheet> > activeStyleSheets; | 417 Vector<RefPtr<StyleSheet> > activeStyleSheets; |
| 418 | 418 |
| 419 activeStyleSheets.append(m_documentStyleSheetCollection.styleSheetsForStyleS
heetList()); | 419 activeStyleSheets.append(m_documentStyleSheetCollection.styleSheetsForStyleS
heetList()); |
| 420 | 420 |
| 421 TreeScopeSet::iterator begin = m_activeTreeScopes.begin(); | 421 TreeScopeSet::iterator begin = m_activeTreeScopes.begin(); |
| 422 TreeScopeSet::iterator end = m_activeTreeScopes.end(); | 422 TreeScopeSet::iterator end = m_activeTreeScopes.end(); |
| 423 for (TreeScopeSet::iterator it = begin; it != end; ++it) { | 423 for (TreeScopeSet::iterator it = begin; it != end; ++it) { |
| 424 if (StyleSheetCollection* collection = m_styleSheetCollectionMap.get(*it
)) | 424 if (StyleSheetCollection* collection = m_styleSheetCollectionMap.get(*it
)) |
| 425 activeStyleSheets.append(collection->styleSheetsForStyleSheetList())
; | 425 activeStyleSheets.append(collection->styleSheetsForStyleSheetList())
; |
| 426 } | 426 } |
| 427 | 427 |
| 428 // FIXME: Inspector needs a vector which has all active stylesheets. | 428 // FIXME: Inspector needs a vector which has all active stylesheets. |
| 429 // However, creating such a large vector might cause performance regression. | 429 // However, creating such a large vector might cause performance regression. |
| 430 // Need to implement some smarter solution. | 430 // Need to implement some smarter solution. |
| 431 InspectorInstrumentation::activeStyleSheetsUpdated(m_document, activeStyleSh
eets); | 431 InspectorInstrumentation::activeStyleSheetsUpdated(&m_document, activeStyleS
heets); |
| 432 } | 432 } |
| 433 | 433 |
| 434 void StyleSheetCollections::didRemoveShadowRoot(ShadowRoot* shadowRoot) | 434 void StyleSheetCollections::didRemoveShadowRoot(ShadowRoot* shadowRoot) |
| 435 { | 435 { |
| 436 m_styleSheetCollectionMap.remove(shadowRoot); | 436 m_styleSheetCollectionMap.remove(shadowRoot); |
| 437 } | 437 } |
| 438 | 438 |
| 439 void StyleSheetCollections::appendActiveAuthorStyleSheets(StyleResolver* styleRe
solver) | 439 void StyleSheetCollections::appendActiveAuthorStyleSheets(StyleResolver* styleRe
solver) |
| 440 { | 440 { |
| 441 ASSERT(styleResolver); | 441 ASSERT(styleResolver); |
| 442 | 442 |
| 443 styleResolver->setBuildScopedStyleTreeInDocumentOrder(true); | 443 styleResolver->setBuildScopedStyleTreeInDocumentOrder(true); |
| 444 styleResolver->appendAuthorStyleSheets(0, m_documentStyleSheetCollection.act
iveAuthorStyleSheets()); | 444 styleResolver->appendAuthorStyleSheets(0, m_documentStyleSheetCollection.act
iveAuthorStyleSheets()); |
| 445 | 445 |
| 446 TreeScopeSet::iterator begin = m_activeTreeScopes.begin(); | 446 TreeScopeSet::iterator begin = m_activeTreeScopes.begin(); |
| 447 TreeScopeSet::iterator end = m_activeTreeScopes.end(); | 447 TreeScopeSet::iterator end = m_activeTreeScopes.end(); |
| 448 for (TreeScopeSet::iterator it = begin; it != end; ++it) { | 448 for (TreeScopeSet::iterator it = begin; it != end; ++it) { |
| 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 |