Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /* This Source Code Form is subject to the terms of the Mozilla Public
3 : * License, v. 2.0. If a copy of the MPL was not distributed with this
4 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 :
6 : #ifndef nsTreeContentView_h__
7 : #define nsTreeContentView_h__
8 :
9 : #include "nsCycleCollectionParticipant.h"
10 : #include "nsTArray.h"
11 : #include "nsStubDocumentObserver.h"
12 : #include "nsITreeBoxObject.h"
13 : #include "nsITreeView.h"
14 : #include "nsITreeContentView.h"
15 : #include "nsITreeSelection.h"
16 : #include "mozilla/Attributes.h"
17 : #include "mozilla/UniquePtr.h"
18 :
19 : class nsIDocument;
20 : class nsSelection;
21 : class nsTreeColumn;
22 : class Row;
23 :
24 : namespace mozilla {
25 : namespace dom {
26 : class DataTransfer;
27 : class TreeBoxObject;
28 : } // namespace dom
29 : } // namespace mozilla
30 :
31 : nsresult NS_NewTreeContentView(nsITreeView** aResult);
32 :
33 : class nsTreeContentView final : public nsINativeTreeView,
34 : public nsITreeContentView,
35 : public nsStubDocumentObserver,
36 : public nsWrapperCache
37 : {
38 : public:
39 : nsTreeContentView(void);
40 :
41 : NS_DECL_CYCLE_COLLECTING_ISUPPORTS
42 0 : NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(nsTreeContentView,
43 : nsINativeTreeView)
44 :
45 : virtual JSObject* WrapObject(JSContext* aCx,
46 : JS::Handle<JSObject*> aGivenProto) override;
47 : nsISupports* GetParentObject();
48 :
49 0 : int32_t RowCount()
50 : {
51 0 : return mRows.Length();
52 : }
53 0 : nsITreeSelection* GetSelection()
54 : {
55 0 : return mSelection;
56 : }
57 : void SetSelection(nsITreeSelection* aSelection,
58 : mozilla::ErrorResult& aError);
59 : void GetRowProperties(int32_t aRow, nsAString& aProperties,
60 : mozilla::ErrorResult& aError);
61 : void GetCellProperties(int32_t aRow, nsTreeColumn& aColumn,
62 : nsAString& aProperies, mozilla::ErrorResult& aError);
63 : void GetColumnProperties(nsTreeColumn& aColumn, nsAString& aProperies);
64 : bool IsContainer(int32_t aRow, mozilla::ErrorResult& aError);
65 : bool IsContainerOpen(int32_t aRow, mozilla::ErrorResult& aError);
66 : bool IsContainerEmpty(int32_t aRow, mozilla::ErrorResult& aError);
67 : bool IsSeparator(int32_t aRow, mozilla::ErrorResult& aError);
68 0 : bool IsSorted()
69 : {
70 0 : return false;
71 : }
72 : bool CanDrop(int32_t aRow, int32_t aOrientation,
73 : mozilla::dom::DataTransfer* aDataTransfer,
74 : mozilla::ErrorResult& aError);
75 : void Drop(int32_t aRow, int32_t aOrientation,
76 : mozilla::dom::DataTransfer* aDataTransfer,
77 : mozilla::ErrorResult& aError);
78 : int32_t GetParentIndex(int32_t aRow, mozilla::ErrorResult& aError);
79 : bool HasNextSibling(int32_t aRow, int32_t aAfterIndex,
80 : mozilla::ErrorResult& aError);
81 : int32_t GetLevel(int32_t aRow, mozilla::ErrorResult& aError);
82 : void GetImageSrc(int32_t aRow, nsTreeColumn& aColumn, nsAString& aSrc,
83 : mozilla::ErrorResult& aError);
84 : int32_t GetProgressMode(int32_t aRow, nsTreeColumn& aColumn,
85 : mozilla::ErrorResult& aError);
86 : void GetCellValue(int32_t aRow, nsTreeColumn& aColumn, nsAString& aValue,
87 : mozilla::ErrorResult& aError);
88 : void GetCellText(int32_t aRow, nsTreeColumn& aColumn, nsAString& aText,
89 : mozilla::ErrorResult& aError);
90 : void SetTree(mozilla::dom::TreeBoxObject* aTree,
91 : mozilla::ErrorResult& aError);
92 : void ToggleOpenState(int32_t aRow, mozilla::ErrorResult& aError);
93 : void CycleHeader(nsTreeColumn& aColumn, mozilla::ErrorResult& aError);
94 : // XPCOM SelectionChanged() is OK
95 0 : void CycleCell(int32_t aRow, nsTreeColumn& aColumn)
96 : {
97 0 : }
98 : bool IsEditable(int32_t aRow, nsTreeColumn& aColumn,
99 : mozilla::ErrorResult& aError);
100 : bool IsSelectable(int32_t aRow, nsTreeColumn& aColumn,
101 : mozilla::ErrorResult& aError);
102 : void SetCellValue(int32_t aRow, nsTreeColumn& aColumn,
103 : const nsAString& aValue, mozilla::ErrorResult& aError);
104 : void SetCellText(int32_t aRow, nsTreeColumn& aColumn,
105 : const nsAString& aText, mozilla::ErrorResult& aError);
106 0 : void PerformAction(const nsAString& aAction)
107 : {
108 0 : }
109 0 : void PerformActionOnRow(const nsAString& aAction, int32_t aRow)
110 : {
111 0 : }
112 0 : void PerformActionOnCell(const nsAString& aAction, int32_t aRow,
113 : nsTreeColumn& aColumn)
114 : {
115 0 : }
116 : mozilla::dom::Element* GetItemAtIndex(int32_t aRow,
117 : mozilla::ErrorResult& aError);
118 : int32_t GetIndexOfItem(mozilla::dom::Element* aItem);
119 :
120 : NS_DECL_NSITREEVIEW
121 : // nsINativeTreeView: Untrusted code can use us
122 0 : NS_IMETHOD EnsureNative() override { return NS_OK; }
123 :
124 : NS_DECL_NSITREECONTENTVIEW
125 :
126 : // nsIDocumentObserver
127 : NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTECHANGED
128 : NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED
129 : NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED
130 : NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED
131 : NS_DECL_NSIMUTATIONOBSERVER_NODEWILLBEDESTROYED
132 :
133 : static bool CanTrustTreeSelection(nsISupports* aValue);
134 :
135 : protected:
136 : ~nsTreeContentView(void);
137 :
138 : // Recursive methods which deal with serializing of nested content.
139 : void Serialize(nsIContent* aContent, int32_t aParentIndex, int32_t* aIndex,
140 : nsTArray<mozilla::UniquePtr<Row>>& aRows);
141 :
142 : void SerializeItem(Element* aContent, int32_t aParentIndex,
143 : int32_t* aIndex, nsTArray<mozilla::UniquePtr<Row>>& aRows);
144 :
145 : void SerializeSeparator(Element* aContent, int32_t aParentIndex,
146 : int32_t* aIndex, nsTArray<mozilla::UniquePtr<Row>>& aRows);
147 :
148 : void GetIndexInSubtree(nsIContent* aContainer, nsIContent* aContent, int32_t* aResult);
149 :
150 : // Helper methods which we use to manage our plain array of rows.
151 : int32_t EnsureSubtree(int32_t aIndex);
152 :
153 : int32_t RemoveSubtree(int32_t aIndex);
154 :
155 : int32_t InsertRow(int32_t aParentIndex, int32_t aIndex, nsIContent* aContent);
156 :
157 : void InsertRowFor(nsIContent* aParent, nsIContent* aChild);
158 :
159 : int32_t RemoveRow(int32_t aIndex);
160 :
161 : void ClearRows();
162 :
163 : void OpenContainer(int32_t aIndex);
164 :
165 : void CloseContainer(int32_t aIndex);
166 :
167 : int32_t FindContent(nsIContent* aContent);
168 :
169 : void UpdateSubtreeSizes(int32_t aIndex, int32_t aCount);
170 :
171 : void UpdateParentIndexes(int32_t aIndex, int32_t aSkip, int32_t aCount);
172 :
173 : // Content helpers.
174 : nsIContent* GetCell(nsIContent* aContainer, nsTreeColumn& aCol);
175 :
176 : private:
177 : bool IsValidRowIndex(int32_t aRowIndex);
178 :
179 : nsCOMPtr<nsITreeBoxObject> mBoxObject;
180 : nsCOMPtr<nsITreeSelection> mSelection;
181 : nsCOMPtr<nsIContent> mRoot;
182 : nsCOMPtr<nsIContent> mBody;
183 : nsIDocument* mDocument; // WEAK
184 : nsTArray<mozilla::UniquePtr<Row>> mRows;
185 : };
186 :
187 : #endif // nsTreeContentView_h__
|