Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 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. |
| 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 Murdoch | 591b958 | 2013-07-10 11:41:44 +0100 | [diff] [blame] | 31 | #include "core/dom/Document.h" |
| 32 | #include "core/dom/DocumentOrderedList.h" |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 33 | #include "core/dom/StyleSheetCollection.h" |
Ben Murdoch | 591b958 | 2013-07-10 11:41:44 +0100 | [diff] [blame] | 34 | #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) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 39 | |
| 40 | namespace WebCore { |
| 41 | |
| 42 | class CSSStyleSheet; |
Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 43 | class Node; |
Ben Murdoch | 7757ec2 | 2013-07-23 11:17:36 +0100 | [diff] [blame] | 44 | class RuleFeatureSet; |
Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 45 | class StyleSheet; |
| 46 | class StyleSheetContents; |
| 47 | class StyleSheetList; |
| 48 | |
| 49 | class DocumentStyleSheetCollection { |
| 50 | WTF_MAKE_FAST_ALLOCATED; |
| 51 | public: |
| 52 | static PassOwnPtr<DocumentStyleSheetCollection> create(Document* document) { return adoptPtr(new DocumentStyleSheetCollection(document)); } |
| 53 | |
| 54 | ~DocumentStyleSheetCollection(); |
| 55 | |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 56 | const Vector<RefPtr<StyleSheet> >& styleSheetsForStyleSheetList(); |
| 57 | const Vector<RefPtr<CSSStyleSheet> >& activeAuthorStyleSheets() const; |
Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 58 | |
| 59 | CSSStyleSheet* pageUserSheet(); |
Torne (Richard Coles) | 926b001 | 2013-03-28 15:32:48 +0000 | [diff] [blame] | 60 | 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) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 64 | |
| 65 | void addStyleSheetCandidateNode(Node*, bool createdByParser); |
Ben Murdoch | 02772c6 | 2013-07-26 10:21:05 +0100 | [diff] [blame] | 66 | void removeStyleSheetCandidateNode(Node*, ContainerNode* scopingNode = 0); |
Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 67 | |
| 68 | void clearPageUserSheet(); |
| 69 | void updatePageUserSheet(); |
Torne (Richard Coles) | 926b001 | 2013-03-28 15:32:48 +0000 | [diff] [blame] | 70 | void invalidateInjectedStyleSheetCache(); |
| 71 | void updateInjectedStyleSheetCache() const; |
Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 72 | |
Torne (Richard Coles) | 926b001 | 2013-03-28 15:32:48 +0000 | [diff] [blame] | 73 | void addAuthorSheet(PassRefPtr<StyleSheetContents> authorSheet); |
Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 74 | void addUserSheet(PassRefPtr<StyleSheetContents> userSheet); |
| 75 | |
| 76 | bool needsUpdateActiveStylesheetsOnStyleRecalc() const { return m_needsUpdateActiveStylesheetsOnStyleRecalc; } |
| 77 | |
Ben Murdoch | 591b958 | 2013-07-10 11:41:44 +0100 | [diff] [blame] | 78 | bool updateActiveStyleSheets(StyleResolverUpdateMode); |
Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 79 | |
| 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 Murdoch | 02772c6 | 2013-07-26 10:21:05 +0100 | [diff] [blame] | 103 | bool hasScopedStyleSheet() { return m_collectionForDocument.scopingNodesForStyleScoped(); } |
Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 104 | |
Ben Murdoch | 7757ec2 | 2013-07-23 11:17:36 +0100 | [diff] [blame] | 105 | void combineCSSFeatureFlags(const RuleFeatureSet&); |
| 106 | void resetCSSFeatureFlags(const RuleFeatureSet&); |
Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 107 | |
Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 108 | private: |
| 109 | DocumentStyleSheetCollection(Document*); |
| 110 | |
Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 111 | Document* m_document; |
| 112 | |
Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 113 | // 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) | 926b001 | 2013-03-28 15:32:48 +0000 | [diff] [blame] | 120 | |
| 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) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 127 | |
| 128 | bool m_hadActiveLoadingStylesheet; |
| 129 | bool m_needsUpdateActiveStylesheetsOnStyleRecalc; |
| 130 | |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 131 | StyleSheetCollection m_collectionForDocument; |
Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 132 | |
| 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 | |