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, | |
49 DocumentStyleSheetCollector& collector) { | 48 DocumentStyleSheetCollector& collector) { |
50 for (Node* n : m_styleSheetCandidateNodes) { | 49 for (Node* n : m_styleSheetCandidateNodes) { |
51 StyleSheetCandidate candidate(*n); | 50 StyleSheetCandidate candidate(*n); |
52 | 51 |
53 DCHECK(!candidate.isXSL()); | 52 DCHECK(!candidate.isXSL()); |
54 if (candidate.isImport()) { | 53 if (candidate.isImport()) { |
55 Document* document = candidate.importedDocument(); | 54 Document* document = candidate.importedDocument(); |
56 if (!document) | 55 if (!document) |
57 continue; | 56 continue; |
58 if (collector.hasVisited(document)) | 57 if (collector.hasVisited(document)) |
59 continue; | 58 continue; |
60 collector.willVisit(document); | 59 collector.willVisit(document); |
61 document->styleEngine().updateStyleSheetsInImport(collector); | 60 document->styleEngine().updateStyleSheetsInImport(collector); |
62 continue; | 61 continue; |
63 } | 62 } |
64 | 63 |
65 if (candidate.isEnabledAndLoading()) | 64 if (candidate.isEnabledAndLoading()) |
66 continue; | 65 continue; |
67 | 66 |
68 StyleSheet* sheet = candidate.sheet(); | 67 StyleSheet* sheet = candidate.sheet(); |
69 if (!sheet) | 68 if (!sheet) |
70 continue; | 69 continue; |
71 | 70 |
72 collector.appendSheetForList(sheet); | 71 collector.appendSheetForList(sheet); |
73 if (candidate.canBeActivated(engine.preferredStylesheetSetName())) | 72 if (!candidate.canBeActivated( |
74 collector.appendActiveStyleSheet(toCSSStyleSheet(sheet)); | 73 document().styleEngine().preferredStylesheetSetName())) |
| 74 continue; |
| 75 |
| 76 CSSStyleSheet* cssSheet = toCSSStyleSheet(sheet); |
| 77 collector.appendActiveStyleSheet(std::make_pair( |
| 78 cssSheet, document().styleEngine().ruleSetForSheet(*cssSheet))); |
75 } | 79 } |
76 } | 80 } |
77 | 81 |
78 void DocumentStyleSheetCollection::collectStyleSheets( | 82 void DocumentStyleSheetCollection::collectStyleSheets( |
79 StyleEngine& engine, | |
80 DocumentStyleSheetCollector& collector) { | 83 DocumentStyleSheetCollector& collector) { |
81 DCHECK_EQ(&document().styleEngine(), &engine); | 84 for (auto& sheet : document().styleEngine().injectedAuthorStyleSheets()) { |
82 collector.appendActiveStyleSheets(engine.injectedAuthorStyleSheets()); | 85 collector.appendActiveStyleSheet(std::make_pair( |
83 collectStyleSheetsFromCandidates(engine, collector); | 86 sheet, document().styleEngine().ruleSetForSheet(*sheet))); |
84 if (engine.inspectorStyleSheet()) | 87 } |
85 collector.appendActiveStyleSheet(engine.inspectorStyleSheet()); | 88 collectStyleSheetsFromCandidates(collector); |
| 89 if (CSSStyleSheet* inspectorSheet = |
| 90 document().styleEngine().inspectorStyleSheet()) { |
| 91 collector.appendActiveStyleSheet(std::make_pair( |
| 92 inspectorSheet, |
| 93 document().styleEngine().ruleSetForSheet(*inspectorSheet))); |
| 94 } |
86 } | 95 } |
87 | 96 |
88 void DocumentStyleSheetCollection::updateActiveStyleSheets( | 97 void DocumentStyleSheetCollection::updateActiveStyleSheets() { |
89 StyleEngine& engine, | |
90 StyleResolverUpdateMode updateMode) { | |
91 // StyleSheetCollection is GarbageCollected<>, allocate it on the heap. | 98 // StyleSheetCollection is GarbageCollected<>, allocate it on the heap. |
92 StyleSheetCollection* collection = StyleSheetCollection::create(); | 99 StyleSheetCollection* collection = StyleSheetCollection::create(); |
93 ActiveDocumentStyleSheetCollector collector(*collection); | 100 ActiveDocumentStyleSheetCollector collector(*collection); |
94 collectStyleSheets(engine, collector); | 101 collectStyleSheets(collector); |
95 | 102 applyActiveStyleSheetChanges(*collection); |
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(); | |
131 } | 103 } |
132 | 104 |
133 void DocumentStyleSheetCollection::collectViewportRules( | 105 void DocumentStyleSheetCollection::collectViewportRules( |
134 ViewportStyleResolver& viewportResolver) { | 106 ViewportStyleResolver& viewportResolver) { |
135 for (Node* node : m_styleSheetCandidateNodes) { | 107 for (Node* node : m_styleSheetCandidateNodes) { |
136 StyleSheetCandidate candidate(*node); | 108 StyleSheetCandidate candidate(*node); |
137 | 109 |
138 if (candidate.isImport()) | 110 if (candidate.isImport()) |
139 continue; | 111 continue; |
140 StyleSheet* sheet = candidate.sheet(); | 112 StyleSheet* sheet = candidate.sheet(); |
141 if (!sheet) | 113 if (!sheet) |
142 continue; | 114 continue; |
143 if (!candidate.canBeActivated( | 115 if (!candidate.canBeActivated( |
144 document().styleEngine().preferredStylesheetSetName())) | 116 document().styleEngine().preferredStylesheetSetName())) |
145 continue; | 117 continue; |
146 viewportResolver.collectViewportRulesFromAuthorSheet( | 118 viewportResolver.collectViewportRulesFromAuthorSheet( |
147 *toCSSStyleSheet(sheet)); | 119 *toCSSStyleSheet(sheet)); |
148 } | 120 } |
149 } | 121 } |
150 | 122 |
151 } // namespace blink | 123 } // namespace blink |
OLD | NEW |