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 1696 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()->attrNodeList() : 0; |
| 1836 } |
| 1837 |
| 1838 WillBeHeapVector<RefPtrWillBeMember<Attr> >& Element::ensureAttrNodeList() |
| 1839 { |
| 1840 setHasSyntheticAttrChildNodes(true); |
| 1841 return ensureElementRareData().ensureAttrNodeList(); |
| 1842 } |
| 1843 |
| 1844 void Element::removeAttrNodeList() |
1869 { | 1845 { |
1870 ASSERT(hasSyntheticAttrChildNodes()); | 1846 ASSERT(hasSyntheticAttrChildNodes()); |
1871 return *attrNodeListForElement(this); | 1847 if (hasRareData()) |
| 1848 elementRareData()->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 1045 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()) |
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* list = attrNodeList(); |
3011 for (unsigned i = 0; i < attrNodeList->size(); ++i) { | 2989 for (unsigned i = 0; i < list->size(); ++i) { |
3012 if (attrNodeList->at(i)->qualifiedName() == attrNode->qualifiedName()) { | 2990 if (list->at(i)->qualifiedName() == attrNode->qualifiedName()) { |
3013 attrNodeList->remove(i); | 2991 list->remove(i); |
3014 if (attrNodeList->isEmpty()) | 2992 if (list->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* list = this->attrNodeList(); |
3025 ASSERT(attrNodeList); | 3003 ASSERT(list); |
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(*list, it->na
me())) |
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 |