/** This is the master routine invoked to visit the nodes * selected by this range. For each such node, different * actions are taken depending on the value of the TraversalType argument. */ DOM_DocumentFragment RangeImpl::traverseContents(TraversalType how) { if (fDetached) throw DOM_DOMException(DOM_DOMException::INVALID_STATE_ERR, null); if (fStartContainer == null || fEndContainer == null) { return DOM_DocumentFragment(); // REVIST: Throw exception? } /* Traversal is accomplished by first determining the relationship between the endpoints of the range. For each of four significant relationships, we will delegate the traversal call to a method that can make appropriate assumptions. */ // case 1: same container if ( fStartContainer == fEndContainer ) return traverseSameContainer( how ); // case 2: Child C of start container is ancestor of end container for (DOM_Node node = fStartContainer.getFirstChild(); node != null; node=node.getNextSibling()) { if (isAncestorOf(node, fEndContainer)) return traverseCommonStartContainer( node, how ); } // case 3: Child C of end container is ancestor of start container for (DOM_Node nd = fEndContainer.getFirstChild(); nd != null; nd=nd.getNextSibling()) { if (isAncestorOf(nd, fStartContainer)) return traverseCommonEndContainer( nd, how ); } // case 4: preorder traversal of context tree. // There is a common ancestor container. Find the // ancestor siblings that are children of that container. DOM_Node ancestor = commonAncestorOf(fStartContainer, fEndContainer); return traverseCommonAncestors( ancestor, ancestor, how ); }
DOM_DocumentFragment DOM_Document::createDocumentFragment() { return DOM_DocumentFragment(((DocumentImpl *)fImpl)->createDocumentFragment()); };