Changeset 104259 in webkit
- Timestamp:
- Jan 5, 2012 5:58:34 PM (12 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 2 added
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/CMakeLists.txt
r104197 r104259 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
- Property svn:executable deleted
r104257 r104259 1 2012-01-04 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-05 Jochen Eisinger <jochen@chromium.org> 2 59 -
trunk/Source/WebCore/GNUmakefile.list.am
r104197 r104259 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
r104197 r104259 575 575 dom/Traversal.cpp \ 576 576 dom/TreeScope.cpp \ 577 dom/TreeScopeAdopter.cpp \ 577 578 dom/TreeWalker.cpp \ 578 579 dom/UIEvent.cpp \ … … 1671 1672 dom/TreeDepthLimit.h \ 1672 1673 dom/TreeScope.h \ 1674 dom/TreeScopeAdopter.h \ 1673 1675 dom/TreeWalker.h \ 1674 1676 dom/UIEvent.h \ -
trunk/Source/WebCore/WebCore.gypi
r104199 r104259 5466 5466 'dom/TreeScope.cpp', 5467 5467 'dom/TreeScope.h', 5468 'dom/TreeScopeAdopter.cpp', 5469 'dom/TreeScopeAdopter.h', 5468 5470 'dom/TreeWalker.cpp', 5469 5471 'dom/TreeWalker.h', -
trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj
r104197 r104259 51775 51775 </File> 51776 51776 <File 51777 RelativePath="..\dom\TreeScopeAdopter.cpp" 51778 > 51779 <FileConfiguration 51780 Name="Debug|Win32" 51781 ExcludedFromBuild="true" 51782 > 51783 <Tool 51784 Name="VCCLCompilerTool" 51785 /> 51786 </FileConfiguration> 51787 <FileConfiguration 51788 Name="Release|Win32" 51789 ExcludedFromBuild="true" 51790 > 51791 <Tool 51792 Name="VCCLCompilerTool" 51793 /> 51794 </FileConfiguration> 51795 <FileConfiguration 51796 Name="Debug_Cairo_CFLite|Win32" 51797 ExcludedFromBuild="true" 51798 > 51799 <Tool 51800 Name="VCCLCompilerTool" 51801 /> 51802 </FileConfiguration> 51803 <FileConfiguration 51804 Name="Release_Cairo_CFLite|Win32" 51805 ExcludedFromBuild="true" 51806 > 51807 <Tool 51808 Name="VCCLCompilerTool" 51809 /> 51810 </FileConfiguration> 51811 <FileConfiguration 51812 Name="Debug_All|Win32" 51813 ExcludedFromBuild="true" 51814 > 51815 <Tool 51816 Name="VCCLCompilerTool" 51817 /> 51818 </FileConfiguration> 51819 <FileConfiguration 51820 Name="Production|Win32" 51821 ExcludedFromBuild="true" 51822 > 51823 <Tool 51824 Name="VCCLCompilerTool" 51825 /> 51826 </FileConfiguration> 51827 </File> 51828 <File 51829 RelativePath="..\dom\TreeScopeAdopter.h" 51830 > 51831 </File> 51832 <File 51777 51833 RelativePath="..\dom\TreeWalker.cpp" 51778 51834 > -
trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj
r104254 r104259 3508 3508 A77B41A012E675A90054343D /* TextEventInputType.h in Headers */ = {isa = PBXBuildFile; fileRef = A77B419F12E675A90054343D /* TextEventInputType.h */; settings = {ATTRIBUTES = (Private, ); }; }; 3509 3509 A77D0012133B0AEB00D6658C /* TextChecking.h in Headers */ = {isa = PBXBuildFile; fileRef = A77D0011133B0AEB00D6658C /* TextChecking.h */; settings = {ATTRIBUTES = (Private, ); }; }; 3510 A77E1FEF14AACB6E005B7CB6 /* TreeScopeAdopter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A77E1FED14AACB6E005B7CB6 /* TreeScopeAdopter.cpp */; }; 3511 A77E1FF014AACB6E005B7CB6 /* TreeScopeAdopter.h in Headers */ = {isa = PBXBuildFile; fileRef = A77E1FEE14AACB6E005B7CB6 /* TreeScopeAdopter.h */; }; 3510 3512 A781C6A713828B5D0012A62A /* DocumentMarker.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A781C6A613828B5D0012A62A /* DocumentMarker.cpp */; }; 3511 3513 A784941B0B5FE507001E237A /* Clipboard.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A784941A0B5FE507001E237A /* Clipboard.cpp */; }; … … 10777 10779 A77B419F12E675A90054343D /* TextEventInputType.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TextEventInputType.h; sourceTree = "<group>"; }; 10778 10780 A77D0011133B0AEB00D6658C /* TextChecking.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TextChecking.h; sourceTree = "<group>"; }; 10781 A77E1FED14AACB6E005B7CB6 /* TreeScopeAdopter.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TreeScopeAdopter.cpp; sourceTree = "<group>"; }; 10782 A77E1FEE14AACB6E005B7CB6 /* TreeScopeAdopter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TreeScopeAdopter.h; sourceTree = "<group>"; }; 10779 10783 A781C6A613828B5D0012A62A /* DocumentMarker.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DocumentMarker.cpp; sourceTree = "<group>"; }; 10780 10784 A784941A0B5FE507001E237A /* Clipboard.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = Clipboard.cpp; sourceTree = "<group>"; }; … … 21445 21449 14D64B5A134A5B6B00E58FDA /* TreeScope.cpp */, 21446 21450 14D64B5B134A5B6B00E58FDA /* TreeScope.h */, 21451 A77E1FED14AACB6E005B7CB6 /* TreeScopeAdopter.cpp */, 21452 A77E1FEE14AACB6E005B7CB6 /* TreeScopeAdopter.h */, 21447 21453 854FE72E0A2297BE0058D7AD /* TreeWalker.cpp */, 21448 21454 854FE72F0A2297BE0058D7AD /* TreeWalker.h */, … … 24696 24702 37FD4298118368460093C029 /* TreeDepthLimit.h in Headers */, 24697 24703 14D64B5D134A5B6B00E58FDA /* TreeScope.h in Headers */, 24704 A77E1FF014AACB6E005B7CB6 /* TreeScopeAdopter.h in Headers */, 24698 24705 1419D2C50CEA6F6100FF507A /* TreeShared.h in Headers */, 24699 24706 854FE7390A2297BE0058D7AD /* TreeWalker.h in Headers */, … … 27627 27634 854FE7360A2297BE0058D7AD /* Traversal.cpp in Sources */, 27628 27635 14D64B5C134A5B6B00E58FDA /* TreeScope.cpp in Sources */, 27636 A77E1FEF14AACB6E005B7CB6 /* TreeScopeAdopter.cpp in Sources */, 27629 27637 854FE7380A2297BE0058D7AD /* TreeWalker.cpp in Sources */, 27630 27638 93309E19099E64920056E581 /* TypingCommand.cpp in Sources */, -
trunk/Source/WebCore/dom/ContainerNode.cpp
r102834 r104259 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
r102333 r104259 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
r104060 r104259 713 713 m_docType = docType; 714 714 if (m_docType) 715 m_docType->setTreeScopeRecursively(this);715 this->adoptIfNeeded(m_docType.get()); 716 716 } 717 717 … … 943 943 } 944 944 945 source->setTreeScopeRecursively(this);945 this->adoptIfNeeded(source.get()); 946 946 947 947 return source; -
trunk/Source/WebCore/dom/Element.cpp
r104210 r104259 1222 1222 1223 1223 oldRoot->setShadowHost(0); 1224 oldRoot->setTreeScopeRecursively(document());1224 document()->adoptIfNeeded(oldRoot.get()); 1225 1225 if (oldRoot->inDocument()) 1226 1226 oldRoot->removedFromDocument(); -
trunk/Source/WebCore/dom/Node.cpp
r104210 r104259 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 … … 851 797 { 852 798 return node->isElementNode() ? toElement(node)->shadowRoot() : 0; 853 }854 855 void Node::setDocumentRecursively(Document* newDocument)856 {857 ASSERT(document() != newDocument);858 859 for (Node* node = this; node; node = node->traverseNextNode(this)) {860 node->setDocument(newDocument);861 if (!node->isElementNode())862 continue;863 if (ShadowRoot* shadow = shadowRoot(node))864 shadow->setDocumentRecursively(newDocument);865 }866 799 } 867 800 … … 2409 2342 void Node::didMoveToNewDocument(Document* oldDocument) 2410 2343 { 2411 ASSERT(!didMoveToNewDocumentWasCalled); 2412 ASSERT_UNUSED(oldDocument, oldDocument == oldDocumentDidMoveToNewDocumentWasCalledWith); 2413 2414 #ifndef NDEBUG 2415 didMoveToNewDocumentWasCalled = true; 2416 #endif 2344 TreeScopeAdopter::ensureDidMoveToNewDocumentWasCalled(oldDocument); 2417 2345 2418 2346 // FIXME: Event listener types for this node should be set on the new owner document here. -
trunk/Source/WebCore/dom/Node.h
r104210 r104259 105 105 friend class Document; 106 106 friend class TreeScope; 107 friend class TreeScopeAdopter; 107 108 108 109 public: … … 384 385 TreeScope* treeScope() const; 385 386 386 // Used by the basic DOM methods (e.g., appendChild()).387 void setTreeScopeRecursively(TreeScope*);388 389 387 // Returns true if this node is associated with a document and is in its associated document's 390 388 // node tree, false otherwise. … … 696 694 697 695 private: 698 // Do not use this method to change the document of a node until after the node has been699 // removed from its previous document.700 void setDocumentRecursively(Document*);696 // These API should be only used for a tree scope migration. 697 // setTreeScope() returns NodeRareData to save extra nodeRareData() invocations on the caller site. 698 NodeRareData* setTreeScope(TreeScope*); 701 699 void setDocument(Document*); 702 700 -
trunk/Source/WebCore/dom/TreeScope.cpp
r96782 r104259 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
r96782 r104259 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.