Back to index

lightning-sunbird  0.9+nobinonly
nsXFormsRangeElement.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is Mozilla XForms support.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Novell, Inc.
00019  * Portions created by the Initial Developer are Copyright (C) 2005
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *  Allan Beaufour <allan@beaufour.dk>
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either the GNU General Public License Version 2 or later (the "GPL"), or
00027  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 
00039 #include "nsXFormsDelegateStub.h"
00040 #include "nsXFormsRangeAccessors.h"
00041 #include "nsIEventStateManager.h"
00042 #include "nsISchema.h"
00043 #include "nsIStringBundle.h"
00044 #include "nsServiceManagerUtils.h"
00045 
00052 class nsXFormsRangeElement : public nsXFormsDelegateStub
00053 {
00054 public:
00055 
00056   // nsIXFormsControl
00057   NS_IMETHOD GetDefaultIntrinsicState(PRInt32 *aState);
00058   NS_IMETHOD GetDisabledIntrinsicState(PRInt32 *aState);
00059 
00060   // nsIXFormsDelegate overrides
00061   NS_IMETHOD GetXFormsAccessors(nsIXFormsAccessors **aAccessor);
00062 
00063   // nsXFormsDelegateStub override
00064   NS_IMETHOD IsTypeAllowed(PRUint16 aType, PRBool *aIsAllowed,
00065                            nsRestrictionFlag *aRestriction,
00066                            nsAString &aAllowedTypes);
00067 
00068 #ifdef DEBUG_smaug
00069   virtual const char* Name() { return "range"; }
00070 #endif
00071 };
00072 
00073 // nsIXFormsControl
00074 
00075 NS_IMETHODIMP
00076 nsXFormsRangeElement::IsTypeAllowed(PRUint16 aType, PRBool *aIsAllowed,
00077                                     nsRestrictionFlag *aRestriction,
00078                                     nsAString &aAllowedTypes)
00079 {
00080   NS_ENSURE_ARG_POINTER(aRestriction);
00081   NS_ENSURE_ARG_POINTER(aIsAllowed);
00082   *aRestriction = eTypes_Inclusive;
00083   *aIsAllowed = PR_FALSE;
00084 
00085   // Range needs to have the type duration, date, time, dateTime, gYearMonth,
00086   // gYear, gMonthDay, gDay, gMonth, float, decimal or double.  Or an
00087   // extension or derivation of one of these types.  If not, then put an error
00088   // in the console.  CSS and XBL will make sure that the control won't appear
00089   // in the form.
00090 
00091   if (aType == nsISchemaBuiltinType::BUILTIN_TYPE_DURATION ||
00092       aType == nsISchemaBuiltinType::BUILTIN_TYPE_DATE ||
00093       aType == nsISchemaBuiltinType::BUILTIN_TYPE_TIME ||
00094       aType == nsISchemaBuiltinType::BUILTIN_TYPE_DATETIME ||
00095       aType == nsISchemaBuiltinType::BUILTIN_TYPE_GYEARMONTH ||
00096       aType == nsISchemaBuiltinType::BUILTIN_TYPE_GYEAR ||
00097       aType == nsISchemaBuiltinType::BUILTIN_TYPE_GMONTHDAY ||
00098       aType == nsISchemaBuiltinType::BUILTIN_TYPE_GDAY ||
00099       aType == nsISchemaBuiltinType::BUILTIN_TYPE_GMONTH ||
00100       aType == nsISchemaBuiltinType::BUILTIN_TYPE_FLOAT ||
00101       aType == nsISchemaBuiltinType::BUILTIN_TYPE_DECIMAL ||
00102       aType == nsISchemaBuiltinType::BUILTIN_TYPE_DOUBLE) {
00103 
00104     *aIsAllowed = PR_TRUE;
00105     return NS_OK;
00106   }
00107 
00108   // build the string of types that range can bind to
00109   aAllowedTypes.AssignLiteral("xsd:duration xsd:date xsd:time xsd:dateTime xsd:gYearMonth xsd:gYear xsd:gMonthDay xsd:gDay xsd:gMonth xsd:float xsd:decimal xsd:double");
00110   return NS_OK;
00111 }
00112 
00113 NS_IMETHODIMP
00114 nsXFormsRangeElement::GetDefaultIntrinsicState(PRInt32 *aState)
00115 {
00116   NS_ENSURE_ARG_POINTER(aState);
00117   nsXFormsDelegateStub::GetDefaultIntrinsicState(aState);
00118   *aState |= NS_EVENT_STATE_INRANGE;
00119   return NS_OK;
00120 }
00121 
00122 NS_IMETHODIMP
00123 nsXFormsRangeElement::GetDisabledIntrinsicState(PRInt32 *aState)
00124 {
00125   NS_ENSURE_ARG_POINTER(aState);
00126   nsXFormsDelegateStub::GetDisabledIntrinsicState(aState);
00127   *aState |= NS_EVENT_STATE_INRANGE;
00128   return NS_OK;
00129 }
00130 
00131 // nsIXFormsDelegate
00132 
00133 NS_IMETHODIMP
00134 nsXFormsRangeElement::GetXFormsAccessors(nsIXFormsAccessors **aAccessor)
00135 {
00136   if (!mAccessor) {
00137     mAccessor = new nsXFormsRangeAccessors(this, mElement);
00138     if (!mAccessor) {
00139       return NS_ERROR_OUT_OF_MEMORY;
00140     }
00141   }
00142   NS_ADDREF(*aAccessor = mAccessor);
00143   return NS_OK;
00144 }
00145 
00146 
00147 // Creator
00148 
00149 NS_HIDDEN_(nsresult)
00150 NS_NewXFormsRangeElement(nsIXTFElement **aResult)
00151 {
00152   *aResult = new nsXFormsRangeElement();
00153   if (!*aResult)
00154     return NS_ERROR_OUT_OF_MEMORY;
00155 
00156   NS_ADDREF(*aResult);
00157   return NS_OK;
00158 }