Changeset 104528 in webkit
- Timestamp:
- Jan 9, 2012 6:11:30 PM (12 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 2 added
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/CMakeLists.txt
r104380 r104528 611 611 dom/Traversal.cpp 612 612 dom/TreeScope.cpp 613 dom/TreeScopeAdopter.cpp 613 614 dom/TreeWalker.cpp 614 615 dom/UIEvent.cpp -
trunk/Source/WebCore/ChangeLog
r104526 r104528 1 2012-01-06 Hajime Morrita <morrita@chromium.org> 2 3 [Refactoring] Moving between TreeScopes should be done by its own class. 4 https://bugs.webkit.org/show_bug.cgi?id=75290 5 6 Reviewed by Ryosuke Niwa. 7 8 This change extracted Node::setTreeScopeRecursively(), 9 setDocumentRecursively() and a part of setDocument() into a new 10 class called TreeScopeAdopter. By doing this, the idea of 11 moving a node from scope to scope, that was originally hidden 12 behind the forest of Node APIs, has become clearer. 13 14 Note that this change is a preparation for Bug 59816. 15 16 No new tests. No behavioral change. 17 18 * CMakeLists.txt: 19 * GNUmakefile.list.am: 20 * Target.pri: 21 * WebCore.gypi: 22 * WebCore.vcproj/WebCore.vcproj: 23 * WebCore.xcodeproj/project.pbxproj: 24 * dom/ContainerNode.cpp: Followed the renaming. 25 (WebCore::ContainerNode::takeAllChildrenFrom): 26 (WebCore::ContainerNode::insertBefore): 27 (WebCore::ContainerNode::replaceChild): 28 (WebCore::ContainerNode::removeBetween): 29 (WebCore::ContainerNode::removeChildren): 30 (WebCore::ContainerNode::appendChild): 31 (WebCore::ContainerNode::parserAddChild): 32 * dom/DOMAllInOne.cpp: 33 * dom/Document.cpp: Followed te renaming. 34 (WebCore::Document::setDocType): 35 (WebCore::Document::adoptNode): 36 * dom/Element.cpp: Followed te renaming. 37 (WebCore::Element::removeShadowRoot): 38 * dom/Node.cpp: 39 (WebCore::Node::setDocument): 40 (WebCore::Node::setTreeScope): 41 (WebCore::Node::didMoveToNewDocument): 42 * dom/Node.h: 43 * dom/TreeScope.h: 44 * dom/TreeScope.cpp: 45 (WebCore::TreeScope::adoptIfNeeded): moved from setTreeScopeRecursively() 46 * dom/TreeScopeAdopter.cpp: Added. 47 (WebCore::TreeScopeAdopter::TreeScopeAdopter): 48 (WebCore::TreeScopeAdopter::moveTreeToNewScope): 49 (WebCore::TreeScopeAdopter::moveTreeToNewDocument): 50 (WebCore::TreeScopeAdopter::ensureDidMoveToNewDocumentWasCalled): 51 (WebCore::TreeScopeAdopter::moveNodeToNewDocument): 52 * dom/TreeScopeAdopter.h: Added. 53 (WebCore::TreeScopeAdopter::ensureDidMoveToNewDocumentWasCalled): 54 (WebCore::TreeScopeAdopter::execute): 55 (WebCore::TreeScopeAdopter::needsScopeChange()): 56 (WebCore::TreeScopeAdopter::shadowRootFor): 57 1 58 2012-01-09 Adam Barth <abarth@webkit.org> 2 59 -
trunk/Source/WebCore/GNUmakefile.list.am
r104459 r104528 1675 1675 Source/WebCore/dom/TreeScope.cpp \ 1676 1676 Source/WebCore/dom/TreeScope.h \ 1677 Source/WebCore/dom/TreeScopeAdopter.cpp \ 1678 Source/WebCore/dom/TreeScopeAdopter.h \ 1677 1679 Source/WebCore/dom/TreeWalker.cpp \ 1678 1680 Source/WebCore/dom/TreeWalker.h \ -
trunk/Source/WebCore/Target.pri
r104447 r104528 575 575 dom/Traversal.cpp \ 576 576 dom/TreeScope.cpp \ 577 dom/TreeScopeAdopter.cpp \ 577 578 dom/TreeWalker.cpp \ 578 579 dom/UIEvent.cpp \ … … 1675 1676 dom/TreeDepthLimit.h \ 1676 1677 dom/TreeScope.h \ 1678 dom/TreeScopeAdopter.h \ 1677 1679 dom/TreeWalker.h \ 1678 1680 dom/UIEvent.h \ -
trunk/Source/WebCore/WebCore.gypi
r104507 r104528 5471 5471 'dom/TreeScope.cpp', 5472 5472 'dom/TreeScope.h', 5473 'dom/TreeScopeAdopter.cpp', 5474 'dom/TreeScopeAdopter.h', 5473 5475 'dom/TreeWalker.cpp', 5474 5476 'dom/TreeWalker.h', -
trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj
r104380 r104528 51791 51791 </File> 51792 51792 <File 51793 RelativePath="..\dom\TreeScopeAdopter.cpp" 51794 > 51795 <FileConfiguration 51796 Name="Debug|Win32" 51797 ExcludedFromBuild="true" 51798 > 51799 <Tool 51800 Name="VCCLCompilerTool" 51801 /> 51802 </FileConfiguration> 51803 <FileConfiguration 51804 Name="Release|Win32" 51805 ExcludedFromBuild="true" 51806 > 51807 <Tool 51808 Name="VCCLCompilerTool" 51809 /> 51810 </FileConfiguration> 51811 <FileConfiguration 51812 Name="Debug_Cairo_CFLite|Win32" 51813 ExcludedFromBuild="true" 51814 > 51815 <Tool 51816 Name="VCCLCompilerTool" 51817 /> 51818 </FileConfiguration> 51819 <FileConfiguration 51820 Name="Release_Cairo_CFLite|Win32" 51821 ExcludedFromBuild="true" 51822 > 51823 <Tool 51824 Name="VCCLCompilerTool" 51825 /> 51826 </FileConfiguration> 51827 <FileConfiguration 51828 Name="Debug_All|Win32" 51829 ExcludedFromBuild="true" 51830 > 51831 <Tool 51832 Name="VCCLCompilerTool" 51833 /> 51834 </FileConfiguration> 51835 <FileConfiguration 51836 Name="Production|Win32" 51837 ExcludedFromBuild="true" 51838 > 51839 <Tool 51840 Name="VCCLCompilerTool" 51841 /> 51842 </FileConfiguration> 51843 </File> 51844 <File 51845 RelativePath="..\dom\TreeScopeAdopter.h" 51846 > 51847 </File> 51848 <File 51793 51849 RelativePath="..\dom\TreeWalker.cpp" 51794 51850 > -
trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj
r104380 r104528 3512 3512 A77B41A012E675A90054343D /* TextEventInputType.h in Headers */ = {isa = PBXBuildFile; fileRef = A77B419F12E675A90054343D /* TextEventInputType.h */; settings = {ATTRIBUTES = (Private, ); }; }; 3513 3513 A77D0012133B0AEB00D6658C /* TextChecking.h in Headers */ = {isa = PBXBuildFile; fileRef = A77D0011133B0AEB00D6658C /* TextChecking.h */; settings = {ATTRIBUTES = (Private, ); }; }; 3514 A77E1FEF14AACB6E005B7CB6 /* TreeScopeAdopter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A77E1FED14AACB6E005B7CB6 /* TreeScopeAdopter.cpp */; }; 3515 A77E1FF014AACB6E005B7CB6 /* TreeScopeAdopter.h in Headers */ = {isa = PBXBuildFile; fileRef = A77E1FEE14AACB6E005B7CB6 /* TreeScopeAdopter.h */; }; 3514 3516 A781C6A713828B5D0012A62A /* DocumentMarker.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A781C6A613828B5D0012A62A /* DocumentMarker.cpp */; }; 3515 3517 A784941B0B5FE507001E237A /* Clipboard.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A784941A0B5FE507001E237A /* Clipboard.cpp */; }; … … 10787 10789 A77B419F12E675A90054343D /* TextEventInputType.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TextEventInputType.h; sourceTree = "<group>"; }; 10788 10790 A77D0011133B0AEB00D6658C /* TextChecking.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TextChecking.h; sourceTree = "<group>"; }; 10791 A77E1FED14AACB6E005B7CB6 /* TreeScopeAdopter.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TreeScopeAdopter.cpp; sourceTree = "<group>"; }; 10792 A77E1FEE14AACB6E005B7CB6 /* TreeScopeAdopter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TreeScopeAdopter.h; sourceTree = "<group>"; }; 10789 10793 A781C6A613828B5D0012A62A /* DocumentMarker.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DocumentMarker.cpp; sourceTree = "<group>"; }; 10790 10794 A784941A0B5FE507001E237A /* Clipboard.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = Clipboard.cpp; sourceTree = "<group>"; }; … … 21463 21467 14D64B5A134A5B6B00E58FDA /* TreeScope.cpp */, 21464 21468 14D64B5B134A5B6B00E58FDA /* TreeScope.h */, 21469 A77E1FED14AACB6E005B7CB6 /* TreeScopeAdopter.cpp */, 21470 A77E1FEE14AACB6E005B7CB6 /* TreeScopeAdopter.h */, 21465 21471 854FE72E0A2297BE0058D7AD /* TreeWalker.cpp */, 21466 21472 854FE72F0A2297BE0058D7AD /* TreeWalker.h */, … … 24715 24721 37FD4298118368460093C029 /* TreeDepthLimit.h in Headers */, 24716 24722 14D64B5D134A5B6B00E58FDA /* TreeScope.h in Headers */, 24723 A77E1FF014AACB6E005B7CB6 /* TreeScopeAdopter.h in Headers */, 24717 24724 1419D2C50CEA6F6100FF507A /* TreeShared.h in Headers */, 24718 24725 854FE7390A2297BE0058D7AD /* TreeWalker.h in Headers */, … … 27649 27656 854FE7360A2297BE0058D7AD /* Traversal.cpp in Sources */, 27650 27657 14D64B5C134A5B6B00E58FDA /* TreeScope.cpp in Sources */, 27658 A77E1FEF14AACB6E005B7CB6 /* TreeScopeAdopter.cpp in Sources */, 27651 27659 854FE7380A2297BE0058D7AD /* TreeWalker.cpp in Sources */, 27652 27660 93309E19099E64920056E581 /* TypingCommand.cpp in Sources */, -
trunk/Source/WebCore/dom/ContainerNode.cpp
r104271 r104528 100 100 // (if the document changed or oldParent was in a shadow tree, AND *this is in a shadow tree). 101 101 // Can we do better? 102 child->setTreeScopeRecursively(treeScope());102 treeScope()->adoptIfNeeded(child.get()); 103 103 if (attached() && !child->attached()) 104 104 child->attach(); … … 176 176 #endif 177 177 178 child->setTreeScopeRecursively(treeScope());178 treeScope()->adoptIfNeeded(child); 179 179 180 180 insertBeforeCommon(next.get(), child); … … 330 330 #endif 331 331 332 child->setTreeScopeRecursively(treeScope());332 treeScope()->adoptIfNeeded(child.get()); 333 333 334 334 // Add child after "prev". … … 510 510 oldChild->setParent(0); 511 511 512 oldChild->setTreeScopeRecursively(document());512 document()->adoptIfNeeded(oldChild); 513 513 514 514 allowEventDispatch(); … … 565 565 n->setNextSibling(0); 566 566 n->setParent(0); 567 n->setTreeScopeRecursively(document());567 document()->adoptIfNeeded(n.get()); 568 568 569 569 m_firstChild = next; … … 650 650 #endif 651 651 652 child->setTreeScopeRecursively(treeScope());652 treeScope()->adoptIfNeeded(child); 653 653 654 654 // Append child to the end of the list … … 698 698 // FIXME: This method should take a PassRefPtr. 699 699 appendChildToContainer<Node, ContainerNode>(newChild.get(), this); 700 newChild->setTreeScopeRecursively(treeScope());700 treeScope()->adoptIfNeeded(newChild.get()); 701 701 702 702 allowEventDispatch(); -
trunk/Source/WebCore/dom/DOMAllInOne.cpp
r104271 r104528 130 130 #include "Traversal.cpp" 131 131 #include "TreeScope.cpp" 132 #include "TreeScopeAdopter.cpp" 132 133 #include "TreeWalker.cpp" 133 134 #include "UIEvent.cpp" -
trunk/Source/WebCore/dom/Document.cpp
r104458 r104528 709 709 m_docType = docType; 710 710 if (m_docType) 711 m_docType->setTreeScopeRecursively(this);711 this->adoptIfNeeded(m_docType.get()); 712 712 // Doctype affects the interpretation of the stylesheets. 713 713 clearStyleSelector(); … … 944 944 } 945 945 946 source->setTreeScopeRecursively(this);946 this->adoptIfNeeded(source.get()); 947 947 948 948 return source; -
trunk/Source/WebCore/dom/Element.cpp
r104404 r104528 1215 1215 1216 1216 oldRoot->setShadowHost(0); 1217 oldRoot->setTreeScopeRecursively(document());1217 document()->adoptIfNeeded(oldRoot.get()); 1218 1218 if (oldRoot->inDocument()) 1219 1219 oldRoot->removedFromDocument(); -
trunk/Source/WebCore/dom/Node.cpp
r104276 r104528 91 91 #include "Text.h" 92 92 #include "TextEvent.h" 93 #include "TreeScopeAdopter.h" 93 94 #include "UIEvent.h" 94 95 #include "UIEventWithKeyState.h" … … 418 419 } 419 420 420 #ifndef NDEBUG421 422 static bool didMoveToNewDocumentWasCalled;423 static Document* oldDocumentDidMoveToNewDocumentWasCalledWith;424 425 #endif426 427 421 void Node::setDocument(Document* document) 428 422 { … … 431 425 return; 432 426 433 document->guardRef();434 435 if (m_document) {436 m_document->moveNodeIteratorsToNewDocument(this, document);437 m_document->guardDeref();438 }439 440 Document* oldDocument = m_document;441 427 m_document = document; 442 443 #ifndef NDEBUG 444 didMoveToNewDocumentWasCalled = false; 445 oldDocumentDidMoveToNewDocumentWasCalledWith = oldDocument; 446 #endif 447 448 didMoveToNewDocument(oldDocument); 449 450 ASSERT(didMoveToNewDocumentWasCalled); 428 } 429 430 NodeRareData* Node::setTreeScope(TreeScope* scope) 431 { 432 if (!scope) { 433 if (hasRareData()) { 434 NodeRareData* data = rareData(); 435 data->setTreeScope(0); 436 return data; 437 } 438 439 return 0; 440 } 441 442 NodeRareData* data = ensureRareData(); 443 data->setTreeScope(scope); 444 return data; 451 445 } 452 446 … … 458 452 TreeScope* scope = rareData()->treeScope(); 459 453 return scope ? scope : m_document; 460 }461 462 void Node::setTreeScopeRecursively(TreeScope* newTreeScope)463 {464 ASSERT(this);465 ASSERT(!isDocumentNode());466 ASSERT(newTreeScope);467 ASSERT(!m_deletionHasBegun);468 469 TreeScope* currentTreeScope = treeScope();470 if (currentTreeScope == newTreeScope)471 return;472 473 Document* currentDocument = document();474 Document* newDocument = newTreeScope->document();475 // If an element is moved from a document and then eventually back again the collection cache for476 // that element may contain stale data as changes made to it will have updated the DOMTreeVersion477 // of the document it was moved to. By increasing the DOMTreeVersion of the donating document here478 // we ensure that the collection cache will be invalidated as needed when the element is moved back.479 if (currentDocument && currentDocument != newDocument)480 currentDocument->incDOMTreeVersion();481 482 for (Node* node = this; node; node = node->traverseNextNode(this)) {483 if (newTreeScope == newDocument) {484 if (node->hasRareData())485 node->rareData()->setTreeScope(0);486 // Setting the new document tree scope will be handled implicitly487 // by setDocument() below.488 } else489 node->ensureRareData()->setTreeScope(newTreeScope);490 491 if (node->hasRareData() && node->rareData()->nodeLists()) {492 node->rareData()->nodeLists()->invalidateCaches();493 if (currentTreeScope)494 currentTreeScope->removeNodeListCache();495 newTreeScope->addNodeListCache();496 }497 498 node->setDocument(newDocument);499 500 if (!node->isElementNode())501 continue;502 if (ShadowRoot* shadowRoot = toElement(node)->shadowRoot()) {503 shadowRoot->setParentTreeScope(newTreeScope);504 if (currentDocument != newDocument)505 shadowRoot->setDocumentRecursively(newDocument);506 }507 }508 454 } 509 455 … … 870 816 { 871 817 return node->isElementNode() ? toElement(node)->shadowRoot() : 0; 872 }873 874 void Node::setDocumentRecursively(Document* newDocument)875 {876 ASSERT(document() != newDocument);877 878 for (Node* node = this; node; node = node->traverseNextNode(this)) {879 node->setDocument(newDocument);880 if (!node->isElementNode())881 continue;882 if (ShadowRoot* shadow = shadowRoot(node))883 shadow->setDocumentRecursively(newDocument);884 }885 818 } 886 819 … … 2436 2369 void Node::didMoveToNewDocument(Document* oldDocument) 2437 2370 { 2438 ASSERT(!didMoveToNewDocumentWasCalled); 2439 ASSERT_UNUSED(oldDocument, oldDocument == oldDocumentDidMoveToNewDocumentWasCalledWith); 2440 2441 #ifndef NDEBUG 2442 didMoveToNewDocumentWasCalled = true; 2443 #endif 2371 TreeScopeAdopter::ensureDidMoveToNewDocumentWasCalled(oldDocument); 2444 2372 2445 2373 // FIXME: Event listener types for this node should be set on the new owner document here. -
trunk/Source/WebCore/dom/Node.h
r104276 r104528 106 106 friend class Document; 107 107 friend class TreeScope; 108 friend class TreeScopeAdopter; 108 109 109 110 public: … … 408 409 TreeScope* treeScope() const; 409 410 410 // Used by the basic DOM methods (e.g., appendChild()).411 void setTreeScopeRecursively(TreeScope*);412 413 411 // Returns true if this node is associated with a document and is in its associated document's 414 412 // node tree, false otherwise. … … 720 718 721 719 private: 722 // Do not use this method to change the document of a node until after the node has been723 // removed from its previous document.724 void setDocumentRecursively(Document*);720 // These API should be only used for a tree scope migration. 721 // setTreeScope() returns NodeRareData to save extra nodeRareData() invocations on the caller site. 722 NodeRareData* setTreeScope(TreeScope*); 725 723 void setDocument(Document*); 726 724 -
trunk/Source/WebCore/dom/TreeScope.cpp
r104271 r104528 32 32 #include "HTMLNames.h" 33 33 #include "NodeRareData.h" 34 #include "TreeScopeAdopter.h" 34 35 35 36 namespace WebCore { … … 138 139 } 139 140 141 void TreeScope::adoptIfNeeded(Node* node) 142 { 143 ASSERT(this); 144 ASSERT(node); 145 ASSERT(!node->isDocumentNode()); 146 ASSERT(!node->m_deletionHasBegun); 147 TreeScopeAdopter adopter(node, this); 148 if (adopter.needsScopeChange()) 149 adopter.execute(); 150 } 151 140 152 } // namespace WebCore 141 153 -
trunk/Source/WebCore/dom/TreeScope.h
r104271 r104528 65 65 virtual bool applyAuthorSheets() const; 66 66 67 // Used by the basic DOM mutation methods (e.g., appendChild()). 68 void adoptIfNeeded(Node*); 69 67 70 protected: 68 71 TreeScope(Document*, ConstructionType = CreateContainer);
Note: See TracChangeset
for help on using the changeset viewer.