Changeset 84394 in webkit
- Timestamp:
- Apr 20, 2011 10:25:33 AM (13 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r84389 r84394 1 2011-04-19 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 .) Adapt JavaScript Node wrappers (temporary code - see https://bugs.webkit.org/show_bug.cgi?id=58704). 13 14 No new tests. (refactoring) 15 16 * bindings/js/JSNodeCustom.cpp: 17 (WebCore::createWrapperInline): 18 * bindings/v8/custom/V8NodeCustom.cpp: 19 (WebCore::toV8Slow): 20 * dom/ContainerNode.cpp: 21 (WebCore::ContainerNode::takeAllChildrenFrom): 22 (WebCore::ContainerNode::removeBetween): 23 (WebCore::ContainerNode::removeChildren): 24 (WebCore::ContainerNode::parserAddChild): 25 * dom/Document.cpp: 26 (WebCore::Document::Document): 27 (WebCore::Document::~Document): 28 (WebCore::Document::setDocType): 29 * dom/Element.h: 30 * dom/Node.cpp: 31 (WebCore::Node::treeScope): 32 (WebCore::Node::setTreeScopeRecursively): 33 * dom/Node.h: 34 (WebCore::Node::document): 35 * dom/ShadowRoot.cpp: 36 (WebCore::ShadowRoot::ShadowRoot): 37 (WebCore::ShadowRoot::~ShadowRoot): 38 (WebCore::ShadowRoot::nodeType): 39 (WebCore::ShadowRoot::cloneNode): 40 (WebCore::ShadowRoot::childTypeAllowed): 41 * dom/ShadowRoot.h: 42 (WebCore::toShadowRoot): 43 * dom/TreeScope.cpp: 44 (WebCore::TreeScope::TreeScope): 45 (WebCore::TreeScope::setParentTreeScope): 46 * dom/TreeScope.h: 47 * rendering/RenderSlider.cpp: 48 1 49 2011-04-20 Vsevolod Vlasov <vsevik@chromium.org> 2 50 -
trunk/Source/WebCore/bindings/js/JSNodeCustom.cpp
r84194 r84394 64 64 #include "ProcessingInstruction.h" 65 65 #include "RegisteredEventListener.h" 66 #include "ShadowRoot.h" 66 67 #include "StyleSheet.h" 67 68 #include "StyledElement.h" … … 291 292 break; 292 293 case Node::DOCUMENT_FRAGMENT_NODE: 293 wrapper = CREATE_DOM_NODE_WRAPPER(exec, globalObject, DocumentFragment, node); 294 // FIXME: remove 'if' once ShadowRoot gets its own node type (see bug 58704) 295 if (node->isShadowBoundary()) 296 wrapper = CREATE_DOM_NODE_WRAPPER(exec, globalObject, Node, node); 297 else 298 wrapper = CREATE_DOM_NODE_WRAPPER(exec, globalObject, DocumentFragment, node); 294 299 break; 295 300 case Node::ENTITY_REFERENCE_NODE: -
trunk/Source/WebCore/bindings/v8/custom/V8NodeCustom.cpp
r74646 r84394 34 34 #include "Document.h" 35 35 #include "EventListener.h" 36 #include "ShadowRoot.h" 36 37 37 38 #include "V8AbstractEventListener.h" … … 163 164 return toV8(static_cast<DocumentType*>(impl), forceNewObject); 164 165 case Node::DOCUMENT_FRAGMENT_NODE: 166 // FIXME: remove 'if' once ShadowRoot gets its own node type (see bug 58704) 167 if (impl->isShadowBoundary()) 168 return toV8(static_cast<ShadowRoot*>(impl), forceNewObject); 165 169 return toV8(static_cast<DocumentFragment*>(impl), forceNewObject); 166 170 case Node::NOTATION_NODE: -
trunk/Source/WebCore/dom/ContainerNode.cpp
r84251 r84394 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
r84251 r84394 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) … … 514 514 ASSERT(!m_styleRecalcTimer.isActive()); 515 515 ASSERT(!m_parentTreeScope); 516 ASSERT(!m_guardRefCount); 516 517 517 518 m_scriptRunner.clear(); … … 671 672 m_docType = docType; 672 673 if (m_docType) 673 m_docType->setTreeScope (this);674 m_docType->setTreeScopeRecursively(this); 674 675 } 675 676 -
trunk/Source/WebCore/dom/Element.h
r84251 r84394 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
r84371 r84394 77 77 #include "ScopedEventQueue.h" 78 78 #include "SelectorNodeList.h" 79 #include "ShadowRoot.h" 79 80 #include "StaticNodeList.h" 80 81 #include "TagNodeList.h" … … 468 469 TreeScope* Node::treeScope() const 469 470 { 471 // FIXME: Using m_document directly is not good -> see comment with document() in the header file. 470 472 if (!hasRareData()) 471 return document();473 return m_document; 472 474 TreeScope* scope = rareData()->treeScope(); 473 // FIXME: Until we land shadow scopes, there should be no non-document scopes. 474 ASSERT(!scope); 475 return scope ? scope : document(); 476 } 477 478 void Node::setTreeScope(TreeScope* newTreeScope) 479 { 480 ASSERT(!isDocumentNode()); 475 return scope ? scope : m_document; 476 } 477 478 void Node::setTreeScopeRecursively(TreeScope* newTreeScope, bool includeRoot) 479 { 480 ASSERT(this); 481 ASSERT(!includeRoot || !isDocumentNode()); 481 482 ASSERT(newTreeScope); 482 ASSERT(!inDocument() || treeScope() == newTreeScope); 483 484 if (newTreeScope->isDocumentNode()) { 485 if (hasRareData()) 486 rareData()->setTreeScope(0); 487 // Setting the new document scope will be handled implicitly 488 // by setDocument() below. 489 } else { 490 // FIXME: Until we land shadow scopes, this branch should be inert. 491 ASSERT_NOT_REACHED(); 492 ensureRareData()->setTreeScope(newTreeScope); 493 } 494 495 setDocument(newTreeScope->document()); 496 } 497 498 void Node::setTreeScopeRecursively(TreeScope* newTreeScope) 499 { 500 ASSERT(!isDocumentNode()); 501 ASSERT(newTreeScope); 502 if (treeScope() == newTreeScope) 483 ASSERT(!m_deletionHasBegun); 484 485 TreeScope* currentTreeScope = treeScope(); 486 if (currentTreeScope == newTreeScope) 503 487 return; 504 488 … … 512 496 currentDocument->incDOMTreeVersion(); 513 497 514 for (Node* node = this; node; node = node->traverseNextNode(this)) { 515 node->setTreeScope(newTreeScope); 516 // FIXME: Once shadow scopes are landed, update parent scope, etc. 498 for (Node* node = includeRoot ? this : traverseNextNode(this); node; node = node->traverseNextNode(this)) { 499 if (newTreeScope == newDocument) { 500 if (node->hasRareData()) 501 node->rareData()->setTreeScope(0); 502 // Setting the new document tree scope will be handled implicitly 503 // by setDocument() below. 504 } else 505 node->ensureRareData()->setTreeScope(newTreeScope); 506 507 node->setDocument(newDocument); 508 509 if (!node->isElementNode()) 510 continue; 511 // FIXME: Remove toShadowRoot() once shadowRoot() returns a proper ShadowRoot* (bug 58703). 512 if (ShadowRoot* shadowRoot = toShadowRoot(toElement(node)->shadowRoot())) { 513 shadowRoot->setParentTreeScope(newTreeScope); 514 if (currentDocument != newDocument) 515 shadowRoot->setDocumentRecursively(newDocument); 516 } 517 517 } 518 518 } -
trunk/Source/WebCore/dom/Node.h
r84309 r84394 360 360 { 361 361 ASSERT(this); 362 // FIXME: below ASSERT is useful, but prevents the use of document() in the constructor or destructor 363 // due to the virtual function call to nodeType(). 362 364 ASSERT(m_document || (nodeType() == DOCUMENT_TYPE_NODE && !inDocument())); 363 365 return m_document; … … 366 368 TreeScope* treeScope() const; 367 369 368 // Do not use this method to change the scope of a node until after the node has been369 // removed from its previous scope. Do not use to change documents.370 void setTreeScope(TreeScope*);371 372 370 // Used by the basic DOM methods (e.g., appendChild()). 373 void setTreeScopeRecursively(TreeScope* );371 void setTreeScopeRecursively(TreeScope*, bool includeRoot = true); 374 372 375 373 // Returns true if this node is associated with a document and is in its associated document's -
trunk/Source/WebCore/dom/ShadowRoot.cpp
r84251 r84394 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
r84251 r84394 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
r84251 r84394 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
r84251 r84394 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
r84251 r84394 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.