• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 TreeScopeStyleSheetCollection_h
29 #define TreeScopeStyleSheetCollection_h
30 
31 #include "core/dom/Document.h"
32 #include "core/dom/DocumentOrderedList.h"
33 #include "core/dom/StyleSheetCollection.h"
34 #include "core/dom/StyleSheetScopingNodeList.h"
35 #include "core/dom/TreeScope.h"
36 #include "wtf/FastAllocBase.h"
37 #include "wtf/HashMap.h"
38 #include "wtf/ListHashSet.h"
39 #include "wtf/RefPtr.h"
40 #include "wtf/Vector.h"
41 #include "wtf/text/WTFString.h"
42 
43 namespace WebCore {
44 
45 class ContainerNode;
46 class DocumentStyleSheetCollector;
47 class StyleEngine;
48 class Node;
49 class StyleSheetContents;
50 class StyleSheetList;
51 class StyleRuleFontFace;
52 
53 class TreeScopeStyleSheetCollection : public StyleSheetCollection {
54 public:
55     void addStyleSheetCandidateNode(Node*, bool createdByParser);
56     void removeStyleSheetCandidateNode(Node*, ContainerNode* scopingNode);
hasStyleSheetCandidateNodes()57     bool hasStyleSheetCandidateNodes() const { return !m_styleSheetCandidateNodes.isEmpty(); }
58 
usesRemUnits()59     bool usesRemUnits() const { return m_usesRemUnits; }
60 
styleSheetCandidateNodes()61     DocumentOrderedList& styleSheetCandidateNodes() { return m_styleSheetCandidateNodes; }
scopingNodesForStyleScoped()62     DocumentOrderedList* scopingNodesForStyleScoped() { return m_scopingNodesForStyleScoped.scopingNodes(); }
scopingNodesRemoved()63     ListHashSet<Node*, 4>* scopingNodesRemoved() { return m_scopingNodesForStyleScoped.scopingNodesRemoved(); }
64 
65     void clearMediaQueryRuleSetStyleSheets();
66     void enableExitTransitionStylesheets();
67 
trace(Visitor * visitor)68     virtual void trace(Visitor* visitor) OVERRIDE
69     {
70         StyleSheetCollection::trace(visitor);
71     }
72 
73 protected:
74     explicit TreeScopeStyleSheetCollection(TreeScope&);
75 
document()76     Document& document() const { return m_treeScope.document(); }
77 
78     enum StyleResolverUpdateType {
79         Reconstruct,
80         Reset,
81         Additive
82     };
83 
84     class StyleSheetChange {
85         STACK_ALLOCATED();
86     public:
87         StyleResolverUpdateType styleResolverUpdateType;
88         bool requiresFullStyleRecalc;
89         WillBeHeapVector<RawPtrWillBeMember<const StyleRuleFontFace> > fontFaceRulesToRemove;
90 
StyleSheetChange()91         StyleSheetChange()
92             : styleResolverUpdateType(Reconstruct)
93             , requiresFullStyleRecalc(true) { }
94     };
95 
96     void analyzeStyleSheetChange(StyleResolverUpdateMode, const StyleSheetCollection&, StyleSheetChange&);
97     void resetAllRuleSetsInTreeScope(StyleResolver*);
98     void updateUsesRemUnits();
99 
100 private:
101     static StyleResolverUpdateType compareStyleSheets(const WillBeHeapVector<RefPtrWillBeMember<CSSStyleSheet> >& oldStyleSheets, const WillBeHeapVector<RefPtrWillBeMember<CSSStyleSheet> >& newStylesheets, WillBeHeapVector<RawPtrWillBeMember<StyleSheetContents> >& addedSheets);
102     bool activeLoadingStyleSheetLoaded(const WillBeHeapVector<RefPtrWillBeMember<CSSStyleSheet> >& newStyleSheets);
103 
104 protected:
105     TreeScope& m_treeScope;
106     bool m_hadActiveLoadingStylesheet;
107     bool m_usesRemUnits;
108 
109     DocumentOrderedList m_styleSheetCandidateNodes;
110     StyleSheetScopingNodeList m_scopingNodesForStyleScoped;
111 };
112 
113 }
114 
115 #endif
116 
117