blob: bbafeb858e61cbc4baba7c4c760018c5546f3cfe [file] [log] [blame]
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +00001/*
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.
10 *
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.
15 *
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.
20 *
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.
25 *
26 */
27
28#ifndef DocumentStyleSheetCollection_h
29#define DocumentStyleSheetCollection_h
30
Ben Murdoch591b9582013-07-10 11:41:44 +010031#include "core/dom/Document.h"
32#include "core/dom/DocumentOrderedList.h"
Ben Murdoche69819b2013-07-17 14:56:49 +010033#include "core/dom/StyleSheetCollection.h"
Ben Murdoch591b9582013-07-10 11:41:44 +010034#include "wtf/FastAllocBase.h"
35#include "wtf/ListHashSet.h"
36#include "wtf/RefPtr.h"
37#include "wtf/Vector.h"
38#include "wtf/text/WTFString.h"
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +000039
40namespace WebCore {
41
42class CSSStyleSheet;
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +000043class Node;
Ben Murdoch7757ec22013-07-23 11:17:36 +010044class RuleFeatureSet;
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +000045class StyleSheet;
46class StyleSheetContents;
47class StyleSheetList;
48
49class DocumentStyleSheetCollection {
50 WTF_MAKE_FAST_ALLOCATED;
51public:
52 static PassOwnPtr<DocumentStyleSheetCollection> create(Document* document) { return adoptPtr(new DocumentStyleSheetCollection(document)); }
53
54 ~DocumentStyleSheetCollection();
55
Ben Murdoche69819b2013-07-17 14:56:49 +010056 const Vector<RefPtr<StyleSheet> >& styleSheetsForStyleSheetList();
57 const Vector<RefPtr<CSSStyleSheet> >& activeAuthorStyleSheets() const;
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +000058
59 CSSStyleSheet* pageUserSheet();
Torne (Richard Coles)926b0012013-03-28 15:32:48 +000060 const Vector<RefPtr<CSSStyleSheet> >& documentUserStyleSheets() const { return m_userStyleSheets; }
61 const Vector<RefPtr<CSSStyleSheet> >& documentAuthorStyleSheets() const { return m_authorStyleSheets; }
62 const Vector<RefPtr<CSSStyleSheet> >& injectedUserStyleSheets() const;
63 const Vector<RefPtr<CSSStyleSheet> >& injectedAuthorStyleSheets() const;
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +000064
65 void addStyleSheetCandidateNode(Node*, bool createdByParser);
Ben Murdoch02772c62013-07-26 10:21:05 +010066 void removeStyleSheetCandidateNode(Node*, ContainerNode* scopingNode = 0);
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +000067
68 void clearPageUserSheet();
69 void updatePageUserSheet();
Torne (Richard Coles)926b0012013-03-28 15:32:48 +000070 void invalidateInjectedStyleSheetCache();
71 void updateInjectedStyleSheetCache() const;
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +000072
Torne (Richard Coles)926b0012013-03-28 15:32:48 +000073 void addAuthorSheet(PassRefPtr<StyleSheetContents> authorSheet);
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +000074 void addUserSheet(PassRefPtr<StyleSheetContents> userSheet);
75
76 bool needsUpdateActiveStylesheetsOnStyleRecalc() const { return m_needsUpdateActiveStylesheetsOnStyleRecalc; }
77
Ben Murdoch591b9582013-07-10 11:41:44 +010078 bool updateActiveStyleSheets(StyleResolverUpdateMode);
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +000079
80 String preferredStylesheetSetName() const { return m_preferredStylesheetSetName; }
81 String selectedStylesheetSetName() const { return m_selectedStylesheetSetName; }
82 void setPreferredStylesheetSetName(const String& name) { m_preferredStylesheetSetName = name; }
83 void setSelectedStylesheetSetName(const String& name) { m_selectedStylesheetSetName = name; }
84
85 void addPendingSheet() { m_pendingStylesheets++; }
86 enum RemovePendingSheetNotificationType {
87 RemovePendingSheetNotifyImmediately,
88 RemovePendingSheetNotifyLater
89 };
90 void removePendingSheet(RemovePendingSheetNotificationType = RemovePendingSheetNotifyImmediately);
91
92 bool hasPendingSheets() const { return m_pendingStylesheets > 0; }
93
94 bool usesSiblingRules() const { return m_usesSiblingRules || m_usesSiblingRulesOverride; }
95 void setUsesSiblingRulesOverride(bool b) { m_usesSiblingRulesOverride = b; }
96 bool usesFirstLineRules() const { return m_usesFirstLineRules; }
97 bool usesFirstLetterRules() const { return m_usesFirstLetterRules; }
98 void setUsesFirstLetterRules(bool b) { m_usesFirstLetterRules = b; }
99 bool usesBeforeAfterRules() const { return m_usesBeforeAfterRules || m_usesBeforeAfterRulesOverride; }
100 void setUsesBeforeAfterRulesOverride(bool b) { m_usesBeforeAfterRulesOverride = b; }
101 bool usesRemUnits() const { return m_usesRemUnits; }
102 void setUsesRemUnit(bool b) { m_usesRemUnits = b; }
Ben Murdoch02772c62013-07-26 10:21:05 +0100103 bool hasScopedStyleSheet() { return m_collectionForDocument.scopingNodesForStyleScoped(); }
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +0000104
Ben Murdoch7757ec22013-07-23 11:17:36 +0100105 void combineCSSFeatureFlags(const RuleFeatureSet&);
106 void resetCSSFeatureFlags(const RuleFeatureSet&);
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +0000107
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +0000108private:
109 DocumentStyleSheetCollection(Document*);
110
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +0000111 Document* m_document;
112
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +0000113 // Track the number of currently loading top-level stylesheets needed for rendering.
114 // Sheets loaded using the @import directive are not included in this count.
115 // We use this count of pending sheets to detect when we can begin attaching
116 // elements and when it is safe to execute scripts.
117 int m_pendingStylesheets;
118
119 RefPtr<CSSStyleSheet> m_pageUserSheet;
Torne (Richard Coles)926b0012013-03-28 15:32:48 +0000120
121 mutable Vector<RefPtr<CSSStyleSheet> > m_injectedUserStyleSheets;
122 mutable Vector<RefPtr<CSSStyleSheet> > m_injectedAuthorStyleSheets;
123 mutable bool m_injectedStyleSheetCacheValid;
124
125 Vector<RefPtr<CSSStyleSheet> > m_userStyleSheets;
126 Vector<RefPtr<CSSStyleSheet> > m_authorStyleSheets;
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +0000127
128 bool m_hadActiveLoadingStylesheet;
129 bool m_needsUpdateActiveStylesheetsOnStyleRecalc;
130
Ben Murdoche69819b2013-07-17 14:56:49 +0100131 StyleSheetCollection m_collectionForDocument;
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +0000132
133 String m_preferredStylesheetSetName;
134 String m_selectedStylesheetSetName;
135
136 bool m_usesSiblingRules;
137 bool m_usesSiblingRulesOverride;
138 bool m_usesFirstLineRules;
139 bool m_usesFirstLetterRules;
140 bool m_usesBeforeAfterRules;
141 bool m_usesBeforeAfterRulesOverride;
142 bool m_usesRemUnits;
143};
144
145}
146
147#endif
148