Bug 795804 - Use WeakPtr for nsTextEditorState where appropriate; r=ehsan

This commit is contained in:
Aryeh Gregor 2012-10-10 15:22:27 -04:00
Родитель 81cf290708
Коммит cdb3cc0401
2 изменённых файлов: 9 добавлений и 6 удалений

Просмотреть файл

@ -1010,29 +1010,31 @@ public:
PrepareEditorEvent(nsTextEditorState &aState,
nsIContent *aOwnerContent,
const nsAString &aCurrentValue)
: mState(aState)
: mState(aState.asWeakPtr())
, mOwnerContent(aOwnerContent)
, mCurrentValue(aCurrentValue)
{
mState.mValueTransferInProgress = true;
aState.mValueTransferInProgress = true;
}
NS_IMETHOD Run() {
NS_ENSURE_TRUE(mState, NS_ERROR_NULL_POINTER);
// Transfer the saved value to the editor if we have one
const nsAString *value = nullptr;
if (!mCurrentValue.IsEmpty()) {
value = &mCurrentValue;
}
mState.PrepareEditor(value);
mState->PrepareEditor(value);
mState.mValueTransferInProgress = false;
mState->mValueTransferInProgress = false;
return NS_OK;
}
private:
nsTextEditorState &mState;
WeakPtr<nsTextEditorState> mState;
nsCOMPtr<nsIContent> mOwnerContent; // strong reference
nsAutoString mCurrentValue;
};

Просмотреть файл

@ -13,6 +13,7 @@
#include "nsITextControlFrame.h"
#include "nsCycleCollectionParticipant.h"
#include "nsIContent.h"
#include "mozilla/WeakPtr.h"
class nsTextInputListener;
class nsTextControlFrame;
@ -117,7 +118,7 @@ class nsITextControlElement;
class RestoreSelectionState;
class nsTextEditorState {
class nsTextEditorState : public mozilla::SupportsWeakPtr<nsTextEditorState> {
public:
explicit nsTextEditorState(nsITextControlElement* aOwningElement);
~nsTextEditorState();