diff --git a/mozilla/layout/html/forms/src/nsNativeTextControlFrame.cpp b/mozilla/layout/html/forms/src/nsNativeTextControlFrame.cpp index b7f48171a23..ead7afc92c6 100644 --- a/mozilla/layout/html/forms/src/nsNativeTextControlFrame.cpp +++ b/mozilla/layout/html/forms/src/nsNativeTextControlFrame.cpp @@ -71,6 +71,19 @@ NS_NewNativeTextControlFrame(nsIFrame** aNewFrame) return NS_OK; } +nsNativeTextControlFrame::nsNativeTextControlFrame() +: mCachedState(nsnull) +{ +} + +nsNativeTextControlFrame::~nsNativeTextControlFrame() +{ + if (mCachedState) { + delete mCachedState; + mCachedState = nsnull; + } +} + void nsNativeTextControlFrame::EnterPressed(nsIPresContext& aPresContext) { @@ -244,7 +257,12 @@ nsNativeTextControlFrame::PostCreateWidget(nsIPresContext* aPresContext, nsITextAreaWidget* textArea = nsnull; nsITextWidget* text = nsnull; if (NS_OK == mWidget->QueryInterface(kITextWidgetIID,(void**)&text)) { - GetText(&value, PR_TRUE); + if (mCachedState) { + value = *mCachedState; + delete mCachedState; + mCachedState = nsnull; + } else + GetText(&value, PR_TRUE); text->SetText(value, ignore); PRInt32 maxLength; nsresult result = GetMaxLength(&maxLength); @@ -253,7 +271,12 @@ nsNativeTextControlFrame::PostCreateWidget(nsIPresContext* aPresContext, } NS_RELEASE(text); } else if (NS_OK == mWidget->QueryInterface(kITextAreaWidgetIID,(void**)&textArea)) { - GetText(&value, PR_TRUE); + if (mCachedState) { + value = *mCachedState; + delete mCachedState; + mCachedState = nsnull; + } else + GetText(&value, PR_TRUE); textArea->SetText(value, ignore); NS_RELEASE(textArea); } @@ -539,7 +562,9 @@ void nsNativeTextControlFrame::SetTextControlFrameState(const nsString& aValue) textArea->SetText(aValue,size); NS_RELEASE(textArea); } - } + } else { + mCachedState = new nsString(aValue); + } } NS_IMETHODIMP nsNativeTextControlFrame::SetProperty(nsIAtom* aName, const nsString& aValue) diff --git a/mozilla/layout/html/forms/src/nsNativeTextControlFrame.h b/mozilla/layout/html/forms/src/nsNativeTextControlFrame.h index d999b1b8b2d..96f93a05a8e 100644 --- a/mozilla/layout/html/forms/src/nsNativeTextControlFrame.h +++ b/mozilla/layout/html/forms/src/nsNativeTextControlFrame.h @@ -30,7 +30,10 @@ private: typedef nsNativeFormControlFrame Inherited; public: - // nsIFormControlFrame + nsNativeTextControlFrame(); + virtual ~nsNativeTextControlFrame(); + + // nsIFormControlFrame NS_IMETHOD SetProperty(nsIAtom* aName, const nsString& aValue); NS_IMETHOD GetProperty(nsIAtom* aName, nsString& aValue); @@ -75,6 +78,8 @@ public: virtual nsresult RequiresWidget(PRBool &aRequiresWidget); +protected: + nsString* mCachedState; }; #endif