| 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 | 5 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All |
| 6 * rights reserved. | 6 * rights reserved. |
| 7 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) | 7 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) |
| 8 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. | 8 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. |
| 9 * (http://www.torchmobile.com/) | 9 * (http://www.torchmobile.com/) |
| 10 * Copyright (C) 2011 Google Inc. All rights reserved. | 10 * Copyright (C) 2011 Google Inc. All rights reserved. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 #include "core/dom/Attr.h" | 29 #include "core/dom/Attr.h" |
| 30 #include "core/dom/Node.h" | 30 #include "core/dom/Node.h" |
| 31 #include "core/dom/NodeRareData.h" | 31 #include "core/dom/NodeRareData.h" |
| 32 #include "core/dom/NodeTraversal.h" | 32 #include "core/dom/NodeTraversal.h" |
| 33 #include "core/dom/custom/CustomElement.h" | 33 #include "core/dom/custom/CustomElement.h" |
| 34 #include "core/dom/shadow/ElementShadow.h" | 34 #include "core/dom/shadow/ElementShadow.h" |
| 35 #include "core/dom/shadow/ShadowRoot.h" | 35 #include "core/dom/shadow/ShadowRoot.h" |
| 36 | 36 |
| 37 namespace blink { | 37 namespace blink { |
| 38 | 38 |
| 39 void TreeScopeAdopter::execute() const { |
| 40 moveTreeToNewScope(*m_toAdopt); |
| 41 Document& oldDocument = oldScope().document(); |
| 42 if (oldDocument == newScope().document()) |
| 43 return; |
| 44 oldDocument.didMoveTreeToNewDocument(*m_toAdopt); |
| 45 } |
| 46 |
| 39 void TreeScopeAdopter::moveTreeToNewScope(Node& root) const { | 47 void TreeScopeAdopter::moveTreeToNewScope(Node& root) const { |
| 40 DCHECK(needsScopeChange()); | 48 DCHECK(needsScopeChange()); |
| 41 | 49 |
| 42 // If an element is moved from a document and then eventually back again the | 50 // If an element is moved from a document and then eventually back again the |
| 43 // collection cache for that element may contain stale data as changes made to | 51 // collection cache for that element may contain stale data as changes made to |
| 44 // it will have updated the DOMTreeVersion of the document it was moved to. By | 52 // it will have updated the DOMTreeVersion of the document it was moved to. By |
| 45 // increasing the DOMTreeVersion of the donating document here we ensure that | 53 // increasing the DOMTreeVersion of the donating document here we ensure that |
| 46 // the collection cache will be invalidated as needed when the element is | 54 // the collection cache will be invalidated as needed when the element is |
| 47 // moved back. | 55 // moved back. |
| 48 Document& oldDocument = oldScope().document(); | 56 Document& oldDocument = oldScope().document(); |
| 49 Document& newDocument = newScope().document(); | 57 Document& newDocument = newScope().document(); |
| 50 bool willMoveToNewDocument = oldDocument != newDocument; | 58 bool willMoveToNewDocument = oldDocument != newDocument; |
| 51 if (willMoveToNewDocument) | |
| 52 oldDocument.incDOMTreeVersion(); | |
| 53 | 59 |
| 54 for (Node& node : NodeTraversal::inclusiveDescendantsOf(root)) { | 60 for (Node& node : NodeTraversal::inclusiveDescendantsOf(root)) { |
| 55 updateTreeScope(node); | 61 updateTreeScope(node); |
| 56 | 62 |
| 57 if (willMoveToNewDocument) { | 63 if (willMoveToNewDocument) { |
| 58 moveNodeToNewDocument(node, oldDocument, newDocument); | 64 moveNodeToNewDocument(node, oldDocument, newDocument); |
| 59 } else if (node.hasRareData()) { | 65 } else if (node.hasRareData()) { |
| 60 NodeRareData* rareData = node.rareData(); | 66 NodeRareData* rareData = node.rareData(); |
| 61 if (rareData->nodeLists()) | 67 if (rareData->nodeLists()) |
| 62 rareData->nodeLists()->adoptTreeScope(); | 68 rareData->nodeLists()->adoptTreeScope(); |
| 63 } | 69 } |
| 64 | 70 |
| 65 if (!node.isElementNode()) | 71 if (!node.isElementNode()) |
| 66 continue; | 72 continue; |
| 67 Element& element = toElement(node); | 73 Element& element = toElement(node); |
| 68 | 74 |
| 69 if (HeapVector<Member<Attr>>* attrs = element.attrNodeList()) { | 75 if (HeapVector<Member<Attr>>* attrs = element.attrNodeList()) { |
| 70 for (const auto& attr : *attrs) | 76 for (const auto& attr : *attrs) |
| 71 moveTreeToNewScope(*attr); | 77 moveTreeToNewScope(*attr); |
| 72 } | 78 } |
| 73 | 79 |
| 74 for (ShadowRoot* shadow = element.youngestShadowRoot(); shadow; | 80 for (ShadowRoot* shadow = element.youngestShadowRoot(); shadow; |
| 75 shadow = shadow->olderShadowRoot()) { | 81 shadow = shadow->olderShadowRoot()) { |
| 76 shadow->setParentTreeScope(newScope()); | 82 shadow->setParentTreeScope(newScope()); |
| 77 if (willMoveToNewDocument) | 83 if (willMoveToNewDocument) |
| 78 moveTreeToNewDocument(*shadow, oldDocument, newDocument); | 84 moveTreeToNewDocument(*shadow, oldDocument, newDocument); |
| 79 } | 85 } |
| 80 } | 86 } |
| 81 if (!willMoveToNewDocument) | |
| 82 return; | |
| 83 oldDocument.didMoveTreeToNewDocument(root); | |
| 84 } | 87 } |
| 85 | 88 |
| 86 void TreeScopeAdopter::moveTreeToNewDocument(Node& root, | 89 void TreeScopeAdopter::moveTreeToNewDocument(Node& root, |
| 87 Document& oldDocument, | 90 Document& oldDocument, |
| 88 Document& newDocument) const { | 91 Document& newDocument) const { |
| 89 DCHECK_NE(oldDocument, newDocument); | 92 DCHECK_NE(oldDocument, newDocument); |
| 90 for (Node& node : NodeTraversal::inclusiveDescendantsOf(root)) { | 93 for (Node& node : NodeTraversal::inclusiveDescendantsOf(root)) { |
| 91 moveNodeToNewDocument(node, oldDocument, newDocument); | 94 moveNodeToNewDocument(node, oldDocument, newDocument); |
| 92 | 95 |
| 93 if (!node.isElementNode()) | 96 if (!node.isElementNode()) |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 oldDocumentDidMoveToNewDocumentWasCalledWith = &oldDocument; | 153 oldDocumentDidMoveToNewDocumentWasCalledWith = &oldDocument; |
| 151 #endif | 154 #endif |
| 152 | 155 |
| 153 node.didMoveToNewDocument(oldDocument); | 156 node.didMoveToNewDocument(oldDocument); |
| 154 #if DCHECK_IS_ON() | 157 #if DCHECK_IS_ON() |
| 155 DCHECK(didMoveToNewDocumentWasCalled); | 158 DCHECK(didMoveToNewDocumentWasCalled); |
| 156 #endif | 159 #endif |
| 157 } | 160 } |
| 158 | 161 |
| 159 } // namespace blink | 162 } // namespace blink |
| OLD | NEW |