The script notification happens before the radiobox gets a chance to change its value

so they must return the opposite value for themselves. They don't want to actually set their
values because the script could cancel. So the idea here is to let them know before the script
call that they should return their "future" value (the opposite of their current value)
b=42972 r=kmcclusk
This commit is contained in:
rods%netscape.com 2000-08-02 22:06:37 +00:00
parent ba38e3d7d4
commit 92c1ebc132
2 changed files with 80 additions and 0 deletions

View File

@ -59,6 +59,8 @@
#include "nsIDOMEvent.h"
#include "nsIDOMNodeList.h"
#include "nsIDOMHTMLCollection.h"
#include "nsICheckboxControlFrame.h"
#include "nsIRadioControlFrame.h"
// XXX align=left, hspace, vspace, border? other nav4 attrs
@ -849,11 +851,49 @@ nsHTMLInputElement::HandleDOMEvent(nsIPresContext* aPresContext,
}
}
// When a user clicks on a checkbox the value needs to be set after the onmouseup
// and before the onclick event is processed via script. The EVM always lets script
// get first crack at the processing, and script can cancel further processing of
// the event by return null.
//
// This means the checkbox needs to have it's new value set before it goes to script
// to process the onclick and then if script cancels the event it needs to be set back.
// In Nav and IE there is a flash of it being set and then unset
//
// We have added this extra method to the checkbox to tell it to temporarily return the
// opposite value while processing the click event. This way script gets the correct "future"
// value of the checkbox, but there is no visual updating until after script is done processing.
// That way if the event is cancelled then the checkbox will not flash.
//
// So get the Frame for the checkbox and tell it we are processing an onclick event
nsIFormControlFrame* formControlFrame = nsnull;
rv = nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame, PR_FALSE);
nsCOMPtr<nsICheckboxControlFrame> chkBx;
nsCOMPtr<nsIRadioControlFrame> radio;
if (NS_SUCCEEDED(rv)) {
chkBx = do_QueryInterface(formControlFrame);
if (!chkBx) {
radio = do_QueryInterface(formControlFrame);
}
}
if (aEvent->message == NS_MOUSE_LEFT_CLICK) {
if (chkBx) chkBx->SetIsInClickEvent(PR_TRUE);
if (radio) radio->SetIsInClickEvent(PR_TRUE);
}
// Try script event handlers first if its not a focus/blur event
//we dont want the doc to get these
nsresult ret = mInner.HandleDOMEvent(aPresContext, aEvent, aDOMEvent,
aFlags, aEventStatus);
// Script is done processing, now tell the checkbox we are no longer doing an onclick
// and if it was cancelled the checkbox will get the propriate value via the DOM listener
if (aEvent->message == NS_MOUSE_LEFT_CLICK) {
if (chkBx) chkBx->SetIsInClickEvent(PR_FALSE);
if (radio) radio->SetIsInClickEvent(PR_FALSE);
}
// Finish the special file control processing...
if (type == NS_FORM_INPUT_FILE) {
// If the event is starting here that's fine. If it's not

View File

@ -59,6 +59,8 @@
#include "nsIDOMEvent.h"
#include "nsIDOMNodeList.h"
#include "nsIDOMHTMLCollection.h"
#include "nsICheckboxControlFrame.h"
#include "nsIRadioControlFrame.h"
// XXX align=left, hspace, vspace, border? other nav4 attrs
@ -849,11 +851,49 @@ nsHTMLInputElement::HandleDOMEvent(nsIPresContext* aPresContext,
}
}
// When a user clicks on a checkbox the value needs to be set after the onmouseup
// and before the onclick event is processed via script. The EVM always lets script
// get first crack at the processing, and script can cancel further processing of
// the event by return null.
//
// This means the checkbox needs to have it's new value set before it goes to script
// to process the onclick and then if script cancels the event it needs to be set back.
// In Nav and IE there is a flash of it being set and then unset
//
// We have added this extra method to the checkbox to tell it to temporarily return the
// opposite value while processing the click event. This way script gets the correct "future"
// value of the checkbox, but there is no visual updating until after script is done processing.
// That way if the event is cancelled then the checkbox will not flash.
//
// So get the Frame for the checkbox and tell it we are processing an onclick event
nsIFormControlFrame* formControlFrame = nsnull;
rv = nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame, PR_FALSE);
nsCOMPtr<nsICheckboxControlFrame> chkBx;
nsCOMPtr<nsIRadioControlFrame> radio;
if (NS_SUCCEEDED(rv)) {
chkBx = do_QueryInterface(formControlFrame);
if (!chkBx) {
radio = do_QueryInterface(formControlFrame);
}
}
if (aEvent->message == NS_MOUSE_LEFT_CLICK) {
if (chkBx) chkBx->SetIsInClickEvent(PR_TRUE);
if (radio) radio->SetIsInClickEvent(PR_TRUE);
}
// Try script event handlers first if its not a focus/blur event
//we dont want the doc to get these
nsresult ret = mInner.HandleDOMEvent(aPresContext, aEvent, aDOMEvent,
aFlags, aEventStatus);
// Script is done processing, now tell the checkbox we are no longer doing an onclick
// and if it was cancelled the checkbox will get the propriate value via the DOM listener
if (aEvent->message == NS_MOUSE_LEFT_CLICK) {
if (chkBx) chkBx->SetIsInClickEvent(PR_FALSE);
if (radio) radio->SetIsInClickEvent(PR_FALSE);
}
// Finish the special file control processing...
if (type == NS_FORM_INPUT_FILE) {
// If the event is starting here that's fine. If it's not