static Node* determineScopingNodeForStyleScoped(HTMLStyleElement* ownerElement, StyleSheetContents* styleSheetContents) { ASSERT(ownerElement && ownerElement->isRegisteredAsScoped()); if (ownerElement->isInShadowTree()) { if (hasDistributedRule(styleSheetContents)) { ContainerNode* scope = ownerElement; do { scope = scope->containingShadowRoot()->shadowHost(); } while (scope->isInShadowTree()); return scope; } if (ownerElement->isRegisteredAsScoped()) return ownerElement->containingShadowRoot()->shadowHost(); } return ownerElement->isRegisteredInShadowRoot() ? ownerElement->containingShadowRoot()->shadowHost() : ownerElement->parentNode(); }
void writeQosParams( ContainerNode &node, const pj_qos_params &qos) throw(Error) { ContainerNode this_node = node.writeNewContainer("qosParams"); NODE_WRITE_NUM_T( this_node, pj_uint8_t, qos.flags); NODE_WRITE_NUM_T( this_node, pj_uint8_t, qos.dscp_val); NODE_WRITE_NUM_T( this_node, pj_uint8_t, qos.so_prio); NODE_WRITE_NUM_T( this_node, pj_qos_wmm_prio, qos.wmm_prio); }
void readIntVector( ContainerNode &node, const string &array_name, IntVector &v) throw(Error) { ContainerNode array_node = node.readArray(array_name); v.resize(0); while (array_node.hasUnread()) { v.push_back((int)array_node.readNumber()); } }
void readQosParams( ContainerNode &node, pj_qos_params &qos) throw(Error) { ContainerNode this_node = node.readContainer("qosParams"); NODE_READ_NUM_T( this_node, pj_uint8_t, qos.flags); NODE_READ_NUM_T( this_node, pj_uint8_t, qos.dscp_val); NODE_READ_NUM_T( this_node, pj_uint8_t, qos.so_prio); NODE_READ_NUM_T( this_node, pj_qos_wmm_prio, qos.wmm_prio); }
static void notifyDescendantInsertedIntoDocument(ContainerNode& insertionPoint, ContainerNode& node, NodeVector& postInsertionNotificationTargets) { ChildNodesLazySnapshot snapshot(node); while (RefPtr<Node> child = snapshot.nextNode()) { // If we have been removed from the document during this loop, then // we don't want to tell the rest of our children that they've been // inserted into the document because they haven't. if (node.inDocument() && child->parentNode() == &node) notifyNodeInsertedIntoDocument(insertionPoint, *child, postInsertionNotificationTargets); } if (!is<Element>(node)) return; if (RefPtr<ShadowRoot> root = downcast<Element>(node).shadowRoot()) { if (node.inDocument() && root->host() == &node) notifyNodeInsertedIntoDocument(insertionPoint, *root, postInsertionNotificationTargets); } }
void HTMLConstructionSite::findFosterSite(HTMLConstructionSiteTask& task) { HTMLElementStack::ElementRecord* lastTableElementRecord = m_openElements.topmost(tableTag.localName()); if (lastTableElementRecord) { Element* lastTableElement = lastTableElementRecord->element(); ContainerNode* parent = lastTableElement->parentNode(); // When parsing HTML fragments, we skip step 4.2 ("Let root be a new html element with no attributes") for efficiency, // and instead use the DocumentFragment as a root node. So we must treat the root node (DocumentFragment) as if it is a html element here. if (parent && (parent->isElementNode() || (m_isParsingFragment && parent == m_openElements.rootNode()))) { task.parent = parent; task.nextChild = lastTableElement; return; } task.parent = lastTableElementRecord->next()->element(); return; } // Fragment case task.parent = m_openElements.rootNode(); // DocumentFragment }
XMLTreeBuilder::XMLTreeBuilder(NewXMLDocumentParser* parser, DocumentFragment* fragment, Element* parent) : m_document(fragment->document()) , m_parser(parser) , m_isXHTML(false) , m_sawFirstElement(true) { NodeStackItem stackItem(fragment); // Figure out namespaces Vector<Element*> nodeStack; while (parent) { nodeStack.append(parent); ContainerNode* node = parent->parentNode(); if (!node || !node->isElementNode()) break; parent = static_cast<Element*>(node); } if (nodeStack.isEmpty()) { m_currentNodeStack.append(stackItem); return; } for (Element* element; !nodeStack.isEmpty(); nodeStack.removeLast()) { element = nodeStack.last(); if (element->hasAttributes()) { for (size_t i = 0; i < element->attributeCount(); ++i) { const Attribute* attribute = element->attributeItem(i); if (attribute->localName() == xmlnsAtom) stackItem.setNamespaceURI(attribute->value()); else if (attribute->prefix() == xmlnsAtom) stackItem.setNamespaceURI(attribute->localName(), attribute->value()); } } } // If the parent element is not in document tree, there may be no xmlns attribute; just default to the parent's namespace. if (stackItem.namespaceURI().isNull() && !parent->inDocument()) stackItem.setNamespaceURI(parent->namespaceURI()); m_currentNodeStack.append(stackItem); }
void HTMLElement::setOuterText(const String &text, ExceptionState& es) { if (ieForbidsInsertHTML()) { es.throwDOMException(NoModificationAllowedError); return; } if (hasLocalName(colTag) || hasLocalName(colgroupTag) || hasLocalName(framesetTag) || hasLocalName(headTag) || hasLocalName(htmlTag) || hasLocalName(tableTag) || hasLocalName(tbodyTag) || hasLocalName(tfootTag) || hasLocalName(theadTag) || hasLocalName(trTag)) { es.throwDOMException(NoModificationAllowedError); return; } ContainerNode* parent = parentNode(); if (!parent) { es.throwDOMException(NoModificationAllowedError); return; } RefPtr<Node> prev = previousSibling(); RefPtr<Node> next = nextSibling(); RefPtr<Node> newChild; // Convert text to fragment with <br> tags instead of linebreaks if needed. if (text.contains('\r') || text.contains('\n')) newChild = textToFragment(text, es); else newChild = Text::create(document(), text); if (!this || !parentNode()) es.throwDOMException(HierarchyRequestError); if (es.hadException()) return; parent->replaceChild(newChild.release(), this, es); RefPtr<Node> node = next ? next->previousSibling() : 0; if (!es.hadException() && node && node->isTextNode()) mergeWithNextTextNode(node.release(), es); if (!es.hadException() && prev && prev->isTextNode()) mergeWithNextTextNode(prev.release(), es); }
void HTMLElement::setOuterText(const String& text, ExceptionState& exceptionState) { if (ieForbidsInsertHTML()) { exceptionState.throwDOMException(NoModificationAllowedError, "The '" + localName() + "' element does not support text insertion."); return; } if (shouldProhibitSetInnerOuterText(*this)) { exceptionState.throwDOMException(NoModificationAllowedError, "The '" + localName() + "' element does not support text insertion."); return; } ContainerNode* parent = parentNode(); if (!parent) { exceptionState.throwDOMException(NoModificationAllowedError, "The element has no parent."); return; } RefPtrWillBeRawPtr<Node> prev = previousSibling(); RefPtrWillBeRawPtr<Node> next = nextSibling(); RefPtrWillBeRawPtr<Node> newChild = nullptr; // Convert text to fragment with <br> tags instead of linebreaks if needed. if (text.contains('\r') || text.contains('\n')) newChild = textToFragment(text, exceptionState); else newChild = Text::create(document(), text); // textToFragment might cause mutation events. if (!parentNode()) exceptionState.throwDOMException(HierarchyRequestError, "The element has no parent."); if (exceptionState.hadException()) return; parent->replaceChild(newChild.release(), this, exceptionState); RefPtrWillBeRawPtr<Node> node = next ? next->previousSibling() : nullptr; if (!exceptionState.hadException() && node && node->isTextNode()) mergeWithNextTextNode(toText(node.get()), exceptionState); if (!exceptionState.hadException() && prev && prev->isTextNode()) mergeWithNextTextNode(toText(prev.get()), exceptionState); }
Node::InsertionNotificationRequest HTMLFrameSetElement::insertedInto(ContainerNode& insertionPoint) { HTMLElement::insertedInto(insertionPoint); if (insertionPoint.inDocument()) { if (Frame* frame = document().frame()) frame->loader().client().dispatchDidBecomeFrameset(document().isFrameSet()); } return InsertionDone; }
Node::InsertionNotificationRequest SVGImageElement::insertedInto(ContainerNode& rootParent) { SVGGraphicsElement::insertedInto(rootParent); if (!rootParent.inDocument()) return InsertionDone; // Update image loader, as soon as we're living in the tree. // We can only resolve base URIs properly, after that! m_imageLoader.updateFromElement(); return InsertionDone; }
// FIXME: It is silly that these functions are in HTMLCollection.cpp. Node* LiveNodeListBase::item(unsigned offset) const { if (isItemCacheValid() && cachedItemOffset() == offset) return cachedItem(); if (isLengthCacheValid() && cachedLength() <= offset) return 0; ContainerNode* root = rootContainerNode(); if (!root) { // FIMXE: In someTextNode.childNodes case the root is Text. We shouldn't even make a LiveNodeList for that. setLengthCache(0); return 0; } if (isLengthCacheValid() && !overridesItemAfter() && isLastItemCloserThanLastOrCachedItem(offset)) { Node* lastItem = itemBefore(0); ASSERT(lastItem); setItemCache(lastItem, cachedLength() - 1, 0); } else if (!isItemCacheValid() || isFirstItemCloserThanCachedItem(offset) || (overridesItemAfter() && offset < cachedItemOffset())) { unsigned offsetInArray = 0; Node* firstItem; if (type() == ChildNodeListType) firstItem = root->firstChild(); else if (isNodeList(type())) firstItem = traverseLiveNodeListFirstElement(root); else firstItem = static_cast<const HTMLCollection*>(this)->traverseFirstElement(offsetInArray, root); if (!firstItem) { setLengthCache(0); return 0; } setItemCache(firstItem, 0, offsetInArray); ASSERT(!cachedItemOffset()); } if (cachedItemOffset() == offset) return cachedItem(); return itemBeforeOrAfterCachedItem(offset, root); }
Node* DOMPatchSupport::patchNode(Node* node, const String& markup, ExceptionCode& ec) { // Don't parse <html> as a fragment. if (node->isDocumentNode() || (node->parentNode() && node->parentNode()->isDocumentNode())) { patchDocument(markup); return 0; } Node* previousSibling = node->previousSibling(); RefPtr<DocumentFragment> fragment = DocumentFragment::create(m_document); fragment->parseHTML(markup, node->parentElement() ? node->parentElement() : m_document->documentElement()); // Compose the old list. ContainerNode* parentNode = node->parentNode(); Vector<OwnPtr<Digest> > oldList; for (Node* child = parentNode->firstChild(); child; child = child->nextSibling()) oldList.append(createDigest(child, 0)); // Compose the new list. String markupCopy = markup; markupCopy.makeLower(); Vector<OwnPtr<Digest> > newList; for (Node* child = parentNode->firstChild(); child != node; child = child->nextSibling()) newList.append(createDigest(child, 0)); for (Node* child = fragment->firstChild(); child; child = child->nextSibling()) { if (child->hasTagName(headTag) && !child->firstChild() && markupCopy.find("</head>") == notFound) continue; // HTML5 parser inserts empty <head> tag whenever it parses <body> if (child->hasTagName(bodyTag) && !child->firstChild() && markupCopy.find("</body>") == notFound) continue; // HTML5 parser inserts empty <body> tag whenever it parses </head> newList.append(createDigest(child, &m_unusedNodesMap)); } for (Node* child = node->nextSibling(); child; child = child->nextSibling()) newList.append(createDigest(child, 0)); if (!innerPatchChildren(parentNode, oldList, newList, ec)) { // Fall back to total replace. ec = 0; if (!m_domEditor->replaceChild(parentNode, fragment.release(), node, ec)) return 0; } return previousSibling ? previousSibling->nextSibling() : parentNode->firstChild(); }
void HTMLFrameSetElement::willAttachRenderers() { // Inherit default settings from parent frameset // FIXME: This is not dynamic. for (ContainerNode* node = parentNode(); node; node = node->parentNode()) { if (!node->hasTagName(framesetTag)) continue; HTMLFrameSetElement* frameset = static_cast<HTMLFrameSetElement*>(node); if (!m_frameborderSet) m_frameborder = frameset->hasFrameBorder(); if (m_frameborder) { if (!m_borderSet) m_border = frameset->border(); if (!m_borderColorSet) m_borderColorSet = frameset->hasBorderColor(); } if (!m_noresize) m_noresize = frameset->noResize(); } }
static void swapInNodePreservingAttributesAndChildren(HTMLElement* newNode, HTMLElement* nodeToReplace) { ASSERT(nodeToReplace->inDocument()); ExceptionCode ec = 0; ContainerNode* parentNode = nodeToReplace->parentNode(); parentNode->insertBefore(newNode, nodeToReplace, ec); ASSERT(!ec); RefPtr<Node> nextChild; for (Node* child = nodeToReplace->firstChild(); child; child = nextChild.get()) { nextChild = child->nextSibling(); newNode->appendChild(child, ec); ASSERT(!ec); } newNode->attributes()->setAttributes(*nodeToReplace->attributes()); parentNode->removeChild(nodeToReplace, ec); ASSERT(!ec); }
ComposedTreeIterator::ComposedTreeIterator(ContainerNode& root, FirstChildTag) : m_rootIsInShadowTree(root.isInShadowTree()) { ASSERT(!is<ShadowRoot>(root)); if (is<HTMLSlotElement>(root)) { auto& slot = downcast<HTMLSlotElement>(root); if (auto* assignedNodes = slot.assignedNodes()) { initializeContextStack(root, *assignedNodes->at(0)); return; } } if (auto* shadowRoot = root.shadowRoot()) { ElementAndTextDescendantIterator firstChild(*shadowRoot, ElementAndTextDescendantIterator::FirstChild); initializeContextStack(root, firstChild ? *firstChild : root); return; } m_contextStack.uncheckedAppend(Context(root, FirstChild)); }
inline bool ancestorHasClassName(ContainerNode& rootNode, const AtomicString& className) { if (!rootNode.isElementNode()) return false; for (Element* element = &toElement(rootNode); element; element = element->parentElement()) { if (element->hasClass() && element->classNames().contains(className)) return true; } return false; }
void AccountMediaConfig::readObject(const ContainerNode &node) throw(Error) { ContainerNode this_node = node.readContainer("AccountMediaConfig"); NODE_READ_BOOL ( this_node, lockCodecEnabled); NODE_READ_BOOL ( this_node, streamKaEnabled); NODE_READ_NUM_T ( this_node, pjmedia_srtp_use, srtpUse); NODE_READ_INT ( this_node, srtpSecureSignaling); NODE_READ_NUM_T ( this_node, pjsua_ipv6_use, ipv6Use); NODE_READ_OBJ ( this_node, transportConfig); }
void HTMLImageElement::removedFrom(ContainerNode& insertionPoint) { if (m_form) m_form->removeImgElement(this); if (insertionPoint.inDocument() && !m_lowercasedUsemap.isNull()) document().removeImageElementByLowercasedUsemap(*m_lowercasedUsemap.impl(), *this); m_form = nullptr; HTMLElement::removedFrom(insertionPoint); }
void AccountMediaConfig::writeObject(ContainerNode &node) const throw(Error) { ContainerNode this_node = node.writeNewContainer("AccountMediaConfig"); NODE_WRITE_BOOL ( this_node, lockCodecEnabled); NODE_WRITE_BOOL ( this_node, streamKaEnabled); NODE_WRITE_NUM_T ( this_node, pjmedia_srtp_use, srtpUse); NODE_WRITE_INT ( this_node, srtpSecureSignaling); NODE_WRITE_NUM_T ( this_node, pjsua_ipv6_use, ipv6Use); NODE_WRITE_OBJ ( this_node, transportConfig); }
void AccountPresConfig::readObject(const ContainerNode &node) throw(Error) { ContainerNode this_node = node.readContainer("AccountPresConfig"); NODE_READ_BOOL ( this_node, publishEnabled); NODE_READ_BOOL ( this_node, publishQueue); NODE_READ_UNSIGNED( this_node, publishShutdownWaitMsec); NODE_READ_STRING ( this_node, pidfTupleId); readSipHeaders(this_node, "headers", headers); }
void AccountPresConfig::writeObject(ContainerNode &node) const throw(Error) { ContainerNode this_node = node.writeNewContainer("AccountPresConfig"); NODE_WRITE_BOOL ( this_node, publishEnabled); NODE_WRITE_BOOL ( this_node, publishQueue); NODE_WRITE_UNSIGNED( this_node, publishShutdownWaitMsec); NODE_WRITE_STRING ( this_node, pidfTupleId); writeSipHeaders(this_node, "headers", headers); }
void StyledMarkupTraverser<Strategy>::wrapWithNode(ContainerNode& node, RawPtr<EditingStyle> style) { if (!m_accumulator) return; StringBuilder markup; if (node.isDocumentNode()) { MarkupFormatter::appendXMLDeclaration(markup, toDocument(node)); m_accumulator->pushMarkup(markup.toString()); return; } if (!node.isElementNode()) return; Element& element = toElement(node); if (shouldApplyWrappingStyle(element) || needsInlineStyle(element)) m_accumulator->appendElementWithInlineStyle(markup, element, style); else m_accumulator->appendElement(markup, element); m_accumulator->pushMarkup(markup.toString()); m_accumulator->appendEndTag(toElement(node)); }
Node::InsertionNotificationRequest HTMLImageElement::insertedInto(ContainerNode* insertionPoint) { if (!m_form) { // m_form can be non-null if it was set in constructor. for (ContainerNode* ancestor = parentNode(); ancestor; ancestor = ancestor->parentNode()) { if (ancestor->hasTagName(formTag)) { m_form = static_cast<HTMLFormElement*>(ancestor); m_form->registerImgElement(this); break; } } } // If we have been inserted from a renderer-less document, // our loader may have not fetched the image, so do it now. if (insertionPoint->inDocument() && !m_imageLoader.image()) m_imageLoader.updateFromElement(); return HTMLElement::insertedInto(insertionPoint); }
Node* previousSiblingSlow(const Node* node) { ASSERT(!node->isShadowRoot()); Node* previousSibling = 0; if (node->isAfterPseudoElement()) { ContainerNode* parent = traverseParent(node, CrossShadowRoot); previousSibling = traverseLastChild(parent, CrossShadowRoot); } else previousSibling = traversePreviousSibling(node); if (previousSibling || node->isBeforePseudoElement()) return previousSibling; ContainerNode* parent = traverseParent(node, CrossShadowRoot); if (parent && parent->isElementNode()) return toElement(parent)->beforePseudoElement(); return 0; }
void LogConfig::writeObject(ContainerNode &node) const throw(Error) { ContainerNode this_node = node.writeNewContainer("LogConfig"); NODE_WRITE_UNSIGNED( this_node, msgLogging); NODE_WRITE_UNSIGNED( this_node, level); NODE_WRITE_UNSIGNED( this_node, consoleLevel); NODE_WRITE_UNSIGNED( this_node, decor); NODE_WRITE_STRING ( this_node, filename); NODE_WRITE_UNSIGNED( this_node, fileFlags); }
void LogConfig::readObject(const ContainerNode &node) throw(Error) { ContainerNode this_node = node.readContainer("LogConfig"); NODE_READ_UNSIGNED( this_node, msgLogging); NODE_READ_UNSIGNED( this_node, level); NODE_READ_UNSIGNED( this_node, consoleLevel); NODE_READ_UNSIGNED( this_node, decor); NODE_READ_STRING ( this_node, filename); NODE_READ_UNSIGNED( this_node, fileFlags); }
void writeSipHeaders(ContainerNode &node, const string &array_name, const SipHeaderVector &headers) throw(Error) { ContainerNode headers_node = node.writeNewArray(array_name); for (unsigned i=0; i<headers.size(); ++i) { ContainerNode header_node = headers_node.writeNewContainer("header"); header_node.writeString("hname", headers[i].hName); header_node.writeString("hvalue", headers[i].hValue); } }
NodeRenderingContext::NodeRenderingContext(Node* node) : m_location(LocationNotInTree) , m_phase(AttachStraight) , m_node(node) , m_parentNodeForRenderingAndStyle(0) , m_visualParentShadowRoot(0) , m_includer(0) , m_style(0) , m_parentFlowRenderer(0) { ContainerNode* parent = m_node->parentOrHostNode(); if (!parent) return; if (parent->isShadowRoot()) { m_location = LocationShadowChild; m_parentNodeForRenderingAndStyle = parent->shadowHost(); return; } m_location = LocationLightChild; if (parent->isElementNode()) { m_visualParentShadowRoot = toElement(parent)->shadowRoot(); if (m_visualParentShadowRoot) { if ((m_includer = m_visualParentShadowRoot->includerFor(m_node)) && m_visualParentShadowRoot->isInclusionSelectorActive()) { m_phase = AttachContentForwarded; m_parentNodeForRenderingAndStyle = NodeRenderingContext(m_includer).parentNodeForRenderingAndStyle(); return; } m_phase = AttachContentLight; m_parentNodeForRenderingAndStyle = parent; return; } } m_parentNodeForRenderingAndStyle = parent; }
bool HTMLEmbedElement::rendererIsNeeded(const RenderStyle& style) { if (isImageType()) return HTMLPlugInImageElement::rendererIsNeeded(style); Frame* frame = document().frame(); if (!frame) return false; // If my parent is an <object> and is not set to use fallback content, I // should be ignored and not get a renderer. ContainerNode* p = parentNode(); if (p && p->hasTagName(objectTag)) { ASSERT(p->renderer()); if (!toHTMLObjectElement(p)->useFallbackContent()) { ASSERT(!p->renderer()->isEmbeddedObject()); return false; } } return HTMLPlugInImageElement::rendererIsNeeded(style); }