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 16 matching lines...) Expand all Loading... |
27 * | 27 * |
28 */ | 28 */ |
29 | 29 |
30 #ifndef StyleEngine_h | 30 #ifndef StyleEngine_h |
31 #define StyleEngine_h | 31 #define StyleEngine_h |
32 | 32 |
33 #include "bindings/core/v8/ScriptWrappable.h" | 33 #include "bindings/core/v8/ScriptWrappable.h" |
34 #include "bindings/core/v8/TraceWrapperMember.h" | 34 #include "bindings/core/v8/TraceWrapperMember.h" |
35 #include "core/CoreExport.h" | 35 #include "core/CoreExport.h" |
36 #include "core/css/CSSFontSelectorClient.h" | 36 #include "core/css/CSSFontSelectorClient.h" |
| 37 #include "core/css/CSSGlobalRuleSet.h" |
37 #include "core/css/invalidation/StyleInvalidator.h" | 38 #include "core/css/invalidation/StyleInvalidator.h" |
38 #include "core/css/resolver/StyleResolver.h" | 39 #include "core/css/resolver/StyleResolver.h" |
39 #include "core/css/resolver/StyleResolverStats.h" | 40 #include "core/css/resolver/StyleResolverStats.h" |
40 #include "core/dom/Document.h" | 41 #include "core/dom/Document.h" |
41 #include "core/dom/DocumentOrderedList.h" | 42 #include "core/dom/DocumentOrderedList.h" |
42 #include "core/dom/DocumentStyleSheetCollection.h" | 43 #include "core/dom/DocumentStyleSheetCollection.h" |
43 #include "core/dom/StyleEngineContext.h" | 44 #include "core/dom/StyleEngineContext.h" |
44 #include "platform/heap/Handle.h" | 45 #include "platform/heap/Handle.h" |
45 #include "wtf/Allocator.h" | 46 #include "wtf/Allocator.h" |
46 #include "wtf/AutoReset.h" | 47 #include "wtf/AutoReset.h" |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 void addStyleSheetCandidateNode(Node&); | 102 void addStyleSheetCandidateNode(Node&); |
102 void removeStyleSheetCandidateNode(Node&); | 103 void removeStyleSheetCandidateNode(Node&); |
103 void removeStyleSheetCandidateNode(Node&, TreeScope&); | 104 void removeStyleSheetCandidateNode(Node&, TreeScope&); |
104 void modifiedStyleSheetCandidateNode(Node&); | 105 void modifiedStyleSheetCandidateNode(Node&); |
105 void watchedSelectorsChanged(); | 106 void watchedSelectorsChanged(); |
106 void initialViewportChanged(); | 107 void initialViewportChanged(); |
107 void viewportRulesChanged(); | 108 void viewportRulesChanged(); |
108 | 109 |
109 void injectAuthorSheet(StyleSheetContents* authorSheet); | 110 void injectAuthorSheet(StyleSheetContents* authorSheet); |
110 CSSStyleSheet& ensureInspectorStyleSheet(); | 111 CSSStyleSheet& ensureInspectorStyleSheet(); |
| 112 RuleSet* watchedSelectorsRuleSet() { |
| 113 return m_globalRuleSet.watchedSelectorsRuleSet(); |
| 114 } |
111 | 115 |
112 void clearMediaQueryRuleSetStyleSheets(); | 116 void clearMediaQueryRuleSetStyleSheets(); |
113 void updateStyleSheetsInImport(DocumentStyleSheetCollector& parentCollector); | 117 void updateStyleSheetsInImport(DocumentStyleSheetCollector& parentCollector); |
114 void updateActiveStyleSheets(StyleResolverUpdateMode); | 118 void updateActiveStyleSheets(StyleResolverUpdateMode); |
115 | 119 |
116 enum ActiveSheetsUpdate { DontUpdateActiveSheets, UpdateActiveSheets }; | 120 enum ActiveSheetsUpdate { DontUpdateActiveSheets, UpdateActiveSheets }; |
117 String preferredStylesheetSetName() const { | 121 String preferredStylesheetSetName() const { |
118 return m_preferredStylesheetSetName; | 122 return m_preferredStylesheetSetName; |
119 } | 123 } |
120 String selectedStylesheetSetName() const { | 124 String selectedStylesheetSetName() const { |
(...skipping 15 matching lines...) Expand all Loading... |
136 } | 140 } |
137 bool haveScriptBlockingStylesheetsLoaded() const { | 141 bool haveScriptBlockingStylesheetsLoaded() const { |
138 return !hasPendingScriptBlockingSheets() || m_ignorePendingStylesheets; | 142 return !hasPendingScriptBlockingSheets() || m_ignorePendingStylesheets; |
139 } | 143 } |
140 bool haveRenderBlockingStylesheetsLoaded() const { | 144 bool haveRenderBlockingStylesheetsLoaded() const { |
141 return !hasPendingRenderBlockingSheets() || m_ignorePendingStylesheets; | 145 return !hasPendingRenderBlockingSheets() || m_ignorePendingStylesheets; |
142 } | 146 } |
143 bool ignoringPendingStylesheets() const { return m_ignorePendingStylesheets; } | 147 bool ignoringPendingStylesheets() const { return m_ignorePendingStylesheets; } |
144 | 148 |
145 unsigned maxDirectAdjacentSelectors() const { | 149 unsigned maxDirectAdjacentSelectors() const { |
146 return m_maxDirectAdjacentSelectors; | 150 return ruleFeatureSet().maxDirectAdjacentSelectors(); |
147 } | 151 } |
148 bool usesSiblingRules() const { return m_usesSiblingRules; } | 152 bool usesSiblingRules() const { return ruleFeatureSet().usesSiblingRules(); } |
149 bool usesFirstLineRules() const { return m_usesFirstLineRules; } | 153 bool usesFirstLineRules() const { |
| 154 return ruleFeatureSet().usesFirstLineRules(); |
| 155 } |
150 bool usesWindowInactiveSelector() const { | 156 bool usesWindowInactiveSelector() const { |
151 return m_usesWindowInactiveSelector; | 157 return ruleFeatureSet().usesWindowInactiveSelector(); |
152 } | 158 } |
153 | 159 |
154 bool usesRemUnits() const { return m_usesRemUnits; } | 160 bool usesRemUnits() const { return m_usesRemUnits; } |
155 void setUsesRemUnit(bool b) { m_usesRemUnits = b; } | 161 void setUsesRemUnit(bool usesRemUnits) { m_usesRemUnits = usesRemUnits; } |
156 | 162 |
157 void resetCSSFeatureFlags(const RuleFeatureSet&); | 163 void resetCSSFeatureFlags(const RuleFeatureSet&); |
158 | 164 |
159 void shadowRootRemovedFromDocument(ShadowRoot*); | 165 void shadowRootRemovedFromDocument(ShadowRoot*); |
160 void appendActiveAuthorStyleSheets(); | |
161 void addTreeBoundaryCrossingScope(const TreeScope&); | 166 void addTreeBoundaryCrossingScope(const TreeScope&); |
162 const DocumentOrderedList& treeBoundaryCrossingScopes() const { | 167 const DocumentOrderedList& treeBoundaryCrossingScopes() const { |
163 return m_treeBoundaryCrossingScopes; | 168 return m_treeBoundaryCrossingScopes; |
164 } | 169 } |
165 void resetAuthorStyle(TreeScope&); | 170 void resetAuthorStyle(TreeScope&); |
166 | 171 |
167 StyleResolver* resolver() const { return m_resolver.get(); } | 172 StyleResolver* resolver() const { return m_resolver; } |
168 | 173 |
169 StyleResolver& ensureResolver() { | 174 StyleResolver& ensureResolver() { |
170 if (!m_resolver) { | 175 if (!m_resolver) { |
171 createResolver(); | 176 createResolver(); |
172 } else if (m_resolver->hasPendingAuthorStyleSheets()) { | 177 } else if (m_resolver->hasPendingAuthorStyleSheets()) { |
173 viewportRulesChanged(); | 178 viewportRulesChanged(); |
174 m_resolver->appendPendingAuthorStyleSheets(); | 179 m_resolver->appendPendingAuthorStyleSheets(); |
| 180 finishAppendAuthorStyleSheets(); |
| 181 } else if (m_globalRuleSet.isDirty()) { |
| 182 m_globalRuleSet.update(document()); |
175 } | 183 } |
176 return *m_resolver.get(); | 184 return *m_resolver; |
177 } | 185 } |
178 | 186 |
179 bool hasResolver() const { return m_resolver.get(); } | 187 bool hasResolver() const { return m_resolver; } |
180 void clearResolver(); | 188 void clearResolver(); |
181 void clearMasterResolver(); | 189 void clearMasterResolver(); |
182 | 190 |
183 StyleInvalidator& styleInvalidator() { return m_styleInvalidator; } | 191 StyleInvalidator& styleInvalidator() { return m_styleInvalidator; } |
184 | 192 |
185 CSSFontSelector* fontSelector() { return m_fontSelector.get(); } | 193 CSSFontSelector* fontSelector() { return m_fontSelector; } |
186 void setFontSelector(CSSFontSelector*); | 194 void setFontSelector(CSSFontSelector*); |
187 | 195 |
188 void removeFontFaceRules(const HeapVector<Member<const StyleRuleFontFace>>&); | 196 void removeFontFaceRules(const HeapVector<Member<const StyleRuleFontFace>>&); |
189 void clearFontCache(); | 197 void clearFontCache(); |
190 // updateGenericFontFamilySettings is used from WebSettingsImpl. | 198 // updateGenericFontFamilySettings is used from WebSettingsImpl. |
191 void updateGenericFontFamilySettings(); | 199 void updateGenericFontFamilySettings(); |
192 | 200 |
193 void didDetach(); | 201 void didDetach(); |
194 bool shouldClearResolver() const; | 202 bool shouldClearResolver() const; |
195 void resolverChanged(StyleResolverUpdateMode); | 203 void resolverChanged(StyleResolverUpdateMode); |
196 | 204 |
197 CSSStyleSheet* createSheet(Element&, | 205 CSSStyleSheet* createSheet(Element&, |
198 const String& text, | 206 const String& text, |
199 TextPosition startPosition, | 207 TextPosition startPosition, |
200 StyleEngineContext&); | 208 StyleEngineContext&); |
201 | 209 |
202 void collectScopedStyleFeaturesTo(RuleFeatureSet&) const; | 210 void collectScopedStyleFeaturesTo(RuleFeatureSet&) const; |
203 void ensureFullscreenUAStyle(); | 211 void ensureUAStyleForFullscreen(); |
| 212 void ensureUAStyleForElement(const Element&); |
204 | 213 |
205 void platformColorsChanged(); | 214 void platformColorsChanged(); |
206 | 215 |
| 216 bool hasRulesForId(const AtomicString& id) const; |
207 void classChangedForElement(const SpaceSplitString& changedClasses, Element&); | 217 void classChangedForElement(const SpaceSplitString& changedClasses, Element&); |
208 void classChangedForElement(const SpaceSplitString& oldClasses, | 218 void classChangedForElement(const SpaceSplitString& oldClasses, |
209 const SpaceSplitString& newClasses, | 219 const SpaceSplitString& newClasses, |
210 Element&); | 220 Element&); |
211 void attributeChangedForElement(const QualifiedName& attributeName, Element&); | 221 void attributeChangedForElement(const QualifiedName& attributeName, Element&); |
212 void idChangedForElement(const AtomicString& oldId, | 222 void idChangedForElement(const AtomicString& oldId, |
213 const AtomicString& newId, | 223 const AtomicString& newId, |
214 Element&); | 224 Element&); |
215 void pseudoStateChangedForElement(CSSSelector::PseudoType, Element&); | 225 void pseudoStateChangedForElement(CSSSelector::PseudoType, Element&); |
216 void scheduleSiblingInvalidationsForElement(Element&, | 226 void scheduleSiblingInvalidationsForElement(Element&, |
217 ContainerNode& schedulingParent, | 227 ContainerNode& schedulingParent, |
218 unsigned minDirectAdjacent); | 228 unsigned minDirectAdjacent); |
219 void scheduleInvalidationsForInsertedSibling(Element* beforeElement, | 229 void scheduleInvalidationsForInsertedSibling(Element* beforeElement, |
220 Element& insertedElement); | 230 Element& insertedElement); |
221 void scheduleInvalidationsForRemovedSibling(Element* beforeElement, | 231 void scheduleInvalidationsForRemovedSibling(Element* beforeElement, |
222 Element& removedElement, | 232 Element& removedElement, |
223 Element& afterElement); | 233 Element& afterElement); |
224 void scheduleNthPseudoInvalidations(ContainerNode&); | 234 void scheduleNthPseudoInvalidations(ContainerNode&); |
225 void scheduleInvalidationsForRuleSets(TreeScope&, | 235 void scheduleInvalidationsForRuleSets(TreeScope&, |
226 const HeapVector<Member<RuleSet>>&); | 236 const HeapVector<Member<RuleSet>>&); |
227 | 237 |
228 unsigned styleForElementCount() const { return m_styleForElementCount; } | 238 unsigned styleForElementCount() const { return m_styleForElementCount; } |
229 void incStyleForElementCount() { m_styleForElementCount++; } | 239 void incStyleForElementCount() { m_styleForElementCount++; } |
230 | 240 |
231 StyleResolverStats* stats() { return m_styleResolverStats.get(); } | 241 StyleResolverStats* stats() { return m_styleResolverStats.get(); } |
232 void setStatsEnabled(bool); | 242 void setStatsEnabled(bool); |
233 | 243 |
| 244 PassRefPtr<ComputedStyle> findSharedStyle(const ElementResolveContext&); |
| 245 |
234 DECLARE_VIRTUAL_TRACE(); | 246 DECLARE_VIRTUAL_TRACE(); |
235 DECLARE_TRACE_WRAPPERS(); | 247 DECLARE_TRACE_WRAPPERS(); |
236 | 248 |
237 private: | 249 private: |
238 // CSSFontSelectorClient implementation. | 250 // CSSFontSelectorClient implementation. |
239 void fontsNeedUpdate(CSSFontSelector*) override; | 251 void fontsNeedUpdate(CSSFontSelector*) override; |
240 | 252 |
241 private: | 253 private: |
242 StyleEngine(Document&); | 254 StyleEngine(Document&); |
243 | 255 |
244 TreeScopeStyleSheetCollection* ensureStyleSheetCollectionFor(TreeScope&); | 256 TreeScopeStyleSheetCollection* ensureStyleSheetCollectionFor(TreeScope&); |
245 TreeScopeStyleSheetCollection* styleSheetCollectionFor(TreeScope&); | 257 TreeScopeStyleSheetCollection* styleSheetCollectionFor(TreeScope&); |
246 bool shouldUpdateDocumentStyleSheetCollection(StyleResolverUpdateMode) const; | 258 bool shouldUpdateDocumentStyleSheetCollection(StyleResolverUpdateMode) const; |
247 bool shouldUpdateShadowTreeStyleSheetCollection( | 259 bool shouldUpdateShadowTreeStyleSheetCollection( |
248 StyleResolverUpdateMode) const; | 260 StyleResolverUpdateMode) const; |
249 | 261 |
250 void markDocumentDirty(); | 262 void markDocumentDirty(); |
251 void markTreeScopeDirty(TreeScope&); | 263 void markTreeScopeDirty(TreeScope&); |
252 | 264 |
253 bool isMaster() const { return m_isMaster; } | 265 bool isMaster() const { return m_isMaster; } |
254 Document* master(); | 266 Document* master(); |
255 Document& document() const { return *m_document; } | 267 Document& document() const { return *m_document; } |
256 | 268 |
257 typedef HeapHashSet<Member<TreeScope>> UnorderedTreeScopeSet; | 269 typedef HeapHashSet<Member<TreeScope>> UnorderedTreeScopeSet; |
258 | 270 |
259 void clearMediaQueryRuleSetOnTreeScopeStyleSheets(UnorderedTreeScopeSet&); | 271 void clearMediaQueryRuleSetOnTreeScopeStyleSheets(UnorderedTreeScopeSet&); |
| 272 const RuleFeatureSet& ruleFeatureSet() const { |
| 273 return m_globalRuleSet.ruleFeatureSet(); |
| 274 } |
260 | 275 |
261 void createResolver(); | 276 void createResolver(); |
| 277 void appendActiveAuthorStyleSheets(); |
| 278 void finishAppendAuthorStyleSheets(); |
262 | 279 |
263 CSSStyleSheet* parseSheet(Element&, | 280 CSSStyleSheet* parseSheet(Element&, |
264 const String& text, | 281 const String& text, |
265 TextPosition startPosition); | 282 TextPosition startPosition); |
266 | 283 |
267 const DocumentStyleSheetCollection& documentStyleSheetCollection() const { | 284 const DocumentStyleSheetCollection& documentStyleSheetCollection() const { |
268 DCHECK(m_documentStyleSheetCollection); | 285 DCHECK(m_documentStyleSheetCollection); |
269 return *m_documentStyleSheetCollection; | 286 return *m_documentStyleSheetCollection; |
270 } | 287 } |
271 | 288 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 StyleSheetCollectionMap m_styleSheetCollectionMap; | 323 StyleSheetCollectionMap m_styleSheetCollectionMap; |
307 | 324 |
308 bool m_documentScopeDirty = true; | 325 bool m_documentScopeDirty = true; |
309 UnorderedTreeScopeSet m_dirtyTreeScopes; | 326 UnorderedTreeScopeSet m_dirtyTreeScopes; |
310 UnorderedTreeScopeSet m_activeTreeScopes; | 327 UnorderedTreeScopeSet m_activeTreeScopes; |
311 DocumentOrderedList m_treeBoundaryCrossingScopes; | 328 DocumentOrderedList m_treeBoundaryCrossingScopes; |
312 | 329 |
313 String m_preferredStylesheetSetName; | 330 String m_preferredStylesheetSetName; |
314 String m_selectedStylesheetSetName; | 331 String m_selectedStylesheetSetName; |
315 | 332 |
316 bool m_usesSiblingRules = false; | 333 CSSGlobalRuleSet m_globalRuleSet; |
317 bool m_usesFirstLineRules = false; | 334 |
318 bool m_usesWindowInactiveSelector = false; | |
319 bool m_usesRemUnits = false; | 335 bool m_usesRemUnits = false; |
320 unsigned m_maxDirectAdjacentSelectors = 0; | |
321 | |
322 bool m_ignorePendingStylesheets = false; | 336 bool m_ignorePendingStylesheets = false; |
323 bool m_didCalculateResolver = false; | 337 bool m_didCalculateResolver = false; |
324 | 338 |
325 Member<StyleResolver> m_resolver; | 339 Member<StyleResolver> m_resolver; |
326 Member<ViewportStyleResolver> m_viewportResolver; | 340 Member<ViewportStyleResolver> m_viewportResolver; |
327 StyleInvalidator m_styleInvalidator; | 341 StyleInvalidator m_styleInvalidator; |
328 | 342 |
329 Member<CSSFontSelector> m_fontSelector; | 343 Member<CSSFontSelector> m_fontSelector; |
330 | 344 |
331 HeapHashMap<AtomicString, WeakMember<StyleSheetContents>> m_textToSheetCache; | 345 HeapHashMap<AtomicString, WeakMember<StyleSheetContents>> m_textToSheetCache; |
332 HeapHashMap<WeakMember<StyleSheetContents>, AtomicString> m_sheetToTextCache; | 346 HeapHashMap<WeakMember<StyleSheetContents>, AtomicString> m_sheetToTextCache; |
333 | 347 |
334 std::unique_ptr<StyleResolverStats> m_styleResolverStats; | 348 std::unique_ptr<StyleResolverStats> m_styleResolverStats; |
335 unsigned m_styleForElementCount = 0; | 349 unsigned m_styleForElementCount = 0; |
336 | 350 |
337 friend class StyleEngineTest; | 351 friend class StyleEngineTest; |
338 }; | 352 }; |
339 | 353 |
340 } // namespace blink | 354 } // namespace blink |
341 | 355 |
342 #endif | 356 #endif |
OLD | NEW |