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