Bug 1623858: part 10) Simplify `Selection::AddRangesForSelectableNodes`'s signature. r=smaug

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Mirko Brodesser 2020-03-25 14:28:40 +00:00
Родитель 5bf22279f2
Коммит ec7cb2f8d3
2 изменённых файлов: 28 добавлений и 13 удалений

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

@ -525,7 +525,8 @@ nsresult Selection::MaybeAddTableCellRange(nsRange& aRange, bool* aDidAddRange,
}
*aDidAddRange = true;
return AddRangesForSelectableNodes(&aRange, aOutIndex);
return AddRangesForSelectableNodes(&aRange, aOutIndex,
DispatchSelectstartEvent::Maybe);
}
Selection::Selection(SelectionType aSelectionType,
@ -805,9 +806,9 @@ static void UserSelectRangesToAdd(nsRange* aItem,
}
}
nsresult Selection::AddRangesForSelectableNodes(nsRange* aRange,
int32_t* aOutIndex,
bool aNoStartSelect) {
nsresult Selection::AddRangesForSelectableNodes(
nsRange* aRange, int32_t* aOutIndex,
const DispatchSelectstartEvent aDispatchSelectstartEvent) {
if (!aRange) {
return NS_ERROR_NULL_POINTER;
}
@ -827,9 +828,9 @@ nsresult Selection::AddRangesForSelectableNodes(nsRange* aRange,
StaticPrefs::dom_select_events_enabled() ||
(doc && doc->NodePrincipal()->IsSystemPrincipal());
if (!aNoStartSelect && mSelectionType == SelectionType::eNormal &&
selectEventsEnabled && IsCollapsed() &&
!IsBlockingSelectionChangeEvents()) {
if (aDispatchSelectstartEvent == DispatchSelectstartEvent::Maybe &&
mSelectionType == SelectionType::eNormal && selectEventsEnabled &&
IsCollapsed() && !IsBlockingSelectionChangeEvents()) {
// First, we generate the ranges to add with a scratch range, which is a
// clone of the original range passed in. We do this seperately, because
// the selectstart event could have caused the world to change, and
@ -1887,7 +1888,8 @@ void Selection::AddRangeAndSelectFramesAndNotifyListeners(nsRange& aRange,
}
if (!didAddRange) {
result = AddRangesForSelectableNodes(range, &rangeIndex);
result = AddRangesForSelectableNodes(range, &rangeIndex,
DispatchSelectstartEvent::Maybe);
if (NS_FAILED(result)) {
aRv.Throw(result);
return;
@ -2110,7 +2112,8 @@ void Selection::Collapse(const RawRangeBoundary& aPoint, ErrorResult& aRv) {
#endif
int32_t rangeIndex = -1;
result = AddRangesForSelectableNodes(range, &rangeIndex);
result = AddRangesForSelectableNodes(range, &rangeIndex,
DispatchSelectstartEvent::Maybe);
if (NS_FAILED(result)) {
aRv.Throw(result);
return;
@ -2228,13 +2231,16 @@ utility function
nsresult Selection::SetAnchorFocusToRange(nsRange* aRange) {
NS_ENSURE_STATE(mAnchorFocusRange);
bool collapsed = IsCollapsed();
const DispatchSelectstartEvent dispatchSelectstartEvent =
IsCollapsed() ? DispatchSelectstartEvent::Maybe
: DispatchSelectstartEvent::No;
nsresult res = RemoveRangeInternal(*mAnchorFocusRange);
if (NS_FAILED(res)) return res;
int32_t aOutIndex = -1;
res = AddRangesForSelectableNodes(aRange, &aOutIndex, !collapsed);
res =
AddRangesForSelectableNodes(aRange, &aOutIndex, dispatchSelectstartEvent);
if (NS_FAILED(res)) return res;
SetAnchorFocusRange(aOutIndex);

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

@ -152,6 +152,14 @@ class Selection final : public nsSupportsWeakReference,
nsTArray<StyledRange>* aOutput);
private:
/**
* https://w3c.github.io/selection-api/#selectstart-event.
*/
enum class DispatchSelectstartEvent {
No,
Maybe,
};
/**
* Adds aRange to this Selection. If mUserInitiated is true,
* then aRange is first scanned for -moz-user-select:none nodes and split up
@ -163,8 +171,9 @@ class Selection final : public nsSupportsWeakReference,
* containing it. -1 if mRanges was empty and no range was
* added.
*/
nsresult AddRangesForSelectableNodes(nsRange* aRange, int32_t* aOutIndex,
bool aNoStartSelect = false);
nsresult AddRangesForSelectableNodes(
nsRange* aRange, int32_t* aOutIndex,
DispatchSelectstartEvent aDispatchSelectstartEvent);
/**
* Doesn't remove `aRange` from `mAnchorFocusRange`.