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