Only send the xforms-value-changed event to the correct controls, not everything. Bug 293579, r=smaug+me, a=mkaply, patch by aaronr, NPOTB

This commit is contained in:
allan%beaufour.dk 2005-05-17 12:10:08 +00:00
parent 3ca67d1227
commit 1b4635414b
8 changed files with 83 additions and 0 deletions

View File

@ -91,4 +91,11 @@ interface nsIXFormsControl : nsIXFormsContextControl
* control (XXX)
*/
readonly attribute nsIDOMElement element;
/** According to sec 4.1 in the spec, only certain controls are allowed to
* be targets of the interaction and notification events. The controls
* that inherit from nsXFormsControlStub that SHOULDN'T get these events
* need to override IsEventTarget() and return PR_FALSE
*/
boolean isEventTarget();
};

View File

@ -97,6 +97,7 @@ public:
NS_IMETHOD Bind();
NS_IMETHOD Refresh();
NS_IMETHOD SetContextNode(nsIDOMNode *aContextNode);
NS_IMETHOD IsEventTarget(PRBool *aOK);
// nsIXFormsRepeatItemElement
NS_DECL_NSIXFORMSREPEATITEMELEMENT
@ -274,6 +275,13 @@ nsXFormsContextContainer::Refresh()
return NS_OK;
}
NS_IMETHODIMP
nsXFormsContextContainer::IsEventTarget(PRBool* aOK)
{
*aOK = PR_FALSE;
return NS_OK;
}
// nsIXFormsRepeatItemElement
/**
* @todo Should set/get pseudo-element, not attribute (XXX)

View File

@ -180,6 +180,13 @@ nsXFormsControlStub::TryFocus(PRBool* aOK)
return NS_OK;
}
NS_IMETHODIMP
nsXFormsControlStub::IsEventTarget(PRBool *aOK)
{
*aOK = PR_TRUE;
return NS_OK;
}
nsresult
nsXFormsControlStub::ProcessNodeBinding(const nsString &aBindingAttr,

View File

@ -93,6 +93,7 @@ public:
nsIDOMXPathResult **aResult = nsnull);
NS_IMETHOD Bind();
NS_IMETHOD TryFocus(PRBool* aOK);
NS_IMETHOD IsEventTarget(PRBool *aOK);
// nsIXTFXMLVisual overrides
/** This sets the notification mask and initializes mElement */

View File

@ -57,6 +57,7 @@ class nsXFormsLabelElement : public nsXFormsControlStub
public:
// nsIXFormsControl
NS_IMETHOD Refresh();
NS_IMETHOD IsEventTarget(PRBool *aOK);
// nsIXTFXMLVisual overrides
NS_IMETHOD OnCreated(nsIXTFXMLVisualWrapper *aWrapper);
@ -198,6 +199,13 @@ nsXFormsLabelElement::Refresh()
return NS_OK;
}
NS_IMETHODIMP
nsXFormsLabelElement::IsEventTarget(PRBool *aOK)
{
*aOK = PR_FALSE;
return NS_OK;
}
NS_HIDDEN_(nsresult)
NS_NewXFormsLabelElement(nsIXTFElement **aResult)
{

View File

@ -317,6 +317,7 @@ public:
NS_IMETHOD Bind();
NS_IMETHOD Refresh();
NS_IMETHOD TryFocus(PRBool* aOK);
NS_IMETHOD IsEventTarget(PRBool *aOK);
// nsIXFormsRepeatElement
NS_DECL_NSIXFORMSREPEATELEMENT
@ -973,6 +974,13 @@ nsXFormsRepeatElement::TryFocus(PRBool *aOK)
return control->TryFocus(aOK);
}
NS_IMETHODIMP
nsXFormsRepeatElement::IsEventTarget(PRBool *aOK)
{
*aOK = PR_FALSE;
return NS_OK;
}
/**
* @todo This function will be part of the general schema support, so it will
* only live here until this is implemented there. (XXX)

View File

@ -85,6 +85,7 @@ public:
// nsIXFormsControl
NS_IMETHOD Refresh();
NS_IMETHOD IsEventTarget(PRBool *aOK);
private:
/**
@ -411,6 +412,13 @@ nsXFormsSwitchElement::CaseChanged(nsIDOMNode* aCase, PRBool aRemoved)
SetSelected(element, PR_TRUE);
}
NS_IMETHODIMP
nsXFormsSwitchElement::IsEventTarget(PRBool *aOK)
{
*aOK = PR_FALSE;
return NS_OK;
}
NS_HIDDEN_(nsresult)
NS_NewXFormsSwitchElement(nsIXTFElement **aResult)
{

View File

@ -722,6 +722,42 @@ nsXFormsUtils::DispatchEvent(nsIDOMNode* aTarget, nsXFormsEvent aEvent)
{
if (!aTarget)
return NS_ERROR_FAILURE;
nsCOMPtr<nsIXFormsControl> control = do_QueryInterface(aTarget);
if (control) {
switch (aEvent) {
case eEvent_Previous:
case eEvent_Next:
case eEvent_Focus:
case eEvent_Help:
case eEvent_Hint:
case eEvent_DOMActivate:
case eEvent_ValueChanged:
case eEvent_Valid:
case eEvent_Invalid:
case eEvent_DOMFocusIn:
case eEvent_DOMFocusOut:
case eEvent_Readonly:
case eEvent_Readwrite:
case eEvent_Required:
case eEvent_Optional:
case eEvent_Enabled:
case eEvent_Disabled:
case eEvent_InRange:
case eEvent_OutOfRange:
{
PRBool acceptableEventTarget = PR_FALSE;
control->IsEventTarget(&acceptableEventTarget);
if (!acceptableEventTarget) {
return NS_OK;
}
break;
}
default:
break;
}
}
nsCOMPtr<nsIDOMDocument> domDoc;
aTarget->GetOwnerDocument(getter_AddRefs(domDoc));