mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-25 22:01:30 +00:00
Bug 1614636: simplify arguments of nsFrameSelection::HandleClick
. r=jfkthame
Simplifies understanding its dependent methods. Differential Revision: https://phabricator.services.mozilla.com/D62433 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
a5f89bc5bf
commit
ea1f257885
@ -723,7 +723,10 @@ TextInputSelectionController::CompleteMove(bool aForward, bool aExtend) {
|
||||
}
|
||||
}
|
||||
|
||||
frameSelection->HandleClick(parentDIV, offset, offset, aExtend, false, hint);
|
||||
const nsFrameSelection::FocusMode focusMode =
|
||||
aExtend ? nsFrameSelection::FocusMode::kExtendSelection
|
||||
: nsFrameSelection::FocusMode::kCollapseToNewPoint;
|
||||
frameSelection->HandleClick(parentDIV, offset, offset, focusMode, hint);
|
||||
|
||||
// if we got this far, attempt to scroll no matter what the above result is
|
||||
return CompleteScroll(aForward);
|
||||
|
@ -630,9 +630,10 @@ nsresult AccessibleCaretManager::SelectWordOrShortcut(const nsPoint& aPoint) {
|
||||
offsets.content, offsets.offset, offsets.associate, &offset);
|
||||
if (theFrame && theFrame != ptFrame) {
|
||||
SetSelectionDragState(true);
|
||||
frameSelection->HandleClick(offsets.content, offsets.StartOffset(),
|
||||
offsets.EndOffset(), false, false,
|
||||
offsets.associate);
|
||||
frameSelection->HandleClick(
|
||||
offsets.content, offsets.StartOffset(), offsets.EndOffset(),
|
||||
nsFrameSelection::FocusMode::kCollapseToNewPoint,
|
||||
offsets.associate);
|
||||
SetSelectionDragState(false);
|
||||
ClearMaintainedSelection();
|
||||
|
||||
@ -1257,9 +1258,12 @@ nsresult AccessibleCaretManager::DragCaretInternal(const nsPoint& aPoint) {
|
||||
|
||||
ClearMaintainedSelection();
|
||||
|
||||
const nsFrameSelection::FocusMode focusMode =
|
||||
(GetCaretMode() == CaretMode::Selection)
|
||||
? nsFrameSelection::FocusMode::kExtendSelection
|
||||
: nsFrameSelection::FocusMode::kCollapseToNewPoint;
|
||||
fs->HandleClick(offsets.content, offsets.StartOffset(), offsets.EndOffset(),
|
||||
GetCaretMode() == CaretMode::Selection, false,
|
||||
offsets.associate);
|
||||
focusMode, offsets.associate);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -2315,9 +2315,13 @@ PresShell::CompleteMove(bool aForward, bool aExtend) {
|
||||
: FrameConstructor()->GetRootElementFrame();
|
||||
if (!frame) return NS_ERROR_FAILURE;
|
||||
nsIFrame::CaretPosition pos = frame->GetExtremeCaretPosition(!aForward);
|
||||
|
||||
const nsFrameSelection::FocusMode focusMode =
|
||||
aExtend ? nsFrameSelection::FocusMode::kExtendSelection
|
||||
: nsFrameSelection::FocusMode::kCollapseToNewPoint;
|
||||
frameSelection->HandleClick(
|
||||
pos.mResultContent, pos.mContentOffset, pos.mContentOffset, aExtend,
|
||||
false, aForward ? CARET_ASSOCIATE_AFTER : CARET_ASSOCIATE_BEFORE);
|
||||
pos.mResultContent, pos.mContentOffset, pos.mContentOffset, focusMode,
|
||||
aForward ? CARET_ASSOCIATE_AFTER : CARET_ASSOCIATE_BEFORE);
|
||||
if (limiter) {
|
||||
// HandleClick resets ancestorLimiter, so set it again.
|
||||
frameSelection->SetAncestorLimiter(limiter);
|
||||
|
@ -4719,9 +4719,22 @@ nsFrame::HandlePress(nsPresContext* aPresContext, WidgetGUIEvent* aEvent,
|
||||
|
||||
// Do not touch any nsFrame members after this point without adding
|
||||
// weakFrame checks.
|
||||
const nsFrameSelection::FocusMode focusMode = [&]() {
|
||||
// If "Shift" and "Ctrl" are both pressed, "Shift" is given precedence. This
|
||||
// mimics the old behaviour.
|
||||
if (mouseEvent->IsShift()) {
|
||||
return nsFrameSelection::FocusMode::kExtendSelection;
|
||||
}
|
||||
|
||||
if (control) {
|
||||
return nsFrameSelection::FocusMode::kMultiRangeSelection;
|
||||
}
|
||||
|
||||
return nsFrameSelection::FocusMode::kCollapseToNewPoint;
|
||||
}();
|
||||
|
||||
rv = fc->HandleClick(offsets.content, offsets.StartOffset(),
|
||||
offsets.EndOffset(), mouseEvent->IsShift(), control,
|
||||
offsets.associate);
|
||||
offsets.EndOffset(), focusMode, offsets.associate);
|
||||
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
@ -4867,14 +4880,18 @@ nsresult nsFrame::PeekBackwardAndForward(nsSelectionAmount aAmountBack,
|
||||
// Keep frameSelection alive.
|
||||
RefPtr<nsFrameSelection> frameSelection = GetFrameSelection();
|
||||
|
||||
const nsFrameSelection::FocusMode focusMode =
|
||||
(aSelectFlags & SELECT_ACCUMULATE)
|
||||
? nsFrameSelection::FocusMode::kMultiRangeSelection
|
||||
: nsFrameSelection::FocusMode::kCollapseToNewPoint;
|
||||
rv = frameSelection->HandleClick(
|
||||
startpos.mResultContent, startpos.mContentOffset, startpos.mContentOffset,
|
||||
false, (aSelectFlags & SELECT_ACCUMULATE), CARET_ASSOCIATE_AFTER);
|
||||
focusMode, CARET_ASSOCIATE_AFTER);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = frameSelection->HandleClick(endpos.mResultContent, endpos.mContentOffset,
|
||||
endpos.mContentOffset, true, false,
|
||||
CARET_ASSOCIATE_BEFORE);
|
||||
rv = frameSelection->HandleClick(
|
||||
endpos.mResultContent, endpos.mContentOffset, endpos.mContentOffset,
|
||||
nsFrameSelection::FocusMode::kExtendSelection, CARET_ASSOCIATE_BEFORE);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// maintain selection
|
||||
@ -4987,10 +5004,13 @@ static nsresult HandleFrameSelection(
|
||||
// can do selection)
|
||||
aFrameSelection->SetDragState(true);
|
||||
|
||||
const nsFrameSelection::FocusMode focusMode =
|
||||
aFrameSelection->IsShiftDownInDelayedCaretData()
|
||||
? nsFrameSelection::FocusMode::kExtendSelection
|
||||
: nsFrameSelection::FocusMode::kCollapseToNewPoint;
|
||||
rv = aFrameSelection->HandleClick(
|
||||
aOffsets.content, aOffsets.StartOffset(), aOffsets.EndOffset(),
|
||||
aFrameSelection->IsShiftDownInDelayedCaretData(), false,
|
||||
aOffsets.associate);
|
||||
focusMode, aOffsets.associate);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
@ -183,8 +183,8 @@ bool nsFrameSelection::IsValidSelectionPoint(nsINode* aNode) const {
|
||||
|
||||
namespace mozilla {
|
||||
struct MOZ_RAII AutoPrepareFocusRange {
|
||||
AutoPrepareFocusRange(Selection* aSelection, bool aContinueSelection,
|
||||
bool aMultipleSelection
|
||||
AutoPrepareFocusRange(Selection* aSelection,
|
||||
const bool aMultiRangeSelection
|
||||
MOZ_GUARD_OBJECT_NOTIFIER_PARAM) {
|
||||
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
|
||||
|
||||
@ -198,7 +198,7 @@ struct MOZ_RAII AutoPrepareFocusRange {
|
||||
bool userSelection = aSelection->mUserInitiated;
|
||||
|
||||
nsTArray<StyledRange>& ranges = aSelection->mRanges;
|
||||
if (!userSelection || (!aContinueSelection && aMultipleSelection)) {
|
||||
if (!userSelection || aMultiRangeSelection) {
|
||||
// Scripted command or the user is starting a new explicit multi-range
|
||||
// selection.
|
||||
for (StyledRange& entry : ranges) {
|
||||
@ -673,7 +673,7 @@ nsresult nsFrameSelection::MoveCaret(nsDirection aDirection,
|
||||
PostReason(nsISelectionListener::KEYPRESS_REASON);
|
||||
}
|
||||
|
||||
AutoPrepareFocusRange prep(sel, aContinueSelection, false);
|
||||
AutoPrepareFocusRange prep(sel, false);
|
||||
|
||||
if (aAmount == eSelectLine) {
|
||||
nsresult result = FetchDesiredPos(desiredPos);
|
||||
@ -809,8 +809,11 @@ nsresult nsFrameSelection::MoveCaret(nsDirection aDirection,
|
||||
}
|
||||
// "pos" is on the stack, so pos.mResultContent has stack lifetime, so using
|
||||
// MOZ_KnownLive is ok.
|
||||
const FocusMode focusMode = aContinueSelection
|
||||
? FocusMode::kExtendSelection
|
||||
: FocusMode::kCollapseToNewPoint;
|
||||
result = TakeFocus(MOZ_KnownLive(pos.mResultContent), pos.mContentOffset,
|
||||
pos.mContentOffset, tHint, aContinueSelection, false);
|
||||
pos.mContentOffset, tHint, focusMode);
|
||||
} else if (aAmount <= eSelectWordNoSpace && aDirection == eDirNext &&
|
||||
!aContinueSelection) {
|
||||
// Collapse selection if PeekOffset failed, we either
|
||||
@ -1096,14 +1099,13 @@ bool nsFrameSelection::AdjustForMaintainedSelection(nsIContent* aContent,
|
||||
nsresult nsFrameSelection::HandleClick(nsIContent* aNewFocus,
|
||||
uint32_t aContentOffset,
|
||||
uint32_t aContentEndOffset,
|
||||
bool aContinueSelection,
|
||||
bool aMultipleSelection,
|
||||
const FocusMode aFocusMode,
|
||||
CaretAssociateHint aHint) {
|
||||
if (!aNewFocus) return NS_ERROR_INVALID_ARG;
|
||||
|
||||
InvalidateDesiredPos();
|
||||
|
||||
if (!aContinueSelection) {
|
||||
if (aFocusMode != FocusMode::kExtendSelection) {
|
||||
mMaintainRange = nullptr;
|
||||
if (!IsValidSelectionPoint(aNewFocus)) {
|
||||
mAncestorLimiter = nullptr;
|
||||
@ -1115,15 +1117,15 @@ nsresult nsFrameSelection::HandleClick(nsIContent* aNewFocus,
|
||||
BidiLevelFromClick(aNewFocus, aContentOffset);
|
||||
PostReason(nsISelectionListener::MOUSEDOWN_REASON +
|
||||
nsISelectionListener::DRAG_REASON);
|
||||
if (aContinueSelection &&
|
||||
if ((aFocusMode == FocusMode::kExtendSelection) &&
|
||||
AdjustForMaintainedSelection(aNewFocus, aContentOffset))
|
||||
return NS_OK; // shift clicked to maintained selection. rejected.
|
||||
|
||||
int8_t index = GetIndexFromSelectionType(SelectionType::eNormal);
|
||||
AutoPrepareFocusRange prep(mDomSelections[index], aContinueSelection,
|
||||
aMultipleSelection);
|
||||
AutoPrepareFocusRange prep(mDomSelections[index],
|
||||
aFocusMode == FocusMode::kMultiRangeSelection);
|
||||
return TakeFocus(aNewFocus, aContentOffset, aContentEndOffset, aHint,
|
||||
aContinueSelection, aMultipleSelection);
|
||||
aFocusMode);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
@ -1194,8 +1196,8 @@ void nsFrameSelection::HandleDrag(nsIFrame* aFrame, const nsPoint& aPoint) {
|
||||
}
|
||||
}
|
||||
|
||||
HandleClick(offsets.content, offsets.offset, offsets.offset, true, false,
|
||||
offsets.associate);
|
||||
HandleClick(offsets.content, offsets.offset, offsets.offset,
|
||||
FocusMode::kExtendSelection, offsets.associate);
|
||||
}
|
||||
|
||||
nsresult nsFrameSelection::StartAutoScrollTimer(nsIFrame* aFrame,
|
||||
@ -1226,8 +1228,7 @@ nsresult nsFrameSelection::TakeFocus(nsIContent* aNewFocus,
|
||||
uint32_t aContentOffset,
|
||||
uint32_t aContentEndOffset,
|
||||
CaretAssociateHint aHint,
|
||||
bool aContinueSelection,
|
||||
bool aMultipleSelection) {
|
||||
const FocusMode aFocusMode) {
|
||||
if (!aNewFocus) return NS_ERROR_NULL_POINTER;
|
||||
|
||||
NS_ENSURE_STATE(mPresShell);
|
||||
@ -1253,12 +1254,13 @@ nsresult nsFrameSelection::TakeFocus(nsIContent* aNewFocus,
|
||||
}
|
||||
|
||||
// traverse through document and unselect crap here
|
||||
if (!aContinueSelection) { // single click? setting cursor down
|
||||
if (aFocusMode !=
|
||||
FocusMode::kExtendSelection) { // single click? setting cursor down
|
||||
uint32_t batching = mBatching; // hack to use the collapse code.
|
||||
bool changes = mChangesDuringBatching;
|
||||
mBatching = 1;
|
||||
|
||||
if (aMultipleSelection) {
|
||||
if (aFocusMode == FocusMode::kMultiRangeSelection) {
|
||||
// Remove existing collapsed ranges as there's no point in having
|
||||
// non-anchor/focus collapsed ranges.
|
||||
mDomSelections[index]->RemoveCollapsedRanges();
|
||||
@ -1313,7 +1315,7 @@ nsresult nsFrameSelection::TakeFocus(nsIContent* aNewFocus,
|
||||
}
|
||||
} else {
|
||||
// Now update the range list:
|
||||
if (aContinueSelection && aNewFocus) {
|
||||
if ((aFocusMode == FocusMode::kExtendSelection) && aNewFocus) {
|
||||
int32_t offset;
|
||||
nsINode* cellparent = GetCellParent(aNewFocus);
|
||||
if (mCellParent && cellparent &&
|
||||
@ -1751,7 +1753,9 @@ nsresult nsFrameSelection::PageMove(bool aForward, bool aExtend,
|
||||
RangeBoundary oldAnchor = selection->AnchorRef();
|
||||
RangeBoundary oldFocus = selection->FocusRef();
|
||||
|
||||
HandleClick(offsets.content, offsets.offset, offsets.offset, aExtend, false,
|
||||
const FocusMode focusMode =
|
||||
aExtend ? FocusMode::kExtendSelection : FocusMode::kCollapseToNewPoint;
|
||||
HandleClick(offsets.content, offsets.offset, offsets.offset, focusMode,
|
||||
CARET_ASSOCIATE_AFTER);
|
||||
|
||||
selectionChanged = selection->AnchorRef() != oldAnchor ||
|
||||
@ -1944,9 +1948,9 @@ nsresult nsFrameSelection::SelectAll() {
|
||||
int32_t numChildren = rootContent->GetChildCount();
|
||||
PostReason(nsISelectionListener::NO_REASON);
|
||||
int8_t index = GetIndexFromSelectionType(SelectionType::eNormal);
|
||||
AutoPrepareFocusRange prep(mDomSelections[index], false, false);
|
||||
return TakeFocus(rootContent, 0, numChildren, CARET_ASSOCIATE_BEFORE, false,
|
||||
false);
|
||||
AutoPrepareFocusRange prep(mDomSelections[index], false);
|
||||
return TakeFocus(rootContent, 0, numChildren, CARET_ASSOCIATE_BEFORE,
|
||||
FocusMode::kCollapseToNewPoint);
|
||||
}
|
||||
|
||||
//////////END FRAMESELECTION
|
||||
@ -2731,7 +2735,8 @@ void nsFrameSelection::SetAncestorLimiter(nsIContent* aLimiter) {
|
||||
if (mAncestorLimiter) {
|
||||
PostReason(nsISelectionListener::NO_REASON);
|
||||
nsCOMPtr<nsIContent> limiter(mAncestorLimiter);
|
||||
TakeFocus(limiter, 0, 0, CARET_ASSOCIATE_BEFORE, false, false);
|
||||
TakeFocus(limiter, 0, 0, CARET_ASSOCIATE_BEFORE,
|
||||
FocusMode::kCollapseToNewPoint);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -234,6 +234,13 @@ class nsFrameSelection final {
|
||||
void Init(mozilla::PresShell* aPresShell, nsIContent* aLimiter,
|
||||
bool aAccessibleCaretEnabled);
|
||||
|
||||
enum class FocusMode {
|
||||
kExtendSelection, /** Keep old anchor point. */
|
||||
kCollapseToNewPoint, /** Collapses the Selection to the new point. */
|
||||
kMultiRangeSelection, /** Keeps existing non-collapsed ranges and marks them
|
||||
as generated. */
|
||||
};
|
||||
|
||||
/**
|
||||
* HandleClick will take the focus to the new frame at the new offset and
|
||||
* will either extend the selection from the old anchor, or replace the old
|
||||
@ -248,19 +255,14 @@ class nsFrameSelection final {
|
||||
* is specified different when you need to select to and include both start
|
||||
* and end points
|
||||
*
|
||||
* @param aContinueSelection is the flag that tells the selection to keep the
|
||||
* old anchor point or not.
|
||||
*
|
||||
* @param aMultipleSelection will tell the frame selector to replace /or not
|
||||
* the old selection. cannot coexist with aContinueSelection
|
||||
*
|
||||
* @param aHint will tell the selection which direction geometrically to
|
||||
* actually show the caret on. 1 = end of this line 0 = beginning of this line
|
||||
*/
|
||||
MOZ_CAN_RUN_SCRIPT_BOUNDARY
|
||||
nsresult HandleClick(nsIContent* aNewFocus, uint32_t aContentOffset,
|
||||
uint32_t aContentEndOffset, bool aContinueSelection,
|
||||
bool aMultipleSelection, CaretAssociateHint aHint);
|
||||
MOZ_CAN_RUN_SCRIPT_BOUNDARY nsresult HandleClick(nsIContent* aNewFocus,
|
||||
uint32_t aContentOffset,
|
||||
uint32_t aContentEndOffset,
|
||||
FocusMode aFocusMode,
|
||||
CaretAssociateHint aHint);
|
||||
|
||||
/**
|
||||
* HandleDrag extends the selection to contain the frame closest to aPoint.
|
||||
@ -732,7 +734,7 @@ class nsFrameSelection final {
|
||||
MOZ_CAN_RUN_SCRIPT
|
||||
nsresult TakeFocus(nsIContent* aNewFocus, uint32_t aContentOffset,
|
||||
uint32_t aContentEndOffset, CaretAssociateHint aHint,
|
||||
bool aContinueSelection, bool aMultipleSelection);
|
||||
FocusMode aFocusMode);
|
||||
|
||||
void BidiLevelFromMove(mozilla::PresShell* aPresShell, nsIContent* aNode,
|
||||
uint32_t aContentOffset, nsSelectionAmount aAmount,
|
||||
|
@ -3573,7 +3573,8 @@ void SVGTextFrame::SelectSubString(nsIContent* aContent, uint32_t charnum,
|
||||
|
||||
RefPtr<nsFrameSelection> frameSelection = GetFrameSelection();
|
||||
|
||||
frameSelection->HandleClick(content, charnum, charnum + nchars, false, false,
|
||||
frameSelection->HandleClick(content, charnum, charnum + nchars,
|
||||
nsFrameSelection::FocusMode::kCollapseToNewPoint,
|
||||
CARET_ASSOCIATE_BEFORE);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user