| 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 Dirk Mueller (mueller@kde.org) | 4 * (C) 2001 Dirk Mueller (mueller@kde.org) |
| 5 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All r
ights reserved. | 5 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All r
ights reserved. |
| 6 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) | 6 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) |
| 7 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmo
bile.com/) | 7 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmo
bile.com/) |
| 8 * Copyright (C) 2011 Google Inc. All rights reserved. | 8 * Copyright (C) 2011 Google Inc. All rights reserved. |
| 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 22 matching lines...) Expand all Loading... |
| 33 #include "NodeTraversal.h" | 33 #include "NodeTraversal.h" |
| 34 #include "RenderStyle.h" | 34 #include "RenderStyle.h" |
| 35 #include "ShadowRoot.h" | 35 #include "ShadowRoot.h" |
| 36 | 36 |
| 37 namespace WebCore { | 37 namespace WebCore { |
| 38 | 38 |
| 39 void TreeScopeAdopter::moveTreeToNewScope(Node* root) const | 39 void TreeScopeAdopter::moveTreeToNewScope(Node* root) const |
| 40 { | 40 { |
| 41 ASSERT(needsScopeChange()); | 41 ASSERT(needsScopeChange()); |
| 42 | 42 |
| 43 m_oldScope->guardRef(); |
| 44 |
| 43 // If an element is moved from a document and then eventually back again the
collection cache for | 45 // If an element is moved from a document and then eventually back again the
collection cache for |
| 44 // that element may contain stale data as changes made to it will have updat
ed the DOMTreeVersion | 46 // that element may contain stale data as changes made to it will have updat
ed the DOMTreeVersion |
| 45 // of the document it was moved to. By increasing the DOMTreeVersion of the
donating document here | 47 // of the document it was moved to. By increasing the DOMTreeVersion of the
donating document here |
| 46 // we ensure that the collection cache will be invalidated as needed when th
e element is moved back. | 48 // we ensure that the collection cache will be invalidated as needed when th
e element is moved back. |
| 47 Document* oldDocument = m_oldScope->documentScope(); | 49 Document* oldDocument = m_oldScope->documentScope(); |
| 48 Document* newDocument = m_newScope->documentScope(); | 50 Document* newDocument = m_newScope->documentScope(); |
| 49 bool willMoveToNewDocument = oldDocument != newDocument; | 51 bool willMoveToNewDocument = oldDocument != newDocument; |
| 50 if (oldDocument && willMoveToNewDocument) | 52 if (oldDocument && willMoveToNewDocument) |
| 51 oldDocument->incDOMTreeVersion(); | 53 oldDocument->incDOMTreeVersion(); |
| 52 | 54 |
| 53 for (Node* node = root; node; node = NodeTraversal::next(node, root)) { | 55 for (Node* node = root; node; node = NodeTraversal::next(node, root)) { |
| 54 node->setTreeScope(m_newScope); | 56 updateTreeScope(node); |
| 55 | 57 |
| 56 if (willMoveToNewDocument) | 58 if (willMoveToNewDocument) |
| 57 moveNodeToNewDocument(node, oldDocument, newDocument); | 59 moveNodeToNewDocument(node, oldDocument, newDocument); |
| 58 else if (node->hasRareData()) { | 60 else if (node->hasRareData()) { |
| 59 NodeRareData* rareData = node->rareData(); | 61 NodeRareData* rareData = node->rareData(); |
| 60 if (rareData->nodeLists()) | 62 if (rareData->nodeLists()) |
| 61 rareData->nodeLists()->adoptTreeScope(); | 63 rareData->nodeLists()->adoptTreeScope(); |
| 62 } | 64 } |
| 63 | 65 |
| 64 if (!node->isElementNode()) | 66 if (!node->isElementNode()) |
| 65 continue; | 67 continue; |
| 66 | 68 |
| 67 if (node->hasSyntheticAttrChildNodes()) { | 69 if (node->hasSyntheticAttrChildNodes()) { |
| 68 const Vector<RefPtr<Attr> >& attrs = toElement(node)->attrNodeList()
; | 70 const Vector<RefPtr<Attr> >& attrs = toElement(node)->attrNodeList()
; |
| 69 for (unsigned i = 0; i < attrs.size(); ++i) | 71 for (unsigned i = 0; i < attrs.size(); ++i) |
| 70 moveTreeToNewScope(attrs[i].get()); | 72 moveTreeToNewScope(attrs[i].get()); |
| 71 } | 73 } |
| 72 | 74 |
| 73 for (ShadowRoot* shadow = node->youngestShadowRoot(); shadow; shadow = s
hadow->olderShadowRoot()) { | 75 for (ShadowRoot* shadow = node->youngestShadowRoot(); shadow; shadow = s
hadow->olderShadowRoot()) { |
| 74 shadow->setParentTreeScope(m_newScope); | 76 shadow->setParentTreeScope(m_newScope); |
| 75 if (willMoveToNewDocument) | 77 if (willMoveToNewDocument) |
| 76 moveTreeToNewDocument(shadow, oldDocument, newDocument); | 78 moveTreeToNewDocument(shadow, oldDocument, newDocument); |
| 77 } | 79 } |
| 78 } | 80 } |
| 81 |
| 82 m_oldScope->guardDeref(); |
| 79 } | 83 } |
| 80 | 84 |
| 81 void TreeScopeAdopter::moveTreeToNewDocument(Node* root, Document* oldDocument,
Document* newDocument) const | 85 void TreeScopeAdopter::moveTreeToNewDocument(Node* root, Document* oldDocument,
Document* newDocument) const |
| 82 { | 86 { |
| 83 for (Node* node = root; node; node = NodeTraversal::next(node, root)) { | 87 for (Node* node = root; node; node = NodeTraversal::next(node, root)) { |
| 84 moveNodeToNewDocument(node, oldDocument, newDocument); | 88 moveNodeToNewDocument(node, oldDocument, newDocument); |
| 85 for (ShadowRoot* shadow = node->youngestShadowRoot(); shadow; shadow = s
hadow->olderShadowRoot()) | 89 for (ShadowRoot* shadow = node->youngestShadowRoot(); shadow; shadow = s
hadow->olderShadowRoot()) |
| 86 moveTreeToNewDocument(shadow, oldDocument, newDocument); | 90 moveTreeToNewDocument(shadow, oldDocument, newDocument); |
| 87 } | 91 } |
| 88 } | 92 } |
| 89 | 93 |
| 90 #ifndef NDEBUG | 94 #ifndef NDEBUG |
| 91 static bool didMoveToNewDocumentWasCalled = false; | 95 static bool didMoveToNewDocumentWasCalled = false; |
| 92 static Document* oldDocumentDidMoveToNewDocumentWasCalledWith = 0; | 96 static Document* oldDocumentDidMoveToNewDocumentWasCalledWith = 0; |
| 93 | 97 |
| 94 void TreeScopeAdopter::ensureDidMoveToNewDocumentWasCalled(Document* oldDocument
) | 98 void TreeScopeAdopter::ensureDidMoveToNewDocumentWasCalled(Document* oldDocument
) |
| 95 { | 99 { |
| 96 ASSERT(!didMoveToNewDocumentWasCalled); | 100 ASSERT(!didMoveToNewDocumentWasCalled); |
| 97 ASSERT_UNUSED(oldDocument, oldDocument == oldDocumentDidMoveToNewDocumentWas
CalledWith); | 101 ASSERT_UNUSED(oldDocument, oldDocument == oldDocumentDidMoveToNewDocumentWas
CalledWith); |
| 98 didMoveToNewDocumentWasCalled = true; | 102 didMoveToNewDocumentWasCalled = true; |
| 99 } | 103 } |
| 100 #endif | 104 #endif |
| 101 | 105 |
| 106 inline void TreeScopeAdopter::updateTreeScope(Node* node) const |
| 107 { |
| 108 ASSERT(!node->isTreeScope()); |
| 109 ASSERT(node->treeScope() == m_oldScope); |
| 110 m_newScope->guardRef(); |
| 111 m_oldScope->guardDeref(); |
| 112 node->setTreeScope(m_newScope); |
| 113 } |
| 114 |
| 102 inline void TreeScopeAdopter::moveNodeToNewDocument(Node* node, Document* oldDoc
ument, Document* newDocument) const | 115 inline void TreeScopeAdopter::moveNodeToNewDocument(Node* node, Document* oldDoc
ument, Document* newDocument) const |
| 103 { | 116 { |
| 104 ASSERT(!node->inDocument() || oldDocument != newDocument); | 117 ASSERT(!node->inDocument() || oldDocument != newDocument); |
| 105 | 118 |
| 106 if (node->hasRareData()) { | 119 if (node->hasRareData()) { |
| 107 NodeRareData* rareData = node->rareData(); | 120 NodeRareData* rareData = node->rareData(); |
| 108 if (rareData->nodeLists()) | 121 if (rareData->nodeLists()) |
| 109 rareData->nodeLists()->adoptDocument(oldDocument, newDocument); | 122 rareData->nodeLists()->adoptDocument(oldDocument, newDocument); |
| 110 } | 123 } |
| 111 | 124 |
| 112 newDocument->guardRef(); | |
| 113 if (oldDocument) | 125 if (oldDocument) |
| 114 oldDocument->moveNodeIteratorsToNewDocument(node, newDocument); | 126 oldDocument->moveNodeIteratorsToNewDocument(node, newDocument); |
| 115 | 127 |
| 116 if (node->isShadowRoot()) | 128 if (node->isShadowRoot()) |
| 117 toShadowRoot(node)->setDocumentScope(newDocument); | 129 toShadowRoot(node)->setDocumentScope(newDocument); |
| 118 | 130 |
| 119 #ifndef NDEBUG | 131 #ifndef NDEBUG |
| 120 didMoveToNewDocumentWasCalled = false; | 132 didMoveToNewDocumentWasCalled = false; |
| 121 oldDocumentDidMoveToNewDocumentWasCalledWith = oldDocument; | 133 oldDocumentDidMoveToNewDocumentWasCalledWith = oldDocument; |
| 122 #endif | 134 #endif |
| 123 | 135 |
| 124 node->didMoveToNewDocument(oldDocument); | 136 node->didMoveToNewDocument(oldDocument); |
| 125 ASSERT(didMoveToNewDocumentWasCalled); | 137 ASSERT(didMoveToNewDocumentWasCalled); |
| 126 | |
| 127 if (oldDocument) | |
| 128 oldDocument->guardDeref(); | |
| 129 } | 138 } |
| 130 | 139 |
| 131 } | 140 } |
| OLD | NEW |