mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-30 00:01:50 +00:00
They now cache their state properly in the PresState
b 27063 r=kmmclusk
This commit is contained in:
parent
892fd0b3b5
commit
0eee3592f9
@ -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.
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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; }
|
||||
|
@ -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.
|
||||
|
@ -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;i<numItems && !oneIsDefSelected;i++) {
|
||||
for (i=0;i<numItems;i++) {
|
||||
nsGfxRadioControlFrame * radioBtn = (nsGfxRadioControlFrame*) aGroup->GetRadioAt(i);
|
||||
nsCOMPtr<nsIContent> content;
|
||||
radioBtn->GetContent(getter_AddRefs(content));
|
||||
if (content) {
|
||||
nsCOMPtr<nsIDOMHTMLInputElement> 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<nsIDOMHTMLInputElement> 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);
|
||||
|
@ -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<nsIPresState> mPresState; // Need cache state when list is null
|
||||
|
||||
// XXX temprary only until full system mouse capture works
|
||||
PRBool mIsScrollbarVisible;
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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; }
|
||||
|
Loading…
Reference in New Issue
Block a user