diff --git a/layout/base/AccessibleCaretManager.cpp b/layout/base/AccessibleCaretManager.cpp index 66f4b73d7f7e..51201b8899b1 100644 --- a/layout/base/AccessibleCaretManager.cpp +++ b/layout/base/AccessibleCaretManager.cpp @@ -87,7 +87,7 @@ AccessibleCaretManager::AccessibleCaretManager(PresShell* aPresShell) } AccessibleCaretManager::~AccessibleCaretManager() { - MOZ_RELEASE_ASSERT(!mFlushingLayout, "Going away in FlushLayout? Bad!"); + MOZ_RELEASE_ASSERT(!mFlushingLayout, "Going away in MaybeFlushLayout? Bad!"); } void AccessibleCaretManager::Terminate() { @@ -182,7 +182,7 @@ void AccessibleCaretManager::HideCarets() { } void AccessibleCaretManager::UpdateCarets(const UpdateCaretsHintSet& aHint) { - if (!FlushLayout()) { + if (MaybeFlushLayout() == Terminated::Yes) { return; } @@ -345,7 +345,7 @@ void AccessibleCaretManager::UpdateCaretsForSelectionMode( if (mIsCaretPositionChanged) { // Flush layout to make the carets intersection correct. - if (!FlushLayout()) { + if (MaybeFlushLayout() == Terminated::Yes) { return; } } @@ -969,7 +969,7 @@ void AccessibleCaretManager::ExtendPhoneNumberSelection( // Extend the selection by one char. selection->Modify(u"extend"_ns, aDirection, u"character"_ns, IgnoreErrors()); - if (IsTerminated()) { + if (IsTerminated() == Terminated::Yes) { return; } @@ -1011,7 +1011,7 @@ void AccessibleCaretManager::ClearMaintainedSelection() const { } } -bool AccessibleCaretManager::FlushLayout() { +auto AccessibleCaretManager::MaybeFlushLayout() -> Terminated { if (mPresShell && mAllowFlushingLayout) { AutoRestore flushing(mFlushingLayout); mFlushingLayout = true; @@ -1021,7 +1021,7 @@ bool AccessibleCaretManager::FlushLayout() { } } - return !IsTerminated(); + return IsTerminated(); } nsIFrame* AccessibleCaretManager::GetFrameForFirstRangeStartOrLastRangeEnd( @@ -1390,7 +1390,7 @@ void AccessibleCaretManager::StopSelectionAutoScrollTimer() const { void AccessibleCaretManager::DispatchCaretStateChangedEvent( CaretChangedReason aReason) { - if (!FlushLayout()) { + if (MaybeFlushLayout() == Terminated::Yes) { return; } diff --git a/layout/base/AccessibleCaretManager.h b/layout/base/AccessibleCaretManager.h index 4b80e2eb63d5..dbc4e7a8a92a 100644 --- a/layout/base/AccessibleCaretManager.h +++ b/layout/base/AccessibleCaretManager.h @@ -228,13 +228,15 @@ class AccessibleCaretManager { void ClearMaintainedSelection() const; + enum class Terminated : bool { No, Yes }; + // This method could kill the shell, so callers to methods that call - // FlushLayout should ensure the event hub that owns us is still alive. + // MaybeFlushLayout should ensure the event hub that owns us is still alive. // // See the mRefCnt assertions in AccessibleCaretEventHub. // - // Returns whether mPresShell we're holding is still valid. - [[nodiscard]] MOZ_CAN_RUN_SCRIPT bool FlushLayout(); + // @return IsTerminated(). + [[nodiscard]] MOZ_CAN_RUN_SCRIPT Terminated MaybeFlushLayout(); dom::Element* GetEditingHostForFrame(nsIFrame* aFrame) const; dom::Selection* GetSelection() const; @@ -264,8 +266,10 @@ class AccessibleCaretManager { // --------------------------------------------------------------------------- // The following functions are made virtual for stubbing or mocking in gtest. // - // @return true if Terminate() had been called. - virtual bool IsTerminated() const { return !mPresShell; } + // @return Yes if Terminate() had been called. + virtual Terminated IsTerminated() const { + return mPresShell ? Terminated::No : Terminated::Yes; + } // Get caret mode based on current selection. virtual CaretMode GetCaretMode() const; diff --git a/layout/base/gtest/TestAccessibleCaretManager.cpp b/layout/base/gtest/TestAccessibleCaretManager.cpp index 888d1cb285df..020a23eb30a7 100644 --- a/layout/base/gtest/TestAccessibleCaretManager.cpp +++ b/layout/base/gtest/TestAccessibleCaretManager.cpp @@ -99,7 +99,7 @@ class AccessibleCaretManagerTester : public ::testing::Test { } } - bool IsTerminated() const override { return false; } + Terminated IsTerminated() const override { return Terminated::No; } bool IsScrollStarted() const { return mIsScrollStarted; } MOCK_CONST_METHOD0(GetCaretMode, CaretMode());