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 1220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1231 | 1231 |
1232 if (!insertionPoint->isInTreeScope()) | 1232 if (!insertionPoint->isInTreeScope()) |
1233 return InsertionDone; | 1233 return InsertionDone; |
1234 | 1234 |
1235 if (hasRareData()) | 1235 if (hasRareData()) |
1236 elementRareData()->clearClassListValueForQuirksMode(); | 1236 elementRareData()->clearClassListValueForQuirksMode(); |
1237 | 1237 |
1238 if (isUpgradedCustomElement() && inDocument()) | 1238 if (isUpgradedCustomElement() && inDocument()) |
1239 CustomElement::didEnterDocument(this, document()); | 1239 CustomElement::didEnterDocument(this, document()); |
1240 | 1240 |
1241 TreeScope* scope = insertionPoint->treeScope(); | 1241 if (insertionPoint->treeScope() != treeScope()) |
1242 if (scope != treeScope()) | |
1243 return InsertionDone; | 1242 return InsertionDone; |
1244 | 1243 |
| 1244 HTMLDocument* newDocument = inDocument() && !isInShadowTree() && document()-
>isHTMLDocument() ? toHTMLDocument(document()) : 0; |
| 1245 |
1245 const AtomicString& idValue = getIdAttribute(); | 1246 const AtomicString& idValue = getIdAttribute(); |
1246 if (!idValue.isNull()) | 1247 if (!idValue.isNull()) { |
1247 updateId(scope, nullAtom, idValue); | 1248 updateIdForTreeScope(treeScope(), nullAtom, idValue); |
| 1249 if (newDocument) |
| 1250 updateIdForDocument(newDocument, nullAtom, idValue); |
| 1251 } |
1248 | 1252 |
1249 const AtomicString& nameValue = getNameAttribute(); | 1253 const AtomicString& nameValue = getNameAttribute(); |
1250 if (!nameValue.isNull()) | 1254 if (!nameValue.isNull()) { |
1251 updateName(nullAtom, nameValue); | 1255 updateNameForTreeScope(treeScope(), nullAtom, nameValue); |
| 1256 if (newDocument) |
| 1257 updateNameForDocument(newDocument, nullAtom, nameValue); |
| 1258 } |
1252 | 1259 |
1253 if (hasTagName(labelTag)) { | 1260 if (hasTagName(labelTag)) { |
1254 if (scope->shouldCacheLabelsByForAttribute()) | 1261 if (treeScope()->shouldCacheLabelsByForAttribute()) |
1255 updateLabel(scope, nullAtom, fastGetAttribute(forAttr)); | 1262 updateLabel(treeScope(), nullAtom, fastGetAttribute(forAttr)); |
1256 } | 1263 } |
1257 | 1264 |
1258 if (parentElement() && parentElement()->isInCanvasSubtree()) | 1265 if (parentElement() && parentElement()->isInCanvasSubtree()) |
1259 setIsInCanvasSubtree(true); | 1266 setIsInCanvasSubtree(true); |
1260 | 1267 |
1261 return InsertionDone; | 1268 return InsertionDone; |
1262 } | 1269 } |
1263 | 1270 |
1264 void Element::removedFrom(ContainerNode* insertionPoint) | 1271 void Element::removedFrom(ContainerNode* insertionPoint) |
1265 { | 1272 { |
1266 bool wasInDocument = insertionPoint->inDocument(); | 1273 bool wasInDocument = insertionPoint->inDocument(); |
| 1274 bool wasInShadowTree = isInShadowTree(); // Of course, we might still be in
a shadow tree... |
1267 | 1275 |
1268 if (Element* before = pseudoElement(BEFORE)) | 1276 if (Element* before = pseudoElement(BEFORE)) |
1269 before->removedFrom(insertionPoint); | 1277 before->removedFrom(insertionPoint); |
1270 | 1278 |
1271 if (Element* after = pseudoElement(AFTER)) | 1279 if (Element* after = pseudoElement(AFTER)) |
1272 after->removedFrom(insertionPoint); | 1280 after->removedFrom(insertionPoint); |
1273 | 1281 |
1274 if (Element* backdrop = pseudoElement(BACKDROP)) | 1282 if (Element* backdrop = pseudoElement(BACKDROP)) |
1275 backdrop->removedFrom(insertionPoint); | 1283 backdrop->removedFrom(insertionPoint); |
1276 document()->removeFromTopLayer(this); | 1284 document()->removeFromTopLayer(this); |
1277 | 1285 |
1278 if (containsFullScreenElement()) | 1286 if (containsFullScreenElement()) |
1279 setContainsFullScreenElementOnAncestorsCrossingFrameBoundaries(false); | 1287 setContainsFullScreenElementOnAncestorsCrossingFrameBoundaries(false); |
1280 | 1288 |
1281 if (document()->page()) | 1289 if (document()->page()) |
1282 document()->page()->pointerLockController()->elementRemoved(this); | 1290 document()->page()->pointerLockController()->elementRemoved(this); |
1283 | 1291 |
1284 setSavedLayerScrollOffset(IntSize()); | 1292 setSavedLayerScrollOffset(IntSize()); |
1285 | 1293 |
1286 if (insertionPoint->isInTreeScope() && treeScope() == document()) { | 1294 if (insertionPoint->isInTreeScope() && treeScope() == document()) { |
| 1295 TreeScope* oldScope = insertionPoint->treeScope(); |
| 1296 HTMLDocument* oldDocument = wasInDocument && !wasInShadowTree && oldScop
e->documentScope()->isHTMLDocument() ? toHTMLDocument(oldScope->documentScope())
: 0; |
| 1297 |
1287 const AtomicString& idValue = getIdAttribute(); | 1298 const AtomicString& idValue = getIdAttribute(); |
1288 if (!idValue.isNull()) | 1299 if (!idValue.isNull()) { |
1289 updateId(insertionPoint->treeScope(), idValue, nullAtom); | 1300 updateIdForTreeScope(oldScope, idValue, nullAtom); |
| 1301 if (oldDocument) |
| 1302 updateIdForDocument(oldDocument, idValue, nullAtom); |
| 1303 } |
1290 | 1304 |
1291 const AtomicString& nameValue = getNameAttribute(); | 1305 const AtomicString& nameValue = getNameAttribute(); |
1292 if (!nameValue.isNull()) | 1306 if (!nameValue.isNull()) { |
1293 updateName(nameValue, nullAtom); | 1307 updateNameForTreeScope(oldScope, nameValue, nullAtom); |
| 1308 if (oldDocument) |
| 1309 updateNameForDocument(oldDocument, nameValue, nullAtom); |
| 1310 } |
1294 | 1311 |
1295 if (hasTagName(labelTag)) { | 1312 if (hasTagName(labelTag)) { |
1296 TreeScope* treeScope = insertionPoint->treeScope(); | 1313 if (oldScope->shouldCacheLabelsByForAttribute()) |
1297 if (treeScope->shouldCacheLabelsByForAttribute()) | 1314 updateLabel(oldScope, fastGetAttribute(forAttr), nullAtom); |
1298 updateLabel(treeScope, fastGetAttribute(forAttr), nullAtom); | |
1299 } | 1315 } |
1300 } | 1316 } |
1301 | 1317 |
1302 ContainerNode::removedFrom(insertionPoint); | 1318 ContainerNode::removedFrom(insertionPoint); |
| 1319 |
1303 if (wasInDocument) { | 1320 if (wasInDocument) { |
1304 if (hasPendingResources()) | 1321 if (hasPendingResources()) |
1305 document()->accessSVGExtensions()->removeElementFromPendingResources
(this); | 1322 document()->accessSVGExtensions()->removeElementFromPendingResources
(this); |
1306 | 1323 |
1307 if (isUpgradedCustomElement()) | 1324 if (isUpgradedCustomElement()) |
1308 CustomElement::didLeaveDocument(this, insertionPoint->document()); | 1325 CustomElement::didLeaveDocument(this, insertionPoint->document()); |
1309 } | 1326 } |
1310 | 1327 |
1311 if (hasRareData()) | 1328 if (hasRareData()) |
1312 elementRareData()->setIsInCanvasSubtree(false); | 1329 elementRareData()->setIsInCanvasSubtree(false); |
(...skipping 1440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2753 } | 2770 } |
2754 #endif | 2771 #endif |
2755 | 2772 |
2756 #ifdef DUMP_NODE_STATISTICS | 2773 #ifdef DUMP_NODE_STATISTICS |
2757 bool Element::hasNamedNodeMap() const | 2774 bool Element::hasNamedNodeMap() const |
2758 { | 2775 { |
2759 return hasRareData() && elementRareData()->attributeMap(); | 2776 return hasRareData() && elementRareData()->attributeMap(); |
2760 } | 2777 } |
2761 #endif | 2778 #endif |
2762 | 2779 |
2763 inline void Element::updateName(const AtomicString& oldName, const AtomicString&
newName) | 2780 void Element::updateName(const AtomicString& oldName, const AtomicString& newNam
e) |
2764 { | 2781 { |
2765 if (!inDocument() || isInShadowTree()) | 2782 if (!isInTreeScope()) |
2766 return; | 2783 return; |
2767 | 2784 |
2768 if (oldName == newName) | 2785 if (oldName == newName) |
2769 return; | 2786 return; |
2770 | 2787 |
| 2788 updateNameForTreeScope(treeScope(), oldName, newName); |
| 2789 |
| 2790 if (!inDocument() || isInShadowTree()) |
| 2791 return; |
| 2792 |
| 2793 Document* htmlDocument = document(); |
| 2794 if (!htmlDocument->isHTMLDocument()) |
| 2795 return; |
| 2796 |
| 2797 updateNameForDocument(toHTMLDocument(htmlDocument), oldName, newName); |
| 2798 } |
| 2799 |
| 2800 void Element::updateNameForTreeScope(TreeScope* scope, const AtomicString& oldNa
me, const AtomicString& newName) |
| 2801 { |
| 2802 ASSERT(isInTreeScope()); |
| 2803 ASSERT(oldName != newName); |
| 2804 |
| 2805 if (!oldName.isEmpty()) |
| 2806 scope->removeElementByName(oldName, this); |
| 2807 if (!newName.isEmpty()) |
| 2808 scope->addElementByName(newName, this); |
| 2809 } |
| 2810 |
| 2811 void Element::updateNameForDocument(HTMLDocument* document, const AtomicString&
oldName, const AtomicString& newName) |
| 2812 { |
| 2813 ASSERT(inDocument() && !isInShadowTree()); |
| 2814 ASSERT(oldName != newName); |
| 2815 |
2771 if (shouldRegisterAsNamedItem()) | 2816 if (shouldRegisterAsNamedItem()) |
2772 updateNamedItemRegistration(oldName, newName); | 2817 updateNamedItemRegistration(oldName, newName); |
2773 } | 2818 } |
2774 | 2819 |
2775 inline void Element::updateId(const AtomicString& oldId, const AtomicString& new
Id) | 2820 void Element::updateId(const AtomicString& oldId, const AtomicString& newId) |
2776 { | 2821 { |
2777 if (!isInTreeScope()) | 2822 if (!isInTreeScope()) |
2778 return; | 2823 return; |
2779 | 2824 |
2780 if (oldId == newId) | 2825 if (oldId == newId) |
2781 return; | 2826 return; |
2782 | 2827 |
2783 updateId(treeScope(), oldId, newId); | 2828 updateIdForTreeScope(treeScope(), oldId, newId); |
| 2829 |
| 2830 if (!inDocument() || isInShadowTree()) |
| 2831 return; |
| 2832 |
| 2833 Document* htmlDocument = document(); |
| 2834 if (!htmlDocument->isHTMLDocument()) |
| 2835 return; |
| 2836 |
| 2837 updateIdForDocument(toHTMLDocument(htmlDocument), oldId, newId); |
2784 } | 2838 } |
2785 | 2839 |
2786 inline void Element::updateId(TreeScope* scope, const AtomicString& oldId, const
AtomicString& newId) | 2840 void Element::updateIdForTreeScope(TreeScope* scope, const AtomicString& oldId,
const AtomicString& newId) |
2787 { | 2841 { |
2788 ASSERT(isInTreeScope()); | 2842 ASSERT(isInTreeScope()); |
2789 ASSERT(oldId != newId); | 2843 ASSERT(oldId != newId); |
2790 | 2844 |
2791 if (!oldId.isEmpty()) | 2845 if (!oldId.isEmpty()) |
2792 scope->removeElementById(oldId, this); | 2846 scope->removeElementById(oldId, this); |
2793 if (!newId.isEmpty()) | 2847 if (!newId.isEmpty()) |
2794 scope->addElementById(newId, this); | 2848 scope->addElementById(newId, this); |
| 2849 } |
| 2850 |
| 2851 void Element::updateIdForDocument(HTMLDocument* document, const AtomicString& ol
dId, const AtomicString& newId) |
| 2852 { |
| 2853 ASSERT(inDocument() && !isInShadowTree()); |
| 2854 ASSERT(oldId != newId); |
2795 | 2855 |
2796 if (shouldRegisterAsExtraNamedItem()) | 2856 if (shouldRegisterAsExtraNamedItem()) |
2797 updateExtraNamedItemRegistration(oldId, newId); | 2857 updateExtraNamedItemRegistration(oldId, newId); |
2798 } | 2858 } |
2799 | 2859 |
2800 void Element::updateLabel(TreeScope* scope, const AtomicString& oldForAttributeV
alue, const AtomicString& newForAttributeValue) | 2860 void Element::updateLabel(TreeScope* scope, const AtomicString& oldForAttributeV
alue, const AtomicString& newForAttributeValue) |
2801 { | 2861 { |
2802 ASSERT(hasTagName(labelTag)); | 2862 ASSERT(hasTagName(labelTag)); |
2803 | 2863 |
2804 if (!inDocument()) | 2864 if (!inDocument()) |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2875 if (oldDocument->inQuirksMode() != document()->inQuirksMode()) { | 2935 if (oldDocument->inQuirksMode() != document()->inQuirksMode()) { |
2876 if (hasID()) | 2936 if (hasID()) |
2877 setIdAttribute(getIdAttribute()); | 2937 setIdAttribute(getIdAttribute()); |
2878 if (hasClass()) | 2938 if (hasClass()) |
2879 setAttribute(HTMLNames::classAttr, getClassAttribute()); | 2939 setAttribute(HTMLNames::classAttr, getClassAttribute()); |
2880 } | 2940 } |
2881 } | 2941 } |
2882 | 2942 |
2883 void Element::updateNamedItemRegistration(const AtomicString& oldName, const Ato
micString& newName) | 2943 void Element::updateNamedItemRegistration(const AtomicString& oldName, const Ato
micString& newName) |
2884 { | 2944 { |
2885 if (!document()->isHTMLDocument()) | 2945 ASSERT(document()->isHTMLDocument()); |
2886 return; | |
2887 | 2946 |
2888 if (!oldName.isEmpty()) | 2947 if (!oldName.isEmpty()) |
2889 toHTMLDocument(document())->removeNamedItem(oldName); | 2948 toHTMLDocument(document())->removeNamedItem(oldName); |
2890 | 2949 |
2891 if (!newName.isEmpty()) | 2950 if (!newName.isEmpty()) |
2892 toHTMLDocument(document())->addNamedItem(newName); | 2951 toHTMLDocument(document())->addNamedItem(newName); |
2893 } | 2952 } |
2894 | 2953 |
2895 void Element::updateExtraNamedItemRegistration(const AtomicString& oldId, const
AtomicString& newId) | 2954 void Element::updateExtraNamedItemRegistration(const AtomicString& oldId, const
AtomicString& newId) |
2896 { | 2955 { |
2897 if (!document()->isHTMLDocument()) | 2956 ASSERT(document()->isHTMLDocument()); |
2898 return; | |
2899 | 2957 |
2900 if (!oldId.isEmpty()) | 2958 if (!oldId.isEmpty()) |
2901 toHTMLDocument(document())->removeExtraNamedItem(oldId); | 2959 toHTMLDocument(document())->removeExtraNamedItem(oldId); |
2902 | 2960 |
2903 if (!newId.isEmpty()) | 2961 if (!newId.isEmpty()) |
2904 toHTMLDocument(document())->addExtraNamedItem(newId); | 2962 toHTMLDocument(document())->addExtraNamedItem(newId); |
2905 } | 2963 } |
2906 | 2964 |
2907 PassRefPtr<HTMLCollection> Element::ensureCachedHTMLCollection(CollectionType ty
pe) | 2965 PassRefPtr<HTMLCollection> Element::ensureCachedHTMLCollection(CollectionType ty
pe) |
2908 { | 2966 { |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3026 { | 3084 { |
3027 if (hasSyntheticAttrChildNodes()) | 3085 if (hasSyntheticAttrChildNodes()) |
3028 detachAllAttrNodesFromElement(); | 3086 detachAllAttrNodesFromElement(); |
3029 | 3087 |
3030 other.synchronizeAllAttributes(); | 3088 other.synchronizeAllAttributes(); |
3031 if (!other.m_elementData) { | 3089 if (!other.m_elementData) { |
3032 m_elementData.clear(); | 3090 m_elementData.clear(); |
3033 return; | 3091 return; |
3034 } | 3092 } |
3035 | 3093 |
| 3094 // We can't update window and document's named item maps since the presence
of image and object elements depend on other attributes and children. |
| 3095 // Fortunately, those named item maps are only updated when this element is
in the document, which should never be the case. |
| 3096 ASSERT(!inDocument()); |
| 3097 |
3036 const AtomicString& oldID = getIdAttribute(); | 3098 const AtomicString& oldID = getIdAttribute(); |
3037 const AtomicString& newID = other.getIdAttribute(); | 3099 const AtomicString& newID = other.getIdAttribute(); |
3038 | 3100 |
3039 if (!oldID.isNull() || !newID.isNull()) | 3101 if (!oldID.isNull() || !newID.isNull()) |
3040 updateId(oldID, newID); | 3102 updateId(oldID, newID); |
3041 | 3103 |
3042 const AtomicString& oldName = getNameAttribute(); | 3104 const AtomicString& oldName = getNameAttribute(); |
3043 const AtomicString& newName = other.getNameAttribute(); | 3105 const AtomicString& newName = other.getNameAttribute(); |
3044 | 3106 |
3045 if (!oldName.isNull() || !newName.isNull()) | 3107 if (!oldName.isNull() || !newName.isNull()) |
(...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3642 return 0; | 3704 return 0; |
3643 } | 3705 } |
3644 | 3706 |
3645 Attribute* UniqueElementData::attributeItem(unsigned index) | 3707 Attribute* UniqueElementData::attributeItem(unsigned index) |
3646 { | 3708 { |
3647 ASSERT_WITH_SECURITY_IMPLICATION(index < length()); | 3709 ASSERT_WITH_SECURITY_IMPLICATION(index < length()); |
3648 return &m_attributeVector.at(index); | 3710 return &m_attributeVector.at(index); |
3649 } | 3711 } |
3650 | 3712 |
3651 } // namespace WebCore | 3713 } // namespace WebCore |
OLD | NEW |