Add nsIXMLContentBuilder::textNode()

git-svn-id: svn://10.0.0.236/branches/XTF_20040312_BRANCH@158463 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
alex%croczilla.com
2004-06-25 07:28:40 +00:00
parent 6722e40ce9
commit 4561fca6ba
3 changed files with 26 additions and 2 deletions

View File

@@ -43,7 +43,7 @@
importModule("resource:/jscodelib/StdLib.js");
importModule("resource:/jscodelib/TemplateLib.js");
MOZ_EXPORTED_SYMBOLS = [ "XHTML_NS", "SVG_NS",
MOZ_EXPORTED_SYMBOLS = [ "XHTML_NS", "SVG_NS", "XUL_NS",
"ContentBuilder",
"XTFGenericElement",
"XTFSVGVisual",
@@ -57,7 +57,7 @@ MOZ_EXPORTED_SYMBOLS = [ "XHTML_NS", "SVG_NS",
var XHTML_NS = "http://www.w3.org/1999/xhtml";
var SVG_NS = "http://www.w3.org/2000/svg";
var XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
//----------------------------------------------------------------------
// ContentBuilder: simple interface to facilitate constructing xml
@@ -101,6 +101,12 @@ ContentBuilder.addProtoObj("attrib",
return this;
});
ContentBuilder.addProtoObj("textNode",
function(text) {
this.builder.textNode(text);
return this;
});
ContentBuilder.addProtoObj("attribs",
function(obj) {
for (var a in obj)

View File

@@ -48,6 +48,7 @@ interface nsIXMLContentBuilder : nsISupports
void beginElement(in AString tagname);
void endElement();
void attrib(in AString name, in AString value);
void textNode(in AString text);
readonly attribute nsIDOMElement root;
readonly attribute nsIDOMElement current;
};

View File

@@ -50,6 +50,8 @@
#include "nsContentCID.h"
#include "nsIDocument.h"
#include "nsIDOMElement.h"
#include "nsIDOMDocument.h"
#include "nsIDOMText.h"
static NS_DEFINE_CID(kXMLDocumentCID, NS_XMLDOCUMENT_CID);
@@ -206,6 +208,21 @@ NS_IMETHODIMP nsXMLContentBuilder::Attrib(const nsAString & name, const nsAStrin
return NS_OK;
}
/* void textNode (in AString text); */
NS_IMETHODIMP nsXMLContentBuilder::TextNode(const nsAString & text)
{
NS_ASSERTION(mCurrent, "can't append textnode w/o open element");
nsCOMPtr<nsIDOMDocument> domDoc = do_QueryInterface(mDocument);
NS_ASSERTION(domDoc, "no dom document");
nsCOMPtr<nsIDOMText> textNode;
domDoc->CreateTextNode(text, getter_AddRefs(textNode));
NS_ASSERTION(textNode, "Failed to create text node");
nsCOMPtr<nsIContent> textContent = do_QueryInterface(textNode);
mCurrent->AppendChildTo(textContent, PR_TRUE, PR_TRUE);
return NS_OK;
}
/* readonly attribute nsIDOMElement root; */
NS_IMETHODIMP nsXMLContentBuilder::GetRoot(nsIDOMElement * *aRoot)
{