XForms bug 273428. Patch by aaronr, r=me,beaufour.

This commit is contained in:
doronr%us.ibm.com 2005-02-22 22:11:51 +00:00
parent 473534a724
commit f6d43aa074
9 changed files with 98 additions and 28 deletions

View File

@ -7,4 +7,5 @@ interface nsISchemaValidator : nsISupports {
void loadSchema(in nsISchema aSchema);
boolean validate(in nsIDOMNode aElement);
boolean validateString(in AString aValue, in AString aType, in AString aNamespace);
nsISchemaType getType(in AString aType, in AString aNamespace);
};

View File

@ -246,9 +246,9 @@ NS_IMETHODIMP nsSchemaValidator::Validate(nsIDOMNode* aElement, PRBool *aResult)
/*
Returns the nsISchemaType for a given value/type/namespace pair.
*/
nsresult nsSchemaValidator::GetType(const nsAString & aType,
const nsAString & aNamespace,
nsISchemaType ** aSchemaType)
NS_IMETHODIMP nsSchemaValidator::GetType(const nsAString & aType,
const nsAString & aNamespace,
nsISchemaType ** aSchemaType)
{
nsresult rv;

View File

@ -118,10 +118,6 @@ public:
private:
~nsSchemaValidator();
nsresult GetType(const nsAString & aType,
const nsAString & aNamespace,
nsISchemaType **aSchemaType);
// methods dealing with simpletypes
nsresult ValidateSimpletype(const nsAString & aNodeValue, nsISchemaSimpleType *aSchemaSimpleType, PRBool *aResult);
nsresult ValidateRestrictionSimpletype(const nsAString & aNodeValue, nsISchemaSimpleType *aSchemaSimpleType, PRBool *aResult);

View File

@ -214,7 +214,7 @@ nsXFormsInputElement::OnDestroyed()
NS_IMETHODIMP
nsXFormsInputElement::AttributeSet(nsIAtom *aName, const nsAString &aValue)
{
nsXFormsControlStub::WillSetAttribute(aName, aValue);
nsXFormsControlStub::AttributeSet(aName, aValue);
if (aName == nsXFormsAtoms::incremental)
mIncremental = aValue.EqualsLiteral("true");
@ -235,7 +235,12 @@ nsXFormsInputElement::HandleDefault(nsIDOMEvent *aEvent,
nsAutoString type;
aEvent->GetType(type);
if (type.EqualsLiteral("keyup"))
// Seems like too big of a hassle for too little gain to also check if we are
// a checkbox in addition to checking for the click. Plus, other input types
// like a date picker for input controls bound to a xsi:date type might
// need click updates, too.
if (type.EqualsLiteral("keyup") || type.EqualsLiteral("click"))
UpdateInstanceData();
return NS_OK;
@ -282,7 +287,15 @@ nsXFormsInputElement::UpdateInstanceData()
if (mType == eType_Input && type.EqualsLiteral("checkbox")) {
PRBool checked;
input->GetChecked(&checked);
value.AssignASCII(checked ? "1" : "0", 1);
// XXX we've got a problem here. Since UpdateInstanceData can be called
// due to a blur event, as it stands now we could be changing the instance
// data values even if the user didn't click on the checkbox, but instead
// was just tabbing through the form.
if(checked) {
value.Append(NS_LITERAL_STRING("true"));
} else {
value.Append(NS_LITERAL_STRING("false"));
}
} else {
input->GetValue(value);
}
@ -345,6 +358,10 @@ nsXFormsInputElement::Refresh()
input->SetChecked(text.EqualsLiteral("true") ||
text.EqualsLiteral("1"));
// other xforms processors default to incremental update in this case,
// so we should, too.
mIncremental = PR_TRUE;
} else {
input->RemoveAttribute(NS_LITERAL_STRING("type"));
input->SetValue(text);

View File

@ -768,8 +768,31 @@ NS_IMETHODIMP
nsXFormsModelElement::GetTypeForControl(nsIXFormsControl *aControl,
nsISchemaType **aType)
{
NS_ENSURE_ARG_POINTER(aType);
*aType = nsnull;
return NS_OK;
nsAutoString schemaTypeName;
nsAutoString schemaTypePrefix;
nsCOMPtr<nsIDOMNode> boundNode;
aControl->GetBoundNode(getter_AddRefs(boundNode));
NS_ENSURE_TRUE(boundNode, NS_ERROR_FAILURE);
nsresult rv = nsXFormsUtils::ParseTypeFromNode(boundNode, schemaTypeName,
schemaTypePrefix);
NS_ENSURE_SUCCESS(rv, rv);
// get the namespace url from the prefix
nsCOMPtr<nsIDOM3Node> domNode3 = do_QueryInterface(mElement, &rv);
NS_ENSURE_SUCCESS(rv, rv);
nsAutoString schemaTypeNamespace;
rv = domNode3->LookupNamespaceURI(schemaTypePrefix, schemaTypeNamespace);
NS_ENSURE_SUCCESS(rv, rv);
nsXFormsSchemaValidator validator;
nsCOMPtr<nsISchema> schema = do_QueryInterface(mSchemas);
validator.LoadSchema(schema);
return validator.GetType(schemaTypeName, schemaTypeNamespace, aType);
}
NS_IMETHODIMP
@ -856,32 +879,18 @@ NS_IMETHODIMP
nsXFormsModelElement::ValidateNode(nsIDOMNode *aInstanceNode, PRBool *aResult)
{
NS_ENSURE_ARG_POINTER(aResult);
nsresult rv;
nsAutoString typeAttribute;
nsCOMPtr<nsIDOMElement> nodeElem = do_QueryInterface(aInstanceNode, &rv);
NS_ENSURE_SUCCESS(rv, rv);
nodeElem->GetAttributeNS(NS_LITERAL_STRING(NS_NAMESPACE_XML_SCHEMA_INSTANCE),
NS_LITERAL_STRING("type"), typeAttribute);
// split type (ns:type) into namespace and type.
PRInt32 separator = typeAttribute.FindChar(':');
if ((separator == kNotFound) || ((PRUint32) separator == typeAttribute.Length()))
return NS_ERROR_UNEXPECTED;
// xxx send error to console
nsAutoString schemaTypeName;
nsAutoString schemaTypePrefix;
nsAutoString schemaTypeNamespace;
nsresult rv = nsXFormsUtils::ParseTypeFromNode(aInstanceNode, schemaTypeName,
schemaTypePrefix);
schemaTypePrefix.Assign(Substring(typeAttribute, 0, separator));
schemaTypeName.Assign(Substring(typeAttribute, ++separator, typeAttribute.Length()));
// get the namespace url from the prefix
nsCOMPtr<nsIDOM3Node> domNode3 = do_QueryInterface(mElement, &rv);
NS_ENSURE_SUCCESS(rv, rv);
nsAutoString schemaTypeNamespace;
rv = domNode3->LookupNamespaceURI(schemaTypePrefix, schemaTypeNamespace);
NS_ENSURE_SUCCESS(rv, rv);

View File

@ -77,3 +77,11 @@ PRBool nsXFormsSchemaValidator::Validate(nsIDOMNode* aElement)
return isValid;
}
PRBool nsXFormsSchemaValidator::GetType(const nsAString & aType,
const nsAString & aNamespace, nsISchemaType **aSchemaType)
{
NS_ENSURE_TRUE(mSchemaValidator, PR_FALSE);
nsresult rv = mSchemaValidator->GetType(aType, aNamespace, aSchemaType);
return( NS_SUCCEEDED(rv) );
}

View File

@ -49,6 +49,9 @@ public:
PRBool ValidateString(const nsAString & aValue, const nsAString & aType,
const nsAString & aNamespace);
PRBool Validate(nsIDOMNode* aElement);
PRBool GetType(const nsAString & aType, const nsAString & aNamespace,
nsISchemaType **aSchemaType);
protected:
nsCOMPtr<nsISchemaValidator> mSchemaValidator;

View File

@ -1014,3 +1014,31 @@ nsXFormsUtils::GetInstanceNodeForData(nsIDOMNode *aInstanceDataNode,
return NS_OK;
}
/* static */ nsresult
nsXFormsUtils::ParseTypeFromNode(nsIDOMNode *aInstanceData,
nsAString &aType, nsAString &aNSPrefix)
{
nsresult rv;
nsCOMPtr<nsIDOMElement> nodeElem = do_QueryInterface(aInstanceData, &rv);
NS_ENSURE_TRUE(nodeElem, NS_ERROR_FAILURE);
// right now type is stored as an attribute on the instance node. In the
// future it will be a property.
nsAutoString typeAttribute;
nodeElem->GetAttributeNS(NS_LITERAL_STRING(NS_NAMESPACE_XML_SCHEMA_INSTANCE),
NS_LITERAL_STRING("type"), typeAttribute);
// split type (ns:type) into namespace and type.
PRInt32 separator = typeAttribute.FindChar(':');
if ((separator == kNotFound) ||
((PRUint32) separator == typeAttribute.Length())) {
return NS_ERROR_UNEXPECTED;
// xxx send error to console
}
aNSPrefix.Assign(Substring(typeAttribute, 0, separator));
aType.Assign(Substring(typeAttribute, ++separator, typeAttribute.Length()));
return NS_OK;
}

View File

@ -337,6 +337,14 @@ public:
nsIModelElementPrivate *aModel,
nsIDOMNode **aInstanceNode);
/**
* This function takes an instance data node, finds the type bound to it, and
* returns the seperated out type (integer) and namespace prefix (xsd).
*/
static NS_HIDDEN_(nsresult) ParseTypeFromNode(nsIDOMNode *aInstanceData,
nsAString &aType,
nsAString &aNSPrefix);
};
#endif