Bug 1330739 - Don't use control's frame as reference in SelectionManager. r=surkov

This commit is contained in:
Eitan Isaacson
2017-07-26 19:02:37 -04:00
parent 7d3649825d
commit cb4f300919
2 changed files with 21 additions and 21 deletions

View File

@@ -48,24 +48,21 @@ 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(SelectionType::eNormal);
normalSel->RemoveSelectionListener(this);
nsCOMPtr<nsISelection> 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(SelectionType::eSpellCheck);
spellSel->RemoveSelectionListener(this);
nsCOMPtr<nsISelection> spellSel = do_QueryReferent(mCurrCtrlSpellSel);
if (spellSel) {
spellSel->AsSelection()->RemoveSelectionListener(this);
mCurrCtrlSpellSel = nullptr;
}
}
void
@@ -76,22 +73,24 @@ 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 = frameSel->GetSelection(SelectionType::eNormal);
normalSel->AddSelectionListener(this);
nsCOMPtr<nsISelection> normalSel = frameSel->GetSelection(SelectionType::eNormal);
normalSel->AsSelection()->AddSelectionListener(this);
mCurrCtrlNormalSel = do_GetWeakReference(normalSel);
// Register 'this' as selection listener for the spell check selection.
Selection* spellSel = frameSel->GetSelection(SelectionType::eSpellCheck);
spellSel->AddSelectionListener(this);
nsCOMPtr<nsISelection> spellSel = frameSel->GetSelection(SelectionType::eSpellCheck);
spellSel->AsSelection()->AddSelectionListener(this);
mCurrCtrlSpellSel = do_GetWeakReference(spellSel);
}
void