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 | 6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2011, 2012 Apple Inc. All |
7 * rights reserved. | 7 * rights reserved. |
8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. | 8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. |
9 * (http://www.torchmobile.com/) | 9 * (http://www.torchmobile.com/) |
10 * Copyright (C) 2008, 2009, 2011, 2012 Google Inc. All rights reserved. | 10 * Copyright (C) 2008, 2009, 2011, 2012 Google Inc. All rights reserved. |
(...skipping 19 matching lines...) Expand all Loading... |
30 #include "core/dom/StyleEngine.h" | 30 #include "core/dom/StyleEngine.h" |
31 | 31 |
32 #include "core/HTMLNames.h" | 32 #include "core/HTMLNames.h" |
33 #include "core/css/CSSDefaultStyleSheets.h" | 33 #include "core/css/CSSDefaultStyleSheets.h" |
34 #include "core/css/CSSFontSelector.h" | 34 #include "core/css/CSSFontSelector.h" |
35 #include "core/css/CSSStyleSheet.h" | 35 #include "core/css/CSSStyleSheet.h" |
36 #include "core/css/FontFaceCache.h" | 36 #include "core/css/FontFaceCache.h" |
37 #include "core/css/StyleSheetContents.h" | 37 #include "core/css/StyleSheetContents.h" |
38 #include "core/css/invalidation/InvalidationSet.h" | 38 #include "core/css/invalidation/InvalidationSet.h" |
39 #include "core/css/resolver/ScopedStyleResolver.h" | 39 #include "core/css/resolver/ScopedStyleResolver.h" |
| 40 #include "core/css/resolver/ViewportStyleResolver.h" |
40 #include "core/dom/DocumentStyleSheetCollector.h" | 41 #include "core/dom/DocumentStyleSheetCollector.h" |
41 #include "core/dom/Element.h" | 42 #include "core/dom/Element.h" |
42 #include "core/dom/ElementTraversal.h" | 43 #include "core/dom/ElementTraversal.h" |
43 #include "core/dom/ProcessingInstruction.h" | 44 #include "core/dom/ProcessingInstruction.h" |
44 #include "core/dom/ShadowTreeStyleSheetCollection.h" | 45 #include "core/dom/ShadowTreeStyleSheetCollection.h" |
45 #include "core/dom/StyleChangeReason.h" | 46 #include "core/dom/StyleChangeReason.h" |
46 #include "core/dom/shadow/ShadowRoot.h" | 47 #include "core/dom/shadow/ShadowRoot.h" |
47 #include "core/frame/Settings.h" | 48 #include "core/frame/Settings.h" |
48 #include "core/html/HTMLIFrameElement.h" | 49 #include "core/html/HTMLIFrameElement.h" |
49 #include "core/html/HTMLLinkElement.h" | 50 #include "core/html/HTMLLinkElement.h" |
50 #include "core/html/HTMLSlotElement.h" | 51 #include "core/html/HTMLSlotElement.h" |
51 #include "core/html/imports/HTMLImportsController.h" | 52 #include "core/html/imports/HTMLImportsController.h" |
52 #include "core/inspector/InspectorInstrumentation.h" | 53 #include "core/inspector/InspectorInstrumentation.h" |
53 #include "core/page/Page.h" | 54 #include "core/page/Page.h" |
54 #include "core/svg/SVGStyleElement.h" | 55 #include "core/svg/SVGStyleElement.h" |
55 #include "platform/fonts/FontCache.h" | 56 #include "platform/fonts/FontCache.h" |
56 #include "platform/tracing/TraceEvent.h" | 57 #include "platform/tracing/TraceEvent.h" |
57 | 58 |
58 namespace blink { | 59 namespace blink { |
59 | 60 |
60 using namespace HTMLNames; | 61 using namespace HTMLNames; |
61 | 62 |
62 StyleEngine::StyleEngine(Document& document) | 63 StyleEngine::StyleEngine(Document& document) |
63 : m_document(&document), | 64 : m_document(&document), |
64 m_isMaster(!document.importsController() || | 65 m_isMaster(!document.importsController() || |
65 document.importsController()->master() == &document), | 66 document.importsController()->master() == &document), |
66 m_documentStyleSheetCollection( | 67 m_documentStyleSheetCollection( |
67 DocumentStyleSheetCollection::create(document)), | 68 DocumentStyleSheetCollection::create(document)) { |
68 // We don't need to create CSSFontSelector for imported document or | 69 if (document.frame()) { |
69 // HTMLTemplateElement's document, because those documents have no frame. | 70 // We don't need to create CSSFontSelector for imported document or |
70 m_fontSelector(document.frame() ? CSSFontSelector::create(&document) | 71 // HTMLTemplateElement's document, because those documents have no frame. |
71 : nullptr) { | 72 m_fontSelector = CSSFontSelector::create(&document); |
72 if (m_fontSelector) | |
73 m_fontSelector->registerForInvalidationCallbacks(this); | 73 m_fontSelector->registerForInvalidationCallbacks(this); |
| 74 } |
| 75 if (document.isInMainFrame()) |
| 76 m_viewportResolver = ViewportStyleResolver::create(document); |
74 } | 77 } |
75 | 78 |
76 StyleEngine::~StyleEngine() {} | 79 StyleEngine::~StyleEngine() {} |
77 | 80 |
78 static bool isStyleElement(Node& node) { | 81 static bool isStyleElement(Node& node) { |
79 return isHTMLStyleElement(node) || isSVGStyleElement(node); | 82 return isHTMLStyleElement(node) || isSVGStyleElement(node); |
80 } | 83 } |
81 | 84 |
82 inline Document* StyleEngine::master() { | 85 inline Document* StyleEngine::master() { |
83 if (isMaster()) | 86 if (isMaster()) |
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 collection->activeAuthorStyleSheets()); | 389 collection->activeAuthorStyleSheets()); |
387 } | 390 } |
388 m_styleSheetCollectionMap.remove(shadowRoot); | 391 m_styleSheetCollectionMap.remove(shadowRoot); |
389 m_activeTreeScopes.remove(shadowRoot); | 392 m_activeTreeScopes.remove(shadowRoot); |
390 m_dirtyTreeScopes.remove(shadowRoot); | 393 m_dirtyTreeScopes.remove(shadowRoot); |
391 } | 394 } |
392 | 395 |
393 void StyleEngine::appendActiveAuthorStyleSheets() { | 396 void StyleEngine::appendActiveAuthorStyleSheets() { |
394 DCHECK(isMaster()); | 397 DCHECK(isMaster()); |
395 | 398 |
| 399 viewportRulesChanged(); |
| 400 |
396 m_resolver->appendAuthorStyleSheets( | 401 m_resolver->appendAuthorStyleSheets( |
397 documentStyleSheetCollection().activeAuthorStyleSheets()); | 402 documentStyleSheetCollection().activeAuthorStyleSheets()); |
398 for (TreeScope* treeScope : m_activeTreeScopes) { | 403 for (TreeScope* treeScope : m_activeTreeScopes) { |
399 if (TreeScopeStyleSheetCollection* collection = | 404 if (TreeScopeStyleSheetCollection* collection = |
400 m_styleSheetCollectionMap.get(treeScope)) | 405 m_styleSheetCollectionMap.get(treeScope)) |
401 m_resolver->appendAuthorStyleSheets( | 406 m_resolver->appendAuthorStyleSheets( |
402 collection->activeAuthorStyleSheets()); | 407 collection->activeAuthorStyleSheets()); |
403 } | 408 } |
404 m_resolver->finishAppendAuthorStyleSheets(); | 409 m_resolver->finishAppendAuthorStyleSheets(); |
405 } | 410 } |
(...skipping 29 matching lines...) Expand all Loading... |
435 } | 440 } |
436 } | 441 } |
437 | 442 |
438 void StyleEngine::clearMasterResolver() { | 443 void StyleEngine::clearMasterResolver() { |
439 if (Document* master = this->master()) | 444 if (Document* master = this->master()) |
440 master->styleEngine().clearResolver(); | 445 master->styleEngine().clearResolver(); |
441 } | 446 } |
442 | 447 |
443 void StyleEngine::didDetach() { | 448 void StyleEngine::didDetach() { |
444 clearResolver(); | 449 clearResolver(); |
| 450 m_viewportResolver.clear(); |
445 } | 451 } |
446 | 452 |
447 bool StyleEngine::shouldClearResolver() const { | 453 bool StyleEngine::shouldClearResolver() const { |
448 return !m_didCalculateResolver && !haveScriptBlockingStylesheetsLoaded(); | 454 return !m_didCalculateResolver && !haveScriptBlockingStylesheetsLoaded(); |
449 } | 455 } |
450 | 456 |
451 void StyleEngine::resolverChanged(StyleResolverUpdateMode mode) { | 457 void StyleEngine::resolverChanged(StyleResolverUpdateMode mode) { |
452 if (!isMaster()) { | 458 if (!isMaster()) { |
453 if (Document* master = this->master()) | 459 if (Document* master = this->master()) |
454 master->styleEngine().resolverChanged(mode); | 460 master->styleEngine().resolverChanged(mode); |
(...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
940 } | 946 } |
941 | 947 |
942 void StyleEngine::ensureFullscreenUAStyle() { | 948 void StyleEngine::ensureFullscreenUAStyle() { |
943 CSSDefaultStyleSheets::instance().ensureDefaultStyleSheetForFullscreen(); | 949 CSSDefaultStyleSheets::instance().ensureDefaultStyleSheetForFullscreen(); |
944 if (!m_resolver) | 950 if (!m_resolver) |
945 return; | 951 return; |
946 if (!m_resolver->hasFullscreenUAStyle()) | 952 if (!m_resolver->hasFullscreenUAStyle()) |
947 m_resolver->resetRuleFeatures(); | 953 m_resolver->resetRuleFeatures(); |
948 } | 954 } |
949 | 955 |
| 956 void StyleEngine::initialViewportChanged() { |
| 957 if (!m_viewportResolver) |
| 958 return; |
| 959 |
| 960 m_viewportResolver->initialViewportChanged(); |
| 961 |
| 962 // TODO(rune@opera.com): for async stylesheet update, updateViewport() should |
| 963 // be called as part of the lifecycle update for active style. Synchronous for |
| 964 // now. |
| 965 m_viewportResolver->updateViewport(documentStyleSheetCollection()); |
| 966 } |
| 967 |
| 968 void StyleEngine::viewportRulesChanged() { |
| 969 if (!m_viewportResolver) |
| 970 return; |
| 971 m_viewportResolver->setNeedsCollectRules(); |
| 972 |
| 973 // TODO(rune@opera.com): for async stylesheet update, updateViewport() should |
| 974 // be called as part of the lifecycle update for active style. Synchronous for |
| 975 // now. |
| 976 m_viewportResolver->updateViewport(documentStyleSheetCollection()); |
| 977 } |
| 978 |
950 DEFINE_TRACE(StyleEngine) { | 979 DEFINE_TRACE(StyleEngine) { |
951 visitor->trace(m_document); | 980 visitor->trace(m_document); |
952 visitor->trace(m_injectedAuthorStyleSheets); | 981 visitor->trace(m_injectedAuthorStyleSheets); |
953 visitor->trace(m_inspectorStyleSheet); | 982 visitor->trace(m_inspectorStyleSheet); |
954 visitor->trace(m_documentStyleSheetCollection); | 983 visitor->trace(m_documentStyleSheetCollection); |
955 visitor->trace(m_styleSheetCollectionMap); | 984 visitor->trace(m_styleSheetCollectionMap); |
956 visitor->trace(m_resolver); | 985 visitor->trace(m_resolver); |
| 986 visitor->trace(m_viewportResolver); |
957 visitor->trace(m_styleInvalidator); | 987 visitor->trace(m_styleInvalidator); |
958 visitor->trace(m_dirtyTreeScopes); | 988 visitor->trace(m_dirtyTreeScopes); |
959 visitor->trace(m_activeTreeScopes); | 989 visitor->trace(m_activeTreeScopes); |
960 visitor->trace(m_fontSelector); | 990 visitor->trace(m_fontSelector); |
961 visitor->trace(m_textToSheetCache); | 991 visitor->trace(m_textToSheetCache); |
962 visitor->trace(m_sheetToTextCache); | 992 visitor->trace(m_sheetToTextCache); |
963 CSSFontSelectorClient::trace(visitor); | 993 CSSFontSelectorClient::trace(visitor); |
964 } | 994 } |
965 | 995 |
966 DEFINE_TRACE_WRAPPERS(StyleEngine) { | 996 DEFINE_TRACE_WRAPPERS(StyleEngine) { |
967 for (auto sheet : m_injectedAuthorStyleSheets) { | 997 for (auto sheet : m_injectedAuthorStyleSheets) { |
968 visitor->traceWrappers(sheet); | 998 visitor->traceWrappers(sheet); |
969 } | 999 } |
970 visitor->traceWrappers(m_documentStyleSheetCollection); | 1000 visitor->traceWrappers(m_documentStyleSheetCollection); |
971 } | 1001 } |
972 | 1002 |
973 } // namespace blink | 1003 } // namespace blink |
OLD | NEW |