[XForms] Implement typeList attr and hide upload and inputs based on it. Bug 313313, r=doronr+surkov+olli

This commit is contained in:
aaronr%us.ibm.com 2006-08-10 21:41:25 +00:00
Родитель cab0995d08
Коммит 1ce9f01a4d
7 изменённых файлов: 585 добавлений и 56 удалений

Просмотреть файл

@ -42,12 +42,13 @@ interface nsIXFormsControl;
interface nsISchemaType;
interface nsIInstanceElementPrivate;
interface nsIDOMNode;
interface nsISchemaBuiltinType;
/**
* Private interface implemented by the model element for other
* elements to use.
*/
[uuid(74238f22-d112-4bed-a8dc-cc228df52c2e)]
[uuid(7df6b6ad-9555-4829-9bb0-8e42e6c02bcf)]
interface nsIModelElementPrivate : nsIXFormsModelElement
{
/**
@ -215,4 +216,34 @@ interface nsIModelElementPrivate : nsIXFormsModelElement
* @param control The control to rebind.
*/
void forceRebind(in nsIXFormsControl control);
/**
* Retrieves the list of datatypes that the original type is derived from
* or is an extension of
*
* @param aType The original type
* @param aNamespace The original namespace URI
* @param aTypeList The returned space-delimited list
*
* Returns NS_ERROR_XFORMS_UNION_TYPE if a schema union datatype was
* encounterd while trying to build the type list. Will also return an
* error if we encounter a complex type that comes from complex content
* extension or restriction.
*/
void GetDerivedTypeList(in AString aType, in AString aNamespace,
out AString aTypeList);
/**
* Retrieves the primative builtin type that the original type derives from
*
* @param aType The original type
* @param aBuiltinType The returned builtin type (defined in nsISchema)
*
* Returns NS_ERROR_XFORMS_UNION_TYPE if a schema union datatype was
* encounterd while trying to build the type list. Will also return an
* error if we encounter a complex type that comes from complex content
* extension or restriction.
*/
void GetRootBuiltinType(in nsISchemaType aType,
out unsigned short aBuiltinType);
};

Просмотреть файл

@ -226,20 +226,41 @@ nsXFormsDelegateStub::SetMozTypeAttribute()
{
NS_NAMED_LITERAL_STRING(mozTypeNs, NS_NAMESPACE_MOZ_XFORMS_TYPE);
NS_NAMED_LITERAL_STRING(mozType, "type");
NS_NAMED_LITERAL_STRING(mozTypeList, "typelist");
if (mModel && mBoundNode) {
nsAutoString type, ns;
if (NS_FAILED(mModel->GetTypeAndNSFromNode(mBoundNode, type, ns))) {
nsAutoString type, nsOrig;
if (NS_FAILED(mModel->GetTypeAndNSFromNode(mBoundNode, type, nsOrig))) {
mElement->RemoveAttributeNS(mozTypeNs, mozType);
mElement->RemoveAttributeNS(mozTypeNs, mozTypeList);
return;
}
ns.AppendLiteral("#");
ns.Append(type);
mElement->SetAttributeNS(mozTypeNs, mozType, ns);
} else {
mElement->RemoveAttributeNS(mozTypeNs, mozType);
nsAutoString attrValue(nsOrig);
attrValue.AppendLiteral("#");
attrValue.Append(type);
mElement->SetAttributeNS(mozTypeNs, mozType, attrValue);
// Get the list of types that this type derives from and set it as the
// value of the basetype attribute
nsresult rv = mModel->GetDerivedTypeList(type, nsOrig, attrValue);
if (NS_SUCCEEDED(rv)) {
mElement->SetAttributeNS(mozTypeNs, mozTypeList, attrValue);
return;
}
// Note: even if we can't build the derived type list, we should leave on
// mozType attribute. We can still use the attr for validation, etc. But
// the type-restricted controls like range and upload won't display since
// they are bound to their anonymous content by @typeList. Make sure that
// we don't leave around mozTypeList if it isn't accurate.
mElement->RemoveAttributeNS(mozTypeNs, mozTypeList);
return;
}
mElement->RemoveAttributeNS(mozTypeNs, mozType);
mElement->RemoveAttributeNS(mozTypeNs, mozTypeList);
return;
}
NS_IMETHODIMP

Просмотреть файл

@ -82,6 +82,7 @@
#include "nsIPrefService.h"
#include "nsIPrefBranch.h"
#include "nsIEventStateManager.h"
#include "nsStringEnumerator.h"
#define XFORMS_LAZY_INSTANCE_BINDING \
"chrome://xforms/content/xforms.xml#xforms-lazy-instance"
@ -2598,6 +2599,442 @@ nsXFormsModelElement::ForceRebind(nsIXFormsControl* aControl)
return RefreshSubTree(controlItem->FirstChild(), rebindChildren);
}
nsresult
nsXFormsModelElement::AppendBuiltinTypes(PRUint16 aType,
nsStringArray *aTypeArray)
{
// This function recursively appends aType (and its base types) to
// aTypeArray. 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.
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);
nsresult rv = NS_OK;
if (parentType) {
rv = AppendBuiltinTypes(parentType, aTypeArray);
}
return rv;
}
nsresult
nsXFormsModelElement::WalkTypeChainInternal(nsISchemaType *aType,
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);
nsresult rv = NS_OK;
nsCOMPtr<nsISchemaSimpleType> simpleType;
if (schemaTypeValue == nsISchemaType::SCHEMA_TYPE_SIMPLE) {
simpleType = do_QueryInterface(aType);
NS_ENSURE_STATE(simpleType);
PRUint16 simpleTypeValue;
simpleType->GetSimpleType(&simpleTypeValue);
NS_ENSURE_STATE(simpleTypeValue);
switch (simpleTypeValue) {
case nsISchemaSimpleType::SIMPLE_TYPE_BUILTIN:
{
nsCOMPtr<nsISchemaBuiltinType> builtinType(do_QueryInterface(aType));
NS_ENSURE_STATE(builtinType);
if (onlyFindBuiltinRoot) {
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);
}
case nsISchemaSimpleType::SIMPLE_TYPE_RESTRICTION:
{
nsCOMPtr<nsISchemaRestrictionType> restType(do_QueryInterface(aType));
NS_ENSURE_STATE(restType);
restType->GetBaseType(getter_AddRefs(simpleType));
break;
}
case nsISchemaSimpleType::SIMPLE_TYPE_LIST:
{
nsCOMPtr<nsISchemaListType> listType(do_QueryInterface(aType));
NS_ENSURE_STATE(listType);
listType->GetListType(getter_AddRefs(simpleType));
break;
}
case nsISchemaSimpleType::SIMPLE_TYPE_UNION:
{
// For now union types aren't supported. A union means that the type
// could be of any type listed in the union and still be valid. But we
// don't know which path it will take since we'd basically have to
// validate the node value to know. Someday we may have to figure out
// how to properly handle this, though we may never need to if no other
// processor supports it. Strictly interpreting the spec, we don't
// need to handle unions as far as determining whether a control can
// bind to data of a given type. Just the types defined in the spec
// and restrictions of those types.
return NS_ERROR_XFORMS_UNION_TYPE;
}
default:
// We only anticipate the 4 types listed above. Definitely an error
// if we get something else.
return NS_ERROR_FAILURE;
}
} else if (schemaTypeValue == nsISchemaType::SCHEMA_TYPE_COMPLEX) {
nsCOMPtr<nsISchemaComplexType> complexType(do_QueryInterface(aType));
NS_ENSURE_STATE(complexType);
PRUint16 complexTypeValue = 0;
complexType->GetDerivation(&complexTypeValue);
NS_ENSURE_STATE(complexTypeValue);
if ((complexTypeValue ==
nsISchemaComplexType::DERIVATION_RESTRICTION_SIMPLE) ||
(complexTypeValue ==
nsISchemaComplexType::DERIVATION_EXTENSION_SIMPLE)) {
complexType->GetSimpleBaseType(getter_AddRefs(simpleType));
} else {
return NS_ERROR_FAILURE;
}
} else {
return NS_ERROR_FAILURE;
}
// For SIMPLE_TYPE_LIST and SIMPLE_TYPE_RESTRICTION we need to go around
// the horn again with the next simpleType. Same with
// DERIVATION_RESTRICTION_SIMPLE and DERIVATION_EXTENSION_SIMPLE. All other
// types should not reach here.
NS_ENSURE_STATE(simpleType);
if (!onlyFindBuiltinRoot) {
nsAutoString builtString;
rv = aType->GetTargetNamespace(builtString);
NS_ENSURE_SUCCESS(rv, rv);
nsAutoString typeName;
rv = aType->GetName(typeName);
NS_ENSURE_SUCCESS(rv, rv);
builtString.AppendLiteral("#");
builtString.Append(typeName);
aTypeArray->AppendString(builtString);
}
return WalkTypeChainInternal(simpleType, aBuiltinType, aTypeArray);
}
nsresult
nsXFormsModelElement::BuiltinTypeToPrimative(nsISchemaBuiltinType *aSchemaType,
PRUint16 *aPrimType)
{
NS_ENSURE_ARG(aSchemaType);
NS_ENSURE_ARG_POINTER(aPrimType);
PRUint16 builtinType = 0;
nsresult rv = aSchemaType->GetBuiltinType(&builtinType);
NS_ENSURE_SUCCESS(rv, rv);
// Note: this won't return BUILTIN_TYPE_ANY since that is the root of all
// types.
switch (builtinType) {
case nsISchemaBuiltinType::BUILTIN_TYPE_STRING:
case nsISchemaBuiltinType::BUILTIN_TYPE_BOOLEAN:
case nsISchemaBuiltinType::BUILTIN_TYPE_DECIMAL:
case nsISchemaBuiltinType::BUILTIN_TYPE_FLOAT:
case nsISchemaBuiltinType::BUILTIN_TYPE_DOUBLE:
case nsISchemaBuiltinType::BUILTIN_TYPE_DURATION:
case nsISchemaBuiltinType::BUILTIN_TYPE_DATETIME:
case nsISchemaBuiltinType::BUILTIN_TYPE_TIME:
case nsISchemaBuiltinType::BUILTIN_TYPE_DATE:
case nsISchemaBuiltinType::BUILTIN_TYPE_GYEARMONTH:
case nsISchemaBuiltinType::BUILTIN_TYPE_GYEAR:
case nsISchemaBuiltinType::BUILTIN_TYPE_GMONTHDAY:
case nsISchemaBuiltinType::BUILTIN_TYPE_GDAY:
case nsISchemaBuiltinType::BUILTIN_TYPE_GMONTH:
case nsISchemaBuiltinType::BUILTIN_TYPE_HEXBINARY:
case nsISchemaBuiltinType::BUILTIN_TYPE_BASE64BINARY:
case nsISchemaBuiltinType::BUILTIN_TYPE_ANYURI:
case nsISchemaBuiltinType::BUILTIN_TYPE_QNAME:
case nsISchemaBuiltinType::BUILTIN_TYPE_NOTATION:
*aPrimType = builtinType;
break;
case nsISchemaBuiltinType::BUILTIN_TYPE_NORMALIZED_STRING:
case nsISchemaBuiltinType::BUILTIN_TYPE_TOKEN:
case nsISchemaBuiltinType::BUILTIN_TYPE_LANGUAGE:
case nsISchemaBuiltinType::BUILTIN_TYPE_NMTOKEN:
case nsISchemaBuiltinType::BUILTIN_TYPE_NAME:
case nsISchemaBuiltinType::BUILTIN_TYPE_NCNAME:
case nsISchemaBuiltinType::BUILTIN_TYPE_ID:
case nsISchemaBuiltinType::BUILTIN_TYPE_IDREF:
case nsISchemaBuiltinType::BUILTIN_TYPE_ENTITY:
case nsISchemaBuiltinType::BUILTIN_TYPE_IDREFS:
case nsISchemaBuiltinType::BUILTIN_TYPE_ENTITIES:
case nsISchemaBuiltinType::BUILTIN_TYPE_NMTOKENS:
*aPrimType = nsISchemaBuiltinType::BUILTIN_TYPE_STRING;
break;
case nsISchemaBuiltinType::BUILTIN_TYPE_BYTE:
case nsISchemaBuiltinType::BUILTIN_TYPE_UNSIGNEDBYTE:
case nsISchemaBuiltinType::BUILTIN_TYPE_INTEGER:
case nsISchemaBuiltinType::BUILTIN_TYPE_NEGATIVEINTEGER:
case nsISchemaBuiltinType::BUILTIN_TYPE_NONPOSITIVEINTEGER:
case nsISchemaBuiltinType::BUILTIN_TYPE_LONG:
case nsISchemaBuiltinType::BUILTIN_TYPE_NONNEGATIVEINTEGER:
case nsISchemaBuiltinType::BUILTIN_TYPE_INT:
case nsISchemaBuiltinType::BUILTIN_TYPE_UNSIGNEDINT:
case nsISchemaBuiltinType::BUILTIN_TYPE_UNSIGNEDLONG:
case nsISchemaBuiltinType::BUILTIN_TYPE_POSITIVEINTEGER:
case nsISchemaBuiltinType::BUILTIN_TYPE_SHORT:
case nsISchemaBuiltinType::BUILTIN_TYPE_UNSIGNEDSHORT:
*aPrimType = nsISchemaBuiltinType::BUILTIN_TYPE_DECIMAL;
break;
default:
// should never hit here
NS_WARNING("nsXFormsModelElement::BuiltinTypeToPrimative: Unknown builtin type encountered.");
return NS_ERROR_FAILURE;
}
return NS_OK;
}
NS_IMETHODIMP
nsXFormsModelElement::GetDerivedTypeList(const nsAString &aType,
const nsAString &aNamespace,
nsAString &aBuiltinType)
{
nsCOMPtr<nsISchemaCollection> schemaColl = do_QueryInterface(mSchemas);
NS_ENSURE_STATE(schemaColl);
nsCOMPtr<nsISchemaType> schemaType;
schemaColl->GetType(aType, aNamespace, getter_AddRefs(schemaType));
NS_ENSURE_STATE(schemaType);
nsStringArray typeArray;
nsresult rv = WalkTypeChainInternal(schemaType, nsnull, &typeArray);
if (NS_SUCCEEDED(rv)) {
nsCOMPtr<nsIStringEnumerator> stringEnum;
rv = NS_NewStringEnumerator(getter_AddRefs(stringEnum), &typeArray);
if (NS_SUCCEEDED(rv)) {
nsAutoString constructorString;
PRBool hasMore = PR_FALSE;
rv = stringEnum->HasMore(&hasMore);
while (NS_SUCCEEDED(rv) && hasMore) {
nsAutoString tempString;
rv = stringEnum->GetNext(tempString);
if (NS_SUCCEEDED(rv)) {
constructorString.Append(tempString);
stringEnum->HasMore(&hasMore);
if (hasMore) {
constructorString.AppendLiteral(" ");
}
}
}
if (NS_SUCCEEDED(rv)) {
aBuiltinType.Assign(constructorString);
}
}
}
if (NS_FAILED(rv)) {
aBuiltinType.Assign(EmptyString());
}
typeArray.Clear();
return rv;
}
NS_IMETHODIMP
nsXFormsModelElement::GetRootBuiltinType(nsISchemaType *aType,
PRUint16 *aBuiltinType)
{
NS_ENSURE_ARG(aType);
NS_ENSURE_ARG_POINTER(aBuiltinType);
return WalkTypeChainInternal(aType, aBuiltinType, nsnull);
}
/* static */ void
nsXFormsModelElement::Startup()
{

Просмотреть файл

@ -397,6 +397,33 @@ private:
*/
void ValidateInstanceDocuments();
/**
* 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);
/**
* 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.
*/
NS_HIDDEN_(nsresult) WalkTypeChainInternal(nsISchemaType *aType,
PRUint16 *aBuiltinType,
nsStringArray *aTypeArray);
/**
* Returns the primative type that aSchemaType is derived/extended from
*/
NS_HIDDEN_(nsresult) BuiltinTypeToPrimative(nsISchemaBuiltinType *aSchemaType,
PRUint16 *aPrimType);
nsIDOMElement *mElement;
nsCOMPtr<nsISchemaLoader> mSchemas;
nsStringArray mPendingInlineSchemas;

Просмотреть файл

@ -54,19 +54,11 @@
#include "nsAutoBuffer.h"
#include "nsIEventStateManager.h"
#include "prmem.h"
#include "nsISchema.h"
#define NS_HTMLFORM_BUNDLE_URL \
"chrome://global/locale/layout/HtmlForm.properties"
enum nsBoundType {
TYPE_DEFAULT,
TYPE_ANYURI,
TYPE_BASE64,
TYPE_HEX
};
/**
* Implementation of the \<upload\> element.
*/
@ -81,9 +73,10 @@ public:
private:
/**
* Returns the type of the node to which this element is bound.
* Returns the nsISchemaBuiltinType of the node to which this element is
* bound.
*/
nsBoundType GetBoundType();
PRUint16 GetBoundType();
/**
* Sets file path/contents into instance data. If aFile is nsnull,
@ -102,7 +95,7 @@ private:
* Read the contents of the file and encode in Base64 or Hex. |aResult| must
* be freed by nsMemory::Free().
*/
nsresult EncodeFileContents(nsIFile *aFile, nsBoundType aType,
nsresult EncodeFileContents(nsIFile *aFile, PRUint16 aType,
PRUnichar **aResult);
void BinaryToHex(const char *aBuffer, PRUint32 aCount,
@ -127,43 +120,42 @@ nsXFormsUploadElement::Refresh()
if (!mBoundNode)
return NS_OK;
// If it is not bound to 'anyURI', 'base64Binary', or 'hexBinary', then
// mark as not relevant.
// XXX Bug 313313 - the 'relevant' state should be handled in XBL constructor.
nsCOMPtr<nsIXTFElementWrapper> xtfWrap(do_QueryInterface(mElement));
NS_ENSURE_STATE(xtfWrap);
if (GetBoundType() == TYPE_DEFAULT) {
xtfWrap->SetIntrinsicState(NS_EVENT_STATE_DISABLED);
nsXFormsUtils::ReportError(NS_LITERAL_STRING("uploadBoundTypeError"),
mElement);
} else {
xtfWrap->SetIntrinsicState(NS_EVENT_STATE_ENABLED);
// If it is not bound to 'anyURI', 'base64Binary', 'hexBinary', or an
// extension or derivation of one of these three types, then put an error in
// the console. CSS and XBL will make sure that the control won't appear in
// the form.
PRUint16 boundType = GetBoundType();
if (boundType == nsISchemaBuiltinType::BUILTIN_TYPE_HEXBINARY ||
boundType == nsISchemaBuiltinType::BUILTIN_TYPE_BASE64BINARY ||
boundType == nsISchemaBuiltinType::BUILTIN_TYPE_ANYURI) {
return NS_OK;
}
nsXFormsUtils::ReportError(NS_LITERAL_STRING("uploadBoundTypeError"),
mElement);
return NS_OK;
}
nsBoundType
PRUint16
nsXFormsUploadElement::GetBoundType()
{
nsBoundType result = TYPE_DEFAULT;
if (!mModel)
return result;
return 0;
// get type bound to node
nsAutoString type, nsuri;
nsresult rv = mModel->GetTypeFromNode(mBoundNode, type, nsuri);
if (NS_SUCCEEDED(rv) && nsuri.EqualsLiteral(NS_NAMESPACE_XML_SCHEMA)) {
if (type.EqualsLiteral("anyURI")) {
result = TYPE_ANYURI;
} else if (type.EqualsLiteral("base64Binary")) {
result = TYPE_BASE64;
} else if (type.EqualsLiteral("hexBinary")) {
result = TYPE_HEX;
}
// get type of bound instance data
nsCOMPtr<nsISchemaType> schemaType;
nsresult rv = mModel->GetTypeForControl(this, getter_AddRefs(schemaType));
if (NS_FAILED(rv)) {
return 0;
}
return result;
PRUint16 builtinType = 0;
rv = mModel->GetRootBuiltinType(schemaType, &builtinType);
if (NS_FAILED(rv) || !builtinType) {
return 0;
}
return builtinType;
}
static void
@ -278,14 +270,15 @@ nsXFormsUploadElement::SetFile(nsILocalFile *aFile)
} else {
// set file into instance data
nsBoundType type = GetBoundType();
if (type == TYPE_ANYURI) {
PRUint16 type = GetBoundType();
if (type == nsISchemaBuiltinType::BUILTIN_TYPE_ANYURI) {
// set fully qualified path as value in instance data node
nsCAutoString spec;
NS_GetURLSpecFromFile(aFile, spec);
rv = mModel->SetNodeValue(mBoundNode, NS_ConvertUTF8toUTF16(spec),
PR_FALSE, &dataChanged);
} else if (type == TYPE_BASE64 || type == TYPE_HEX) {
} else if (type == nsISchemaBuiltinType::BUILTIN_TYPE_BASE64BINARY ||
type == nsISchemaBuiltinType::BUILTIN_TYPE_HEXBINARY) {
// encode file contents in base64/hex and set into instance data node
PRUnichar *fileData;
rv = EncodeFileContents(aFile, type, &fileData);
@ -433,7 +426,7 @@ ReportEncodingMemoryError(nsIDOMElement* aElement, nsIFile *aFile,
}
nsresult
nsXFormsUploadElement::EncodeFileContents(nsIFile *aFile, nsBoundType aType,
nsXFormsUploadElement::EncodeFileContents(nsIFile *aFile, PRUint16 aType,
PRUnichar **aResult)
{
nsresult rv;
@ -461,7 +454,7 @@ nsXFormsUploadElement::EncodeFileContents(nsIFile *aFile, nsBoundType aType,
"fileStream->Read failed");
if (NS_SUCCEEDED(rv)) {
if (aType == TYPE_BASE64) {
if (aType == nsISchemaBuiltinType::BUILTIN_TYPE_BASE64BINARY) {
// encode file contents
*aResult = nsnull;
char *buffer = PL_Base64Encode(fileData.get(), bytesRead, nsnull);
@ -475,7 +468,7 @@ nsXFormsUploadElement::EncodeFileContents(nsIFile *aFile, nsBoundType aType,
ReportEncodingMemoryError(mElement, aFile, failedSize);
rv = NS_ERROR_OUT_OF_MEMORY;
}
} else if (aType == TYPE_HEX) {
} else if (aType == nsISchemaBuiltinType::BUILTIN_TYPE_HEXBINARY) {
// create buffer for hex encoded data
PRUint32 length = bytesRead * 2 + 1;
PRUnichar *fileDataHex =

Просмотреть файл

@ -84,6 +84,8 @@ NS_ERROR_GENERATE_SUCCESS(NS_ERROR_MODULE_GENERAL, 2)
#define NS_ERROR_XFORMS_CALCUATION_EXCEPTION \
NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GENERAL, 3001)
#define NS_ERROR_XFORMS_UNION_TYPE \
NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GENERAL, 3002)
/**
* XForms event types

Просмотреть файл

@ -272,6 +272,21 @@ html|*:root input[mozType|type="http://www.w3.org/2001/XMLSchema#gDay"] {
-moz-binding: url('chrome://xforms/content/input-xhtml.xml#xformswidget-input-day');
}
html|*:root input[mozType|typelist~="http://www.w3.org/2001/XMLSchema#base64Binary"],
html|*:root input[mozType|typelist~="http://www.w3.org/2001/XMLSchema#hexBinary"],
html|*:root secret[mozType|typelist~="http://www.w3.org/2001/XMLSchema#base64Binary"],
html|*:root secret[mozType|typelist~="http://www.w3.org/2001/XMLSchema#hexBinary"],
html|*:root textarea[mozType|typelist~="http://www.w3.org/2001/XMLSchema#base64Binary"],
html|*:root textarea[mozType|typelist~="http://www.w3.org/2001/XMLSchema#hexBinary"],
xul|*:root input[mozType|typelist~="http://www.w3.org/2001/XMLSchema#base64Binary"],
xul|*:root input[mozType|typelist~="http://www.w3.org/2001/XMLSchema#hexBinary"],
xul|*:root secret[mozType|typelist~="http://www.w3.org/2001/XMLSchema#base64Binary"],
xul|*:root secret[mozType|typelist~="http://www.w3.org/2001/XMLSchema#hexBinary"],
xul|*:root textarea[mozType|typelist~="http://www.w3.org/2001/XMLSchema#base64Binary"],
xul|*:root textarea[mozType|typelist~="http://www.w3.org/2001/XMLSchema#hexBinary"] {
display: none;
}
/* secret widgets */
html|*:root secret {
-moz-binding: url('chrome://xforms/content/input-xhtml.xml#xformswidget-secret');
@ -625,12 +640,14 @@ xul|*:root select, xul|*:root select1 {
/* upload widgets */
html|*:root upload {
-moz-binding: url('chrome://xforms/content/xforms-xhtml.xml#xformswidget-upload-disabled');
display: none;
}
html|*:root upload[mozType|type="http://www.w3.org/2001/XMLSchema#anyURI"],
html|*:root upload[mozType|type="http://www.w3.org/2001/XMLSchema#base64Binary"],
html|*:root upload[mozType|type="http://www.w3.org/2001/XMLSchema#hexBinary"] {
html|*:root upload[mozType|typelist~="http://www.w3.org/2001/XMLSchema#anyURI"],
html|*:root upload[mozType|typelist~="http://www.w3.org/2001/XMLSchema#base64Binary"],
html|*:root upload[mozType|typelist~="http://www.w3.org/2001/XMLSchema#hexBinary"] {
-moz-binding: url('chrome://xforms/content/xforms-xhtml.xml#xformswidget-upload');
display: inline;
}
/* repeat widgets */
@ -660,4 +677,5 @@ xul|*:root repeat[appearance="compact"] *|*[anonid="insertion"] {
}
xul|*:root repeat .xf-repeat-item {
-moz-box-flex: 1;
}
}