michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef nsGrid_h___ michael@0: #define nsGrid_h___ michael@0: michael@0: #include "nsStackLayout.h" michael@0: #include "nsIGridPart.h" michael@0: #include "nsCOMPtr.h" michael@0: michael@0: class nsGridRowGroupLayout; michael@0: class nsGridRowLayout; michael@0: class nsBoxLayoutState; michael@0: class nsGridCell; michael@0: michael@0: //#define DEBUG_grid 1 michael@0: michael@0: /** michael@0: * The grid data structure, i.e., the grid cellmap. michael@0: */ michael@0: class nsGrid michael@0: { michael@0: public: michael@0: nsGrid(); michael@0: ~nsGrid(); michael@0: michael@0: nsGridRow* GetColumnAt(int32_t aIndex, bool aIsHorizontal = true); michael@0: nsGridRow* GetRowAt(int32_t aIndex, bool aIsHorizontal = true); michael@0: nsGridCell* GetCellAt(int32_t aX, int32_t aY); michael@0: michael@0: void NeedsRebuild(nsBoxLayoutState& aBoxLayoutState); michael@0: void RebuildIfNeeded(); michael@0: michael@0: // For all the methods taking an aIsHorizontal parameter: michael@0: // * When aIsHorizontal is true, the words "rows" and (for michael@0: // GetColumnCount) "columns" refer to their normal meanings. michael@0: // * When aIsHorizontal is false, the meanings are flipped. michael@0: // FIXME: Maybe eliminate GetColumnCount and change aIsHorizontal to michael@0: // aIsRows? (Calling it horizontal doesn't really make sense because michael@0: // row groups and columns have vertical orientation, whereas column michael@0: // groups and rows are horizontal.) michael@0: michael@0: nsSize GetPrefRowSize(nsBoxLayoutState& aBoxLayoutState, int32_t aRowIndex, bool aIsHorizontal = true); michael@0: nsSize GetMinRowSize(nsBoxLayoutState& aBoxLayoutState, int32_t aRowIndex, bool aIsHorizontal = true); michael@0: nsSize GetMaxRowSize(nsBoxLayoutState& aBoxLayoutState, int32_t aRowIndex, bool aIsHorizontal = true); michael@0: nscoord GetRowFlex(nsBoxLayoutState& aBoxLayoutState, int32_t aRowIndex, bool aIsHorizontal = true); michael@0: michael@0: nscoord GetPrefRowHeight(nsBoxLayoutState& aBoxLayoutState, int32_t aRowIndex, bool aIsHorizontal = true); michael@0: nscoord GetMinRowHeight(nsBoxLayoutState& aBoxLayoutState, int32_t aRowIndex, bool aIsHorizontal = true); michael@0: nscoord GetMaxRowHeight(nsBoxLayoutState& aBoxLayoutState, int32_t aRowIndex, bool aIsHorizontal = true); michael@0: void GetRowOffsets(nsBoxLayoutState& aState, int32_t aIndex, nscoord& aTop, nscoord& aBottom, bool aIsHorizontal = true); michael@0: michael@0: void RowAddedOrRemoved(nsBoxLayoutState& aBoxLayoutState, int32_t aIndex, bool aIsHorizontal = true); michael@0: void CellAddedOrRemoved(nsBoxLayoutState& aBoxLayoutState, int32_t aIndex, bool aIsHorizontal = true); michael@0: void DirtyRows(nsIFrame* aRowBox, nsBoxLayoutState& aState); michael@0: #ifdef DEBUG_grid michael@0: void PrintCellMap(); michael@0: #endif michael@0: int32_t GetExtraColumnCount(bool aIsHorizontal = true); michael@0: int32_t GetExtraRowCount(bool aIsHorizontal = true); michael@0: michael@0: // accessors michael@0: void SetBox(nsIFrame* aBox) { mBox = aBox; } michael@0: nsIFrame* GetBox() { return mBox; } michael@0: nsIFrame* GetRowsBox() { return mRowsBox; } michael@0: nsIFrame* GetColumnsBox() { return mColumnsBox; } michael@0: int32_t GetRowCount(int32_t aIsHorizontal = true); michael@0: int32_t GetColumnCount(int32_t aIsHorizontal = true); michael@0: michael@0: static nsIFrame* GetScrolledBox(nsIFrame* aChild); michael@0: static nsIFrame* GetScrollBox(nsIFrame* aChild); michael@0: static nsIGridPart* GetPartFromBox(nsIFrame* aBox); michael@0: void GetFirstAndLastRow(nsBoxLayoutState& aState, michael@0: int32_t& aFirstIndex, michael@0: int32_t& aLastIndex, michael@0: nsGridRow*& aFirstRow, michael@0: nsGridRow*& aLastRow, michael@0: bool aIsHorizontal); michael@0: michael@0: private: michael@0: michael@0: nsMargin GetBoxTotalMargin(nsIFrame* aBox, bool aIsHorizontal = true); michael@0: michael@0: void FreeMap(); michael@0: void FindRowsAndColumns(nsIFrame** aRows, nsIFrame** aColumns); michael@0: void BuildRows(nsIFrame* aBox, int32_t aSize, nsGridRow** aColumnsRows, bool aIsHorizontal = true); michael@0: nsGridCell* BuildCellMap(int32_t aRows, int32_t aColumns); michael@0: void PopulateCellMap(nsGridRow* aRows, nsGridRow* aColumns, int32_t aRowCount, int32_t aColumnCount, bool aIsHorizontal = true); michael@0: void CountRowsColumns(nsIFrame* aBox, int32_t& aRowCount, int32_t& aComputedColumnCount); michael@0: void SetLargestSize(nsSize& aSize, nscoord aHeight, bool aIsHorizontal = true); michael@0: void SetSmallestSize(nsSize& aSize, nscoord aHeight, bool aIsHorizontal = true); michael@0: bool IsGrid(nsIFrame* aBox); michael@0: michael@0: // the box that implement the tag michael@0: nsIFrame* mBox; michael@0: michael@0: // an array of row object michael@0: nsGridRow* mRows; michael@0: michael@0: // an array of columns objects. michael@0: nsGridRow* mColumns; michael@0: michael@0: // the first in the that implements the tag. michael@0: nsIFrame* mRowsBox; michael@0: michael@0: // the first in the that implements the tag. michael@0: nsIFrame* mColumnsBox; michael@0: michael@0: // a flag that is false tells us to rebuild the who grid michael@0: bool mNeedsRebuild; michael@0: michael@0: // number of rows and columns as defined by the XUL michael@0: int32_t mRowCount; michael@0: int32_t mColumnCount; michael@0: michael@0: // number of rows and columns that are implied but not michael@0: // explicitly defined int he XUL michael@0: int32_t mExtraRowCount; michael@0: int32_t mExtraColumnCount; michael@0: michael@0: // x,y array of cells in the rows and columns michael@0: nsGridCell* mCellMap; michael@0: michael@0: // a flag that when true suppresses all other MarkDirties. This michael@0: // prevents lots of extra work being done. michael@0: bool mMarkingDirty; michael@0: }; michael@0: michael@0: #endif michael@0: