Line data Source code
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 "nsQueryObject.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 : class ErrorResult;
26 : namespace dom {
27 : class Element;
28 : class TreeBoxObject;
29 : } // namespace dom
30 : } // namespace mozilla
31 :
32 : #define NS_TREECOLUMN_IMPL_CID \
33 : { /* 02cd1963-4b5d-4a6c-9223-814d3ade93a3 */ \
34 : 0x02cd1963, \
35 : 0x4b5d, \
36 : 0x4a6c, \
37 : {0x92, 0x23, 0x81, 0x4d, 0x3a, 0xde, 0x93, 0xa3} \
38 : }
39 :
40 : // This class is our column info. We use it to iterate our columns and to obtain
41 : // information about each column.
42 : class nsTreeColumn final : public nsITreeColumn
43 : , public nsWrapperCache
44 : {
45 : public:
46 : nsTreeColumn(nsTreeColumns* aColumns, nsIContent* aContent);
47 :
48 : NS_DECLARE_STATIC_IID_ACCESSOR(NS_TREECOLUMN_IMPL_CID)
49 :
50 0 : static already_AddRefed<nsTreeColumn> From(nsITreeColumn* aColumn)
51 : {
52 0 : RefPtr<nsTreeColumn> col = do_QueryObject(aColumn);
53 0 : return col.forget();
54 : }
55 :
56 : NS_DECL_CYCLE_COLLECTING_ISUPPORTS
57 0 : NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(nsTreeColumn)
58 : NS_DECL_NSITREECOLUMN
59 :
60 : // WebIDL
61 : nsIContent* GetParentObject() const;
62 : virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
63 :
64 : mozilla::dom::Element* GetElement(mozilla::ErrorResult& aRv);
65 :
66 0 : nsTreeColumns* GetColumns() const { return mColumns; }
67 :
68 : int32_t GetX(mozilla::ErrorResult& aRv);
69 : int32_t GetWidth(mozilla::ErrorResult& aRv);
70 :
71 : // GetId is fine
72 0 : int32_t Index() const { return mIndex; }
73 :
74 0 : bool Primary() const { return mIsPrimary; }
75 0 : bool Cycler() const { return mIsCycler; }
76 0 : bool Editable() const { return mIsEditable; }
77 0 : bool Selectable() const { return mIsSelectable; }
78 0 : int16_t Type() const { return mType; }
79 :
80 0 : nsTreeColumn* GetNext() const { return mNext; }
81 0 : nsTreeColumn* GetPrevious() const { return mPrevious; }
82 :
83 : void Invalidate(mozilla::ErrorResult& aRv);
84 :
85 : friend class nsTreeBodyFrame;
86 : friend class nsTreeColumns;
87 :
88 : protected:
89 : ~nsTreeColumn();
90 : nsIFrame* GetFrame();
91 : nsIFrame* GetFrame(nsTreeBodyFrame* aBodyFrame);
92 : // Don't call this if GetWidthInTwips or GetRect fails
93 : bool IsLastVisible(nsTreeBodyFrame* aBodyFrame);
94 :
95 : /**
96 : * Returns a rect with x and width taken from the frame's rect and specified
97 : * y and height. May fail in case there's no frame for the column.
98 : */
99 : nsresult GetRect(nsTreeBodyFrame* aBodyFrame, nscoord aY, nscoord aHeight,
100 : nsRect* aResult);
101 :
102 : nsresult GetXInTwips(nsTreeBodyFrame* aBodyFrame, nscoord* aResult);
103 : nsresult GetWidthInTwips(nsTreeBodyFrame* aBodyFrame, nscoord* aResult);
104 :
105 0 : void SetColumns(nsTreeColumns* aColumns) { mColumns = aColumns; }
106 :
107 0 : const nsAString& GetId() { return mId; }
108 :
109 : public:
110 0 : nsIAtom* GetAtom() { return mAtom; }
111 0 : int32_t GetIndex() { return mIndex; }
112 :
113 : protected:
114 0 : bool IsPrimary() { return mIsPrimary; }
115 0 : bool IsCycler() { return mIsCycler; }
116 0 : bool IsEditable() { return mIsEditable; }
117 0 : bool IsSelectable() { return mIsSelectable; }
118 0 : bool Overflow() { return mOverflow; }
119 :
120 0 : int16_t GetType() { return mType; }
121 :
122 0 : int8_t GetCropStyle() { return mCropStyle; }
123 0 : int32_t GetTextAlignment() { return mTextAlignment; }
124 :
125 0 : void SetNext(nsTreeColumn* aNext) {
126 0 : NS_ASSERTION(!mNext, "already have a next sibling");
127 0 : mNext = aNext;
128 0 : }
129 0 : void SetPrevious(nsTreeColumn* aPrevious) { mPrevious = aPrevious; }
130 :
131 : private:
132 : /**
133 : * Non-null nsIContent for the associated <treecol> element.
134 : */
135 : nsCOMPtr<nsIContent> mContent;
136 :
137 : nsTreeColumns* mColumns;
138 :
139 : nsString mId;
140 : nsCOMPtr<nsIAtom> mAtom;
141 :
142 : int32_t mIndex;
143 :
144 : bool mIsPrimary;
145 : bool mIsCycler;
146 : bool mIsEditable;
147 : bool mIsSelectable;
148 : bool mOverflow;
149 :
150 : int16_t mType;
151 :
152 : int8_t mCropStyle;
153 : int8_t mTextAlignment;
154 :
155 : RefPtr<nsTreeColumn> mNext;
156 : nsTreeColumn* mPrevious;
157 : };
158 :
159 : NS_DEFINE_STATIC_IID_ACCESSOR(nsTreeColumn, NS_TREECOLUMN_IMPL_CID)
160 :
161 : class nsTreeColumns final : public nsITreeColumns
162 : , public nsWrapperCache
163 : {
164 : private:
165 : ~nsTreeColumns();
166 :
167 : public:
168 : explicit nsTreeColumns(nsTreeBodyFrame* aTree);
169 :
170 : NS_DECL_CYCLE_COLLECTING_ISUPPORTS
171 0 : NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(nsTreeColumns)
172 : NS_DECL_NSITREECOLUMNS
173 :
174 : nsIContent* GetParentObject() const;
175 : virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
176 :
177 : // WebIDL
178 : mozilla::dom::TreeBoxObject* GetTree() const;
179 : uint32_t Count();
180 0 : uint32_t Length()
181 : {
182 0 : return Count();
183 : }
184 :
185 0 : nsTreeColumn* GetFirstColumn() { EnsureColumns(); return mFirstColumn; }
186 : nsTreeColumn* GetLastColumn();
187 :
188 : nsTreeColumn* GetPrimaryColumn();
189 : nsTreeColumn* GetSortedColumn();
190 : nsTreeColumn* GetKeyColumn();
191 :
192 : nsTreeColumn* GetColumnFor(mozilla::dom::Element* aElement);
193 :
194 : nsTreeColumn* IndexedGetter(uint32_t aIndex, bool& aFound);
195 : nsTreeColumn* GetColumnAt(uint32_t aIndex);
196 : nsTreeColumn* NamedGetter(const nsAString& aId, bool& aFound);
197 : nsTreeColumn* GetNamedColumn(const nsAString& aId);
198 : void GetSupportedNames(nsTArray<nsString>& aNames);
199 :
200 : // Uses XPCOM InvalidateColumns().
201 : // Uses XPCOM RestoreNaturalOrder().
202 :
203 : friend class nsTreeBodyFrame;
204 : protected:
205 0 : void SetTree(nsTreeBodyFrame* aTree) { mTree = aTree; }
206 :
207 : // Builds our cache of column info.
208 : void EnsureColumns();
209 :
210 : private:
211 : nsTreeBodyFrame* mTree;
212 :
213 : /**
214 : * The first column in the list of columns. All of the columns are supposed
215 : * to be "alive", i.e. have a frame. This is achieved by clearing the columns
216 : * list each time an nsTreeColFrame is destroyed.
217 : *
218 : * XXX this means that new nsTreeColumn objects are unnecessarily created
219 : * for untouched columns.
220 : */
221 : RefPtr<nsTreeColumn> mFirstColumn;
222 : };
223 :
224 : #endif // nsTreeColumns_h__
|