| 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 26 matching lines...) Expand all Loading... |
| 37 #include "sky/engine/core/dom/shadow/ShadowRoot.h" | 37 #include "sky/engine/core/dom/shadow/ShadowRoot.h" |
| 38 #include "sky/engine/core/frame/Settings.h" | 38 #include "sky/engine/core/frame/Settings.h" |
| 39 #include "sky/engine/core/html/HTMLStyleElement.h" | 39 #include "sky/engine/core/html/HTMLStyleElement.h" |
| 40 #include "sky/engine/core/html/imports/HTMLImportsController.h" | 40 #include "sky/engine/core/html/imports/HTMLImportsController.h" |
| 41 #include "sky/engine/core/page/Page.h" | 41 #include "sky/engine/core/page/Page.h" |
| 42 | 42 |
| 43 namespace blink { | 43 namespace blink { |
| 44 | 44 |
| 45 StyleEngine::StyleEngine(Document& document) | 45 StyleEngine::StyleEngine(Document& document) |
| 46 : m_document(&document) | 46 : m_document(&document) |
| 47 , m_isMaster(!document.importsController() || document.importsController()->
master() == &document) | |
| 48 , m_documentStyleSheetCollection(StyleSheetCollection::create(document)) | 47 , m_documentStyleSheetCollection(StyleSheetCollection::create(document)) |
| 49 , m_documentScopeDirty(true) | |
| 50 , m_ignorePendingStylesheets(false) | 48 , m_ignorePendingStylesheets(false) |
| 51 // We don't need to create CSSFontSelector for imported document or | 49 // We don't need to create CSSFontSelector for imported document or |
| 52 // HTMLTemplateElement's document, because those documents have no frame. | 50 // HTMLTemplateElement's document, because those documents have no frame. |
| 53 , m_fontSelector(document.frame() ? CSSFontSelector::create(&document) : nul
lptr) | 51 , m_fontSelector(document.frame() ? CSSFontSelector::create(&document) : nul
lptr) |
| 54 { | 52 { |
| 55 if (m_fontSelector) | 53 if (m_fontSelector) |
| 56 m_fontSelector->registerForInvalidationCallbacks(this); | 54 m_fontSelector->registerForInvalidationCallbacks(this); |
| 57 } | 55 } |
| 58 | 56 |
| 59 StyleEngine::~StyleEngine() | 57 StyleEngine::~StyleEngine() |
| (...skipping 13 matching lines...) Expand all Loading... |
| 73 | 71 |
| 74 // Decrement reference counts for things we could be keeping alive. | 72 // Decrement reference counts for things we could be keeping alive. |
| 75 m_fontSelector.clear(); | 73 m_fontSelector.clear(); |
| 76 m_resolver.clear(); | 74 m_resolver.clear(); |
| 77 m_styleSheetCollectionMap.clear(); | 75 m_styleSheetCollectionMap.clear(); |
| 78 for (ScopedStyleResolverSet::iterator it = m_scopedStyleResolvers.begin(); i
t != m_scopedStyleResolvers.end(); ++it) | 76 for (ScopedStyleResolverSet::iterator it = m_scopedStyleResolvers.begin(); i
t != m_scopedStyleResolvers.end(); ++it) |
| 79 const_cast<TreeScope&>((*it)->treeScope()).clearScopedStyleResolver(); | 77 const_cast<TreeScope&>((*it)->treeScope()).clearScopedStyleResolver(); |
| 80 m_scopedStyleResolvers.clear(); | 78 m_scopedStyleResolvers.clear(); |
| 81 } | 79 } |
| 82 | 80 |
| 83 inline Document* StyleEngine::master() | |
| 84 { | |
| 85 if (isMaster()) | |
| 86 return m_document; | |
| 87 HTMLImportsController* import = document().importsController(); | |
| 88 if (!import) // Document::import() can return null while executing its destr
uctor. | |
| 89 return 0; | |
| 90 return import->master(); | |
| 91 } | |
| 92 | |
| 93 const Vector<RefPtr<CSSStyleSheet>>& StyleEngine::activeAuthorStyleSheetsFor(Tre
eScope& treeScope) | 81 const Vector<RefPtr<CSSStyleSheet>>& StyleEngine::activeAuthorStyleSheetsFor(Tre
eScope& treeScope) |
| 94 { | 82 { |
| 95 if (treeScope == m_document) | 83 if (treeScope == m_document) |
| 96 return documentStyleSheetCollection()->activeAuthorStyleSheets(); | 84 return documentStyleSheetCollection()->activeAuthorStyleSheets(); |
| 97 return ensureStyleSheetCollectionFor(treeScope)->activeAuthorStyleSheets(); | 85 return ensureStyleSheetCollectionFor(treeScope)->activeAuthorStyleSheets(); |
| 98 } | 86 } |
| 99 | 87 |
| 100 void StyleEngine::insertTreeScopeInDocumentOrder(TreeScopeSet& treeScopes, TreeS
cope* treeScope) | 88 void StyleEngine::insertTreeScopeInDocumentOrder(TreeScopeSet& treeScopes, TreeS
cope* treeScope) |
| 101 { | 89 { |
| 102 if (treeScopes.isEmpty()) { | 90 if (treeScopes.isEmpty()) { |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 StyleSheetCollection* collection = styleSheetCollectionFor(treeScope); | 172 StyleSheetCollection* collection = styleSheetCollectionFor(treeScope); |
| 185 ASSERT(collection); | 173 ASSERT(collection); |
| 186 collection->removeStyleSheetCandidateNode(node, scopingNode); | 174 collection->removeStyleSheetCandidateNode(node, scopingNode); |
| 187 | 175 |
| 188 markTreeScopeDirty(treeScope); | 176 markTreeScopeDirty(treeScope); |
| 189 m_activeTreeScopes.remove(&treeScope); | 177 m_activeTreeScopes.remove(&treeScope); |
| 190 } | 178 } |
| 191 | 179 |
| 192 void StyleEngine::updateActiveStyleSheets() | 180 void StyleEngine::updateActiveStyleSheets() |
| 193 { | 181 { |
| 194 ASSERT(isMaster()); | 182 ASSERT(!m_document->inStyleRecalc()); |
| 195 ASSERT(!document().inStyleRecalc()); | |
| 196 | 183 |
| 197 if (!document().isActive()) | 184 if (!m_document->isActive()) |
| 198 return; | 185 return; |
| 199 | 186 |
| 200 documentStyleSheetCollection()->updateActiveStyleSheets(this); | 187 documentStyleSheetCollection()->updateActiveStyleSheets(this); |
| 201 | 188 |
| 202 TreeScopeSet treeScopes = m_activeTreeScopes; | 189 TreeScopeSet treeScopes = m_activeTreeScopes; |
| 203 HashSet<TreeScope*> treeScopesRemoved; | 190 HashSet<TreeScope*> treeScopesRemoved; |
| 204 | 191 |
| 205 for (TreeScopeSet::iterator it = treeScopes.begin(); it != treeScopes.end();
++it) { | 192 for (TreeScopeSet::iterator it = treeScopes.begin(); it != treeScopes.end();
++it) { |
| 206 TreeScope* treeScope = *it; | 193 TreeScope* treeScope = *it; |
| 207 ASSERT(treeScope != m_document); | 194 ASSERT(treeScope != m_document); |
| 208 StyleSheetCollection* collection = styleSheetCollectionFor(*treeScope); | 195 StyleSheetCollection* collection = styleSheetCollectionFor(*treeScope); |
| 209 ASSERT(collection); | 196 ASSERT(collection); |
| 210 collection->updateActiveStyleSheets(this); | 197 collection->updateActiveStyleSheets(this); |
| 211 if (!collection->hasStyleSheetCandidateNodes()) | 198 if (!collection->hasStyleSheetCandidateNodes()) |
| 212 treeScopesRemoved.add(treeScope); | 199 treeScopesRemoved.add(treeScope); |
| 213 } | 200 } |
| 214 m_activeTreeScopes.removeAll(treeScopesRemoved); | 201 m_activeTreeScopes.removeAll(treeScopesRemoved); |
| 215 | 202 |
| 216 m_dirtyTreeScopes.clear(); | 203 m_dirtyTreeScopes.clear(); |
| 217 m_documentScopeDirty = false; | |
| 218 } | 204 } |
| 219 | 205 |
| 220 void StyleEngine::didRemoveShadowRoot(ShadowRoot* shadowRoot) | 206 void StyleEngine::didRemoveShadowRoot(ShadowRoot* shadowRoot) |
| 221 { | 207 { |
| 222 if (shadowRoot->scopedStyleResolver()) | 208 if (shadowRoot->scopedStyleResolver()) |
| 223 removeScopedStyleResolver(shadowRoot->scopedStyleResolver()); | 209 removeScopedStyleResolver(shadowRoot->scopedStyleResolver()); |
| 224 m_styleSheetCollectionMap.remove(shadowRoot); | 210 m_styleSheetCollectionMap.remove(shadowRoot); |
| 225 } | 211 } |
| 226 | 212 |
| 227 void StyleEngine::appendActiveAuthorStyleSheets() | 213 void StyleEngine::appendActiveAuthorStyleSheets() |
| 228 { | 214 { |
| 229 ASSERT(isMaster()); | |
| 230 | |
| 231 m_resolver->appendAuthorStyleSheets(documentStyleSheetCollection()->activeAu
thorStyleSheets()); | 215 m_resolver->appendAuthorStyleSheets(documentStyleSheetCollection()->activeAu
thorStyleSheets()); |
| 232 | 216 |
| 233 TreeScopeSet::iterator begin = m_activeTreeScopes.begin(); | 217 TreeScopeSet::iterator begin = m_activeTreeScopes.begin(); |
| 234 TreeScopeSet::iterator end = m_activeTreeScopes.end(); | 218 TreeScopeSet::iterator end = m_activeTreeScopes.end(); |
| 235 for (TreeScopeSet::iterator it = begin; it != end; ++it) { | 219 for (TreeScopeSet::iterator it = begin; it != end; ++it) { |
| 236 if (StyleSheetCollection* collection = m_styleSheetCollectionMap.get(*it
)) | 220 if (StyleSheetCollection* collection = m_styleSheetCollectionMap.get(*it
)) |
| 237 m_resolver->appendAuthorStyleSheets(collection->activeAuthorStyleShe
ets()); | 221 m_resolver->appendAuthorStyleSheets(collection->activeAuthorStyleShe
ets()); |
| 238 } | 222 } |
| 239 m_resolver->finishAppendAuthorStyleSheets(); | 223 m_resolver->finishAppendAuthorStyleSheets(); |
| 240 } | 224 } |
| 241 | 225 |
| 242 void StyleEngine::createResolver() | 226 void StyleEngine::createResolver() |
| 243 { | 227 { |
| 244 // It is a programming error to attempt to resolve style on a Document | 228 // It is a programming error to attempt to resolve style on a Document |
| 245 // which is not in a frame. Code which hits this should have checked | 229 // which is not in a frame. Code which hits this should have checked |
| 246 // Document::isActive() before calling into code which could get here. | 230 // Document::isActive() before calling into code which could get here. |
| 247 | 231 |
| 248 ASSERT(document().frame()); | 232 ASSERT(m_document->frame()); |
| 249 | 233 |
| 250 m_resolver = adoptPtr(new StyleResolver(*m_document)); | 234 m_resolver = adoptPtr(new StyleResolver(*m_document)); |
| 251 addScopedStyleResolver(&m_document->ensureScopedStyleResolver()); | 235 addScopedStyleResolver(&m_document->ensureScopedStyleResolver()); |
| 252 | 236 |
| 253 appendActiveAuthorStyleSheets(); | 237 appendActiveAuthorStyleSheets(); |
| 254 } | 238 } |
| 255 | 239 |
| 256 void StyleEngine::clearResolver() | 240 void StyleEngine::clearResolver() |
| 257 { | 241 { |
| 258 ASSERT(!document().inStyleRecalc()); | 242 ASSERT(!m_document->inStyleRecalc()); |
| 259 ASSERT(isMaster() || !m_resolver); | |
| 260 | 243 |
| 261 for (ScopedStyleResolverSet::iterator it = m_scopedStyleResolvers.begin(); i
t != m_scopedStyleResolvers.end(); ++it) | 244 for (ScopedStyleResolverSet::iterator it = m_scopedStyleResolvers.begin(); i
t != m_scopedStyleResolvers.end(); ++it) |
| 262 const_cast<TreeScope&>((*it)->treeScope()).clearScopedStyleResolver(); | 245 const_cast<TreeScope&>((*it)->treeScope()).clearScopedStyleResolver(); |
| 263 m_scopedStyleResolvers.clear(); | 246 m_scopedStyleResolvers.clear(); |
| 264 m_resolver.clear(); | 247 m_resolver.clear(); |
| 265 } | 248 } |
| 266 | 249 |
| 267 void StyleEngine::clearMasterResolver() | |
| 268 { | |
| 269 if (Document* master = this->master()) | |
| 270 master->styleEngine()->clearResolver(); | |
| 271 } | |
| 272 | |
| 273 unsigned StyleEngine::resolverAccessCount() const | 250 unsigned StyleEngine::resolverAccessCount() const |
| 274 { | 251 { |
| 275 return m_resolver ? m_resolver->accessCount() : 0; | 252 return m_resolver ? m_resolver->accessCount() : 0; |
| 276 } | 253 } |
| 277 | 254 |
| 278 void StyleEngine::didDetach() | 255 void StyleEngine::didDetach() |
| 279 { | 256 { |
| 280 clearResolver(); | 257 clearResolver(); |
| 281 } | 258 } |
| 282 | 259 |
| 283 void StyleEngine::resolverChanged() | 260 void StyleEngine::resolverChanged() |
| 284 { | 261 { |
| 285 if (!isMaster()) { | |
| 286 if (Document* master = this->master()) | |
| 287 master->styleResolverChanged(); | |
| 288 return; | |
| 289 } | |
| 290 | |
| 291 // Don't bother updating, since we haven't loaded all our style info yet | 262 // Don't bother updating, since we haven't loaded all our style info yet |
| 292 // and haven't calculated the style selector for the first time. | 263 // and haven't calculated the style selector for the first time. |
| 293 if (!document().isActive()) { | 264 if (!m_document->isActive()) { |
| 294 clearResolver(); | 265 clearResolver(); |
| 295 return; | 266 return; |
| 296 } | 267 } |
| 297 | 268 |
| 298 updateActiveStyleSheets(); | 269 updateActiveStyleSheets(); |
| 299 } | 270 } |
| 300 | 271 |
| 301 void StyleEngine::clearFontCache() | 272 void StyleEngine::clearFontCache() |
| 302 { | 273 { |
| 303 if (m_fontSelector) | 274 if (m_fontSelector) |
| 304 m_fontSelector->fontFaceCache()->clearCSSConnected(); | 275 m_fontSelector->fontFaceCache()->clearCSSConnected(); |
| 305 if (m_resolver) | 276 if (m_resolver) |
| 306 m_resolver->invalidateMatchedPropertiesCache(); | 277 m_resolver->invalidateMatchedPropertiesCache(); |
| 307 } | 278 } |
| 308 | 279 |
| 309 void StyleEngine::updateGenericFontFamilySettings() | 280 void StyleEngine::updateGenericFontFamilySettings() |
| 310 { | 281 { |
| 311 // FIXME: we should not update generic font family settings when | 282 // FIXME: we should not update generic font family settings when |
| 312 // document is inactive. | 283 // document is inactive. |
| 313 ASSERT(document().isActive()); | 284 ASSERT(m_document->isActive()); |
| 314 | 285 |
| 315 if (!m_fontSelector) | 286 if (!m_fontSelector) |
| 316 return; | 287 return; |
| 317 | 288 |
| 318 m_fontSelector->updateGenericFontFamilySettings(*m_document); | 289 m_fontSelector->updateGenericFontFamilySettings(*m_document); |
| 319 if (m_resolver) | 290 if (m_resolver) |
| 320 m_resolver->invalidateMatchedPropertiesCache(); | 291 m_resolver->invalidateMatchedPropertiesCache(); |
| 321 } | 292 } |
| 322 | 293 |
| 323 void StyleEngine::removeFontFaceRules(const Vector<RawPtr<const StyleRuleFontFac
e> >& fontFaceRules) | 294 void StyleEngine::removeFontFaceRules(const Vector<RawPtr<const StyleRuleFontFac
e> >& fontFaceRules) |
| 324 { | 295 { |
| 325 if (!m_fontSelector) | 296 if (!m_fontSelector) |
| 326 return; | 297 return; |
| 327 | 298 |
| 328 FontFaceCache* cache = m_fontSelector->fontFaceCache(); | 299 FontFaceCache* cache = m_fontSelector->fontFaceCache(); |
| 329 for (unsigned i = 0; i < fontFaceRules.size(); ++i) | 300 for (unsigned i = 0; i < fontFaceRules.size(); ++i) |
| 330 cache->remove(fontFaceRules[i]); | 301 cache->remove(fontFaceRules[i]); |
| 331 if (m_resolver) | 302 if (m_resolver) |
| 332 m_resolver->invalidateMatchedPropertiesCache(); | 303 m_resolver->invalidateMatchedPropertiesCache(); |
| 333 } | 304 } |
| 334 | 305 |
| 335 void StyleEngine::markTreeScopeDirty(TreeScope& scope) | 306 void StyleEngine::markTreeScopeDirty(TreeScope& scope) |
| 336 { | 307 { |
| 337 if (scope == m_document) { | 308 // TODO(esprehn): Make document not special. |
| 338 markDocumentDirty(); | 309 if (scope == m_document) |
| 339 return; | 310 return; |
| 340 } | |
| 341 | |
| 342 m_dirtyTreeScopes.add(&scope); | 311 m_dirtyTreeScopes.add(&scope); |
| 343 } | 312 } |
| 344 | 313 |
| 345 void StyleEngine::markDocumentDirty() | |
| 346 { | |
| 347 m_documentScopeDirty = true; | |
| 348 if (document().importLoader()) | |
| 349 document().importsController()->master()->styleEngine()->markDocumentDir
ty(); | |
| 350 } | |
| 351 | |
| 352 PassRefPtr<CSSStyleSheet> StyleEngine::createSheet(Element* e, const String& tex
t) | 314 PassRefPtr<CSSStyleSheet> StyleEngine::createSheet(Element* e, const String& tex
t) |
| 353 { | 315 { |
| 354 RefPtr<CSSStyleSheet> styleSheet; | 316 RefPtr<CSSStyleSheet> styleSheet; |
| 355 AtomicString textContent(text); | 317 AtomicString textContent(text); |
| 356 | 318 |
| 357 HashMap<AtomicString, RawPtr<StyleSheetContents> >::AddResult result = m_tex
tToSheetCache.add(textContent, nullptr); | 319 HashMap<AtomicString, RawPtr<StyleSheetContents> >::AddResult result = m_tex
tToSheetCache.add(textContent, nullptr); |
| 358 if (result.isNewEntry || !result.storedValue->value) { | 320 if (result.isNewEntry || !result.storedValue->value) { |
| 359 styleSheet = CSSStyleSheet::create(e, KURL()); | 321 styleSheet = CSSStyleSheet::create(e, KURL()); |
| 360 styleSheet->contents()->parseString(text); | 322 styleSheet->contents()->parseString(text); |
| 361 if (result.isNewEntry) { | 323 if (result.isNewEntry) { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 384 | 346 |
| 385 void StyleEngine::collectScopedStyleFeaturesTo(RuleFeatureSet& features) const | 347 void StyleEngine::collectScopedStyleFeaturesTo(RuleFeatureSet& features) const |
| 386 { | 348 { |
| 387 HashSet<const StyleSheetContents*> visitedSharedStyleSheetContents; | 349 HashSet<const StyleSheetContents*> visitedSharedStyleSheetContents; |
| 388 for (ScopedStyleResolverSet::iterator it = m_scopedStyleResolvers.begin(); i
t != m_scopedStyleResolvers.end(); ++it) | 350 for (ScopedStyleResolverSet::iterator it = m_scopedStyleResolvers.begin(); i
t != m_scopedStyleResolvers.end(); ++it) |
| 389 (*it)->collectFeaturesTo(features, visitedSharedStyleSheetContents); | 351 (*it)->collectFeaturesTo(features, visitedSharedStyleSheetContents); |
| 390 } | 352 } |
| 391 | 353 |
| 392 void StyleEngine::fontsNeedUpdate(CSSFontSelector*) | 354 void StyleEngine::fontsNeedUpdate(CSSFontSelector*) |
| 393 { | 355 { |
| 394 if (!document().isActive()) | |
| 395 return; | |
| 396 | |
| 397 if (m_resolver) | 356 if (m_resolver) |
| 398 m_resolver->invalidateMatchedPropertiesCache(); | 357 m_resolver->invalidateMatchedPropertiesCache(); |
| 399 document().setNeedsStyleRecalc(SubtreeStyleChange); | 358 m_document->setNeedsStyleRecalc(SubtreeStyleChange); |
| 400 } | 359 } |
| 401 | 360 |
| 402 } | 361 } |
| OLD | NEW |