Bug 1635709: part 11) Factor removing generated ranges out from `AutoPrepareFocusRange`. r=masayuki

Differential Revision: https://phabricator.services.mozilla.com/D74857
This commit is contained in:
Mirko Brodesser 2020-05-13 08:00:51 +00:00
Родитель cb2a7735a3
Коммит 3310444867
1 изменённых файлов: 16 добавлений и 11 удалений

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

@ -277,23 +277,28 @@ struct MOZ_RAII AutoPrepareFocusRange {
range->SetIsGenerated(false);
aSelection->mAnchorFocusRange = range;
// Remove all generated ranges (including the old mAnchorFocusRange).
RefPtr<nsPresContext> presContext = aSelection->GetPresContext();
size_t i = len;
while (i--) {
range = aSelection->mStyledRanges.mRanges[i].mRange;
if (range->IsGenerated()) {
range->UnregisterSelection();
aSelection->SelectFrames(presContext, range, false);
aSelection->mStyledRanges.mRanges.RemoveElementAt(i);
}
}
RemoveGeneratedRanges(*aSelection);
if (aSelection->mFrameSelection) {
aSelection->mFrameSelection->InvalidateDesiredCaretPos();
}
}
private:
static void RemoveGeneratedRanges(Selection& aSelection) {
RefPtr<nsPresContext> presContext = aSelection.GetPresContext();
nsTArray<StyledRange>& ranges = aSelection.mStyledRanges.mRanges;
size_t i = ranges.Length();
while (i--) {
nsRange* range = ranges[i].mRange;
if (range->IsGenerated()) {
range->UnregisterSelection();
aSelection.SelectFrames(presContext, range, false);
ranges.RemoveElementAt(i);
}
}
}
/**
* @aParam aSelectionChangeReasons can be multiple of the reasons defined in
nsISelectionListener.idl.