Use the Range methods instead of homebrew stuff to determine when a point is contained in a range; eliminate code duplication

This commit is contained in:
akkana%netscape.com 1999-07-19 22:41:49 +00:00
parent 262bb2c519
commit feb61c6d4c
10 changed files with 30 additions and 180 deletions

View File

@ -285,8 +285,6 @@ public:
virtual void FinishConvertToXIF(nsXIFConverter& aConverter, nsIDOMNode* aNode) = 0;
/* Helper methods to help determine the logical positioning of content */
virtual PRBool IsInRange(const nsIContent *aStartContent, const nsIContent* aEndContent, const nsIContent* aContent) const = 0;
virtual PRBool IsBefore(const nsIContent *aNewContent, const nsIContent* aCurrentContent) const = 0;
virtual PRBool IsInSelection(nsIDOMSelection* aSelection, const nsIContent *aContent) const = 0;
virtual nsIContent* GetPrevContent(const nsIContent *aContent) const = 0;
virtual nsIContent* GetNextContent(const nsIContent *aContent) const = 0;

View File

@ -2891,37 +2891,6 @@ nsIContent* nsDocument::FindContent(const nsIContent* aStartNode,
return nsnull;
}
PRBool nsDocument::IsInRange(const nsIContent *aStartContent, const nsIContent* aEndContent, const nsIContent* aContent) const
{
PRBool result;
if (aStartContent == aEndContent)
{
return PRBool(aContent == aStartContent);
}
else if (aStartContent == aContent || aEndContent == aContent)
{
result = PR_TRUE;
}
else
{
result = IsBefore(aStartContent,aContent);
if (result == PR_TRUE)
{
result = IsBefore(aContent,aEndContent);
if (!result)
{
// If aContent is a parent of aEndContent, then
// IsBefore returned false but IsInRange should be true.
if (FindContent(aContent, aEndContent, 0) == aEndContent)
result = PR_TRUE;
}
}
}
return result;
}
/**
* Determines if the content is found within the selection
@ -2935,37 +2904,17 @@ PRBool nsDocument::IsInSelection(nsIDOMSelection* aSelection, const nsIContent*
{
PRBool result = PR_FALSE;
if (aSelection != nsnull) {
//traverses through an iterator to see if the acontent is in the ranges
nsIEnumerator *enumerator;
if (NS_SUCCEEDED(aSelection->QueryInterface(kIEnumeratorIID, (void **)&enumerator)))
if (NS_SUCCEEDED(aSelection->QueryInterface(kIEnumeratorIID, (void **)&enumerator))
&& enumerator)
{
for (enumerator->First();NS_OK != enumerator->IsDone() ; enumerator->Next()) {
nsIDOMRange* range = nsnull;
if (NS_SUCCEEDED(enumerator->CurrentItem((nsISupports**)&range)))
{
nsIDOMNode* startNode = nsnull;
nsIDOMNode* endNode = nsnull;
range->GetStartParent(&startNode);
range->GetEndParent(&endNode);
if (startNode && endNode)
{
nsIContent* start;
nsIContent* end;
if (NS_SUCCEEDED(startNode->QueryInterface(kIContentIID, (void **)&start)) &&
NS_SUCCEEDED(endNode->QueryInterface(kIContentIID, (void **)&end)) )
{
result = IsInRange(start,end,aContent);
}
NS_IF_RELEASE(start);
NS_IF_RELEASE(end);
}
NS_IF_RELEASE(startNode);
NS_IF_RELEASE(endNode);
return IsNodeIntersectsRange(aContent, range);
NS_RELEASE(range);
}
if (result) break;
@ -2976,23 +2925,6 @@ PRBool nsDocument::IsInSelection(nsIDOMSelection* aSelection, const nsIContent*
return result;
}
PRBool nsDocument::IsBefore(const nsIContent *aNewContent, const nsIContent* aCurrentContent) const
{
PRBool result = PR_FALSE;
if (nsnull != aNewContent && nsnull != aCurrentContent && aNewContent != aCurrentContent)
{
nsIContent* test = FindContent(mRootContent,aNewContent,aCurrentContent);
if (test == aNewContent)
result = PR_TRUE;
NS_RELEASE(test);
}
return result;
}
nsIContent* nsDocument::GetPrevContent(const nsIContent *aContent) const
{
nsIContent* result = nsnull;

View File

@ -382,9 +382,7 @@ public:
nsEventStatus& aEventStatus);
virtual PRBool IsInRange(const nsIContent *aStartContent, const nsIContent* aEndContent, const nsIContent* aContent) const;
virtual PRBool IsInSelection(nsIDOMSelection* aSelection, const nsIContent *aContent) const;
virtual PRBool IsBefore(const nsIContent *aNewContent, const nsIContent* aCurrentContent) const;
virtual nsIContent* GetPrevContent(const nsIContent *aContent) const;
virtual nsIContent* GetNextContent(const nsIContent *aContent) const;
virtual void SetDisplaySelection(PRBool aToggle);

View File

@ -473,8 +473,6 @@ void nsHTMLContentSinkStream::EncodeToBuffer(const nsString& aSrc)
if (mUnicodeEncoder == nsnull)
return;
#define CH_NBSP 160
PRInt32 length = htmlstr.Length();
nsresult result;
@ -491,14 +489,20 @@ void nsHTMLContentSinkStream::EncodeToBuffer(const nsString& aSrc)
if (NS_SUCCEEDED(result))
result = mUnicodeEncoder->Finish(mBuffer,&temp);
#if 0
// Do some conversions to make up for the unicode encoder's foibles:
PRInt32 nbsp = nsHTMLEntities::EntityToUnicode(nsCAutoString("nbsp"));
PRInt32 quot = nsHTMLEntities::EntityToUnicode(nsCAutoString("quot"));
for (PRInt32 i = 0; i < mBufferLength; i++)
{
if (mBuffer[i] == char(CH_NBSP))
if (mBuffer[i] == quot)
mBuffer[i] = '"';
// I don't know why this nbsp mapping was here ...
else if (mBuffer[i] == nbsp)
mBuffer[i] = ' ';
}
}
#endif
}
@ -535,7 +539,6 @@ void nsHTMLContentSinkStream::Write(const nsString& aString)
}
}
void nsHTMLContentSinkStream::Write(const char* aData)
{
if (mStream)
@ -563,10 +566,6 @@ void nsHTMLContentSinkStream::Write(char aData)
}
/**
*
* @update 04/30/99 gpk
@ -1007,9 +1006,7 @@ nsHTMLContentSinkStream::AddLeaf(const nsIParserNode& aNode){
if (mHTMLStackPos > 0)
tag = mHTMLTagStack[mHTMLStackPos-1];
PRBool preformatted = PR_FALSE;
PRBool preformatted = PR_FALSE;
for (PRInt32 i = mHTMLStackPos-1; i >= 0; i--)
{

View File

@ -70,8 +70,8 @@ class nsHTMLContentSinkStream : public nsIHTMLContentSink {
nsHTMLContentSinkStream(nsIOutputStream* aOutStream,
nsString* aOutString,
const nsString* aCharsetOverride,
PRBool aDoFormat = PR_TRUE,
PRBool aDoHeader = PR_TRUE);
PRBool aDoFormat,
PRBool aDoHeader);
/**
* virtual destructor

View File

@ -285,8 +285,6 @@ public:
virtual void FinishConvertToXIF(nsXIFConverter& aConverter, nsIDOMNode* aNode) = 0;
/* Helper methods to help determine the logical positioning of content */
virtual PRBool IsInRange(const nsIContent *aStartContent, const nsIContent* aEndContent, const nsIContent* aContent) const = 0;
virtual PRBool IsBefore(const nsIContent *aNewContent, const nsIContent* aCurrentContent) const = 0;
virtual PRBool IsInSelection(nsIDOMSelection* aSelection, const nsIContent *aContent) const = 0;
virtual nsIContent* GetPrevContent(const nsIContent *aContent) const = 0;
virtual nsIContent* GetNextContent(const nsIContent *aContent) const = 0;

View File

@ -2891,37 +2891,6 @@ nsIContent* nsDocument::FindContent(const nsIContent* aStartNode,
return nsnull;
}
PRBool nsDocument::IsInRange(const nsIContent *aStartContent, const nsIContent* aEndContent, const nsIContent* aContent) const
{
PRBool result;
if (aStartContent == aEndContent)
{
return PRBool(aContent == aStartContent);
}
else if (aStartContent == aContent || aEndContent == aContent)
{
result = PR_TRUE;
}
else
{
result = IsBefore(aStartContent,aContent);
if (result == PR_TRUE)
{
result = IsBefore(aContent,aEndContent);
if (!result)
{
// If aContent is a parent of aEndContent, then
// IsBefore returned false but IsInRange should be true.
if (FindContent(aContent, aEndContent, 0) == aEndContent)
result = PR_TRUE;
}
}
}
return result;
}
/**
* Determines if the content is found within the selection
@ -2935,37 +2904,17 @@ PRBool nsDocument::IsInSelection(nsIDOMSelection* aSelection, const nsIContent*
{
PRBool result = PR_FALSE;
if (aSelection != nsnull) {
//traverses through an iterator to see if the acontent is in the ranges
nsIEnumerator *enumerator;
if (NS_SUCCEEDED(aSelection->QueryInterface(kIEnumeratorIID, (void **)&enumerator)))
if (NS_SUCCEEDED(aSelection->QueryInterface(kIEnumeratorIID, (void **)&enumerator))
&& enumerator)
{
for (enumerator->First();NS_OK != enumerator->IsDone() ; enumerator->Next()) {
nsIDOMRange* range = nsnull;
if (NS_SUCCEEDED(enumerator->CurrentItem((nsISupports**)&range)))
{
nsIDOMNode* startNode = nsnull;
nsIDOMNode* endNode = nsnull;
range->GetStartParent(&startNode);
range->GetEndParent(&endNode);
if (startNode && endNode)
{
nsIContent* start;
nsIContent* end;
if (NS_SUCCEEDED(startNode->QueryInterface(kIContentIID, (void **)&start)) &&
NS_SUCCEEDED(endNode->QueryInterface(kIContentIID, (void **)&end)) )
{
result = IsInRange(start,end,aContent);
}
NS_IF_RELEASE(start);
NS_IF_RELEASE(end);
}
NS_IF_RELEASE(startNode);
NS_IF_RELEASE(endNode);
return IsNodeIntersectsRange(aContent, range);
NS_RELEASE(range);
}
if (result) break;
@ -2976,23 +2925,6 @@ PRBool nsDocument::IsInSelection(nsIDOMSelection* aSelection, const nsIContent*
return result;
}
PRBool nsDocument::IsBefore(const nsIContent *aNewContent, const nsIContent* aCurrentContent) const
{
PRBool result = PR_FALSE;
if (nsnull != aNewContent && nsnull != aCurrentContent && aNewContent != aCurrentContent)
{
nsIContent* test = FindContent(mRootContent,aNewContent,aCurrentContent);
if (test == aNewContent)
result = PR_TRUE;
NS_RELEASE(test);
}
return result;
}
nsIContent* nsDocument::GetPrevContent(const nsIContent *aContent) const
{
nsIContent* result = nsnull;

View File

@ -382,9 +382,7 @@ public:
nsEventStatus& aEventStatus);
virtual PRBool IsInRange(const nsIContent *aStartContent, const nsIContent* aEndContent, const nsIContent* aContent) const;
virtual PRBool IsInSelection(nsIDOMSelection* aSelection, const nsIContent *aContent) const;
virtual PRBool IsBefore(const nsIContent *aNewContent, const nsIContent* aCurrentContent) const;
virtual nsIContent* GetPrevContent(const nsIContent *aContent) const;
virtual nsIContent* GetNextContent(const nsIContent *aContent) const;
virtual void SetDisplaySelection(PRBool aToggle);

View File

@ -473,8 +473,6 @@ void nsHTMLContentSinkStream::EncodeToBuffer(const nsString& aSrc)
if (mUnicodeEncoder == nsnull)
return;
#define CH_NBSP 160
PRInt32 length = htmlstr.Length();
nsresult result;
@ -491,14 +489,20 @@ void nsHTMLContentSinkStream::EncodeToBuffer(const nsString& aSrc)
if (NS_SUCCEEDED(result))
result = mUnicodeEncoder->Finish(mBuffer,&temp);
#if 0
// Do some conversions to make up for the unicode encoder's foibles:
PRInt32 nbsp = nsHTMLEntities::EntityToUnicode(nsCAutoString("nbsp"));
PRInt32 quot = nsHTMLEntities::EntityToUnicode(nsCAutoString("quot"));
for (PRInt32 i = 0; i < mBufferLength; i++)
{
if (mBuffer[i] == char(CH_NBSP))
if (mBuffer[i] == quot)
mBuffer[i] = '"';
// I don't know why this nbsp mapping was here ...
else if (mBuffer[i] == nbsp)
mBuffer[i] = ' ';
}
}
#endif
}
@ -535,7 +539,6 @@ void nsHTMLContentSinkStream::Write(const nsString& aString)
}
}
void nsHTMLContentSinkStream::Write(const char* aData)
{
if (mStream)
@ -563,10 +566,6 @@ void nsHTMLContentSinkStream::Write(char aData)
}
/**
*
* @update 04/30/99 gpk
@ -1007,9 +1006,7 @@ nsHTMLContentSinkStream::AddLeaf(const nsIParserNode& aNode){
if (mHTMLStackPos > 0)
tag = mHTMLTagStack[mHTMLStackPos-1];
PRBool preformatted = PR_FALSE;
PRBool preformatted = PR_FALSE;
for (PRInt32 i = mHTMLStackPos-1; i >= 0; i--)
{

View File

@ -70,8 +70,8 @@ class nsHTMLContentSinkStream : public nsIHTMLContentSink {
nsHTMLContentSinkStream(nsIOutputStream* aOutStream,
nsString* aOutString,
const nsString* aCharsetOverride,
PRBool aDoFormat = PR_TRUE,
PRBool aDoHeader = PR_TRUE);
PRBool aDoFormat,
PRBool aDoHeader);
/**
* virtual destructor