1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /* ***** BEGIN LICENSE BLOCK *****
3 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 : *
5 : * The contents of this file are subject to the Mozilla Public License Version
6 : * 1.1 (the "License"); you may not use this file except in compliance with
7 : * the License. You may obtain a copy of the License at
8 : * http://www.mozilla.org/MPL/
9 : *
10 : * Software distributed under the License is distributed on an "AS IS" basis,
11 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : * for the specific language governing rights and limitations under the
13 : * License.
14 : *
15 : * The Original Code is mozilla.org code.
16 : *
17 : * The Initial Developer of the Original Code is Jan Varga.
18 : * Portions created by the Initial Developer are Copyright (C) 2001
19 : * the Initial Developer. All Rights Reserved.
20 : *
21 : * Contributor(s):
22 : * Brian Ryner <bryner@brianryner.com>
23 : *
24 : * Alternatively, the contents of this file may be used under the terms of
25 : * either of the GNU General Public License Version 2 or later (the "GPL"),
26 : * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 : * in which case the provisions of the GPL or the LGPL are applicable instead
28 : * of those above. If you wish to allow use of your version of this file only
29 : * under the terms of either the GPL or the LGPL, and not to allow others to
30 : * use your version of this file under the terms of the MPL, indicate your
31 : * decision by deleting the provisions above and replace them with the notice
32 : * and other provisions required by the GPL or the LGPL. If you do not delete
33 : * the provisions above, a recipient may use your version of this file under
34 : * the terms of any one of the MPL, the GPL or the LGPL.
35 : *
36 : * ***** END LICENSE BLOCK ***** */
37 :
38 : #ifndef nsTreeContentView_h__
39 : #define nsTreeContentView_h__
40 :
41 : #include "nsFixedSizeAllocator.h"
42 : #include "nsTArray.h"
43 : #include "nsIDocument.h"
44 : #include "nsStubDocumentObserver.h"
45 : #include "nsITreeBoxObject.h"
46 : #include "nsITreeColumns.h"
47 : #include "nsITreeView.h"
48 : #include "nsITreeContentView.h"
49 : #include "nsITreeSelection.h"
50 :
51 : class Row;
52 :
53 : nsresult NS_NewTreeContentView(nsITreeView** aResult);
54 :
55 : class nsTreeContentView : public nsINativeTreeView,
56 : public nsITreeContentView,
57 : public nsStubDocumentObserver
58 : {
59 : public:
60 : nsTreeContentView(void);
61 :
62 : ~nsTreeContentView(void);
63 :
64 0 : NS_DECL_CYCLE_COLLECTING_ISUPPORTS
65 1464 : NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsTreeContentView,
66 : nsINativeTreeView)
67 :
68 : NS_DECL_NSITREEVIEW
69 : // nsINativeTreeView: Untrusted code can use us
70 0 : NS_IMETHOD EnsureNative() { return NS_OK; }
71 :
72 : NS_DECL_NSITREECONTENTVIEW
73 :
74 : // nsIDocumentObserver
75 : NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTECHANGED
76 : NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED
77 : NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED
78 : NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED
79 : NS_DECL_NSIMUTATIONOBSERVER_NODEWILLBEDESTROYED
80 :
81 : static bool CanTrustTreeSelection(nsISupports* aValue);
82 :
83 : protected:
84 : // Recursive methods which deal with serializing of nested content.
85 : void Serialize(nsIContent* aContent, PRInt32 aParentIndex, PRInt32* aIndex,
86 : nsTArray<Row*>& aRows);
87 :
88 : void SerializeItem(nsIContent* aContent, PRInt32 aParentIndex,
89 : PRInt32* aIndex, nsTArray<Row*>& aRows);
90 :
91 : void SerializeSeparator(nsIContent* aContent, PRInt32 aParentIndex,
92 : PRInt32* aIndex, nsTArray<Row*>& aRows);
93 :
94 : void GetIndexInSubtree(nsIContent* aContainer, nsIContent* aContent, PRInt32* aResult);
95 :
96 : // Helper methods which we use to manage our plain array of rows.
97 : PRInt32 EnsureSubtree(PRInt32 aIndex);
98 :
99 : PRInt32 RemoveSubtree(PRInt32 aIndex);
100 :
101 : PRInt32 InsertRow(PRInt32 aParentIndex, PRInt32 aIndex, nsIContent* aContent);
102 :
103 : void InsertRowFor(nsIContent* aParent, nsIContent* aChild);
104 :
105 : PRInt32 RemoveRow(PRInt32 aIndex);
106 :
107 : void ClearRows();
108 :
109 : void OpenContainer(PRInt32 aIndex);
110 :
111 : void CloseContainer(PRInt32 aIndex);
112 :
113 : PRInt32 FindContent(nsIContent* aContent);
114 :
115 : void UpdateSubtreeSizes(PRInt32 aIndex, PRInt32 aCount);
116 :
117 : void UpdateParentIndexes(PRInt32 aIndex, PRInt32 aSkip, PRInt32 aCount);
118 :
119 : // Content helpers.
120 : nsIContent* GetCell(nsIContent* aContainer, nsITreeColumn* aCol);
121 :
122 : private:
123 : nsCOMPtr<nsITreeBoxObject> mBoxObject;
124 : nsCOMPtr<nsITreeSelection> mSelection;
125 : nsCOMPtr<nsIContent> mRoot;
126 : nsCOMPtr<nsIContent> mBody;
127 : nsIDocument* mDocument; // WEAK
128 : nsFixedSizeAllocator mAllocator;
129 : nsTArray<Row*> mRows;
130 : };
131 :
132 : #endif // nsTreeContentView_h__
|