diff --git a/layout/base/AccessibleCaretManager.cpp b/layout/base/AccessibleCaretManager.cpp index 5143eb0cf77f..1c84231852cd 100644 --- a/layout/base/AccessibleCaretManager.cpp +++ b/layout/base/AccessibleCaretManager.cpp @@ -123,8 +123,7 @@ nsresult AccessibleCaretManager::OnSelectionChanged(Document* aDoc, StaticPrefs::layout_accessiblecaret_script_change_update_mode()); if (mode == kScriptAlwaysShow || (mode == kScriptUpdateVisible && - (mCarets.mFirst->IsLogicallyVisible() || - mCarets.mSecond->IsLogicallyVisible()))) { + mCarets.AreLogicallyVisible())) { UpdateCarets(); return NS_OK; } @@ -174,8 +173,7 @@ nsresult AccessibleCaretManager::OnSelectionChanged(Document* aDoc, } void AccessibleCaretManager::HideCaretsAndDispatchCaretStateChangedEvent() { - if (mCarets.mFirst->IsLogicallyVisible() || - mCarets.mSecond->IsLogicallyVisible()) { + if (mCarets.AreLogicallyVisible()) { AC_LOG("%s", __FUNCTION__); mCarets.mFirst->SetAppearance(Appearance::None); mCarets.mSecond->SetAppearance(Appearance::None); @@ -699,8 +697,7 @@ void AccessibleCaretManager::OnScrollStart() { mIsScrollStarted = true; - if (mCarets.mFirst->IsLogicallyVisible() || - mCarets.mSecond->IsLogicallyVisible()) { + if (mCarets.AreLogicallyVisible()) { // Dispatch the event only if one of the carets is logically visible like in // HideCaretsAndDispatchCaretStateChangedEvent(). DispatchCaretStateChangedEvent(CaretChangedReason::Scroll); @@ -747,8 +744,7 @@ void AccessibleCaretManager::OnScrollPositionChanged() { assert.emplace(*mPresShell); } - if (mCarets.mFirst->IsLogicallyVisible() || - mCarets.mSecond->IsLogicallyVisible()) { + if (mCarets.AreLogicallyVisible()) { if (mIsScrollStarted) { // We don't want extra CaretStateChangedEvents dispatched when user is // scrolling the page. @@ -772,8 +768,7 @@ void AccessibleCaretManager::OnReflow() { assert.emplace(*mPresShell); } - if (mCarets.mFirst->IsLogicallyVisible() || - mCarets.mSecond->IsLogicallyVisible()) { + if (mCarets.AreLogicallyVisible()) { AC_LOG("%s: UpdateCarets(RespectOldAppearance)", __FUNCTION__); UpdateCarets(UpdateCaretsHint::RespectOldAppearance); } @@ -1480,8 +1475,7 @@ void AccessibleCaretManager::DispatchCaretStateChangedEvent( init.mBoundingClientRect = domRect; init.mReason = aReason; init.mCollapsed = sel->IsCollapsed(); - init.mCaretVisible = mCarets.mFirst->IsLogicallyVisible() || - mCarets.mSecond->IsLogicallyVisible(); + init.mCaretVisible = mCarets.AreLogicallyVisible(); init.mCaretVisuallyVisible = mCarets.mFirst->IsVisuallyVisible() || mCarets.mSecond->IsVisuallyVisible(); init.mSelectedTextContent = StringifiedSelection(); diff --git a/layout/base/AccessibleCaretManager.h b/layout/base/AccessibleCaretManager.h index c2f43d7ebfb6..bf70cd0a901e 100644 --- a/layout/base/AccessibleCaretManager.h +++ b/layout/base/AccessibleCaretManager.h @@ -314,7 +314,13 @@ class AccessibleCaretManager { // nullptr either we are in gtest or PresShell::IsDestroying() is true. PresShell* MOZ_NON_OWNING_REF mPresShell = nullptr; - struct Carets { + class Carets { + public: + // See `AccessibleCaret::IsLogicallyVisible`. + bool AreLogicallyVisible() const { + return mFirst->IsLogicallyVisible() || mSecond->IsLogicallyVisible(); + } + // First caret is attached to nsCaret in cursor mode, and is attached to // selection highlight as the left caret in selection mode. UniquePtr mFirst;