static nsresult SetUpEncoder(nsIDOMNode *aRoot, const nsACString& aCharset, nsIDocumentEncoder **aEncoder) { *aEncoder = nsnull; nsresult rv; nsCOMPtr<nsIDocumentEncoder> encoder = do_CreateInstance(NS_DOC_ENCODER_CONTRACTID_BASE "application/xhtml+xml", &rv); if (NS_FAILED(rv)) return rv; bool entireDocument = true; nsCOMPtr<nsIDOMDocument> domDoc(do_QueryInterface(aRoot)); if (!domDoc) { entireDocument = false; rv = aRoot->GetOwnerDocument(getter_AddRefs(domDoc)); if (NS_FAILED(rv)) return rv; } // This method will fail if no document rv = encoder->Init(domDoc, NS_LITERAL_STRING("application/xhtml+xml"), nsIDocumentEncoder::OutputRaw | nsIDocumentEncoder::OutputDontRewriteEncodingDeclaration); if (NS_FAILED(rv)) return rv; nsCAutoString charset(aCharset); if (charset.IsEmpty()) { nsCOMPtr<nsIDocument> doc = do_QueryInterface(domDoc); NS_ASSERTION(doc, "Need a document"); charset = doc->GetDocumentCharacterSet(); } rv = encoder->SetCharset(charset); if (NS_FAILED(rv)) return rv; // 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_SUCCEEDED(rv)) { *aEncoder = encoder.get(); NS_ADDREF(*aEncoder); } return rv; }
nsIContent* nsCoreUtils::GetRoleContent(nsINode *aNode) { nsCOMPtr<nsIContent> content(do_QueryInterface(aNode)); if (!content) { nsCOMPtr<nsIDOMDocument> domDoc(do_QueryInterface(aNode)); if (domDoc) { nsCOMPtr<nsIDOMHTMLDocument> htmlDoc(do_QueryInterface(aNode)); if (htmlDoc) { nsCOMPtr<nsIDOMHTMLElement> bodyElement; htmlDoc->GetBody(getter_AddRefs(bodyElement)); content = do_QueryInterface(bodyElement); } else { nsCOMPtr<nsIDOMElement> docElement; domDoc->GetDocumentElement(getter_AddRefs(docElement)); content = do_QueryInterface(docElement); } } } return content; }
void ImageshackTalker::parseAddPhotoToGalleryDone(QByteArray data) { //int errCode = -1; QString errMsg = QString::fromLatin1(""); QDomDocument domDoc(QString::fromLatin1("galleryXML")); qCDebug(KIPIPLUGINS_LOG) << data; if (!domDoc.setContent(data)) return; QDomElement rootElem = domDoc.documentElement(); if (rootElem.isNull() || rootElem.tagName() != QString::fromLatin1("gallery")) { // TODO error cheking } else { emit signalBusy(false); emit signalAddPhotoDone(0, QString::fromLatin1("")); } }
PRBool nsXBLWindowKeyHandler::WalkHandlersAndExecute(nsIDOMKeyEvent* aKeyEvent, nsIAtom* aEventType, nsXBLPrototypeHandler* aHandler, PRUint32 aCharCode, PRBool aIgnoreShiftKey) { nsresult rv; nsCOMPtr<nsIPrivateDOMEvent> privateEvent(do_QueryInterface(aKeyEvent)); // Try all of the handlers until we find one that matches the event. for (nsXBLPrototypeHandler *currHandler = aHandler; currHandler; currHandler = currHandler->GetNextHandler()) { PRBool stopped; privateEvent->IsDispatchStopped(&stopped); if (stopped) { // The event is finished, don't execute any more handlers return NS_OK; } if (!EventMatched(currHandler, aEventType, aKeyEvent, aCharCode, aIgnoreShiftKey)) continue; // try the next one // Before executing this handler, check that it's not disabled, // and that it has something to do (oncommand of the <key> or its // <command> is non-empty). nsCOMPtr<nsIContent> elt = currHandler->GetHandlerElement(); nsCOMPtr<nsIDOMElement> commandElt; // See if we're in a XUL doc. nsCOMPtr<nsIDOMElement> el = GetElement(); if (el && elt) { // We are. Obtain our command attribute. nsAutoString command; elt->GetAttr(kNameSpaceID_None, nsGkAtoms::command, command); if (!command.IsEmpty()) { // Locate the command element in question. Note that we // know "elt" is in a doc if we're dealing with it here. NS_ASSERTION(elt->IsInDoc(), "elt must be in document"); nsCOMPtr<nsIDOMDocument> domDoc( do_QueryInterface(elt->GetCurrentDoc())); if (domDoc) domDoc->GetElementById(command, getter_AddRefs(commandElt)); if (!commandElt) { NS_ERROR("A XUL <key> is observing a command that doesn't exist. Unable to execute key binding!\n"); continue; } } } if (!commandElt) { commandElt = do_QueryInterface(elt); } if (commandElt) { nsAutoString value; commandElt->GetAttribute(NS_LITERAL_STRING("disabled"), value); if (value.EqualsLiteral("true")) { continue; // this handler is disabled, try the next one } // Check that there is an oncommand handler commandElt->GetAttribute(NS_LITERAL_STRING("oncommand"), value); if (value.IsEmpty()) { continue; // nothing to do } } nsCOMPtr<nsPIDOMEventTarget> piTarget; nsCOMPtr<nsIDOMElement> element = GetElement(); if (element) { piTarget = do_QueryInterface(commandElt); } else { piTarget = mTarget; } rv = currHandler->ExecuteHandler(piTarget, aKeyEvent); if (NS_SUCCEEDED(rv)) { return PR_TRUE; } } return PR_FALSE; }
PRBool nsPopupSetFrame::OnCreate(PRInt32 aX, PRInt32 aY, nsIContent* aPopupContent) { nsEventStatus status = nsEventStatus_eIgnore; nsMouseEvent event(PR_TRUE, NS_XUL_POPUP_SHOWING, nsnull, nsMouseEvent::eReal); event.point.x = aX; event.point.y = aY; if (aPopupContent) { nsCOMPtr<nsIContent> kungFuDeathGrip(aPopupContent); nsCOMPtr<nsIPresShell> shell = mPresContext->GetPresShell(); if (shell) { nsresult rv = shell->HandleDOMEventWithTarget(aPopupContent, &event, &status); if ( NS_FAILED(rv) || status == nsEventStatus_eConsumeNoDefault ) return PR_FALSE; } // The menu is going to show, and the create handler has executed. // We should now walk all of our menu item children, checking to see if any // of them has a command attribute. If so, then several attributes must // potentially be updated. nsCOMPtr<nsIDOMDocument> domDoc(do_QueryInterface(aPopupContent->GetDocument())); PRUint32 count = aPopupContent->GetChildCount(); for (PRUint32 i = 0; i < count; i++) { nsCOMPtr<nsIContent> grandChild = aPopupContent->GetChildAt(i); if (grandChild->Tag() == nsXULAtoms::menuitem) { // See if we have a command attribute. nsAutoString command; grandChild->GetAttr(kNameSpaceID_None, nsXULAtoms::command, command); if (!command.IsEmpty()) { // We do! Look it up in our document nsCOMPtr<nsIDOMElement> commandElt; domDoc->GetElementById(command, getter_AddRefs(commandElt)); nsCOMPtr<nsIContent> commandContent(do_QueryInterface(commandElt)); if ( commandContent ) { nsAutoString commandDisabled, menuDisabled; commandContent->GetAttr(kNameSpaceID_None, nsHTMLAtoms::disabled, commandDisabled); grandChild->GetAttr(kNameSpaceID_None, nsHTMLAtoms::disabled, menuDisabled); if (!commandDisabled.Equals(menuDisabled)) { // The menu's disabled state needs to be updated to match the command. if (commandDisabled.IsEmpty()) grandChild->UnsetAttr(kNameSpaceID_None, nsHTMLAtoms::disabled, PR_TRUE); else grandChild->SetAttr(kNameSpaceID_None, nsHTMLAtoms::disabled, commandDisabled, PR_TRUE); } nsAutoString commandValue, menuValue; commandContent->GetAttr(kNameSpaceID_None, nsXULAtoms::label, commandValue); grandChild->GetAttr(kNameSpaceID_None, nsXULAtoms::label, menuValue); if (!commandValue.Equals(menuValue)) { // The menu's value state needs to be updated to match the command. // Note that (unlike the disabled state) if the command has *no* value, we // assume the menu is supplying its own. if (!commandValue.IsEmpty()) grandChild->SetAttr(kNameSpaceID_None, nsXULAtoms::label, commandValue, PR_TRUE); } // The menu's accesskey needs to be updated to match the command. // If the command has no accesskey, assume the menu is supplying its own. commandContent->GetAttr(kNameSpaceID_None, nsHTMLAtoms::accesskey, commandValue); grandChild->GetAttr(kNameSpaceID_None, nsHTMLAtoms::accesskey, menuValue); if (!commandValue.Equals(menuValue)) { if (!commandValue.IsEmpty()) grandChild->SetAttr(kNameSpaceID_None, nsHTMLAtoms::accesskey, commandValue, PR_TRUE); } } } } } } return PR_TRUE; }
NS_IMETHODIMP nsXFormsItemSetElement::Refresh() { // We need to create item elements for each element referenced by the // nodeset. Each of these items will create an anonymous HTML option element // which will return from GetAnonymousNodes. We then clone our template // content and insert the cloned content as children of the HTML option. if (!nsXFormsUtils::IsDocumentReadyForBind(mElement)) { // not ready to bind yet, defer nsXFormsModelElement::DeferElementBind(this); return NS_OK; } nsCOMPtr<nsIModelElementPrivate> model; nsCOMPtr<nsIDOMXPathResult> result; nsresult rv = ProcessNodeBinding(NS_LITERAL_STRING("nodeset"), nsIDOMXPathResult::ORDERED_NODE_SNAPSHOT_TYPE, getter_AddRefs(result), getter_AddRefs(model)); if (NS_FAILED(rv) | !result | !model) return rv; nsCOMPtr<nsIDOMNode> node, templateNode, cloneNode, tmpNode; nsCOMPtr<nsIDOMElement> itemNode, itemWrapperNode, contextContainer; nsCOMPtr<nsIDOMNodeList> templateNodes; mElement->GetChildNodes(getter_AddRefs(templateNodes)); PRUint32 templateNodeCount = 0; if (templateNodes) templateNodes->GetLength(&templateNodeCount); nsCOMPtr<nsIContent> content(do_QueryInterface(mElement)); NS_ENSURE_STATE(content); nsCOMPtr<nsIDocument> doc = content->GetCurrentDoc(); nsCOMPtr<nsIDOMDocument> domDoc(do_QueryInterface(doc)); NS_ENSURE_STATE(domDoc); PRUint32 nodeCount; result->GetSnapshotLength(&nodeCount); nsCOMPtr<nsIDOMNode> parent, tmp; mElement->GetParentNode(getter_AddRefs(parent)); while (parent) { if (nsXFormsUtils::IsXFormsElement(parent, NS_LITERAL_STRING("select1")) || nsXFormsUtils::IsXFormsElement(parent, NS_LITERAL_STRING("select"))) { break; } tmp.swap(parent); tmp->GetParentNode(getter_AddRefs(parent)); } nsCOMPtr<nsIXFormsItemSetUIElement> uiItemSet(do_QueryInterface(mElement)); nsCOMPtr<nsIDOMElement> anonContent; if (uiItemSet) { uiItemSet->GetAnonymousItemSetContent(getter_AddRefs(anonContent)); } NS_ENSURE_STATE(anonContent); nsCOMPtr<nsIDOMNode> childNode, nodeReturn; while (NS_SUCCEEDED(anonContent->GetFirstChild(getter_AddRefs(childNode))) && childNode) { anonContent->RemoveChild(childNode, getter_AddRefs(nodeReturn)); } for (PRUint32 i = 0; i < nodeCount; ++i) { result->SnapshotItem(i, getter_AddRefs(node)); NS_ASSERTION(node, "incorrect snapshot length"); rv = domDoc->CreateElementNS(NS_LITERAL_STRING(NS_NAMESPACE_XFORMS), NS_LITERAL_STRING("item"), getter_AddRefs(itemNode)); NS_ENSURE_SUCCESS(rv, rv); anonContent->AppendChild(itemNode, getter_AddRefs(tmpNode)); nsCOMPtr<nsIXFormsContextControl> ctx(do_QueryInterface(itemNode)); if (ctx) { ctx->SetContext(node, i + 1, nodeCount); } // Clone the template content under the item for (PRUint32 j = 0; j < templateNodeCount; ++j) { templateNodes->Item(j, getter_AddRefs(templateNode)); templateNode->CloneNode(PR_TRUE, getter_AddRefs(cloneNode)); itemNode->AppendChild(cloneNode, getter_AddRefs(templateNode)); } } // refresh parent so that it has a chance to reflect the changes we just made if (parent) { nsCOMPtr<nsIXFormsControlBase> control = do_QueryInterface(parent); if (control) { control->Refresh(); } } return NS_OK; }