nsGrid.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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 nsGrid_h___
  6. #define nsGrid_h___
  7. #include "nsStackLayout.h"
  8. #include "nsIGridPart.h"
  9. #include "nsCOMPtr.h"
  10. #include "mozilla/UniquePtr.h"
  11. class nsBoxLayoutState;
  12. class nsGridCell;
  13. //#define DEBUG_grid 1
  14. /**
  15. * The grid data structure, i.e., the grid cellmap.
  16. */
  17. class nsGrid
  18. {
  19. public:
  20. nsGrid();
  21. ~nsGrid();
  22. nsGridRow* GetColumnAt(int32_t aIndex, bool aIsHorizontal = true);
  23. nsGridRow* GetRowAt(int32_t aIndex, bool aIsHorizontal = true);
  24. nsGridCell* GetCellAt(int32_t aX, int32_t aY);
  25. void NeedsRebuild(nsBoxLayoutState& aBoxLayoutState);
  26. void RebuildIfNeeded();
  27. // For all the methods taking an aIsHorizontal parameter:
  28. // * When aIsHorizontal is true, the words "rows" and (for
  29. // GetColumnCount) "columns" refer to their normal meanings.
  30. // * When aIsHorizontal is false, the meanings are flipped.
  31. // FIXME: Maybe eliminate GetColumnCount and change aIsHorizontal to
  32. // aIsRows? (Calling it horizontal doesn't really make sense because
  33. // row groups and columns have vertical orientation, whereas column
  34. // groups and rows are horizontal.)
  35. nsSize GetPrefRowSize(nsBoxLayoutState& aBoxLayoutState, int32_t aRowIndex, bool aIsHorizontal = true);
  36. nsSize GetMinRowSize(nsBoxLayoutState& aBoxLayoutState, int32_t aRowIndex, bool aIsHorizontal = true);
  37. nsSize GetMaxRowSize(nsBoxLayoutState& aBoxLayoutState, int32_t aRowIndex, bool aIsHorizontal = true);
  38. nscoord GetRowFlex(int32_t aRowIndex, bool aIsHorizontal = true);
  39. nscoord GetPrefRowHeight(nsBoxLayoutState& aBoxLayoutState, int32_t aRowIndex, bool aIsHorizontal = true);
  40. nscoord GetMinRowHeight(nsBoxLayoutState& aBoxLayoutState, int32_t aRowIndex, bool aIsHorizontal = true);
  41. nscoord GetMaxRowHeight(nsBoxLayoutState& aBoxLayoutState, int32_t aRowIndex, bool aIsHorizontal = true);
  42. void GetRowOffsets(int32_t aIndex, nscoord& aTop, nscoord& aBottom, bool aIsHorizontal = true);
  43. void RowAddedOrRemoved(nsBoxLayoutState& aBoxLayoutState, int32_t aIndex, bool aIsHorizontal = true);
  44. void CellAddedOrRemoved(nsBoxLayoutState& aBoxLayoutState, int32_t aIndex, bool aIsHorizontal = true);
  45. void DirtyRows(nsIFrame* aRowBox, nsBoxLayoutState& aState);
  46. #ifdef DEBUG_grid
  47. void PrintCellMap();
  48. #endif
  49. int32_t GetExtraColumnCount(bool aIsHorizontal = true);
  50. int32_t GetExtraRowCount(bool aIsHorizontal = true);
  51. // accessors
  52. void SetBox(nsIFrame* aBox) { mBox = aBox; }
  53. nsIFrame* GetBox() { return mBox; }
  54. nsIFrame* GetRowsBox() { return mRowsBox; }
  55. nsIFrame* GetColumnsBox() { return mColumnsBox; }
  56. int32_t GetRowCount(int32_t aIsHorizontal = true);
  57. int32_t GetColumnCount(int32_t aIsHorizontal = true);
  58. static nsIFrame* GetScrolledBox(nsIFrame* aChild);
  59. static nsIFrame* GetScrollBox(nsIFrame* aChild);
  60. static nsIGridPart* GetPartFromBox(nsIFrame* aBox);
  61. void GetFirstAndLastRow(int32_t& aFirstIndex,
  62. int32_t& aLastIndex,
  63. nsGridRow*& aFirstRow,
  64. nsGridRow*& aLastRow,
  65. bool aIsHorizontal);
  66. private:
  67. nsMargin GetBoxTotalMargin(nsIFrame* aBox, bool aIsHorizontal = true);
  68. void FreeMap();
  69. void FindRowsAndColumns(nsIFrame** aRows, nsIFrame** aColumns);
  70. mozilla::UniquePtr<nsGridRow[]> BuildRows(nsIFrame* aBox, int32_t aSize,
  71. bool aIsHorizontal = true);
  72. mozilla::UniquePtr<nsGridCell[]> BuildCellMap(int32_t aRows, int32_t aColumns);
  73. void PopulateCellMap(nsGridRow* aRows, nsGridRow* aColumns, int32_t aRowCount, int32_t aColumnCount, bool aIsHorizontal = true);
  74. void CountRowsColumns(nsIFrame* aBox, int32_t& aRowCount, int32_t& aComputedColumnCount);
  75. void SetLargestSize(nsSize& aSize, nscoord aHeight, bool aIsHorizontal = true);
  76. void SetSmallestSize(nsSize& aSize, nscoord aHeight, bool aIsHorizontal = true);
  77. bool IsGrid(nsIFrame* aBox);
  78. // the box that implement the <grid> tag
  79. nsIFrame* mBox;
  80. // an array of row object
  81. mozilla::UniquePtr<nsGridRow[]> mRows;
  82. // an array of columns objects.
  83. mozilla::UniquePtr<nsGridRow[]> mColumns;
  84. // the first in the <grid> that implements the <rows> tag.
  85. nsIFrame* mRowsBox;
  86. // the first in the <grid> that implements the <columns> tag.
  87. nsIFrame* mColumnsBox;
  88. // a flag that is false tells us to rebuild the who grid
  89. bool mNeedsRebuild;
  90. // number of rows and columns as defined by the XUL
  91. int32_t mRowCount;
  92. int32_t mColumnCount;
  93. // number of rows and columns that are implied but not
  94. // explicitly defined int he XUL
  95. int32_t mExtraRowCount;
  96. int32_t mExtraColumnCount;
  97. // x,y array of cells in the rows and columns
  98. mozilla::UniquePtr<nsGridCell[]> mCellMap;
  99. // a flag that when true suppresses all other MarkDirties. This
  100. // prevents lots of extra work being done.
  101. bool mMarkingDirty;
  102. };
  103. #endif