Bug 748216 - Avoid dynamic allocation of nsHTMLTextAreaElement::mState; r=smaug

This commit is contained in:
Ehsan Akhgari 2012-04-24 00:19:26 -04:00
Родитель 4a0a3ebbce
Коммит 3b1c4ed726
4 изменённых файлов: 55 добавлений и 50 удалений

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

@ -573,8 +573,7 @@ nsHTMLInputElement::nsHTMLInputElement(already_AddRefed<nsINodeInfo> aNodeInfo,
, mCanShowInvalidUI(true)
{
mInputData.mState = new nsTextEditorState(this);
NS_ADDREF(mInputData.mState);
if (!gUploadLastDir)
nsHTMLInputElement::InitUploadLastDir();
@ -605,7 +604,8 @@ nsHTMLInputElement::FreeData()
mInputData.mValue = nsnull;
} else {
UnbindFromFrame(nsnull);
NS_IF_RELEASE(mInputData.mState);
delete mInputData.mState;
mInputData.mState = nsnull;
}
}
@ -630,7 +630,7 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsHTMLInputElement,
nsGenericHTMLFormElement)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mControllers)
if (tmp->IsSingleLineTextControl(false)) {
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NATIVE_MEMBER(mInputData.mState, nsTextEditorState)
tmp->mInputData.mState->Traverse(cb);
}
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMARRAY(mFiles)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mFileList)
@ -644,6 +644,9 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(nsHTMLInputElement,
tmp->mFileList->Disconnect();
tmp->mFileList = nsnull;
}
if (tmp->IsSingleLineTextControl(false)) {
tmp->mInputData.mState->Unlink();
}
//XXX should unlink more?
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
@ -2396,7 +2399,6 @@ nsHTMLInputElement::HandleTypeChange(PRUint8 aNewType)
if (isNewTypeSingleLine && !isCurrentTypeSingleLine) {
FreeData();
mInputData.mState = new nsTextEditorState(this);
NS_ADDREF(mInputData.mState);
} else if (isCurrentTypeSingleLine && !isNewTypeSingleLine) {
FreeData();
}

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

@ -259,7 +259,7 @@ protected:
bool mCanShowValidUI;
/** The state of the text editor (selection controller and the editor) **/
nsRefPtr<nsTextEditorState> mState;
nsTextEditorState mState;
NS_IMETHOD SelectAll(nsPresContext* aPresContext);
/**
@ -333,7 +333,7 @@ nsHTMLTextAreaElement::nsHTMLTextAreaElement(already_AddRefed<nsINodeInfo> aNode
mDisabledChanged(false),
mCanShowInvalidUI(true),
mCanShowValidUI(true),
mState(new nsTextEditorState(this))
mState(this)
{
AddMutationObserver(this);
@ -352,11 +352,12 @@ NS_IMPL_CYCLE_COLLECTION_CLASS(nsHTMLTextAreaElement)
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(nsHTMLTextAreaElement,
nsGenericHTMLFormElement)
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mControllers)
tmp->mState.Unlink();
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsHTMLTextAreaElement,
nsGenericHTMLFormElement)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mControllers)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NATIVE_MEMBER(mState, nsTextEditorState)
tmp->mState.Traverse(cb);
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_IMPL_ADDREF_INHERITED(nsHTMLTextAreaElement, nsGenericElement)
@ -498,76 +499,76 @@ nsHTMLTextAreaElement::GetValue(nsAString& aValue)
void
nsHTMLTextAreaElement::GetValueInternal(nsAString& aValue, bool aIgnoreWrap) const
{
mState->GetValue(aValue, aIgnoreWrap);
mState.GetValue(aValue, aIgnoreWrap);
}
NS_IMETHODIMP_(nsIEditor*)
nsHTMLTextAreaElement::GetTextEditor()
{
return mState->GetEditor();
return mState.GetEditor();
}
NS_IMETHODIMP_(nsISelectionController*)
nsHTMLTextAreaElement::GetSelectionController()
{
return mState->GetSelectionController();
return mState.GetSelectionController();
}
NS_IMETHODIMP_(nsFrameSelection*)
nsHTMLTextAreaElement::GetConstFrameSelection()
{
return mState->GetConstFrameSelection();
return mState.GetConstFrameSelection();
}
NS_IMETHODIMP
nsHTMLTextAreaElement::BindToFrame(nsTextControlFrame* aFrame)
{
return mState->BindToFrame(aFrame);
return mState.BindToFrame(aFrame);
}
NS_IMETHODIMP_(void)
nsHTMLTextAreaElement::UnbindFromFrame(nsTextControlFrame* aFrame)
{
if (aFrame) {
mState->UnbindFromFrame(aFrame);
mState.UnbindFromFrame(aFrame);
}
}
NS_IMETHODIMP
nsHTMLTextAreaElement::CreateEditor()
{
return mState->PrepareEditor();
return mState.PrepareEditor();
}
NS_IMETHODIMP_(nsIContent*)
nsHTMLTextAreaElement::GetRootEditorNode()
{
return mState->GetRootNode();
return mState.GetRootNode();
}
NS_IMETHODIMP_(nsIContent*)
nsHTMLTextAreaElement::CreatePlaceholderNode()
{
NS_ENSURE_SUCCESS(mState->CreatePlaceholderNode(), nsnull);
return mState->GetPlaceholderNode();
NS_ENSURE_SUCCESS(mState.CreatePlaceholderNode(), nsnull);
return mState.GetPlaceholderNode();
}
NS_IMETHODIMP_(nsIContent*)
nsHTMLTextAreaElement::GetPlaceholderNode()
{
return mState->GetPlaceholderNode();
return mState.GetPlaceholderNode();
}
NS_IMETHODIMP_(void)
nsHTMLTextAreaElement::UpdatePlaceholderText(bool aNotify)
{
mState->UpdatePlaceholderText(aNotify);
mState.UpdatePlaceholderText(aNotify);
}
NS_IMETHODIMP_(void)
nsHTMLTextAreaElement::SetPlaceholderClass(bool aVisible, bool aNotify)
{
mState->SetPlaceholderClass(aVisible, aNotify);
mState.SetPlaceholderClass(aVisible, aNotify);
}
nsresult
@ -578,7 +579,7 @@ nsHTMLTextAreaElement::SetValueInternal(const nsAString& aValue,
// nsTextControlFrame::UpdateValueDisplay retrieves the correct value
// if needed.
SetValueChanged(true);
mState->SetValue(aValue, aUserInput);
mState.SetValue(aValue, aUserInput);
return NS_OK;
}
@ -605,8 +606,8 @@ nsHTMLTextAreaElement::SetValueChanged(bool aValueChanged)
bool previousValue = mValueChanged;
mValueChanged = aValueChanged;
if (!aValueChanged && !mState->IsEmpty()) {
mState->EmptyValue();
if (!aValueChanged && !mState.IsEmpty()) {
mState.EmptyValue();
}
if (mValueChanged != previousValue) {
@ -848,8 +849,8 @@ nsHTMLTextAreaElement::GetSelectionStart(PRInt32 *aSelectionStart)
PRInt32 selEnd;
nsresult rv = GetSelectionRange(aSelectionStart, &selEnd);
if (NS_FAILED(rv) && mState->IsSelectionCached()) {
*aSelectionStart = mState->GetSelectionProperties().mStart;
if (NS_FAILED(rv) && mState.IsSelectionCached()) {
*aSelectionStart = mState.GetSelectionProperties().mStart;
return NS_OK;
}
return rv;
@ -858,8 +859,8 @@ nsHTMLTextAreaElement::GetSelectionStart(PRInt32 *aSelectionStart)
NS_IMETHODIMP
nsHTMLTextAreaElement::SetSelectionStart(PRInt32 aSelectionStart)
{
if (mState->IsSelectionCached()) {
mState->GetSelectionProperties().mStart = aSelectionStart;
if (mState.IsSelectionCached()) {
mState.GetSelectionProperties().mStart = aSelectionStart;
return NS_OK;
}
@ -884,8 +885,8 @@ nsHTMLTextAreaElement::GetSelectionEnd(PRInt32 *aSelectionEnd)
PRInt32 selStart;
nsresult rv = GetSelectionRange(&selStart, aSelectionEnd);
if (NS_FAILED(rv) && mState->IsSelectionCached()) {
*aSelectionEnd = mState->GetSelectionProperties().mEnd;
if (NS_FAILED(rv) && mState.IsSelectionCached()) {
*aSelectionEnd = mState.GetSelectionProperties().mEnd;
return NS_OK;
}
return rv;
@ -894,8 +895,8 @@ nsHTMLTextAreaElement::GetSelectionEnd(PRInt32 *aSelectionEnd)
NS_IMETHODIMP
nsHTMLTextAreaElement::SetSelectionEnd(PRInt32 aSelectionEnd)
{
if (mState->IsSelectionCached()) {
mState->GetSelectionProperties().mEnd = aSelectionEnd;
if (mState.IsSelectionCached()) {
mState.GetSelectionProperties().mEnd = aSelectionEnd;
return NS_OK;
}
@ -960,8 +961,8 @@ nsHTMLTextAreaElement::GetSelectionDirection(nsAString& aDirection)
}
if (NS_FAILED(rv)) {
if (mState->IsSelectionCached()) {
DirectionToName(mState->GetSelectionProperties().mDirection, aDirection);
if (mState.IsSelectionCached()) {
DirectionToName(mState.GetSelectionProperties().mDirection, aDirection);
return NS_OK;
}
}
@ -971,14 +972,14 @@ nsHTMLTextAreaElement::GetSelectionDirection(nsAString& aDirection)
NS_IMETHODIMP
nsHTMLTextAreaElement::SetSelectionDirection(const nsAString& aDirection) {
if (mState->IsSelectionCached()) {
if (mState.IsSelectionCached()) {
nsITextControlFrame::SelectionDirection dir = nsITextControlFrame::eNone;
if (aDirection.EqualsLiteral("forward")) {
dir = nsITextControlFrame::eForward;
} else if (aDirection.EqualsLiteral("backward")) {
dir = nsITextControlFrame::eBackward;
}
mState->GetSelectionProperties().mDirection = dir;
mState.GetSelectionProperties().mDirection = dir;
return NS_OK;
}
@ -1293,7 +1294,7 @@ nsHTMLTextAreaElement::AfterSetAttr(PRInt32 aNameSpaceID, nsIAtom* aName,
if (aName == nsGkAtoms::readonly) {
UpdateEditableState(aNotify);
mState->UpdateEditableState(aNotify);
mState.UpdateEditableState(aNotify);
}
UpdateState(aNotify);
}
@ -1525,20 +1526,20 @@ NS_IMETHODIMP_(void)
nsHTMLTextAreaElement::GetTextEditorValue(nsAString& aValue,
bool aIgnoreWrap) const
{
mState->GetValue(aValue, aIgnoreWrap);
mState.GetValue(aValue, aIgnoreWrap);
}
NS_IMETHODIMP_(void)
nsHTMLTextAreaElement::SetTextEditorValue(const nsAString& aValue,
bool aUserInput)
{
mState->SetValue(aValue, aUserInput);
mState.SetValue(aValue, aUserInput);
}
NS_IMETHODIMP_(void)
nsHTMLTextAreaElement::InitializeKeyboardEventListeners()
{
mState->InitializeKeyboardEventListeners();
mState.InitializeKeyboardEventListeners();
}
NS_IMETHODIMP_(void)
@ -1559,7 +1560,7 @@ nsHTMLTextAreaElement::OnValueChanged(bool aNotify)
NS_IMETHODIMP_(bool)
nsHTMLTextAreaElement::HasCachedSelection()
{
return mState->IsSelectionCached();
return mState.IsSelectionCached();
}
void

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

@ -970,22 +970,24 @@ nsTextEditorState::Clear()
NS_IF_RELEASE(mTextListener);
}
NS_IMPL_CYCLE_COLLECTION_CLASS(nsTextEditorState)
NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(nsTextEditorState, AddRef)
NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(nsTextEditorState, Release)
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_NATIVE(nsTextEditorState)
void nsTextEditorState::Unlink()
{
nsTextEditorState* tmp = this;
tmp->Clear();
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mSelCon)
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mEditor)
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mRootNode)
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mPlaceholderDiv)
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NATIVE_BEGIN(nsTextEditorState)
}
void nsTextEditorState::Traverse(nsCycleCollectionTraversalCallback& cb)
{
nsTextEditorState* tmp = this;
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR_AMBIGUOUS(mSelCon, nsISelectionController)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mEditor)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mRootNode)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mPlaceholderDiv)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
}
nsFrameSelection*
nsTextEditorState::GetConstFrameSelection() {

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

@ -154,8 +154,8 @@ public:
explicit nsTextEditorState(nsITextControlElement* aOwningElement);
~nsTextEditorState();
NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS(nsTextEditorState)
NS_INLINE_DECL_REFCOUNTING(nsTextEditorState)
void Traverse(nsCycleCollectionTraversalCallback& cb);
void Unlink();
nsIEditor* GetEditor();
nsISelectionController* GetSelectionController() const;