From 506d091582943ab31b5068b7097f69bb9666c145 Mon Sep 17 00:00:00 2001 From: "Olli.Pettay%helsinki.fi" Date: Tue, 23 Jan 2007 07:43:18 +0000 Subject: [PATCH] Bug 367256, Expose datatype object attribute, p=surkov, r=aaronr, aaronl, me git-svn-id: svn://10.0.0.236/trunk@218795 18797224-902f-48f8-a5cc-f745e15eee43 --- .../src/xforms/nsXFormsAccessible.cpp | 18 ++ .../src/xforms/nsXFormsAccessible.h | 4 + .../base/public/nsIXFormsUtilityService.h | 13 +- .../xforms/nsIModelElementPrivate.idl | 40 ++- .../xforms/nsXFormsModelElement.cpp | 305 +++++++++++------- .../extensions/xforms/nsXFormsModelElement.h | 33 +- .../xforms/nsXFormsUtilityService.cpp | 16 + .../xforms/nsXFormsUtilityService.h | 1 + 8 files changed, 289 insertions(+), 141 deletions(-) diff --git a/mozilla/accessible/src/xforms/nsXFormsAccessible.cpp b/mozilla/accessible/src/xforms/nsXFormsAccessible.cpp index 8c88cbd6aa1..3be89935a3b 100755 --- a/mozilla/accessible/src/xforms/nsXFormsAccessible.cpp +++ b/mozilla/accessible/src/xforms/nsXFormsAccessible.cpp @@ -45,6 +45,7 @@ #include "nsIMutableArray.h" #include "nsIXFormsUtilityService.h" #include "nsIPlaintextEditor.h" +#include "nsIPersistentProperties2.h" // nsXFormsAccessibleBase @@ -241,6 +242,23 @@ nsXFormsAccessible::GetDescription(nsAString& aDescription) return GetBoundChildElementValue(NS_LITERAL_STRING("hint"), aDescription); } +NS_IMETHODIMP +nsXFormsAccessible::GetAttributes(nsIPersistentProperties **aAttributes) +{ + NS_ENSURE_ARG_POINTER(aAttributes); + + nsresult rv = nsHyperTextAccessible::GetAttributes(aAttributes); + NS_ENSURE_SUCCESS(rv, rv); + + nsAutoString name; + rv = sXFormsService->GetBuiltinTypeName(mDOMNode, name); + NS_ENSURE_SUCCESS(rv, rv); + + nsAutoString unused; + return (*aAttributes)->SetStringProperty(NS_LITERAL_CSTRING("datatype"), + name, unused); +} + NS_IMETHODIMP nsXFormsAccessible::GetAllowsAnonChildAccessibles(PRBool *aAllowsAnonChildren) { diff --git a/mozilla/accessible/src/xforms/nsXFormsAccessible.h b/mozilla/accessible/src/xforms/nsXFormsAccessible.h index d07218758aa..5cf9e9193df 100755 --- a/mozilla/accessible/src/xforms/nsXFormsAccessible.h +++ b/mozilla/accessible/src/xforms/nsXFormsAccessible.h @@ -85,6 +85,10 @@ public: // Returns value of child xforms 'hint' element. NS_IMETHOD GetDescription(nsAString& aDescription); + // Appends ARIA 'datatype' property based on datatype of instance node that + // element is bound to. + NS_IMETHOD GetAttributes(nsIPersistentProperties **aAttributes); + // Denies accessible nodes in anonymous content of xforms element by // always returning PR_FALSE value. NS_IMETHOD GetAllowsAnonChildAccessibles(PRBool *aAllowsAnonChildren); diff --git a/mozilla/content/base/public/nsIXFormsUtilityService.h b/mozilla/content/base/public/nsIXFormsUtilityService.h index 71b16e344d8..07348765961 100755 --- a/mozilla/content/base/public/nsIXFormsUtilityService.h +++ b/mozilla/content/base/public/nsIXFormsUtilityService.h @@ -52,10 +52,11 @@ class nsIEditor; #endif /* nsIXFormsUtilityService */ -#define NS_IXFORMSUTILITYSERVICE_IID_STR "88d9eaa9-1498-4ffb-85a6-44267595cb20" +#define NS_IXFORMSUTILITYSERVICE_IID_STR "cd3457b6-cb6a-496c-bdfa-6cfecb2bd5fb" #define NS_IXFORMSUTILITYSERVICE_IID \ -{ 0x88d9eaa9, 0x1498, 0x4ffb, \ - { 0x85, 0xa6, 0x44, 0x26, 0x75, 0x95, 0xcb, 0x20 } } +{ 0xcd3457b6, 0xcb6a, 0x496c, \ + { 0xbd, 0xfa, 0x6c, 0xfe, 0xcb, 0x2b, 0xd5, 0xfb } } + /** * Private interface implemented by the nsXFormsUtilityService in XForms @@ -72,6 +73,12 @@ public: STATE_NOT_A_RANGE }; + /** + * Returns the name of the builtin type of the instance node that aElement is + * bound to. Fails if aElement doesn't have a bound node. + */ + NS_IMETHOD GetBuiltinTypeName(nsIDOMNode *aElement, nsAString& aName); + /** * Return true if instance node that element is bound to is readonly. */ diff --git a/mozilla/extensions/xforms/nsIModelElementPrivate.idl b/mozilla/extensions/xforms/nsIModelElementPrivate.idl index a0846efdca3..ee2ef997f78 100644 --- a/mozilla/extensions/xforms/nsIModelElementPrivate.idl +++ b/mozilla/extensions/xforms/nsIModelElementPrivate.idl @@ -48,7 +48,7 @@ interface nsISchemaBuiltinType; * Private interface implemented by the model element for other * elements to use. */ -[uuid(7df6b6ad-9555-4829-9bb0-8e42e6c02bcf)] +[uuid(3d94c3a4-e8d4-466c-a753-3cc65a338954)] interface nsIModelElementPrivate : nsIXFormsModelElement { /** @@ -59,21 +59,6 @@ interface nsIModelElementPrivate : nsIXFormsModelElement void addFormControl(in nsIXFormsControl control, in nsIXFormsControl parent); void removeFormControl(in nsIXFormsControl control); - /** - * Determine the type for a form control based on the schema included by - * this model. - */ - nsISchemaType getTypeForControl(in nsIXFormsControl control); - - /** - * This function takes an instance data node, finds the type bound to it, and - * returns the separated out type and namespace URI. If no type is set for - * the node, then it returns the defaults: "http://www.w3.org/2001/XMLSchema" - * and "string" - */ - void getTypeAndNSFromNode(in nsIDOMNode instancenode, out AString type, - out AString namespaceURI); - /** * Notification that an instance element has started or finished loading * its instance data. Model construction cannot complete until all of @@ -217,6 +202,27 @@ interface nsIModelElementPrivate : nsIXFormsModelElement */ void forceRebind(in nsIXFormsControl control); + /** + * Determine the type for a form control based on the schema included by + * this model. + */ + nsISchemaType getTypeForControl(in nsIXFormsControl control); + + /** + * Return builtin type name for a form control based on the schema included by + * this model. + */ + AString getBuiltinTypeNameForControl(in nsIXFormsControl control); + + /** + * This function takes an instance data node, finds the type bound to it, and + * returns the separated out type and namespace URI. If no type is set for + * the node, then it returns the defaults: "http://www.w3.org/2001/XMLSchema" + * and "string" + */ + void getTypeAndNSFromNode(in nsIDOMNode instancenode, out AString type, + out AString namespaceURI); + /** * Retrieves the list of datatypes that the original type is derived from * or is an extension of @@ -230,7 +236,7 @@ interface nsIModelElementPrivate : nsIXFormsModelElement * error if we encounter a complex type that comes from complex content * extension or restriction. */ - void GetDerivedTypeList(in AString aType, in AString aNamespace, + void getDerivedTypeList(in AString aType, in AString aNamespace, out AString aTypeList); /** diff --git a/mozilla/extensions/xforms/nsXFormsModelElement.cpp b/mozilla/extensions/xforms/nsXFormsModelElement.cpp index 95cdc624478..4229d6b4e83 100644 --- a/mozilla/extensions/xforms/nsXFormsModelElement.cpp +++ b/mozilla/extensions/xforms/nsXFormsModelElement.cpp @@ -2647,203 +2647,261 @@ nsXFormsModelElement::ForceRebind(nsIXFormsControl* aControl) } nsresult -nsXFormsModelElement::AppendBuiltinTypes(PRUint16 aType, - nsStringArray *aTypeArray) +nsXFormsModelElement::GetBuiltinTypeName(PRUint16 aType, + nsAString& aName) +{ + switch (aType) { + case nsISchemaBuiltinType::BUILTIN_TYPE_STRING: + aName.AssignLiteral("string"); + break; + case nsISchemaBuiltinType::BUILTIN_TYPE_BOOLEAN: + aName.AssignLiteral("boolean"); + break; + case nsISchemaBuiltinType::BUILTIN_TYPE_DECIMAL: + aName.AssignLiteral("decimal"); + break; + case nsISchemaBuiltinType::BUILTIN_TYPE_FLOAT: + aName.AssignLiteral("float"); + break; + case nsISchemaBuiltinType::BUILTIN_TYPE_DOUBLE: + aName.AssignLiteral("double"); + break; + case nsISchemaBuiltinType::BUILTIN_TYPE_DURATION: + aName.AssignLiteral("duration"); + break; + case nsISchemaBuiltinType::BUILTIN_TYPE_DATETIME: + aName.AssignLiteral("dateTime"); + break; + case nsISchemaBuiltinType::BUILTIN_TYPE_TIME: + aName.AssignLiteral("time"); + break; + case nsISchemaBuiltinType::BUILTIN_TYPE_DATE: + aName.AssignLiteral("date"); + break; + case nsISchemaBuiltinType::BUILTIN_TYPE_GYEARMONTH: + aName.AssignLiteral("gYearMonth"); + break; + case nsISchemaBuiltinType::BUILTIN_TYPE_GYEAR: + aName.AssignLiteral("gYear"); + break; + case nsISchemaBuiltinType::BUILTIN_TYPE_GMONTHDAY: + aName.AssignLiteral("gMonthDay"); + break; + case nsISchemaBuiltinType::BUILTIN_TYPE_GDAY: + aName.AssignLiteral("gDay"); + break; + case nsISchemaBuiltinType::BUILTIN_TYPE_GMONTH: + aName.AssignLiteral("gMonth"); + break; + case nsISchemaBuiltinType::BUILTIN_TYPE_HEXBINARY: + aName.AssignLiteral("hexBinary"); + break; + case nsISchemaBuiltinType::BUILTIN_TYPE_BASE64BINARY: + aName.AssignLiteral("base64Binary"); + break; + case nsISchemaBuiltinType::BUILTIN_TYPE_ANYURI: + aName.AssignLiteral("anyURI"); + break; + case nsISchemaBuiltinType::BUILTIN_TYPE_QNAME: + aName.AssignLiteral("QName"); + break; + case nsISchemaBuiltinType::BUILTIN_TYPE_NOTATION: + aName.AssignLiteral("NOTATION"); + break; + case nsISchemaBuiltinType::BUILTIN_TYPE_NORMALIZED_STRING: + aName.AssignLiteral("normalizedString"); + break; + case nsISchemaBuiltinType::BUILTIN_TYPE_TOKEN: + aName.AssignLiteral("token"); + break; + case nsISchemaBuiltinType::BUILTIN_TYPE_BYTE: + aName.AssignLiteral("byte"); + break; + case nsISchemaBuiltinType::BUILTIN_TYPE_UNSIGNEDBYTE: + aName.AssignLiteral("unsignedByte"); + break; + case nsISchemaBuiltinType::BUILTIN_TYPE_INTEGER: + aName.AssignLiteral("integer"); + break; + case nsISchemaBuiltinType::BUILTIN_TYPE_NEGATIVEINTEGER: + aName.AssignLiteral("negativeInteger"); + break; + case nsISchemaBuiltinType::BUILTIN_TYPE_NONPOSITIVEINTEGER: + aName.AssignLiteral("nonPositiveInteger"); + break; + case nsISchemaBuiltinType::BUILTIN_TYPE_LONG: + aName.AssignLiteral("long"); + break; + case nsISchemaBuiltinType::BUILTIN_TYPE_NONNEGATIVEINTEGER: + aName.AssignLiteral("nonNegativeInteger"); + break; + case nsISchemaBuiltinType::BUILTIN_TYPE_INT: + aName.AssignLiteral("int"); + break; + case nsISchemaBuiltinType::BUILTIN_TYPE_UNSIGNEDINT: + aName.AssignLiteral("unsignedInt"); + break; + case nsISchemaBuiltinType::BUILTIN_TYPE_UNSIGNEDLONG: + aName.AssignLiteral("unsignedLong"); + break; + case nsISchemaBuiltinType::BUILTIN_TYPE_POSITIVEINTEGER: + aName.AssignLiteral("positiveInteger"); + break; + case nsISchemaBuiltinType::BUILTIN_TYPE_SHORT: + aName.AssignLiteral("short"); + break; + case nsISchemaBuiltinType::BUILTIN_TYPE_UNSIGNEDSHORT: + aName.AssignLiteral("unsignedShort"); + break; + case nsISchemaBuiltinType::BUILTIN_TYPE_LANGUAGE: + aName.AssignLiteral("language"); + break; + case nsISchemaBuiltinType::BUILTIN_TYPE_NMTOKEN: + aName.AssignLiteral("NMTOKEN"); + break; + case nsISchemaBuiltinType::BUILTIN_TYPE_NAME: + aName.AssignLiteral("Name"); + break; + case nsISchemaBuiltinType::BUILTIN_TYPE_NCNAME: + aName.AssignLiteral("NCName"); + break; + case nsISchemaBuiltinType::BUILTIN_TYPE_ID: + aName.AssignLiteral("ID"); + break; + case nsISchemaBuiltinType::BUILTIN_TYPE_IDREF: + aName.AssignLiteral("IDREF"); + break; + case nsISchemaBuiltinType::BUILTIN_TYPE_ENTITY: + aName.AssignLiteral("ENTITY"); + break; + case nsISchemaBuiltinType::BUILTIN_TYPE_IDREFS: + aName.AssignLiteral("IDREFS"); + break; + case nsISchemaBuiltinType::BUILTIN_TYPE_ENTITIES: + aName.AssignLiteral("ENTITIES"); + break; + case nsISchemaBuiltinType::BUILTIN_TYPE_NMTOKENS: + aName.AssignLiteral("NMTOKENS"); + break; + default: + // should never hit here + NS_WARNING("nsXFormsModelElement::GetBuiltinTypeName: Unknown builtin type encountered."); + return NS_ERROR_FAILURE; + } + + return NS_OK; +} + +nsresult +nsXFormsModelElement::GetBuiltinTypesNames(PRUint16 aType, + nsStringArray *aNameArray) { // This function recursively appends aType (and its base types) to - // aTypeArray. So it assumes aType isn't in the array already. + // aNameArray. So it assumes aType isn't in the array already. nsAutoString typeString, builtString; PRUint16 parentType = 0; // We won't append xsd:anyType as the base of every type since that is kinda // redundant. + nsresult rv = GetBuiltinTypeName(aType, typeString); + NS_ENSURE_SUCCESS(rv, rv); + switch (aType) { - case nsISchemaBuiltinType::BUILTIN_TYPE_STRING: - typeString.AppendLiteral("string"); - break; - case nsISchemaBuiltinType::BUILTIN_TYPE_BOOLEAN: - typeString.AppendLiteral("boolean"); - break; - case nsISchemaBuiltinType::BUILTIN_TYPE_DECIMAL: - typeString.AppendLiteral("decimal"); - break; - case nsISchemaBuiltinType::BUILTIN_TYPE_FLOAT: - typeString.AppendLiteral("float"); - break; - case nsISchemaBuiltinType::BUILTIN_TYPE_DOUBLE: - typeString.AppendLiteral("double"); - break; - case nsISchemaBuiltinType::BUILTIN_TYPE_DURATION: - typeString.AppendLiteral("duration"); - break; - case nsISchemaBuiltinType::BUILTIN_TYPE_DATETIME: - typeString.AppendLiteral("dateTime"); - break; - case nsISchemaBuiltinType::BUILTIN_TYPE_TIME: - typeString.AppendLiteral("time"); - break; - case nsISchemaBuiltinType::BUILTIN_TYPE_DATE: - typeString.AppendLiteral("date"); - break; - case nsISchemaBuiltinType::BUILTIN_TYPE_GYEARMONTH: - typeString.AppendLiteral("gYearMonth"); - break; - case nsISchemaBuiltinType::BUILTIN_TYPE_GYEAR: - typeString.AppendLiteral("gYear"); - break; - case nsISchemaBuiltinType::BUILTIN_TYPE_GMONTHDAY: - typeString.AppendLiteral("gMonthDay"); - break; - case nsISchemaBuiltinType::BUILTIN_TYPE_GDAY: - typeString.AppendLiteral("gDay"); - break; - case nsISchemaBuiltinType::BUILTIN_TYPE_GMONTH: - typeString.AppendLiteral("gMonth"); - break; - case nsISchemaBuiltinType::BUILTIN_TYPE_HEXBINARY: - typeString.AppendLiteral("hexBinary"); - break; - case nsISchemaBuiltinType::BUILTIN_TYPE_BASE64BINARY: - typeString.AppendLiteral("base64Binary"); - break; - case nsISchemaBuiltinType::BUILTIN_TYPE_ANYURI: - typeString.AppendLiteral("anyURI"); - break; - case nsISchemaBuiltinType::BUILTIN_TYPE_QNAME: - typeString.AppendLiteral("QName"); - break; - case nsISchemaBuiltinType::BUILTIN_TYPE_NOTATION: - typeString.AppendLiteral("NOTATION"); - break; case nsISchemaBuiltinType::BUILTIN_TYPE_NORMALIZED_STRING: - typeString.AppendLiteral("normalizedString"); parentType = nsISchemaBuiltinType::BUILTIN_TYPE_STRING; break; case nsISchemaBuiltinType::BUILTIN_TYPE_TOKEN: - typeString.AppendLiteral("token"); parentType = nsISchemaBuiltinType::BUILTIN_TYPE_NORMALIZED_STRING; break; case nsISchemaBuiltinType::BUILTIN_TYPE_BYTE: - typeString.AppendLiteral("byte"); parentType = nsISchemaBuiltinType::BUILTIN_TYPE_SHORT; break; case nsISchemaBuiltinType::BUILTIN_TYPE_UNSIGNEDBYTE: - typeString.AppendLiteral("unsignedByte"); parentType = nsISchemaBuiltinType::BUILTIN_TYPE_UNSIGNEDSHORT; break; case nsISchemaBuiltinType::BUILTIN_TYPE_INTEGER: - typeString.AppendLiteral("integer"); parentType = nsISchemaBuiltinType::BUILTIN_TYPE_DECIMAL; break; case nsISchemaBuiltinType::BUILTIN_TYPE_NEGATIVEINTEGER: - typeString.AppendLiteral("negativeInteger"); parentType = nsISchemaBuiltinType::BUILTIN_TYPE_NONPOSITIVEINTEGER; break; case nsISchemaBuiltinType::BUILTIN_TYPE_NONPOSITIVEINTEGER: - typeString.AppendLiteral("nonPositiveInteger"); parentType = nsISchemaBuiltinType::BUILTIN_TYPE_INTEGER; break; case nsISchemaBuiltinType::BUILTIN_TYPE_LONG: - typeString.AppendLiteral("long"); parentType = nsISchemaBuiltinType::BUILTIN_TYPE_INTEGER; break; case nsISchemaBuiltinType::BUILTIN_TYPE_NONNEGATIVEINTEGER: - typeString.AppendLiteral("nonNegativeInteger"); parentType = nsISchemaBuiltinType::BUILTIN_TYPE_INTEGER; break; case nsISchemaBuiltinType::BUILTIN_TYPE_INT: - typeString.AppendLiteral("int"); parentType = nsISchemaBuiltinType::BUILTIN_TYPE_LONG; break; case nsISchemaBuiltinType::BUILTIN_TYPE_UNSIGNEDINT: - typeString.AppendLiteral("unsignedInt"); parentType = nsISchemaBuiltinType::BUILTIN_TYPE_UNSIGNEDLONG; break; case nsISchemaBuiltinType::BUILTIN_TYPE_UNSIGNEDLONG: - typeString.AppendLiteral("unsignedLong"); parentType = nsISchemaBuiltinType::BUILTIN_TYPE_NONNEGATIVEINTEGER; break; case nsISchemaBuiltinType::BUILTIN_TYPE_POSITIVEINTEGER: - typeString.AppendLiteral("positiveInteger"); parentType = nsISchemaBuiltinType::BUILTIN_TYPE_NONNEGATIVEINTEGER; break; case nsISchemaBuiltinType::BUILTIN_TYPE_SHORT: - typeString.AppendLiteral("short"); parentType = nsISchemaBuiltinType::BUILTIN_TYPE_INT; break; case nsISchemaBuiltinType::BUILTIN_TYPE_UNSIGNEDSHORT: - typeString.AppendLiteral("unsignedShort"); parentType = nsISchemaBuiltinType::BUILTIN_TYPE_UNSIGNEDINT; break; case nsISchemaBuiltinType::BUILTIN_TYPE_LANGUAGE: - typeString.AppendLiteral("language"); parentType = nsISchemaBuiltinType::BUILTIN_TYPE_TOKEN; break; case nsISchemaBuiltinType::BUILTIN_TYPE_NMTOKEN: - typeString.AppendLiteral("NMTOKEN"); parentType = nsISchemaBuiltinType::BUILTIN_TYPE_TOKEN; break; case nsISchemaBuiltinType::BUILTIN_TYPE_NAME: - typeString.AppendLiteral("Name"); parentType = nsISchemaBuiltinType::BUILTIN_TYPE_TOKEN; break; case nsISchemaBuiltinType::BUILTIN_TYPE_NCNAME: - typeString.AppendLiteral("NCName"); parentType = nsISchemaBuiltinType::BUILTIN_TYPE_NAME; break; case nsISchemaBuiltinType::BUILTIN_TYPE_ID: - typeString.AppendLiteral("ID"); parentType = nsISchemaBuiltinType::BUILTIN_TYPE_NCNAME; break; case nsISchemaBuiltinType::BUILTIN_TYPE_IDREF: - typeString.AppendLiteral("IDREF"); parentType = nsISchemaBuiltinType::BUILTIN_TYPE_NCNAME; break; case nsISchemaBuiltinType::BUILTIN_TYPE_ENTITY: - typeString.AppendLiteral("ENTITY"); parentType = nsISchemaBuiltinType::BUILTIN_TYPE_NCNAME; break; case nsISchemaBuiltinType::BUILTIN_TYPE_IDREFS: - typeString.AppendLiteral("IDREFS"); parentType = nsISchemaBuiltinType::BUILTIN_TYPE_IDREF; break; case nsISchemaBuiltinType::BUILTIN_TYPE_ENTITIES: - typeString.AppendLiteral("ENTITIES"); parentType = nsISchemaBuiltinType::BUILTIN_TYPE_ENTITY; break; case nsISchemaBuiltinType::BUILTIN_TYPE_NMTOKENS: - typeString.AppendLiteral("NMTOKENS"); parentType = nsISchemaBuiltinType::BUILTIN_TYPE_NMTOKEN; break; - default: - // should never hit here - NS_WARNING("nsXFormsModelElement::AppendBuiltinTypes: Unknown builtin type encountered."); - return NS_ERROR_FAILURE; } builtString.AppendLiteral(NS_NAMESPACE_XML_SCHEMA); builtString.AppendLiteral("#"); builtString.Append(typeString); - aTypeArray->AppendString(builtString); + aNameArray->AppendString(builtString); - nsresult rv = NS_OK; - if (parentType) { - rv = AppendBuiltinTypes(parentType, aTypeArray); - } + if (parentType) + return GetBuiltinTypesNames(parentType, aNameArray); - return rv; + return NS_OK; } nsresult nsXFormsModelElement::WalkTypeChainInternal(nsISchemaType *aType, + PRBool aFindRootBuiltin, PRUint16 *aBuiltinType, nsStringArray *aTypeArray) { - // If aBuiltinType is !nsnull, then we are only looking for the root - // primative type for aType. Otherwise build the whole string array. - PRBool onlyFindBuiltinRoot = aBuiltinType ? PR_TRUE : PR_FALSE; - PRUint16 schemaTypeValue = 0; aType->GetSchemaType(&schemaTypeValue); NS_ENSURE_STATE(schemaTypeValue); @@ -2863,15 +2921,20 @@ nsXFormsModelElement::WalkTypeChainInternal(nsISchemaType *aType, nsCOMPtr builtinType(do_QueryInterface(aType)); NS_ENSURE_STATE(builtinType); - if (onlyFindBuiltinRoot) { + if (aFindRootBuiltin) return BuiltinTypeToPrimative(builtinType, aBuiltinType); - } - // the datatype URI for aType will be added to the array by - // AppendBuiltinTypes + PRUint16 builtinTypeVal; rv = builtinType->GetBuiltinType(&builtinTypeVal); NS_ENSURE_SUCCESS(rv, rv); - return AppendBuiltinTypes(builtinTypeVal, aTypeArray); + + if (aBuiltinType) + *aBuiltinType = builtinTypeVal; + + if (aTypeArray) + return GetBuiltinTypesNames(builtinTypeVal, aTypeArray); + + return NS_OK; } case nsISchemaSimpleType::SIMPLE_TYPE_RESTRICTION: { @@ -2933,7 +2996,7 @@ nsXFormsModelElement::WalkTypeChainInternal(nsISchemaType *aType, NS_ENSURE_STATE(simpleType); - if (!onlyFindBuiltinRoot) { + if (aTypeArray) { nsAutoString builtString; rv = aType->GetTargetNamespace(builtString); NS_ENSURE_SUCCESS(rv, rv); @@ -2945,7 +3008,8 @@ nsXFormsModelElement::WalkTypeChainInternal(nsISchemaType *aType, aTypeArray->AppendString(builtString); } - return WalkTypeChainInternal(simpleType, aBuiltinType, aTypeArray); + return WalkTypeChainInternal(simpleType, aFindRootBuiltin, aBuiltinType, + aTypeArray); } @@ -3027,7 +3091,7 @@ nsXFormsModelElement::BuiltinTypeToPrimative(nsISchemaBuiltinType *aSchemaType, NS_IMETHODIMP nsXFormsModelElement::GetDerivedTypeList(const nsAString &aType, const nsAString &aNamespace, - nsAString &aBuiltinType) + nsAString &aTypeList) { nsCOMPtr schemaColl = do_QueryInterface(mSchemas); NS_ENSURE_STATE(schemaColl); @@ -3035,9 +3099,9 @@ nsXFormsModelElement::GetDerivedTypeList(const nsAString &aType, nsCOMPtr schemaType; schemaColl->GetType(aType, aNamespace, getter_AddRefs(schemaType)); NS_ENSURE_STATE(schemaType); - nsStringArray typeArray; - nsresult rv = WalkTypeChainInternal(schemaType, nsnull, &typeArray); + nsStringArray typeArray; + nsresult rv = WalkTypeChainInternal(schemaType, PR_FALSE, nsnull, &typeArray); if (NS_SUCCEEDED(rv)) { nsCOMPtr stringEnum; rv = NS_NewStringEnumerator(getter_AddRefs(stringEnum), &typeArray); @@ -3058,13 +3122,13 @@ nsXFormsModelElement::GetDerivedTypeList(const nsAString &aType, } if (NS_SUCCEEDED(rv)) { - aBuiltinType.Assign(constructorString); + aTypeList.Assign(constructorString); } } } if (NS_FAILED(rv)) { - aBuiltinType.Assign(EmptyString()); + aTypeList.Assign(EmptyString()); } typeArray.Clear(); @@ -3072,6 +3136,23 @@ nsXFormsModelElement::GetDerivedTypeList(const nsAString &aType, return rv; } +NS_IMETHODIMP +nsXFormsModelElement::GetBuiltinTypeNameForControl(nsIXFormsControl *aControl, + nsAString& aTypeName) +{ + NS_ENSURE_ARG(aControl); + + nsCOMPtr schemaType; + nsresult rv = GetTypeForControl(aControl, getter_AddRefs(schemaType)); + NS_ENSURE_SUCCESS(rv, rv); + + PRUint16 builtinType; + rv = WalkTypeChainInternal(schemaType, PR_FALSE, &builtinType); + NS_ENSURE_SUCCESS(rv, rv); + + return GetBuiltinTypeName(builtinType, aTypeName); +} + NS_IMETHODIMP nsXFormsModelElement::GetRootBuiltinType(nsISchemaType *aType, PRUint16 *aBuiltinType) @@ -3079,7 +3160,7 @@ nsXFormsModelElement::GetRootBuiltinType(nsISchemaType *aType, NS_ENSURE_ARG(aType); NS_ENSURE_ARG_POINTER(aBuiltinType); - return WalkTypeChainInternal(aType, aBuiltinType, nsnull); + return WalkTypeChainInternal(aType, PR_TRUE, aBuiltinType); } /* static */ void diff --git a/mozilla/extensions/xforms/nsXFormsModelElement.h b/mozilla/extensions/xforms/nsXFormsModelElement.h index e0e5ff9f678..3af99bd5674 100644 --- a/mozilla/extensions/xforms/nsXFormsModelElement.h +++ b/mozilla/extensions/xforms/nsXFormsModelElement.h @@ -397,27 +397,42 @@ private: */ void ValidateInstanceDocuments(); + /** + * Return the name of builitn type. + * + * @param aType The builtin type + * @param aName The name of the given type + */ + NS_HIDDEN_(nsresult) GetBuiltinTypeName(PRUint16 aType, + nsAString& aName); + /** * Starting with aType, walks through the builtin derived types back to the * builtin primative type, appending the datatype URIs to the string array as * it goes */ - NS_HIDDEN_(nsresult) AppendBuiltinTypes(PRUint16 aType, - nsStringArray *aBuiltinType); + NS_HIDDEN_(nsresult) GetBuiltinTypesNames(PRUint16 aType, + nsStringArray *aNameArray); + /** * Starting from aType, walks the chain of datatype extension/derivation to * gather information. * - * @param aType The type we are trying to find datatype information - * for - * @param aBuiltinType If non-null, we'll return the root primative type - * of aType in this buffer - * @param aTypeArray If aBuiltinType is nsnull, we'll build a string - * array of datatype URIs and put them in aTypeArray. + * @param aType The type we are trying to find datatype information + * for + * @param aFindRootBuiltin If true then root builtin type will be returned + only + * @param aBuiltinType If non-null, we'll return the builtin (if + * aFindRootBuiltin is false) or root builtin (if + * aFindRootBuiltin is true) type of the given type + * @param aTypeArray If non-null and aFindRootBuiltin is false, we'll + * build a string array of datatype URIs and put them + * in aTypeArray. */ NS_HIDDEN_(nsresult) WalkTypeChainInternal(nsISchemaType *aType, + PRBool aFindRootBuiltin, PRUint16 *aBuiltinType, - nsStringArray *aTypeArray); + nsStringArray *aTypeArray = nsnull); /** * Returns the primative type that aSchemaType is derived/extended from */ diff --git a/mozilla/extensions/xforms/nsXFormsUtilityService.cpp b/mozilla/extensions/xforms/nsXFormsUtilityService.cpp index f663a67fa43..840e8542784 100644 --- a/mozilla/extensions/xforms/nsXFormsUtilityService.cpp +++ b/mozilla/extensions/xforms/nsXFormsUtilityService.cpp @@ -41,6 +41,7 @@ #include "nsIContent.h" +#include "nsIXFormsControl.h" #include "nsIXFormsDelegate.h" #include "nsIXFormsAccessors.h" #include "nsIXFormsRangeConditionAccessors.h" @@ -52,6 +53,7 @@ #include "nsIXFormsNSSelectElement.h" #include "nsIXFormsNSSelect1Element.h" #include "nsIXFormsItemElement.h" +#include "nsIModelElementPrivate.h" #include "nsXFormsUtils.h" #include "nsXFormsAtoms.h" @@ -89,6 +91,20 @@ NS_ENSURE_ARG(aElement);\ nsCOMPtr widget(do_QueryInterface(aElement));\ NS_ENSURE_TRUE(widget, NS_ERROR_FAILURE);\ +NS_IMETHODIMP +nsXFormsUtilityService::GetBuiltinTypeName(nsIDOMNode *aElement, + nsAString& aName) +{ + nsCOMPtr element(do_QueryInterface(aElement)); + NS_ENSURE_TRUE(element, NS_ERROR_FAILURE); + + nsCOMPtr model = nsXFormsUtils::GetModel(element); + NS_ENSURE_TRUE(model, NS_ERROR_FAILURE); + + nsCOMPtr control(do_QueryInterface(element)); + return model->GetBuiltinTypeNameForControl(control, aName); +} + NS_IMETHODIMP nsXFormsUtilityService::IsReadonly(nsIDOMNode *aElement, PRBool *aState) { diff --git a/mozilla/extensions/xforms/nsXFormsUtilityService.h b/mozilla/extensions/xforms/nsXFormsUtilityService.h index 0665e53049c..5bed5a246ef 100644 --- a/mozilla/extensions/xforms/nsXFormsUtilityService.h +++ b/mozilla/extensions/xforms/nsXFormsUtilityService.h @@ -57,6 +57,7 @@ public: NS_DECL_ISUPPORTS // nsIXFormsUtilityService + NS_IMETHOD GetBuiltinTypeName(nsIDOMNode *aElement, nsAString& aName); NS_IMETHOD IsReadonly(nsIDOMNode *aElement, PRBool *aState); NS_IMETHOD IsRelevant(nsIDOMNode *aElement, PRBool *aState); NS_IMETHOD IsRequired(nsIDOMNode *aElement, PRBool *aState);