Bug 488417. Need to hold strong refs to ranges across calling RemoveRange. r+sr=roc

This commit is contained in:
Boris Zbarsky 2009-04-21 15:57:40 -04:00
parent e66e25e993
commit 1c4f1309c3
3 changed files with 65 additions and 2 deletions

View File

@ -213,6 +213,8 @@ public:
nsresult Collapse(nsINode* aParentNode, PRInt32 aOffset);
nsresult Extend(nsINode* aParentNode, PRInt32 aOffset);
nsresult AddRange(nsIRange* aRange);
// The nsIRange version of RemoveRange assumes the caller is holding
// a strong reference to aRange.
nsresult RemoveRange(nsIRange* aRange);
nsIRange* GetRangeAt(PRInt32 aIndex);
nsresult GetTableSelectionType(nsIRange* aRange,
@ -2711,7 +2713,9 @@ printf("HandleTableSelection: Unselecting mUnselectCellOnMouseUp; rangeCount=%d\
#endif
for( PRInt32 i = 0; i < rangeCount; i++)
{
nsIRange* range = mDomSelections[index]->GetRangeAt(i);
// Strong reference, because sometimes we want to remove
// this range, and then we might be the only owner.
nsCOMPtr<nsIRange> range = mDomSelections[index]->GetRangeAt(i);
if (!range) return NS_ERROR_NULL_POINTER;
nsINode* parent = range->GetStartParent();
@ -2799,7 +2803,8 @@ nsFrameSelection::SelectBlockOfCells(nsIContent *aStartCell, nsIContent *aEndCel
if (!mDomSelections[index])
return NS_ERROR_NULL_POINTER;
nsIRange* range = GetFirstCellRange();
// Strong reference because we sometimes remove the range
nsCOMPtr<nsIRange> range = GetFirstCellRange();
nsIContent* cellNode = GetFirstSelectedContent(range);
NS_PRECONDITION(!range || cellNode, "Must have cellNode if had a range");

View File

@ -75,6 +75,7 @@ _TEST_FILES = \
test_bug468167.html \
test_bug469613.xul \
test_bug470212.html \
test_bug488417.html \
test_movement_by_characters.html \
test_movement_by_words.html \
test_plugin_clipping.xhtml \

View File

@ -0,0 +1,57 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=488417
-->
<head>
<title>Test for Bug 488417</title>
<script type="application/javascript" src="/MochiKit/MochiKit.js"></script>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=488417">Mozilla Bug 488417</a>
<div id="display">
<table border="1">
<tr>
<td id="a">A1</td>
<td id="b">B1</td>
</tr>
<tr>
<td>A2</td>
<td>B2</td>
</tr>
</table>
</div>
<div id="content" style="display: none">
</div>
<pre id="test">
<script type="application/javascript">
function clickIt(node) {
synthesizeMouse(node, node.getBoundingClientRect().width/2,
node.getBoundingClientRect().height/2,
{ accelKey: 1 });
}
/** Test for Bug 488417 **/
SimpleTest.waitForExplicitFinish();
addLoadEvent(function() {
// Do the test async so we can unsuppress painting
SimpleTest.executeSoon(function() {
clickIt($("a"));
clickIt($("b"));
clickIt($("a"));
ok(1, "Got here");
SimpleTest.finish();
});
});
</script>
</pre>
</body>
</html>