OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) | 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
4 * (C) 2001 Peter Kelly (pmk@post.com) | 4 * (C) 2001 Peter Kelly (pmk@post.com) |
5 * (C) 2001 Dirk Mueller (mueller@kde.org) | 5 * (C) 2001 Dirk Mueller (mueller@kde.org) |
6 * (C) 2007 David Smith (catfish.man@gmail.com) | 6 * (C) 2007 David Smith (catfish.man@gmail.com) |
7 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012, 2013 Apple Inc. All rights reserved. | 7 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012, 2013 Apple Inc. All rights reserved. |
8 * (C) 2007 Eric Seidel (eric@webkit.org) | 8 * (C) 2007 Eric Seidel (eric@webkit.org) |
9 * | 9 * |
10 * This library is free software; you can redistribute it and/or | 10 * This library is free software; you can redistribute it and/or |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
107 #include "wtf/text/CString.h" | 107 #include "wtf/text/CString.h" |
108 #include "wtf/text/StringBuilder.h" | 108 #include "wtf/text/StringBuilder.h" |
109 #include "wtf/text/TextPosition.h" | 109 #include "wtf/text/TextPosition.h" |
110 | 110 |
111 namespace WebCore { | 111 namespace WebCore { |
112 | 112 |
113 using namespace HTMLNames; | 113 using namespace HTMLNames; |
114 using namespace XMLNames; | 114 using namespace XMLNames; |
115 | 115 |
116 typedef WillBeHeapVector<RefPtrWillBeMember<Attr> > AttrNodeList; | 116 typedef WillBeHeapVector<RefPtrWillBeMember<Attr> > AttrNodeList; |
117 typedef WillBePersistentHeapHashMap<RawPtrWillBeWeakMember<Element>, OwnPtrWillB eMember<AttrNodeList> > AttrNodeListMap; | |
118 | |
119 static AttrNodeListMap& attrNodeListMap() | |
120 { | |
121 DEFINE_STATIC_LOCAL(AttrNodeListMap, map, ()); | |
122 return map; | |
123 } | |
124 | |
125 static AttrNodeList* attrNodeListForElement(Element* element) | |
126 { | |
127 if (!element->hasSyntheticAttrChildNodes()) | |
128 return 0; | |
129 ASSERT(attrNodeListMap().contains(element)); | |
130 return attrNodeListMap().get(element); | |
131 } | |
132 | |
133 static AttrNodeList& ensureAttrNodeListForElement(Element* element) | |
134 { | |
135 if (element->hasSyntheticAttrChildNodes()) { | |
136 ASSERT(attrNodeListMap().contains(element)); | |
137 return *attrNodeListMap().get(element); | |
138 } | |
139 ASSERT(!attrNodeListMap().contains(element)); | |
140 element->setHasSyntheticAttrChildNodes(true); | |
141 AttrNodeListMap::AddResult result = attrNodeListMap().add(element, adoptPtrW illBeNoop(new AttrNodeList)); | |
142 return *result.storedValue->value; | |
143 } | |
144 | |
145 static void removeAttrNodeListForElement(Element* element) | |
146 { | |
147 ASSERT(element->hasSyntheticAttrChildNodes()); | |
148 ASSERT(attrNodeListMap().contains(element)); | |
149 attrNodeListMap().remove(element); | |
150 element->setHasSyntheticAttrChildNodes(false); | |
151 } | |
152 | 117 |
153 static Attr* findAttrNodeInList(const AttrNodeList& attrNodeList, const Qualifie dName& name) | 118 static Attr* findAttrNodeInList(const AttrNodeList& attrNodeList, const Qualifie dName& name) |
154 { | 119 { |
155 AttrNodeList::const_iterator end = attrNodeList.end(); | 120 AttrNodeList::const_iterator end = attrNodeList.end(); |
156 for (AttrNodeList::const_iterator it = attrNodeList.begin(); it != end; ++it ) { | 121 for (AttrNodeList::const_iterator it = attrNodeList.begin(); it != end; ++it ) { |
157 if ((*it)->qualifiedName() == name) | 122 if ((*it)->qualifiedName() == name) |
158 return it->get(); | 123 return it->get(); |
159 } | 124 } |
160 return 0; | 125 return 0; |
161 } | 126 } |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
347 void Element::setBooleanAttribute(const QualifiedName& name, bool value) | 312 void Element::setBooleanAttribute(const QualifiedName& name, bool value) |
348 { | 313 { |
349 if (value) | 314 if (value) |
350 setAttribute(name, emptyAtom); | 315 setAttribute(name, emptyAtom); |
351 else | 316 else |
352 removeAttribute(name); | 317 removeAttribute(name); |
353 } | 318 } |
354 | 319 |
355 NamedNodeMap* Element::attributes() const | 320 NamedNodeMap* Element::attributes() const |
356 { | 321 { |
357 ElementRareData& rareData = const_cast<Element*>(this)->ensureElementRareDat a(); | 322 AttrData& attrData = const_cast<Element*>(this)->ensureElementRareData().ens ureAttrData(); |
358 if (NamedNodeMap* attributeMap = rareData.attributeMap()) | 323 if (NamedNodeMap* attributeMap = attrData.attributeMap()) |
359 return attributeMap; | 324 return attributeMap; |
360 | 325 |
361 rareData.setAttributeMap(NamedNodeMap::create(const_cast<Element*>(this))); | 326 attrData.setAttributeMap(NamedNodeMap::create(const_cast<Element*>(this))); |
362 return rareData.attributeMap(); | 327 return attrData.attributeMap(); |
363 } | 328 } |
364 | 329 |
365 ActiveAnimations* Element::activeAnimations() const | 330 ActiveAnimations* Element::activeAnimations() const |
366 { | 331 { |
367 if (hasRareData()) | 332 if (hasRareData()) |
368 return elementRareData()->activeAnimations(); | 333 return elementRareData()->activeAnimations(); |
369 return 0; | 334 return 0; |
370 } | 335 } |
371 | 336 |
372 ActiveAnimations& Element::ensureActiveAnimations() | 337 ActiveAnimations& Element::ensureActiveAnimations() |
(...skipping 1485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1858 if (result.length() > 0) | 1823 if (result.length() > 0) |
1859 result.appendLiteral("; "); | 1824 result.appendLiteral("; "); |
1860 result.appendLiteral("class="); | 1825 result.appendLiteral("class="); |
1861 result.append(s); | 1826 result.append(s); |
1862 } | 1827 } |
1863 | 1828 |
1864 strncpy(buffer, result.toString().utf8().data(), length - 1); | 1829 strncpy(buffer, result.toString().utf8().data(), length - 1); |
1865 } | 1830 } |
1866 #endif | 1831 #endif |
1867 | 1832 |
1868 const WillBeHeapVector<RefPtrWillBeMember<Attr> >& Element::attrNodeList() | 1833 WillBeHeapVector<RefPtrWillBeMember<Attr> >* Element::attrNodeList() |
1834 { | |
1835 return hasRareData() && elementRareData()->attrData() ? elementRareData()->a ttrData()->attrNodeList() : 0; | |
esprehn
2014/06/17 08:27:05
This would be better as:
if (!hasRareData())
re
| |
1836 } | |
1837 | |
1838 WillBeHeapVector<RefPtrWillBeMember<Attr> >& Element::ensureAttrNodeList() | |
1839 { | |
1840 setHasSyntheticAttrChildNodes(true); | |
esprehn
2014/06/17 08:27:05
You can remove this bitfield now. hasSyntheticAttr
| |
1841 return ensureElementRareData().ensureAttrData().ensureAttrNodeList(); | |
1842 } | |
1843 | |
1844 void Element::removeAttrNodeList() | |
1869 { | 1845 { |
1870 ASSERT(hasSyntheticAttrChildNodes()); | 1846 ASSERT(hasSyntheticAttrChildNodes()); |
1871 return *attrNodeListForElement(this); | 1847 if (hasRareData() && elementRareData()->attrData()) |
1848 elementRareData()->attrData()->removeAttrNodeList(); | |
1849 setHasSyntheticAttrChildNodes(false); | |
1872 } | 1850 } |
1873 | 1851 |
1874 PassRefPtrWillBeRawPtr<Attr> Element::setAttributeNode(Attr* attrNode, Exception State& exceptionState) | 1852 PassRefPtrWillBeRawPtr<Attr> Element::setAttributeNode(Attr* attrNode, Exception State& exceptionState) |
1875 { | 1853 { |
1876 if (!attrNode) { | 1854 if (!attrNode) { |
1877 exceptionState.throwDOMException(TypeMismatchError, ExceptionMessages::a rgumentNullOrIncorrectType(1, "Attr")); | 1855 exceptionState.throwDOMException(TypeMismatchError, ExceptionMessages::a rgumentNullOrIncorrectType(1, "Attr")); |
1878 return nullptr; | 1856 return nullptr; |
1879 } | 1857 } |
1880 | 1858 |
1881 RefPtrWillBeRawPtr<Attr> oldAttrNode = attrIfExists(attrNode->qualifiedName( )); | 1859 RefPtrWillBeRawPtr<Attr> oldAttrNode = attrIfExists(attrNode->qualifiedName( )); |
(...skipping 30 matching lines...) Expand all Loading... | |
1912 // all but Gecko (and, arguably, the DOM Level1 spec text.) | 1890 // all but Gecko (and, arguably, the DOM Level1 spec text.) |
1913 // Consider switching. | 1891 // Consider switching. |
1914 oldAttrNode = Attr::create(document(), attrNode->qualifiedName(), at tr.value()); | 1892 oldAttrNode = Attr::create(document(), attrNode->qualifiedName(), at tr.value()); |
1915 } | 1893 } |
1916 } | 1894 } |
1917 | 1895 |
1918 setAttributeInternal(index, attrNode->qualifiedName(), attrNode->value(), No tInSynchronizationOfLazyAttribute); | 1896 setAttributeInternal(index, attrNode->qualifiedName(), attrNode->value(), No tInSynchronizationOfLazyAttribute); |
1919 | 1897 |
1920 attrNode->attachToElement(this, localName); | 1898 attrNode->attachToElement(this, localName); |
1921 treeScope().adoptIfNeeded(*attrNode); | 1899 treeScope().adoptIfNeeded(*attrNode); |
1922 ensureAttrNodeListForElement(this).append(attrNode); | 1900 ensureAttrNodeList().append(attrNode); |
1923 | 1901 |
1924 return oldAttrNode.release(); | 1902 return oldAttrNode.release(); |
1925 } | 1903 } |
1926 | 1904 |
1927 PassRefPtrWillBeRawPtr<Attr> Element::setAttributeNodeNS(Attr* attr, ExceptionSt ate& exceptionState) | 1905 PassRefPtrWillBeRawPtr<Attr> Element::setAttributeNodeNS(Attr* attr, ExceptionSt ate& exceptionState) |
1928 { | 1906 { |
1929 return setAttributeNode(attr, exceptionState); | 1907 return setAttributeNode(attr, exceptionState); |
1930 } | 1908 } |
1931 | 1909 |
1932 PassRefPtrWillBeRawPtr<Attr> Element::removeAttributeNode(Attr* attr, ExceptionS tate& exceptionState) | 1910 PassRefPtrWillBeRawPtr<Attr> Element::removeAttributeNode(Attr* attr, ExceptionS tate& exceptionState) |
(...skipping 830 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2763 if (isSVGElement()) | 2741 if (isSVGElement()) |
2764 return !toSVGElement(this)->isAnimatableAttribute(name); | 2742 return !toSVGElement(this)->isAnimatableAttribute(name); |
2765 | 2743 |
2766 return true; | 2744 return true; |
2767 } | 2745 } |
2768 #endif | 2746 #endif |
2769 | 2747 |
2770 #ifdef DUMP_NODE_STATISTICS | 2748 #ifdef DUMP_NODE_STATISTICS |
2771 bool Element::hasNamedNodeMap() const | 2749 bool Element::hasNamedNodeMap() const |
2772 { | 2750 { |
2773 return hasRareData() && elementRareData()->attributeMap(); | 2751 return hasRareData() && elementRareData()->attrData() && elementRareData()-> attrData()->attributeMap(); |
esprehn
2014/06/17 08:27:05
ditto
| |
2774 } | 2752 } |
2775 #endif | 2753 #endif |
2776 | 2754 |
2777 inline void Element::updateName(const AtomicString& oldName, const AtomicString& newName) | 2755 inline void Element::updateName(const AtomicString& oldName, const AtomicString& newName) |
2778 { | 2756 { |
2779 if (!inDocument() || isInShadowTree()) | 2757 if (!inDocument() || isInShadowTree()) |
2780 return; | 2758 return; |
2781 | 2759 |
2782 if (oldName == newName) | 2760 if (oldName == newName) |
2783 return; | 2761 return; |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2978 | 2956 |
2979 void Element::setSavedLayerScrollOffset(const IntSize& size) | 2957 void Element::setSavedLayerScrollOffset(const IntSize& size) |
2980 { | 2958 { |
2981 if (size.isZero() && !hasRareData()) | 2959 if (size.isZero() && !hasRareData()) |
2982 return; | 2960 return; |
2983 ensureElementRareData().setSavedLayerScrollOffset(size); | 2961 ensureElementRareData().setSavedLayerScrollOffset(size); |
2984 } | 2962 } |
2985 | 2963 |
2986 PassRefPtrWillBeRawPtr<Attr> Element::attrIfExists(const QualifiedName& name) | 2964 PassRefPtrWillBeRawPtr<Attr> Element::attrIfExists(const QualifiedName& name) |
2987 { | 2965 { |
2988 if (AttrNodeList* attrNodeList = attrNodeListForElement(this)) | 2966 if (AttrNodeList* attrNodeList = this->attrNodeList()) |
haraken
2014/06/17 02:07:02
Rename the |attrNodeList| variable to something el
esprehn
2014/06/17 08:27:05
list = ...
| |
2989 return findAttrNodeInList(*attrNodeList, name); | 2967 return findAttrNodeInList(*attrNodeList, name); |
2990 return nullptr; | 2968 return nullptr; |
2991 } | 2969 } |
2992 | 2970 |
2993 PassRefPtrWillBeRawPtr<Attr> Element::ensureAttr(const QualifiedName& name) | 2971 PassRefPtrWillBeRawPtr<Attr> Element::ensureAttr(const QualifiedName& name) |
2994 { | 2972 { |
2995 AttrNodeList& attrNodeList = ensureAttrNodeListForElement(this); | 2973 AttrNodeList& attrNodeList = ensureAttrNodeList(); |
2996 RefPtrWillBeRawPtr<Attr> attrNode = findAttrNodeInList(attrNodeList, name); | 2974 RefPtrWillBeRawPtr<Attr> attrNode = findAttrNodeInList(attrNodeList, name); |
2997 if (!attrNode) { | 2975 if (!attrNode) { |
2998 attrNode = Attr::create(*this, name); | 2976 attrNode = Attr::create(*this, name); |
2999 treeScope().adoptIfNeeded(*attrNode); | 2977 treeScope().adoptIfNeeded(*attrNode); |
3000 attrNodeList.append(attrNode); | 2978 attrNodeList.append(attrNode); |
3001 } | 2979 } |
3002 return attrNode.release(); | 2980 return attrNode.release(); |
3003 } | 2981 } |
3004 | 2982 |
3005 void Element::detachAttrNodeFromElementWithValue(Attr* attrNode, const AtomicStr ing& value) | 2983 void Element::detachAttrNodeFromElementWithValue(Attr* attrNode, const AtomicStr ing& value) |
3006 { | 2984 { |
3007 ASSERT(hasSyntheticAttrChildNodes()); | 2985 ASSERT(hasSyntheticAttrChildNodes()); |
3008 attrNode->detachFromElementWithValue(value); | 2986 attrNode->detachFromElementWithValue(value); |
3009 | 2987 |
3010 AttrNodeList* attrNodeList = attrNodeListForElement(this); | 2988 AttrNodeList* attrNodeList = this->attrNodeList(); |
3011 for (unsigned i = 0; i < attrNodeList->size(); ++i) { | 2989 for (unsigned i = 0; i < attrNodeList->size(); ++i) { |
3012 if (attrNodeList->at(i)->qualifiedName() == attrNode->qualifiedName()) { | 2990 if (attrNodeList->at(i)->qualifiedName() == attrNode->qualifiedName()) { |
3013 attrNodeList->remove(i); | 2991 attrNodeList->remove(i); |
3014 if (attrNodeList->isEmpty()) | 2992 if (attrNodeList->isEmpty()) |
3015 removeAttrNodeListForElement(this); | 2993 removeAttrNodeList(); |
3016 return; | 2994 return; |
3017 } | 2995 } |
3018 } | 2996 } |
3019 ASSERT_NOT_REACHED(); | 2997 ASSERT_NOT_REACHED(); |
3020 } | 2998 } |
3021 | 2999 |
3022 void Element::detachAllAttrNodesFromElement() | 3000 void Element::detachAllAttrNodesFromElement() |
3023 { | 3001 { |
3024 AttrNodeList* attrNodeList = attrNodeListForElement(this); | 3002 AttrNodeList* attrNodeList = this->attrNodeList(); |
3025 ASSERT(attrNodeList); | 3003 ASSERT(attrNodeList); |
3026 | 3004 |
3027 AttributeIteratorAccessor attributes = attributesIterator(); | 3005 AttributeIteratorAccessor attributes = attributesIterator(); |
3028 AttributeConstIterator end = attributes.end(); | 3006 AttributeConstIterator end = attributes.end(); |
3029 for (AttributeConstIterator it = attributes.begin(); it != end; ++it) { | 3007 for (AttributeConstIterator it = attributes.begin(); it != end; ++it) { |
3030 if (RefPtrWillBeRawPtr<Attr> attrNode = findAttrNodeInList(*attrNodeList , it->name())) | 3008 if (RefPtrWillBeRawPtr<Attr> attrNode = findAttrNodeInList(*attrNodeList , it->name())) |
3031 attrNode->detachFromElementWithValue(it->value()); | 3009 attrNode->detachFromElementWithValue(it->value()); |
3032 } | 3010 } |
3033 | 3011 |
3034 removeAttrNodeListForElement(this); | 3012 removeAttrNodeList(); |
3035 } | 3013 } |
3036 | 3014 |
3037 void Element::willRecalcStyle(StyleRecalcChange) | 3015 void Element::willRecalcStyle(StyleRecalcChange) |
3038 { | 3016 { |
3039 ASSERT(hasCustomStyleCallbacks()); | 3017 ASSERT(hasCustomStyleCallbacks()); |
3040 } | 3018 } |
3041 | 3019 |
3042 void Element::didRecalcStyle(StyleRecalcChange) | 3020 void Element::didRecalcStyle(StyleRecalcChange) |
3043 { | 3021 { |
3044 ASSERT(hasCustomStyleCallbacks()); | 3022 ASSERT(hasCustomStyleCallbacks()); |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3333 | 3311 |
3334 void Element::trace(Visitor* visitor) | 3312 void Element::trace(Visitor* visitor) |
3335 { | 3313 { |
3336 if (hasRareData()) | 3314 if (hasRareData()) |
3337 visitor->trace(elementRareData()); | 3315 visitor->trace(elementRareData()); |
3338 | 3316 |
3339 ContainerNode::trace(visitor); | 3317 ContainerNode::trace(visitor); |
3340 } | 3318 } |
3341 | 3319 |
3342 } // namespace WebCore | 3320 } // namespace WebCore |
OLD | NEW |