1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/layout/xul/grid/nsGrid.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,133 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 + 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#ifndef nsGrid_h___ 1.11 +#define nsGrid_h___ 1.12 + 1.13 +#include "nsStackLayout.h" 1.14 +#include "nsIGridPart.h" 1.15 +#include "nsCOMPtr.h" 1.16 + 1.17 +class nsGridRowGroupLayout; 1.18 +class nsGridRowLayout; 1.19 +class nsBoxLayoutState; 1.20 +class nsGridCell; 1.21 + 1.22 +//#define DEBUG_grid 1 1.23 + 1.24 +/** 1.25 + * The grid data structure, i.e., the grid cellmap. 1.26 + */ 1.27 +class nsGrid 1.28 +{ 1.29 +public: 1.30 + nsGrid(); 1.31 + ~nsGrid(); 1.32 + 1.33 + nsGridRow* GetColumnAt(int32_t aIndex, bool aIsHorizontal = true); 1.34 + nsGridRow* GetRowAt(int32_t aIndex, bool aIsHorizontal = true); 1.35 + nsGridCell* GetCellAt(int32_t aX, int32_t aY); 1.36 + 1.37 + void NeedsRebuild(nsBoxLayoutState& aBoxLayoutState); 1.38 + void RebuildIfNeeded(); 1.39 + 1.40 + // For all the methods taking an aIsHorizontal parameter: 1.41 + // * When aIsHorizontal is true, the words "rows" and (for 1.42 + // GetColumnCount) "columns" refer to their normal meanings. 1.43 + // * When aIsHorizontal is false, the meanings are flipped. 1.44 + // FIXME: Maybe eliminate GetColumnCount and change aIsHorizontal to 1.45 + // aIsRows? (Calling it horizontal doesn't really make sense because 1.46 + // row groups and columns have vertical orientation, whereas column 1.47 + // groups and rows are horizontal.) 1.48 + 1.49 + nsSize GetPrefRowSize(nsBoxLayoutState& aBoxLayoutState, int32_t aRowIndex, bool aIsHorizontal = true); 1.50 + nsSize GetMinRowSize(nsBoxLayoutState& aBoxLayoutState, int32_t aRowIndex, bool aIsHorizontal = true); 1.51 + nsSize GetMaxRowSize(nsBoxLayoutState& aBoxLayoutState, int32_t aRowIndex, bool aIsHorizontal = true); 1.52 + nscoord GetRowFlex(nsBoxLayoutState& aBoxLayoutState, int32_t aRowIndex, bool aIsHorizontal = true); 1.53 + 1.54 + nscoord GetPrefRowHeight(nsBoxLayoutState& aBoxLayoutState, int32_t aRowIndex, bool aIsHorizontal = true); 1.55 + nscoord GetMinRowHeight(nsBoxLayoutState& aBoxLayoutState, int32_t aRowIndex, bool aIsHorizontal = true); 1.56 + nscoord GetMaxRowHeight(nsBoxLayoutState& aBoxLayoutState, int32_t aRowIndex, bool aIsHorizontal = true); 1.57 + void GetRowOffsets(nsBoxLayoutState& aState, int32_t aIndex, nscoord& aTop, nscoord& aBottom, bool aIsHorizontal = true); 1.58 + 1.59 + void RowAddedOrRemoved(nsBoxLayoutState& aBoxLayoutState, int32_t aIndex, bool aIsHorizontal = true); 1.60 + void CellAddedOrRemoved(nsBoxLayoutState& aBoxLayoutState, int32_t aIndex, bool aIsHorizontal = true); 1.61 + void DirtyRows(nsIFrame* aRowBox, nsBoxLayoutState& aState); 1.62 +#ifdef DEBUG_grid 1.63 + void PrintCellMap(); 1.64 +#endif 1.65 + int32_t GetExtraColumnCount(bool aIsHorizontal = true); 1.66 + int32_t GetExtraRowCount(bool aIsHorizontal = true); 1.67 + 1.68 +// accessors 1.69 + void SetBox(nsIFrame* aBox) { mBox = aBox; } 1.70 + nsIFrame* GetBox() { return mBox; } 1.71 + nsIFrame* GetRowsBox() { return mRowsBox; } 1.72 + nsIFrame* GetColumnsBox() { return mColumnsBox; } 1.73 + int32_t GetRowCount(int32_t aIsHorizontal = true); 1.74 + int32_t GetColumnCount(int32_t aIsHorizontal = true); 1.75 + 1.76 + static nsIFrame* GetScrolledBox(nsIFrame* aChild); 1.77 + static nsIFrame* GetScrollBox(nsIFrame* aChild); 1.78 + static nsIGridPart* GetPartFromBox(nsIFrame* aBox); 1.79 + void GetFirstAndLastRow(nsBoxLayoutState& aState, 1.80 + int32_t& aFirstIndex, 1.81 + int32_t& aLastIndex, 1.82 + nsGridRow*& aFirstRow, 1.83 + nsGridRow*& aLastRow, 1.84 + bool aIsHorizontal); 1.85 + 1.86 +private: 1.87 + 1.88 + nsMargin GetBoxTotalMargin(nsIFrame* aBox, bool aIsHorizontal = true); 1.89 + 1.90 + void FreeMap(); 1.91 + void FindRowsAndColumns(nsIFrame** aRows, nsIFrame** aColumns); 1.92 + void BuildRows(nsIFrame* aBox, int32_t aSize, nsGridRow** aColumnsRows, bool aIsHorizontal = true); 1.93 + nsGridCell* BuildCellMap(int32_t aRows, int32_t aColumns); 1.94 + void PopulateCellMap(nsGridRow* aRows, nsGridRow* aColumns, int32_t aRowCount, int32_t aColumnCount, bool aIsHorizontal = true); 1.95 + void CountRowsColumns(nsIFrame* aBox, int32_t& aRowCount, int32_t& aComputedColumnCount); 1.96 + void SetLargestSize(nsSize& aSize, nscoord aHeight, bool aIsHorizontal = true); 1.97 + void SetSmallestSize(nsSize& aSize, nscoord aHeight, bool aIsHorizontal = true); 1.98 + bool IsGrid(nsIFrame* aBox); 1.99 + 1.100 + // the box that implement the <grid> tag 1.101 + nsIFrame* mBox; 1.102 + 1.103 + // an array of row object 1.104 + nsGridRow* mRows; 1.105 + 1.106 + // an array of columns objects. 1.107 + nsGridRow* mColumns; 1.108 + 1.109 + // the first in the <grid> that implements the <rows> tag. 1.110 + nsIFrame* mRowsBox; 1.111 + 1.112 + // the first in the <grid> that implements the <columns> tag. 1.113 + nsIFrame* mColumnsBox; 1.114 + 1.115 + // a flag that is false tells us to rebuild the who grid 1.116 + bool mNeedsRebuild; 1.117 + 1.118 + // number of rows and columns as defined by the XUL 1.119 + int32_t mRowCount; 1.120 + int32_t mColumnCount; 1.121 + 1.122 + // number of rows and columns that are implied but not 1.123 + // explicitly defined int he XUL 1.124 + int32_t mExtraRowCount; 1.125 + int32_t mExtraColumnCount; 1.126 + 1.127 + // x,y array of cells in the rows and columns 1.128 + nsGridCell* mCellMap; 1.129 + 1.130 + // a flag that when true suppresses all other MarkDirties. This 1.131 + // prevents lots of extra work being done. 1.132 + bool mMarkingDirty; 1.133 +}; 1.134 + 1.135 +#endif 1.136 +