Bug 1685303: part 17) Slightly refactor AccessibleCaretManager::FlushLayout. r=TYLin

Now the method states clearer what it does.

Differential Revision: https://phabricator.services.mozilla.com/D102192
This commit is contained in:
Mirko Brodesser 2021-01-20 10:13:07 +00:00
parent e9ee99f363
commit 3e7a8c2653
3 changed files with 17 additions and 13 deletions

View File

@ -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<bool> 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;
}

View File

@ -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;

View File

@ -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());