Back to index

lightning-sunbird  0.9+nobinonly
nsXFormsControlStub.h
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) 2004
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *  Allan Beaufour <abeaufour@novell.com>
00024  *  Olli Pettay <Olli.Pettay@helsinki.fi>
00025  *
00026  * Alternatively, the contents of this file may be used under the terms of
00027  * either the GNU General Public License Version 2 or later (the "GPL"), or
00028  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00029  * in which case the provisions of the GPL or the LGPL are applicable instead
00030  * of those above. If you wish to allow use of your version of this file only
00031  * under the terms of either the GPL or the LGPL, and not to allow others to
00032  * use your version of this file under the terms of the MPL, indicate your
00033  * decision by deleting the provisions above and replace them with the notice
00034  * and other provisions required by the GPL or the LGPL. If you do not delete
00035  * the provisions above, a recipient may use your version of this file under
00036  * the terms of any one of the MPL, the GPL or the LGPL.
00037  *
00038  * ***** END LICENSE BLOCK ***** */
00039 
00040 #ifndef nsXFormsControlStub_h_
00041 #define nsXFormsControlStub_h_
00042 
00043 #include "nsCOMPtr.h"
00044 #include "nsString.h"
00045 
00046 #include "nsIDOMElement.h"
00047 #include "nsIDOMNode.h"
00048 #include "nsIXTFElement.h"
00049 #include "nsXFormsAtoms.h"
00050 #include "nsIDOMEventListener.h"
00051 
00052 #include "nsIModelElementPrivate.h"
00053 #include "nsIXFormsControl.h"
00054 #include "nsIXFormsRepeatElement.h"
00055 #include "nsXFormsStubElement.h"
00056 #include "nsXFormsUtils.h"
00057 #include "nsIXTFBindableElementWrapper.h"
00058 #include "nsIXFormsControlBase.h"
00059 
00060 class nsIDOMEvent;
00061 class nsIDOMXPathResult;
00062 
00067 class nsXFormsControlStubBase : public nsIXFormsControl
00068 {
00069 public:
00070 
00072   const PRUint32 kStandardNotificationMask;
00073 
00078   const PRUint32 kElementFlags;
00079 
00080   // nsIXFormsControl
00081   NS_IMETHOD GetBoundNode(nsIDOMNode **aBoundNode);
00082   NS_IMETHOD BindToModel(PRBool aSetBoundNode = PR_FALSE);
00083   NS_IMETHOD GetDependencies(nsCOMArray<nsIDOMNode> **aDependencies);
00084   NS_IMETHOD GetElement(nsIDOMElement **aElement);
00085   NS_IMETHOD ResetBoundNode(const nsString &aBindAttribute,
00086                             PRUint16        aResultType,
00087                             PRBool         *aContextChanged);
00088   NS_IMETHOD Bind(PRBool *aContextChanged);
00089   NS_IMETHOD Refresh();
00090   NS_IMETHOD GetOnDeferredBindList(PRBool *onList);
00091   NS_IMETHOD SetOnDeferredBindList(PRBool putOnList);
00092   NS_IMETHOD TryFocus(PRBool* aOK);
00093   NS_IMETHOD IsEventTarget(PRBool *aOK);
00094   NS_IMETHOD GetUsesModelBinding(PRBool *aRes);
00095   NS_IMETHOD GetUsesSingleNodeBinding(PRBool *aRes);
00096   NS_IMETHOD GetDefaultIntrinsicState(PRInt32 *aRes);
00097   NS_IMETHOD GetDisabledIntrinsicState(PRInt32 *aRes);
00098   NS_IMETHOD RebindAndRefresh();
00099   NS_IMETHOD GetAbortedBindListContainer(nsIXFormsContextControl **aContainer);
00100   NS_IMETHOD SetAbortedBindListContainer(nsIXFormsContextControl *aContainer);
00101 
00102   nsresult Create(nsIXTFElementWrapper *aWrapper);
00103   // for nsIXTFElement
00104   nsresult HandleDefault(nsIDOMEvent *aEvent,
00105                          PRBool      *aHandled);
00106   nsresult OnDestroyed();
00107   nsresult WillChangeDocument(nsIDOMDocument *aNewDocument);
00108   nsresult DocumentChanged(nsIDOMDocument *aNewDocument);
00109   nsresult WillChangeParent(nsIDOMElement *aNewParent);
00110   nsresult ParentChanged(nsIDOMElement *aNewParent);
00111   nsresult WillSetAttribute(nsIAtom *aName, const nsAString &aValue);
00112   nsresult AttributeSet(nsIAtom *aName, const nsAString &aValue);
00113   nsresult WillRemoveAttribute(nsIAtom *aName);
00114   nsresult AttributeRemoved(nsIAtom *aName);
00115 
00132   void AddRemoveSNBAttr(nsIAtom *aName, const nsAString &aValue);
00133 
00140   virtual PRBool IsContentAllowed();
00141 
00147   virtual PRBool IsContentComplex();
00148 
00154   virtual nsRepeatState GetRepeatState();
00155   virtual void SetRepeatState(nsRepeatState aState);
00156 
00157   // nsIXFormsContextControl
00158   NS_DECL_NSIXFORMSCONTEXTCONTROL
00159 
00160 #ifdef DEBUG_smaug
00161   virtual const char* Name() { return "[undefined]"; }
00162 #endif
00163   
00164 
00166   nsXFormsControlStubBase() :
00167     kStandardNotificationMask(nsIXTFElement::NOTIFY_WILL_SET_ATTRIBUTE |
00168                               nsIXTFElement::NOTIFY_ATTRIBUTE_SET |
00169                               nsIXTFElement::NOTIFY_WILL_REMOVE_ATTRIBUTE | 
00170                               nsIXTFElement::NOTIFY_ATTRIBUTE_REMOVED | 
00171                               nsIXTFElement::NOTIFY_WILL_CHANGE_DOCUMENT |
00172                               nsIXTFElement::NOTIFY_DOCUMENT_CHANGED |
00173                               nsIXTFElement::NOTIFY_WILL_CHANGE_PARENT |
00174                               nsIXTFElement::NOTIFY_PARENT_CHANGED |
00175                               nsIXTFElement::NOTIFY_HANDLE_DEFAULT),
00176     kElementFlags(nsXFormsUtils::ELEMENT_WITH_MODEL_ATTR),
00177     mHasParent(PR_FALSE),
00178     mHasDoc(PR_FALSE),
00179     mPreventLoop(PR_FALSE),
00180     mUsesModelBinding(PR_FALSE),
00181     mAppearDisabled(PR_FALSE),
00182     mOnDeferredBindList(PR_FALSE),
00183     mBindAttrsCount(0),
00184     mRepeatState(eType_Unknown)
00185     {};
00186 
00187 protected:
00189   nsIDOMElement*                      mElement;
00190 
00192   nsCOMPtr<nsIDOMNode>                mBoundNode;
00193 
00195   nsCOMArray<nsIDOMNode>              mDependencies;
00196 
00198   nsCOMPtr<nsIModelElementPrivate>    mModel;
00199 
00201   nsCOMPtr<nsIDOMEventListener>       mEventListener;
00202 
00204   PRPackedBool                        mHasParent;
00205 
00207   PRPackedBool                        mHasDoc;
00208 
00212   PRPackedBool                        mPreventLoop;
00213 
00217   PRPackedBool                        mUsesModelBinding;
00218 
00223   PRPackedBool                        mAppearDisabled;
00224 
00228   PRPackedBool                        mOnDeferredBindList;
00229 
00234   PRInt8 mBindAttrsCount;
00235 
00236   nsRepeatState mRepeatState;
00237 
00242   nsCOMArray<nsIXFormsRepeatElement>  mIndexesUsed;
00243 
00253   nsCOMArray<nsIXFormsControl> mAbortedBindList;
00254 
00259   nsCOMPtr<nsIXFormsContextControl> mAbortedBindListContainer;
00260 
00264   PRBool HasBindingAttribute() const { return mBindAttrsCount != 0; };
00265 
00267   PRBool GetRelevantState();
00268 
00281   nsresult
00282     ProcessNodeBinding(const nsString          &aBindingAttr,
00283                        PRUint16                 aResultType,
00284                        nsIDOMXPathResult      **aResult,
00285                        nsIModelElementPrivate **aModel = nsnull);
00286   
00291   void ResetHelpAndHint(PRBool aInitialize);
00292 
00300   virtual PRBool IsBindingAttribute(const nsIAtom *aAttr) const;
00301  
00307   virtual void AfterSetAttribute(nsIAtom *aName);
00308 
00317   void BeforeSetAttribute(nsIAtom *aName, const nsAString &aValue);
00318 
00320   void RemoveIndexListeners();
00321 
00327   nsresult ForceModelDetach(PRBool aRebind);
00328 
00335   nsresult MaybeAddToModel(nsIModelElementPrivate *aOldModel,
00336                            nsIXFormsControl       *aParent);
00337 
00342   nsresult GetBoundBuiltinType(PRUint16 *aBuiltinType);
00343 
00351   virtual nsRepeatState UpdateRepeatState(nsIDOMNode *aParent);
00352 
00353 };
00354 
00358 class nsXFormsBindableControlStub : public nsXFormsControlStubBase,
00359                                     public nsXFormsBindableStub
00360 {
00361 public:
00362   NS_DECL_ISUPPORTS_INHERITED
00363   // nsIXTFBindableElement overrides
00365   NS_IMETHOD OnCreated(nsIXTFBindableElementWrapper *aWrapper)
00366   {
00367     nsresult rv = nsXFormsBindableStub::OnCreated(aWrapper);
00368     return NS_SUCCEEDED(rv) ? nsXFormsControlStubBase::Create(aWrapper) : rv;
00369   }
00370 
00371   // nsIXTFElement overrides
00372   NS_IMETHOD HandleDefault(nsIDOMEvent *aEvent,
00373                            PRBool      *aHandled)
00374   {
00375     return nsXFormsControlStubBase::HandleDefault(aEvent, aHandled);
00376   }
00377 
00378   NS_IMETHOD OnDestroyed() {
00379     return nsXFormsControlStubBase::OnDestroyed();
00380   }
00381 
00382   NS_IMETHOD WillChangeDocument(nsIDOMDocument *aNewDocument)
00383   {
00384     return nsXFormsControlStubBase::WillChangeDocument(aNewDocument);
00385   }
00386 
00387   NS_IMETHOD DocumentChanged(nsIDOMDocument *aNewDocument)
00388   {
00389     return nsXFormsControlStubBase::DocumentChanged(aNewDocument);
00390   }
00391 
00392   NS_IMETHOD WillChangeParent(nsIDOMElement *aNewParent)
00393   {
00394     return nsXFormsControlStubBase::WillChangeParent(aNewParent);
00395   }
00396 
00397   NS_IMETHOD ParentChanged(nsIDOMElement *aNewParent)
00398   {
00399     return nsXFormsControlStubBase::ParentChanged(aNewParent);
00400   }
00401 
00402   NS_IMETHOD WillSetAttribute(nsIAtom *aName, const nsAString &aValue)
00403   {
00404     return nsXFormsControlStubBase::WillSetAttribute(aName, aValue);
00405   }
00406 
00407   NS_IMETHOD AttributeSet(nsIAtom *aName, const nsAString &aValue)
00408   {
00409     return nsXFormsControlStubBase::AttributeSet(aName, aValue);
00410   }
00411 
00412   NS_IMETHOD WillRemoveAttribute(nsIAtom *aName)
00413   {
00414     return nsXFormsControlStubBase::WillRemoveAttribute(aName);
00415   }
00416 
00417   NS_IMETHOD AttributeRemoved(nsIAtom *aName)
00418   {
00419     return nsXFormsControlStubBase::AttributeRemoved(aName);
00420   }
00421   
00423   nsXFormsBindableControlStub() : nsXFormsControlStubBase() {};
00424 };
00425 #endif