mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-17 14:25:49 +00:00
Bug 1433345 - part 3: Make HTMLEditor store ResizerSelectionListener directly r=m_kato
This patch makes HTMLEditor store ResizerSelectionListener directly and make it cycle collectable. However, in the following patch, this class will be removed completely because it doesn't necessary if HTMLEditor becomes a selection listener. MozReview-Commit-ID: 2iXlTcZdzvj --HG-- extra : rebase_source : 893a3bbf290eb1752a701d6d8ac284a1630a6fbe
This commit is contained in:
parent
905d027c8f
commit
1ef303c32e
@ -146,19 +146,16 @@ HTMLEditor::~HTMLEditor()
|
||||
RefPtr<Selection> selection = GetSelection();
|
||||
// if we don't get the selection, just skip this
|
||||
if (selection) {
|
||||
nsCOMPtr<nsISelectionListener>listener;
|
||||
listener = do_QueryInterface(mTypeInState);
|
||||
if (listener) {
|
||||
selection->RemoveSelectionListener(listener);
|
||||
if (mTypeInState) {
|
||||
selection->RemoveSelectionListener(mTypeInState);
|
||||
}
|
||||
listener = do_QueryInterface(mSelectionListenerP);
|
||||
if (listener) {
|
||||
selection->RemoveSelectionListener(listener);
|
||||
if (mResizerSelectionListener) {
|
||||
selection->RemoveSelectionListener(mResizerSelectionListener);
|
||||
}
|
||||
}
|
||||
|
||||
mTypeInState = nullptr;
|
||||
mSelectionListenerP = nullptr;
|
||||
mResizerSelectionListener = nullptr;
|
||||
|
||||
if (mLinkHandler && IsInitialized()) {
|
||||
nsCOMPtr<nsIPresShell> ps = GetPresShell();
|
||||
@ -202,6 +199,7 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(HTMLEditor, TextEditor)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mTypeInState)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mComposerCommandsUpdater)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mResizerSelectionListener)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mStyleSheets)
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mTopLeftHandle)
|
||||
@ -217,7 +215,6 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(HTMLEditor, TextEditor)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mResizingInfo)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mResizedObject)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mMouseMotionListenerP)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mSelectionListenerP)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mResizeEventListenerP)
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mAbsolutelyPositionedObject)
|
||||
@ -303,7 +300,7 @@ HTMLEditor::Init(nsIDOMDocument* aDoc,
|
||||
mTypeInState = new TypeInState();
|
||||
|
||||
// init the selection listener for image resizing
|
||||
mSelectionListenerP = new ResizerSelectionListener(*this);
|
||||
mResizerSelectionListener = new ResizerSelectionListener(*this);
|
||||
|
||||
if (!IsInteractionAllowed()) {
|
||||
// ignore any errors from this in case the file is missing
|
||||
@ -312,14 +309,11 @@ HTMLEditor::Init(nsIDOMDocument* aDoc,
|
||||
|
||||
RefPtr<Selection> selection = GetSelection();
|
||||
if (selection) {
|
||||
nsCOMPtr<nsISelectionListener>listener;
|
||||
listener = do_QueryInterface(mTypeInState);
|
||||
if (listener) {
|
||||
selection->AddSelectionListener(listener);
|
||||
if (mTypeInState) {
|
||||
selection->AddSelectionListener(mTypeInState);
|
||||
}
|
||||
listener = do_QueryInterface(mSelectionListenerP);
|
||||
if (listener) {
|
||||
selection->AddSelectionListener(listener);
|
||||
if (mResizerSelectionListener) {
|
||||
selection->AddSelectionListener(mResizerSelectionListener);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -49,6 +49,7 @@ namespace mozilla {
|
||||
class AutoSelectionSetterAfterTableEdit;
|
||||
class HTMLEditorEventListener;
|
||||
class HTMLEditRules;
|
||||
class ResizerSelectionListener;
|
||||
class TypeInState;
|
||||
class WSRunObject;
|
||||
enum class EditAction : int32_t;
|
||||
@ -989,6 +990,7 @@ protected:
|
||||
protected:
|
||||
RefPtr<TypeInState> mTypeInState;
|
||||
RefPtr<ComposerCommandsUpdater> mComposerCommandsUpdater;
|
||||
RefPtr<ResizerSelectionListener> mResizerSelectionListener;
|
||||
|
||||
bool mCRInParagraphCreatesParagraph;
|
||||
|
||||
@ -1072,7 +1074,6 @@ protected:
|
||||
nsCOMPtr<Element> mResizedObject;
|
||||
|
||||
nsCOMPtr<nsIDOMEventListener> mMouseMotionListenerP;
|
||||
nsCOMPtr<nsISelectionListener> mSelectionListenerP;
|
||||
nsCOMPtr<nsIDOMEventListener> mResizeEventListenerP;
|
||||
|
||||
int32_t mOriginalX;
|
||||
|
@ -71,10 +71,20 @@ DocumentResizeEventListener::HandleEvent(nsIDOMEvent* aMouseEvent)
|
||||
* mozilla::ResizerSelectionListener
|
||||
******************************************************************************/
|
||||
|
||||
NS_IMPL_ISUPPORTS(ResizerSelectionListener, nsISelectionListener)
|
||||
NS_IMPL_CYCLE_COLLECTING_ADDREF(ResizerSelectionListener)
|
||||
NS_IMPL_CYCLE_COLLECTING_RELEASE(ResizerSelectionListener)
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN(ResizerSelectionListener)
|
||||
NS_INTERFACE_MAP_ENTRY(nsISelectionListener)
|
||||
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsISelectionListener)
|
||||
NS_INTERFACE_MAP_ENTRIES_CYCLE_COLLECTION(ResizerSelectionListener)
|
||||
NS_INTERFACE_MAP_END
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION(ResizerSelectionListener,
|
||||
mHTMLEditor)
|
||||
|
||||
ResizerSelectionListener::ResizerSelectionListener(HTMLEditor& aHTMLEditor)
|
||||
: mHTMLEditorWeak(&aHTMLEditor)
|
||||
: mHTMLEditor(&aHTMLEditor)
|
||||
{
|
||||
}
|
||||
|
||||
@ -83,12 +93,15 @@ ResizerSelectionListener::NotifySelectionChanged(nsIDOMDocument* aDOMDocument,
|
||||
nsISelection* aSelection,
|
||||
int16_t aReason)
|
||||
{
|
||||
if (!mHTMLEditor) {
|
||||
return NS_OK;
|
||||
}
|
||||
if ((aReason & (nsISelectionListener::MOUSEDOWN_REASON |
|
||||
nsISelectionListener::KEYPRESS_REASON |
|
||||
nsISelectionListener::SELECTALL_REASON)) && aSelection) {
|
||||
// the selection changed and we need to check if we have to
|
||||
// hide and/or redisplay resizing handles
|
||||
RefPtr<HTMLEditor> htmlEditor = mHTMLEditorWeak.get();
|
||||
RefPtr<HTMLEditor> htmlEditor = mHTMLEditor;
|
||||
if (htmlEditor) {
|
||||
htmlEditor->CheckSelectionStateForAnonymousButtons(aSelection);
|
||||
}
|
||||
|
@ -7,6 +7,7 @@
|
||||
#define HTMLEditorObjectResizerUtils_h
|
||||
|
||||
#include "mozilla/HTMLEditor.h"
|
||||
#include "nsCycleCollectionParticipant.h"
|
||||
#include "nsIDOMEventListener.h"
|
||||
#include "nsISelectionListener.h"
|
||||
#include "nsISupportsImpl.h"
|
||||
@ -36,12 +37,15 @@ public:
|
||||
explicit ResizerSelectionListener(HTMLEditor& aHTMLEditor);
|
||||
void Reset();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
||||
NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(ResizerSelectionListener,
|
||||
nsISelectionListener)
|
||||
|
||||
NS_DECL_NSISELECTIONLISTENER
|
||||
|
||||
protected:
|
||||
virtual ~ResizerSelectionListener() {}
|
||||
CachedWeakPtr<HTMLEditor, nsIHTMLEditor> mHTMLEditorWeak;
|
||||
virtual ~ResizerSelectionListener() = default;
|
||||
RefPtr<HTMLEditor> mHTMLEditor;
|
||||
};
|
||||
|
||||
/******************************************************************************
|
||||
|
Loading…
x
Reference in New Issue
Block a user