From acee8474e05ac1d5d194972280c177b98a4cf755 Mon Sep 17 00:00:00 2001 From: Mirko Brodesser Date: Wed, 27 Jan 2021 09:43:35 +0000 Subject: [PATCH] Bug 1688832: part 4) Add `AccessibleCaretManager::SelectionStringifyer`. r=TYLin Will help to simplify `AccessibleCaretManager::Dispatch...`. Differential Revision: https://phabricator.services.mozilla.com/D102920 --- layout/base/AccessibleCaretManager.cpp | 17 +++++---- layout/base/AccessibleCaretManager.h | 53 ++++++++++++++++---------- 2 files changed, 43 insertions(+), 27 deletions(-) diff --git a/layout/base/AccessibleCaretManager.cpp b/layout/base/AccessibleCaretManager.cpp index a7a623d717fc..5d4c890fa917 100644 --- a/layout/base/AccessibleCaretManager.cpp +++ b/layout/base/AccessibleCaretManager.cpp @@ -77,7 +77,7 @@ std::ostream& operator<<( #undef AC_PROCESS_ENUM_TO_STREAM AccessibleCaretManager::AccessibleCaretManager(PresShell* aPresShell) - : mPresShell(aPresShell) { + : mSelectionStringifyer{mLayoutFlusher}, mPresShell{aPresShell} { if (!mPresShell) { return; } @@ -838,13 +838,16 @@ already_AddRefed AccessibleCaretManager::GetFrameSelection() } nsAutoString AccessibleCaretManager::StringifiedSelection() const { - nsAutoString str; RefPtr selection = GetSelection(); - if (selection) { - selection->Stringify(str, mLayoutFlusher.mAllowFlushing - ? Selection::FlushFrames::Yes - : Selection::FlushFrames::No); - } + return mSelectionStringifyer.Stringify(*selection); +} + +nsAutoString AccessibleCaretManager::SelectionStringifyer::Stringify( + Selection& aSelection) const { + nsAutoString str; + aSelection.Stringify(str, mLayoutFlusher.mAllowFlushing + ? Selection::FlushFrames::Yes + : Selection::FlushFrames::No); return str; } diff --git a/layout/base/AccessibleCaretManager.h b/layout/base/AccessibleCaretManager.h index 6759199b6889..632c26493ada 100644 --- a/layout/base/AccessibleCaretManager.h +++ b/layout/base/AccessibleCaretManager.h @@ -245,8 +245,39 @@ class AccessibleCaretManager { dom::Selection* GetSelection() const; already_AddRefed GetFrameSelection() const; - MOZ_CAN_RUN_SCRIPT - nsAutoString StringifiedSelection() const; + class LayoutFlusher final { + public: + ~LayoutFlusher(); + + MOZ_CAN_RUN_SCRIPT void MaybeFlush(const PresShell& aPresShell); + + // Set to false to disallow flushing layout in some callbacks such as + // OnReflow(), OnScrollStart(), OnScrollStart(), or + // OnScrollPositionChanged(). + bool mAllowFlushing = true; + + private: + // Whether we're flushing layout, used for sanity-checking. + bool mFlushing = false; + }; + + LayoutFlusher mLayoutFlusher; + + MOZ_CAN_RUN_SCRIPT nsAutoString StringifiedSelection() const; + + class SelectionStringifyer final { + public: + explicit SelectionStringifyer(LayoutFlusher& aLayoutFlusher) + : mLayoutFlusher{aLayoutFlusher} {} + + [[nodiscard]] MOZ_CAN_RUN_SCRIPT nsAutoString + Stringify(dom::Selection& aSelection) const; + + private: + LayoutFlusher mLayoutFlusher; + }; + + SelectionStringifyer mSelectionStringifyer; // Get the union of all the child frame scrollable overflow rects for aFrame, // which is used as a helper function to restrict the area where the caret can @@ -352,24 +383,6 @@ class AccessibleCaretManager { // Set to true in OnScrollStart() and set to false in OnScrollEnd(). bool mIsScrollStarted = false; - class LayoutFlusher final { - public: - ~LayoutFlusher(); - - MOZ_CAN_RUN_SCRIPT void MaybeFlush(const PresShell& aPresShell); - - // Set to false to disallow flushing layout in some callbacks such as - // OnReflow(), OnScrollStart(), OnScrollStart(), or - // OnScrollPositionChanged(). - bool mAllowFlushing = true; - - private: - // Whether we're flushing layout, used for sanity-checking. - bool mFlushing = false; - }; - - LayoutFlusher mLayoutFlusher; - // Set to True if one of the caret's position is changed in last update. bool mIsCaretPositionChanged = false;