nsTreeBodyFrame.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651
  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. #ifndef nsTreeBodyFrame_h
  6. #define nsTreeBodyFrame_h
  7. #include "mozilla/Attributes.h"
  8. #include "nsLeafBoxFrame.h"
  9. #include "nsITreeView.h"
  10. #include "nsICSSPseudoComparator.h"
  11. #include "nsIScrollbarMediator.h"
  12. #include "nsITimer.h"
  13. #include "nsIReflowCallback.h"
  14. #include "nsTArray.h"
  15. #include "nsTreeStyleCache.h"
  16. #include "nsTreeColumns.h"
  17. #include "nsDataHashtable.h"
  18. #include "imgIRequest.h"
  19. #include "imgINotificationObserver.h"
  20. #include "nsScrollbarFrame.h"
  21. #include "nsThreadUtils.h"
  22. #include "mozilla/LookAndFeel.h"
  23. class nsFontMetrics;
  24. class nsOverflowChecker;
  25. class nsTreeImageListener;
  26. namespace mozilla {
  27. namespace layout {
  28. class ScrollbarActivity;
  29. } // namespace layout
  30. } // namespace mozilla
  31. // An entry in the tree's image cache
  32. struct nsTreeImageCacheEntry
  33. {
  34. nsTreeImageCacheEntry() {}
  35. nsTreeImageCacheEntry(imgIRequest *aRequest, imgINotificationObserver *aListener)
  36. : request(aRequest), listener(aListener) {}
  37. nsCOMPtr<imgIRequest> request;
  38. nsCOMPtr<imgINotificationObserver> listener;
  39. };
  40. // The actual frame that paints the cells and rows.
  41. class nsTreeBodyFrame final
  42. : public nsLeafBoxFrame
  43. , public nsICSSPseudoComparator
  44. , public nsIScrollbarMediator
  45. , public nsIReflowCallback
  46. {
  47. typedef mozilla::layout::ScrollbarActivity ScrollbarActivity;
  48. typedef mozilla::image::DrawResult DrawResult;
  49. public:
  50. explicit nsTreeBodyFrame(nsStyleContext* aContext);
  51. ~nsTreeBodyFrame();
  52. NS_DECL_QUERYFRAME_TARGET(nsTreeBodyFrame)
  53. NS_DECL_QUERYFRAME
  54. NS_DECL_FRAMEARENA_HELPERS
  55. // Callback handler methods for refresh driver based animations.
  56. // Calls to these functions are forwarded from nsTreeImageListener. These
  57. // mirror how nsImageFrame works.
  58. nsresult OnImageIsAnimated(imgIRequest* aRequest);
  59. // non-virtual signatures like nsITreeBodyFrame
  60. already_AddRefed<nsTreeColumns> Columns() const
  61. {
  62. RefPtr<nsTreeColumns> cols = mColumns;
  63. return cols.forget();
  64. }
  65. already_AddRefed<nsITreeView> GetExistingView() const
  66. {
  67. nsCOMPtr<nsITreeView> view = mView;
  68. return view.forget();
  69. }
  70. nsresult GetView(nsITreeView **aView);
  71. nsresult SetView(nsITreeView *aView);
  72. bool GetFocused() const { return mFocused; }
  73. nsresult SetFocused(bool aFocused);
  74. nsresult GetTreeBody(nsIDOMElement **aElement);
  75. int32_t RowHeight() const;
  76. int32_t RowWidth();
  77. int32_t GetHorizontalPosition() const;
  78. nsresult GetSelectionRegion(nsIScriptableRegion **aRegion);
  79. int32_t FirstVisibleRow() const { return mTopRowIndex; }
  80. int32_t LastVisibleRow() const { return mTopRowIndex + mPageLength; }
  81. int32_t PageLength() const { return mPageLength; }
  82. nsresult EnsureRowIsVisible(int32_t aRow);
  83. nsresult EnsureCellIsVisible(int32_t aRow, nsITreeColumn *aCol);
  84. nsresult ScrollToRow(int32_t aRow);
  85. nsresult ScrollByLines(int32_t aNumLines);
  86. nsresult ScrollByPages(int32_t aNumPages);
  87. nsresult ScrollToCell(int32_t aRow, nsITreeColumn *aCol);
  88. nsresult ScrollToColumn(nsITreeColumn *aCol);
  89. nsresult ScrollToHorizontalPosition(int32_t aValue);
  90. nsresult Invalidate();
  91. nsresult InvalidateColumn(nsITreeColumn *aCol);
  92. nsresult InvalidateRow(int32_t aRow);
  93. nsresult InvalidateCell(int32_t aRow, nsITreeColumn *aCol);
  94. nsresult InvalidateRange(int32_t aStart, int32_t aEnd);
  95. nsresult InvalidateColumnRange(int32_t aStart, int32_t aEnd,
  96. nsITreeColumn *aCol);
  97. nsresult GetRowAt(int32_t aX, int32_t aY, int32_t *aValue);
  98. nsresult GetCellAt(int32_t aX, int32_t aY, int32_t *aRow,
  99. nsITreeColumn **aCol, nsACString &aChildElt);
  100. nsresult GetCoordsForCellItem(int32_t aRow, nsITreeColumn *aCol,
  101. const nsACString &aElt,
  102. int32_t *aX, int32_t *aY,
  103. int32_t *aWidth, int32_t *aHeight);
  104. nsresult IsCellCropped(int32_t aRow, nsITreeColumn *aCol, bool *aResult);
  105. nsresult RowCountChanged(int32_t aIndex, int32_t aCount);
  106. nsresult BeginUpdateBatch();
  107. nsresult EndUpdateBatch();
  108. nsresult ClearStyleAndImageCaches();
  109. void CancelImageRequests();
  110. void ManageReflowCallback(const nsRect& aRect, nscoord aHorzWidth);
  111. virtual nsSize GetXULMinSize(nsBoxLayoutState& aBoxLayoutState) override;
  112. virtual void SetXULBounds(nsBoxLayoutState& aBoxLayoutState, const nsRect& aRect,
  113. bool aRemoveOverflowArea = false) override;
  114. // nsIReflowCallback
  115. virtual bool ReflowFinished() override;
  116. virtual void ReflowCallbackCanceled() override;
  117. // nsICSSPseudoComparator
  118. virtual bool PseudoMatches(nsCSSSelector* aSelector) override;
  119. // nsIScrollbarMediator
  120. virtual void ScrollByPage(nsScrollbarFrame* aScrollbar, int32_t aDirection,
  121. nsIScrollbarMediator::ScrollSnapMode aSnap
  122. = nsIScrollbarMediator::DISABLE_SNAP) override;
  123. virtual void ScrollByWhole(nsScrollbarFrame* aScrollbar, int32_t aDirection,
  124. nsIScrollbarMediator::ScrollSnapMode aSnap
  125. = nsIScrollbarMediator::DISABLE_SNAP) override;
  126. virtual void ScrollByLine(nsScrollbarFrame* aScrollbar, int32_t aDirection,
  127. nsIScrollbarMediator::ScrollSnapMode aSnap
  128. = nsIScrollbarMediator::DISABLE_SNAP) override;
  129. virtual void RepeatButtonScroll(nsScrollbarFrame* aScrollbar) override;
  130. virtual void ThumbMoved(nsScrollbarFrame* aScrollbar,
  131. nscoord aOldPos,
  132. nscoord aNewPos) override;
  133. virtual void ScrollbarReleased(nsScrollbarFrame* aScrollbar) override {}
  134. virtual void VisibilityChanged(bool aVisible) override { Invalidate(); }
  135. virtual nsIFrame* GetScrollbarBox(bool aVertical) override {
  136. ScrollParts parts = GetScrollParts();
  137. return aVertical ? parts.mVScrollbar : parts.mHScrollbar;
  138. }
  139. virtual void ScrollbarActivityStarted() const override;
  140. virtual void ScrollbarActivityStopped() const override;
  141. virtual bool IsScrollbarOnRight() const override {
  142. return (StyleVisibility()->mDirection == NS_STYLE_DIRECTION_LTR);
  143. }
  144. virtual bool ShouldSuppressScrollbarRepaints() const override {
  145. return false;
  146. }
  147. // Overridden from nsIFrame to cache our pres context.
  148. virtual void Init(nsIContent* aContent,
  149. nsContainerFrame* aParent,
  150. nsIFrame* aPrevInFlow) override;
  151. virtual void DestroyFrom(nsIFrame* aDestructRoot) override;
  152. virtual nsresult GetCursor(const nsPoint& aPoint,
  153. nsIFrame::Cursor& aCursor) override;
  154. virtual nsresult HandleEvent(nsPresContext* aPresContext,
  155. mozilla::WidgetGUIEvent* aEvent,
  156. nsEventStatus* aEventStatus) override;
  157. virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder,
  158. const nsDisplayListSet& aLists) override;
  159. virtual void DidSetStyleContext(nsStyleContext* aOldStyleContext) override;
  160. friend nsIFrame* NS_NewTreeBodyFrame(nsIPresShell* aPresShell);
  161. friend class nsTreeColumn;
  162. struct ScrollParts {
  163. nsScrollbarFrame* mVScrollbar;
  164. nsCOMPtr<nsIContent> mVScrollbarContent;
  165. nsScrollbarFrame* mHScrollbar;
  166. nsCOMPtr<nsIContent> mHScrollbarContent;
  167. nsIFrame* mColumnsFrame;
  168. nsIScrollableFrame* mColumnsScrollFrame;
  169. };
  170. DrawResult PaintTreeBody(nsRenderingContext& aRenderingContext,
  171. const nsRect& aDirtyRect, nsPoint aPt);
  172. nsITreeBoxObject* GetTreeBoxObject() const { return mTreeBoxObject; }
  173. // Get the base element, <tree> or <select>
  174. nsIContent* GetBaseElement();
  175. bool GetVerticalOverflow() const { return mVerticalOverflow; }
  176. bool GetHorizontalOverflow() const {return mHorizontalOverflow; }
  177. protected:
  178. friend class nsOverflowChecker;
  179. // This method paints a specific column background of the tree.
  180. DrawResult PaintColumn(nsTreeColumn* aColumn,
  181. const nsRect& aColumnRect,
  182. nsPresContext* aPresContext,
  183. nsRenderingContext& aRenderingContext,
  184. const nsRect& aDirtyRect);
  185. // This method paints a single row in the tree.
  186. DrawResult PaintRow(int32_t aRowIndex,
  187. const nsRect& aRowRect,
  188. nsPresContext* aPresContext,
  189. nsRenderingContext& aRenderingContext,
  190. const nsRect& aDirtyRect,
  191. nsPoint aPt);
  192. // This method paints a single separator in the tree.
  193. DrawResult PaintSeparator(int32_t aRowIndex,
  194. const nsRect& aSeparatorRect,
  195. nsPresContext* aPresContext,
  196. nsRenderingContext& aRenderingContext,
  197. const nsRect& aDirtyRect);
  198. // This method paints a specific cell in a given row of the tree.
  199. DrawResult PaintCell(int32_t aRowIndex,
  200. nsTreeColumn* aColumn,
  201. const nsRect& aCellRect,
  202. nsPresContext* aPresContext,
  203. nsRenderingContext& aRenderingContext,
  204. const nsRect& aDirtyRect,
  205. nscoord& aCurrX,
  206. nsPoint aPt);
  207. // This method paints the twisty inside a cell in the primary column of an tree.
  208. DrawResult PaintTwisty(int32_t aRowIndex,
  209. nsTreeColumn* aColumn,
  210. const nsRect& aTwistyRect,
  211. nsPresContext* aPresContext,
  212. nsRenderingContext& aRenderingContext,
  213. const nsRect& aDirtyRect,
  214. nscoord& aRemainingWidth,
  215. nscoord& aCurrX);
  216. // This method paints the image inside the cell of an tree.
  217. DrawResult PaintImage(int32_t aRowIndex,
  218. nsTreeColumn* aColumn,
  219. const nsRect& aImageRect,
  220. nsPresContext* aPresContext,
  221. nsRenderingContext& aRenderingContext,
  222. const nsRect& aDirtyRect,
  223. nscoord& aRemainingWidth,
  224. nscoord& aCurrX);
  225. // This method paints the text string inside a particular cell of the tree.
  226. DrawResult PaintText(int32_t aRowIndex,
  227. nsTreeColumn* aColumn,
  228. const nsRect& aTextRect,
  229. nsPresContext* aPresContext,
  230. nsRenderingContext& aRenderingContext,
  231. const nsRect& aDirtyRect,
  232. nscoord& aCurrX);
  233. // This method paints the checkbox inside a particular cell of the tree.
  234. DrawResult PaintCheckbox(int32_t aRowIndex,
  235. nsTreeColumn* aColumn,
  236. const nsRect& aCheckboxRect,
  237. nsPresContext* aPresContext,
  238. nsRenderingContext& aRenderingContext,
  239. const nsRect& aDirtyRect);
  240. // This method paints the progress meter inside a particular cell of the tree.
  241. DrawResult PaintProgressMeter(int32_t aRowIndex,
  242. nsTreeColumn* aColumn,
  243. const nsRect& aProgressMeterRect,
  244. nsPresContext* aPresContext,
  245. nsRenderingContext& aRenderingContext,
  246. const nsRect& aDirtyRect);
  247. // This method paints a drop feedback of the tree.
  248. DrawResult PaintDropFeedback(const nsRect& aDropFeedbackRect,
  249. nsPresContext* aPresContext,
  250. nsRenderingContext& aRenderingContext,
  251. const nsRect& aDirtyRect,
  252. nsPoint aPt);
  253. // This method is called with a specific style context and rect to
  254. // paint the background rect as if it were a full-blown frame.
  255. DrawResult PaintBackgroundLayer(nsStyleContext* aStyleContext,
  256. nsPresContext* aPresContext,
  257. nsRenderingContext& aRenderingContext,
  258. const nsRect& aRect,
  259. const nsRect& aDirtyRect);
  260. // An internal hit test. aX and aY are expected to be in twips in the
  261. // coordinate system of this frame.
  262. int32_t GetRowAt(nscoord aX, nscoord aY);
  263. // Check for bidi characters in the text, and if there are any, ensure
  264. // that the prescontext is in bidi mode.
  265. void CheckTextForBidi(nsAutoString& aText);
  266. void AdjustForCellText(nsAutoString& aText,
  267. int32_t aRowIndex,
  268. nsTreeColumn* aColumn,
  269. nsRenderingContext& aRenderingContext,
  270. nsFontMetrics& aFontMetrics,
  271. nsRect& aTextRect);
  272. // A helper used when hit testing.
  273. nsIAtom* GetItemWithinCellAt(nscoord aX, const nsRect& aCellRect,
  274. int32_t aRowIndex, nsTreeColumn* aColumn);
  275. // An internal hit test. aX and aY are expected to be in twips in the
  276. // coordinate system of this frame.
  277. void GetCellAt(nscoord aX, nscoord aY, int32_t* aRow, nsTreeColumn** aCol,
  278. nsIAtom** aChildElt);
  279. // Retrieve the area for the twisty for a cell.
  280. nsITheme* GetTwistyRect(int32_t aRowIndex,
  281. nsTreeColumn* aColumn,
  282. nsRect& aImageRect,
  283. nsRect& aTwistyRect,
  284. nsPresContext* aPresContext,
  285. nsStyleContext* aTwistyContext);
  286. // Fetch an image from the image cache.
  287. nsresult GetImage(int32_t aRowIndex, nsTreeColumn* aCol, bool aUseContext,
  288. nsStyleContext* aStyleContext, bool& aAllowImageRegions, imgIContainer** aResult);
  289. // Returns the size of a given image. This size *includes* border and
  290. // padding. It does not include margins.
  291. nsRect GetImageSize(int32_t aRowIndex, nsTreeColumn* aCol, bool aUseContext, nsStyleContext* aStyleContext);
  292. // Returns the destination size of the image, not including borders and padding.
  293. nsSize GetImageDestSize(nsStyleContext* aStyleContext, bool useImageRegion, imgIContainer* image);
  294. // Returns the source rectangle of the image to be displayed.
  295. nsRect GetImageSourceRect(nsStyleContext* aStyleContext, bool useImageRegion, imgIContainer* image);
  296. // Returns the height of rows in the tree.
  297. int32_t GetRowHeight();
  298. // Returns our indentation width.
  299. int32_t GetIndentation();
  300. // Calculates our width/height once border and padding have been removed.
  301. void CalcInnerBox();
  302. // Calculate the total width of our scrollable portion
  303. nscoord CalcHorzWidth(const ScrollParts& aParts);
  304. // Looks up a style context in the style cache. On a cache miss we resolve
  305. // the pseudo-styles passed in and place them into the cache.
  306. nsStyleContext* GetPseudoStyleContext(nsIAtom* aPseudoElement);
  307. // Retrieves the scrollbars and scrollview relevant to this treebody. We
  308. // traverse the frame tree under our base element, in frame order, looking
  309. // for the first relevant vertical scrollbar, horizontal scrollbar, and
  310. // scrollable frame (with associated content and scrollable view). These
  311. // are all volatile and should not be retained.
  312. ScrollParts GetScrollParts();
  313. // Update the curpos of the scrollbar.
  314. void UpdateScrollbars(const ScrollParts& aParts);
  315. // Update the maxpos of the scrollbar.
  316. void InvalidateScrollbars(const ScrollParts& aParts, nsWeakFrame& aWeakColumnsFrame);
  317. // Check overflow and generate events.
  318. void CheckOverflow(const ScrollParts& aParts);
  319. // Calls UpdateScrollbars, Invalidate aNeedsFullInvalidation if true,
  320. // InvalidateScrollbars and finally CheckOverflow.
  321. // returns true if the frame is still alive after the method call.
  322. bool FullScrollbarsUpdate(bool aNeedsFullInvalidation);
  323. // Use to auto-fill some of the common properties without the view having to do it.
  324. // Examples include container, open, selected, and focus.
  325. void PrefillPropertyArray(int32_t aRowIndex, nsTreeColumn* aCol);
  326. // Our internal scroll method, used by all the public scroll methods.
  327. nsresult ScrollInternal(const ScrollParts& aParts, int32_t aRow);
  328. nsresult ScrollToRowInternal(const ScrollParts& aParts, int32_t aRow);
  329. nsresult ScrollToColumnInternal(const ScrollParts& aParts, nsITreeColumn* aCol);
  330. nsresult ScrollHorzInternal(const ScrollParts& aParts, int32_t aPosition);
  331. nsresult EnsureRowIsVisibleInternal(const ScrollParts& aParts, int32_t aRow);
  332. // Convert client pixels into appunits in our coordinate space.
  333. nsPoint AdjustClientCoordsToBoxCoordSpace(int32_t aX, int32_t aY);
  334. // Cache the box object
  335. void EnsureBoxObject();
  336. void EnsureView();
  337. nsresult GetCellWidth(int32_t aRow, nsTreeColumn* aCol,
  338. nsRenderingContext* aRenderingContext,
  339. nscoord& aDesiredSize, nscoord& aCurrentSize);
  340. nscoord CalcMaxRowWidth();
  341. // Translate the given rect horizontally from tree coordinates into the
  342. // coordinate system of our nsTreeBodyFrame. If clip is true, then clip the
  343. // rect to its intersection with mInnerBox in the horizontal direction.
  344. // Return whether the result has a nonempty intersection with mInnerBox
  345. // after projecting both onto the horizontal coordinate axis.
  346. bool OffsetForHorzScroll(nsRect& rect, bool clip);
  347. bool CanAutoScroll(int32_t aRowIndex);
  348. // Calc the row and above/below/on status given where the mouse currently is hovering.
  349. // Also calc if we're in the region in which we want to auto-scroll the tree.
  350. // A positive value of |aScrollLines| means scroll down, a negative value
  351. // means scroll up, a zero value means that we aren't in drag scroll region.
  352. void ComputeDropPosition(mozilla::WidgetGUIEvent* aEvent,
  353. int32_t* aRow,
  354. int16_t* aOrient,
  355. int16_t* aScrollLines);
  356. // Mark ourselves dirty if we're a select widget
  357. void MarkDirtyIfSelect();
  358. void InvalidateDropFeedback(int32_t aRow, int16_t aOrientation) {
  359. InvalidateRow(aRow);
  360. if (aOrientation != nsITreeView::DROP_ON)
  361. InvalidateRow(aRow + aOrientation);
  362. }
  363. public:
  364. static
  365. already_AddRefed<nsTreeColumn> GetColumnImpl(nsITreeColumn* aUnknownCol) {
  366. if (!aUnknownCol)
  367. return nullptr;
  368. nsCOMPtr<nsTreeColumn> col = do_QueryInterface(aUnknownCol);
  369. return col.forget();
  370. }
  371. /**
  372. * Remove an nsITreeImageListener from being tracked by this frame. Only tree
  373. * image listeners that are created by this frame are tracked.
  374. *
  375. * @param aListener A pointer to an nsTreeImageListener to no longer
  376. * track.
  377. */
  378. void RemoveTreeImageListener(nsTreeImageListener* aListener);
  379. protected:
  380. // Create a new timer. This method is used to delay various actions like
  381. // opening/closing folders or tree scrolling.
  382. // aID is type of the action, aFunc is the function to be called when
  383. // the timer fires and aType is type of timer - one shot or repeating.
  384. nsresult CreateTimer(const mozilla::LookAndFeel::IntID aID,
  385. nsTimerCallbackFunc aFunc, int32_t aType,
  386. nsITimer** aTimer);
  387. static void OpenCallback(nsITimer *aTimer, void *aClosure);
  388. static void CloseCallback(nsITimer *aTimer, void *aClosure);
  389. static void LazyScrollCallback(nsITimer *aTimer, void *aClosure);
  390. static void ScrollCallback(nsITimer *aTimer, void *aClosure);
  391. class ScrollEvent : public mozilla::Runnable {
  392. public:
  393. NS_DECL_NSIRUNNABLE
  394. explicit ScrollEvent(nsTreeBodyFrame *aInner) : mInner(aInner) {}
  395. void Revoke() { mInner = nullptr; }
  396. private:
  397. nsTreeBodyFrame* mInner;
  398. };
  399. void PostScrollEvent();
  400. void FireScrollEvent();
  401. /**
  402. * Clear the pointer to this frame for all nsTreeImageListeners that were
  403. * created by this frame.
  404. */
  405. void DetachImageListeners();
  406. #ifdef ACCESSIBILITY
  407. /**
  408. * Fires 'treeRowCountChanged' event asynchronously. The event supports
  409. * nsIDOMCustomEvent interface that is used to expose the following
  410. * information structures.
  411. *
  412. * @param aIndex the row index rows are added/removed from
  413. * @param aCount the number of added/removed rows (the sign points to
  414. * an operation, plus - addition, minus - removing)
  415. */
  416. void FireRowCountChangedEvent(int32_t aIndex, int32_t aCount);
  417. /**
  418. * Fires 'treeInvalidated' event asynchronously. The event supports
  419. * nsIDOMCustomEvent interface that is used to expose the information
  420. * structures described by method arguments.
  421. *
  422. * @param aStartRow the start index of invalidated rows, -1 means that
  423. * columns have been invalidated only
  424. * @param aEndRow the end index of invalidated rows, -1 means that columns
  425. * have been invalidated only
  426. * @param aStartCol the start invalidated column, nullptr means that only rows
  427. * have been invalidated
  428. * @param aEndCol the end invalidated column, nullptr means that rows have
  429. * been invalidated only
  430. */
  431. void FireInvalidateEvent(int32_t aStartRow, int32_t aEndRow,
  432. nsITreeColumn *aStartCol, nsITreeColumn *aEndCol);
  433. #endif
  434. protected: // Data Members
  435. class Slots {
  436. public:
  437. Slots() {
  438. }
  439. ~Slots() {
  440. if (mTimer)
  441. mTimer->Cancel();
  442. }
  443. friend class nsTreeBodyFrame;
  444. protected:
  445. // If the drop is actually allowed here or not.
  446. bool mDropAllowed;
  447. // True while dragging over the tree.
  448. bool mIsDragging;
  449. // The row the mouse is hovering over during a drop.
  450. int32_t mDropRow;
  451. // Where we want to draw feedback (above/on this row/below) if allowed.
  452. int16_t mDropOrient;
  453. // Number of lines to be scrolled.
  454. int16_t mScrollLines;
  455. // The drag action that was received for this slot
  456. uint32_t mDragAction;
  457. // Timer for opening/closing spring loaded folders or scrolling the tree.
  458. nsCOMPtr<nsITimer> mTimer;
  459. // An array used to keep track of all spring loaded folders.
  460. nsTArray<int32_t> mArray;
  461. };
  462. Slots* mSlots;
  463. nsRevocableEventPtr<ScrollEvent> mScrollEvent;
  464. RefPtr<ScrollbarActivity> mScrollbarActivity;
  465. // The cached box object parent.
  466. nsCOMPtr<nsITreeBoxObject> mTreeBoxObject;
  467. // Cached column information.
  468. RefPtr<nsTreeColumns> mColumns;
  469. // The current view for this tree widget. We get all of our row and cell data
  470. // from the view.
  471. nsCOMPtr<nsITreeView> mView;
  472. // A cache of all the style contexts we have seen for rows and cells of the tree. This is a mapping from
  473. // a list of atoms to a corresponding style context. This cache stores every combination that
  474. // occurs in the tree, so for n distinct properties, this cache could have 2 to the n entries
  475. // (the power set of all row properties).
  476. nsTreeStyleCache mStyleCache;
  477. // A hashtable that maps from URLs to image request/listener pairs. The URL
  478. // is provided by the view or by the style context. The style context
  479. // represents a resolved :-moz-tree-cell-image (or twisty) pseudo-element.
  480. // It maps directly to an imgIRequest.
  481. nsDataHashtable<nsStringHashKey, nsTreeImageCacheEntry> mImageCache;
  482. // A scratch array used when looking up cached style contexts.
  483. AtomArray mScratchArray;
  484. // The index of the first visible row and the # of rows visible onscreen.
  485. // The tree only examines onscreen rows, starting from
  486. // this index and going up to index+pageLength.
  487. int32_t mTopRowIndex;
  488. int32_t mPageLength;
  489. // The horizontal scroll position
  490. nscoord mHorzPosition;
  491. // The original desired horizontal width before changing it and posting a
  492. // reflow callback. In some cases, the desired horizontal width can first be
  493. // different from the current desired horizontal width, only to return to
  494. // the same value later during the same reflow. In this case, we can cancel
  495. // the posted reflow callback and prevent an unnecessary reflow.
  496. nscoord mOriginalHorzWidth;
  497. // Our desired horizontal width (the width for which we actually have tree
  498. // columns).
  499. nscoord mHorzWidth;
  500. // The amount by which to adjust the width of the last cell.
  501. // This depends on whether or not the columnpicker and scrollbars are present.
  502. nscoord mAdjustWidth;
  503. // Cached heights and indent info.
  504. nsRect mInnerBox; // 4-byte aligned
  505. int32_t mRowHeight;
  506. int32_t mIndentation;
  507. nscoord mStringWidth;
  508. int32_t mUpdateBatchNest;
  509. // Cached row count.
  510. int32_t mRowCount;
  511. // The row the mouse is hovering over.
  512. int32_t mMouseOverRow;
  513. // Whether or not we're currently focused.
  514. bool mFocused;
  515. // Do we have a fixed number of onscreen rows?
  516. bool mHasFixedRowCount;
  517. bool mVerticalOverflow;
  518. bool mHorizontalOverflow;
  519. bool mReflowCallbackPosted;
  520. // Set while we flush layout to take account of effects of
  521. // overflow/underflow event handlers
  522. bool mCheckingOverflow;
  523. // Hash table to keep track of which listeners we created and thus
  524. // have pointers to us.
  525. nsTHashtable<nsPtrHashKey<nsTreeImageListener> > mCreatedListeners;
  526. }; // class nsTreeBodyFrame
  527. #endif