Back to index

lightning-sunbird  0.9+nobinonly
nsXFormsRangeConditionAccessors.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  * IBM Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 2006
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Aaron Reed <aaronr@us.ibm.com>
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either of the GNU General Public License Version 2 or later (the "GPL"),
00027  * or 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 "nsXFormsRangeConditionAccessors.h"
00040 #include "nsIContent.h"
00041 #include "nsIDOMElement.h"
00042 #include "nsIXTFElementWrapper.h"
00043 #include "nsIXFormsControl.h"
00044 #include "nsIEventStateManager.h"
00045 #include "nsXFormsUtils.h"
00046 
00047 NS_IMPL_ISUPPORTS_INHERITED2(nsXFormsRangeConditionAccessors,
00048                              nsXFormsAccessors,
00049                              nsIXFormsRangeConditionAccessors,
00050                              nsIClassInfo)
00051 
00052 // nsXFormsRangeConditionAccessors
00053 
00054 NS_IMETHODIMP
00055 nsXFormsRangeConditionAccessors::IsInRange(PRBool *aInRange)
00056 {
00057   return GetState(NS_EVENT_STATE_INRANGE, aInRange);
00058 }
00059 
00060 NS_IMETHODIMP
00061 nsXFormsRangeConditionAccessors::SetInRange(PRBool aInRange)
00062 {
00063   PRBool currRange;
00064   nsresult rv = IsInRange(&currRange);
00065   NS_ENSURE_SUCCESS(rv, rv);
00066   if (currRange == aInRange) {
00067     return NS_OK;
00068   }
00069 
00070   /* when this call changes the control's previous in or out of range state,
00071    * then we need to set the state to the new value and dispatch
00072    * xforms-in-range or xforms-out-of-range
00073    */
00074   nsCOMPtr<nsIXFormsControl> control(do_QueryInterface(mDelegate));
00075   NS_ENSURE_STATE(control);
00076 
00077   nsCOMPtr<nsIDOMElement> element;
00078   control->GetElement(getter_AddRefs(element));
00079   nsCOMPtr<nsIXTFElementWrapper> xtfWrap(do_QueryInterface(element));
00080   NS_ENSURE_STATE(xtfWrap);
00081   nsCOMPtr<nsIContent> content(do_QueryInterface(element));
00082   NS_ENSURE_STATE(content);
00083 
00084   PRInt32 state = content->IntrinsicState();
00085   if (!aInRange) {
00086     state &= ~NS_EVENT_STATE_INRANGE;
00087     state |= NS_EVENT_STATE_OUTOFRANGE;
00088   } else {
00089     state &= ~NS_EVENT_STATE_OUTOFRANGE;
00090     state |= NS_EVENT_STATE_INRANGE;
00091   }
00092 
00093   rv = xtfWrap->SetIntrinsicState(state);
00094   NS_ENSURE_SUCCESS(rv, rv);
00095 
00096   nsXFormsUtils::DispatchEvent(element,
00097                                aInRange ? eEvent_InRange : eEvent_OutOfRange);
00098 
00099   return NS_OK;
00100 }
00101 
00102 // nsIClassInfo implementation
00103 
00104 static const nsIID sScriptingIIDs[] = {
00105   NS_IXFORMSACCESSORS_IID,
00106   NS_IXFORMSRANGECONDITIONACCESSORS_IID
00107 };
00108 
00109 NS_IMETHODIMP
00110 nsXFormsRangeConditionAccessors::GetInterfaces(PRUint32 *aCount,
00111                                                nsIID * **aArray)
00112 {
00113   return nsXFormsUtils::CloneScriptingInterfaces(sScriptingIIDs,
00114                                                  NS_ARRAY_LENGTH(sScriptingIIDs),
00115                                                  aCount, aArray);
00116 }