From ea7b13db8383978825625f453526ee653ad73ee0 Mon Sep 17 00:00:00 2001 From: Cameron Kaiser Date: Sat, 23 Sep 2017 15:45:05 -0700 Subject: [PATCH] #433: M1368269 M1400399 --- accessible/base/SelectionManager.cpp | 42 +++++++++++------------- accessible/base/SelectionManager.h | 5 +-- accessible/xul/XULTreeAccessible.cpp | 2 +- accessible/xul/XULTreeGridAccessible.cpp | 2 +- 4 files changed, 24 insertions(+), 27 deletions(-) diff --git a/accessible/base/SelectionManager.cpp b/accessible/base/SelectionManager.cpp index eb12dd15b..4d3dec419 100644 --- a/accessible/base/SelectionManager.cpp +++ b/accessible/base/SelectionManager.cpp @@ -48,26 +48,20 @@ SelectionManager::SelectionManager() : void SelectionManager::ClearControlSelectionListener() { - if (!mCurrCtrlFrame) - return; - - const nsFrameSelection* frameSel = mCurrCtrlFrame->GetConstFrameSelection(); - NS_ASSERTION(frameSel, "No frame selection for the element!"); - - mCurrCtrlFrame = nullptr; - if (!frameSel) - return; - // Remove 'this' registered as selection listener for the normal selection. - Selection* normalSel = - frameSel->GetSelection(nsISelectionController::SELECTION_NORMAL); - normalSel->RemoveSelectionListener(this); + nsCOMPtr normalSel = do_QueryReferent(mCurrCtrlNormalSel); + if (normalSel) { + normalSel->AsSelection()->RemoveSelectionListener(this); + mCurrCtrlNormalSel = nullptr; + } // Remove 'this' registered as selection listener for the spellcheck // selection. - Selection* spellSel = - frameSel->GetSelection(nsISelectionController::SELECTION_SPELLCHECK); - spellSel->RemoveSelectionListener(this); + nsCOMPtr spellSel = do_QueryReferent(mCurrCtrlSpellSel); + if (spellSel) { + spellSel->AsSelection()->RemoveSelectionListener(this); + mCurrCtrlSpellSel = nullptr; + } } void @@ -78,24 +72,26 @@ SelectionManager::SetControlSelectionListener(dom::Element* aFocusedElm) // the current focus. ClearControlSelectionListener(); - mCurrCtrlFrame = aFocusedElm->GetPrimaryFrame(); - if (!mCurrCtrlFrame) + nsIFrame* controlFrame = aFocusedElm->GetPrimaryFrame(); + if (!controlFrame) return; - const nsFrameSelection* frameSel = mCurrCtrlFrame->GetConstFrameSelection(); + const nsFrameSelection* frameSel = controlFrame->GetConstFrameSelection(); NS_ASSERTION(frameSel, "No frame selection for focused element!"); if (!frameSel) return; // Register 'this' as selection listener for the normal selection. - Selection* normalSel = + nsCOMPtr normalSel = frameSel->GetSelection(nsISelectionController::SELECTION_NORMAL); - normalSel->AddSelectionListener(this); + normalSel->AsSelection()->AddSelectionListener(this); + mCurrCtrlNormalSel = do_GetWeakReference(normalSel); // Register 'this' as selection listener for the spell check selection. - Selection* spellSel = + nsCOMPtr spellSel = frameSel->GetSelection(nsISelectionController::SELECTION_SPELLCHECK); - spellSel->AddSelectionListener(this); + spellSel->AsSelection()->AddSelectionListener(this); + mCurrCtrlSpellSel = do_GetWeakReference(spellSel); } void diff --git a/accessible/base/SelectionManager.h b/accessible/base/SelectionManager.h index c24f638f8..d8e6dabbd 100644 --- a/accessible/base/SelectionManager.h +++ b/accessible/base/SelectionManager.h @@ -120,10 +120,11 @@ protected: void ProcessSelectionChanged(SelData* aSelData); private: - // Currently focused control. - nsWeakFrame mCurrCtrlFrame; int32_t mCaretOffset; HyperTextAccessible* mAccWithCaret; + // Currently focused controls. + nsWeakPtr mCurrCtrlNormalSel; + nsWeakPtr mCurrCtrlSpellSel; }; } // namespace a11y diff --git a/accessible/xul/XULTreeAccessible.cpp b/accessible/xul/XULTreeAccessible.cpp index f6dfb7eaa..029509952 100644 --- a/accessible/xul/XULTreeAccessible.cpp +++ b/accessible/xul/XULTreeAccessible.cpp @@ -145,7 +145,7 @@ XULTreeAccessible::Value(nsString& aValue) void XULTreeAccessible::Shutdown() { - if (!mDoc->IsDefunct()) { + if (mDoc && !mDoc->IsDefunct()) { UnbindCacheEntriesFromDocument(mAccessibleCache); } diff --git a/accessible/xul/XULTreeGridAccessible.cpp b/accessible/xul/XULTreeGridAccessible.cpp index dc809b0ed..112397c43 100644 --- a/accessible/xul/XULTreeGridAccessible.cpp +++ b/accessible/xul/XULTreeGridAccessible.cpp @@ -276,7 +276,7 @@ NS_IMPL_RELEASE_INHERITED(XULTreeGridRowAccessible, void XULTreeGridRowAccessible::Shutdown() { - if (!mDoc->IsDefunct()) { + if (mDoc && !mDoc->IsDefunct()) { UnbindCacheEntriesFromDocument(mAccessibleCache); }