mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-15 06:15:43 +00:00
Bug 640978 - Various clean-ups to nsIRadioVisitor and its children. r=peterv
This commit is contained in:
parent
51d69e129d
commit
c96fc1d573
@ -6750,10 +6750,8 @@ nsDocument::WalkRadioGroup(const nsAString& aName,
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
PRBool stop = PR_FALSE;
|
||||
for (int i = 0; i < radioGroup->mRadioButtons.Count(); i++) {
|
||||
aVisitor->Visit(radioGroup->mRadioButtons[i], &stop);
|
||||
if (stop) {
|
||||
if (!aVisitor->Visit(radioGroup->mRadioButtons[i])) {
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
@ -45,8 +45,8 @@ class nsIDocument;
|
||||
|
||||
// IID for the nsIRadioControl interface
|
||||
#define NS_IRADIOVISITOR_IID \
|
||||
{ 0xd3494bd2, 0x1dd1, 0x11b2, \
|
||||
{ 0xbe, 0x86, 0xb5, 0x08, 0xc8, 0x71, 0xd7, 0xc5 } }
|
||||
{ 0xc6bed232, 0x1181, 0x4ab2, \
|
||||
{ 0xa1, 0xda, 0x55, 0xc2, 0x13, 0x6d, 0xea, 0x3d } }
|
||||
|
||||
/**
|
||||
* This interface is used for the text control frame to store its value away
|
||||
@ -62,14 +62,13 @@ public:
|
||||
* group, sequentially. (Each radio group implementor may define
|
||||
* sequentially in their own way, it just has to be the same every time.)
|
||||
* Currently all radio groups are ordered in the order they appear in the
|
||||
* document. Radio group implementors should honor the aStop parameter and
|
||||
* stop iterating over form controls when Visit() returns true there.
|
||||
* document. Radio group implementors should honor the return value of the
|
||||
* method and stop iterating if the return value is false.
|
||||
*
|
||||
* @param aRadio the radio button in question (must be nsnull and QI'able to
|
||||
* nsIRadioControlElement)
|
||||
* @param aStop whether or not to stop iterating (out-param)
|
||||
*/
|
||||
NS_IMETHOD Visit(nsIFormControl* aRadio, PRBool* aStop) = 0;
|
||||
virtual PRBool Visit(nsIFormControl* aRadio) = 0;
|
||||
};
|
||||
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(nsIRadioVisitor, NS_IRADIOVISITOR_IID)
|
||||
@ -81,7 +80,7 @@ NS_DEFINE_STATIC_IID_ACCESSOR(nsIRadioVisitor, NS_IRADIOVISITOR_IID)
|
||||
* @param aCheckedChanged the value of CheckedChanged to set on all elements
|
||||
*/
|
||||
nsresult
|
||||
NS_GetRadioSetCheckedChangedVisitor(PRBool aCheckedChanged,
|
||||
NS_GetRadioSetCheckedChangedVisitor(bool aCheckedChanged,
|
||||
nsIRadioVisitor** aVisitor);
|
||||
|
||||
/**
|
||||
@ -94,7 +93,7 @@ NS_GetRadioSetCheckedChangedVisitor(PRBool aCheckedChanged,
|
||||
* @param aExcludeElement the element
|
||||
*/
|
||||
nsresult
|
||||
NS_GetRadioGetCheckedChangedVisitor(PRBool* aCheckedChanged,
|
||||
NS_GetRadioGetCheckedChangedVisitor(bool* aCheckedChanged,
|
||||
nsIFormControl* aExcludeElement,
|
||||
nsIRadioVisitor** aVisitor);
|
||||
|
||||
|
@ -2055,8 +2055,6 @@ nsHTMLFormElement::WalkRadioGroup(const nsAString& aName,
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
PRBool stopIterating = PR_FALSE;
|
||||
|
||||
if (aName.IsEmpty()) {
|
||||
//
|
||||
// XXX If the name is empty, it's not stored in the control list. There
|
||||
@ -2071,8 +2069,7 @@ nsHTMLFormElement::WalkRadioGroup(const nsAString& aName,
|
||||
if (controlContent) {
|
||||
if (controlContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::name,
|
||||
EmptyString(), eCaseMatters)) {
|
||||
aVisitor->Visit(control, &stopIterating);
|
||||
if (stopIterating) {
|
||||
if (!aVisitor->Visit(control)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -2094,7 +2091,7 @@ nsHTMLFormElement::WalkRadioGroup(const nsAString& aName,
|
||||
nsCOMPtr<nsIFormControl> formControl(do_QueryInterface(item));
|
||||
if (formControl) {
|
||||
if (formControl->GetType() == NS_FORM_INPUT_RADIO) {
|
||||
aVisitor->Visit(formControl, &stopIterating);
|
||||
aVisitor->Visit(formControl);
|
||||
}
|
||||
} else {
|
||||
nsCOMPtr<nsIDOMNodeList> nodeList(do_QueryInterface(item));
|
||||
@ -2107,8 +2104,7 @@ nsHTMLFormElement::WalkRadioGroup(const nsAString& aName,
|
||||
nsCOMPtr<nsIFormControl> formControl(do_QueryInterface(node));
|
||||
if (formControl) {
|
||||
if (formControl->GetType() == NS_FORM_INPUT_RADIO) {
|
||||
aVisitor->Visit(formControl, &stopIterating);
|
||||
if (stopIterating) {
|
||||
if (!aVisitor->Visit(formControl)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -3417,7 +3417,7 @@ nsHTMLInputElement::AddedToRadioGroup()
|
||||
// For integrity purposes, we have to ensure that "checkedChanged" is
|
||||
// the same for this new element as for all the others in the group
|
||||
//
|
||||
PRBool checkedChanged = GET_BOOLBIT(mBitField, BF_CHECKED_CHANGED);
|
||||
bool checkedChanged = GET_BOOLBIT(mBitField, BF_CHECKED_CHANGED);
|
||||
nsCOMPtr<nsIRadioVisitor> visitor;
|
||||
nsresult rv = NS_GetRadioGetCheckedChangedVisitor(&checkedChanged, this,
|
||||
getter_AddRefs(visitor));
|
||||
@ -3581,12 +3581,10 @@ nsHTMLInputElement::VisitGroup(nsIRadioVisitor* aVisitor, PRBool aFlushContent)
|
||||
if (GetNameIfExists(name)) {
|
||||
rv = container->WalkRadioGroup(name, aVisitor, aFlushContent);
|
||||
} else {
|
||||
PRBool stop;
|
||||
aVisitor->Visit(this, &stop);
|
||||
aVisitor->Visit(this);
|
||||
}
|
||||
} else {
|
||||
PRBool stop;
|
||||
aVisitor->Visit(this, &stop);
|
||||
aVisitor->Visit(this);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
@ -4173,7 +4171,7 @@ public:
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_IMETHOD Visit(nsIFormControl* aRadio, PRBool* aStop) = 0;
|
||||
virtual PRBool Visit(nsIFormControl* aRadio) = 0;
|
||||
};
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsRadioVisitor, nsIRadioVisitor)
|
||||
@ -4184,23 +4182,23 @@ NS_IMPL_ISUPPORTS1(nsRadioVisitor, nsIRadioVisitor)
|
||||
//
|
||||
class nsRadioSetCheckedChangedVisitor : public nsRadioVisitor {
|
||||
public:
|
||||
nsRadioSetCheckedChangedVisitor(PRBool aCheckedChanged) :
|
||||
nsRadioSetCheckedChangedVisitor(bool aCheckedChanged) :
|
||||
nsRadioVisitor(), mCheckedChanged(aCheckedChanged)
|
||||
{ }
|
||||
|
||||
virtual ~nsRadioSetCheckedChangedVisitor() { }
|
||||
|
||||
NS_IMETHOD Visit(nsIFormControl* aRadio, PRBool* aStop)
|
||||
virtual PRBool Visit(nsIFormControl* aRadio)
|
||||
{
|
||||
nsRefPtr<nsHTMLInputElement> radio =
|
||||
static_cast<nsHTMLInputElement*>(aRadio);
|
||||
NS_ASSERTION(radio, "Visit() passed a null button!");
|
||||
radio->SetCheckedChangedInternal(mCheckedChanged);
|
||||
return NS_OK;
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
protected:
|
||||
PRPackedBool mCheckedChanged;
|
||||
bool mCheckedChanged;
|
||||
};
|
||||
|
||||
//
|
||||
@ -4208,7 +4206,7 @@ protected:
|
||||
//
|
||||
class nsRadioGetCheckedChangedVisitor : public nsRadioVisitor {
|
||||
public:
|
||||
nsRadioGetCheckedChangedVisitor(PRBool* aCheckedChanged,
|
||||
nsRadioGetCheckedChangedVisitor(bool* aCheckedChanged,
|
||||
nsIFormControl* aExcludeElement) :
|
||||
nsRadioVisitor(),
|
||||
mCheckedChanged(aCheckedChanged),
|
||||
@ -4217,21 +4215,20 @@ public:
|
||||
|
||||
virtual ~nsRadioGetCheckedChangedVisitor() { }
|
||||
|
||||
NS_IMETHOD Visit(nsIFormControl* aRadio, PRBool* aStop)
|
||||
virtual PRBool Visit(nsIFormControl* aRadio)
|
||||
{
|
||||
if (aRadio == mExcludeElement) {
|
||||
return NS_OK;
|
||||
return PR_TRUE;
|
||||
}
|
||||
nsRefPtr<nsHTMLInputElement> radio =
|
||||
static_cast<nsHTMLInputElement*>(aRadio);
|
||||
NS_ASSERTION(radio, "Visit() passed a null button!");
|
||||
*mCheckedChanged = radio->GetCheckedChanged();
|
||||
*aStop = PR_TRUE;
|
||||
return NS_OK;
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
protected:
|
||||
PRBool* mCheckedChanged;
|
||||
bool* mCheckedChanged;
|
||||
nsIFormControl* mExcludeElement;
|
||||
};
|
||||
|
||||
@ -4246,10 +4243,10 @@ public:
|
||||
, mNotify(aNotify)
|
||||
{ }
|
||||
|
||||
NS_IMETHOD Visit(nsIFormControl* aRadio, PRBool* aStop)
|
||||
virtual PRBool Visit(nsIFormControl* aRadio)
|
||||
{
|
||||
if (aRadio == mExcludeElement) {
|
||||
return NS_OK;
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
nsHTMLInputElement* input = static_cast<nsHTMLInputElement*>(aRadio);
|
||||
@ -4265,7 +4262,7 @@ public:
|
||||
NS_EVENT_STATE_MOZ_UI_INVALID);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
protected:
|
||||
@ -4276,7 +4273,7 @@ protected:
|
||||
};
|
||||
|
||||
nsresult
|
||||
NS_GetRadioSetCheckedChangedVisitor(PRBool aCheckedChanged,
|
||||
NS_GetRadioSetCheckedChangedVisitor(bool aCheckedChanged,
|
||||
nsIRadioVisitor** aVisitor)
|
||||
{
|
||||
//
|
||||
@ -4292,7 +4289,7 @@ NS_GetRadioSetCheckedChangedVisitor(PRBool aCheckedChanged,
|
||||
//
|
||||
if (aCheckedChanged) {
|
||||
if (!sVisitorTrue) {
|
||||
sVisitorTrue = new nsRadioSetCheckedChangedVisitor(PR_TRUE);
|
||||
sVisitorTrue = new nsRadioSetCheckedChangedVisitor(true);
|
||||
if (!sVisitorTrue) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
@ -4311,7 +4308,7 @@ NS_GetRadioSetCheckedChangedVisitor(PRBool aCheckedChanged,
|
||||
//
|
||||
else {
|
||||
if (!sVisitorFalse) {
|
||||
sVisitorFalse = new nsRadioSetCheckedChangedVisitor(PR_FALSE);
|
||||
sVisitorFalse = new nsRadioSetCheckedChangedVisitor(false);
|
||||
if (!sVisitorFalse) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
@ -4331,7 +4328,7 @@ NS_GetRadioSetCheckedChangedVisitor(PRBool aCheckedChanged,
|
||||
}
|
||||
|
||||
nsresult
|
||||
NS_GetRadioGetCheckedChangedVisitor(PRBool* aCheckedChanged,
|
||||
NS_GetRadioGetCheckedChangedVisitor(bool* aCheckedChanged,
|
||||
nsIFormControl* aExcludeElement,
|
||||
nsIRadioVisitor** aVisitor)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user