restoring my original fix for 46554, with some additional tweaks to deal gracefully with generated content. To forgive, divine.

This commit is contained in:
jfrancis%netscape.com 2000-08-29 06:37:12 +00:00
parent 56ef0c603c
commit 995b111b30
3 changed files with 60 additions and 12 deletions

View File

@ -5239,7 +5239,7 @@ nsDOMSelection::ContainsNode(nsIDOMNode* aNode, PRBool aRecursive, PRBool* aYes)
nsCOMPtr<nsIDOMRange> range = do_QueryInterface(element);
if (!range)
return NS_ERROR_UNEXPECTED;
/*
// For bug 46554: since the only callers of ContainsNode() is the copy code from document,
// I'm altering the semantics of this routine. Now it will consider any node whose
// children are all selected to be selected itself. This is to help the user get
@ -5252,11 +5252,11 @@ nsDOMSelection::ContainsNode(nsIDOMNode* aNode, PRBool aRecursive, PRBool* aYes)
rv = PromoteRange(newrange);
if (NS_FAILED(rv)) return rv;
*/
nsCOMPtr<nsIContent> content (do_QueryInterface(aNode));
if (content)
{
if (IsNodeIntersectsRange(content, range))
if (IsNodeIntersectsRange(content, newrange))
{
// If recursive, then we're done -- IsNodeIntersectsRange does the right thing
if (aRecursive)
@ -5268,7 +5268,7 @@ nsDOMSelection::ContainsNode(nsIDOMNode* aNode, PRBool aRecursive, PRBool* aYes)
// else not recursive -- node itself must be contained,
// so we need to do more checking
PRBool nodeStartsBeforeRange, nodeEndsAfterRange;
if (NS_SUCCEEDED(CompareNodeToRange(content, range,
if (NS_SUCCEEDED(CompareNodeToRange(content, newrange,
&nodeStartsBeforeRange,
&nodeEndsAfterRange)))
{
@ -5363,11 +5363,19 @@ nsDOMSelection::GetPromotedPoint(Endpoint aWhere, nsIDOMNode *aNode, PRInt32 aOf
{
res = GetNodeLocation(node, &parent, &offset);
if (NS_FAILED(res)) return res;
if (offset == -1) return NS_OK; // we hit generated content; STOP
while ((IsFirstNode(node)) && (!IsBody(parent)))
{
node = parent;
res = GetNodeLocation(node, &parent, &offset);
if (NS_FAILED(res)) return res;
if (offset == -1) // we hit generated content; STOP
{
// back up a bit
parent = node;
offset = 0;
break;
}
}
*outNode = parent;
*outOffset = offset;
@ -5401,11 +5409,19 @@ nsDOMSelection::GetPromotedPoint(Endpoint aWhere, nsIDOMNode *aNode, PRInt32 aOf
{
res = GetNodeLocation(node, &parent, &offset);
if (NS_FAILED(res)) return res;
if (offset == -1) return NS_OK; // we hit generated content; STOP
while ((IsLastNode(node)) && (!IsBody(parent)))
{
node = parent;
res = GetNodeLocation(node, &parent, &offset);
if (NS_FAILED(res)) return res;
if (offset == -1) // we hit generated content; STOP
{
// back up a bit
parent = node;
offset = 0;
break;
}
}
*outNode = parent;
offset++; // add one since this in an endpoint - want to be AFTER node.

View File

@ -5239,7 +5239,7 @@ nsDOMSelection::ContainsNode(nsIDOMNode* aNode, PRBool aRecursive, PRBool* aYes)
nsCOMPtr<nsIDOMRange> range = do_QueryInterface(element);
if (!range)
return NS_ERROR_UNEXPECTED;
/*
// For bug 46554: since the only callers of ContainsNode() is the copy code from document,
// I'm altering the semantics of this routine. Now it will consider any node whose
// children are all selected to be selected itself. This is to help the user get
@ -5252,11 +5252,11 @@ nsDOMSelection::ContainsNode(nsIDOMNode* aNode, PRBool aRecursive, PRBool* aYes)
rv = PromoteRange(newrange);
if (NS_FAILED(rv)) return rv;
*/
nsCOMPtr<nsIContent> content (do_QueryInterface(aNode));
if (content)
{
if (IsNodeIntersectsRange(content, range))
if (IsNodeIntersectsRange(content, newrange))
{
// If recursive, then we're done -- IsNodeIntersectsRange does the right thing
if (aRecursive)
@ -5268,7 +5268,7 @@ nsDOMSelection::ContainsNode(nsIDOMNode* aNode, PRBool aRecursive, PRBool* aYes)
// else not recursive -- node itself must be contained,
// so we need to do more checking
PRBool nodeStartsBeforeRange, nodeEndsAfterRange;
if (NS_SUCCEEDED(CompareNodeToRange(content, range,
if (NS_SUCCEEDED(CompareNodeToRange(content, newrange,
&nodeStartsBeforeRange,
&nodeEndsAfterRange)))
{
@ -5363,11 +5363,19 @@ nsDOMSelection::GetPromotedPoint(Endpoint aWhere, nsIDOMNode *aNode, PRInt32 aOf
{
res = GetNodeLocation(node, &parent, &offset);
if (NS_FAILED(res)) return res;
if (offset == -1) return NS_OK; // we hit generated content; STOP
while ((IsFirstNode(node)) && (!IsBody(parent)))
{
node = parent;
res = GetNodeLocation(node, &parent, &offset);
if (NS_FAILED(res)) return res;
if (offset == -1) // we hit generated content; STOP
{
// back up a bit
parent = node;
offset = 0;
break;
}
}
*outNode = parent;
*outOffset = offset;
@ -5401,11 +5409,19 @@ nsDOMSelection::GetPromotedPoint(Endpoint aWhere, nsIDOMNode *aNode, PRInt32 aOf
{
res = GetNodeLocation(node, &parent, &offset);
if (NS_FAILED(res)) return res;
if (offset == -1) return NS_OK; // we hit generated content; STOP
while ((IsLastNode(node)) && (!IsBody(parent)))
{
node = parent;
res = GetNodeLocation(node, &parent, &offset);
if (NS_FAILED(res)) return res;
if (offset == -1) // we hit generated content; STOP
{
// back up a bit
parent = node;
offset = 0;
break;
}
}
*outNode = parent;
offset++; // add one since this in an endpoint - want to be AFTER node.

View File

@ -5239,7 +5239,7 @@ nsDOMSelection::ContainsNode(nsIDOMNode* aNode, PRBool aRecursive, PRBool* aYes)
nsCOMPtr<nsIDOMRange> range = do_QueryInterface(element);
if (!range)
return NS_ERROR_UNEXPECTED;
/*
// For bug 46554: since the only callers of ContainsNode() is the copy code from document,
// I'm altering the semantics of this routine. Now it will consider any node whose
// children are all selected to be selected itself. This is to help the user get
@ -5252,11 +5252,11 @@ nsDOMSelection::ContainsNode(nsIDOMNode* aNode, PRBool aRecursive, PRBool* aYes)
rv = PromoteRange(newrange);
if (NS_FAILED(rv)) return rv;
*/
nsCOMPtr<nsIContent> content (do_QueryInterface(aNode));
if (content)
{
if (IsNodeIntersectsRange(content, range))
if (IsNodeIntersectsRange(content, newrange))
{
// If recursive, then we're done -- IsNodeIntersectsRange does the right thing
if (aRecursive)
@ -5268,7 +5268,7 @@ nsDOMSelection::ContainsNode(nsIDOMNode* aNode, PRBool aRecursive, PRBool* aYes)
// else not recursive -- node itself must be contained,
// so we need to do more checking
PRBool nodeStartsBeforeRange, nodeEndsAfterRange;
if (NS_SUCCEEDED(CompareNodeToRange(content, range,
if (NS_SUCCEEDED(CompareNodeToRange(content, newrange,
&nodeStartsBeforeRange,
&nodeEndsAfterRange)))
{
@ -5363,11 +5363,19 @@ nsDOMSelection::GetPromotedPoint(Endpoint aWhere, nsIDOMNode *aNode, PRInt32 aOf
{
res = GetNodeLocation(node, &parent, &offset);
if (NS_FAILED(res)) return res;
if (offset == -1) return NS_OK; // we hit generated content; STOP
while ((IsFirstNode(node)) && (!IsBody(parent)))
{
node = parent;
res = GetNodeLocation(node, &parent, &offset);
if (NS_FAILED(res)) return res;
if (offset == -1) // we hit generated content; STOP
{
// back up a bit
parent = node;
offset = 0;
break;
}
}
*outNode = parent;
*outOffset = offset;
@ -5401,11 +5409,19 @@ nsDOMSelection::GetPromotedPoint(Endpoint aWhere, nsIDOMNode *aNode, PRInt32 aOf
{
res = GetNodeLocation(node, &parent, &offset);
if (NS_FAILED(res)) return res;
if (offset == -1) return NS_OK; // we hit generated content; STOP
while ((IsLastNode(node)) && (!IsBody(parent)))
{
node = parent;
res = GetNodeLocation(node, &parent, &offset);
if (NS_FAILED(res)) return res;
if (offset == -1) // we hit generated content; STOP
{
// back up a bit
parent = node;
offset = 0;
break;
}
}
*outNode = parent;
offset++; // add one since this in an endpoint - want to be AFTER node.