Bug 1615581: part 8) Decouple `CreateAndAddRange` from `nsFrameSelection`. r=jfkthame

Preparation to move `SelectCellElement` to `TableSelection`.

Differential Revision: https://phabricator.services.mozilla.com/D63157

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Mirko Brodesser 2020-02-20 15:03:19 +00:00
Родитель 84b2b1a8b5
Коммит 7b16ca222e
2 изменённых файлов: 17 добавлений и 10 удалений

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

@ -87,6 +87,8 @@ static nsAtom* GetTag(nsINode* aNode);
// returns the parent
static nsINode* ParentOffset(nsINode* aNode, int32_t* aChildOffset);
static nsINode* GetCellParent(nsINode* aDomNode);
static nsresult CreateAndAddRange(nsINode* aContainer, int32_t aOffset,
Selection& aNormalSelection);
#ifdef PRINT_RANGE
static void printRange(nsRange* aDomRange);
@ -2202,8 +2204,9 @@ nsresult nsFrameSelection::HandleTableSelection(nsINode* aParentContent,
mTableSelection.mEndSelectedCell = nullptr;
// Remove existing selection and select the table
mDomSelections[index]->RemoveAllRanges(IgnoreErrors());
return CreateAndAddRange(aParentContent, aContentOffset);
const RefPtr<Selection> selection = mDomSelections[index];
selection->RemoveAllRanges(IgnoreErrors());
return CreateAndAddRange(aParentContent, aContentOffset, *selection);
}
if (aTarget == TableSelectionMode::Row ||
aTarget == TableSelectionMode::Column) {
@ -2739,11 +2742,19 @@ nsresult nsFrameSelection::SelectCellElement(nsIContent* aCellElement) {
// Get child offset
int32_t offset = parent->ComputeIndexOf(aCellElement);
return CreateAndAddRange(parent, offset);
const int8_t index = GetIndexFromSelectionType(SelectionType::eNormal);
const RefPtr<Selection> selection = mDomSelections[index];
if (!selection) {
return NS_ERROR_NULL_POINTER;
}
return CreateAndAddRange(parent, offset, *selection);
}
nsresult nsFrameSelection::CreateAndAddRange(nsINode* aContainer,
int32_t aOffset) {
nsresult CreateAndAddRange(nsINode* aContainer, int32_t aOffset,
Selection& aNormalSelection) {
MOZ_ASSERT(aNormalSelection.Type() == SelectionType::eNormal);
if (!aContainer) {
return NS_ERROR_NULL_POINTER;
}
@ -2757,11 +2768,8 @@ nsresult nsFrameSelection::CreateAndAddRange(nsINode* aContainer,
}
MOZ_ASSERT(range);
int8_t index = GetIndexFromSelectionType(SelectionType::eNormal);
if (!mDomSelections[index]) return NS_ERROR_NULL_POINTER;
ErrorResult err;
mDomSelections[index]->AddRangeAndSelectFramesAndNotifyListeners(*range, err);
aNormalSelection.AddRangeAndSelectFramesAndNotifyListeners(*range, err);
return err.StealNSResult();
}

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

@ -800,7 +800,6 @@ class nsFrameSelection final {
nsIContent* aContent2);
// Might return null
static nsIContent* GetParentTable(nsIContent* aCellNode);
nsresult CreateAndAddRange(nsINode* aContainer, int32_t aOffset);
////////////BEGIN nsFrameSelection members