mirror of
https://github.com/classilla/tenfourfox.git
synced 2025-01-12 20:30:18 +00:00
#402, Bug 1363396 - Ensure ContentViewer listeners are handled only when needed. r=mccr8, a=abillings
This commit is contained in:
parent
eb8492dd33
commit
c1a5c64e78
@ -169,6 +169,8 @@ public:
|
||||
|
||||
nsresult Init(nsDocumentViewer *aDocViewer);
|
||||
|
||||
void Disconnect() { mDocViewer = nullptr; }
|
||||
|
||||
protected:
|
||||
|
||||
virtual ~nsDocViewerSelectionListener() {}
|
||||
@ -193,6 +195,8 @@ public:
|
||||
|
||||
nsresult Init(nsDocumentViewer *aDocViewer);
|
||||
|
||||
void Disconnect() { mDocViewer = nullptr; }
|
||||
|
||||
protected:
|
||||
/** default destructor
|
||||
*/
|
||||
@ -347,7 +351,7 @@ protected:
|
||||
RefPtr<nsPresContext> mPresContext;
|
||||
nsCOMPtr<nsIPresShell> mPresShell;
|
||||
|
||||
nsCOMPtr<nsISelectionListener> mSelectionListener;
|
||||
RefPtr<nsDocViewerSelectionListener> mSelectionListener;
|
||||
RefPtr<nsDocViewerFocusListener> mFocusListener;
|
||||
|
||||
nsCOMPtr<nsIContentViewer> mPreviousViewer;
|
||||
@ -523,6 +527,14 @@ nsDocumentViewer::~nsDocumentViewer()
|
||||
Destroy();
|
||||
}
|
||||
|
||||
if (mSelectionListener) {
|
||||
mSelectionListener->Disconnect();
|
||||
}
|
||||
|
||||
if (mFocusListener) {
|
||||
mFocusListener->Disconnect();
|
||||
}
|
||||
|
||||
// XXX(?) Revoke pending invalidate events
|
||||
}
|
||||
|
||||
@ -701,6 +713,9 @@ nsDocumentViewer::InitPresentationStuff(bool aDoInitialReflow)
|
||||
|
||||
// Save old listener so we can unregister it
|
||||
RefPtr<nsDocViewerFocusListener> oldFocusListener = mFocusListener;
|
||||
if (oldFocusListener) {
|
||||
oldFocusListener->Disconnect();
|
||||
}
|
||||
|
||||
// focus listener
|
||||
//
|
||||
@ -1467,11 +1482,14 @@ nsDocumentViewer::Close(nsISHEntry *aSHEntry)
|
||||
mDocument->RemovedFromDocShell();
|
||||
}
|
||||
|
||||
if (mFocusListener && mDocument) {
|
||||
mDocument->RemoveEventListener(NS_LITERAL_STRING("focus"), mFocusListener,
|
||||
false);
|
||||
mDocument->RemoveEventListener(NS_LITERAL_STRING("blur"), mFocusListener,
|
||||
false);
|
||||
if (mFocusListener) {
|
||||
mFocusListener->Disconnect();
|
||||
if (mDocument) {
|
||||
mDocument->RemoveEventListener(NS_LITERAL_STRING("focus"), mFocusListener,
|
||||
false);
|
||||
mDocument->RemoveEventListener(NS_LITERAL_STRING("blur"), mFocusListener,
|
||||
false);
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
@ -3450,7 +3468,9 @@ NS_IMETHODIMP nsDocumentViewer::GetInImage(bool* aInImage)
|
||||
|
||||
NS_IMETHODIMP nsDocViewerSelectionListener::NotifySelectionChanged(nsIDOMDocument *, nsISelection *, int16_t aReason)
|
||||
{
|
||||
NS_ASSERTION(mDocViewer, "Should have doc viewer!");
|
||||
if (!mDocViewer) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// get the selection state
|
||||
RefPtr<mozilla::dom::Selection> selection = mDocViewer->GetDocumentSelection();
|
||||
|
Loading…
x
Reference in New Issue
Block a user