added a param to GetPriorNode and GetNextNode to tell these methods whether to use or skip

non-editable content.
added some comments, turned off some debugging flags.
This commit is contained in:
buster%netscape.com 1999-05-05 04:51:54 +00:00
Родитель 0410d0a2f2
Коммит cadc514e1d
7 изменённых файлов: 200 добавлений и 54 удалений

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

@ -150,7 +150,7 @@ const char* nsEditor::kMOZEditorBogusNodeAttr="MOZ_EDITOR_BOGUS_NODE";
const char* nsEditor::kMOZEditorBogusNodeValue="TRUE";
#ifdef NS_DEBUG_EDITOR
static PRBool gNoisy = PR_TRUE;
static PRBool gNoisy = PR_FALSE;
#else
static const PRBool gNoisy = PR_FALSE;
#endif
@ -1622,7 +1622,7 @@ nsEditor::CreateTxnForDeleteInsertionPoint(nsIDOMRange *aRange,
if ((nsIEditor::eRTL==aDir) && (PR_TRUE==isFirst))
{ // we're backspacing from the beginning of the node. Delete the first thing to our left
nsCOMPtr<nsIDOMNode> priorNode;
result = GetPriorNode(node, getter_AddRefs(priorNode));
result = GetPriorNode(node, PR_TRUE, getter_AddRefs(priorNode));
if ((NS_SUCCEEDED(result)) && priorNode)
{ // there is a priorNode, so delete it's last child (if text content, delete the last char.)
// if it has no children, delete it
@ -1659,7 +1659,7 @@ nsEditor::CreateTxnForDeleteInsertionPoint(nsIDOMRange *aRange,
else if ((nsIEditor::eLTR==aDir) && (PR_TRUE==isLast))
{ // we're deleting from the end of the node. Delete the first thing to our right
nsCOMPtr<nsIDOMNode> nextNode;
result = GetNextNode(node, getter_AddRefs(nextNode));
result = GetNextNode(node, PR_TRUE, getter_AddRefs(nextNode));
if ((NS_SUCCEEDED(result)) && nextNode)
{ // there is a priorNode, so delete it's last child (if text content, delete the last char.)
// if it has no children, delete it
@ -2343,19 +2343,37 @@ nsEditor::IntermediateNodesAreInline(nsIDOMRange *aRange,
nsresult
nsEditor::GetPriorNode(nsIDOMNode *aCurrentNode, nsIDOMNode **aResultNode)
nsEditor::GetPriorNode(nsIDOMNode *aCurrentNode,
PRBool aEditableNode,
nsIDOMNode **aResultNode)
{
nsresult result;
*aResultNode = nsnull;
if (!aCurrentNode || !aResultNode) { return NS_ERROR_NULL_POINTER; }
*aResultNode = nsnull; // init out-param
// if aCurrentNode has a left sibling, return that sibling's rightmost child (or itself if it has no children)
result = aCurrentNode->GetPreviousSibling(aResultNode);
if ((NS_SUCCEEDED(result)) && *aResultNode)
return GetRightmostChild(*aResultNode, aResultNode);
{
result = GetRightmostChild(*aResultNode, aResultNode);
if (NS_FAILED(result)) { return result; }
if (PR_FALSE==aEditableNode) {
return result;
}
if (PR_TRUE==IsEditable(*aResultNode)) {
return result;
}
else
{ // restart the search from the non-editable node we just found
nsCOMPtr<nsIDOMNode> notEditableNode = do_QueryInterface(*aResultNode);
return GetPriorNode(notEditableNode, aEditableNode, aResultNode);
}
}
// otherwise, walk up the parent change until there is a child that comes before
// the ancestor of aCurrentNode. Then return that node's rightmost child
nsCOMPtr<nsIDOMNode> parent(do_QueryInterface(aCurrentNode));
nsCOMPtr<nsIDOMNode> parent = do_QueryInterface(aCurrentNode);
do {
nsCOMPtr<nsIDOMNode> node(parent);
result = node->GetParentNode(getter_AddRefs(parent));
@ -2364,8 +2382,19 @@ nsEditor::GetPriorNode(nsIDOMNode *aCurrentNode, nsIDOMNode **aResultNode)
result = parent->GetPreviousSibling(getter_AddRefs(node));
if ((NS_SUCCEEDED(result)) && node)
{
return GetRightmostChild(node, aResultNode);
result = GetRightmostChild(node, aResultNode);
if (NS_FAILED(result)) { return result; }
if (PR_FALSE==aEditableNode) {
return result;
}
if (PR_TRUE==IsEditable(*aResultNode)) {
return result;
}
else
{ // restart the search from the non-editable node we just found
nsCOMPtr<nsIDOMNode> notEditableNode = do_QueryInterface(*aResultNode);
return GetPriorNode(notEditableNode, aEditableNode, aResultNode);
}
}
}
} while ((NS_SUCCEEDED(result)) && parent);
@ -2374,14 +2403,30 @@ nsEditor::GetPriorNode(nsIDOMNode *aCurrentNode, nsIDOMNode **aResultNode)
}
nsresult
nsEditor::GetNextNode(nsIDOMNode *aCurrentNode, nsIDOMNode **aResultNode)
nsEditor::GetNextNode(nsIDOMNode *aCurrentNode,
PRBool aEditableNode,
nsIDOMNode **aResultNode)
{
nsresult result;
*aResultNode = nsnull;
// if aCurrentNode has a right sibling, return that sibling's leftmost child (or itself if it has no children)
result = aCurrentNode->GetNextSibling(aResultNode);
if ((NS_SUCCEEDED(result)) && *aResultNode)
return GetLeftmostChild(*aResultNode, aResultNode);
{
result = GetLeftmostChild(*aResultNode, aResultNode);
if (NS_FAILED(result)) { return result; }
if (PR_FALSE==aEditableNode) {
return result;
}
if (PR_TRUE==IsEditable(*aResultNode)) {
return result;
}
else
{ // restart the search from the non-editable node we just found
nsCOMPtr<nsIDOMNode> notEditableNode = do_QueryInterface(*aResultNode);
return GetNextNode(notEditableNode, aEditableNode, aResultNode);
}
}
// otherwise, walk up the parent change until there is a child that comes before
// the ancestor of aCurrentNode. Then return that node's rightmost child
@ -2395,7 +2440,19 @@ nsEditor::GetNextNode(nsIDOMNode *aCurrentNode, nsIDOMNode **aResultNode)
result = parent->GetNextSibling(getter_AddRefs(node));
if ((NS_SUCCEEDED(result)) && node)
{
return GetLeftmostChild(node, aResultNode);
result = GetLeftmostChild(node, aResultNode);
if (NS_FAILED(result)) { return result; }
if (PR_FALSE==aEditableNode) {
return result;
}
if (PR_TRUE==IsEditable(*aResultNode)) {
return result;
}
else
{ // restart the search from the non-editable node we just found
nsCOMPtr<nsIDOMNode> notEditableNode = do_QueryInterface(*aResultNode);
return GetNextNode(notEditableNode, aEditableNode, aResultNode);
}
}
}
} while ((NS_SUCCEEDED(result)) && parent);

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

@ -384,20 +384,36 @@ public:
*/
static nsresult GetLengthOfDOMNode(nsIDOMNode *aNode, PRUint32 &aCount);
/**
*/
static nsresult GetPriorNode(nsIDOMNode *aCurrentNode, nsIDOMNode **aResultNode);
/** get the node immediately prior to aCurrentNode
* @param aCurrentNode the node from which we start the search
* @param aEditableNode if PR_TRUE, only return an editable node
* @param aResultNode [OUT] the node that occurs before aCurrentNode in the tree,
* skipping non-editable nodes if aEditableNode is PR_TRUE.
* If there is no prior node, aResultNode will be nsnull.
*/
static nsresult GetPriorNode(nsIDOMNode *aCurrentNode,
PRBool aEditableNode,
nsIDOMNode **aResultNode);
/**
*/
static nsresult GetNextNode(nsIDOMNode *aCurrentNode, nsIDOMNode **aResultNode);
/** get the node immediately after to aCurrentNode
* @param aCurrentNode the node from which we start the search
* @param aEditableNode if PR_TRUE, only return an editable node
* @param aResultNode [OUT] the node that occurs after aCurrentNode in the tree,
* skipping non-editable nodes if aEditableNode is PR_TRUE.
* If there is no prior node, aResultNode will be nsnull.
*/
static nsresult GetNextNode(nsIDOMNode *aCurrentNode,
PRBool aEditableNode,
nsIDOMNode **aResultNode);
/**
*/
/** Get the rightmost child of aCurrentNode, and return it in aResultNode
* aResultNode is set to nsnull if aCurrentNode has no children.
*/
static nsresult GetRightmostChild(nsIDOMNode *aCurrentNode, nsIDOMNode **aResultNode);
/**
*/
/** Get the leftmost child of aCurrentNode, and return it in aResultNode
* aResultNode is set to nsnull if aCurrentNode has no children.
*/
static nsresult GetLeftmostChild(nsIDOMNode *aCurrentNode, nsIDOMNode **aResultNode);
/** GetFirstTextNode ADDREFFS and will get the next available text node from the passed

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

@ -58,7 +58,7 @@ static NS_DEFINE_CID(kCContentIteratorCID, NS_CONTENTITERATOR_CID);
static NS_DEFINE_IID(kIContentIteratorIID, NS_ICONTENTITERTOR_IID);
#ifdef NS_DEBUG
static PRBool gNoisy = PR_TRUE;
static PRBool gNoisy = PR_FALSE;
#else
static const PRBool gNoisy = PR_FALSE;
#endif
@ -771,7 +771,7 @@ nsHTMLEditor::ReParentBlockContent(nsIDOMNode *aNode,
{
// if the prior node is a <BR> and we did something to change vertical whitespacing, delete the <BR>
nsCOMPtr<nsIDOMNode> brNode;
result = GetPriorNode(leftNode, getter_AddRefs(brNode));
result = GetPriorNode(leftNode, PR_TRUE, getter_AddRefs(brNode));
if (NS_SUCCEEDED(result) && brNode)
{
nsCOMPtr<nsIContent> brContent = do_QueryInterface(brNode);
@ -788,7 +788,7 @@ nsHTMLEditor::ReParentBlockContent(nsIDOMNode *aNode,
// if the next node is a <BR> and we did something to change vertical whitespacing, delete the <BR>
if (NS_SUCCEEDED(result))
{
result = GetNextNode(rightNode, getter_AddRefs(brNode));
result = GetNextNode(rightNode, PR_TRUE, getter_AddRefs(brNode));
if (NS_SUCCEEDED(result) && brNode)
{
nsCOMPtr<nsIContent> brContent = do_QueryInterface(brNode);

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

@ -95,7 +95,7 @@ static NS_DEFINE_IID(kIInputStreamIID, NS_IINPUTSTREAM_IID);
static NS_DEFINE_IID(kIOutputStreamIID, NS_IOUTPUTSTREAM_IID);
#ifdef NS_DEBUG
static PRBool gNoisy = PR_TRUE;
static PRBool gNoisy = PR_FALSE;
#else
static const PRBool gNoisy = PR_FALSE;
#endif
@ -1910,7 +1910,7 @@ nsTextEditor::RemoveTextPropertiesForNodeWithDifferentParents(nsIDOMNode *aStar
// compute the start node
nsCOMPtr<nsIDOMNode>startNode = do_QueryInterface(aStartNode);
if (PR_TRUE==skippedStartNode) {
nsEditor::GetNextNode(aStartNode, getter_AddRefs(startNode));
nsEditor::GetNextNode(aStartNode, PR_TRUE, getter_AddRefs(startNode));
}
range->SetStart(startNode, rangeStartOffset);
range->SetEnd(aEndNode, rangeEndOffset);

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

@ -150,7 +150,7 @@ const char* nsEditor::kMOZEditorBogusNodeAttr="MOZ_EDITOR_BOGUS_NODE";
const char* nsEditor::kMOZEditorBogusNodeValue="TRUE";
#ifdef NS_DEBUG_EDITOR
static PRBool gNoisy = PR_TRUE;
static PRBool gNoisy = PR_FALSE;
#else
static const PRBool gNoisy = PR_FALSE;
#endif
@ -1622,7 +1622,7 @@ nsEditor::CreateTxnForDeleteInsertionPoint(nsIDOMRange *aRange,
if ((nsIEditor::eRTL==aDir) && (PR_TRUE==isFirst))
{ // we're backspacing from the beginning of the node. Delete the first thing to our left
nsCOMPtr<nsIDOMNode> priorNode;
result = GetPriorNode(node, getter_AddRefs(priorNode));
result = GetPriorNode(node, PR_TRUE, getter_AddRefs(priorNode));
if ((NS_SUCCEEDED(result)) && priorNode)
{ // there is a priorNode, so delete it's last child (if text content, delete the last char.)
// if it has no children, delete it
@ -1659,7 +1659,7 @@ nsEditor::CreateTxnForDeleteInsertionPoint(nsIDOMRange *aRange,
else if ((nsIEditor::eLTR==aDir) && (PR_TRUE==isLast))
{ // we're deleting from the end of the node. Delete the first thing to our right
nsCOMPtr<nsIDOMNode> nextNode;
result = GetNextNode(node, getter_AddRefs(nextNode));
result = GetNextNode(node, PR_TRUE, getter_AddRefs(nextNode));
if ((NS_SUCCEEDED(result)) && nextNode)
{ // there is a priorNode, so delete it's last child (if text content, delete the last char.)
// if it has no children, delete it
@ -2343,19 +2343,37 @@ nsEditor::IntermediateNodesAreInline(nsIDOMRange *aRange,
nsresult
nsEditor::GetPriorNode(nsIDOMNode *aCurrentNode, nsIDOMNode **aResultNode)
nsEditor::GetPriorNode(nsIDOMNode *aCurrentNode,
PRBool aEditableNode,
nsIDOMNode **aResultNode)
{
nsresult result;
*aResultNode = nsnull;
if (!aCurrentNode || !aResultNode) { return NS_ERROR_NULL_POINTER; }
*aResultNode = nsnull; // init out-param
// if aCurrentNode has a left sibling, return that sibling's rightmost child (or itself if it has no children)
result = aCurrentNode->GetPreviousSibling(aResultNode);
if ((NS_SUCCEEDED(result)) && *aResultNode)
return GetRightmostChild(*aResultNode, aResultNode);
{
result = GetRightmostChild(*aResultNode, aResultNode);
if (NS_FAILED(result)) { return result; }
if (PR_FALSE==aEditableNode) {
return result;
}
if (PR_TRUE==IsEditable(*aResultNode)) {
return result;
}
else
{ // restart the search from the non-editable node we just found
nsCOMPtr<nsIDOMNode> notEditableNode = do_QueryInterface(*aResultNode);
return GetPriorNode(notEditableNode, aEditableNode, aResultNode);
}
}
// otherwise, walk up the parent change until there is a child that comes before
// the ancestor of aCurrentNode. Then return that node's rightmost child
nsCOMPtr<nsIDOMNode> parent(do_QueryInterface(aCurrentNode));
nsCOMPtr<nsIDOMNode> parent = do_QueryInterface(aCurrentNode);
do {
nsCOMPtr<nsIDOMNode> node(parent);
result = node->GetParentNode(getter_AddRefs(parent));
@ -2364,8 +2382,19 @@ nsEditor::GetPriorNode(nsIDOMNode *aCurrentNode, nsIDOMNode **aResultNode)
result = parent->GetPreviousSibling(getter_AddRefs(node));
if ((NS_SUCCEEDED(result)) && node)
{
return GetRightmostChild(node, aResultNode);
result = GetRightmostChild(node, aResultNode);
if (NS_FAILED(result)) { return result; }
if (PR_FALSE==aEditableNode) {
return result;
}
if (PR_TRUE==IsEditable(*aResultNode)) {
return result;
}
else
{ // restart the search from the non-editable node we just found
nsCOMPtr<nsIDOMNode> notEditableNode = do_QueryInterface(*aResultNode);
return GetPriorNode(notEditableNode, aEditableNode, aResultNode);
}
}
}
} while ((NS_SUCCEEDED(result)) && parent);
@ -2374,14 +2403,30 @@ nsEditor::GetPriorNode(nsIDOMNode *aCurrentNode, nsIDOMNode **aResultNode)
}
nsresult
nsEditor::GetNextNode(nsIDOMNode *aCurrentNode, nsIDOMNode **aResultNode)
nsEditor::GetNextNode(nsIDOMNode *aCurrentNode,
PRBool aEditableNode,
nsIDOMNode **aResultNode)
{
nsresult result;
*aResultNode = nsnull;
// if aCurrentNode has a right sibling, return that sibling's leftmost child (or itself if it has no children)
result = aCurrentNode->GetNextSibling(aResultNode);
if ((NS_SUCCEEDED(result)) && *aResultNode)
return GetLeftmostChild(*aResultNode, aResultNode);
{
result = GetLeftmostChild(*aResultNode, aResultNode);
if (NS_FAILED(result)) { return result; }
if (PR_FALSE==aEditableNode) {
return result;
}
if (PR_TRUE==IsEditable(*aResultNode)) {
return result;
}
else
{ // restart the search from the non-editable node we just found
nsCOMPtr<nsIDOMNode> notEditableNode = do_QueryInterface(*aResultNode);
return GetNextNode(notEditableNode, aEditableNode, aResultNode);
}
}
// otherwise, walk up the parent change until there is a child that comes before
// the ancestor of aCurrentNode. Then return that node's rightmost child
@ -2395,7 +2440,19 @@ nsEditor::GetNextNode(nsIDOMNode *aCurrentNode, nsIDOMNode **aResultNode)
result = parent->GetNextSibling(getter_AddRefs(node));
if ((NS_SUCCEEDED(result)) && node)
{
return GetLeftmostChild(node, aResultNode);
result = GetLeftmostChild(node, aResultNode);
if (NS_FAILED(result)) { return result; }
if (PR_FALSE==aEditableNode) {
return result;
}
if (PR_TRUE==IsEditable(*aResultNode)) {
return result;
}
else
{ // restart the search from the non-editable node we just found
nsCOMPtr<nsIDOMNode> notEditableNode = do_QueryInterface(*aResultNode);
return GetNextNode(notEditableNode, aEditableNode, aResultNode);
}
}
}
} while ((NS_SUCCEEDED(result)) && parent);

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

@ -384,20 +384,36 @@ public:
*/
static nsresult GetLengthOfDOMNode(nsIDOMNode *aNode, PRUint32 &aCount);
/**
*/
static nsresult GetPriorNode(nsIDOMNode *aCurrentNode, nsIDOMNode **aResultNode);
/** get the node immediately prior to aCurrentNode
* @param aCurrentNode the node from which we start the search
* @param aEditableNode if PR_TRUE, only return an editable node
* @param aResultNode [OUT] the node that occurs before aCurrentNode in the tree,
* skipping non-editable nodes if aEditableNode is PR_TRUE.
* If there is no prior node, aResultNode will be nsnull.
*/
static nsresult GetPriorNode(nsIDOMNode *aCurrentNode,
PRBool aEditableNode,
nsIDOMNode **aResultNode);
/**
*/
static nsresult GetNextNode(nsIDOMNode *aCurrentNode, nsIDOMNode **aResultNode);
/** get the node immediately after to aCurrentNode
* @param aCurrentNode the node from which we start the search
* @param aEditableNode if PR_TRUE, only return an editable node
* @param aResultNode [OUT] the node that occurs after aCurrentNode in the tree,
* skipping non-editable nodes if aEditableNode is PR_TRUE.
* If there is no prior node, aResultNode will be nsnull.
*/
static nsresult GetNextNode(nsIDOMNode *aCurrentNode,
PRBool aEditableNode,
nsIDOMNode **aResultNode);
/**
*/
/** Get the rightmost child of aCurrentNode, and return it in aResultNode
* aResultNode is set to nsnull if aCurrentNode has no children.
*/
static nsresult GetRightmostChild(nsIDOMNode *aCurrentNode, nsIDOMNode **aResultNode);
/**
*/
/** Get the leftmost child of aCurrentNode, and return it in aResultNode
* aResultNode is set to nsnull if aCurrentNode has no children.
*/
static nsresult GetLeftmostChild(nsIDOMNode *aCurrentNode, nsIDOMNode **aResultNode);
/** GetFirstTextNode ADDREFFS and will get the next available text node from the passed

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

@ -58,7 +58,7 @@ static NS_DEFINE_CID(kCContentIteratorCID, NS_CONTENTITERATOR_CID);
static NS_DEFINE_IID(kIContentIteratorIID, NS_ICONTENTITERTOR_IID);
#ifdef NS_DEBUG
static PRBool gNoisy = PR_TRUE;
static PRBool gNoisy = PR_FALSE;
#else
static const PRBool gNoisy = PR_FALSE;
#endif
@ -771,7 +771,7 @@ nsHTMLEditor::ReParentBlockContent(nsIDOMNode *aNode,
{
// if the prior node is a <BR> and we did something to change vertical whitespacing, delete the <BR>
nsCOMPtr<nsIDOMNode> brNode;
result = GetPriorNode(leftNode, getter_AddRefs(brNode));
result = GetPriorNode(leftNode, PR_TRUE, getter_AddRefs(brNode));
if (NS_SUCCEEDED(result) && brNode)
{
nsCOMPtr<nsIContent> brContent = do_QueryInterface(brNode);
@ -788,7 +788,7 @@ nsHTMLEditor::ReParentBlockContent(nsIDOMNode *aNode,
// if the next node is a <BR> and we did something to change vertical whitespacing, delete the <BR>
if (NS_SUCCEEDED(result))
{
result = GetNextNode(rightNode, getter_AddRefs(brNode));
result = GetNextNode(rightNode, PR_TRUE, getter_AddRefs(brNode));
if (NS_SUCCEEDED(result) && brNode)
{
nsCOMPtr<nsIContent> brContent = do_QueryInterface(brNode);