Back to index

lightning-sunbird  0.9+nobinonly
nsXFormsMDGEngine.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  *  David Landwehr <dlandwehr@novell.com>
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 __NSXFORMSMDGENGINE__
00041 #define __NSXFORMSMDGENGINE__
00042 
00043 #include "nscore.h"
00044 #include "nsClassHashtable.h"
00045 #include "nsCOMArray.h"
00046 #include "nsCOMPtr.h"
00047 #include "nsVoidArray.h"
00048 
00049 #include "nsIDOMNode.h"
00050 
00051 #include "nsXFormsTypes.h"
00052 #include "nsXFormsNodeState.h"
00053 
00054 class nsIDOMNSXPathExpression;
00055 class nsXFormsModelElement;
00056 
00063 class nsXFormsMDGNode {
00064 private:
00066   PRBool mDirty;
00067 
00069   PRBool mHasExpr;
00070   
00071 public:
00073   nsCOMPtr<nsIDOMNode> mContextNode;
00074   
00076   nsCOMPtr<nsIDOMNSXPathExpression> mExpression;
00077   
00079   nsVoidArray mSuc;
00080   
00082   unsigned int mCount;
00083   
00085   ModelItemPropName mType;
00086   
00088   PRInt32 mContextSize;
00089   
00091   PRInt32 mContextPosition;
00092   
00094   PRBool mDynFunc;
00095 
00100   nsXFormsMDGNode* mNext;
00101 
00108   nsXFormsMDGNode(nsIDOMNode             *aNode,
00109                   const ModelItemPropName aType);
00110   
00112   ~nsXFormsMDGNode();
00113   
00122   void SetExpression(nsIDOMNSXPathExpression *aExpression,
00123                      PRBool                   aDynFunc,
00124                      PRInt32                  aContextPosition,
00125                      PRInt32                  aContextSize);
00126                      
00128   PRBool HasExpr() const;
00129   
00131   PRBool IsDirty() const;
00132   
00133   /* Mark node clean */
00134   void MarkClean();
00135 
00136   /* Mark node dirty */
00137   void MarkDirty();
00138 };
00139 
00140 
00155 class nsXFormsMDGEngine
00156 {
00157 protected:
00159   nsClassHashtable<nsISupportsHashKey, nsXFormsMDGNode> mNodeToMDG; 
00160   
00162   nsClassHashtable<nsISupportsHashKey, nsXFormsNodeState> mNodeStates;
00163 
00165   nsXFormsNodeState mDefaultState;
00166   
00168   PRBool mJustRebuilt;
00169   
00171   PRBool mFirstCalculate;
00172   
00174   nsVoidArray mGraph;
00175 
00177   nsXFormsModelElement *mModel;
00178   
00182   nsCOMArray<nsIDOMNode> mMarkedNodes;
00183   
00185   PRInt32 mNodesInGraph;
00186   
00188   nsXFormsMDGEngine(nsXFormsMDGEngine&) {}
00189   
00194   static PLDHashOperator PR_CALLBACK
00195     DeleteLinkedNodes(nsISupports                *aKey,
00196                       nsAutoPtr<nsXFormsMDGNode> &aNode,
00197                       void                       *aArg);
00198   
00203   static PLDHashOperator PR_CALLBACK
00204     AddStartNodes(nsISupports     *aKey,
00205                   nsXFormsMDGNode *aNode,
00206                   void            *aDeque);
00207   
00211   static PLDHashOperator PR_CALLBACK
00212     AndFlag(nsISupports                  *aKey,
00213             nsAutoPtr<nsXFormsNodeState> &aState,
00214             void                         *aMask);
00215 
00223   nsXFormsNodeState* GetNCNodeState(nsIDOMNode *aContextNode);
00224 
00232   nsresult CreateNewChild(nsIDOMNode      *aContextNode,
00233                           const nsAString &aNodeValue,
00234                           nsIDOMNode      *aBeforeNode = nsnull);
00235 
00248   nsXFormsMDGNode* GetNode(nsIDOMNode       *aDomNode,
00249                            ModelItemPropName aType,
00250                            PRBool            aCreate = PR_TRUE);
00251 
00258   PRBool   AndFlags(PRUint16 aAndMask);
00259   
00266   nsresult BooleanExpression(nsXFormsMDGNode *aNode,
00267                              PRBool          &aRes);
00268   
00277   nsresult ComputeMIP(eFlag_t          aStateFlag,
00278                       eFlag_t          aDispatchFlag,
00279                       nsXFormsMDGNode *aNode,
00280                       PRBool          &aDidChange);
00281   
00291   nsresult ComputeMIPWithInheritance(eFlag_t                 aStateFlag,
00292                                      eFlag_t                 aDispatchFlag,
00293                                      eFlag_t                 aInheritanceFlag,
00294                                      nsXFormsMDGNode        *aNode,
00295                                      nsCOMArray<nsIDOMNode> *aSet);
00296 
00305   nsresult AttachInheritance(nsCOMArray<nsIDOMNode> *aSet,
00306                              nsIDOMNode             *aSrc,
00307                              PRBool                 aState,
00308                              eFlag_t                aStateFlag);
00309 
00313   nsresult Invalidate();
00314   
00324   nsresult SetNodeValueInternal(nsIDOMNode      *aContextNode,
00325                                 const nsAString &aNodeValue,
00326                                 PRBool           aMarkNode = PR_TRUE,
00327                                 PRBool           aIsCalculate = PR_FALSE,
00328                                 PRBool          *aNodeChanged = nsnull);
00329 
00336   nsresult HandleMarkedNodes(nsCOMArray<nsIDOMNode> *aArray);
00337 
00338 public:
00342   nsXFormsMDGEngine();
00343 
00344   /*
00345    * Destructor
00346    */
00347   ~nsXFormsMDGEngine();
00348   
00354   nsresult Init(nsXFormsModelElement *aModel);
00355 
00367   nsresult AddMIP(ModelItemPropName         aType,
00368                   nsIDOMNSXPathExpression  *aExpression,
00369                   nsCOMArray<nsIDOMNode>   *aDependencies,
00370                   PRBool                    aDynFunc,
00371                   nsIDOMNode               *aContextNode,
00372                   PRInt32                   aContextPos,
00373                   PRInt32                   aContextSize);
00374 
00380   nsresult Recalculate(nsCOMArray<nsIDOMNode> *aChangedNodes);
00381 
00387   nsresult Revalidate(nsCOMArray<nsIDOMNode> *aNodes);
00388 
00392   nsresult Rebuild();
00393 
00397   nsresult Clear();
00398 
00402   nsresult ClearDispatchFlags();
00403 
00409   nsresult MarkNodeAsChanged(nsIDOMNode *aContextNode);
00410 
00418   nsresult SetNodeValue(nsIDOMNode      *aContextNode,
00419                         const nsAString &aNodeValue,
00420                         PRBool          *aNodeChanged = nsnull);
00421 
00429   nsresult SetNodeContent(nsIDOMNode      *aContextNode,
00430                           nsIDOMNode      *aContentEnvelope);
00431 
00439   const nsXFormsNodeState* GetNodeState(nsIDOMNode *aContextNode);
00440 
00441 #ifdef DEBUG_beaufour
00442 
00447   void PrintDot(const char* aFile = nsnull);
00448 #endif
00449 };
00450 
00451 #endif