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

Side by Side Diff: Source/core/css/StylePropertySet.h

Issue 1164573002: CSSValue Immediates: Change CSSValue to an object instead of a pointer (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Some small fixes to (hopefully) fix some broken tests Created 5 years, 6 months 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
OLDNEW
1 /* 1 /*
2 * (C) 1999-2003 Lars Knoll (knoll@kde.org) 2 * (C) 1999-2003 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2004, 2005, 2006, 2008, 2012 Apple Inc. All rights reserved. 3 * Copyright (C) 2004, 2005, 2006, 2008, 2012 Apple Inc. All rights reserved.
4 * 4 *
5 * This library is free software; you can redistribute it and/or 5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public 6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either 7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version. 8 * version 2 of the License, or (at your option) any later version.
9 * 9 *
10 * This library is distributed in the hope that it will be useful, 10 * This library is distributed in the hope that it will be useful,
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 { 63 {
64 } 64 }
65 65
66 CSSPropertyID id() const { return static_cast<CSSPropertyID>(propertyMet adata().m_propertyID); } 66 CSSPropertyID id() const { return static_cast<CSSPropertyID>(propertyMet adata().m_propertyID); }
67 CSSPropertyID shorthandID() const { return propertyMetadata().shorthandI D(); } 67 CSSPropertyID shorthandID() const { return propertyMetadata().shorthandI D(); }
68 68
69 bool isImportant() const { return propertyMetadata().m_important; } 69 bool isImportant() const { return propertyMetadata().m_important; }
70 bool isInherited() const { return propertyMetadata().m_inherited; } 70 bool isInherited() const { return propertyMetadata().m_inherited; }
71 bool isImplicit() const { return propertyMetadata().m_implicit; } 71 bool isImplicit() const { return propertyMetadata().m_implicit; }
72 72
73 const CSSValue* value() const { return propertyValue(); } 73 const CSSValue value() const { return propertyValue(); }
74 // FIXME: We should try to remove this mutable overload. 74 // FIXME: We should try to remove this mutable overload.
75 CSSValue* value() { return const_cast<CSSValue*>(propertyValue()); } 75 CSSValue value() { return propertyValue(); }
76 76
77 // FIXME: Remove this. 77 // FIXME: Remove this.
78 CSSProperty toCSSProperty() const { return CSSProperty(propertyMetadata( ), const_cast<CSSValue*>(propertyValue())); } 78 CSSProperty toCSSProperty() const { return CSSProperty(propertyMetadata( ), propertyValue()); }
79 79
80 const StylePropertyMetadata& propertyMetadata() const; 80 const StylePropertyMetadata& propertyMetadata() const;
81 81
82 private: 82 private:
83 const CSSValue* propertyValue() const; 83 const CSSValue propertyValue() const;
84 84
85 const StylePropertySet& m_propertySet; 85 const StylePropertySet& m_propertySet;
86 unsigned m_index; 86 unsigned m_index;
87 }; 87 };
88 88
89 unsigned propertyCount() const; 89 unsigned propertyCount() const;
90 bool isEmpty() const; 90 bool isEmpty() const;
91 PropertyReference propertyAt(unsigned index) const { return PropertyReferenc e(*this, index); } 91 PropertyReference propertyAt(unsigned index) const { return PropertyReferenc e(*this, index); }
92 int findPropertyIndex(CSSPropertyID) const; 92 int findPropertyIndex(CSSPropertyID) const;
93 bool hasProperty(CSSPropertyID property) const { return findPropertyIndex(pr operty) != -1; } 93 bool hasProperty(CSSPropertyID property) const { return findPropertyIndex(pr operty) != -1; }
94 94
95 PassRefPtrWillBeRawPtr<CSSValue> getPropertyCSSValue(CSSPropertyID) const; 95 NullableCSSValue getPropertyCSSValue(CSSPropertyID) const;
96 String getPropertyValue(CSSPropertyID) const; 96 String getPropertyValue(CSSPropertyID) const;
97 97
98 bool propertyIsImportant(CSSPropertyID) const; 98 bool propertyIsImportant(CSSPropertyID) const;
99 CSSPropertyID getPropertyShorthand(CSSPropertyID) const; 99 CSSPropertyID getPropertyShorthand(CSSPropertyID) const;
100 bool isPropertyImplicit(CSSPropertyID) const; 100 bool isPropertyImplicit(CSSPropertyID) const;
101 101
102 PassRefPtrWillBeRawPtr<MutableStylePropertySet> copyBlockProperties() const; 102 PassRefPtrWillBeRawPtr<MutableStylePropertySet> copyBlockProperties() const;
103 103
104 CSSParserMode cssParserMode() const { return static_cast<CSSParserMode>(m_cs sParserMode); } 104 CSSParserMode cssParserMode() const { return static_cast<CSSParserMode>(m_cs sParserMode); }
105 105
106 PassRefPtrWillBeRawPtr<MutableStylePropertySet> mutableCopy() const; 106 PassRefPtrWillBeRawPtr<MutableStylePropertySet> mutableCopy() const;
107 PassRefPtrWillBeRawPtr<ImmutableStylePropertySet> immutableCopyIfNeeded() co nst; 107 PassRefPtrWillBeRawPtr<ImmutableStylePropertySet> immutableCopyIfNeeded() co nst;
108 108
109 PassRefPtrWillBeRawPtr<MutableStylePropertySet> copyPropertiesInSet(const Ve ctor<CSSPropertyID>&) const; 109 PassRefPtrWillBeRawPtr<MutableStylePropertySet> copyPropertiesInSet(const Ve ctor<CSSPropertyID>&) const;
110 110
111 String asText() const; 111 String asText() const;
112 112
113 bool isMutable() const { return m_isMutable; } 113 bool isMutable() const { return m_isMutable; }
114 114
115 bool hasFailedOrCanceledSubresources() const; 115 bool hasFailedOrCanceledSubresources() const;
116 116
117 static unsigned averageSizeInBytes(); 117 static unsigned averageSizeInBytes();
118 118
119 #ifndef NDEBUG 119 #ifndef NDEBUG
120 void showStyle(); 120 void showStyle();
121 #endif 121 #endif
122 122
123 bool propertyMatches(CSSPropertyID, const CSSValue*) const; 123 bool propertyMatches(CSSPropertyID, const CSSValue) const;
124 124
125 DECLARE_TRACE(); 125 DECLARE_TRACE();
126 DEFINE_INLINE_TRACE_AFTER_DISPATCH() { } 126 DEFINE_INLINE_TRACE_AFTER_DISPATCH() { }
127 127
128 protected: 128 protected:
129 129
130 enum { MaxArraySize = (1 << 28) - 1 }; 130 enum { MaxArraySize = (1 << 28) - 1 };
131 131
132 StylePropertySet(CSSParserMode cssParserMode) 132 StylePropertySet(CSSParserMode cssParserMode)
133 : m_cssParserMode(cssParserMode) 133 : m_cssParserMode(cssParserMode)
(...skipping 14 matching lines...) Expand all
148 friend class PropertySetCSSStyleDeclaration; 148 friend class PropertySetCSSStyleDeclaration;
149 }; 149 };
150 150
151 class CORE_EXPORT ImmutableStylePropertySet : public StylePropertySet { 151 class CORE_EXPORT ImmutableStylePropertySet : public StylePropertySet {
152 public: 152 public:
153 ~ImmutableStylePropertySet(); 153 ~ImmutableStylePropertySet();
154 static PassRefPtrWillBeRawPtr<ImmutableStylePropertySet> create(const CSSPro perty* properties, unsigned count, CSSParserMode); 154 static PassRefPtrWillBeRawPtr<ImmutableStylePropertySet> create(const CSSPro perty* properties, unsigned count, CSSParserMode);
155 155
156 unsigned propertyCount() const { return m_arraySize; } 156 unsigned propertyCount() const { return m_arraySize; }
157 157
158 const RawPtrWillBeMember<CSSValue>* valueArray() const; 158 const CSSValue* valueArray() const;
159 const StylePropertyMetadata* metadataArray() const; 159 const StylePropertyMetadata* metadataArray() const;
160 int findPropertyIndex(CSSPropertyID) const; 160 int findPropertyIndex(CSSPropertyID) const;
161 161
162 DECLARE_TRACE_AFTER_DISPATCH(); 162 DECLARE_TRACE_AFTER_DISPATCH();
163 163
164 void* operator new(std::size_t, void* location) 164 void* operator new(std::size_t, void* location)
165 { 165 {
166 return location; 166 return location;
167 } 167 }
168 168
169 void* m_storage; 169 void* m_storage;
170 170
171 private: 171 private:
172 ImmutableStylePropertySet(const CSSProperty*, unsigned count, CSSParserMode) ; 172 ImmutableStylePropertySet(const CSSProperty*, unsigned count, CSSParserMode) ;
173 }; 173 };
174 174
175 inline const RawPtrWillBeMember<CSSValue>* ImmutableStylePropertySet::valueArray () const 175 inline const CSSValue* ImmutableStylePropertySet::valueArray() const
176 { 176 {
177 return reinterpret_cast<const RawPtrWillBeMember<CSSValue>*>(const_cast<cons t void**>(&(this->m_storage))); 177 return reinterpret_cast<const CSSValue*>(const_cast<const void**>(&(this->m_ storage)));
178 } 178 }
179 179
180 inline const StylePropertyMetadata* ImmutableStylePropertySet::metadataArray() c onst 180 inline const StylePropertyMetadata* ImmutableStylePropertySet::metadataArray() c onst
181 { 181 {
182 return reinterpret_cast<const StylePropertyMetadata*>(&reinterpret_cast<cons t char*>(&(this->m_storage))[m_arraySize * sizeof(RawPtrWillBeMember<CSSValue>)] ); 182 return reinterpret_cast<const StylePropertyMetadata*>(&reinterpret_cast<cons t char*>(&(this->m_storage))[m_arraySize * sizeof(CSSValue)]);
183 } 183 }
184 184
185 DEFINE_TYPE_CASTS(ImmutableStylePropertySet, StylePropertySet, set, !set->isMuta ble(), !set.isMutable()); 185 DEFINE_TYPE_CASTS(ImmutableStylePropertySet, StylePropertySet, set, !set->isMuta ble(), !set.isMutable());
186 186
187 class CORE_EXPORT MutableStylePropertySet : public StylePropertySet { 187 class CORE_EXPORT MutableStylePropertySet : public StylePropertySet {
188 public: 188 public:
189 ~MutableStylePropertySet() { } 189 ~MutableStylePropertySet() { }
190 static PassRefPtrWillBeRawPtr<MutableStylePropertySet> create(CSSParserMode = HTMLQuirksMode); 190 static PassRefPtrWillBeRawPtr<MutableStylePropertySet> create(CSSParserMode = HTMLQuirksMode);
191 static PassRefPtrWillBeRawPtr<MutableStylePropertySet> create(const CSSPrope rty* properties, unsigned count); 191 static PassRefPtrWillBeRawPtr<MutableStylePropertySet> create(const CSSPrope rty* properties, unsigned count);
192 192
193 unsigned propertyCount() const { return m_propertyVector.size(); } 193 unsigned propertyCount() const { return m_propertyVector.size(); }
194 194
195 // Returns whether this style set was changed. 195 // Returns whether this style set was changed.
196 bool addParsedProperties(const WillBeHeapVector<CSSProperty, 256>&); 196 bool addParsedProperties(const WillBeHeapVector<CSSProperty, 256>&);
197 bool addRespectingCascade(const CSSProperty&); 197 bool addRespectingCascade(const CSSProperty&);
198 198
199 // These expand shorthand properties into multiple properties. 199 // These expand shorthand properties into multiple properties.
200 bool setProperty(CSSPropertyID unresolvedProperty, const String& value, bool important = false, StyleSheetContents* contextStyleSheet = 0); 200 bool setProperty(CSSPropertyID unresolvedProperty, const String& value, bool important = false, StyleSheetContents* contextStyleSheet = 0);
201 void setProperty(CSSPropertyID, PassRefPtrWillBeRawPtr<CSSValue>, bool impor tant = false); 201 void setProperty(CSSPropertyID, CSSValue, bool important = false);
202 202
203 // These do not. FIXME: This is too messy, we can do better. 203 // These do not. FIXME: This is too messy, we can do better.
204 bool setProperty(CSSPropertyID, CSSValueID identifier, bool important = fals e); 204 bool setProperty(CSSPropertyID, CSSValueID identifier, bool important = fals e);
205 bool setProperty(const CSSProperty&, CSSProperty* slot = 0); 205 bool setProperty(const CSSProperty&, CSSProperty* slot = 0);
206 206
207 bool removeProperty(CSSPropertyID, String* returnText = 0); 207 bool removeProperty(CSSPropertyID, String* returnText = 0);
208 void removeBlockProperties(); 208 void removeBlockProperties();
209 bool removePropertiesInSet(const CSSPropertyID* set, unsigned length); 209 bool removePropertiesInSet(const CSSPropertyID* set, unsigned length);
210 void removeEquivalentProperties(const StylePropertySet*); 210 void removeEquivalentProperties(const StylePropertySet*);
211 void removeEquivalentProperties(const CSSStyleDeclaration*); 211 void removeEquivalentProperties(const CSSStyleDeclaration*);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 return toMutableStylePropertySet(set.get()); 251 return toMutableStylePropertySet(set.get());
252 } 252 }
253 253
254 inline const StylePropertyMetadata& StylePropertySet::PropertyReference::propert yMetadata() const 254 inline const StylePropertyMetadata& StylePropertySet::PropertyReference::propert yMetadata() const
255 { 255 {
256 if (m_propertySet.isMutable()) 256 if (m_propertySet.isMutable())
257 return toMutableStylePropertySet(m_propertySet).m_propertyVector.at(m_in dex).metadata(); 257 return toMutableStylePropertySet(m_propertySet).m_propertyVector.at(m_in dex).metadata();
258 return toImmutableStylePropertySet(m_propertySet).metadataArray()[m_index]; 258 return toImmutableStylePropertySet(m_propertySet).metadataArray()[m_index];
259 } 259 }
260 260
261 inline const CSSValue* StylePropertySet::PropertyReference::propertyValue() cons t 261 inline const CSSValue StylePropertySet::PropertyReference::propertyValue() const
262 { 262 {
263 if (m_propertySet.isMutable()) 263 if (m_propertySet.isMutable())
264 return toMutableStylePropertySet(m_propertySet).m_propertyVector.at(m_in dex).value(); 264 return toMutableStylePropertySet(m_propertySet).m_propertyVector.at(m_in dex).value();
265 return toImmutableStylePropertySet(m_propertySet).valueArray()[m_index]; 265 return toImmutableStylePropertySet(m_propertySet).valueArray()[m_index];
266 } 266 }
267 267
268 inline unsigned StylePropertySet::propertyCount() const 268 inline unsigned StylePropertySet::propertyCount() const
269 { 269 {
270 if (m_isMutable) 270 if (m_isMutable)
271 return toMutableStylePropertySet(this)->m_propertyVector.size(); 271 return toMutableStylePropertySet(this)->m_propertyVector.size();
(...skipping 21 matching lines...) Expand all
293 inline int StylePropertySet::findPropertyIndex(CSSPropertyID propertyID) const 293 inline int StylePropertySet::findPropertyIndex(CSSPropertyID propertyID) const
294 { 294 {
295 if (m_isMutable) 295 if (m_isMutable)
296 return toMutableStylePropertySet(this)->findPropertyIndex(propertyID); 296 return toMutableStylePropertySet(this)->findPropertyIndex(propertyID);
297 return toImmutableStylePropertySet(this)->findPropertyIndex(propertyID); 297 return toImmutableStylePropertySet(this)->findPropertyIndex(propertyID);
298 } 298 }
299 299
300 } // namespace blink 300 } // namespace blink
301 301
302 #endif // StylePropertySet_h 302 #endif // StylePropertySet_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698