Bug 1688832: part 4) Add AccessibleCaretManager::SelectionStringifyer. r=TYLin

Will help to simplify `AccessibleCaretManager::Dispatch...`.

Differential Revision: https://phabricator.services.mozilla.com/D102920
This commit is contained in:
Mirko Brodesser 2021-01-27 09:43:35 +00:00
parent 3d4ea57f64
commit acee8474e0
2 changed files with 43 additions and 27 deletions

View File

@ -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<nsFrameSelection> AccessibleCaretManager::GetFrameSelection()
}
nsAutoString AccessibleCaretManager::StringifiedSelection() const {
nsAutoString str;
RefPtr<Selection> 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;
}

View File

@ -245,8 +245,39 @@ class AccessibleCaretManager {
dom::Selection* GetSelection() const;
already_AddRefed<nsFrameSelection> 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;