void MarkupAccumulator::serializeNodesWithNamespaces(Node* targetNode, Node* nodeToSkip, EChildrenOnly childrenOnly, const Namespaces* namespaces, Vector<QualifiedName>* tagNamesToSkip) { if (targetNode == nodeToSkip) return; if (tagNamesToSkip) { for (size_t i = 0; i < tagNamesToSkip->size(); ++i) { if (targetNode->hasTagName(tagNamesToSkip->at(i))) return; } } Namespaces namespaceHash; if (namespaces) namespaceHash = *namespaces; if (!childrenOnly) appendStartTag(targetNode, &namespaceHash); if (!(targetNode->document()->isHTMLDocument() && elementCannotHaveEndTag(targetNode))) { #if ENABLE(TEMPLATE_ELEMENT) Node* current = targetNode->hasTagName(templateTag) ? toHTMLTemplateElement(targetNode)->content()->firstChild() : targetNode->firstChild(); #else Node* current = targetNode->firstChild(); #endif for ( ; current; current = current->nextSibling()) serializeNodesWithNamespaces(current, nodeToSkip, IncludeNode, &namespaceHash, tagNamesToSkip); } if (!childrenOnly) appendEndTag(targetNode); }
void MarkupAccumulator::serializeNodesWithNamespaces(Node& targetNode, EChildrenOnly childrenOnly, const Namespaces* namespaces, Vector<QualifiedName>* tagNamesToSkip) { if (tagNamesToSkip) { for (size_t i = 0; i < tagNamesToSkip->size(); ++i) { if (targetNode.hasTagName(tagNamesToSkip->at(i))) return; } } Namespaces namespaceHash; if (namespaces) namespaceHash = *namespaces; if (!childrenOnly) appendStartTag(targetNode, &namespaceHash); if (!(serializeAsHTMLDocument(targetNode) && elementCannotHaveEndTag(targetNode))) { Node* current = isHTMLTemplateElement(targetNode) ? toHTMLTemplateElement(targetNode).content()->firstChild() : targetNode.firstChild(); for ( ; current; current = current->nextSibling()) serializeNodesWithNamespaces(*current, IncludeNode, &namespaceHash, tagNamesToSkip); } if (!childrenOnly) appendEndTag(targetNode); }
void HTMLElement::setInnerHTML(const String& html, ExceptionState& es) { if (RefPtr<DocumentFragment> fragment = createFragmentForInnerOuterHTML(html, this, AllowScriptingContent, es)) { ContainerNode* container = this; if (hasLocalName(templateTag)) container = toHTMLTemplateElement(this)->content(); replaceChildrenWithFragment(container, fragment.release(), es); } }
void HTMLElement::setInnerHTML(const String& html, ExceptionCode& ec) { if (RefPtr<DocumentFragment> fragment = createFragmentForInnerOuterHTML(html, this, AllowScriptingContent, ec)) { ContainerNode* container = this; #if ENABLE(TEMPLATE_ELEMENT) if (hasLocalName(templateTag)) container = toHTMLTemplateElement(this)->content(); #endif replaceChildrenWithFragment(container, fragment.release(), ec); } }
void HTMLConstructionSite::insertTextNode(const String& string, WhitespaceMode whitespaceMode) { HTMLConstructionSiteTask dummyTask(HTMLConstructionSiteTask::Insert); dummyTask.parent = currentNode(); // FIXME: This probably doesn't need to be done both here and in insert(Task). if (isHTMLTemplateElement(*dummyTask.parent)) dummyTask.parent = toHTMLTemplateElement(dummyTask.parent.get())->content(); // Unclear when parent != case occurs. Somehow we insert text into two separate // nodes while processing the same Token. When it happens we have to flush the // pending text into the task queue before making more. if (!m_pendingText.isEmpty() && (m_pendingText.parent != dummyTask.parent)) flushPendingText(); m_pendingText.append(dummyTask.parent, string, whitespaceMode); }
bool traverseTree(Node* rootNode, WillBeHeapVector<RawPtrWillBeMember<Node>, initialNodeVectorSize>* partiallyDependentNodes) { // To make each minor GC time bounded, we might need to give up // traversing at some point for a large DOM tree. That being said, // I could not observe the need even in pathological test cases. for (Node& node : NodeTraversal::startsAt(rootNode)) { if (node.containsWrapper()) { if (!node.isV8CollectableDuringMinorGC()) { // This node is not in the new space of V8. This indicates that // the minor GC cannot anyway judge reachability of this DOM tree. // Thus we give up traversing the DOM tree. return false; } node.clearV8CollectableDuringMinorGC(); partiallyDependentNodes->append(&node); } if (ShadowRoot* shadowRoot = node.youngestShadowRoot()) { if (!traverseTree(shadowRoot, partiallyDependentNodes)) return false; } else if (node.isShadowRoot()) { if (ShadowRoot* shadowRoot = toShadowRoot(node).olderShadowRoot()) { if (!traverseTree(shadowRoot, partiallyDependentNodes)) return false; } } // <template> has a |content| property holding a DOM fragment which we must traverse, // just like we do for the shadow trees above. if (isHTMLTemplateElement(node)) { if (!traverseTree(toHTMLTemplateElement(node).content(), partiallyDependentNodes)) return false; } // Document maintains the list of imported documents through HTMLImportsController. if (node.isDocumentNode()) { Document& document = toDocument(node); HTMLImportsController* controller = document.importsController(); if (controller && document == controller->master()) { for (unsigned i = 0; i < controller->loaderCount(); ++i) { if (!traverseTree(controller->loaderDocumentAt(i), partiallyDependentNodes)) return false; } } } } return true; }
void MarkupAccumulator::serializeNodesWithNamespaces(Node& targetNode, Node* nodeToSkip, EChildrenOnly childrenOnly, const Namespaces* namespaces, Vector<QualifiedName>* tagNamesToSkip) { if (&targetNode == nodeToSkip) return; if (tagNamesToSkip && targetNode.isElementNode()) { for (size_t i = 0; i < tagNamesToSkip->size(); ++i) { if (targetNode.hasTagName(tagNamesToSkip->at(i))) return; } } Namespaces namespaceHash; if (namespaces) namespaceHash = *namespaces; else if (inXMLFragmentSerialization()) { // Make sure xml prefix and namespace are always known to uphold the constraints listed at http://www.w3.org/TR/xml-names11/#xmlReserved. namespaceHash.set(xmlAtom.impl(), XMLNames::xmlNamespaceURI.impl()); namespaceHash.set(XMLNames::xmlNamespaceURI.impl(), xmlAtom.impl()); } if (!childrenOnly) appendStartTag(targetNode, &namespaceHash); if (!(targetNode.document().isHTMLDocument() && elementCannotHaveEndTag(targetNode))) { #if ENABLE(TEMPLATE_ELEMENT) Node* current = targetNode.hasTagName(templateTag) ? toHTMLTemplateElement(targetNode).content()->firstChild() : targetNode.firstChild(); #else Node* current = targetNode.firstChild(); #endif for ( ; current; current = current->nextSibling()) serializeNodesWithNamespaces(*current, nodeToSkip, IncludeNode, &namespaceHash, tagNamesToSkip); } if (!childrenOnly) appendEndTag(targetNode); }
static inline void insert(HTMLConstructionSiteTask& task) { if (isHTMLTemplateElement(*task.parent)) task.parent = toHTMLTemplateElement(task.parent.get())->content(); task.parent->parserAppendChild(task.child.get()); }
inline Document& HTMLConstructionSite::ownerDocumentForCurrentNode() { if (isHTMLTemplateElement(*currentNode())) return toHTMLTemplateElement(currentElement())->content()->document(); return currentNode()->document(); }