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 XULTreeElement_h__
8 #define XULTreeElement_h__
10 #include "mozilla/Attributes.h"
11 #include "nsCycleCollectionParticipant.h"
12 #include "nsWrapperCache.h"
14 #include "nsXULElement.h"
15 #include "nsITreeView.h"
17 class nsTreeBodyFrame
;
28 enum class CallerType
: uint32_t;
30 class XULTreeElement final
: public nsXULElement
{
32 explicit XULTreeElement(already_AddRefed
<mozilla::dom::NodeInfo
>&& aNodeInfo
)
33 : nsXULElement(std::move(aNodeInfo
)),
34 mCachedFirstVisibleRow(0),
37 NS_IMPL_FROMNODE_WITH_TAG(XULTreeElement
, kNameSpaceID_XUL
, tree
)
39 NS_DECL_ISUPPORTS_INHERITED
40 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(XULTreeElement
, nsXULElement
)
42 nsTreeBodyFrame
* GetTreeBodyFrame(FlushType
= FlushType::Frames
);
43 nsTreeBodyFrame
* GetCachedTreeBodyFrame() { return mTreeBody
; }
45 already_AddRefed
<nsTreeColumns
> GetColumns(FlushType
= FlushType::Frames
);
47 already_AddRefed
<nsITreeView
> GetView(CallerType
/* unused */) {
50 already_AddRefed
<nsITreeView
> GetView(FlushType
= FlushType::Frames
);
52 void SetView(nsITreeView
* arg
, CallerType aCallerType
, ErrorResult
& aRv
);
56 already_AddRefed
<Element
> GetTreeBody();
62 int32_t HorizontalPosition();
64 void EnsureCellIsVisible(int32_t row
, nsTreeColumn
* col
, ErrorResult
& aRv
);
66 void ScrollToRow(int32_t aRow
);
68 void ScrollByLines(int32_t aNumLines
);
70 void ScrollByPages(int32_t aNumPages
);
72 int32_t GetFirstVisibleRow();
74 int32_t GetLastVisibleRow();
76 int32_t GetPageLength();
78 int32_t GetRowAt(int32_t x
, int32_t y
);
80 void GetCellAt(int32_t x
, int32_t y
, TreeCellInfo
& aRetVal
, ErrorResult
& aRv
);
82 nsIntRect
GetCoordsForCellItem(int32_t aRow
, nsTreeColumn
* aCol
,
83 const nsAString
& aElement
, nsresult
& rv
);
84 already_AddRefed
<DOMRect
> GetCoordsForCellItem(int32_t row
, nsTreeColumn
& col
,
85 const nsAString
& element
,
88 bool IsCellCropped(int32_t row
, nsTreeColumn
* col
, ErrorResult
& aRv
);
90 void RemoveImageCacheEntry(int32_t row
, nsTreeColumn
& col
, ErrorResult
& aRv
);
92 void SetFocused(bool aFocused
);
93 void EnsureRowIsVisible(int32_t index
);
94 void Invalidate(void);
95 void InvalidateColumn(nsTreeColumn
* col
);
96 void InvalidateRow(int32_t index
);
97 void InvalidateCell(int32_t row
, nsTreeColumn
* col
);
98 void InvalidateRange(int32_t startIndex
, int32_t endIndex
);
99 void RowCountChanged(int32_t index
, int32_t count
);
100 void BeginUpdateBatch(void);
101 void EndUpdateBatch(void);
102 void ClearStyleAndImageCaches(void);
104 virtual void UnbindFromTree(UnbindContext
&) override
;
105 virtual void DestroyContent() override
;
107 void BodyDestroyed(int32_t aFirstVisibleRow
) {
109 mCachedFirstVisibleRow
= aFirstVisibleRow
;
112 int32_t GetCachedTopVisibleRow() { return mCachedFirstVisibleRow
; }
115 int32_t mCachedFirstVisibleRow
;
117 nsTreeBodyFrame
* mTreeBody
;
118 nsCOMPtr
<nsITreeView
> mView
;
120 virtual ~XULTreeElement() = default;
122 JSObject
* WrapNode(JSContext
* aCx
,
123 JS::Handle
<JSObject
*> aGivenProto
) override
;
127 } // namespace mozilla