1 | /* |
2 | * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
3 | * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved. |
4 | * Copyright (C) 2013 Google Inc. All rights reserved. |
5 | * |
6 | * This library is free software; you can redistribute it and/or |
7 | * modify it under the terms of the GNU Library General Public |
8 | * License as published by the Free Software Foundation; either |
9 | * version 2 of the License, or (at your option) any later version. |
10 | * |
11 | * This library is distributed in the hope that it will be useful, |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | * Library General Public License for more details. |
15 | * |
16 | * You should have received a copy of the GNU Library General Public License |
17 | * along with this library; see the file COPYING.LIB. If not, write to |
18 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
19 | * Boston, MA 02110-1301, USA. |
20 | * |
21 | */ |
22 | |
23 | #pragma once |
24 | |
25 | #include "CSSDefaultStyleSheets.h" |
26 | #include "RuleFeature.h" |
27 | #include "RuleSet.h" |
28 | #include <memory> |
29 | #include <wtf/HashMap.h> |
30 | #include <wtf/RefPtr.h> |
31 | #include <wtf/Vector.h> |
32 | |
33 | namespace WebCore { |
34 | |
35 | class CSSStyleRule; |
36 | class CSSStyleSheet; |
37 | class ExtensionStyleSheets; |
38 | class InspectorCSSOMWrappers; |
39 | class MediaQueryEvaluator; |
40 | |
41 | struct InvalidationRuleSet { |
42 | MatchElement matchElement; |
43 | std::unique_ptr<RuleSet> ruleSet; |
44 | Vector<const CSSSelector*> invalidationSelectors; |
45 | |
46 | WTF_MAKE_FAST_ALLOCATED; |
47 | }; |
48 | |
49 | class DocumentRuleSets { |
50 | public: |
51 | DocumentRuleSets(StyleResolver&); |
52 | ~DocumentRuleSets(); |
53 | |
54 | bool isAuthorStyleDefined() const { return m_isAuthorStyleDefined; } |
55 | RuleSet* userAgentMediaQueryStyle() const; |
56 | RuleSet& authorStyle() const { return *m_authorStyle.get(); } |
57 | RuleSet* userStyle() const; |
58 | const RuleFeatureSet& features() const; |
59 | RuleSet* sibling() const { return m_siblingRuleSet.get(); } |
60 | RuleSet* uncommonAttribute() const { return m_uncommonAttributeRuleSet.get(); } |
61 | |
62 | const Vector<InvalidationRuleSet>* classInvalidationRuleSets(const AtomicString& className) const; |
63 | const Vector<InvalidationRuleSet>* attributeInvalidationRuleSets(const AtomicString& attributeName) const; |
64 | |
65 | bool hasComplexSelectorsForStyleAttribute() const; |
66 | |
67 | void setIsForShadowScope() { m_isForShadowScope = true; } |
68 | |
69 | void setUsesSharedUserStyle(bool b) { m_usesSharedUserStyle = b; } |
70 | void initializeUserStyle(); |
71 | |
72 | void resetAuthorStyle(); |
73 | void appendAuthorStyleSheets(const Vector<RefPtr<CSSStyleSheet>>&, MediaQueryEvaluator*, InspectorCSSOMWrappers&, StyleResolver*); |
74 | |
75 | void resetUserAgentMediaQueryStyle(); |
76 | |
77 | RuleFeatureSet& mutableFeatures(); |
78 | |
79 | private: |
80 | void collectFeatures() const; |
81 | void collectRulesFromUserStyleSheets(const Vector<RefPtr<CSSStyleSheet>>&, RuleSet& userStyle, const MediaQueryEvaluator&, StyleResolver&); |
82 | void updateUserAgentMediaQueryStyleIfNeeded() const; |
83 | |
84 | std::unique_ptr<RuleSet> m_authorStyle; |
85 | mutable std::unique_ptr<RuleSet> m_userAgentMediaQueryStyle; |
86 | std::unique_ptr<RuleSet> m_userStyle; |
87 | |
88 | StyleResolver& m_styleResolver; |
89 | mutable RuleFeatureSet m_features; |
90 | mutable std::unique_ptr<RuleSet> m_siblingRuleSet; |
91 | mutable std::unique_ptr<RuleSet> m_uncommonAttributeRuleSet; |
92 | mutable HashMap<AtomicString, std::unique_ptr<Vector<InvalidationRuleSet>>> m_classInvalidationRuleSets; |
93 | mutable HashMap<AtomicString, std::unique_ptr<Vector<InvalidationRuleSet>>> m_attributeInvalidationRuleSets; |
94 | |
95 | mutable Optional<bool> m_cachedHasComplexSelectorsForStyleAttribute; |
96 | |
97 | mutable unsigned m_defaultStyleVersionOnFeatureCollection { 0 }; |
98 | mutable unsigned m_userAgentMediaQueryRuleCountOnUpdate { 0 }; |
99 | |
100 | bool m_usesSharedUserStyle { false }; |
101 | bool m_isForShadowScope { false }; |
102 | bool m_isAuthorStyleDefined { false }; |
103 | }; |
104 | |
105 | inline const RuleFeatureSet& DocumentRuleSets::features() const |
106 | { |
107 | if (m_defaultStyleVersionOnFeatureCollection < CSSDefaultStyleSheets::defaultStyleVersion) |
108 | collectFeatures(); |
109 | return m_features; |
110 | } |
111 | |
112 | // FIXME: There should be just the const version. |
113 | inline RuleFeatureSet& DocumentRuleSets::mutableFeatures() |
114 | { |
115 | if (m_defaultStyleVersionOnFeatureCollection < CSSDefaultStyleSheets::defaultStyleVersion) |
116 | collectFeatures(); |
117 | return m_features; |
118 | } |
119 | |
120 | } // namespace WebCore |
121 | |