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/. */
7 #ifndef nsTreeColumns_h__
8 #define nsTreeColumns_h__
10 #include "mozilla/Attributes.h"
11 #include "mozilla/RefPtr.h"
13 #include "nsCycleCollectionParticipant.h"
14 #include "nsQueryObject.h"
15 #include "nsWrapperCache.h"
19 class nsTreeBodyFrame
;
26 enum class StyleTextAlignKeyword
: uint8_t;
27 using StyleTextAlign
= StyleTextAlignKeyword
;
33 } // namespace mozilla
35 #define NS_TREECOLUMN_IMPL_CID \
36 { /* 02cd1963-4b5d-4a6c-9223-814d3ade93a3 */ \
37 0x02cd1963, 0x4b5d, 0x4a6c, { \
38 0x92, 0x23, 0x81, 0x4d, 0x3a, 0xde, 0x93, 0xa3 \
42 // This class is our column info. We use it to iterate our columns and to
43 // obtain information about each column.
44 class nsTreeColumn final
: public nsISupports
, public nsWrapperCache
{
46 nsTreeColumn(nsTreeColumns
* aColumns
, mozilla::dom::Element
* aElement
);
48 NS_DECLARE_STATIC_IID_ACCESSOR(NS_TREECOLUMN_IMPL_CID
)
50 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
51 NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(nsTreeColumn
)
54 nsIContent
* GetParentObject() const;
55 virtual JSObject
* WrapObject(JSContext
* aCx
,
56 JS::Handle
<JSObject
*> aGivenProto
) override
;
58 mozilla::dom::Element
* Element();
60 nsTreeColumns
* GetColumns() const { return mColumns
; }
62 int32_t GetX(mozilla::ErrorResult
& aRv
);
63 int32_t GetWidth(mozilla::ErrorResult
& aRv
);
65 void GetId(nsAString
& aId
) const;
66 int32_t Index() const { return mIndex
; }
68 bool Primary() const { return mIsPrimary
; }
69 bool Cycler() const { return mIsCycler
; }
70 bool Editable() const { return mIsEditable
; }
71 int16_t Type() const { return mType
; }
73 nsTreeColumn
* GetNext() const { return mNext
; }
74 nsTreeColumn
* GetPrevious() const { return mPrevious
; }
76 already_AddRefed
<nsTreeColumn
> GetPreviousColumn();
78 void Invalidate(mozilla::ErrorResult
& aRv
);
80 friend class nsTreeBodyFrame
;
81 friend class nsTreeColumns
;
86 nsIFrame
* GetFrame(nsTreeBodyFrame
* aBodyFrame
);
87 // Don't call this if GetWidthInTwips or GetRect fails
88 bool IsLastVisible(nsTreeBodyFrame
* aBodyFrame
);
91 * Returns a rect with x and width taken from the frame's rect and specified
92 * y and height. May fail in case there's no frame for the column.
94 nsresult
GetRect(nsTreeBodyFrame
* aBodyFrame
, nscoord aY
, nscoord aHeight
,
97 nsresult
GetXInTwips(nsTreeBodyFrame
* aBodyFrame
, nscoord
* aResult
);
98 nsresult
GetWidthInTwips(nsTreeBodyFrame
* aBodyFrame
, nscoord
* aResult
);
100 void SetColumns(nsTreeColumns
* aColumns
) { mColumns
= aColumns
; }
103 const nsAString
& GetId() const { return mId
; }
104 nsAtom
* GetAtom() { return mAtom
; }
105 int32_t GetIndex() { return mIndex
; }
108 bool IsPrimary() { return mIsPrimary
; }
109 bool IsCycler() { return mIsCycler
; }
110 bool IsEditable() { return mIsEditable
; }
111 bool Overflow() { return mOverflow
; }
113 int16_t GetType() { return mType
; }
115 int8_t GetCropStyle() { return mCropStyle
; }
116 mozilla::StyleTextAlign
GetTextAlignment() { return mTextAlignment
; }
118 void SetNext(nsTreeColumn
* aNext
) {
119 NS_ASSERTION(!mNext
, "already have a next sibling");
122 void SetPrevious(nsTreeColumn
* aPrevious
) { mPrevious
= aPrevious
; }
126 * Non-null nsIContent for the associated <treecol> element.
128 RefPtr
<mozilla::dom::Element
> mContent
;
130 nsTreeColumns
* mColumns
;
133 RefPtr
<nsAtom
> mAtom
;
145 mozilla::StyleTextAlign mTextAlignment
;
147 RefPtr
<nsTreeColumn
> mNext
;
148 nsTreeColumn
* mPrevious
;
151 NS_DEFINE_STATIC_IID_ACCESSOR(nsTreeColumn
, NS_TREECOLUMN_IMPL_CID
)
153 class nsTreeColumns final
: public nsISupports
, public nsWrapperCache
{
158 explicit nsTreeColumns(nsTreeBodyFrame
* aTree
);
160 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
161 NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(nsTreeColumns
)
163 nsIContent
* GetParentObject() const;
164 virtual JSObject
* WrapObject(JSContext
* aCx
,
165 JS::Handle
<JSObject
*> aGivenProto
) override
;
168 mozilla::dom::XULTreeElement
* GetTree() const;
170 uint32_t Length() { return Count(); }
172 nsTreeColumn
* GetFirstColumn() {
176 nsTreeColumn
* GetLastColumn();
178 nsTreeColumn
* GetPrimaryColumn();
179 nsTreeColumn
* GetSortedColumn();
180 nsTreeColumn
* GetKeyColumn();
182 nsTreeColumn
* GetColumnFor(mozilla::dom::Element
* aElement
);
184 nsTreeColumn
* IndexedGetter(uint32_t aIndex
, bool& aFound
);
185 nsTreeColumn
* GetColumnAt(uint32_t aIndex
);
186 nsTreeColumn
* NamedGetter(const nsAString
& aId
, bool& aFound
);
187 nsTreeColumn
* GetNamedColumn(const nsAString
& aId
);
188 void GetSupportedNames(nsTArray
<nsString
>& aNames
);
190 void InvalidateColumns();
192 friend class nsTreeBodyFrame
;
195 void SetTree(nsTreeBodyFrame
* aTree
) { mTree
= aTree
; }
197 // Builds our cache of column info.
198 void EnsureColumns();
201 nsTreeBodyFrame
* mTree
;
204 * The first column in the list of columns. All of the columns are supposed
205 * to be "alive", i.e. have a frame. This is achieved by clearing the columns
206 * list each time a treecol changes size.
208 * XXX this means that new nsTreeColumn objects are unnecessarily created
209 * for untouched columns.
211 RefPtr
<nsTreeColumn
> mFirstColumn
;
214 #endif // nsTreeColumns_h__