From e0304db4c36fae178016254db4624d084ab2864f Mon Sep 17 00:00:00 2001 From: Kagami Sascha Rosylight Date: Wed, 3 Feb 2021 21:52:15 +0000 Subject: [PATCH] Bug 1671768 - Part 2: Use MOZ_CAN_RUN_SCRIPT for Selection::Extend r=masayuki Differential Revision: https://phabricator.services.mozilla.com/D103778 --- dom/base/Selection.h | 12 +++++------- layout/generic/nsFrameSelection.cpp | 24 ++++++++++++------------ 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/dom/base/Selection.h b/dom/base/Selection.h index 2a2182e2ad4c..e363fa5fca4f 100644 --- a/dom/base/Selection.h +++ b/dom/base/Selection.h @@ -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); diff --git a/layout/generic/nsFrameSelection.cpp b/layout/generic/nsFrameSelection.cpp index 9936a9a5f633..3d281b2f8d32 100644 --- a/layout/generic/nsFrameSelection.cpp +++ b/layout/generic/nsFrameSelection.cpp @@ -1390,10 +1390,12 @@ nsresult nsFrameSelection::TakeFocus(nsIContent& aNewFocus, mBatching; // hack to use the collapse code. mBatching.mCounter = 1; + RefPtr 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 newRange = nsRange::Create( @@ -1402,14 +1404,12 @@ nsresult nsFrameSelection::TakeFocus(nsIContent& aNewFocus, return error.StealNSResult(); } MOZ_ASSERT(newRange); - const RefPtr selection{mDomSelections[index]}; selection->AddRangeAndSelectFramesAndNotifyListeners(*newRange, IgnoreErrors()); } else { bool oldDesiredPosSet = mDesiredCaretPos.mIsSet; // need to keep old desired // position if it was set. - RefPtr 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 = 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; }