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 DocumentStyleSheetCollection_h
29 #define DocumentStyleSheetCollection_h
31 #include <wtf/FastAllocBase.h>
32 #include <wtf/ListHashSet.h>
33 #include <wtf/RefPtr.h>
34 #include <wtf/Vector.h>
35 #include <wtf/text/WTFString.h>
43 class StyleSheetContents;
46 class DocumentStyleSheetCollection {
47 WTF_MAKE_FAST_ALLOCATED;
49 DocumentStyleSheetCollection(Document*);
50 ~DocumentStyleSheetCollection();
52 const Vector<RefPtr<StyleSheet> >& authorStyleSheets() { return m_authorStyleSheets; }
54 CSSStyleSheet* pageUserSheet();
55 const Vector<RefPtr<CSSStyleSheet> >* pageGroupUserSheets() const;
56 const Vector<RefPtr<CSSStyleSheet> >* documentUserSheets() const { return m_userSheets.get(); }
58 void addStyleSheetCandidateNode(Node*, bool createdByParser);
59 void removeStyleSheetCandidateNode(Node*);
61 void clearPageUserSheet();
62 void updatePageUserSheet();
63 void clearPageGroupUserSheets();
64 void updatePageGroupUserSheets();
66 void addUserSheet(PassRefPtr<StyleSheetContents> userSheet);
68 bool needsUpdateActiveStylesheetsOnStyleRecalc() { return m_needsUpdateActiveStylesheetsOnStyleRecalc; }
70 enum UpdateFlag { FullUpdate, OptimizedUpdate };
71 bool updateActiveStyleSheets(UpdateFlag);
73 String preferredStylesheetSetName() const { return m_preferredStylesheetSetName; }
74 String selectedStylesheetSetName() const { return m_selectedStylesheetSetName; }
75 void setPreferredStylesheetSetName(const String& name) { m_preferredStylesheetSetName = name; }
76 void setSelectedStylesheetSetName(const String& name) { m_selectedStylesheetSetName = name; }
78 void addPendingSheet() { m_pendingStylesheets++; }
79 enum RemovePendingSheetNotificationType {
80 RemovePendingSheetNotifyImmediately,
81 RemovePendingSheetNotifyLater
83 void removePendingSheet(RemovePendingSheetNotificationType = RemovePendingSheetNotifyImmediately);
85 bool hasPendingSheets() const { return m_pendingStylesheets > 0; }
87 bool usesSiblingRules() const { return m_usesSiblingRules || m_usesSiblingRulesOverride; }
88 void setUsesSiblingRulesOverride(bool b) { m_usesSiblingRulesOverride = b; }
89 bool usesFirstLineRules() const { return m_usesFirstLineRules; }
90 bool usesFirstLetterRules() const { return m_usesFirstLetterRules; }
91 void setUsesFirstLetterRules(bool b) { m_usesFirstLetterRules = b; }
92 bool usesBeforeAfterRules() const { return m_usesBeforeAfterRules || m_usesBeforeAfterRulesOverride; }
93 void setUsesBeforeAfterRulesOverride(bool b) { m_usesBeforeAfterRulesOverride = b; }
94 bool usesRemUnits() const { return m_usesRemUnits; }
95 void setUsesRemUnit(bool b) { m_usesRemUnits = b; }
97 void combineCSSFeatureFlags();
98 void resetCSSFeatureFlags();
100 void reportMemoryUsage(MemoryObjectInfo*) const;
103 void collectActiveStyleSheets(Vector<RefPtr<StyleSheet> >&);
104 bool testAddedStyleSheetRequiresStyleRecalc(StyleSheetContents*);
105 enum StyleResolverUpdateType {
110 void analyzeStyleSheetChange(UpdateFlag, const Vector<RefPtr<StyleSheet> >& newStylesheets, StyleResolverUpdateType&, bool& requiresFullStyleRecalc);
112 Document* m_document;
114 Vector<RefPtr<StyleSheet> > m_authorStyleSheets;
116 // Track the number of currently loading top-level stylesheets needed for rendering.
117 // Sheets loaded using the @import directive are not included in this count.
118 // We use this count of pending sheets to detect when we can begin attaching
119 // elements and when it is safe to execute scripts.
120 int m_pendingStylesheets;
122 RefPtr<CSSStyleSheet> m_pageUserSheet;
123 mutable OwnPtr<Vector<RefPtr<CSSStyleSheet> > > m_pageGroupUserSheets;
124 OwnPtr<Vector<RefPtr<CSSStyleSheet> > > m_userSheets;
125 mutable bool m_pageGroupUserSheetCacheValid;
127 bool m_hadActiveLoadingStylesheet;
128 bool m_needsUpdateActiveStylesheetsOnStyleRecalc;
130 typedef ListHashSet<Node*, 32> StyleSheetCandidateListHashSet;
131 StyleSheetCandidateListHashSet m_styleSheetCandidateNodes;
133 String m_preferredStylesheetSetName;
134 String m_selectedStylesheetSetName;
136 bool m_usesSiblingRules;
137 bool m_usesSiblingRulesOverride;
138 bool m_usesFirstLineRules;
139 bool m_usesFirstLetterRules;
140 bool m_usesBeforeAfterRules;
141 bool m_usesBeforeAfterRulesOverride;