Back to index

lightning-sunbird  0.9+nobinonly
nsTreeWalker.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
00002  *
00003  * ***** BEGIN LICENSE BLOCK *****
00004  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00005  *
00006  * The contents of this file are subject to the Mozilla Public License Version
00007  * 1.1 (the "License"); you may not use this file except in compliance with
00008  * the License. You may obtain a copy of the License at
00009  * http://www.mozilla.org/MPL/
00010  *
00011  * Software distributed under the License is distributed on an "AS IS" basis,
00012  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00013  * for the specific language governing rights and limitations under the
00014  * License.
00015  *
00016  * The Original Code is this file as it was released on May 1 2001.
00017  *
00018  * The Initial Developer of the Original Code is
00019  * Jonas Sicking.
00020  * Portions created by the Initial Developer are Copyright (C) 2001
00021  * the Initial Developer. All Rights Reserved.
00022  *
00023  * Contributor(s):
00024  *   Jonas Sicking <sicking@bigfoot.com> (Original Author)
00025  *
00026  * Alternatively, the contents of this file may be used under the terms of
00027  * either of the GNU General Public License Version 2 or later (the "GPL"),
00028  * or 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 nsTreeWalker_h___
00041 #define nsTreeWalker_h___
00042 
00043 /*
00044  * nsTreeWalker.h: interface of the nsTreeWalker object.
00045  */
00046 
00047 #include "nsIDOMNode.h"
00048 #include "nsIDOMTreeWalker.h"
00049 #include "nsIDOMNodeFilter.h"
00050 #include "nsCOMPtr.h"
00051 #include "nsVoidArray.h"
00052 #include "nsIDOMGCParticipant.h"
00053 #include "nsJSUtils.h"
00054 
00055 class nsTreeWalker : public nsIDOMTreeWalker, public nsIDOMGCParticipant
00056 {
00057 public:
00058     NS_DECL_ISUPPORTS
00059     NS_DECL_NSIDOMTREEWALKER
00060 
00061     // nsIDOMGCParticipant
00062     virtual nsIDOMGCParticipant* GetSCCIndex();
00063     virtual void AppendReachableList(nsCOMArray<nsIDOMGCParticipant>& aArray);
00064 
00065     nsTreeWalker(nsIDOMNode *aRoot,
00066                  PRUint32 aWhatToShow,
00067                  nsIDOMNodeFilter *aFilter,
00068                  PRBool aExpandEntityReferences);
00069     virtual ~nsTreeWalker();
00070     /* additional members */
00071 private:
00072     nsCOMPtr<nsIDOMNode> mRoot;
00073     PRUint32 mWhatToShow;
00074     nsMarkedJSFunctionHolder<nsIDOMNodeFilter> mFilter;
00075     PRBool mExpandEntityReferences;
00076     nsCOMPtr<nsIDOMNode> mCurrentNode;
00077     
00078     /*
00079      * Array with all child indexes up the tree. This should only be
00080      * considered a hint and the value could be wrong.
00081      * The array contains casted PRInt32's
00082      */
00083     nsAutoVoidArray mPossibleIndexes;
00084     
00085     /*
00086      * Position of mCurrentNode in mPossibleIndexes
00087      */
00088     PRInt32 mPossibleIndexesPos;
00089     
00090     /*
00091      * Finds the first child of aNode and returns it. If a child is
00092      * found, mCurrentNode is set to that child.
00093      * @param aNode     Node to search for children.
00094      * @param aReversed Reverses search to find the last child instead
00095      *                  of first.
00096      * @param aIndexPos Position of aNode in mPossibleIndexes.
00097      * @param _retval   Returned node. Null if no child is found
00098      * @returns         Errorcode
00099      */
00100     nsresult FirstChildOf(nsIDOMNode* aNode,
00101                           PRBool aReversed,
00102                           PRInt32 aIndexPos,
00103                           nsIDOMNode** _retval);
00104 
00105     /*
00106      * Finds the following sibling of aNode and returns it. If a sibling
00107      * is found, mCurrentNode is set to that node.
00108      * @param aNode     Node to start search at.
00109      * @param aReversed Reverses search to find the previous sibling
00110      *                  instead of next.
00111      * @param aIndexPos Position of aNode in mPossibleIndexes.
00112      * @param _retval   Returned node. Null if no sibling is found
00113      * @returns         Errorcode
00114      */
00115     nsresult NextSiblingOf(nsIDOMNode* aNode,
00116                            PRBool aReversed,
00117                            PRInt32 aIndexPos,
00118                            nsIDOMNode** _retval);
00119                            
00120     /*
00121      * Finds the next node in document order of aNode and returns it.
00122      * If a node is found, mCurrentNode is set to that node.
00123      * @param aNode     Node to start search at.
00124      * @param aReversed Reverses search to find the preceding node
00125      *                  instead of next.
00126      * @param aIndexPos Position of aNode in mPossibleIndexes.
00127      * @param _retval   Returned node. Null if no node is found
00128      * @returns         Errorcode
00129      */
00130     nsresult NextInDocumentOrderOf(nsIDOMNode* aNode,
00131                                    PRBool aReversed,
00132                                    PRInt32 aIndexPos,
00133                                    nsIDOMNode** _retval);
00134 
00135     /*
00136      * Finds the first child of aNode after child N and returns it. If a
00137      * child is found, mCurrentNode is set to that child
00138      * @param aNode     Node to search for children
00139      * @param childNum  Child number to start search from. The child with
00140      *                  this number is not searched
00141      * @param aReversed Reverses search to find the last child instead
00142      *                  of first
00143      * @param aIndexPos Position of aNode in mPossibleIndexes
00144      * @param _retval   Returned node. Null if no child is found
00145      * @returns         Errorcode
00146      */
00147     nsresult ChildOf(nsIDOMNode* aNode,
00148                      PRInt32 childNum,
00149                      PRBool aReversed,
00150                      PRInt32 aIndexPos,
00151                      nsIDOMNode** _retval);
00152 
00153     /*
00154      * Tests if and how a node should be filtered. Uses mWhatToShow and
00155      * mFilter to test the node.
00156      * @param aNode     Node to test
00157      * @param _filtered Returned filtervalue. See nsIDOMNodeFilter.idl
00158      * @returns         Errorcode
00159      */
00160     nsresult TestNode(nsIDOMNode* aNode, PRInt16* _filtered);
00161     
00162     /*
00163      * Gets the child index of a node within it's parent. Gets a possible index
00164      * from mPossibleIndexes to gain speed. If the value in mPossibleIndexes
00165      * isn't correct it'll get the index the usual way.
00166      * @param aParent   in which to get the index
00167      * @param aChild    node to get the index of
00168      * @param aIndexPos position in mPossibleIndexes that contains the possible.
00169      *                  index
00170      * @param _childNum returned index
00171      * @returns         Errorcode
00172      */
00173     nsresult IndexOf(nsIDOMNode* aParent,
00174                      nsIDOMNode* aChild,
00175                      PRInt32 aIndexPos,
00176                      PRInt32* _childNum);
00177 
00178     /*
00179      * Sets the child index at the specified level. It doesn't matter if this
00180      * fails since mPossibleIndexes should only be considered a hint
00181      * @param aIndexPos   position in mPossibleIndexes to set
00182      * @param aChildIndex child index at specified position
00183      */
00184     void SetChildIndex(PRInt32 aIndexPos, PRInt32 aChildIndex);
00185 
00186 };
00187 
00188 // Make a new nsIDOMTreeWalker object
00189 nsresult NS_NewTreeWalker(nsIDOMNode *aRoot,
00190                           PRUint32 aWhatToShow,
00191                           nsIDOMNodeFilter *aFilter,
00192                           PRBool aEntityReferenceExpansion,
00193                           nsIDOMTreeWalker **aInstancePtrResult);
00194 
00195 #endif
00196