Changeset 84050 in webkit
- Timestamp:
- Apr 15, 2011 4:47:24 PM (13 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r84049 r84050 1 2011-04-15 Roland Steiner <rolandsteiner@chromium.org> 2 3 Reviewed by Dimitri Glazkov. 4 5 Bug 52963 - Enable O(1) access to root from any node in shadow DOM subtree 6 https://bugs.webkit.org/show_bug.cgi?id=52963 7 8 .) Change base class of ShadowRoot from DocumentFragment to TreeScope. 9 .) Re-enable tree scope handling in Node (had ASSERT_NOT_REACHED, etc.). 10 .) Merged setTreeScope() with setTreeScopeRecursively() 11 .) Call setTreeScopeRecursively in DOM manipulation functions where applicable. 12 13 No new tests. (refactoring) 14 15 * dom/ContainerNode.cpp: 16 (WebCore::ContainerNode::takeAllChildrenFrom): 17 (WebCore::ContainerNode::removeBetween): 18 (WebCore::ContainerNode::removeChildren): 19 (WebCore::ContainerNode::parserAddChild): 20 * dom/Document.cpp: 21 (WebCore::Document::Document): 22 (WebCore::Document::~Document): 23 (WebCore::Document::setDocType): 24 * dom/Element.h: 25 * dom/Node.cpp: 26 (WebCore::Node::treeScope): 27 (WebCore::Node::setTreeScopeRecursively): 28 * dom/Node.h: 29 (WebCore::Node::document): 30 * dom/ShadowRoot.cpp: 31 (WebCore::ShadowRoot::ShadowRoot): 32 (WebCore::ShadowRoot::~ShadowRoot): 33 (WebCore::ShadowRoot::nodeType): 34 (WebCore::ShadowRoot::cloneNode): 35 (WebCore::ShadowRoot::childTypeAllowed): 36 * dom/ShadowRoot.h: 37 (WebCore::toShadowRoot): 38 * dom/TreeScope.cpp: 39 (WebCore::TreeScope::TreeScope): 40 (WebCore::TreeScope::setParentTreeScope): 41 * dom/TreeScope.h: 42 * rendering/RenderSlider.cpp: 43 1 44 2011-04-15 Geoffrey Garen <ggaren@apple.com> 2 45 -
trunk/Source/WebCore/dom/ContainerNode.cpp
r83349 r84050 91 91 ASSERT(!ec); 92 92 parserAddChild(child.get()); 93 // FIXME: Together with adoptNode above, the tree scope might get updated recursively twice 94 // (if the document changed or oldParent was in a shadow tree, AND *this is in a shadow tree). 95 // Can we do better? 96 child->setTreeScopeRecursively(treeScope()); 93 97 if (attached() && !child->attached()) 94 98 child->attach(); … … 482 486 oldChild->setParent(0); 483 487 488 oldChild->setTreeScopeRecursively(document()); 489 484 490 allowEventDispatch(); 485 491 } … … 531 537 n->setNextSibling(0); 532 538 n->setParent(0); 539 n->setTreeScopeRecursively(document()); 533 540 534 541 m_firstChild = next; … … 649 656 // FIXME: This method should take a PassRefPtr. 650 657 appendChildToContainer<Node, ContainerNode>(newChild.get(), this); 658 newChild->setTreeScopeRecursively(treeScope()); 659 651 660 allowEventDispatch(); 652 661 -
trunk/Source/WebCore/dom/Document.cpp
r83990 r84050 378 378 379 379 Document::Document(Frame* frame, const KURL& url, bool isXHTML, bool isHTML) 380 : TreeScope( this)380 : TreeScope(0) 381 381 , m_guardRefCount(0) 382 382 , m_compatibilityMode(NoQuirksMode) … … 435 435 , m_writeRecursionDepth(0) 436 436 { 437 437 438 m_document = this; 438 439 … … 515 516 ASSERT(!m_styleRecalcTimer.isActive()); 516 517 ASSERT(!m_parentTreeScope); 518 ASSERT(!m_guardRefCount); 517 519 518 520 m_scriptRunner.clear(); … … 666 668 m_docType = docType; 667 669 if (m_docType) 668 m_docType->setTreeScope (this);670 m_docType->setTreeScopeRecursively(this); 669 671 } 670 672 -
trunk/Source/WebCore/dom/Element.h
r83816 r84050 40 40 class ElementRareData; 41 41 class IntSize; 42 class ShadowRoot; 42 43 class WebKitAnimationList; 43 44 … … 230 231 virtual void recalcStyle(StyleChange = NoChange); 231 232 233 // FIXME: Make these return a proper ShadowRoot* (bug 58703). 232 234 ContainerNode* shadowRoot() const; 233 235 ContainerNode* ensureShadowRoot(); -
trunk/Source/WebCore/dom/Node.cpp
r84039 r84050 78 78 #include "ScriptController.h" 79 79 #include "SelectorNodeList.h" 80 #include "ShadowRoot.h" 80 81 #include "StaticNodeList.h" 81 82 #include "TagNodeList.h" … … 469 470 TreeScope* Node::treeScope() const 470 471 { 472 // FIXME: Using m_document directly is not good -> see comment with document() in the header file. 471 473 if (!hasRareData()) 472 return document();474 return m_document; 473 475 TreeScope* scope = rareData()->treeScope(); 474 // FIXME: Until we land shadow scopes, there should be no non-document scopes. 475 ASSERT(!scope); 476 return scope ? scope : document(); 477 } 478 479 void Node::setTreeScope(TreeScope* newTreeScope) 480 { 481 ASSERT(!isDocumentNode()); 476 return scope ? scope : m_document; 477 } 478 479 void Node::setTreeScopeRecursively(TreeScope* newTreeScope, bool includeRoot) 480 { 481 ASSERT(this); 482 ASSERT(!includeRoot || !isDocumentNode()); 482 483 ASSERT(newTreeScope); 483 ASSERT(!inDocument() || treeScope() == newTreeScope); 484 485 if (newTreeScope->isDocumentNode()) { 486 if (hasRareData()) 487 rareData()->setTreeScope(0); 488 // Setting the new document scope will be handled implicitly 489 // by setDocument() below. 490 } else { 491 // FIXME: Until we land shadow scopes, this branch should be inert. 492 ASSERT_NOT_REACHED(); 493 ensureRareData()->setTreeScope(newTreeScope); 494 } 495 496 setDocument(newTreeScope->document()); 497 } 498 499 void Node::setTreeScopeRecursively(TreeScope* newTreeScope) 500 { 501 ASSERT(!isDocumentNode()); 502 ASSERT(newTreeScope); 503 if (treeScope() == newTreeScope) 484 ASSERT(!m_deletionHasBegun); 485 486 TreeScope* currentTreeScope = treeScope(); 487 if (currentTreeScope == newTreeScope) 504 488 return; 505 489 … … 513 497 currentDocument->incDOMTreeVersion(); 514 498 515 for (Node* node = this; node; node = node->traverseNextNode(this)) { 516 node->setTreeScope(newTreeScope); 517 // FIXME: Once shadow scopes are landed, update parent scope, etc. 499 for (Node* node = includeRoot ? this : traverseNextNode(this); node; node = node->traverseNextNode(this)) { 500 if (newTreeScope == newDocument) { 501 if (node->hasRareData()) 502 node->rareData()->setTreeScope(0); 503 // Setting the new document tree scope will be handled implicitly 504 // by setDocument() below. 505 } else 506 node->ensureRareData()->setTreeScope(newTreeScope); 507 508 node->setDocument(newDocument); 509 510 if (!node->isElementNode()) 511 continue; 512 // FIXME: Remove toShadowRoot() once shadowRoot() returns a proper ShadowRoot* (bug 58703). 513 if (ShadowRoot* shadowRoot = toShadowRoot(toElement(node)->shadowRoot())) { 514 shadowRoot->setParentTreeScope(newTreeScope); 515 if (currentDocument != newDocument) 516 shadowRoot->setDocumentRecursively(newDocument); 517 } 518 518 } 519 519 } -
trunk/Source/WebCore/dom/Node.h
r84039 r84050 353 353 { 354 354 ASSERT(this); 355 // FIXME: below ASSERT is useful, but prevents the use of document() in the constructor or destructor 356 // due to the virtual function call to nodeType(). 355 357 ASSERT(m_document || (nodeType() == DOCUMENT_TYPE_NODE && !inDocument())); 356 358 return m_document; … … 359 361 TreeScope* treeScope() const; 360 362 361 // Do not use this method to change the scope of a node until after the node has been362 // removed from its previous scope. Do not use to change documents.363 void setTreeScope(TreeScope*);364 365 363 // Used by the basic DOM methods (e.g., appendChild()). 366 void setTreeScopeRecursively(TreeScope* );364 void setTreeScopeRecursively(TreeScope*, bool includeRoot = true); 367 365 368 366 // Returns true if this node is associated with a document and is in its associated document's -
trunk/Source/WebCore/dom/ShadowRoot.cpp
r83796 r84050 28 28 #include "ShadowRoot.h" 29 29 30 #include "Document.h" 31 #include "NodeRareData.h" 32 30 33 namespace WebCore { 31 34 32 35 ShadowRoot::ShadowRoot(Document* document) 33 : DocumentFragment(document)36 : TreeScope(document) 34 37 { 35 38 ASSERT(document); 39 40 // Assume document as parent scope. 41 setParentTreeScope(document); 42 // Shadow tree scopes have the scope pointer point to themselves. 43 // This way, direct children will receive the correct scope pointer. 44 ensureRareData()->setTreeScope(this); 45 } 46 47 ShadowRoot::~ShadowRoot() 48 { 36 49 } 37 50 … … 39 52 { 40 53 return "#shadow-root"; 54 } 55 56 Node::NodeType ShadowRoot::nodeType() const 57 { 58 // FIXME: Decide correct node type (bug 58704). 59 return DOCUMENT_FRAGMENT_NODE; 60 } 61 62 PassRefPtr<Node> ShadowRoot::cloneNode(bool) 63 { 64 // ShadowRoot should not be arbitrarily cloned. 65 return 0; 66 } 67 68 bool ShadowRoot::childTypeAllowed(NodeType type) const 69 { 70 switch (type) { 71 case ELEMENT_NODE: 72 case PROCESSING_INSTRUCTION_NODE: 73 case COMMENT_NODE: 74 case TEXT_NODE: 75 case CDATA_SECTION_NODE: 76 case ENTITY_REFERENCE_NODE: 77 return true; 78 default: 79 return false; 80 } 41 81 } 42 82 -
trunk/Source/WebCore/dom/ShadowRoot.h
r83796 r84050 28 28 #define ShadowRoot_h 29 29 30 #include " DocumentFragment.h"30 #include "TreeScope.h" 31 31 32 32 namespace WebCore { … … 34 34 class Document; 35 35 36 class ShadowRoot : public DocumentFragment{36 class ShadowRoot : public TreeScope { 37 37 public: 38 38 static PassRefPtr<ShadowRoot> create(Document*); … … 43 43 private: 44 44 ShadowRoot(Document*); 45 virtual ~ShadowRoot(); 46 45 47 virtual String nodeName() const; 48 virtual NodeType nodeType() const; 49 virtual PassRefPtr<Node> cloneNode(bool deep); 50 virtual bool childTypeAllowed(NodeType) const; 46 51 }; 47 52 … … 51 56 } 52 57 58 inline ShadowRoot* toShadowRoot(Node* node) 59 { 60 ASSERT(!node || node->isShadowBoundary()); 61 return static_cast<ShadowRoot*>(node); 62 } 63 53 64 } // namespace 54 65 -
trunk/Source/WebCore/dom/TreeScope.cpp
r83349 r84050 37 37 using namespace HTMLNames; 38 38 39 TreeScope::TreeScope(Document* document , ConstructionType constructionType)40 : ContainerNode( 0, constructionType)39 TreeScope::TreeScope(Document* document) 40 : ContainerNode(document) 41 41 , m_parentTreeScope(0) 42 42 , m_accessKeyMapValid(false) 43 43 , m_numNodeListCaches(0) 44 44 { 45 m_document = document;46 if (document != this) {47 // Assume document as parent scope48 m_parentTreeScope = document;49 // FIXME: This branch should be inert until shadow scopes are landed.50 ASSERT_NOT_REACHED();51 }52 45 } 53 46 … … 70 63 ASSERT(!isDocumentNode()); 71 64 // Every scope other than document needs a parent scope. 72 ASSERT(m_parentTreeScope);73 65 ASSERT(newParentScope); 74 66 -
trunk/Source/WebCore/dom/TreeScope.h
r83349 r84050 40 40 public: 41 41 TreeScope* parentTreeScope() const { return m_parentTreeScope; } 42 void setParentTreeScope(TreeScope*); 42 43 43 44 Element* getElementById(const AtomicString&) const; … … 66 67 67 68 protected: 68 TreeScope(Document*, ConstructionType = CreateContainer); 69 69 TreeScope(Document*); 70 70 virtual ~TreeScope(); 71 71 72 72 void destroyTreeScopeData(); 73 74 void setParentTreeScope(TreeScope*);75 73 76 74 private: -
trunk/Source/WebCore/rendering/RenderSlider.cpp
r83256 r84050 38 38 #include "RenderTheme.h" 39 39 #include "RenderView.h" 40 #include "Shadow Element.h"40 #include "ShadowRoot.h" 41 41 #include "SliderThumbElement.h" 42 42 #include "StepRange.h"
Note: See TracChangeset
for help on using the changeset viewer.