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 XULTreeElement_h__ 8 #define XULTreeElement_h__ 9 10 #include "mozilla/Attributes.h" 11 #include "nsCycleCollectionParticipant.h" 12 #include "nsWrapperCache.h" 13 #include "nsString.h" 14 #include "nsXULElement.h" 15 #include "nsITreeView.h" 16 17 class nsTreeBodyFrame; 18 class nsTreeColumn; 19 class nsTreeColumns; 20 21 namespace mozilla { 22 class ErrorResult; 23 24 namespace dom { 25 26 struct TreeCellInfo; 27 class DOMRect; 28 enum class CallerType : uint32_t; 29 30 class XULTreeElement final : public nsXULElement { 31 public: XULTreeElement(already_AddRefed<mozilla::dom::NodeInfo> && aNodeInfo)32 explicit XULTreeElement(already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo) 33 : nsXULElement(std::move(aNodeInfo)), 34 mCachedFirstVisibleRow(0), 35 mTreeBody(nullptr) {} 36 37 NS_IMPL_FROMNODE_WITH_TAG(XULTreeElement, kNameSpaceID_XUL, tree) 38 39 NS_DECL_ISUPPORTS_INHERITED 40 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(XULTreeElement, nsXULElement) 41 42 nsTreeBodyFrame* GetTreeBodyFrame(FlushType = FlushType::Frames); GetCachedTreeBodyFrame()43 nsTreeBodyFrame* GetCachedTreeBodyFrame() { return mTreeBody; } 44 45 already_AddRefed<nsTreeColumns> GetColumns(FlushType = FlushType::Frames); 46 GetView(CallerType)47 already_AddRefed<nsITreeView> GetView(CallerType /* unused */) { 48 return GetView(); 49 } 50 already_AddRefed<nsITreeView> GetView(FlushType = FlushType::Frames); 51 52 void SetView(nsITreeView* arg, CallerType aCallerType, ErrorResult& aRv); 53 54 bool Focused(); 55 56 already_AddRefed<Element> GetTreeBody(); 57 58 int32_t RowHeight(); 59 60 int32_t RowWidth(); 61 62 int32_t HorizontalPosition(); 63 64 void EnsureCellIsVisible(int32_t row, nsTreeColumn* col, ErrorResult& aRv); 65 66 void ScrollToRow(int32_t aRow); 67 68 void ScrollByLines(int32_t aNumLines); 69 70 void ScrollByPages(int32_t aNumPages); 71 72 int32_t GetFirstVisibleRow(); 73 74 int32_t GetLastVisibleRow(); 75 76 int32_t GetPageLength(); 77 78 int32_t GetRowAt(int32_t x, int32_t y); 79 80 void GetCellAt(int32_t x, int32_t y, TreeCellInfo& aRetVal, ErrorResult& aRv); 81 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, 86 ErrorResult& aRv); 87 88 bool IsCellCropped(int32_t row, nsTreeColumn* col, ErrorResult& aRv); 89 90 void RemoveImageCacheEntry(int32_t row, nsTreeColumn& col, ErrorResult& aRv); 91 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); 103 104 virtual void UnbindFromTree(bool aNullParent) override; 105 virtual void DestroyContent() override; 106 BodyDestroyed(int32_t aFirstVisibleRow)107 void BodyDestroyed(int32_t aFirstVisibleRow) { 108 mTreeBody = nullptr; 109 mCachedFirstVisibleRow = aFirstVisibleRow; 110 } 111 GetCachedTopVisibleRow()112 int32_t GetCachedTopVisibleRow() { return mCachedFirstVisibleRow; } 113 114 protected: 115 int32_t mCachedFirstVisibleRow; 116 117 nsTreeBodyFrame* mTreeBody; 118 nsCOMPtr<nsITreeView> mView; 119 120 virtual ~XULTreeElement() = default; 121 122 JSObject* WrapNode(JSContext* aCx, 123 JS::Handle<JSObject*> aGivenProto) override; 124 }; 125 126 } // namespace dom 127 } // namespace mozilla 128 129 #endif 130