Bug 1671768 - Part 2: Use MOZ_CAN_RUN_SCRIPT for Selection::Extend r=masayuki

Differential Revision: https://phabricator.services.mozilla.com/D103778
This commit is contained in:
Kagami Sascha Rosylight 2021-02-03 21:52:15 +00:00
Родитель 03a9abe590
Коммит e0304db4c3
2 изменённых файлов: 17 добавлений и 19 удалений

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

@ -210,8 +210,7 @@ class Selection final : public nsSupportsWeakReference,
CollapseInternal(InLimiter::eYes, aPoint, aRv);
}
MOZ_CAN_RUN_SCRIPT_BOUNDARY
nsresult Extend(nsINode* aContainer, int32_t aOffset);
MOZ_CAN_RUN_SCRIPT nsresult Extend(nsINode* aContainer, int32_t aOffset);
/**
* See mStyledRanges.mRanges.
@ -329,9 +328,8 @@ class Selection final : public nsSupportsWeakReference,
MOZ_CAN_RUN_SCRIPT void CollapseToStartJS(mozilla::ErrorResult& aRv);
MOZ_CAN_RUN_SCRIPT void CollapseToEndJS(mozilla::ErrorResult& aRv);
MOZ_CAN_RUN_SCRIPT_BOUNDARY
void ExtendJS(nsINode& aContainer, uint32_t aOffset,
mozilla::ErrorResult& aRv);
MOZ_CAN_RUN_SCRIPT void ExtendJS(nsINode& aContainer, uint32_t aOffset,
mozilla::ErrorResult& aRv);
void SelectAllChildrenJS(nsINode& aNode, mozilla::ErrorResult& aRv);
@ -504,8 +502,8 @@ class Selection final : public nsSupportsWeakReference,
* @param aOffset Where in aContainer to place the offset of the new
* selection end.
*/
MOZ_CAN_RUN_SCRIPT_BOUNDARY
void Extend(nsINode& aContainer, uint32_t aOffset, ErrorResult& aRv);
MOZ_CAN_RUN_SCRIPT void Extend(nsINode& aContainer, uint32_t aOffset,
ErrorResult& aRv);
MOZ_CAN_RUN_SCRIPT void AddRangeAndSelectFramesAndNotifyListeners(
nsRange& aRange, mozilla::ErrorResult& aRv);

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

@ -1390,10 +1390,12 @@ nsresult nsFrameSelection::TakeFocus(nsIContent& aNewFocus,
mBatching; // hack to use the collapse code.
mBatching.mCounter = 1;
RefPtr<Selection> selection = mDomSelections[index];
if (aFocusMode == FocusMode::kMultiRangeSelection) {
// Remove existing collapsed ranges as there's no point in having
// non-anchor/focus collapsed ranges.
mDomSelections[index]->RemoveCollapsedRanges();
selection->RemoveCollapsedRanges();
ErrorResult error;
RefPtr<nsRange> newRange = nsRange::Create(
@ -1402,14 +1404,12 @@ nsresult nsFrameSelection::TakeFocus(nsIContent& aNewFocus,
return error.StealNSResult();
}
MOZ_ASSERT(newRange);
const RefPtr<Selection> selection{mDomSelections[index]};
selection->AddRangeAndSelectFramesAndNotifyListeners(*newRange,
IgnoreErrors());
} else {
bool oldDesiredPosSet =
mDesiredCaretPos.mIsSet; // need to keep old desired
// position if it was set.
RefPtr<Selection> selection = mDomSelections[index];
selection->CollapseInLimiter(&aNewFocus, aContentOffset);
mDesiredCaretPos.mIsSet =
oldDesiredPosSet; // now reset desired pos back.
@ -1418,7 +1418,7 @@ nsresult nsFrameSelection::TakeFocus(nsIContent& aNewFocus,
mBatching = saveBatching;
if (aContentEndOffset != aContentOffset) {
mDomSelections[index]->Extend(&aNewFocus, aContentEndOffset);
selection->Extend(&aNewFocus, aContentEndOffset);
}
// find out if we are inside a table. if so, find out which one and which
@ -1487,16 +1487,16 @@ nsresult nsFrameSelection::TakeFocus(nsIContent& aNewFocus,
}
}
} else {
RefPtr<Selection> selection = mDomSelections[index];
// XXXX Problem: Shift+click in browser is appending text selection to
// selected table!!!
// is this the place to erase seleced cells ?????
if (mDomSelections[index]->GetDirection() == eDirNext &&
aContentEndOffset > aContentOffset) // didn't go far enough
{
mDomSelections[index]->Extend(
&aNewFocus, aContentEndOffset); // this will only redraw the diff
} else
mDomSelections[index]->Extend(&aNewFocus, aContentOffset);
// is this the place to erase selected cells ?????
uint32_t offset =
(selection->GetDirection() == eDirNext &&
aContentEndOffset > aContentOffset) // didn't go far enough
? aContentEndOffset // this will only redraw the diff
: aContentOffset;
selection->Extend(&aNewFocus, offset);
}
break;
}