From c102e73bbac3ee54b22379795c573a1286293194 Mon Sep 17 00:00:00 2001 From: "bzbarsky%mit.edu" Date: Mon, 7 Jan 2002 20:37:22 +0000 Subject: [PATCH] Checkin in for John Keiser . Make checkboxes and radio buttons not fire onChange on pageload if they are checked by default. Bug 112218, r=rods, sr=jst git-svn-id: svn://10.0.0.236/trunk@111502 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/layout/forms/nsGfxCheckboxControlFrame.cpp | 10 +++++++++- mozilla/layout/forms/nsGfxRadioControlFrame.cpp | 11 +++++++++-- .../html/forms/src/nsGfxCheckboxControlFrame.cpp | 10 +++++++++- .../layout/html/forms/src/nsGfxRadioControlFrame.cpp | 11 +++++++++-- 4 files changed, 36 insertions(+), 6 deletions(-) diff --git a/mozilla/layout/forms/nsGfxCheckboxControlFrame.cpp b/mozilla/layout/forms/nsGfxCheckboxControlFrame.cpp index 5c9c8053551..7a355e46b17 100644 --- a/mozilla/layout/forms/nsGfxCheckboxControlFrame.cpp +++ b/mozilla/layout/forms/nsGfxCheckboxControlFrame.cpp @@ -313,7 +313,15 @@ nsGfxCheckboxControlFrame::InitializeControl(nsIPresContext* aPresContext) if (!primaryPresShell) return; if (presShell.get() == primaryPresShell.get()) { - nsFormControlHelper::Reset(this, aPresContext); + // Reset the value + // XXX We set the checkbox directly in the frame, because + // content fires onChange :( + PRBool checked = PR_FALSE; + nsresult rv = GetDefaultCheckState(&checked); + + if (NS_CONTENT_ATTR_HAS_VALUE == rv) { + SetCheckboxState (aPresContext, checked ? eOn : eOff ); + } } } diff --git a/mozilla/layout/forms/nsGfxRadioControlFrame.cpp b/mozilla/layout/forms/nsGfxRadioControlFrame.cpp index ec5a3fbe673..6a040ee0bee 100644 --- a/mozilla/layout/forms/nsGfxRadioControlFrame.cpp +++ b/mozilla/layout/forms/nsGfxRadioControlFrame.cpp @@ -347,7 +347,7 @@ PRBool nsGfxRadioControlFrame::GetRadioState() void nsGfxRadioControlFrame::SetRadioState(nsIPresContext* aPresContext, PRBool aValue) { mChecked = aValue; - nsFormControlHelper::ForceDrawFrame(aPresContext, this); + nsFormControlHelper::ForceDrawFrame(aPresContext, this); } void @@ -370,7 +370,14 @@ nsGfxRadioControlFrame::InitializeControl(nsIPresContext* aPresContext) if (!primaryPresShell) return; if (presShell.get() == primaryPresShell.get()) { - nsFormControlHelper::Reset(this, aPresContext); + // set the widget to the initial state + // XXX We can't use reset because radio buttons fire onChange + // from content (much to our dismay) + PRBool checked = PR_FALSE; + nsresult rv = GetDefaultCheckState(&checked); + if (NS_CONTENT_ATTR_HAS_VALUE == rv) { + SetRadioState(aPresContext, checked); + } } } diff --git a/mozilla/layout/html/forms/src/nsGfxCheckboxControlFrame.cpp b/mozilla/layout/html/forms/src/nsGfxCheckboxControlFrame.cpp index 5c9c8053551..7a355e46b17 100644 --- a/mozilla/layout/html/forms/src/nsGfxCheckboxControlFrame.cpp +++ b/mozilla/layout/html/forms/src/nsGfxCheckboxControlFrame.cpp @@ -313,7 +313,15 @@ nsGfxCheckboxControlFrame::InitializeControl(nsIPresContext* aPresContext) if (!primaryPresShell) return; if (presShell.get() == primaryPresShell.get()) { - nsFormControlHelper::Reset(this, aPresContext); + // Reset the value + // XXX We set the checkbox directly in the frame, because + // content fires onChange :( + PRBool checked = PR_FALSE; + nsresult rv = GetDefaultCheckState(&checked); + + if (NS_CONTENT_ATTR_HAS_VALUE == rv) { + SetCheckboxState (aPresContext, checked ? eOn : eOff ); + } } } diff --git a/mozilla/layout/html/forms/src/nsGfxRadioControlFrame.cpp b/mozilla/layout/html/forms/src/nsGfxRadioControlFrame.cpp index ec5a3fbe673..6a040ee0bee 100644 --- a/mozilla/layout/html/forms/src/nsGfxRadioControlFrame.cpp +++ b/mozilla/layout/html/forms/src/nsGfxRadioControlFrame.cpp @@ -347,7 +347,7 @@ PRBool nsGfxRadioControlFrame::GetRadioState() void nsGfxRadioControlFrame::SetRadioState(nsIPresContext* aPresContext, PRBool aValue) { mChecked = aValue; - nsFormControlHelper::ForceDrawFrame(aPresContext, this); + nsFormControlHelper::ForceDrawFrame(aPresContext, this); } void @@ -370,7 +370,14 @@ nsGfxRadioControlFrame::InitializeControl(nsIPresContext* aPresContext) if (!primaryPresShell) return; if (presShell.get() == primaryPresShell.get()) { - nsFormControlHelper::Reset(this, aPresContext); + // set the widget to the initial state + // XXX We can't use reset because radio buttons fire onChange + // from content (much to our dismay) + PRBool checked = PR_FALSE; + nsresult rv = GetDefaultCheckState(&checked); + if (NS_CONTENT_ATTR_HAS_VALUE == rv) { + SetRadioState(aPresContext, checked); + } } }