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, 2010, 2012 Apple Inc. All | 6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 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) 2010 Nokia Corporation and/or its subsidiary(-ies) | 10 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) |
(...skipping 27 matching lines...) Expand all Loading... |
38 #include "core/dom/StyleSheetCandidate.h" | 38 #include "core/dom/StyleSheetCandidate.h" |
39 | 39 |
40 namespace blink { | 40 namespace blink { |
41 | 41 |
42 DocumentStyleSheetCollection::DocumentStyleSheetCollection(TreeScope& treeScope) | 42 DocumentStyleSheetCollection::DocumentStyleSheetCollection(TreeScope& treeScope) |
43 : TreeScopeStyleSheetCollection(treeScope) { | 43 : TreeScopeStyleSheetCollection(treeScope) { |
44 DCHECK_EQ(treeScope.rootNode(), treeScope.rootNode().document()); | 44 DCHECK_EQ(treeScope.rootNode(), treeScope.rootNode().document()); |
45 } | 45 } |
46 | 46 |
47 void DocumentStyleSheetCollection::collectStyleSheetsFromCandidates( | 47 void DocumentStyleSheetCollection::collectStyleSheetsFromCandidates( |
| 48 StyleEngine& engine, |
48 DocumentStyleSheetCollector& collector) { | 49 DocumentStyleSheetCollector& collector) { |
49 for (Node* n : m_styleSheetCandidateNodes) { | 50 for (Node* n : m_styleSheetCandidateNodes) { |
50 StyleSheetCandidate candidate(*n); | 51 StyleSheetCandidate candidate(*n); |
51 | 52 |
52 DCHECK(!candidate.isXSL()); | 53 DCHECK(!candidate.isXSL()); |
53 if (candidate.isImport()) { | 54 if (candidate.isImport()) { |
54 Document* document = candidate.importedDocument(); | 55 Document* document = candidate.importedDocument(); |
55 if (!document) | 56 if (!document) |
56 continue; | 57 continue; |
57 if (collector.hasVisited(document)) | 58 if (collector.hasVisited(document)) |
58 continue; | 59 continue; |
59 collector.willVisit(document); | 60 collector.willVisit(document); |
60 document->styleEngine().updateStyleSheetsInImport(collector); | 61 document->styleEngine().updateStyleSheetsInImport(collector); |
61 continue; | 62 continue; |
62 } | 63 } |
63 | 64 |
64 if (candidate.isEnabledAndLoading()) | 65 if (candidate.isEnabledAndLoading()) |
65 continue; | 66 continue; |
66 | 67 |
67 StyleSheet* sheet = candidate.sheet(); | 68 StyleSheet* sheet = candidate.sheet(); |
68 if (!sheet) | 69 if (!sheet) |
69 continue; | 70 continue; |
70 | 71 |
71 collector.appendSheetForList(sheet); | 72 collector.appendSheetForList(sheet); |
72 if (!candidate.canBeActivated( | 73 if (candidate.canBeActivated(engine.preferredStylesheetSetName())) |
73 document().styleEngine().preferredStylesheetSetName())) | 74 collector.appendActiveStyleSheet(toCSSStyleSheet(sheet)); |
74 continue; | |
75 | |
76 CSSStyleSheet* cssSheet = toCSSStyleSheet(sheet); | |
77 collector.appendActiveStyleSheet(std::make_pair( | |
78 cssSheet, document().styleEngine().ruleSetForSheet(*cssSheet))); | |
79 } | 75 } |
80 } | 76 } |
81 | 77 |
82 void DocumentStyleSheetCollection::collectStyleSheets( | 78 void DocumentStyleSheetCollection::collectStyleSheets( |
| 79 StyleEngine& engine, |
83 DocumentStyleSheetCollector& collector) { | 80 DocumentStyleSheetCollector& collector) { |
84 for (auto& sheet : document().styleEngine().injectedAuthorStyleSheets()) { | 81 DCHECK_EQ(&document().styleEngine(), &engine); |
85 collector.appendActiveStyleSheet(std::make_pair( | 82 collector.appendActiveStyleSheets(engine.injectedAuthorStyleSheets()); |
86 sheet, document().styleEngine().ruleSetForSheet(*sheet))); | 83 collectStyleSheetsFromCandidates(engine, collector); |
87 } | 84 if (engine.inspectorStyleSheet()) |
88 collectStyleSheetsFromCandidates(collector); | 85 collector.appendActiveStyleSheet(engine.inspectorStyleSheet()); |
89 if (CSSStyleSheet* inspectorSheet = | |
90 document().styleEngine().inspectorStyleSheet()) { | |
91 collector.appendActiveStyleSheet(std::make_pair( | |
92 inspectorSheet, | |
93 document().styleEngine().ruleSetForSheet(*inspectorSheet))); | |
94 } | |
95 } | 86 } |
96 | 87 |
97 void DocumentStyleSheetCollection::updateActiveStyleSheets() { | 88 void DocumentStyleSheetCollection::updateActiveStyleSheets( |
| 89 StyleEngine& engine, |
| 90 StyleResolverUpdateMode updateMode) { |
98 // StyleSheetCollection is GarbageCollected<>, allocate it on the heap. | 91 // StyleSheetCollection is GarbageCollected<>, allocate it on the heap. |
99 StyleSheetCollection* collection = StyleSheetCollection::create(); | 92 StyleSheetCollection* collection = StyleSheetCollection::create(); |
100 ActiveDocumentStyleSheetCollector collector(*collection); | 93 ActiveDocumentStyleSheetCollector collector(*collection); |
101 collectStyleSheets(collector); | 94 collectStyleSheets(engine, collector); |
102 applyActiveStyleSheetChanges(*collection); | 95 |
| 96 StyleSheetChange change; |
| 97 analyzeStyleSheetChange(updateMode, collection->activeAuthorStyleSheets(), |
| 98 change); |
| 99 |
| 100 if (change.styleResolverUpdateType == Reconstruct) { |
| 101 engine.clearMasterResolver(); |
| 102 // TODO(rune@opera.com): The following depends on whether StyleRuleFontFace |
| 103 // was modified or not. We should only remove modified/removed @font-face |
| 104 // rules, or @font-face rules from removed stylesheets. We currently avoid |
| 105 // clearing the font cache when we have had an analyzed update and no |
| 106 // @font-face rules were removed, in which case requiresFullStyleRecalc will |
| 107 // be false. |
| 108 if (change.requiresFullStyleRecalc) |
| 109 engine.clearFontCache(); |
| 110 } else if (StyleResolver* styleResolver = engine.resolver()) { |
| 111 if (change.styleResolverUpdateType != Additive) { |
| 112 DCHECK_EQ(change.styleResolverUpdateType, Reset); |
| 113 engine.resetAuthorStyle(treeScope()); |
| 114 engine.removeFontFaceRules(change.fontFaceRulesToRemove); |
| 115 styleResolver->removePendingAuthorStyleSheets(m_activeAuthorStyleSheets); |
| 116 styleResolver->lazyAppendAuthorStyleSheets( |
| 117 0, collection->activeAuthorStyleSheets()); |
| 118 } else { |
| 119 styleResolver->lazyAppendAuthorStyleSheets( |
| 120 m_activeAuthorStyleSheets.size(), |
| 121 collection->activeAuthorStyleSheets()); |
| 122 } |
| 123 } |
| 124 if (change.requiresFullStyleRecalc) |
| 125 document().setNeedsStyleRecalc( |
| 126 SubtreeStyleChange, StyleChangeReasonForTracing::create( |
| 127 StyleChangeReason::ActiveStylesheetsUpdate)); |
| 128 |
| 129 collection->swap(*this); |
| 130 collection->dispose(); |
103 } | 131 } |
104 | 132 |
105 void DocumentStyleSheetCollection::collectViewportRules( | 133 void DocumentStyleSheetCollection::collectViewportRules( |
106 ViewportStyleResolver& viewportResolver) { | 134 ViewportStyleResolver& viewportResolver) { |
107 for (Node* node : m_styleSheetCandidateNodes) { | 135 for (Node* node : m_styleSheetCandidateNodes) { |
108 StyleSheetCandidate candidate(*node); | 136 StyleSheetCandidate candidate(*node); |
109 | 137 |
110 if (candidate.isImport()) | 138 if (candidate.isImport()) |
111 continue; | 139 continue; |
112 StyleSheet* sheet = candidate.sheet(); | 140 StyleSheet* sheet = candidate.sheet(); |
113 if (!sheet) | 141 if (!sheet) |
114 continue; | 142 continue; |
115 if (!candidate.canBeActivated( | 143 if (!candidate.canBeActivated( |
116 document().styleEngine().preferredStylesheetSetName())) | 144 document().styleEngine().preferredStylesheetSetName())) |
117 continue; | 145 continue; |
118 viewportResolver.collectViewportRulesFromAuthorSheet( | 146 viewportResolver.collectViewportRulesFromAuthorSheet( |
119 *toCSSStyleSheet(sheet)); | 147 *toCSSStyleSheet(sheet)); |
120 } | 148 } |
121 } | 149 } |
122 | 150 |
123 } // namespace blink | 151 } // namespace blink |
OLD | NEW |