From 1ea34c359f71479d4085dcf8b47bb9face69b214 Mon Sep 17 00:00:00 2001 From: Mirko Brodesser Date: Tue, 2 Feb 2021 16:16:22 +0000 Subject: [PATCH] Bug 1688832: part 9) Change argument of `nsFrameSelection::TakeFocus` from pointer to reference. r=smaug Simplification. Differential Revision: https://phabricator.services.mozilla.com/D103772 --- layout/generic/nsFrameSelection.cpp | 32 ++++++++++++++------------------ layout/generic/nsFrameSelection.h | 2 +- 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/layout/generic/nsFrameSelection.cpp b/layout/generic/nsFrameSelection.cpp index 9c860f34269e..9936a9a5f633 100644 --- a/layout/generic/nsFrameSelection.cpp +++ b/layout/generic/nsFrameSelection.cpp @@ -858,7 +858,7 @@ nsresult nsFrameSelection::MoveCaret(nsDirection aDirection, const FocusMode focusMode = aContinueSelection ? FocusMode::kExtendSelection : FocusMode::kCollapseToNewPoint; - rv = TakeFocus(MOZ_KnownLive(pos.mResultContent), pos.mContentOffset, + rv = TakeFocus(MOZ_KnownLive(*pos.mResultContent), pos.mContentOffset, pos.mContentOffset, tHint, focusMode); } else if (aAmount <= eSelectWordNoSpace && direction == eDirNext && !aContinueSelection) { @@ -1239,7 +1239,7 @@ nsresult nsFrameSelection::HandleClick(nsIContent* aNewFocus, AutoPrepareFocusRange prep(selection, aFocusMode == FocusMode::kMultiRangeSelection); - return TakeFocus(aNewFocus, aContentOffset, aContentEndOffset, aHint, + return TakeFocus(*aNewFocus, aContentOffset, aContentEndOffset, aHint, aFocusMode); } @@ -1346,24 +1346,20 @@ struct ParentAndOffset { /** hard to go from nodes to frames, easy the other way! */ -nsresult nsFrameSelection::TakeFocus(nsIContent* const aNewFocus, +nsresult nsFrameSelection::TakeFocus(nsIContent& aNewFocus, uint32_t aContentOffset, uint32_t aContentEndOffset, CaretAssociateHint aHint, const FocusMode aFocusMode) { - if (!aNewFocus) { - return NS_ERROR_NULL_POINTER; - } - NS_ENSURE_STATE(mPresShell); - if (!IsValidSelectionPoint(aNewFocus)) { + if (!IsValidSelectionPoint(&aNewFocus)) { return NS_ERROR_FAILURE; } MOZ_LOG(sFrameSelectionLog, LogLevel::Verbose, ("%s: new focus=%p, offsets=(%u, %u), hint=%i, focusMode=%i", - __FUNCTION__, aNewFocus, aContentOffset, aContentEndOffset, + __FUNCTION__, &aNewFocus, aContentOffset, aContentEndOffset, static_cast(aHint), static_cast(aFocusMode))); mPresShell->FrameSelectionWillTakeFocus(*this); @@ -1401,7 +1397,7 @@ nsresult nsFrameSelection::TakeFocus(nsIContent* const aNewFocus, ErrorResult error; RefPtr newRange = nsRange::Create( - aNewFocus, aContentOffset, aNewFocus, aContentOffset, error); + &aNewFocus, aContentOffset, &aNewFocus, aContentOffset, error); if (NS_WARN_IF(error.Failed())) { return error.StealNSResult(); } @@ -1414,7 +1410,7 @@ nsresult nsFrameSelection::TakeFocus(nsIContent* const aNewFocus, mDesiredCaretPos.mIsSet; // need to keep old desired // position if it was set. RefPtr selection = mDomSelections[index]; - selection->CollapseInLimiter(aNewFocus, aContentOffset); + selection->CollapseInLimiter(&aNewFocus, aContentOffset); mDesiredCaretPos.mIsSet = oldDesiredPosSet; // now reset desired pos back. } @@ -1422,7 +1418,7 @@ nsresult nsFrameSelection::TakeFocus(nsIContent* const aNewFocus, mBatching = saveBatching; if (aContentEndOffset != aContentOffset) { - mDomSelections[index]->Extend(aNewFocus, aContentEndOffset); + mDomSelections[index]->Extend(&aNewFocus, aContentEndOffset); } // find out if we are inside a table. if so, find out which one and which @@ -1434,8 +1430,8 @@ nsresult nsFrameSelection::TakeFocus(nsIContent* const aNewFocus, RefPtr context = mPresShell->GetPresContext(); mTableSelection.mClosestInclusiveTableCellAncestor = nullptr; if (nsINode* inclusiveTableCellAncestor = - TableSelection::IsContentInActivelyEditableTableCell(context, - aNewFocus)) { + TableSelection::IsContentInActivelyEditableTableCell( + context, &aNewFocus)) { mTableSelection.mClosestInclusiveTableCellAncestor = inclusiveTableCellAncestor; MOZ_LOG(sFrameSelectionLog, LogLevel::Debug, @@ -1447,7 +1443,7 @@ nsresult nsFrameSelection::TakeFocus(nsIContent* const aNewFocus, case FocusMode::kExtendSelection: { // Now update the range list: nsINode* inclusiveTableCellAncestor = - GetClosestInclusiveTableCellAncestor(aNewFocus); + GetClosestInclusiveTableCellAncestor(&aNewFocus); if (mTableSelection.mClosestInclusiveTableCellAncestor && inclusiveTableCellAncestor && inclusiveTableCellAncestor != @@ -1498,9 +1494,9 @@ nsresult nsFrameSelection::TakeFocus(nsIContent* const aNewFocus, aContentEndOffset > aContentOffset) // didn't go far enough { mDomSelections[index]->Extend( - aNewFocus, aContentEndOffset); // this will only redraw the diff + &aNewFocus, aContentEndOffset); // this will only redraw the diff } else - mDomSelections[index]->Extend(aNewFocus, aContentOffset); + mDomSelections[index]->Extend(&aNewFocus, aContentOffset); } break; } @@ -3062,7 +3058,7 @@ void nsFrameSelection::SetAncestorLimiter(nsIContent* aLimiter) { if (mLimiters.mAncestorLimiter) { SetChangeReasons(nsISelectionListener::NO_REASON); nsCOMPtr limiter(mLimiters.mAncestorLimiter); - const nsresult rv = TakeFocus(limiter, 0, 0, CARET_ASSOCIATE_BEFORE, + const nsresult rv = TakeFocus(*limiter, 0, 0, CARET_ASSOCIATE_BEFORE, FocusMode::kCollapseToNewPoint); Unused << NS_WARN_IF(NS_FAILED(rv)); // TODO: in case of failure, propagate it to the callers. diff --git a/layout/generic/nsFrameSelection.h b/layout/generic/nsFrameSelection.h index b08f0c6c5571..d11659c2b6e2 100644 --- a/layout/generic/nsFrameSelection.h +++ b/layout/generic/nsFrameSelection.h @@ -745,7 +745,7 @@ class nsFrameSelection final { // TODO: in case an error is returned, it sometimes refers to a programming // error, in other cases to runtime errors. This deserves to be cleaned up. [[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult - TakeFocus(nsIContent* aNewFocus, uint32_t aContentOffset, + TakeFocus(nsIContent& aNewFocus, uint32_t aContentOffset, uint32_t aContentEndOffset, CaretAssociateHint aHint, FocusMode aFocusMode); -- 2.11.4.GIT