Skip to content
This repository has been archived by the owner on Aug 4, 2022. It is now read-only.

Commit

Permalink
Bug 1601285 - Remove AutoPrepareFocusRange from Selection.cpp; r=smaug
Browse files Browse the repository at this point in the history
In bug 1373999, we moved nsFrameSelection from Selection.cpp to nsFrameSelection.cpp. And AutoPrepareFocusRange is only used in nsFrameSelection. It looks like somehow we left duplicated codes in Selection.cpp.

Differential Revision: https://phabricator.services.mozilla.com/D55806
  • Loading branch information
EdgarChen committed Dec 4, 2019
1 parent 24cd407 commit c1e6d47
Showing 1 changed file with 0 additions and 94 deletions.
94 changes: 0 additions & 94 deletions dom/base/Selection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,100 +276,6 @@ bool IsValidSelectionPoint(nsFrameSelection* aFrameSel, nsINode* aNode) {
return !limiter || aNode->IsInclusiveDescendantOf(limiter);
}

namespace mozilla {
struct MOZ_RAII AutoPrepareFocusRange {
AutoPrepareFocusRange(Selection* aSelection, bool aContinueSelection,
bool aMultipleSelection
MOZ_GUARD_OBJECT_NOTIFIER_PARAM) {
MOZ_GUARD_OBJECT_NOTIFIER_INIT;

if (aSelection->mRanges.Length() <= 1) {
return;
}

if (aSelection->mFrameSelection->IsUserSelectionReason()) {
mUserSelect.emplace(aSelection);
}
bool userSelection = aSelection->mUserInitiated;

nsTArray<RangeData>& ranges = aSelection->mRanges;
if (!userSelection || (!aContinueSelection && aMultipleSelection)) {
// Scripted command or the user is starting a new explicit multi-range
// selection.
for (RangeData& entry : ranges) {
entry.mRange->SetIsGenerated(false);
}
return;
}

int16_t reason = aSelection->mFrameSelection->mSelectionChangeReason;
bool isAnchorRelativeOp =
(reason & (nsISelectionListener::DRAG_REASON |
nsISelectionListener::MOUSEDOWN_REASON |
nsISelectionListener::MOUSEUP_REASON |
nsISelectionListener::COLLAPSETOSTART_REASON));
if (!isAnchorRelativeOp) {
return;
}

// This operation is against the anchor but our current mAnchorFocusRange
// represents the focus in a multi-range selection. The anchor from a user
// perspective is the most distant generated range on the opposite side.
// Find that range and make it the mAnchorFocusRange.
const size_t len = ranges.Length();
size_t newAnchorFocusIndex = size_t(-1);
if (aSelection->GetDirection() == eDirNext) {
for (size_t i = 0; i < len; ++i) {
if (ranges[i].mRange->IsGenerated()) {
newAnchorFocusIndex = i;
break;
}
}
} else {
size_t i = len;
while (i--) {
if (ranges[i].mRange->IsGenerated()) {
newAnchorFocusIndex = i;
break;
}
}
}

if (newAnchorFocusIndex == size_t(-1)) {
// There are no generated ranges - that's fine.
return;
}

// Setup the new mAnchorFocusRange and mark the old one as generated.
if (aSelection->mAnchorFocusRange) {
aSelection->mAnchorFocusRange->SetIsGenerated(true);
}
nsRange* range = ranges[newAnchorFocusIndex].mRange;
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->mRanges[i].mRange;
if (range->IsGenerated()) {
range->SetSelection(nullptr);
aSelection->SelectFrames(presContext, range, false);
aSelection->mRanges.RemoveElementAt(i);
}
}
if (aSelection->mFrameSelection) {
aSelection->mFrameSelection->InvalidateDesiredPos();
}
}

Maybe<Selection::AutoUserInitiated> mUserSelect;
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
};

} // namespace mozilla

#ifdef PRINT_RANGE
void printRange(nsRange* aDomRange) {
if (!aDomRange) {
Expand Down

0 comments on commit c1e6d47

Please sign in to comment.