From 5609eaece759bde097cd3bd22f71810c85c7d421 Mon Sep 17 00:00:00 2001 From: "rods%netscape.com" Date: Tue, 15 Feb 2000 15:05:56 +0000 Subject: [PATCH] They now cache their state properly in the PresState b 27063 r=kmmclusk git-svn-id: svn://10.0.0.236/trunk@60882 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/layout/forms/nsFormControlHelper.h | 2 +- .../layout/forms/nsGfxRadioControlFrame.cpp | 26 ++++++++---- mozilla/layout/forms/nsGfxRadioControlFrame.h | 12 ++++-- .../html/forms/src/nsFormControlHelper.h | 2 +- mozilla/layout/html/forms/src/nsFormFrame.cpp | 42 ++++++++++++------- .../html/forms/src/nsGfxListControlFrame.h | 4 +- .../html/forms/src/nsGfxRadioControlFrame.cpp | 26 ++++++++---- .../html/forms/src/nsGfxRadioControlFrame.h | 12 ++++-- 8 files changed, 87 insertions(+), 39 deletions(-) diff --git a/mozilla/layout/forms/nsFormControlHelper.h b/mozilla/layout/forms/nsFormControlHelper.h index 5effe7fcb12..d927ad7382c 100644 --- a/mozilla/layout/forms/nsFormControlHelper.h +++ b/mozilla/layout/forms/nsFormControlHelper.h @@ -186,7 +186,7 @@ public: * @returns NS_OK or NS_CONTENT_ATTR_HAS_VALUE */ - nsresult GetCurrentCheckState(PRBool* aState); + //nsresult GetCurrentCheckState(PRBool* aState); /** * Set the state of the checked attribute. diff --git a/mozilla/layout/forms/nsGfxRadioControlFrame.cpp b/mozilla/layout/forms/nsGfxRadioControlFrame.cpp index e005f53b162..0b83d4c002c 100644 --- a/mozilla/layout/forms/nsGfxRadioControlFrame.cpp +++ b/mozilla/layout/forms/nsGfxRadioControlFrame.cpp @@ -156,15 +156,19 @@ NS_IMETHODIMP nsGfxRadioControlFrame::GetProperty(nsIAtom* aName, nsString& aVal //-------------------------------------------------------------- PRBool -nsGfxRadioControlFrame::GetChecked(PRBool aGetInitialValue) +nsGfxRadioControlFrame::GetChecked() { PRBool checked = PR_FALSE; - if (PR_TRUE == aGetInitialValue) { - GetDefaultCheckState(&checked); - } - else { - GetCurrentCheckState(&checked); - } + GetDefaultCheckState(&checked); + return(checked); +} + +//-------------------------------------------------------------- +PRBool +nsGfxRadioControlFrame::GetDefaultChecked() +{ + PRBool checked = PR_FALSE; + GetCurrentCheckState(&checked); return(checked); } @@ -350,10 +354,16 @@ nsGfxRadioControlFrame::RestoreState(nsIPresContext* aPresContext, nsIPresState* InitializeControl(aPresContext); mDidInit = PR_TRUE; } + + mIsRestored = PR_TRUE; nsAutoString string; aState->GetStateProperty("checked", string); PRBool state = (string == NS_STRING_TRUE) ? PR_TRUE : PR_FALSE; - SetRadioState(aPresContext, state); + + SetRadioState(aPresContext, state); // sets mChecked + mRestoredChecked = mChecked; + + return NS_OK; } diff --git a/mozilla/layout/forms/nsGfxRadioControlFrame.h b/mozilla/layout/forms/nsGfxRadioControlFrame.h index e40ab27e3f8..0ad05abb4e1 100644 --- a/mozilla/layout/forms/nsGfxRadioControlFrame.h +++ b/mozilla/layout/forms/nsGfxRadioControlFrame.h @@ -48,7 +48,11 @@ public: NS_IMETHOD SetRadioButtonFaceStyleContext(nsIStyleContext *aRadioButtonFaceStyleContext); - virtual PRBool GetChecked(PRBool aGetInitialValue); + virtual PRBool GetChecked(); + virtual PRBool GetDefaultChecked(); + virtual PRBool GetRestoredChecked() { return mRestoredChecked;} + virtual PRBool IsRestored() { return mIsRestored;} + virtual void SetChecked(nsIPresContext* aPresContext, PRBool aValue, PRBool aSetInitialValue); void InitializeControl(nsIPresContext* aPresContext); @@ -107,8 +111,10 @@ protected: virtual void SetRadioState(nsIPresContext* aPresContext, PRBool aValue); //GFX-rendered state variables - PRBool mChecked; - nsIStyleContext* mRadioButtonFaceStyle; + PRBool mChecked; + nsIStyleContext* mRadioButtonFaceStyle; + PRBool mRestoredChecked; + PRBool mIsRestored; private: NS_IMETHOD_(nsrefcnt) AddRef() { return NS_OK; } diff --git a/mozilla/layout/html/forms/src/nsFormControlHelper.h b/mozilla/layout/html/forms/src/nsFormControlHelper.h index 5effe7fcb12..d927ad7382c 100644 --- a/mozilla/layout/html/forms/src/nsFormControlHelper.h +++ b/mozilla/layout/html/forms/src/nsFormControlHelper.h @@ -186,7 +186,7 @@ public: * @returns NS_OK or NS_CONTENT_ATTR_HAS_VALUE */ - nsresult GetCurrentCheckState(PRBool* aState); + //nsresult GetCurrentCheckState(PRBool* aState); /** * Set the state of the checked attribute. diff --git a/mozilla/layout/html/forms/src/nsFormFrame.cpp b/mozilla/layout/html/forms/src/nsFormFrame.cpp index 2ae1d489b7a..66ac150915c 100644 --- a/mozilla/layout/html/forms/src/nsFormFrame.cpp +++ b/mozilla/layout/html/forms/src/nsFormFrame.cpp @@ -316,8 +316,8 @@ void nsFormFrame::AddFormControlFrame(nsIPresContext* aPresContext, nsIFrame& aF nsFormFrame* formFrame = nsnull; result = presShell->GetPrimaryFrameFor(formContent, (nsIFrame**)&formFrame); if (NS_SUCCEEDED(result) && formFrame) { - formFrame->AddFormControlFrame(aPresContext, *fcFrame); fcFrame->SetFormFrame(formFrame); + formFrame->AddFormControlFrame(aPresContext, *fcFrame); } NS_RELEASE(formContent); } @@ -339,8 +339,6 @@ nsFormFrame::RemoveFrame(nsIPresContext* aPresContext, nsIAtom* aListName, nsIFrame* aOldFrame) { - nsresult rv = NS_OK; - nsIFormControlFrame* fcFrame = nsnull; nsresult result = aOldFrame->QueryInterface(kIFormControlFrameIID, (void**)&fcFrame); if ((NS_OK == result) || (nsnull != fcFrame)) { @@ -389,7 +387,7 @@ void nsFormFrame::DoDefaultSelection(nsIPresContext* aPresContext, nsRadioControlGroup * aGroup, nsGfxRadioControlFrame * aRadioToIgnore) { -#if 0 +#if 1 // If in standard mode, then a radio group MUST default // to the first item in the group (it must be selected) nsCompatibility mode; @@ -398,19 +396,29 @@ void nsFormFrame::DoDefaultSelection(nsIPresContext* aPresContext, // first find out if any have a default selection PRInt32 i; PRInt32 numItems = aGroup->GetNumRadios(); - PRBool changed = PR_FALSE; PRBool oneIsDefSelected = PR_FALSE; - for (i=0;iGetRadioAt(i); nsCOMPtr content; radioBtn->GetContent(getter_AddRefs(content)); if (content) { nsCOMPtr input(do_QueryInterface(content)); if (input) { - input->GetDefaultChecked(&oneIsDefSelected); - PRBool currentValue = radioBtn->GetChecked(PR_FALSE); - if (currentValue != oneIsDefSelected) { - changed = PR_TRUE; + PRBool initiallyChecked = PR_FALSE; + if (radioBtn->IsRestored()) { + initiallyChecked = radioBtn->GetRestoredChecked(); + } else { + initiallyChecked = radioBtn->GetDefaultChecked(); + } + + PRBool isRestored = radioBtn->IsRestored(); + PRBool currentValue = radioBtn->GetChecked(); + if (currentValue != initiallyChecked ) { + input->SetChecked(initiallyChecked); + //radioBtn->SetChecked(aPresContext, initSelected, PR_FALSE); + } + if (initiallyChecked) { + oneIsDefSelected = PR_TRUE; } } } @@ -420,7 +428,7 @@ void nsFormFrame::DoDefaultSelection(nsIPresContext* aPresContext, // select the firdst one in the group. // if aRadioToIgnore is not null then it is being deleted // so don't select that item, select the next one if there is one. - if (!changed && !oneIsDefSelected && numItems > 0) { + if (!oneIsDefSelected && numItems > 0) { nsGfxRadioControlFrame * radioBtn = (nsGfxRadioControlFrame*) aGroup->GetRadioAt(0); if (aRadioToIgnore != nsnull && aRadioToIgnore == radioBtn) { if (numItems == 1) { @@ -434,7 +442,7 @@ void nsFormFrame::DoDefaultSelection(nsIPresContext* aPresContext, nsCOMPtr input(do_QueryInterface(content)); if (input) { input->SetChecked(PR_TRUE); - OnRadioChecked(aPresContext, *radioBtn, PR_TRUE); + //OnRadioChecked(aPresContext, *radioBtn, PR_TRUE); } } } @@ -478,11 +486,17 @@ void nsFormFrame::AddFormControlFrame(nsIPresContext* aPresContext, nsIFormContr group->AddRadio(radioFrame); } // allow only one checked radio button - if (radioFrame->GetChecked(PR_TRUE)) { + PRBool initiallyChecked = PR_FALSE; + if (radioFrame->IsRestored()) { + initiallyChecked = radioFrame->GetRestoredChecked(); + } else { + initiallyChecked = radioFrame->GetDefaultChecked(); + } + if (initiallyChecked) { if (nsnull == group->GetCheckedRadio()) { group->SetCheckedRadio(radioFrame); } else { - radioFrame->SetChecked(aPresContext, PR_FALSE, PR_TRUE); + radioFrame->SetChecked(aPresContext, PR_FALSE, PR_FALSE); } } DoDefaultSelection(aPresContext, group); diff --git a/mozilla/layout/html/forms/src/nsGfxListControlFrame.h b/mozilla/layout/html/forms/src/nsGfxListControlFrame.h index 927e75bf52f..26c8e67a727 100644 --- a/mozilla/layout/html/forms/src/nsGfxListControlFrame.h +++ b/mozilla/layout/html/forms/src/nsGfxListControlFrame.h @@ -31,6 +31,7 @@ #include "nsIStatefulFrame.h" #include "nsHTMLContainerFrame.h" +#include "nsIPresState.h" class nsIDOMHTMLSelectElement; class nsIDOMHTMLCollection; @@ -38,7 +39,6 @@ class nsIDOMHTMLOptionElement; class nsIComboboxControlFrame; class nsIViewManager; class nsIPresContext; -class nsIPresState; /** * Frame-based listbox. @@ -125,6 +125,7 @@ public: NS_IMETHOD AboutToDropDown(); NS_IMETHOD AboutToRollup(); NS_IMETHOD UpdateSelection(PRBool aDoDispatchEvent, PRBool aForceUpdate, nsIContent* aContent); + NS_IMETHOD SetPresState(nsIPresState * aState) { mPresState = aState; return NS_OK;} // nsISelectControlFrame NS_IMETHOD AddOption(nsIPresContext* aPresContext, PRInt32 index); @@ -244,6 +245,7 @@ protected: PRBool mHasBeenInitialized; nsIPresContext* mPresContext; // XXX: Remove the need to cache the pres context. + nsCOMPtr mPresState; // Need cache state when list is null // XXX temprary only until full system mouse capture works PRBool mIsScrollbarVisible; diff --git a/mozilla/layout/html/forms/src/nsGfxRadioControlFrame.cpp b/mozilla/layout/html/forms/src/nsGfxRadioControlFrame.cpp index e005f53b162..0b83d4c002c 100644 --- a/mozilla/layout/html/forms/src/nsGfxRadioControlFrame.cpp +++ b/mozilla/layout/html/forms/src/nsGfxRadioControlFrame.cpp @@ -156,15 +156,19 @@ NS_IMETHODIMP nsGfxRadioControlFrame::GetProperty(nsIAtom* aName, nsString& aVal //-------------------------------------------------------------- PRBool -nsGfxRadioControlFrame::GetChecked(PRBool aGetInitialValue) +nsGfxRadioControlFrame::GetChecked() { PRBool checked = PR_FALSE; - if (PR_TRUE == aGetInitialValue) { - GetDefaultCheckState(&checked); - } - else { - GetCurrentCheckState(&checked); - } + GetDefaultCheckState(&checked); + return(checked); +} + +//-------------------------------------------------------------- +PRBool +nsGfxRadioControlFrame::GetDefaultChecked() +{ + PRBool checked = PR_FALSE; + GetCurrentCheckState(&checked); return(checked); } @@ -350,10 +354,16 @@ nsGfxRadioControlFrame::RestoreState(nsIPresContext* aPresContext, nsIPresState* InitializeControl(aPresContext); mDidInit = PR_TRUE; } + + mIsRestored = PR_TRUE; nsAutoString string; aState->GetStateProperty("checked", string); PRBool state = (string == NS_STRING_TRUE) ? PR_TRUE : PR_FALSE; - SetRadioState(aPresContext, state); + + SetRadioState(aPresContext, state); // sets mChecked + mRestoredChecked = mChecked; + + return NS_OK; } diff --git a/mozilla/layout/html/forms/src/nsGfxRadioControlFrame.h b/mozilla/layout/html/forms/src/nsGfxRadioControlFrame.h index e40ab27e3f8..0ad05abb4e1 100644 --- a/mozilla/layout/html/forms/src/nsGfxRadioControlFrame.h +++ b/mozilla/layout/html/forms/src/nsGfxRadioControlFrame.h @@ -48,7 +48,11 @@ public: NS_IMETHOD SetRadioButtonFaceStyleContext(nsIStyleContext *aRadioButtonFaceStyleContext); - virtual PRBool GetChecked(PRBool aGetInitialValue); + virtual PRBool GetChecked(); + virtual PRBool GetDefaultChecked(); + virtual PRBool GetRestoredChecked() { return mRestoredChecked;} + virtual PRBool IsRestored() { return mIsRestored;} + virtual void SetChecked(nsIPresContext* aPresContext, PRBool aValue, PRBool aSetInitialValue); void InitializeControl(nsIPresContext* aPresContext); @@ -107,8 +111,10 @@ protected: virtual void SetRadioState(nsIPresContext* aPresContext, PRBool aValue); //GFX-rendered state variables - PRBool mChecked; - nsIStyleContext* mRadioButtonFaceStyle; + PRBool mChecked; + nsIStyleContext* mRadioButtonFaceStyle; + PRBool mRestoredChecked; + PRBool mIsRestored; private: NS_IMETHOD_(nsrefcnt) AddRef() { return NS_OK; }