Vidur's initial implementation of Insert HTML Fragment
git-svn-id: svn://10.0.0.236/trunk@33637 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -36,6 +36,9 @@
|
||||
#include "nsIParser.h"
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsParserCIID.h"
|
||||
#include "nsIHTMLFragmentContentSink.h"
|
||||
// XXX Temporary inclusion to deal with fragment parsing
|
||||
#include "nsHTMLParts.h"
|
||||
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
|
||||
@@ -1713,13 +1716,97 @@ nsresult nsRange::TextOwnerChanged(nsIContent* aTextNode, PRInt32 aStartChanged,
|
||||
|
||||
// nsIDOMNSRange interface
|
||||
NS_IMETHODIMP
|
||||
nsRange::InsertFragment(const nsString& aFragment)
|
||||
nsRange::CreateContextualFragment(const nsString& aFragment,
|
||||
nsIDOMDocumentFragment** aReturn)
|
||||
{
|
||||
#ifdef NS_DEBUG
|
||||
printf("InsertFragment: not yet implemented!!\n");
|
||||
#endif
|
||||
nsresult result = NS_OK;
|
||||
nsCOMPtr<nsIParser> parser;
|
||||
nsITagStack* tagStack;
|
||||
|
||||
return NS_OK;
|
||||
if (!mIsPositioned) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
// Create a new parser for this entire operation
|
||||
result = nsComponentManager::CreateInstance(kCParserCID,
|
||||
nsnull,
|
||||
kCParserIID,
|
||||
(void **)getter_AddRefs(parser));
|
||||
if (NS_SUCCEEDED(result)) {
|
||||
result = parser->CreateTagStack(&tagStack);
|
||||
|
||||
if (NS_SUCCEEDED(result)) {
|
||||
nsCOMPtr<nsIDOMNode> parent;
|
||||
nsCOMPtr<nsIContent> content(do_QueryInterface(mStartParent, &result));
|
||||
|
||||
if (NS_SUCCEEDED(result)) {
|
||||
nsCOMPtr<nsIDocument> document;
|
||||
|
||||
result = content->GetDocument(*getter_AddRefs(document));
|
||||
|
||||
if (NS_SUCCEEDED(result)) {
|
||||
nsCOMPtr<nsIDOMDocument> domDocument(do_QueryInterface(document, &result));
|
||||
|
||||
if (NS_SUCCEEDED(result)) {
|
||||
parent = mStartParent;
|
||||
while (parent &&
|
||||
(parent != domDocument) &&
|
||||
NS_SUCCEEDED(result)) {
|
||||
nsCOMPtr<nsIDOMNode> temp;
|
||||
nsAutoString tagName;
|
||||
PRUnichar* name = nsnull;
|
||||
|
||||
parent->GetNodeName(tagName);
|
||||
// XXX Wish we didn't have to allocate here
|
||||
name = tagName.ToNewUnicode();
|
||||
if (nsnull != name) {
|
||||
tagStack->Push(name);
|
||||
temp = parent;
|
||||
result = temp->GetParentNode(getter_AddRefs(parent));
|
||||
}
|
||||
else {
|
||||
result = NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
|
||||
if (NS_SUCCEEDED(result)) {
|
||||
nsAutoString contentType;
|
||||
nsIHTMLFragmentContentSink* sink;
|
||||
|
||||
result = NS_NewHTMLFragmentContentSink(&sink);
|
||||
if (NS_SUCCEEDED(result)) {
|
||||
parser->SetContentSink(sink);
|
||||
document->GetContentType(contentType);
|
||||
|
||||
result = parser->ParseFragment(aFragment, (void*)0,
|
||||
*tagStack,
|
||||
0, contentType);
|
||||
|
||||
if (NS_SUCCEEDED(result)) {
|
||||
sink->GetFragment(aReturn);
|
||||
}
|
||||
|
||||
NS_RELEASE(sink);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// XXX Ick! Delete strings we allocated above.
|
||||
PRUnichar* str = nsnull;
|
||||
str = tagStack->Pop();
|
||||
while (nsnull != str) {
|
||||
delete[] str;
|
||||
str = tagStack->Pop();
|
||||
}
|
||||
|
||||
// XXX Double Ick! Deleting something that someone else newed.
|
||||
delete tagStack;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
||||
@@ -84,7 +84,8 @@ public:
|
||||
NS_IMETHOD ToString(nsString& aReturn);
|
||||
|
||||
// nsIDOMNSRange interface
|
||||
NS_IMETHOD InsertFragment(const nsString& aFragment);
|
||||
NS_IMETHOD CreateContextualFragment(const nsString& aFragment,
|
||||
nsIDOMDocumentFragment** aReturn);
|
||||
NS_IMETHOD IsValidFragment(const nsString& aFragment, PRBool* aReturn);
|
||||
|
||||
/*BEGIN nsIScriptObjectOwner interface implementations*/
|
||||
|
||||
@@ -45,6 +45,6 @@ interface Range {
|
||||
interface NSRange {
|
||||
/* IID: { 0xa6cf90f2, 0x15b3, 0x11d2, \
|
||||
{ 0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32 } } */
|
||||
void insertFragment(in DOMString fragment);
|
||||
DocumentFragment createContextualFragment(in DOMString fragment);
|
||||
boolean isValidFragment(in DOMString fragment);
|
||||
};
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include "nsString.h"
|
||||
#include "nsIScriptContext.h"
|
||||
|
||||
class nsIDOMDocumentFragment;
|
||||
|
||||
#define NS_IDOMNSRANGE_IID \
|
||||
{ 0xa6cf90f2, 0x15b3, 0x11d2, \
|
||||
@@ -33,20 +34,20 @@ class nsIDOMNSRange : public nsISupports {
|
||||
public:
|
||||
static const nsIID& GetIID() { static nsIID iid = NS_IDOMNSRANGE_IID; return iid; }
|
||||
|
||||
NS_IMETHOD InsertFragment(const nsString& aFragment)=0;
|
||||
NS_IMETHOD CreateContextualFragment(const nsString& aFragment, nsIDOMDocumentFragment** aReturn)=0;
|
||||
|
||||
NS_IMETHOD IsValidFragment(const nsString& aFragment, PRBool* aReturn)=0;
|
||||
};
|
||||
|
||||
|
||||
#define NS_DECL_IDOMNSRANGE \
|
||||
NS_IMETHOD InsertFragment(const nsString& aFragment); \
|
||||
NS_IMETHOD CreateContextualFragment(const nsString& aFragment, nsIDOMDocumentFragment** aReturn); \
|
||||
NS_IMETHOD IsValidFragment(const nsString& aFragment, PRBool* aReturn); \
|
||||
|
||||
|
||||
|
||||
#define NS_FORWARD_IDOMNSRANGE(_to) \
|
||||
NS_IMETHOD InsertFragment(const nsString& aFragment) { return _to InsertFragment(aFragment); } \
|
||||
NS_IMETHOD CreateContextualFragment(const nsString& aFragment, nsIDOMDocumentFragment** aReturn) { return _to CreateContextualFragment(aFragment, aReturn); } \
|
||||
NS_IMETHOD IsValidFragment(const nsString& aFragment, PRBool* aReturn) { return _to IsValidFragment(aFragment, aReturn); } \
|
||||
|
||||
|
||||
|
||||
@@ -58,12 +58,12 @@ NS_IMPL_ISUPPORTS(nsScriptNameSpaceManager, kIScriptNameSpaceManagerIID);
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsScriptNameSpaceManager::RegisterGlobalName(const nsString& aName,
|
||||
const nsIID& aCID,
|
||||
PRBool aIsConstructor)
|
||||
const nsIID& aCID,
|
||||
PRBool aIsConstructor)
|
||||
{
|
||||
if (nsnull == mGlobalNames) {
|
||||
mGlobalNames = PL_NewHashTable(4, PL_HashString, PL_CompareStrings,
|
||||
PL_CompareValues, nsnull, nsnull);
|
||||
PL_CompareValues, nsnull, nsnull);
|
||||
}
|
||||
|
||||
char* name = aName.ToNewCString();
|
||||
@@ -86,8 +86,8 @@ nsScriptNameSpaceManager::UnregisterGlobalName(const nsString& aName)
|
||||
char* name = aName.ToNewCString();
|
||||
PLHashNumber hn = PL_HashString(name);
|
||||
PLHashEntry** hep = PL_HashTableRawLookup(mGlobalNames,
|
||||
hn,
|
||||
name);
|
||||
hn,
|
||||
name);
|
||||
PLHashEntry* entry = *hep;
|
||||
|
||||
if (nsnull != entry) {
|
||||
@@ -107,8 +107,8 @@ nsScriptNameSpaceManager::UnregisterGlobalName(const nsString& aName)
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsScriptNameSpaceManager::LookupName(const nsString& aName,
|
||||
PRBool aIsConstructor,
|
||||
nsIID& aCID)
|
||||
PRBool aIsConstructor,
|
||||
nsIID& aCID)
|
||||
{
|
||||
if (nsnull != mGlobalNames) {
|
||||
char* name = aName.ToNewCString();
|
||||
|
||||
@@ -58,12 +58,12 @@ NS_IMPL_ISUPPORTS(nsScriptNameSpaceManager, kIScriptNameSpaceManagerIID);
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsScriptNameSpaceManager::RegisterGlobalName(const nsString& aName,
|
||||
const nsIID& aCID,
|
||||
PRBool aIsConstructor)
|
||||
const nsIID& aCID,
|
||||
PRBool aIsConstructor)
|
||||
{
|
||||
if (nsnull == mGlobalNames) {
|
||||
mGlobalNames = PL_NewHashTable(4, PL_HashString, PL_CompareStrings,
|
||||
PL_CompareValues, nsnull, nsnull);
|
||||
PL_CompareValues, nsnull, nsnull);
|
||||
}
|
||||
|
||||
char* name = aName.ToNewCString();
|
||||
@@ -86,8 +86,8 @@ nsScriptNameSpaceManager::UnregisterGlobalName(const nsString& aName)
|
||||
char* name = aName.ToNewCString();
|
||||
PLHashNumber hn = PL_HashString(name);
|
||||
PLHashEntry** hep = PL_HashTableRawLookup(mGlobalNames,
|
||||
hn,
|
||||
name);
|
||||
hn,
|
||||
name);
|
||||
PLHashEntry* entry = *hep;
|
||||
|
||||
if (nsnull != entry) {
|
||||
@@ -107,8 +107,8 @@ nsScriptNameSpaceManager::UnregisterGlobalName(const nsString& aName)
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsScriptNameSpaceManager::LookupName(const nsString& aName,
|
||||
PRBool aIsConstructor,
|
||||
nsIID& aCID)
|
||||
PRBool aIsConstructor,
|
||||
nsIID& aCID)
|
||||
{
|
||||
if (nsnull != mGlobalNames) {
|
||||
char* name = aName.ToNewCString();
|
||||
|
||||
@@ -1201,10 +1201,10 @@ RangeToString(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval
|
||||
|
||||
|
||||
//
|
||||
// Native method InsertFragment
|
||||
// Native method CreateContextualFragment
|
||||
//
|
||||
PR_STATIC_CALLBACK(JSBool)
|
||||
NSRangeInsertFragment(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
NSRangeCreateContextualFragment(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
{
|
||||
nsIDOMRange *privateThis = (nsIDOMRange*)JS_GetPrivate(cx, obj);
|
||||
nsIDOMNSRange *nativeThis = nsnull;
|
||||
@@ -1214,6 +1214,7 @@ NSRangeInsertFragment(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsv
|
||||
}
|
||||
|
||||
JSBool rBool = JS_FALSE;
|
||||
nsIDOMDocumentFragment* nativeRet;
|
||||
nsAutoString b0;
|
||||
|
||||
*rval = JSVAL_NULL;
|
||||
@@ -1222,7 +1223,7 @@ NSRangeInsertFragment(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsv
|
||||
nsIScriptSecurityManager *secMan;
|
||||
if (NS_OK == scriptCX->GetSecurityManager(&secMan)) {
|
||||
PRBool ok;
|
||||
secMan->CheckScriptAccess(scriptCX, obj, "nsrange.insertfragment", &ok);
|
||||
secMan->CheckScriptAccess(scriptCX, obj, "nsrange.createcontextualfragment", &ok);
|
||||
if (!ok) {
|
||||
//Need to throw error here
|
||||
return JS_FALSE;
|
||||
@@ -1242,14 +1243,14 @@ NSRangeInsertFragment(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsv
|
||||
|
||||
nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]);
|
||||
|
||||
if (NS_OK != nativeThis->InsertFragment(b0)) {
|
||||
if (NS_OK != nativeThis->CreateContextualFragment(b0, &nativeRet)) {
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
*rval = JSVAL_VOID;
|
||||
nsJSUtils::nsConvertObjectToJSVal(nativeRet, cx, rval);
|
||||
}
|
||||
else {
|
||||
JS_ReportError(cx, "Function insertFragment requires 1 parameters");
|
||||
JS_ReportError(cx, "Function createContextualFragment requires 1 parameters");
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
@@ -1370,7 +1371,7 @@ static JSFunctionSpec RangeMethods[] =
|
||||
{"surroundContents", RangeSurroundContents, 1},
|
||||
{"clone", RangeClone, 0},
|
||||
{"toString", RangeToString, 0},
|
||||
{"insertFragment", NSRangeInsertFragment, 1},
|
||||
{"createContextualFragment", NSRangeCreateContextualFragment, 1},
|
||||
{"isValidFragment", NSRangeIsValidFragment, 1},
|
||||
{0}
|
||||
};
|
||||
|
||||
@@ -44,6 +44,7 @@ nsInsertHTMLTxn::~nsInsertHTMLTxn()
|
||||
|
||||
NS_IMETHODIMP nsInsertHTMLTxn::Do(void)
|
||||
{
|
||||
#if 0
|
||||
nsCOMPtr<nsIDOMSelection>selection;
|
||||
nsresult res = mEditor->GetSelection(getter_AddRefs(selection));
|
||||
if (NS_SUCCEEDED(res) && selection)
|
||||
@@ -70,6 +71,9 @@ NS_IMETHODIMP nsInsertHTMLTxn::Do(void)
|
||||
}
|
||||
|
||||
return res;
|
||||
#else
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
#endif
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsInsertHTMLTxn::Undo(void)
|
||||
|
||||
@@ -66,6 +66,7 @@ EXPORTS = \
|
||||
nsIExpatTokenizer.h \
|
||||
nsIHTMLContentSink.h \
|
||||
nsHTMLContentSinkStream.h \
|
||||
nsIHTMLFragmentContentSink.h \
|
||||
nsHTMLToTXTSinkStream.h \
|
||||
nsHTMLEntities.h \
|
||||
nsHTMLTokens.h \
|
||||
|
||||
@@ -95,6 +95,7 @@ EXPORTS= \
|
||||
nsIHTMLContentSink.h \
|
||||
nsILoggingSink.h \
|
||||
nsHTMLContentSinkStream.h \
|
||||
nsIHTMLFragmentContentSink.h \
|
||||
nsHTMLToTXTSinkStream.h \
|
||||
nsHTMLEntities.h \
|
||||
nsHTMLTokens.h \
|
||||
|
||||
@@ -167,7 +167,7 @@ class nsIParser : public nsISupports {
|
||||
virtual nsresult Parse(nsString& aSourceBuffer,void* aKey,const nsString& aContentType,PRBool aEnableVerify,PRBool aLastCall) = 0;
|
||||
|
||||
virtual PRBool IsValidFragment(const nsString& aSourceBuffer,nsITagStack& aStack,PRUint32 anInsertPos,const nsString& aContentType)=0;
|
||||
virtual nsresult ParseFragment(nsString& aSourceBuffer,void* aKey,nsITagStack& aStack,PRUint32 anInsertPos,const nsString& aContentType)=0;
|
||||
virtual nsresult ParseFragment(const nsString& aSourceBuffer,void* aKey,nsITagStack& aStack,PRUint32 anInsertPos,const nsString& aContentType)=0;
|
||||
|
||||
/**
|
||||
* This method gets called when the tokens have been consumed, and it's time
|
||||
|
||||
@@ -809,8 +809,26 @@ PRBool nsParser::IsValidFragment(const nsString& aSourceBuffer,nsITagStack& aSta
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
nsresult nsParser::ParseFragment(nsString& aSourceBuffer,void* aKey,nsITagStack& aStack,PRUint32 anInsertPos,const nsString& aContentType){
|
||||
PRBool result=PR_FALSE;
|
||||
nsresult nsParser::ParseFragment(const nsString& aSourceBuffer,void* aKey,nsITagStack& aStack,PRUint32 anInsertPos,const nsString& aContentType){
|
||||
|
||||
nsresult result=NS_OK;
|
||||
nsAutoString theContext;
|
||||
PRUint32 theCount=aStack.GetSize();
|
||||
PRUint32 theIndex=0;
|
||||
while(theIndex++<theCount){
|
||||
theContext.Append("<");
|
||||
theContext.Append(aStack.TagAt(theCount-theIndex));
|
||||
theContext.Append(">");
|
||||
}
|
||||
theContext.Append("<endnote>"); //XXXHack! I'll make this better later.
|
||||
nsAutoString theBuffer(theContext);
|
||||
theBuffer.Append(aSourceBuffer);
|
||||
|
||||
if(theBuffer.Length()){
|
||||
//now it's time to try to build the model from this fragment
|
||||
result=Parse(theBuffer,(void*)&theBuffer,aContentType,PR_FALSE,PR_TRUE);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -189,7 +189,7 @@ friend class CTokenHandler;
|
||||
virtual nsresult Parse(nsString& aSourceBuffer,void* aKey,const nsString& aContentType,PRBool aEnableVerify=PR_FALSE,PRBool aLastCall=PR_FALSE);
|
||||
|
||||
virtual PRBool IsValidFragment(const nsString& aSourceBuffer,nsITagStack& aStack,PRUint32 anInsertPos,const nsString& aContentType);
|
||||
virtual nsresult ParseFragment(nsString& aSourceBuffer,void* aKey,nsITagStack& aStack,PRUint32 anInsertPos,const nsString& aContentType);
|
||||
virtual nsresult ParseFragment(const nsString& aSourceBuffer,void* aKey,nsITagStack& aStack,PRUint32 anInsertPos,const nsString& aContentType);
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -36,6 +36,9 @@
|
||||
#include "nsIParser.h"
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsParserCIID.h"
|
||||
#include "nsIHTMLFragmentContentSink.h"
|
||||
// XXX Temporary inclusion to deal with fragment parsing
|
||||
#include "nsHTMLParts.h"
|
||||
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
|
||||
@@ -1713,13 +1716,97 @@ nsresult nsRange::TextOwnerChanged(nsIContent* aTextNode, PRInt32 aStartChanged,
|
||||
|
||||
// nsIDOMNSRange interface
|
||||
NS_IMETHODIMP
|
||||
nsRange::InsertFragment(const nsString& aFragment)
|
||||
nsRange::CreateContextualFragment(const nsString& aFragment,
|
||||
nsIDOMDocumentFragment** aReturn)
|
||||
{
|
||||
#ifdef NS_DEBUG
|
||||
printf("InsertFragment: not yet implemented!!\n");
|
||||
#endif
|
||||
nsresult result = NS_OK;
|
||||
nsCOMPtr<nsIParser> parser;
|
||||
nsITagStack* tagStack;
|
||||
|
||||
return NS_OK;
|
||||
if (!mIsPositioned) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
// Create a new parser for this entire operation
|
||||
result = nsComponentManager::CreateInstance(kCParserCID,
|
||||
nsnull,
|
||||
kCParserIID,
|
||||
(void **)getter_AddRefs(parser));
|
||||
if (NS_SUCCEEDED(result)) {
|
||||
result = parser->CreateTagStack(&tagStack);
|
||||
|
||||
if (NS_SUCCEEDED(result)) {
|
||||
nsCOMPtr<nsIDOMNode> parent;
|
||||
nsCOMPtr<nsIContent> content(do_QueryInterface(mStartParent, &result));
|
||||
|
||||
if (NS_SUCCEEDED(result)) {
|
||||
nsCOMPtr<nsIDocument> document;
|
||||
|
||||
result = content->GetDocument(*getter_AddRefs(document));
|
||||
|
||||
if (NS_SUCCEEDED(result)) {
|
||||
nsCOMPtr<nsIDOMDocument> domDocument(do_QueryInterface(document, &result));
|
||||
|
||||
if (NS_SUCCEEDED(result)) {
|
||||
parent = mStartParent;
|
||||
while (parent &&
|
||||
(parent != domDocument) &&
|
||||
NS_SUCCEEDED(result)) {
|
||||
nsCOMPtr<nsIDOMNode> temp;
|
||||
nsAutoString tagName;
|
||||
PRUnichar* name = nsnull;
|
||||
|
||||
parent->GetNodeName(tagName);
|
||||
// XXX Wish we didn't have to allocate here
|
||||
name = tagName.ToNewUnicode();
|
||||
if (nsnull != name) {
|
||||
tagStack->Push(name);
|
||||
temp = parent;
|
||||
result = temp->GetParentNode(getter_AddRefs(parent));
|
||||
}
|
||||
else {
|
||||
result = NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
|
||||
if (NS_SUCCEEDED(result)) {
|
||||
nsAutoString contentType;
|
||||
nsIHTMLFragmentContentSink* sink;
|
||||
|
||||
result = NS_NewHTMLFragmentContentSink(&sink);
|
||||
if (NS_SUCCEEDED(result)) {
|
||||
parser->SetContentSink(sink);
|
||||
document->GetContentType(contentType);
|
||||
|
||||
result = parser->ParseFragment(aFragment, (void*)0,
|
||||
*tagStack,
|
||||
0, contentType);
|
||||
|
||||
if (NS_SUCCEEDED(result)) {
|
||||
sink->GetFragment(aReturn);
|
||||
}
|
||||
|
||||
NS_RELEASE(sink);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// XXX Ick! Delete strings we allocated above.
|
||||
PRUnichar* str = nsnull;
|
||||
str = tagStack->Pop();
|
||||
while (nsnull != str) {
|
||||
delete[] str;
|
||||
str = tagStack->Pop();
|
||||
}
|
||||
|
||||
// XXX Double Ick! Deleting something that someone else newed.
|
||||
delete tagStack;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
||||
@@ -84,7 +84,8 @@ public:
|
||||
NS_IMETHOD ToString(nsString& aReturn);
|
||||
|
||||
// nsIDOMNSRange interface
|
||||
NS_IMETHOD InsertFragment(const nsString& aFragment);
|
||||
NS_IMETHOD CreateContextualFragment(const nsString& aFragment,
|
||||
nsIDOMDocumentFragment** aReturn);
|
||||
NS_IMETHOD IsValidFragment(const nsString& aFragment, PRBool* aReturn);
|
||||
|
||||
/*BEGIN nsIScriptObjectOwner interface implementations*/
|
||||
|
||||
@@ -66,6 +66,7 @@ CPPSRCS= \
|
||||
EXPORTS = \
|
||||
nsIHTMLContent.h \
|
||||
nsILineIterator.h \
|
||||
nsHTMLParts.h \
|
||||
$(NULL)
|
||||
|
||||
EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS))
|
||||
|
||||
@@ -28,6 +28,7 @@ DEFINES = $(DEFINES) -DXP_NEW_SELECTION
|
||||
EXPORTS = \
|
||||
nsIHTMLContent.h \
|
||||
nsILineIterator.h \
|
||||
nsHTMLParts.h \
|
||||
$(NULL)
|
||||
|
||||
CPPSRCS= \
|
||||
|
||||
@@ -40,6 +40,7 @@ INCLUDES += \
|
||||
# Note the sophisticated alphabetical ordering :-|
|
||||
CPPSRCS = \
|
||||
nsHTMLContentSink.cpp \
|
||||
nsHTMLFragmentContentSink.cpp \
|
||||
nsHTMLDocument.cpp \
|
||||
nsFrameFrame.cpp \
|
||||
nsFrameSetFrame.cpp \
|
||||
|
||||
@@ -29,6 +29,7 @@ DEFINES = $(DEFINES) -DXP_NEW_SELECTION
|
||||
CPPSRCS= \
|
||||
nsHTMLContentSink.cpp \
|
||||
nsHTMLDocument.cpp \
|
||||
nsHTMLFragmentContentSink.cpp \
|
||||
nsFrameFrame.cpp \
|
||||
nsFrameSetFrame.cpp \
|
||||
nsImageDocument.cpp \
|
||||
@@ -38,6 +39,7 @@ CPPSRCS= \
|
||||
CPP_OBJS= \
|
||||
.\$(OBJDIR)\nsHTMLContentSink.obj \
|
||||
.\$(OBJDIR)\nsHTMLDocument.obj \
|
||||
.\$(OBJDIR)\nsHTMLFragmentContentSink.cpp \
|
||||
.\$(OBJDIR)\nsFrameFrame.obj \
|
||||
.\$(OBJDIR)\nsFrameSetFrame.obj \
|
||||
.\$(OBJDIR)\nsImageDocument.obj \
|
||||
|
||||
@@ -66,6 +66,7 @@ EXPORTS = \
|
||||
nsIExpatTokenizer.h \
|
||||
nsIHTMLContentSink.h \
|
||||
nsHTMLContentSinkStream.h \
|
||||
nsIHTMLFragmentContentSink.h \
|
||||
nsHTMLToTXTSinkStream.h \
|
||||
nsHTMLEntities.h \
|
||||
nsHTMLTokens.h \
|
||||
|
||||
@@ -95,6 +95,7 @@ EXPORTS= \
|
||||
nsIHTMLContentSink.h \
|
||||
nsILoggingSink.h \
|
||||
nsHTMLContentSinkStream.h \
|
||||
nsIHTMLFragmentContentSink.h \
|
||||
nsHTMLToTXTSinkStream.h \
|
||||
nsHTMLEntities.h \
|
||||
nsHTMLTokens.h \
|
||||
|
||||
@@ -167,7 +167,7 @@ class nsIParser : public nsISupports {
|
||||
virtual nsresult Parse(nsString& aSourceBuffer,void* aKey,const nsString& aContentType,PRBool aEnableVerify,PRBool aLastCall) = 0;
|
||||
|
||||
virtual PRBool IsValidFragment(const nsString& aSourceBuffer,nsITagStack& aStack,PRUint32 anInsertPos,const nsString& aContentType)=0;
|
||||
virtual nsresult ParseFragment(nsString& aSourceBuffer,void* aKey,nsITagStack& aStack,PRUint32 anInsertPos,const nsString& aContentType)=0;
|
||||
virtual nsresult ParseFragment(const nsString& aSourceBuffer,void* aKey,nsITagStack& aStack,PRUint32 anInsertPos,const nsString& aContentType)=0;
|
||||
|
||||
/**
|
||||
* This method gets called when the tokens have been consumed, and it's time
|
||||
|
||||
@@ -809,8 +809,26 @@ PRBool nsParser::IsValidFragment(const nsString& aSourceBuffer,nsITagStack& aSta
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
nsresult nsParser::ParseFragment(nsString& aSourceBuffer,void* aKey,nsITagStack& aStack,PRUint32 anInsertPos,const nsString& aContentType){
|
||||
PRBool result=PR_FALSE;
|
||||
nsresult nsParser::ParseFragment(const nsString& aSourceBuffer,void* aKey,nsITagStack& aStack,PRUint32 anInsertPos,const nsString& aContentType){
|
||||
|
||||
nsresult result=NS_OK;
|
||||
nsAutoString theContext;
|
||||
PRUint32 theCount=aStack.GetSize();
|
||||
PRUint32 theIndex=0;
|
||||
while(theIndex++<theCount){
|
||||
theContext.Append("<");
|
||||
theContext.Append(aStack.TagAt(theCount-theIndex));
|
||||
theContext.Append(">");
|
||||
}
|
||||
theContext.Append("<endnote>"); //XXXHack! I'll make this better later.
|
||||
nsAutoString theBuffer(theContext);
|
||||
theBuffer.Append(aSourceBuffer);
|
||||
|
||||
if(theBuffer.Length()){
|
||||
//now it's time to try to build the model from this fragment
|
||||
result=Parse(theBuffer,(void*)&theBuffer,aContentType,PR_FALSE,PR_TRUE);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -189,7 +189,7 @@ friend class CTokenHandler;
|
||||
virtual nsresult Parse(nsString& aSourceBuffer,void* aKey,const nsString& aContentType,PRBool aEnableVerify=PR_FALSE,PRBool aLastCall=PR_FALSE);
|
||||
|
||||
virtual PRBool IsValidFragment(const nsString& aSourceBuffer,nsITagStack& aStack,PRUint32 anInsertPos,const nsString& aContentType);
|
||||
virtual nsresult ParseFragment(nsString& aSourceBuffer,void* aKey,nsITagStack& aStack,PRUint32 anInsertPos,const nsString& aContentType);
|
||||
virtual nsresult ParseFragment(const nsString& aSourceBuffer,void* aKey,nsITagStack& aStack,PRUint32 anInsertPos,const nsString& aContentType);
|
||||
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user