layout/xul/grid/nsGrid.h

Fri, 16 Jan 2015 18:13:44 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 18:13:44 +0100
branch
TOR_BUG_9701
changeset 14
925c144e1f1f
permissions
-rw-r--r--

Integrate suggestion from review to improve consistency with existing code.

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

mercurial