Bug 771873 part 1 - Check for reversed indices in Selection::GetIndicesForInterval; r=ehsan

This commit is contained in:
Aryeh Gregor 2012-07-12 18:56:30 +03:00
Родитель aa41501b44
Коммит 98c0f7c228
2 изменённых файлов: 30 добавлений и 21 удалений

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

@ -188,10 +188,10 @@ private:
bool EqualsRangeAtPoint(nsINode* aBeginNode, PRInt32 aBeginOffset,
nsINode* aEndNode, PRInt32 aEndOffset,
PRInt32 aRangeIndex);
void GetIndicesForInterval(nsINode* aBeginNode, PRInt32 aBeginOffset,
nsINode* aEndNode, PRInt32 aEndOffset,
bool aAllowAdjacent,
PRInt32 *aStartIndex, PRInt32 *aEndIndex);
nsresult GetIndicesForInterval(nsINode* aBeginNode, PRInt32 aBeginOffset,
nsINode* aEndNode, PRInt32 aEndOffset,
bool aAllowAdjacent,
PRInt32* aStartIndex, PRInt32* aEndIndex);
RangeData* FindRangeData(nsIDOMRange* aRange);
// These are the ranges inside this selection. They are kept sorted in order

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

@ -3474,9 +3474,12 @@ Selection::AddItem(nsRange* aItem, PRInt32* aOutIndex)
}
PRInt32 startIndex, endIndex;
GetIndicesForInterval(aItem->GetStartParent(), aItem->StartOffset(),
aItem->GetEndParent(), aItem->EndOffset(),
false, &startIndex, &endIndex);
nsresult rv = GetIndicesForInterval(aItem->GetStartParent(),
aItem->StartOffset(),
aItem->GetEndParent(),
aItem->EndOffset(), false,
&startIndex, &endIndex);
NS_ENSURE_SUCCESS(rv, rv);
if (endIndex == -1) {
// All ranges start after the given range. We can insert our range at
@ -3540,10 +3543,9 @@ Selection::AddItem(nsRange* aItem, PRInt32* aOutIndex)
// Insert the new element into our "leftovers" array
PRInt32 insertionPoint;
nsresult rv = FindInsertionPoint(&temp, aItem->GetStartParent(),
aItem->StartOffset(),
CompareToRangeStart,
&insertionPoint);
rv = FindInsertionPoint(&temp, aItem->GetStartParent(),
aItem->StartOffset(), CompareToRangeStart,
&insertionPoint);
NS_ENSURE_SUCCESS(rv, rv);
if (!temp.InsertElementAt(insertionPoint, RangeData(aItem)))
@ -3738,8 +3740,11 @@ Selection::GetRangesForIntervalArray(nsINode* aBeginNode, PRInt32 aBeginOffset,
{
aRanges->Clear();
PRInt32 startIndex, endIndex;
GetIndicesForInterval(aBeginNode, aBeginOffset, aEndNode, aEndOffset,
aAllowAdjacent, &startIndex, &endIndex);
nsresult res = GetIndicesForInterval(aBeginNode, aBeginOffset,
aEndNode, aEndOffset, aAllowAdjacent,
&startIndex, &endIndex);
NS_ENSURE_SUCCESS(res, res);
if (startIndex == -1 || endIndex == -1)
return NS_OK;
@ -3757,7 +3762,7 @@ Selection::GetRangesForIntervalArray(nsINode* aBeginNode, PRInt32 aBeginOffset,
// instead this returns the indices into mRanges between which the
// overlapping ranges lie.
void
nsresult
Selection::GetIndicesForInterval(nsINode* aBeginNode, PRInt32 aBeginOffset,
nsINode* aEndNode, PRInt32 aEndOffset,
bool aAllowAdjacent,
@ -3775,7 +3780,7 @@ Selection::GetIndicesForInterval(nsINode* aBeginNode, PRInt32 aBeginOffset,
*aEndIndex = -1;
if (mRanges.Length() == 0)
return;
return NS_OK;
bool intervalIsCollapsed = aBeginNode == aEndNode &&
aBeginOffset == aEndOffset;
@ -3786,7 +3791,7 @@ Selection::GetIndicesForInterval(nsINode* aBeginNode, PRInt32 aBeginOffset,
if (NS_FAILED(FindInsertionPoint(&mRanges, aEndNode, aEndOffset,
&CompareToRangeStart,
&endsBeforeIndex))) {
return;
return NS_OK;
}
if (endsBeforeIndex == 0) {
@ -3795,7 +3800,7 @@ Selection::GetIndicesForInterval(nsINode* aBeginNode, PRInt32 aBeginOffset,
// If the interval is strictly before the range at index 0, we can optimize
// by returning now - all ranges start after the given interval
if (!RangeMatchesBeginPoint(endRange, aEndNode, aEndOffset))
return;
return NS_OK;
// We now know that the start point of mRanges[0].mRange equals the end of
// the interval. Thus, when aAllowadjacent is true, the caller is always
@ -3803,7 +3808,7 @@ Selection::GetIndicesForInterval(nsINode* aBeginNode, PRInt32 aBeginOffset,
// remember to include the range when both it and the given interval are
// collapsed to the same point
if (!aAllowAdjacent && !(endRange->Collapsed() && intervalIsCollapsed))
return;
return NS_OK;
}
*aEndIndex = endsBeforeIndex;
@ -3811,10 +3816,10 @@ Selection::GetIndicesForInterval(nsINode* aBeginNode, PRInt32 aBeginOffset,
if (NS_FAILED(FindInsertionPoint(&mRanges, aBeginNode, aBeginOffset,
&CompareToRangeEnd,
&beginsAfterIndex))) {
return;
return NS_OK;
}
if (beginsAfterIndex == (PRInt32) mRanges.Length())
return; // optimization: all ranges are strictly before us
return NS_OK; // optimization: all ranges are strictly before us
if (aAllowAdjacent) {
// At this point, one of the following holds:
@ -3874,9 +3879,13 @@ Selection::GetIndicesForInterval(nsINode* aBeginNode, PRInt32 aBeginOffset,
}
}
NS_ASSERTION(beginsAfterIndex <= endsBeforeIndex,
"Is mRanges not ordered?");
NS_ENSURE_STATE(beginsAfterIndex <= endsBeforeIndex);
*aStartIndex = beginsAfterIndex;
*aEndIndex = endsBeforeIndex;
return;
return NS_OK;
}
NS_IMETHODIMP