void ChromeNodeList::Remove(nsINode& aNode, ErrorResult& aError) { if (!aNode.IsContent()) { aError.Throw(NS_ERROR_DOM_TYPE_ERR); return; } RemoveElement(aNode.AsContent()); }
void ChromeNodeList::Append(nsINode& aNode, ErrorResult& aError) { if (!aNode.IsContent()) { // nsINodeList deals with nsIContent objects only, so need to // filter out other nodes for now. aError.Throw(NS_ERROR_DOM_TYPE_ERR); return; } AppendElement(aNode.AsContent()); }
void nsDOMSerializer::SerializeToStream(nsINode& aRoot, nsIOutputStream* aStream, const nsAString& aCharset, ErrorResult& rv) { rv = nsDOMSerializer::SerializeToStream(aRoot.AsDOMNode(), aStream, NS_ConvertUTF16toUTF8(aCharset)); }
/////////////////////////////////////////////////////////////////////////// // IsHeader: true if node an html header // bool nsHTMLEditUtils::IsHeader(nsINode& aNode) { return aNode.IsAnyOfHTMLElements(nsGkAtoms::h1, nsGkAtoms::h2, nsGkAtoms::h3, nsGkAtoms::h4, nsGkAtoms::h5, nsGkAtoms::h6); }
/////////////////////////////////////////////////////////////////////////// // IsHeader: true if node an html header // bool nsHTMLEditUtils::IsHeader(nsINode& aNode) { nsCOMPtr<nsIAtom> nodeAtom = aNode.Tag(); return (nodeAtom == nsGkAtoms::h1) || (nodeAtom == nsGkAtoms::h2) || (nodeAtom == nsGkAtoms::h3) || (nodeAtom == nsGkAtoms::h4) || (nodeAtom == nsGkAtoms::h5) || (nodeAtom == nsGkAtoms::h6); }
static already_AddRefed<nsIDocumentEncoder> SetUpEncoder( nsINode& aRoot, const nsAString& aCharset, ErrorResult& aRv) { nsCOMPtr<nsIDocumentEncoder> encoder = do_createDocumentEncoder("application/xhtml+xml"); if (!encoder) { aRv.Throw(NS_ERROR_FAILURE); return nullptr; } dom::Document* doc = aRoot.OwnerDoc(); bool entireDocument = (doc == &aRoot); // This method will fail if no document nsresult rv = encoder->NativeInit( doc, NS_LITERAL_STRING("application/xhtml+xml"), nsIDocumentEncoder::OutputRaw | nsIDocumentEncoder::OutputDontRewriteEncodingDeclaration); if (NS_FAILED(rv)) { aRv.Throw(rv); return nullptr; } NS_ConvertUTF16toUTF8 charset(aCharset); if (charset.IsEmpty()) { doc->GetDocumentCharacterSet()->Name(charset); } rv = encoder->SetCharset(charset); if (NS_FAILED(rv)) { aRv.Throw(rv); return nullptr; } // If we are working on the entire document we do not need to // specify which part to serialize if (!entireDocument) { rv = encoder->SetNode(&aRoot); } if (NS_FAILED(rv)) { aRv.Throw(rv); return nullptr; } return encoder.forget(); }
bool HTMLEditUtils::SupportsAlignAttr(nsINode& aNode) { return aNode.IsAnyOfHTMLElements(nsGkAtoms::hr, nsGkAtoms::table, nsGkAtoms::tbody, nsGkAtoms::tfoot, nsGkAtoms::thead, nsGkAtoms::tr, nsGkAtoms::td, nsGkAtoms::th, nsGkAtoms::div, nsGkAtoms::p, nsGkAtoms::h1, nsGkAtoms::h2, nsGkAtoms::h3, nsGkAtoms::h4, nsGkAtoms::h5, nsGkAtoms::h6); }
already_AddRefed<XPathResult> XPathExpression::EvaluateWithContext(nsINode& aContextNode, uint32_t aContextPosition, uint32_t aContextSize, uint16_t aType, XPathResult* aInResult, ErrorResult& aRv) { if (aContextPosition > aContextSize) { aRv.Throw(NS_ERROR_FAILURE); return nullptr; } if (!nsContentUtils::LegacyIsCallerNativeCode() && !nsContentUtils::CanCallerAccess(&aContextNode)) { aRv.Throw(NS_ERROR_DOM_SECURITY_ERR); return nullptr; } if (mCheckDocument) { nsCOMPtr<nsIDocument> doc = do_QueryReferent(mDocument); if (doc != aContextNode.OwnerDoc()) { aRv.Throw(NS_ERROR_DOM_WRONG_DOCUMENT_ERR); return nullptr; } } uint16_t nodeType = aContextNode.NodeType(); if (nodeType == nsIDOMNode::TEXT_NODE || nodeType == nsIDOMNode::CDATA_SECTION_NODE) { nsCOMPtr<nsIDOMCharacterData> textNode = do_QueryInterface(&aContextNode); if (!textNode) { aRv.Throw(NS_ERROR_FAILURE); return nullptr; } uint32_t textLength; textNode->GetLength(&textLength); if (textLength == 0) { aRv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR); return nullptr; } // XXX Need to get logical XPath text node for CDATASection // and Text nodes. } else if (nodeType != nsIDOMNode::DOCUMENT_NODE && nodeType != nsIDOMNode::ELEMENT_NODE && nodeType != nsIDOMNode::ATTRIBUTE_NODE && nodeType != nsIDOMNode::COMMENT_NODE && nodeType != nsIDOMNode::PROCESSING_INSTRUCTION_NODE) { aRv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR); return nullptr; } nsAutoPtr<txXPathNode> contextNode(txXPathNativeNode::createXPathNode(&aContextNode)); if (!contextNode) { aRv.Throw(NS_ERROR_FAILURE); return nullptr; } EvalContextImpl eContext(*contextNode, aContextPosition, aContextSize, mRecycler); RefPtr<txAExprResult> exprResult; aRv = mExpression->evaluate(&eContext, getter_AddRefs(exprResult)); if (aRv.Failed()) { return nullptr; } uint16_t resultType = aType; if (aType == XPathResult::ANY_TYPE) { short exprResultType = exprResult->getResultType(); switch (exprResultType) { case txAExprResult::NUMBER: resultType = XPathResult::NUMBER_TYPE; break; case txAExprResult::STRING: resultType = XPathResult::STRING_TYPE; break; case txAExprResult::BOOLEAN: resultType = XPathResult::BOOLEAN_TYPE; break; case txAExprResult::NODESET: resultType = XPathResult::UNORDERED_NODE_ITERATOR_TYPE; break; case txAExprResult::RESULT_TREE_FRAGMENT: aRv.Throw(NS_ERROR_FAILURE); return nullptr; } } RefPtr<XPathResult> xpathResult = aInResult; if (!xpathResult) { xpathResult = new XPathResult(&aContextNode); } aRv = xpathResult->SetExprResult(exprResult, resultType, &aContextNode); return xpathResult.forget(); }
void nsDOMSerializer::SerializeToString(nsINode& aRoot, nsAString& aStr, ErrorResult& rv) { rv = nsDOMSerializer::SerializeToString(aRoot.AsDOMNode(), aStr); }
/** * IsTableCellOrCaption() returns true if aNode is an html td or th or caption. */ bool HTMLEditUtils::IsTableCellOrCaption(nsINode& aNode) { return aNode.IsAnyOfHTMLElements(nsGkAtoms::td, nsGkAtoms::th, nsGkAtoms::caption); }