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