From 25950ae5743bc0b1d9836230b708e9d26716ca58 Mon Sep 17 00:00:00 2001 From: "pollmann%netscape.com" Date: Tue, 24 Apr 2001 08:33:57 +0000 Subject: [PATCH] Bug 74639: Preserve frame state through form demotion, don't store uninitialized frame state, r=nisheeth@netscape.com, sr=jst@netscape.com git-svn-id: svn://10.0.0.236/trunk@92992 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/layout/build/nsLayoutCID.h | 4 ++++ mozilla/layout/build/nsLayoutFactory.cpp | 9 +++++++++ mozilla/layout/build/nsLayoutModule.cpp | 1 + mozilla/layout/forms/nsFileControlFrame.cpp | 14 +++++++++++--- mozilla/layout/forms/nsGfxCheckboxControlFrame.cpp | 5 +++++ mozilla/layout/forms/nsGfxRadioControlFrame.cpp | 5 +++++ mozilla/layout/forms/nsListControlFrame.cpp | 5 +++++ .../layout/html/forms/src/nsFileControlFrame.cpp | 14 +++++++++++--- .../html/forms/src/nsGfxCheckboxControlFrame.cpp | 5 +++++ .../html/forms/src/nsGfxRadioControlFrame.cpp | 5 +++++ .../html/forms/src/nsGfxTextControlFrame2.cpp | 9 +++++++-- .../layout/html/forms/src/nsListControlFrame.cpp | 5 +++++ 12 files changed, 73 insertions(+), 8 deletions(-) diff --git a/mozilla/layout/build/nsLayoutCID.h b/mozilla/layout/build/nsLayoutCID.h index 7e03e06cea0..f37bfe368a9 100644 --- a/mozilla/layout/build/nsLayoutCID.h +++ b/mozilla/layout/build/nsLayoutCID.h @@ -231,4 +231,8 @@ #define NS_PLAINTEXTSERIALIZER_CID \ { 0x6030f7ef, 0x32ed, 0x46a7, { 0x9a, 0x63, 0x6a, 0x5d, 0x3f, 0x90, 0x44, 0x5f } } +// {5C5AF390-34BE-11d5-A03B-0010A4EF48C9} +#define NS_LAYOUT_HISTORY_STATE_CID \ +{ 0x5c5af390, 0x34be, 0x11d5, { 0xa0, 0x3b, 0x00, 0x10, 0xa4, 0xef, 0x48, 0xc9 } } + #endif /* nsLayoutCID_h__ */ diff --git a/mozilla/layout/build/nsLayoutFactory.cpp b/mozilla/layout/build/nsLayoutFactory.cpp index c4305fe3bd3..66adcbae94d 100644 --- a/mozilla/layout/build/nsLayoutFactory.cpp +++ b/mozilla/layout/build/nsLayoutFactory.cpp @@ -88,6 +88,7 @@ static NS_DEFINE_CID(kIFrameBoxObjectCID, NS_IFRAMEBOXOBJECT_CID); static NS_DEFINE_CID(kOutlinerBoxObjectCID, NS_OUTLINERBOXOBJECT_CID); static NS_DEFINE_CID(kAutoCopyServiceCID, NS_AUTOCOPYSERVICE_CID); +static NS_DEFINE_CID(kLayoutHistoryStateCID, NS_LAYOUT_HISTORY_STATE_CID); extern nsresult NS_NewLayoutDocumentLoaderFactory(nsIDocumentLoaderFactory** aResult); #ifdef NS_DEBUG @@ -115,6 +116,7 @@ extern nsresult NS_NewPrintContext(nsIPrintContext** aResult); extern nsresult NS_CreateFrameTraversal(nsIFrameTraversal** aResult); extern nsresult NS_CreateCSSFrameConstructor(nsICSSFrameConstructor** aResult); +extern nsresult NS_NewLayoutHistoryState(nsILayoutHistoryState** aResult); //---------------------------------------------------------------------- @@ -314,6 +316,13 @@ nsLayoutFactory::CreateInstance(nsISupports *aOuter, return res; } } + else if (mClassID.Equals(kLayoutHistoryStateCID)) { + res = NS_NewLayoutHistoryState((nsILayoutHistoryState**) &inst); + if (NS_FAILED(res)) { + LOG_NEW_FAILURE("NS_NewLayoutHistoryState", res); + return res; + } + } else { return NS_NOINTERFACE; } diff --git a/mozilla/layout/build/nsLayoutModule.cpp b/mozilla/layout/build/nsLayoutModule.cpp index 876cce33bf9..fd09fbf0ae2 100644 --- a/mozilla/layout/build/nsLayoutModule.cpp +++ b/mozilla/layout/build/nsLayoutModule.cpp @@ -324,6 +324,7 @@ static Components gComponents[] = { { "CSS Frame Constructor", NS_CSSFRAMECONSTRUCTOR_CID, nsnull, }, { "Frame Traversal", NS_FRAMETRAVERSAL_CID, nsnull, }, + { "Layout History State", NS_LAYOUT_HISTORY_STATE_CID, nsnull, }, // XXX ick { "Presentation shell", NS_PRESSHELL_CID, nsnull, }, diff --git a/mozilla/layout/forms/nsFileControlFrame.cpp b/mozilla/layout/forms/nsFileControlFrame.cpp index 02bbab90c03..106f78883ab 100644 --- a/mozilla/layout/forms/nsFileControlFrame.cpp +++ b/mozilla/layout/forms/nsFileControlFrame.cpp @@ -655,12 +655,15 @@ NS_IMETHODIMP nsFileControlFrame::SetProperty(nsIPresContext* aPresContext, NS_IMETHODIMP nsFileControlFrame::GetProperty(nsIAtom* aName, nsAWritableString& aValue) { - // Return the value of the property from the widget it is not null. - // If widget is null, assume the widget is GFX-rendered and return a member variable instead. + aValue.Truncate(); // initialize out param if (nsHTMLAtoms::value == aName) { - if (mTextFrame) + if (mTextFrame) { mTextFrame->GetTextControlFrameState(aValue); + } + else if (mCachedState) { + aValue.Assign(*mCachedState); + } } return NS_OK; } @@ -699,6 +702,11 @@ nsFileControlFrame::SaveState(nsIPresContext* aPresContext, nsIPresState** aStat { NS_ENSURE_ARG_POINTER(aState); + // Don't save state before we are initialized + if (!mTextFrame && !mCachedState) { + return NS_OK; + } + // Get the value string nsAutoString stateString; nsresult res = GetProperty(nsHTMLAtoms::value, stateString); diff --git a/mozilla/layout/forms/nsGfxCheckboxControlFrame.cpp b/mozilla/layout/forms/nsGfxCheckboxControlFrame.cpp index 00338960e6a..2bf12e04fc0 100644 --- a/mozilla/layout/forms/nsGfxCheckboxControlFrame.cpp +++ b/mozilla/layout/forms/nsGfxCheckboxControlFrame.cpp @@ -626,6 +626,11 @@ NS_IMETHODIMP nsGfxCheckboxControlFrame::SaveState(nsIPresContext* aPresContext, { NS_ENSURE_ARG_POINTER(aState); + // Don't save state before we are initialized + if (!mDidInit) { + return NS_OK; + } + CheckState stateCheck = GetCheckboxState(); PRBool defaultStateBool = PR_FALSE; nsresult res = GetDefaultCheckState(&defaultStateBool); diff --git a/mozilla/layout/forms/nsGfxRadioControlFrame.cpp b/mozilla/layout/forms/nsGfxRadioControlFrame.cpp index 99d09cd02a5..3662fc1026f 100644 --- a/mozilla/layout/forms/nsGfxRadioControlFrame.cpp +++ b/mozilla/layout/forms/nsGfxRadioControlFrame.cpp @@ -389,6 +389,11 @@ nsGfxRadioControlFrame::SaveState(nsIPresContext* aPresContext, nsIPresState** a { NS_ENSURE_ARG_POINTER(aState); + // Don't save state before we are initialized + if (!mDidInit) { + return NS_OK; + } + nsresult res = NS_OK; PRBool stateBool = GetRadioState(); PRBool defaultStateBool = GetDefaultChecked(); diff --git a/mozilla/layout/forms/nsListControlFrame.cpp b/mozilla/layout/forms/nsListControlFrame.cpp index 54f2d4a86df..4eed2c46566 100644 --- a/mozilla/layout/forms/nsListControlFrame.cpp +++ b/mozilla/layout/forms/nsListControlFrame.cpp @@ -3983,6 +3983,11 @@ nsListControlFrame::GetStateType(nsIPresContext* aPresContext, NS_IMETHODIMP nsListControlFrame::SaveStateInternal(nsIPresContext* aPresContext, nsIPresState** aState) { + // Don't save state before we are initialized + if (!mHasBeenInitialized) { + return NS_OK; + } + PRBool saveState = PR_FALSE; nsresult res = NS_OK; diff --git a/mozilla/layout/html/forms/src/nsFileControlFrame.cpp b/mozilla/layout/html/forms/src/nsFileControlFrame.cpp index 02bbab90c03..106f78883ab 100644 --- a/mozilla/layout/html/forms/src/nsFileControlFrame.cpp +++ b/mozilla/layout/html/forms/src/nsFileControlFrame.cpp @@ -655,12 +655,15 @@ NS_IMETHODIMP nsFileControlFrame::SetProperty(nsIPresContext* aPresContext, NS_IMETHODIMP nsFileControlFrame::GetProperty(nsIAtom* aName, nsAWritableString& aValue) { - // Return the value of the property from the widget it is not null. - // If widget is null, assume the widget is GFX-rendered and return a member variable instead. + aValue.Truncate(); // initialize out param if (nsHTMLAtoms::value == aName) { - if (mTextFrame) + if (mTextFrame) { mTextFrame->GetTextControlFrameState(aValue); + } + else if (mCachedState) { + aValue.Assign(*mCachedState); + } } return NS_OK; } @@ -699,6 +702,11 @@ nsFileControlFrame::SaveState(nsIPresContext* aPresContext, nsIPresState** aStat { NS_ENSURE_ARG_POINTER(aState); + // Don't save state before we are initialized + if (!mTextFrame && !mCachedState) { + return NS_OK; + } + // Get the value string nsAutoString stateString; nsresult res = GetProperty(nsHTMLAtoms::value, stateString); diff --git a/mozilla/layout/html/forms/src/nsGfxCheckboxControlFrame.cpp b/mozilla/layout/html/forms/src/nsGfxCheckboxControlFrame.cpp index 00338960e6a..2bf12e04fc0 100644 --- a/mozilla/layout/html/forms/src/nsGfxCheckboxControlFrame.cpp +++ b/mozilla/layout/html/forms/src/nsGfxCheckboxControlFrame.cpp @@ -626,6 +626,11 @@ NS_IMETHODIMP nsGfxCheckboxControlFrame::SaveState(nsIPresContext* aPresContext, { NS_ENSURE_ARG_POINTER(aState); + // Don't save state before we are initialized + if (!mDidInit) { + return NS_OK; + } + CheckState stateCheck = GetCheckboxState(); PRBool defaultStateBool = PR_FALSE; nsresult res = GetDefaultCheckState(&defaultStateBool); diff --git a/mozilla/layout/html/forms/src/nsGfxRadioControlFrame.cpp b/mozilla/layout/html/forms/src/nsGfxRadioControlFrame.cpp index 99d09cd02a5..3662fc1026f 100644 --- a/mozilla/layout/html/forms/src/nsGfxRadioControlFrame.cpp +++ b/mozilla/layout/html/forms/src/nsGfxRadioControlFrame.cpp @@ -389,6 +389,11 @@ nsGfxRadioControlFrame::SaveState(nsIPresContext* aPresContext, nsIPresState** a { NS_ENSURE_ARG_POINTER(aState); + // Don't save state before we are initialized + if (!mDidInit) { + return NS_OK; + } + nsresult res = NS_OK; PRBool stateBool = GetRadioState(); PRBool defaultStateBool = GetDefaultChecked(); diff --git a/mozilla/layout/html/forms/src/nsGfxTextControlFrame2.cpp b/mozilla/layout/html/forms/src/nsGfxTextControlFrame2.cpp index b78431bf68e..eb496054ea4 100644 --- a/mozilla/layout/html/forms/src/nsGfxTextControlFrame2.cpp +++ b/mozilla/layout/html/forms/src/nsGfxTextControlFrame2.cpp @@ -3087,7 +3087,7 @@ nsGfxTextControlFrame2::InvalidateCachedState() void nsGfxTextControlFrame2::GetTextControlFrameState(nsAWritableString& aValue) { - aValue.SetLength(0); // initialize out param + aValue.Truncate(); // initialize out param if (mEditor && mUseEditor) { @@ -3110,7 +3110,7 @@ void nsGfxTextControlFrame2::GetTextControlFrameState(nsAWritableString& aValue) mEditor->OutputToString(aValue, NS_LITERAL_STRING("text/plain"), flags); } - else if (mCachedState && mCachedState->Length() > 0) + else if (mCachedState) aValue.Assign(*mCachedState); } @@ -3303,6 +3303,11 @@ nsGfxTextControlFrame2::SaveState(nsIPresContext* aPresContext, nsIPresState** a { NS_ENSURE_ARG_POINTER(aState); + // Don't save state before we are initialized + if (!mUseEditor) { + return NS_OK; + } + // Get the value string nsString stateString; nsresult res = GetProperty(nsHTMLAtoms::value, stateString); diff --git a/mozilla/layout/html/forms/src/nsListControlFrame.cpp b/mozilla/layout/html/forms/src/nsListControlFrame.cpp index 54f2d4a86df..4eed2c46566 100644 --- a/mozilla/layout/html/forms/src/nsListControlFrame.cpp +++ b/mozilla/layout/html/forms/src/nsListControlFrame.cpp @@ -3983,6 +3983,11 @@ nsListControlFrame::GetStateType(nsIPresContext* aPresContext, NS_IMETHODIMP nsListControlFrame::SaveStateInternal(nsIPresContext* aPresContext, nsIPresState** aState) { + // Don't save state before we are initialized + if (!mHasBeenInitialized) { + return NS_OK; + } + PRBool saveState = PR_FALSE; nsresult res = NS_OK;