зеркало из https://github.com/mozilla/pjs.git
Implemented GetChecked and SetChecked for nsHTMLInputElement by going through
the nsCheckboxControlFrame and nsRadioControlFrame.cpp
This commit is contained in:
Родитель
2013dcecb1
Коммит
208e63a001
|
@ -360,23 +360,35 @@ nsHTMLInputElement::SetValue(const nsString& aValue)
|
|||
NS_IMETHODIMP
|
||||
nsHTMLInputElement::GetChecked(PRBool* aValue)
|
||||
{
|
||||
nsString val;
|
||||
nsresult rv = mInner.GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::checked, val);
|
||||
*aValue = (NS_CONTENT_ATTR_NOT_THERE != rv);
|
||||
return NS_OK;
|
||||
nsIFormControlFrame* formControlFrame = nsnull;
|
||||
if (NS_OK == GetPrimaryFrame(formControlFrame)) {
|
||||
nsString value("0");
|
||||
formControlFrame->GetProperty(nsHTMLAtoms::checked, value);
|
||||
if (value == "1")
|
||||
*aValue = PR_TRUE;
|
||||
else
|
||||
*aValue = PR_FALSE;
|
||||
|
||||
NS_RELEASE(formControlFrame);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLInputElement::SetChecked(PRBool aValue)
|
||||
{
|
||||
nsAutoString empty;
|
||||
if (aValue) {
|
||||
return mInner.SetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::checked, empty, PR_TRUE);
|
||||
} else {
|
||||
mInner.UnsetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::checked, PR_TRUE);
|
||||
return NS_OK;
|
||||
}
|
||||
nsIFormControlFrame* formControlFrame = nsnull;
|
||||
if (NS_OK == GetPrimaryFrame(formControlFrame)) {
|
||||
if (PR_TRUE == aValue) {
|
||||
formControlFrame->SetProperty(nsHTMLAtoms::checked, "1");
|
||||
}
|
||||
else {
|
||||
formControlFrame->SetProperty(nsHTMLAtoms::checked, "0");
|
||||
}
|
||||
NS_RELEASE(formControlFrame);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
|
|
@ -360,23 +360,35 @@ nsHTMLInputElement::SetValue(const nsString& aValue)
|
|||
NS_IMETHODIMP
|
||||
nsHTMLInputElement::GetChecked(PRBool* aValue)
|
||||
{
|
||||
nsString val;
|
||||
nsresult rv = mInner.GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::checked, val);
|
||||
*aValue = (NS_CONTENT_ATTR_NOT_THERE != rv);
|
||||
return NS_OK;
|
||||
nsIFormControlFrame* formControlFrame = nsnull;
|
||||
if (NS_OK == GetPrimaryFrame(formControlFrame)) {
|
||||
nsString value("0");
|
||||
formControlFrame->GetProperty(nsHTMLAtoms::checked, value);
|
||||
if (value == "1")
|
||||
*aValue = PR_TRUE;
|
||||
else
|
||||
*aValue = PR_FALSE;
|
||||
|
||||
NS_RELEASE(formControlFrame);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLInputElement::SetChecked(PRBool aValue)
|
||||
{
|
||||
nsAutoString empty;
|
||||
if (aValue) {
|
||||
return mInner.SetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::checked, empty, PR_TRUE);
|
||||
} else {
|
||||
mInner.UnsetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::checked, PR_TRUE);
|
||||
return NS_OK;
|
||||
}
|
||||
nsIFormControlFrame* formControlFrame = nsnull;
|
||||
if (NS_OK == GetPrimaryFrame(formControlFrame)) {
|
||||
if (PR_TRUE == aValue) {
|
||||
formControlFrame->SetProperty(nsHTMLAtoms::checked, "1");
|
||||
}
|
||||
else {
|
||||
formControlFrame->SetProperty(nsHTMLAtoms::checked, "0");
|
||||
}
|
||||
NS_RELEASE(formControlFrame);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
|
|
@ -76,6 +76,10 @@ public:
|
|||
NS_IMETHOD SetProperty(nsIAtom* aName, const nsString& aValue);
|
||||
NS_IMETHOD GetProperty(nsIAtom* aName, nsString& aValue);
|
||||
|
||||
// Utility methods for implementing SetProperty/GetProperty
|
||||
void SetCheckboxControlFrameState(const nsString& aValue);
|
||||
void GetCheckboxControlFrameState(nsString& aValue);
|
||||
|
||||
//
|
||||
// Methods used to GFX-render the checkbox
|
||||
//
|
||||
|
@ -155,23 +159,20 @@ nsCheckboxControlFrame::GetDesiredSize(nsIPresContext* aPresContext,
|
|||
void
|
||||
nsCheckboxControlFrame::PostCreateWidget(nsIPresContext* aPresContext, nscoord& aWidth, nscoord& aHeight)
|
||||
{
|
||||
if (!mWidget) {
|
||||
return;
|
||||
// set the widget to the initial state
|
||||
PRBool checked = PR_FALSE;
|
||||
nsresult result = GetDefaultCheckState(&checked);
|
||||
if (NS_CONTENT_ATTR_HAS_VALUE == result) {
|
||||
if (PR_TRUE == checked)
|
||||
SetProperty(nsHTMLAtoms::checked, "1");
|
||||
else
|
||||
SetProperty(nsHTMLAtoms::checked, "0");
|
||||
}
|
||||
|
||||
SetColors(*aPresContext);
|
||||
mWidget->Enable(!nsFormFrame::GetDisabled(this));
|
||||
|
||||
// set the widget to the initial state
|
||||
nsICheckButton* checkbox = nsnull;
|
||||
if (NS_OK == mWidget->QueryInterface(GetIID(),(void**)&checkbox)) {
|
||||
PRBool checked;
|
||||
nsresult result = GetCurrentCheckState(&checked);
|
||||
if (NS_CONTENT_ATTR_HAS_VALUE == result) {
|
||||
checkbox->SetState(checked);
|
||||
}
|
||||
NS_RELEASE(checkbox);
|
||||
}
|
||||
if (mWidget != nsnull) {
|
||||
SetColors(*aPresContext);
|
||||
mWidget->Enable(!nsFormFrame::GetDisabled(this));
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
@ -368,14 +369,73 @@ NS_METHOD nsCheckboxControlFrame::HandleEvent(nsIPresContext& aPresContext,
|
|||
return(nsFormControlFrame::HandleEvent(aPresContext, aEvent, aEventStatus));
|
||||
}
|
||||
|
||||
|
||||
void nsCheckboxControlFrame::GetCheckboxControlFrameState(nsString& aValue)
|
||||
{
|
||||
if (nsnull != mWidget) {
|
||||
nsICheckButton* checkBox = nsnull;
|
||||
if (NS_OK == mWidget->QueryInterface(kICheckButtonIID,(void**)&checkBox)) {
|
||||
PRBool state = PR_FALSE;
|
||||
checkBox->GetState(state);
|
||||
if (PR_TRUE == state)
|
||||
aValue = "1";
|
||||
else
|
||||
aValue = "0";
|
||||
NS_RELEASE(checkBox);
|
||||
}
|
||||
else {
|
||||
//XXX: This should return the local field for GFX-rendered widgets
|
||||
aValue = "0";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void nsCheckboxControlFrame::SetCheckboxControlFrameState(const nsString& aValue)
|
||||
{
|
||||
if (nsnull != mWidget) {
|
||||
nsICheckButton* checkBox = nsnull;
|
||||
if (NS_OK == mWidget->QueryInterface(kICheckButtonIID,(void**)&checkBox)) {
|
||||
PRBool state = PR_FALSE;
|
||||
if (aValue == "1")
|
||||
checkBox->SetState(PR_TRUE);
|
||||
else
|
||||
checkBox->SetState(PR_FALSE);
|
||||
|
||||
NS_RELEASE(checkBox);
|
||||
}
|
||||
else {
|
||||
//XXX: This should set he local field for GFX-rendered widgets
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsCheckboxControlFrame::SetProperty(nsIAtom* aName, const nsString& aValue)
|
||||
{
|
||||
return NS_OK;
|
||||
if (nsHTMLAtoms::checked == aName) {
|
||||
SetCheckboxControlFrameState(aValue);
|
||||
}
|
||||
else {
|
||||
return nsFormControlFrame::SetProperty(aName, aValue);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsCheckboxControlFrame::GetProperty(nsIAtom* aName, nsString& aValue)
|
||||
{
|
||||
return NS_OK;
|
||||
// Return the value of the property from the widget it is not null.
|
||||
// If is null, assume the widget is GFX-rendered and return a member variable instead.
|
||||
|
||||
if (nsHTMLAtoms::checked == aName) {
|
||||
GetCheckboxControlFrameState(aValue);
|
||||
}
|
||||
else {
|
||||
return nsFormControlFrame::GetProperty(aName, aValue);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -89,23 +89,28 @@ nsRadioControlFrame::GetDesiredSize(nsIPresContext* aPresContext,
|
|||
void
|
||||
nsRadioControlFrame::PostCreateWidget(nsIPresContext* aPresContext, nscoord& aWidth, nscoord& aHeight)
|
||||
{
|
||||
nsIRadioButton* radio = nsnull;
|
||||
if (mWidget && (NS_OK == mWidget->QueryInterface(GetIID(),(void**)&radio))) {
|
||||
PRBool checked = PR_TRUE;
|
||||
GetCurrentCheckState(&checked);
|
||||
radio->SetState(checked);
|
||||
|
||||
const nsStyleColor* color =
|
||||
nsStyleUtil::FindNonTransparentBackground(mStyleContext);
|
||||
|
||||
if (nsnull != color) {
|
||||
mWidget->SetBackgroundColor(color->mBackgroundColor);
|
||||
} else {
|
||||
mWidget->SetBackgroundColor(NS_RGB(0xFF, 0xFF, 0xFF));
|
||||
}
|
||||
NS_RELEASE(radio);
|
||||
mWidget->Enable(!nsFormFrame::GetDisabled(this));
|
||||
// set the widget to the initial state
|
||||
PRBool checked = PR_FALSE;
|
||||
nsresult result = GetDefaultCheckState(&checked);
|
||||
if (NS_CONTENT_ATTR_HAS_VALUE == result) {
|
||||
if (PR_TRUE == checked)
|
||||
SetProperty(nsHTMLAtoms::checked, "1");
|
||||
else
|
||||
SetProperty(nsHTMLAtoms::checked, "0");
|
||||
}
|
||||
|
||||
if (mWidget != nsnull) {
|
||||
const nsStyleColor* color =
|
||||
nsStyleUtil::FindNonTransparentBackground(mStyleContext);
|
||||
|
||||
if (nsnull != color) {
|
||||
mWidget->SetBackgroundColor(color->mBackgroundColor);
|
||||
} else {
|
||||
mWidget->SetBackgroundColor(NS_RGB(0xFF, 0xFF, 0xFF));
|
||||
}
|
||||
mWidget->Enable(!nsFormFrame::GetDisabled(this));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -144,20 +149,14 @@ nsRadioControlFrame::AttributeChanged(nsIPresContext* aPresContext,
|
|||
void
|
||||
nsRadioControlFrame::MouseClicked(nsIPresContext* aPresContext)
|
||||
{
|
||||
nsIRadioButton* radioWidget;
|
||||
if (mWidget && (NS_OK == mWidget->QueryInterface(kIRadioIID, (void**)&radioWidget))) {
|
||||
radioWidget->SetState(PR_TRUE);
|
||||
NS_RELEASE(radioWidget);
|
||||
}
|
||||
SetProperty(nsHTMLAtoms::checked, "1");
|
||||
|
||||
SetCurrentCheckState(PR_TRUE); // Update content model.
|
||||
|
||||
if (mFormFrame) {
|
||||
// The form frame will determine which radio button needs
|
||||
// to be turned off and will call SetChecked on the
|
||||
// to be turned off and will call SetChecked on the
|
||||
// nsRadioControlFrame to unset the checked state
|
||||
mFormFrame->OnRadioChecked(*this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PRBool
|
||||
|
@ -178,11 +177,11 @@ nsRadioControlFrame::SetChecked(PRBool aValue, PRBool aSetInitialValue)
|
|||
mContent->SetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::checked, nsAutoString("0"), PR_FALSE);
|
||||
}
|
||||
}
|
||||
nsIRadioButton* radio = nsnull;
|
||||
if (mWidget && (NS_OK == mWidget->QueryInterface(kIRadioIID,(void**)&radio))) {
|
||||
radio->SetState(aValue);
|
||||
NS_RELEASE(radio);
|
||||
}
|
||||
|
||||
if (PR_TRUE == aValue)
|
||||
SetProperty(nsHTMLAtoms::checked, "1");
|
||||
else
|
||||
SetProperty(nsHTMLAtoms::checked, "0");
|
||||
}
|
||||
|
||||
|
||||
|
@ -344,13 +343,69 @@ nsRadioControlFrame::Paint(nsIPresContext& aPresContext,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
void nsRadioControlFrame::GetRadioControlFrameState(nsString& aValue)
|
||||
{
|
||||
if (nsnull != mWidget) {
|
||||
nsIRadioButton* radio = nsnull;
|
||||
if (NS_OK == mWidget->QueryInterface(kIRadioIID,(void**)&radio)) {
|
||||
PRBool state = PR_FALSE;
|
||||
radio->GetState(state);
|
||||
if (PR_TRUE == state)
|
||||
aValue = "1";
|
||||
else
|
||||
aValue = "0";
|
||||
NS_RELEASE(radio);
|
||||
}
|
||||
else {
|
||||
//XXX: This should return the local field for GFX-rendered widgets
|
||||
aValue = "0";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void nsRadioControlFrame::SetRadioControlFrameState(const nsString& aValue)
|
||||
{
|
||||
if (nsnull != mWidget) {
|
||||
nsIRadioButton* radio = nsnull;
|
||||
if (NS_OK == mWidget->QueryInterface(kIRadioIID,(void**)&radio)) {
|
||||
PRBool state = PR_FALSE;
|
||||
if (aValue == "1")
|
||||
radio->SetState(PR_TRUE);
|
||||
else
|
||||
radio->SetState(PR_FALSE);
|
||||
|
||||
NS_RELEASE(radio);
|
||||
}
|
||||
else {
|
||||
//XXX: This should set he local field for GFX-rendered widgets
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsRadioControlFrame::SetProperty(nsIAtom* aName, const nsString& aValue)
|
||||
{
|
||||
return NS_OK;
|
||||
if (nsHTMLAtoms::checked == aName) {
|
||||
SetRadioControlFrameState(aValue);
|
||||
}
|
||||
else {
|
||||
return nsFormControlFrame::SetProperty(aName, aValue);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsRadioControlFrame::GetProperty(nsIAtom* aName, nsString& aValue)
|
||||
{
|
||||
return NS_OK;
|
||||
// Return the value of the property from the widget it is not null.
|
||||
// If is null, assume the widget is GFX-rendered and return a member variable instead.
|
||||
|
||||
if (nsHTMLAtoms::checked == aName) {
|
||||
GetRadioControlFrameState(aValue);
|
||||
}
|
||||
else {
|
||||
return nsFormControlFrame::GetProperty(aName, aValue);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -78,6 +78,10 @@ public:
|
|||
|
||||
protected:
|
||||
|
||||
// Utility methods for implementing SetProperty/GetProperty
|
||||
void SetRadioControlFrameState(const nsString& aValue);
|
||||
void GetRadioControlFrameState(nsString& aValue);
|
||||
|
||||
virtual void GetDesiredSize(nsIPresContext* aPresContext,
|
||||
const nsHTMLReflowState& aReflowState,
|
||||
nsHTMLReflowMetrics& aDesiredLayoutSize,
|
||||
|
|
Загрузка…
Ссылка в новой задаче