Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / Source / core / dom / StyleEngine.h
blobd2dddeb37abed753bf98e98eb7bc8bec34559d49
1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Dirk Mueller (mueller@kde.org)
5 * (C) 2006 Alexey Proskuryakov (ap@webkit.org)
6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012 Apple Inc. All rights reserved.
7 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
8 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
9 * Copyright (C) 2011 Google Inc. All rights reserved.
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Library General Public
13 * License as published by the Free Software Foundation; either
14 * version 2 of the License, or (at your option) any later version.
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Library General Public License for more details.
21 * You should have received a copy of the GNU Library General Public License
22 * along with this library; see the file COPYING.LIB. If not, write to
23 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 * Boston, MA 02110-1301, USA.
28 #ifndef StyleEngine_h
29 #define StyleEngine_h
31 #include "core/CoreExport.h"
32 #include "core/css/CSSFontSelectorClient.h"
33 #include "core/css/invalidation/StyleInvalidator.h"
34 #include "core/css/resolver/StyleResolver.h"
35 #include "core/dom/Document.h"
36 #include "core/dom/DocumentOrderedList.h"
37 #include "core/dom/DocumentStyleSheetCollection.h"
38 #include "platform/heap/Handle.h"
39 #include "wtf/FastAllocBase.h"
40 #include "wtf/ListHashSet.h"
41 #include "wtf/RefPtr.h"
42 #include "wtf/TemporaryChange.h"
43 #include "wtf/Vector.h"
44 #include "wtf/text/WTFString.h"
46 namespace blink {
48 class CSSFontSelector;
49 class CSSStyleSheet;
50 class Node;
51 class RuleFeatureSet;
52 class ShadowTreeStyleSheetCollection;
53 class StyleRuleFontFace;
54 class StyleSheet;
55 class StyleSheetContents;
57 class CORE_EXPORT StyleEngine final : public NoBaseWillBeGarbageCollectedFinalized<StyleEngine>, public CSSFontSelectorClient {
58 WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED(StyleEngine);
59 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(StyleEngine);
60 public:
62 class IgnoringPendingStylesheet : public TemporaryChange<bool> {
63 DISALLOW_ALLOCATION();
64 public:
65 IgnoringPendingStylesheet(StyleEngine& engine)
66 : TemporaryChange<bool>(engine.m_ignorePendingStylesheets, true)
71 friend class IgnoringPendingStylesheet;
73 static PassOwnPtrWillBeRawPtr<StyleEngine> create(Document& document) { return adoptPtrWillBeNoop(new StyleEngine(document)); }
75 ~StyleEngine();
77 #if !ENABLE(OILPAN)
78 void detachFromDocument();
79 #endif
81 const WillBeHeapVector<RefPtrWillBeMember<StyleSheet>>& styleSheetsForStyleSheetList(TreeScope&);
82 const WillBeHeapVector<RefPtrWillBeMember<CSSStyleSheet>>& activeAuthorStyleSheets() const;
84 const WillBeHeapVector<RefPtrWillBeMember<CSSStyleSheet>>& documentAuthorStyleSheets() const { return m_authorStyleSheets; }
86 const WillBeHeapVector<RefPtrWillBeMember<CSSStyleSheet>> activeStyleSheetsForInspector() const;
88 void modifiedStyleSheet(StyleSheet*);
89 void addStyleSheetCandidateNode(Node*, bool createdByParser);
90 void removeStyleSheetCandidateNode(Node*);
91 void removeStyleSheetCandidateNode(Node*, TreeScope&);
92 void modifiedStyleSheetCandidateNode(Node*);
94 void addAuthorSheet(PassRefPtrWillBeRawPtr<StyleSheetContents> authorSheet);
96 void clearMediaQueryRuleSetStyleSheets();
97 void updateStyleSheetsInImport(DocumentStyleSheetCollector& parentCollector);
98 void updateActiveStyleSheets(StyleResolverUpdateMode);
100 String preferredStylesheetSetName() const { return m_preferredStylesheetSetName; }
101 String selectedStylesheetSetName() const { return m_selectedStylesheetSetName; }
102 void setPreferredStylesheetSetName(const String& name) { m_preferredStylesheetSetName = name; }
103 void setSelectedStylesheetSetName(const String& name) { m_selectedStylesheetSetName = name; }
105 void selectStylesheetSetName(const String& name)
107 setPreferredStylesheetSetName(name);
108 setSelectedStylesheetSetName(name);
111 void addPendingSheet();
112 void removePendingSheet(Node* styleSheetCandidateNode);
114 bool hasPendingSheets() const { return m_pendingStylesheets > 0; }
115 bool haveStylesheetsLoaded() const { return !hasPendingSheets() || m_ignorePendingStylesheets; }
116 bool ignoringPendingStylesheets() const { return m_ignorePendingStylesheets; }
118 unsigned maxDirectAdjacentSelectors() const { return m_maxDirectAdjacentSelectors; }
119 bool usesSiblingRules() const { return m_usesSiblingRules; }
120 bool usesFirstLineRules() const { return m_usesFirstLineRules; }
121 bool usesWindowInactiveSelector() const { return m_usesWindowInactiveSelector; }
123 bool usesRemUnits() const { return m_usesRemUnits; }
124 void setUsesRemUnit(bool b) { m_usesRemUnits = b; }
126 void combineCSSFeatureFlags(const RuleFeatureSet&);
127 void resetCSSFeatureFlags(const RuleFeatureSet&);
129 void didRemoveShadowRoot(ShadowRoot*);
130 void shadowRootRemovedFromDocument(ShadowRoot*);
131 void appendActiveAuthorStyleSheets();
133 StyleResolver* resolver() const
135 return m_resolver.get();
138 StyleResolver& ensureResolver()
140 if (!m_resolver) {
141 createResolver();
142 } else if (m_resolver->hasPendingAuthorStyleSheets()) {
143 m_resolver->appendPendingAuthorStyleSheets();
145 return *m_resolver.get();
148 bool hasResolver() const { return m_resolver.get(); }
149 void clearResolver();
150 void clearMasterResolver();
152 StyleInvalidator& styleInvalidator() { return m_styleInvalidator; }
154 CSSFontSelector* fontSelector() { return m_fontSelector.get(); }
155 void setFontSelector(PassRefPtrWillBeRawPtr<CSSFontSelector>);
157 void removeFontFaceRules(const WillBeHeapVector<RawPtrWillBeMember<const StyleRuleFontFace>>&);
158 void clearFontCache();
159 // updateGenericFontFamilySettings is used from WebSettingsImpl.
160 void updateGenericFontFamilySettings();
162 void didDetach();
163 bool shouldClearResolver() const;
164 void resolverChanged(StyleResolverUpdateMode);
165 unsigned resolverAccessCount() const;
167 void markDocumentDirty();
169 PassRefPtrWillBeRawPtr<CSSStyleSheet> createSheet(Element*, const String& text, TextPosition startPosition);
170 void removeSheet(StyleSheetContents*);
172 void collectScopedStyleFeaturesTo(RuleFeatureSet&) const;
174 void platformColorsChanged();
176 void classChangedForElement(const SpaceSplitString& changedClasses, Element&);
177 void classChangedForElement(const SpaceSplitString& oldClasses, const SpaceSplitString& newClasses, Element&);
178 void attributeChangedForElement(const QualifiedName& attributeName, Element&);
179 void idChangedForElement(const AtomicString& oldId, const AtomicString& newId, Element&);
180 void pseudoStateChangedForElement(CSSSelector::PseudoType, Element&);
182 DECLARE_VIRTUAL_TRACE();
184 private:
185 // CSSFontSelectorClient implementation.
186 void fontsNeedUpdate(CSSFontSelector*) override;
188 private:
189 StyleEngine(Document&);
191 TreeScopeStyleSheetCollection* ensureStyleSheetCollectionFor(TreeScope&);
192 TreeScopeStyleSheetCollection* styleSheetCollectionFor(TreeScope&);
193 bool shouldUpdateDocumentStyleSheetCollection(StyleResolverUpdateMode) const;
194 bool shouldUpdateShadowTreeStyleSheetCollection(StyleResolverUpdateMode) const;
196 void markTreeScopeDirty(TreeScope&);
198 bool isMaster() const { return m_isMaster; }
199 Document* master();
200 Document& document() const { return *m_document; }
202 void scheduleInvalidationSetsForElement(const InvalidationSetVector&, Element&);
204 typedef WillBeHeapHashSet<RawPtrWillBeMember<TreeScope>> UnorderedTreeScopeSet;
206 void clearMediaQueryRuleSetOnTreeScopeStyleSheets(UnorderedTreeScopeSet&);
208 void createResolver();
210 static PassRefPtrWillBeRawPtr<CSSStyleSheet> parseSheet(Element*, const String& text, TextPosition startPosition);
212 const DocumentStyleSheetCollection* documentStyleSheetCollection() const
214 return m_documentStyleSheetCollection.get();
217 DocumentStyleSheetCollection* documentStyleSheetCollection()
219 return m_documentStyleSheetCollection.get();
222 void updateActiveStyleSheetsInShadow(StyleResolverUpdateMode, TreeScope*, UnorderedTreeScopeSet& treeScopesRemoved);
224 RawPtrWillBeMember<Document> m_document;
225 bool m_isMaster;
227 // Track the number of currently loading top-level stylesheets needed for layout.
228 // Sheets loaded using the @import directive are not included in this count.
229 // We use this count of pending sheets to detect when we can begin attaching
230 // elements and when it is safe to execute scripts.
231 int m_pendingStylesheets;
233 WillBeHeapVector<RefPtrWillBeMember<CSSStyleSheet>> m_authorStyleSheets;
235 OwnPtrWillBeMember<DocumentStyleSheetCollection> m_documentStyleSheetCollection;
237 typedef WillBeHeapHashMap<RawPtrWillBeWeakMember<TreeScope>, OwnPtrWillBeMember<ShadowTreeStyleSheetCollection>> StyleSheetCollectionMap;
238 StyleSheetCollectionMap m_styleSheetCollectionMap;
240 bool m_documentScopeDirty;
241 UnorderedTreeScopeSet m_dirtyTreeScopes;
242 UnorderedTreeScopeSet m_activeTreeScopes;
244 String m_preferredStylesheetSetName;
245 String m_selectedStylesheetSetName;
247 bool m_usesSiblingRules;
248 bool m_usesFirstLineRules;
249 bool m_usesWindowInactiveSelector;
250 bool m_usesRemUnits;
251 unsigned m_maxDirectAdjacentSelectors;
253 bool m_ignorePendingStylesheets;
254 bool m_didCalculateResolver;
255 OwnPtrWillBeMember<StyleResolver> m_resolver;
256 StyleInvalidator m_styleInvalidator;
258 RefPtrWillBeMember<CSSFontSelector> m_fontSelector;
260 WillBeHeapHashMap<AtomicString, RawPtrWillBeMember<StyleSheetContents>> m_textToSheetCache;
261 WillBeHeapHashMap<RawPtrWillBeMember<StyleSheetContents>, AtomicString> m_sheetToTextCache;
266 #endif