New encoder fixup helper interface. b=57996, r=jst

This commit is contained in:
locka%iol.ie 2000-11-30 01:08:22 +00:00
Родитель c320bf8727
Коммит 2b03ecf7c9
4 изменённых файлов: 102 добавлений и 18 удалений

Просмотреть файл

@ -32,6 +32,7 @@ class nsIDOMRange;
class nsISelection;
class nsIOutputStream;
class nsISupportsArray;
class nsIDOMNode;
#define NS_IDOCUMENT_ENCODER_IID \
@ -56,9 +57,26 @@ class nsISupportsArray;
#define NS_HTMLCOPY_TEXT_ENCODER_CID \
{ 0x7f915b01, 0x98fc, 0x11d4, { 0x8e, 0xb0, 0xa8, 0x03, 0xf8, 0x0f, 0xf1, 0xbc } }
// {0BC1FAC0-B710-11d4-959F-0020183BF181}
#define NS_IDOCUMENTENCODERNODEFIXUP_IID \
{ 0xbc1fac0, 0xb710, 0x11d4, { 0x95, 0x9f, 0x0, 0x20, 0x18, 0x3b, 0xf1, 0x81 } }
#define NS_HTMLCOPY_ENCODER_CONTRACTID "@mozilla.org/layout/htmlCopyEncoder"
class nsIDocumentEncoderNodeFixup : public nsISupports
{
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IDOCUMENTENCODERNODEFIXUP_IID)
/**
* Create a fixed up version of a node. This method is called before
* each node in a document is about to be persisted. The implementor
* may return a new node with fixed up attributes or nsnull.
*/
NS_IMETHOD FixupNode(nsIDOMNode *aNode, nsIDOMNode **aOutNode) = 0;
};
class nsIDocumentEncoder : public nsISupports
{
public:
@ -172,6 +190,11 @@ public:
NS_IMETHOD EncodeToStringWithContext(nsAWritableString& aEncodedString,
nsAWritableString& aContextString,
nsAWritableString& aInfoString) = 0;
/**
* Set the fixup object associated with node persistence.
*/
NS_IMETHOD SetNodeFixup(nsIDocumentEncoderNodeFixup *aFixup) = 0;
};
#endif /* nsIDocumentEncoder_h__ */

Просмотреть файл

@ -91,12 +91,12 @@ public:
NS_IMETHOD SetRange(nsIDOMRange* aRange);
NS_IMETHOD SetWrapColumn(PRUint32 aWC);
NS_IMETHOD SetCharset(const nsAReadableString& aCharset);
NS_IMETHOD EncodeToStream(nsIOutputStream* aStream);
NS_IMETHOD EncodeToString(nsAWritableString& aOutputString);
NS_IMETHOD EncodeToStringWithContext(nsAWritableString& aEncodedString,
nsAWritableString& aContextString,
nsAWritableString& aInfoString);
NS_IMETHOD SetNodeFixup(nsIDocumentEncoderNodeFixup *aFixup);
protected:
nsresult SerializeNodeStart(nsIDOMNode* aNode, PRInt32 aStartOffset,
@ -129,6 +129,7 @@ protected:
nsCOMPtr<nsIContentSerializer> mSerializer;
nsCOMPtr<nsIUnicodeEncoder> mUnicodeEncoder;
nsCOMPtr<nsIDOMNode> mCommonParent;
nsCOMPtr<nsIDocumentEncoderNodeFixup> mNodeFixup;
nsString mMimeType;
nsString mCharset;
@ -234,42 +235,52 @@ nsDocumentEncoder::SerializeNodeStart(nsIDOMNode* aNode, PRInt32 aStartOffset,
{
PRUint16 type;
aNode->GetNodeType(&type);
nsCOMPtr<nsIDOMNode> node;
if (mNodeFixup)
{
mNodeFixup->FixupNode(aNode, getter_AddRefs(node));
}
if (!node)
{
node = do_QueryInterface(aNode);
}
node->GetNodeType(&type);
switch (type) {
case nsIDOMNode::ELEMENT_NODE:
{
nsCOMPtr<nsIDOMElement> element = do_QueryInterface(aNode);
nsCOMPtr<nsIDOMElement> element = do_QueryInterface(node);
mSerializer->AppendElementStart(element, aStr);
break;
}
case nsIDOMNode::TEXT_NODE:
{
nsCOMPtr<nsIDOMText> text = do_QueryInterface(aNode);
nsCOMPtr<nsIDOMText> text = do_QueryInterface(node);
mSerializer->AppendText(text, aStartOffset, aEndOffset, aStr);
break;
}
case nsIDOMNode::CDATA_SECTION_NODE:
{
nsCOMPtr<nsIDOMCDATASection> cdata = do_QueryInterface(aNode);
nsCOMPtr<nsIDOMCDATASection> cdata = do_QueryInterface(node);
mSerializer->AppendCDATASection(cdata, aStartOffset, aEndOffset, aStr);
break;
}
case nsIDOMNode::PROCESSING_INSTRUCTION_NODE:
{
nsCOMPtr<nsIDOMProcessingInstruction> pi = do_QueryInterface(aNode);
nsCOMPtr<nsIDOMProcessingInstruction> pi = do_QueryInterface(node);
mSerializer->AppendProcessingInstruction(pi, aStartOffset, aEndOffset,
aStr);
break;
}
case nsIDOMNode::COMMENT_NODE:
{
nsCOMPtr<nsIDOMComment> comment = do_QueryInterface(aNode);
nsCOMPtr<nsIDOMComment> comment = do_QueryInterface(node);
mSerializer->AppendComment(comment, aStartOffset, aEndOffset, aStr);
break;
}
case nsIDOMNode::DOCUMENT_TYPE_NODE:
{
nsCOMPtr<nsIDOMDocumentType> doctype = do_QueryInterface(aNode);
nsCOMPtr<nsIDOMDocumentType> doctype = do_QueryInterface(node);
mSerializer->AppendDoctype(doctype, aStr);
break;
}
@ -922,6 +933,14 @@ nsDocumentEncoder::EncodeToStringWithContext(nsAWritableString& aEncodedString,
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsDocumentEncoder::SetNodeFixup(nsIDocumentEncoderNodeFixup *aFixup)
{
mNodeFixup = aFixup;
return NS_OK;
}
nsresult NS_NewTextEncoder(nsIDocumentEncoder** aResult); // make mac compiler happy
nsresult

Просмотреть файл

@ -32,6 +32,7 @@ class nsIDOMRange;
class nsISelection;
class nsIOutputStream;
class nsISupportsArray;
class nsIDOMNode;
#define NS_IDOCUMENT_ENCODER_IID \
@ -56,9 +57,26 @@ class nsISupportsArray;
#define NS_HTMLCOPY_TEXT_ENCODER_CID \
{ 0x7f915b01, 0x98fc, 0x11d4, { 0x8e, 0xb0, 0xa8, 0x03, 0xf8, 0x0f, 0xf1, 0xbc } }
// {0BC1FAC0-B710-11d4-959F-0020183BF181}
#define NS_IDOCUMENTENCODERNODEFIXUP_IID \
{ 0xbc1fac0, 0xb710, 0x11d4, { 0x95, 0x9f, 0x0, 0x20, 0x18, 0x3b, 0xf1, 0x81 } }
#define NS_HTMLCOPY_ENCODER_CONTRACTID "@mozilla.org/layout/htmlCopyEncoder"
class nsIDocumentEncoderNodeFixup : public nsISupports
{
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IDOCUMENTENCODERNODEFIXUP_IID)
/**
* Create a fixed up version of a node. This method is called before
* each node in a document is about to be persisted. The implementor
* may return a new node with fixed up attributes or nsnull.
*/
NS_IMETHOD FixupNode(nsIDOMNode *aNode, nsIDOMNode **aOutNode) = 0;
};
class nsIDocumentEncoder : public nsISupports
{
public:
@ -172,6 +190,11 @@ public:
NS_IMETHOD EncodeToStringWithContext(nsAWritableString& aEncodedString,
nsAWritableString& aContextString,
nsAWritableString& aInfoString) = 0;
/**
* Set the fixup object associated with node persistence.
*/
NS_IMETHOD SetNodeFixup(nsIDocumentEncoderNodeFixup *aFixup) = 0;
};
#endif /* nsIDocumentEncoder_h__ */

Просмотреть файл

@ -91,12 +91,12 @@ public:
NS_IMETHOD SetRange(nsIDOMRange* aRange);
NS_IMETHOD SetWrapColumn(PRUint32 aWC);
NS_IMETHOD SetCharset(const nsAReadableString& aCharset);
NS_IMETHOD EncodeToStream(nsIOutputStream* aStream);
NS_IMETHOD EncodeToString(nsAWritableString& aOutputString);
NS_IMETHOD EncodeToStringWithContext(nsAWritableString& aEncodedString,
nsAWritableString& aContextString,
nsAWritableString& aInfoString);
NS_IMETHOD SetNodeFixup(nsIDocumentEncoderNodeFixup *aFixup);
protected:
nsresult SerializeNodeStart(nsIDOMNode* aNode, PRInt32 aStartOffset,
@ -129,6 +129,7 @@ protected:
nsCOMPtr<nsIContentSerializer> mSerializer;
nsCOMPtr<nsIUnicodeEncoder> mUnicodeEncoder;
nsCOMPtr<nsIDOMNode> mCommonParent;
nsCOMPtr<nsIDocumentEncoderNodeFixup> mNodeFixup;
nsString mMimeType;
nsString mCharset;
@ -234,42 +235,52 @@ nsDocumentEncoder::SerializeNodeStart(nsIDOMNode* aNode, PRInt32 aStartOffset,
{
PRUint16 type;
aNode->GetNodeType(&type);
nsCOMPtr<nsIDOMNode> node;
if (mNodeFixup)
{
mNodeFixup->FixupNode(aNode, getter_AddRefs(node));
}
if (!node)
{
node = do_QueryInterface(aNode);
}
node->GetNodeType(&type);
switch (type) {
case nsIDOMNode::ELEMENT_NODE:
{
nsCOMPtr<nsIDOMElement> element = do_QueryInterface(aNode);
nsCOMPtr<nsIDOMElement> element = do_QueryInterface(node);
mSerializer->AppendElementStart(element, aStr);
break;
}
case nsIDOMNode::TEXT_NODE:
{
nsCOMPtr<nsIDOMText> text = do_QueryInterface(aNode);
nsCOMPtr<nsIDOMText> text = do_QueryInterface(node);
mSerializer->AppendText(text, aStartOffset, aEndOffset, aStr);
break;
}
case nsIDOMNode::CDATA_SECTION_NODE:
{
nsCOMPtr<nsIDOMCDATASection> cdata = do_QueryInterface(aNode);
nsCOMPtr<nsIDOMCDATASection> cdata = do_QueryInterface(node);
mSerializer->AppendCDATASection(cdata, aStartOffset, aEndOffset, aStr);
break;
}
case nsIDOMNode::PROCESSING_INSTRUCTION_NODE:
{
nsCOMPtr<nsIDOMProcessingInstruction> pi = do_QueryInterface(aNode);
nsCOMPtr<nsIDOMProcessingInstruction> pi = do_QueryInterface(node);
mSerializer->AppendProcessingInstruction(pi, aStartOffset, aEndOffset,
aStr);
break;
}
case nsIDOMNode::COMMENT_NODE:
{
nsCOMPtr<nsIDOMComment> comment = do_QueryInterface(aNode);
nsCOMPtr<nsIDOMComment> comment = do_QueryInterface(node);
mSerializer->AppendComment(comment, aStartOffset, aEndOffset, aStr);
break;
}
case nsIDOMNode::DOCUMENT_TYPE_NODE:
{
nsCOMPtr<nsIDOMDocumentType> doctype = do_QueryInterface(aNode);
nsCOMPtr<nsIDOMDocumentType> doctype = do_QueryInterface(node);
mSerializer->AppendDoctype(doctype, aStr);
break;
}
@ -922,6 +933,14 @@ nsDocumentEncoder::EncodeToStringWithContext(nsAWritableString& aEncodedString,
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsDocumentEncoder::SetNodeFixup(nsIDocumentEncoderNodeFixup *aFixup)
{
mNodeFixup = aFixup;
return NS_OK;
}
nsresult NS_NewTextEncoder(nsIDocumentEncoder** aResult); // make mac compiler happy
nsresult