Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(260)

Side by Side Diff: sky/engine/core/css/StyleRule.h

Issue 758573005: Remove CSSOM mutability in StyleRule. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « sky/engine/core/css/StyleKeyframe.cpp ('k') | sky/engine/core/css/StyleRule.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * (C) 1999-2003 Lars Knoll (knoll@kde.org) 2 * (C) 1999-2003 Lars Knoll (knoll@kde.org)
3 * (C) 2002-2003 Dirk Mueller (mueller@kde.org) 3 * (C) 2002-2003 Dirk Mueller (mueller@kde.org)
4 * Copyright (C) 2002, 2006, 2008, 2012, 2013 Apple Inc. All rights reserved. 4 * Copyright (C) 2002, 2006, 2008, 2012, 2013 Apple Inc. All rights reserved.
5 * 5 *
6 * This library is free software; you can redistribute it and/or 6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public 7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either 8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version. 9 * version 2 of the License, or (at your option) any later version.
10 * 10 *
11 * This library is distributed in the hope that it will be useful, 11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details. 14 * Library General Public License for more details.
15 * 15 *
16 * You should have received a copy of the GNU Library General Public License 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 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, 18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA. 19 * Boston, MA 02110-1301, USA.
20 */ 20 */
21 21
22 #ifndef SKY_ENGINE_CORE_CSS_STYLERULE_H_ 22 #ifndef SKY_ENGINE_CORE_CSS_STYLERULE_H_
23 #define SKY_ENGINE_CORE_CSS_STYLERULE_H_ 23 #define SKY_ENGINE_CORE_CSS_STYLERULE_H_
24 24
25 #include "sky/engine/core/css/CSSSelectorList.h" 25 #include "sky/engine/core/css/CSSSelectorList.h"
26 #include "sky/engine/core/css/MediaList.h" 26 #include "sky/engine/core/css/MediaList.h"
27 #include "sky/engine/wtf/Noncopyable.h"
27 #include "sky/engine/wtf/RefPtr.h" 28 #include "sky/engine/wtf/RefPtr.h"
28 29
29 namespace blink { 30 namespace blink {
30 31
31 class CSSStyleSheet;
32 class MutableStylePropertySet;
33 class StylePropertySet; 32 class StylePropertySet;
34 33
35 class StyleRuleBase : public RefCounted<StyleRuleBase> { 34 class StyleRuleBase : public RefCounted<StyleRuleBase> {
36 WTF_MAKE_FAST_ALLOCATED; 35 WTF_MAKE_FAST_ALLOCATED;
37 public: 36 public:
38 enum Type { 37 enum Type {
39 Unknown, // Not used. 38 Unknown, // Not used.
40 Style, 39 Style,
41 Media, 40 Media,
42 FontFace = 4, 41 FontFace = 4,
43 Keyframes = 5, 42 Keyframes = 5,
44 Keyframe, // Not used. These are internally non-rule StyleKeyframe objec ts. 43 Keyframe, // Not used. These are internally non-rule StyleKeyframe objec ts.
45 Supports = 12, 44 Supports = 12,
46 Filter = 17 45 Filter = 17
47 }; 46 };
48 47
49 Type type() const { return static_cast<Type>(m_type); } 48 Type type() const { return static_cast<Type>(m_type); }
50 49
51 bool isFontFaceRule() const { return type() == FontFace; } 50 bool isFontFaceRule() const { return type() == FontFace; }
52 bool isKeyframesRule() const { return type() == Keyframes; } 51 bool isKeyframesRule() const { return type() == Keyframes; }
53 bool isMediaRule() const { return type() == Media; } 52 bool isMediaRule() const { return type() == Media; }
54 bool isStyleRule() const { return type() == Style; } 53 bool isStyleRule() const { return type() == Style; }
55 bool isSupportsRule() const { return type() == Supports; } 54 bool isSupportsRule() const { return type() == Supports; }
56 bool isFilterRule() const { return type() == Filter; } 55 bool isFilterRule() const { return type() == Filter; }
57 56
58 PassRefPtr<StyleRuleBase> copy() const;
59
60 void deref() 57 void deref()
61 { 58 {
62 if (derefBase()) 59 if (derefBase())
63 destroy(); 60 destroy();
64 } 61 }
65 62
66 protected: 63 protected:
67 StyleRuleBase(Type type) : m_type(type) { } 64 StyleRuleBase(Type type) : m_type(type) { }
68 StyleRuleBase(const StyleRuleBase& o) : m_type(o.m_type) { }
69 65
70 ~StyleRuleBase() { } 66 ~StyleRuleBase() { }
71 67
72 private: 68 private:
73 void destroy(); 69 void destroy();
74 70
75 unsigned m_type : 5; 71 unsigned m_type : 5;
76 }; 72 };
77 73
78 class StyleRule : public StyleRuleBase { 74 class StyleRule final : public StyleRuleBase {
79 WTF_MAKE_FAST_ALLOCATED; 75 WTF_MAKE_FAST_ALLOCATED;
76 WTF_MAKE_NONCOPYABLE(StyleRule);
80 public: 77 public:
81 static PassRefPtr<StyleRule> create() { return adoptRef(new StyleRule()); } 78 static PassRefPtr<StyleRule> create() { return adoptRef(new StyleRule()); }
82 79
83 ~StyleRule(); 80 ~StyleRule();
84 81
85 const CSSSelectorList& selectorList() const { return m_selectorList; } 82 const CSSSelectorList& selectorList() const { return m_selectorList; }
86 const StylePropertySet& properties() const { return *m_properties; } 83 const StylePropertySet& properties() const { return *m_properties; }
87 MutableStylePropertySet& mutableProperties();
88 84
89 void parserAdoptSelectorVector(Vector<OwnPtr<CSSParserSelector> >& selectors ) { m_selectorList.adoptSelectorVector(selectors); } 85 void parserAdoptSelectorVector(Vector<OwnPtr<CSSParserSelector> >& selectors ) { m_selectorList.adoptSelectorVector(selectors); }
90 void wrapperAdoptSelectorList(CSSSelectorList& selectors) { m_selectorList.a dopt(selectors); } 86 void wrapperAdoptSelectorList(CSSSelectorList& selectors) { m_selectorList.a dopt(selectors); }
91 void setProperties(PassRefPtr<StylePropertySet>); 87 void setProperties(PassRefPtr<StylePropertySet>);
92 88
93 PassRefPtr<StyleRule> copy() const { return adoptRef(new StyleRule(*this)); }
94
95 static unsigned averageSizeInBytes(); 89 static unsigned averageSizeInBytes();
96 90
97 private: 91 private:
98 StyleRule(); 92 StyleRule();
99 StyleRule(const StyleRule&);
100 93
101 RefPtr<StylePropertySet> m_properties; // Cannot be null. 94 RefPtr<StylePropertySet> m_properties; // Cannot be null.
102 CSSSelectorList m_selectorList; 95 CSSSelectorList m_selectorList;
103 }; 96 };
104 97
105 class StyleRuleFontFace : public StyleRuleBase { 98 class StyleRuleFontFace final : public StyleRuleBase {
99 WTF_MAKE_NONCOPYABLE(StyleRuleFontFace);
106 public: 100 public:
107 static PassRefPtr<StyleRuleFontFace> create() { return adoptRef(new StyleRul eFontFace); } 101 static PassRefPtr<StyleRuleFontFace> create() { return adoptRef(new StyleRul eFontFace); }
108 102
109 ~StyleRuleFontFace(); 103 ~StyleRuleFontFace();
110 104
111 const StylePropertySet& properties() const { return *m_properties; } 105 const StylePropertySet& properties() const { return *m_properties; }
112 MutableStylePropertySet& mutableProperties();
113 106
114 void setProperties(PassRefPtr<StylePropertySet>); 107 void setProperties(PassRefPtr<StylePropertySet>);
115 108
116 PassRefPtr<StyleRuleFontFace> copy() const { return adoptRef(new StyleRuleFo ntFace(*this)); }
117
118 private: 109 private:
119 StyleRuleFontFace(); 110 StyleRuleFontFace();
120 StyleRuleFontFace(const StyleRuleFontFace&);
121 111
122 RefPtr<StylePropertySet> m_properties; // Cannot be null. 112 RefPtr<StylePropertySet> m_properties; // Cannot be null.
123 }; 113 };
124 114
125 class StyleRuleGroup : public StyleRuleBase { 115 class StyleRuleGroup : public StyleRuleBase {
126 public: 116 public:
127 const Vector<RefPtr<StyleRuleBase> >& childRules() const { return m_childRul es; } 117 const Vector<RefPtr<StyleRuleBase> >& childRules() const { return m_childRul es; }
128 118
129 void wrapperInsertRule(unsigned, PassRefPtr<StyleRuleBase>);
130 void wrapperRemoveRule(unsigned);
131
132 protected: 119 protected:
133 StyleRuleGroup(Type, Vector<RefPtr<StyleRuleBase> >& adoptRule); 120 StyleRuleGroup(Type, Vector<RefPtr<StyleRuleBase> >& adoptRule);
134 StyleRuleGroup(const StyleRuleGroup&);
135 121
136 private: 122 private:
137 Vector<RefPtr<StyleRuleBase> > m_childRules; 123 Vector<RefPtr<StyleRuleBase> > m_childRules;
138 }; 124 };
139 125
140 class StyleRuleMedia : public StyleRuleGroup { 126 class StyleRuleMedia final : public StyleRuleGroup {
127 WTF_MAKE_NONCOPYABLE(StyleRuleMedia);
141 public: 128 public:
142 static PassRefPtr<StyleRuleMedia> create(PassRefPtr<MediaQuerySet> media, Ve ctor<RefPtr<StyleRuleBase> >& adoptRules) 129 static PassRefPtr<StyleRuleMedia> create(PassRefPtr<MediaQuerySet> media, Ve ctor<RefPtr<StyleRuleBase> >& adoptRules)
143 { 130 {
144 return adoptRef(new StyleRuleMedia(media, adoptRules)); 131 return adoptRef(new StyleRuleMedia(media, adoptRules));
145 } 132 }
146 133
147 MediaQuerySet* mediaQueries() const { return m_mediaQueries.get(); } 134 MediaQuerySet* mediaQueries() const { return m_mediaQueries.get(); }
148 135
149 PassRefPtr<StyleRuleMedia> copy() const { return adoptRef(new StyleRuleMedia (*this)); }
150
151 private: 136 private:
152 StyleRuleMedia(PassRefPtr<MediaQuerySet>, Vector<RefPtr<StyleRuleBase> >& ad optRules); 137 StyleRuleMedia(PassRefPtr<MediaQuerySet>, Vector<RefPtr<StyleRuleBase> >& ad optRules);
153 StyleRuleMedia(const StyleRuleMedia&);
154 138
155 RefPtr<MediaQuerySet> m_mediaQueries; 139 RefPtr<MediaQuerySet> m_mediaQueries;
156 }; 140 };
157 141
158 class StyleRuleSupports : public StyleRuleGroup { 142 class StyleRuleSupports final : public StyleRuleGroup {
143 WTF_MAKE_NONCOPYABLE(StyleRuleSupports);
159 public: 144 public:
160 static PassRefPtr<StyleRuleSupports> create(const String& conditionText, boo l conditionIsSupported, Vector<RefPtr<StyleRuleBase> >& adoptRules) 145 static PassRefPtr<StyleRuleSupports> create(const String& conditionText, boo l conditionIsSupported, Vector<RefPtr<StyleRuleBase> >& adoptRules)
161 { 146 {
162 return adoptRef(new StyleRuleSupports(conditionText, conditionIsSupporte d, adoptRules)); 147 return adoptRef(new StyleRuleSupports(conditionText, conditionIsSupporte d, adoptRules));
163 } 148 }
164 149
165 String conditionText() const { return m_conditionText; } 150 String conditionText() const { return m_conditionText; }
166 bool conditionIsSupported() const { return m_conditionIsSupported; } 151 bool conditionIsSupported() const { return m_conditionIsSupported; }
167 PassRefPtr<StyleRuleSupports> copy() const { return adoptRef(new StyleRuleSu pports(*this)); }
168 152
169 private: 153 private:
170 StyleRuleSupports(const String& conditionText, bool conditionIsSupported, Ve ctor<RefPtr<StyleRuleBase> >& adoptRules); 154 StyleRuleSupports(const String& conditionText, bool conditionIsSupported, Ve ctor<RefPtr<StyleRuleBase> >& adoptRules);
171 StyleRuleSupports(const StyleRuleSupports&);
172 155
173 String m_conditionText; 156 String m_conditionText;
174 bool m_conditionIsSupported; 157 bool m_conditionIsSupported;
175 }; 158 };
176 159
177 class StyleRuleFilter : public StyleRuleBase { 160 class StyleRuleFilter final : public StyleRuleBase {
161 WTF_MAKE_NONCOPYABLE(StyleRuleFilter);
178 public: 162 public:
179 static PassRefPtr<StyleRuleFilter> create(const String& filterName) { return adoptRef(new StyleRuleFilter(filterName)); } 163 static PassRefPtr<StyleRuleFilter> create(const String& filterName) { return adoptRef(new StyleRuleFilter(filterName)); }
180 164
181 ~StyleRuleFilter(); 165 ~StyleRuleFilter();
182 166
183 const String& filterName() const { return m_filterName; } 167 const String& filterName() const { return m_filterName; }
184 168
185 const StylePropertySet& properties() const { return *m_properties; } 169 const StylePropertySet& properties() const { return *m_properties; }
186 MutableStylePropertySet& mutableProperties();
187 170
188 void setProperties(PassRefPtr<StylePropertySet>); 171 void setProperties(PassRefPtr<StylePropertySet>);
189 172
190 PassRefPtr<StyleRuleFilter> copy() const { return adoptRef(new StyleRuleFilt er(*this)); }
191
192 private: 173 private:
193 StyleRuleFilter(const String&); 174 StyleRuleFilter(const String&);
194 StyleRuleFilter(const StyleRuleFilter&);
195 175
196 String m_filterName; 176 String m_filterName;
197 RefPtr<StylePropertySet> m_properties; 177 RefPtr<StylePropertySet> m_properties;
198 }; 178 };
199 179
200 #define DEFINE_STYLE_RULE_TYPE_CASTS(Type) \ 180 #define DEFINE_STYLE_RULE_TYPE_CASTS(Type) \
201 DEFINE_TYPE_CASTS(StyleRule##Type, StyleRuleBase, rule, rule->is##Type##Rule (), rule.is##Type##Rule()) 181 DEFINE_TYPE_CASTS(StyleRule##Type, StyleRuleBase, rule, rule->is##Type##Rule (), rule.is##Type##Rule())
202 182
203 DEFINE_TYPE_CASTS(StyleRule, StyleRuleBase, rule, rule->isStyleRule(), rule.isSt yleRule()); 183 DEFINE_TYPE_CASTS(StyleRule, StyleRuleBase, rule, rule->isStyleRule(), rule.isSt yleRule());
204 DEFINE_STYLE_RULE_TYPE_CASTS(FontFace); 184 DEFINE_STYLE_RULE_TYPE_CASTS(FontFace);
205 DEFINE_STYLE_RULE_TYPE_CASTS(Media); 185 DEFINE_STYLE_RULE_TYPE_CASTS(Media);
206 DEFINE_STYLE_RULE_TYPE_CASTS(Supports); 186 DEFINE_STYLE_RULE_TYPE_CASTS(Supports);
207 DEFINE_STYLE_RULE_TYPE_CASTS(Filter); 187 DEFINE_STYLE_RULE_TYPE_CASTS(Filter);
208 188
209 } // namespace blink 189 } // namespace blink
210 190
211 #endif // SKY_ENGINE_CORE_CSS_STYLERULE_H_ 191 #endif // SKY_ENGINE_CORE_CSS_STYLERULE_H_
OLDNEW
« no previous file with comments | « sky/engine/core/css/StyleKeyframe.cpp ('k') | sky/engine/core/css/StyleRule.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698