Changeset 154249 in webkit
- Timestamp:
- Aug 18, 2013 9:01:28 AM (11 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 2 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/CMakeLists.txt
r154240 r154249 1155 1155 dom/DocumentType.cpp 1156 1156 dom/Element.cpp 1157 dom/ElementData.cpp 1157 1158 dom/ElementRareData.cpp 1158 1159 dom/EntityReference.cpp -
trunk/Source/WebCore/ChangeLog
r154248 r154249 1 2013-08-18 Andreas Kling <akling@apple.com> 2 3 <https://webkit.org/b/119981> Move ElementData & co to their own files. 4 5 Reviewed by Antti Koivisto. 6 7 I like to move it move it. 8 1 9 2013-08-18 David Kilzer <ddkilzer@apple.com> 2 10 -
trunk/Source/WebCore/GNUmakefile.list.am
r154240 r154249 2869 2869 Source/WebCore/dom/Element.cpp \ 2870 2870 Source/WebCore/dom/Element.h \ 2871 Source/WebCore/dom/ElementData.cpp \ 2872 Source/WebCore/dom/ElementData.h \ 2871 2873 Source/WebCore/dom/ElementRareData.cpp \ 2872 2874 Source/WebCore/dom/ElementRareData.h \ -
trunk/Source/WebCore/Target.pri
r154240 r154249 401 401 dom/DatasetDOMStringMap.cpp \ 402 402 dom/Element.cpp \ 403 dom/ElementData.cpp \ 403 404 dom/ElementRareData.cpp \ 404 405 dom/EntityReference.cpp \ … … 1611 1612 dom/DatasetDOMStringMap.h \ 1612 1613 dom/Element.h \ 1614 dom/ElementData.h \ 1613 1615 dom/ElementTravesal.h \ 1614 1616 dom/Entity.h \ -
trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj
r154240 r154249 12501 12501 <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Production|x64'">true</ExcludedFromBuild> 12502 12502 </ClCompile> 12503 <ClCompile Include="..\dom\ElementData.cpp" /> 12503 12504 <ClCompile Include="..\dom\ElementRareData.cpp" /> 12504 12505 <ClCompile Include="..\dom\EntityReference.cpp"> … … 20245 20246 <ClInclude Include="..\dom\DOMTimeStamp.h" /> 20246 20247 <ClInclude Include="..\dom\Element.h" /> 20248 <ClInclude Include="..\dom\ElementData.h" /> 20247 20249 <ClInclude Include="..\dom\ElementTraversal.h" /> 20248 20250 <ClInclude Include="..\dom\Entity.h" /> -
trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj
r154240 r154249 4525 4525 B5A684220FFABE9800D24689 /* SQLiteFileSystem.h in Headers */ = {isa = PBXBuildFile; fileRef = B5A684210FFABE9800D24689 /* SQLiteFileSystem.h */; }; 4526 4526 B5A684240FFABEAA00D24689 /* SQLiteFileSystem.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B5A684230FFABEAA00D24689 /* SQLiteFileSystem.cpp */; }; 4527 B5B7A17017C10AA800E4AA0A /* ElementData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B5B7A16F17C1080600E4AA0A /* ElementData.cpp */; }; 4528 B5B7A17117C10AC000E4AA0A /* ElementData.h in Headers */ = {isa = PBXBuildFile; fileRef = B5B7A16E17C1048000E4AA0A /* ElementData.h */; settings = {ATTRIBUTES = (Private, ); }; }; 4527 4529 B5D31DFA11CF610B009F22B4 /* ActiveDOMCallback.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B5D31DF811CF610B009F22B4 /* ActiveDOMCallback.cpp */; }; 4528 4530 B5D31DFB11CF610B009F22B4 /* ActiveDOMCallback.h in Headers */ = {isa = PBXBuildFile; fileRef = B5D31DF911CF610B009F22B4 /* ActiveDOMCallback.h */; }; … … 11173 11175 B5A684210FFABE9800D24689 /* SQLiteFileSystem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SQLiteFileSystem.h; path = sql/SQLiteFileSystem.h; sourceTree = "<group>"; }; 11174 11176 B5A684230FFABEAA00D24689 /* SQLiteFileSystem.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SQLiteFileSystem.cpp; path = sql/SQLiteFileSystem.cpp; sourceTree = "<group>"; }; 11177 B5B7A16E17C1048000E4AA0A /* ElementData.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ElementData.h; sourceTree = "<group>"; }; 11178 B5B7A16F17C1080600E4AA0A /* ElementData.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = ElementData.cpp; sourceTree = "<group>"; }; 11175 11179 B5D31DF811CF610B009F22B4 /* ActiveDOMCallback.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ActiveDOMCallback.cpp; path = generic/ActiveDOMCallback.cpp; sourceTree = "<group>"; }; 11176 11180 B5D31DF911CF610B009F22B4 /* ActiveDOMCallback.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ActiveDOMCallback.h; path = generic/ActiveDOMCallback.h; sourceTree = "<group>"; }; … … 20223 20227 A8C4A7F509D563270003AC8D /* Element.h */, 20224 20228 93EEC1EA09C2877700C515D1 /* Element.idl */, 20229 B5B7A16F17C1080600E4AA0A /* ElementData.cpp */, 20230 B5B7A16E17C1048000E4AA0A /* ElementData.h */, 20225 20231 4FAB48641643A66D00F70C07 /* ElementRareData.cpp */, 20226 20232 637B7ADE0E8767B800E32194 /* ElementRareData.h */, … … 23473 23479 B22279AE0D00BF220071B782 /* SVGDefsElement.h in Headers */, 23474 23480 B22279B10D00BF220071B782 /* SVGDescElement.h in Headers */, 23481 B5B7A17117C10AC000E4AA0A /* ElementData.h in Headers */, 23475 23482 B22279B40D00BF220071B782 /* SVGDocument.h in Headers */, 23476 23483 B28C6A280D00C44800334AA4 /* SVGDocumentExtensions.h in Headers */, … … 26225 26232 A43BF59C1149292800C643CA /* RenderProgress.cpp in Sources */, 26226 26233 5A574F24131DB93900471B88 /* RenderQuote.cpp in Sources */, 26234 B5B7A17017C10AA800E4AA0A /* ElementData.cpp in Sources */, 26227 26235 D70AD65713E1342B005B50B4 /* RenderRegion.cpp in Sources */, 26228 26236 BCE93F471517C6D5008CCF74 /* RenderRegionSet.cpp in Sources */, -
trunk/Source/WebCore/dom/Element.cpp
r154201 r154249 3194 3194 #endif 3195 3195 3196 void ElementData::deref()3197 {3198 if (!derefBase())3199 return;3200 3201 if (m_isUnique)3202 delete static_cast<UniqueElementData*>(this);3203 else3204 delete static_cast<ShareableElementData*>(this);3205 }3206 3207 ElementData::ElementData()3208 : m_isUnique(true)3209 , m_arraySize(0)3210 , m_hasNameAttribute(false)3211 , m_presentationAttributeStyleIsDirty(false)3212 , m_styleAttributeIsDirty(false)3213 #if ENABLE(SVG)3214 , m_animatedSVGAttributesAreDirty(false)3215 #endif3216 {3217 }3218 3219 ElementData::ElementData(unsigned arraySize)3220 : m_isUnique(false)3221 , m_arraySize(arraySize)3222 , m_hasNameAttribute(false)3223 , m_presentationAttributeStyleIsDirty(false)3224 , m_styleAttributeIsDirty(false)3225 #if ENABLE(SVG)3226 , m_animatedSVGAttributesAreDirty(false)3227 #endif3228 {3229 }3230 3231 struct SameSizeAsElementData : public RefCounted<SameSizeAsElementData> {3232 unsigned bitfield;3233 void* refPtrs[3];3234 };3235 3236 COMPILE_ASSERT(sizeof(ElementData) == sizeof(SameSizeAsElementData), element_attribute_data_should_stay_small);3237 3238 static size_t sizeForShareableElementDataWithAttributeCount(unsigned count)3239 {3240 return sizeof(ShareableElementData) + sizeof(Attribute) * count;3241 }3242 3243 PassRefPtr<ShareableElementData> ShareableElementData::createWithAttributes(const Vector<Attribute>& attributes)3244 {3245 void* slot = WTF::fastMalloc(sizeForShareableElementDataWithAttributeCount(attributes.size()));3246 return adoptRef(new (NotNull, slot) ShareableElementData(attributes));3247 }3248 3249 PassRefPtr<UniqueElementData> UniqueElementData::create()3250 {3251 return adoptRef(new UniqueElementData);3252 }3253 3254 ShareableElementData::ShareableElementData(const Vector<Attribute>& attributes)3255 : ElementData(attributes.size())3256 {3257 for (unsigned i = 0; i < m_arraySize; ++i)3258 new (NotNull, &m_attributeArray[i]) Attribute(attributes[i]);3259 }3260 3261 ShareableElementData::~ShareableElementData()3262 {3263 for (unsigned i = 0; i < m_arraySize; ++i)3264 m_attributeArray[i].~Attribute();3265 }3266 3267 ShareableElementData::ShareableElementData(const UniqueElementData& other)3268 : ElementData(other, false)3269 {3270 ASSERT(!other.m_presentationAttributeStyle);3271 3272 if (other.m_inlineStyle) {3273 ASSERT(!other.m_inlineStyle->hasCSSOMWrapper());3274 m_inlineStyle = other.m_inlineStyle->immutableCopyIfNeeded();3275 }3276 3277 for (unsigned i = 0; i < m_arraySize; ++i)3278 new (NotNull, &m_attributeArray[i]) Attribute(other.m_attributeVector.at(i));3279 }3280 3281 ElementData::ElementData(const ElementData& other, bool isUnique)3282 : m_isUnique(isUnique)3283 , m_arraySize(isUnique ? 0 : other.length())3284 , m_hasNameAttribute(other.m_hasNameAttribute)3285 , m_presentationAttributeStyleIsDirty(other.m_presentationAttributeStyleIsDirty)3286 , m_styleAttributeIsDirty(other.m_styleAttributeIsDirty)3287 #if ENABLE(SVG)3288 , m_animatedSVGAttributesAreDirty(other.m_animatedSVGAttributesAreDirty)3289 #endif3290 , m_classNames(other.m_classNames)3291 , m_idForStyleResolution(other.m_idForStyleResolution)3292 {3293 // NOTE: The inline style is copied by the subclass copy constructor since we don't know what to do with it here.3294 }3295 3296 UniqueElementData::UniqueElementData()3297 {3298 }3299 3300 UniqueElementData::UniqueElementData(const UniqueElementData& other)3301 : ElementData(other, true)3302 , m_presentationAttributeStyle(other.m_presentationAttributeStyle)3303 , m_attributeVector(other.m_attributeVector)3304 {3305 m_inlineStyle = other.m_inlineStyle ? other.m_inlineStyle->mutableCopy() : 0;3306 }3307 3308 UniqueElementData::UniqueElementData(const ShareableElementData& other)3309 : ElementData(other, true)3310 {3311 // An ShareableElementData should never have a mutable inline StylePropertySet attached.3312 ASSERT(!other.m_inlineStyle || !other.m_inlineStyle->isMutable());3313 m_inlineStyle = other.m_inlineStyle;3314 3315 m_attributeVector.reserveCapacity(other.length());3316 for (unsigned i = 0; i < other.length(); ++i)3317 m_attributeVector.uncheckedAppend(other.m_attributeArray[i]);3318 }3319 3320 PassRefPtr<UniqueElementData> ElementData::makeUniqueCopy() const3321 {3322 if (isUnique())3323 return adoptRef(new UniqueElementData(static_cast<const UniqueElementData&>(*this)));3324 return adoptRef(new UniqueElementData(static_cast<const ShareableElementData&>(*this)));3325 }3326 3327 PassRefPtr<ShareableElementData> UniqueElementData::makeShareableCopy() const3328 {3329 void* slot = WTF::fastMalloc(sizeForShareableElementDataWithAttributeCount(m_attributeVector.size()));3330 return adoptRef(new (NotNull, slot) ShareableElementData(*this));3331 }3332 3333 void UniqueElementData::addAttribute(const QualifiedName& attributeName, const AtomicString& value)3334 {3335 m_attributeVector.append(Attribute(attributeName, value));3336 }3337 3338 void UniqueElementData::removeAttribute(unsigned index)3339 {3340 ASSERT_WITH_SECURITY_IMPLICATION(index < length());3341 m_attributeVector.remove(index);3342 }3343 3344 bool ElementData::isEquivalent(const ElementData* other) const3345 {3346 if (!other)3347 return isEmpty();3348 3349 unsigned len = length();3350 if (len != other->length())3351 return false;3352 3353 for (unsigned i = 0; i < len; i++) {3354 const Attribute& attribute = attributeAt(i);3355 const Attribute* otherAttr = other->findAttributeByName(attribute.name());3356 if (!otherAttr || attribute.value() != otherAttr->value())3357 return false;3358 }3359 3360 return true;3361 }3362 3363 unsigned ElementData::findAttributeIndexByNameSlowCase(const AtomicString& name, bool shouldIgnoreAttributeCase) const3364 {3365 // Continue to checking case-insensitively and/or full namespaced names if necessary:3366 for (unsigned i = 0; i < length(); ++i) {3367 const Attribute& attribute = attributeAt(i);3368 if (!attribute.name().hasPrefix()) {3369 if (shouldIgnoreAttributeCase && equalIgnoringCase(name, attribute.localName()))3370 return i;3371 } else {3372 // FIXME: Would be faster to do this comparison without calling toString, which3373 // generates a temporary string by concatenation. But this branch is only reached3374 // if the attribute name has a prefix, which is rare in HTML.3375 if (equalPossiblyIgnoringCase(name, attribute.name().toString(), shouldIgnoreAttributeCase))3376 return i;3377 }3378 }3379 return attributeNotFound;3380 }3381 3382 unsigned ElementData::findAttributeIndexByNameForAttributeNode(const Attr* attr, bool shouldIgnoreAttributeCase) const3383 {3384 ASSERT(attr);3385 const Attribute* attributes = attributeBase();3386 unsigned count = length();3387 for (unsigned i = 0; i < count; ++i) {3388 if (attributes[i].name().matchesIgnoringCaseForLocalName(attr->qualifiedName(), shouldIgnoreAttributeCase))3389 return i;3390 }3391 return attributeNotFound;3392 }3393 3394 Attribute* UniqueElementData::findAttributeByName(const QualifiedName& name)3395 {3396 unsigned count = length();3397 for (unsigned i = 0; i < count; ++i) {3398 if (m_attributeVector.at(i).name().matches(name))3399 return &m_attributeVector.at(i);3400 }3401 return 0;3402 }3403 3404 Attribute& UniqueElementData::attributeAt(unsigned index)3405 {3406 ASSERT_WITH_SECURITY_IMPLICATION(index < length());3407 return m_attributeVector.at(index);3408 }3409 3410 3196 } // namespace WebCore -
trunk/Source/WebCore/dom/Element.h
r154165 r154249 26 26 #define Element_h 27 27 28 #include "Attribute.h"29 28 #include "CollectionType.h" 30 29 #include "Document.h" 30 #include "ElementData.h" 31 31 #include "HTMLNames.h" 32 32 #include "RegionOversetState.h" 33 33 #include "ScrollTypes.h" 34 #include "SpaceSplitString.h"35 34 #include "StyleResolveTree.h" 36 35 37 36 namespace WebCore { 38 37 39 class Attr;40 38 class ClientRect; 41 39 class ClientRectList; 42 40 class DOMStringMap; 43 41 class DOMTokenList; 44 class Element;45 42 class ElementRareData; 46 43 class HTMLDocument; 47 class ShareableElementData;48 44 class IntSize; 49 45 class Locale; 50 class UniqueElementData;51 46 class PseudoElement; 52 47 class RenderRegion; 53 48 class ShadowRoot; 54 class StylePropertySet;55 56 class ElementData : public RefCounted<ElementData> {57 WTF_MAKE_FAST_ALLOCATED;58 public:59 // Override RefCounted's deref() to ensure operator delete is called on60 // the appropriate subclass type.61 void deref();62 63 static const unsigned attributeNotFound = static_cast<unsigned>(-1);64 65 void clearClass() const { m_classNames.clear(); }66 void setClass(const AtomicString& className, bool shouldFoldCase) const { m_classNames.set(className, shouldFoldCase); }67 const SpaceSplitString& classNames() const { return m_classNames; }68 69 const AtomicString& idForStyleResolution() const { return m_idForStyleResolution; }70 void setIdForStyleResolution(const AtomicString& newId) const { m_idForStyleResolution = newId; }71 72 const StylePropertySet* inlineStyle() const { return m_inlineStyle.get(); }73 74 const StylePropertySet* presentationAttributeStyle() const;75 76 unsigned length() const;77 bool isEmpty() const { return !length(); }78 79 const Attribute& attributeAt(unsigned index) const;80 const Attribute* findAttributeByName(const QualifiedName&) const;81 unsigned findAttributeIndexByName(const QualifiedName&) const;82 unsigned findAttributeIndexByName(const AtomicString& name, bool shouldIgnoreAttributeCase) const;83 unsigned findAttributeIndexByNameForAttributeNode(const Attr*, bool shouldIgnoreAttributeCase = false) const;84 85 bool hasID() const { return !m_idForStyleResolution.isNull(); }86 bool hasClass() const { return !m_classNames.isNull(); }87 bool hasName() const { return m_hasNameAttribute; }88 89 bool isEquivalent(const ElementData* other) const;90 91 bool isUnique() const { return m_isUnique; }92 93 protected:94 ElementData();95 ElementData(unsigned arraySize);96 ElementData(const ElementData&, bool isUnique);97 98 unsigned m_isUnique : 1;99 unsigned m_arraySize : 27;100 mutable unsigned m_hasNameAttribute : 1;101 mutable unsigned m_presentationAttributeStyleIsDirty : 1;102 mutable unsigned m_styleAttributeIsDirty : 1;103 #if ENABLE(SVG)104 mutable unsigned m_animatedSVGAttributesAreDirty : 1;105 #endif106 107 mutable RefPtr<StylePropertySet> m_inlineStyle;108 mutable SpaceSplitString m_classNames;109 mutable AtomicString m_idForStyleResolution;110 111 private:112 friend class Element;113 friend class StyledElement;114 friend class ShareableElementData;115 friend class UniqueElementData;116 #if ENABLE(SVG)117 friend class SVGElement;118 #endif119 120 const Attribute* attributeBase() const;121 const Attribute* findAttributeByName(const AtomicString& name, bool shouldIgnoreAttributeCase) const;122 unsigned findAttributeIndexByNameSlowCase(const AtomicString& name, bool shouldIgnoreAttributeCase) const;123 124 PassRefPtr<UniqueElementData> makeUniqueCopy() const;125 };126 127 #if COMPILER(MSVC)128 #pragma warning(push)129 #pragma warning(disable: 4200) // Disable "zero-sized array in struct/union" warning130 #endif131 132 class ShareableElementData : public ElementData {133 public:134 static PassRefPtr<ShareableElementData> createWithAttributes(const Vector<Attribute>&);135 136 explicit ShareableElementData(const Vector<Attribute>&);137 explicit ShareableElementData(const UniqueElementData&);138 ~ShareableElementData();139 140 Attribute m_attributeArray[0];141 };142 143 #if COMPILER(MSVC)144 #pragma warning(pop)145 #endif146 147 class UniqueElementData : public ElementData {148 public:149 static PassRefPtr<UniqueElementData> create();150 PassRefPtr<ShareableElementData> makeShareableCopy() const;151 152 // These functions do no error/duplicate checking.153 void addAttribute(const QualifiedName&, const AtomicString&);154 void removeAttribute(unsigned index);155 156 Attribute& attributeAt(unsigned index);157 Attribute* findAttributeByName(const QualifiedName&);158 159 UniqueElementData();160 explicit UniqueElementData(const ShareableElementData&);161 explicit UniqueElementData(const UniqueElementData&);162 163 mutable RefPtr<StylePropertySet> m_presentationAttributeStyle;164 Vector<Attribute, 4> m_attributeVector;165 };166 49 167 50 enum AffectedSelectorType { … … 948 831 } 949 832 950 inline unsigned ElementData::length() const951 {952 if (isUnique())953 return static_cast<const UniqueElementData*>(this)->m_attributeVector.size();954 return m_arraySize;955 }956 957 inline const Attribute* ElementData::attributeBase() const958 {959 if (m_isUnique)960 return static_cast<const UniqueElementData*>(this)->m_attributeVector.data();961 return static_cast<const ShareableElementData*>(this)->m_attributeArray;962 }963 964 inline const StylePropertySet* ElementData::presentationAttributeStyle() const965 {966 if (!m_isUnique)967 return 0;968 return static_cast<const UniqueElementData*>(this)->m_presentationAttributeStyle.get();969 }970 971 inline const Attribute* ElementData::findAttributeByName(const AtomicString& name, bool shouldIgnoreAttributeCase) const972 {973 unsigned index = findAttributeIndexByName(name, shouldIgnoreAttributeCase);974 if (index != attributeNotFound)975 return &attributeAt(index);976 return 0;977 }978 979 inline unsigned ElementData::findAttributeIndexByName(const QualifiedName& name) const980 {981 const Attribute* attributes = attributeBase();982 for (unsigned i = 0, count = length(); i < count; ++i) {983 if (attributes[i].name().matches(name))984 return i;985 }986 return attributeNotFound;987 }988 989 // We use a boolean parameter instead of calling shouldIgnoreAttributeCase so that the caller990 // can tune the behavior (hasAttribute is case sensitive whereas getAttribute is not).991 inline unsigned ElementData::findAttributeIndexByName(const AtomicString& name, bool shouldIgnoreAttributeCase) const992 {993 const Attribute* attributes = attributeBase();994 bool doSlowCheck = shouldIgnoreAttributeCase;995 const AtomicString& caseAdjustedName = shouldIgnoreAttributeCase ? name.lower() : name;996 997 // Optimize for the case where the attribute exists and its name exactly matches.998 for (unsigned i = 0, count = length(); i < count; ++i) {999 if (!attributes[i].name().hasPrefix()) {1000 if (caseAdjustedName == attributes[i].localName())1001 return i;1002 } else1003 doSlowCheck = true;1004 }1005 1006 if (doSlowCheck)1007 return findAttributeIndexByNameSlowCase(name, shouldIgnoreAttributeCase);1008 return attributeNotFound;1009 }1010 1011 inline const Attribute* ElementData::findAttributeByName(const QualifiedName& name) const1012 {1013 const Attribute* attributes = attributeBase();1014 for (unsigned i = 0, count = length(); i < count; ++i) {1015 if (attributes[i].name().matches(name))1016 return &attributes[i];1017 }1018 return 0;1019 }1020 1021 inline const Attribute& ElementData::attributeAt(unsigned index) const1022 {1023 RELEASE_ASSERT(index < length());1024 return attributeBase()[index];1025 }1026 1027 833 } // namespace 1028 834
Note: See TracChangeset
for help on using the changeset viewer.