|
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
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 nsTreeColumns_h__ |
|
7 #define nsTreeColumns_h__ |
|
8 |
|
9 #include "nsITreeColumns.h" |
|
10 #include "nsITreeBoxObject.h" |
|
11 #include "mozilla/Attributes.h" |
|
12 #include "nsCoord.h" |
|
13 #include "nsCycleCollectionParticipant.h" |
|
14 #include "nsAutoPtr.h" |
|
15 #include "nsWrapperCache.h" |
|
16 #include "nsString.h" |
|
17 |
|
18 class nsTreeBodyFrame; |
|
19 class nsTreeColumns; |
|
20 class nsIFrame; |
|
21 class nsIContent; |
|
22 struct nsRect; |
|
23 |
|
24 namespace mozilla { |
|
25 namespace dom { |
|
26 class Element; |
|
27 } // namespace dom |
|
28 } // namespace mozilla |
|
29 |
|
30 #define NS_TREECOLUMN_IMPL_CID \ |
|
31 { /* 02cd1963-4b5d-4a6c-9223-814d3ade93a3 */ \ |
|
32 0x02cd1963, \ |
|
33 0x4b5d, \ |
|
34 0x4a6c, \ |
|
35 {0x92, 0x23, 0x81, 0x4d, 0x3a, 0xde, 0x93, 0xa3} \ |
|
36 } |
|
37 |
|
38 // This class is our column info. We use it to iterate our columns and to obtain |
|
39 // information about each column. |
|
40 class nsTreeColumn MOZ_FINAL : public nsITreeColumn { |
|
41 public: |
|
42 nsTreeColumn(nsTreeColumns* aColumns, nsIContent* aContent); |
|
43 ~nsTreeColumn(); |
|
44 |
|
45 NS_DECLARE_STATIC_IID_ACCESSOR(NS_TREECOLUMN_IMPL_CID) |
|
46 |
|
47 NS_DECL_CYCLE_COLLECTING_ISUPPORTS |
|
48 NS_DECL_CYCLE_COLLECTION_CLASS(nsTreeColumn) |
|
49 NS_DECL_NSITREECOLUMN |
|
50 |
|
51 friend class nsTreeBodyFrame; |
|
52 friend class nsTreeColumns; |
|
53 |
|
54 protected: |
|
55 nsIFrame* GetFrame(); |
|
56 nsIFrame* GetFrame(nsTreeBodyFrame* aBodyFrame); |
|
57 // Don't call this if GetWidthInTwips or GetRect fails |
|
58 bool IsLastVisible(nsTreeBodyFrame* aBodyFrame); |
|
59 |
|
60 /** |
|
61 * Returns a rect with x and width taken from the frame's rect and specified |
|
62 * y and height. May fail in case there's no frame for the column. |
|
63 */ |
|
64 nsresult GetRect(nsTreeBodyFrame* aBodyFrame, nscoord aY, nscoord aHeight, |
|
65 nsRect* aResult); |
|
66 |
|
67 nsresult GetXInTwips(nsTreeBodyFrame* aBodyFrame, nscoord* aResult); |
|
68 nsresult GetWidthInTwips(nsTreeBodyFrame* aBodyFrame, nscoord* aResult); |
|
69 |
|
70 void SetColumns(nsTreeColumns* aColumns) { mColumns = aColumns; } |
|
71 |
|
72 const nsAString& GetId() { return mId; } |
|
73 nsIAtom* GetAtom() { return mAtom; } |
|
74 |
|
75 int32_t GetIndex() { return mIndex; } |
|
76 |
|
77 bool IsPrimary() { return mIsPrimary; } |
|
78 bool IsCycler() { return mIsCycler; } |
|
79 bool IsEditable() { return mIsEditable; } |
|
80 bool IsSelectable() { return mIsSelectable; } |
|
81 bool Overflow() { return mOverflow; } |
|
82 |
|
83 int16_t GetType() { return mType; } |
|
84 |
|
85 int8_t GetCropStyle() { return mCropStyle; } |
|
86 int32_t GetTextAlignment() { return mTextAlignment; } |
|
87 |
|
88 nsTreeColumn* GetNext() { return mNext; } |
|
89 nsTreeColumn* GetPrevious() { return mPrevious; } |
|
90 void SetNext(nsTreeColumn* aNext) { |
|
91 NS_ASSERTION(!mNext, "already have a next sibling"); |
|
92 mNext = aNext; |
|
93 } |
|
94 void SetPrevious(nsTreeColumn* aPrevious) { mPrevious = aPrevious; } |
|
95 |
|
96 private: |
|
97 /** |
|
98 * Non-null nsIContent for the associated <treecol> element. |
|
99 */ |
|
100 nsCOMPtr<nsIContent> mContent; |
|
101 |
|
102 nsTreeColumns* mColumns; |
|
103 |
|
104 nsString mId; |
|
105 nsCOMPtr<nsIAtom> mAtom; |
|
106 |
|
107 int32_t mIndex; |
|
108 |
|
109 bool mIsPrimary; |
|
110 bool mIsCycler; |
|
111 bool mIsEditable; |
|
112 bool mIsSelectable; |
|
113 bool mOverflow; |
|
114 |
|
115 int16_t mType; |
|
116 |
|
117 int8_t mCropStyle; |
|
118 int8_t mTextAlignment; |
|
119 |
|
120 nsRefPtr<nsTreeColumn> mNext; |
|
121 nsTreeColumn* mPrevious; |
|
122 }; |
|
123 |
|
124 NS_DEFINE_STATIC_IID_ACCESSOR(nsTreeColumn, NS_TREECOLUMN_IMPL_CID) |
|
125 |
|
126 class nsTreeColumns MOZ_FINAL : public nsITreeColumns |
|
127 , public nsWrapperCache |
|
128 { |
|
129 public: |
|
130 nsTreeColumns(nsTreeBodyFrame* aTree); |
|
131 ~nsTreeColumns(); |
|
132 |
|
133 NS_DECL_CYCLE_COLLECTING_ISUPPORTS |
|
134 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(nsTreeColumns) |
|
135 NS_DECL_NSITREECOLUMNS |
|
136 |
|
137 nsIContent* GetParentObject() const; |
|
138 virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE; |
|
139 |
|
140 // WebIDL |
|
141 nsITreeBoxObject* GetTree() const; |
|
142 uint32_t Count(); |
|
143 uint32_t Length() |
|
144 { |
|
145 return Count(); |
|
146 } |
|
147 |
|
148 nsTreeColumn* GetFirstColumn() { EnsureColumns(); return mFirstColumn; } |
|
149 nsTreeColumn* GetLastColumn(); |
|
150 |
|
151 nsTreeColumn* GetPrimaryColumn(); |
|
152 nsTreeColumn* GetSortedColumn(); |
|
153 nsTreeColumn* GetKeyColumn(); |
|
154 |
|
155 nsTreeColumn* GetColumnFor(mozilla::dom::Element* aElement); |
|
156 |
|
157 nsTreeColumn* IndexedGetter(uint32_t aIndex, bool& aFound); |
|
158 nsTreeColumn* GetColumnAt(uint32_t aIndex); |
|
159 nsTreeColumn* NamedGetter(const nsAString& aId, bool& aFound); |
|
160 bool NameIsEnumerable(const nsAString& aName); |
|
161 nsTreeColumn* GetNamedColumn(const nsAString& aId); |
|
162 void GetSupportedNames(unsigned, nsTArray<nsString>& aNames); |
|
163 |
|
164 // Uses XPCOM InvalidateColumns(). |
|
165 // Uses XPCOM RestoreNaturalOrder(). |
|
166 |
|
167 friend class nsTreeBodyFrame; |
|
168 protected: |
|
169 void SetTree(nsTreeBodyFrame* aTree) { mTree = aTree; } |
|
170 |
|
171 // Builds our cache of column info. |
|
172 void EnsureColumns(); |
|
173 |
|
174 private: |
|
175 nsTreeBodyFrame* mTree; |
|
176 |
|
177 /** |
|
178 * The first column in the list of columns. All of the columns are supposed |
|
179 * to be "alive", i.e. have a frame. This is achieved by clearing the columns |
|
180 * list each time an nsTreeColFrame is destroyed. |
|
181 * |
|
182 * XXX this means that new nsTreeColumn objects are unnecessarily created |
|
183 * for untouched columns. |
|
184 */ |
|
185 nsTreeColumn* mFirstColumn; |
|
186 }; |
|
187 |
|
188 #endif // nsTreeColumns_h__ |