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
|
|
|
|
|
|
|
//
|
|
|
|
// Eric Vaughan
|
|
|
|
// Netscape Communications
|
|
|
|
//
|
|
|
|
// See documentation in associated header file
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "nsGridLayout2.h"
|
|
|
|
#include "nsGridRowGroupLayout.h"
|
2007-08-21 13:08:58 -07:00
|
|
|
#include "nsGridRow.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsBox.h"
|
|
|
|
#include "nsIScrollableFrame.h"
|
|
|
|
#include "nsSprocketLayout.h"
|
2012-08-05 20:00:56 -07:00
|
|
|
#include "nsHTMLReflowState.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsresult
|
2011-07-11 07:05:10 -07:00
|
|
|
NS_NewGridLayout2( nsIPresShell* aPresShell, nsBoxLayout** aNewLayout)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
*aNewLayout = new nsGridLayout2(aPresShell);
|
|
|
|
NS_IF_ADDREF(*aNewLayout);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
nsGridLayout2::nsGridLayout2(nsIPresShell* aPresShell):nsStackLayout()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-09-13 14:13:54 -07:00
|
|
|
// static
|
|
|
|
void
|
2012-08-05 20:00:57 -07:00
|
|
|
nsGridLayout2::AddOffset(nsBoxLayoutState& aState, nsIFrame* aChild, nsSize& aSize)
|
2009-09-13 14:13:54 -07:00
|
|
|
{
|
|
|
|
nsMargin offset;
|
|
|
|
GetOffset(aState, aChild, offset);
|
|
|
|
aSize.width += offset.left;
|
|
|
|
aSize.height += offset.top;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
2012-08-05 20:00:57 -07:00
|
|
|
nsGridLayout2::Layout(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// XXX This should be set a better way!
|
|
|
|
mGrid.SetBox(aBox);
|
2011-07-04 07:39:10 -07:00
|
|
|
NS_ASSERTION(aBox->GetLayoutManager() == this, "setting incorrect box");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsresult rv = nsStackLayout::Layout(aBox, aBoxLayoutState);
|
|
|
|
#ifdef DEBUG_grid
|
|
|
|
mGrid.PrintCellMap();
|
|
|
|
#endif
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2008-01-08 23:28:39 -08:00
|
|
|
void
|
2012-08-05 20:00:57 -07:00
|
|
|
nsGridLayout2::IntrinsicWidthsDirty(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-01-08 23:28:39 -08:00
|
|
|
nsStackLayout::IntrinsicWidthsDirty(aBox, aBoxLayoutState);
|
2007-03-22 10:30:00 -07:00
|
|
|
// XXXldb We really don't need to do all the work that NeedsRebuild
|
|
|
|
// does; we just need to mark intrinsic widths dirty on the
|
|
|
|
// (row/column)(s/-groups).
|
|
|
|
mGrid.NeedsRebuild(aBoxLayoutState);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsGrid*
|
2012-08-22 08:56:38 -07:00
|
|
|
nsGridLayout2::GetGrid(nsIFrame* aBox, int32_t* aIndex, nsGridRowLayout* aRequestor)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// XXX This should be set a better way!
|
|
|
|
mGrid.SetBox(aBox);
|
2011-07-04 07:39:10 -07:00
|
|
|
NS_ASSERTION(aBox->GetLayoutManager() == this, "setting incorrect box");
|
2007-03-22 10:30:00 -07:00
|
|
|
return &mGrid;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-09-28 23:19:26 -07:00
|
|
|
nsGridLayout2::AddWidth(nsSize& aSize, nscoord aSize2, bool aIsHorizontal)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nscoord& size = GET_WIDTH(aSize, aIsHorizontal);
|
|
|
|
|
|
|
|
if (size != NS_INTRINSICSIZE) {
|
|
|
|
if (aSize2 == NS_INTRINSICSIZE)
|
|
|
|
size = NS_INTRINSICSIZE;
|
|
|
|
else
|
|
|
|
size += aSize2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-08 23:28:39 -08:00
|
|
|
nsSize
|
2012-08-05 20:00:57 -07:00
|
|
|
nsGridLayout2::GetMinSize(nsIFrame* aBox, nsBoxLayoutState& aState)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-01-08 23:28:39 -08:00
|
|
|
nsSize minSize = nsStackLayout::GetMinSize(aBox, aState);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// if there are no <rows> tags that will sum up our columns,
|
|
|
|
// sum up our columns here.
|
|
|
|
nsSize total(0,0);
|
2012-08-05 20:00:57 -07:00
|
|
|
nsIFrame* rowsBox = mGrid.GetRowsBox();
|
|
|
|
nsIFrame* columnsBox = mGrid.GetColumnsBox();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!rowsBox || !columnsBox) {
|
|
|
|
if (!rowsBox) {
|
|
|
|
// max height is the sum of our rows
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t rows = mGrid.GetRowCount();
|
|
|
|
for (int32_t i=0; i < rows; i++)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
nscoord height = mGrid.GetMinRowHeight(aState, i, true);
|
|
|
|
AddWidth(total, height, false); // AddHeight
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!columnsBox) {
|
|
|
|
// max height is the sum of our rows
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t columns = mGrid.GetColumnCount();
|
|
|
|
for (int32_t i=0; i < columns; i++)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
nscoord width = mGrid.GetMinRowHeight(aState, i, false);
|
|
|
|
AddWidth(total, width, true); // AddWidth
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
AddMargin(aBox, total);
|
|
|
|
AddOffset(aState, aBox, total);
|
2008-01-08 23:28:39 -08:00
|
|
|
AddLargestSize(minSize, total);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-01-08 23:28:39 -08:00
|
|
|
return minSize;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-01-08 23:28:39 -08:00
|
|
|
nsSize
|
2012-08-05 20:00:57 -07:00
|
|
|
nsGridLayout2::GetPrefSize(nsIFrame* aBox, nsBoxLayoutState& aState)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-01-08 23:28:39 -08:00
|
|
|
nsSize pref = nsStackLayout::GetPrefSize(aBox, aState);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// if there are no <rows> tags that will sum up our columns,
|
|
|
|
// sum up our columns here.
|
|
|
|
nsSize total(0,0);
|
2012-08-05 20:00:57 -07:00
|
|
|
nsIFrame* rowsBox = mGrid.GetRowsBox();
|
|
|
|
nsIFrame* columnsBox = mGrid.GetColumnsBox();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!rowsBox || !columnsBox) {
|
|
|
|
if (!rowsBox) {
|
|
|
|
// max height is the sum of our rows
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t rows = mGrid.GetRowCount();
|
|
|
|
for (int32_t i=0; i < rows; i++)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
nscoord height = mGrid.GetPrefRowHeight(aState, i, true);
|
|
|
|
AddWidth(total, height, false); // AddHeight
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!columnsBox) {
|
|
|
|
// max height is the sum of our rows
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t columns = mGrid.GetColumnCount();
|
|
|
|
for (int32_t i=0; i < columns; i++)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
nscoord width = mGrid.GetPrefRowHeight(aState, i, false);
|
|
|
|
AddWidth(total, width, true); // AddWidth
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
AddMargin(aBox, total);
|
|
|
|
AddOffset(aState, aBox, total);
|
2008-01-08 23:28:39 -08:00
|
|
|
AddLargestSize(pref, total);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-01-08 23:28:39 -08:00
|
|
|
return pref;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-01-08 23:28:39 -08:00
|
|
|
nsSize
|
2012-08-05 20:00:57 -07:00
|
|
|
nsGridLayout2::GetMaxSize(nsIFrame* aBox, nsBoxLayoutState& aState)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-01-08 23:28:39 -08:00
|
|
|
nsSize maxSize = nsStackLayout::GetMaxSize(aBox, aState);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// if there are no <rows> tags that will sum up our columns,
|
|
|
|
// sum up our columns here.
|
|
|
|
nsSize total(NS_INTRINSICSIZE, NS_INTRINSICSIZE);
|
2012-08-05 20:00:57 -07:00
|
|
|
nsIFrame* rowsBox = mGrid.GetRowsBox();
|
|
|
|
nsIFrame* columnsBox = mGrid.GetColumnsBox();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!rowsBox || !columnsBox) {
|
|
|
|
if (!rowsBox) {
|
|
|
|
total.height = 0;
|
|
|
|
// max height is the sum of our rows
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t rows = mGrid.GetRowCount();
|
|
|
|
for (int32_t i=0; i < rows; i++)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
nscoord height = mGrid.GetMaxRowHeight(aState, i, true);
|
|
|
|
AddWidth(total, height, false); // AddHeight
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!columnsBox) {
|
|
|
|
total.width = 0;
|
|
|
|
// max height is the sum of our rows
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t columns = mGrid.GetColumnCount();
|
|
|
|
for (int32_t i=0; i < columns; i++)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
nscoord width = mGrid.GetMaxRowHeight(aState, i, false);
|
|
|
|
AddWidth(total, width, true); // AddWidth
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
AddMargin(aBox, total);
|
|
|
|
AddOffset(aState, aBox, total);
|
2008-01-08 23:28:39 -08:00
|
|
|
AddSmallestSize(maxSize, total);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-01-08 23:28:39 -08:00
|
|
|
return maxSize;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t
|
2012-08-05 20:00:57 -07:00
|
|
|
nsGridLayout2::BuildRows(nsIFrame* aBox, nsGridRow* aRows)
|
2007-08-21 13:08:58 -07:00
|
|
|
{
|
|
|
|
if (aBox) {
|
2011-10-17 07:59:28 -07:00
|
|
|
aRows[0].Init(aBox, true);
|
2007-08-21 13:08:58 -07:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsMargin
|
2012-08-05 20:00:57 -07:00
|
|
|
nsGridLayout2::GetTotalMargin(nsIFrame* aBox, bool aIsHorizontal)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsMargin margin(0,0,0,0);
|
|
|
|
return margin;
|
|
|
|
}
|
|
|
|
|
2008-01-08 23:28:39 -08:00
|
|
|
void
|
2012-08-05 20:00:57 -07:00
|
|
|
nsGridLayout2::ChildrenInserted(nsIFrame* aBox, nsBoxLayoutState& aState,
|
|
|
|
nsIFrame* aPrevBox,
|
2009-07-30 10:23:32 -07:00
|
|
|
const nsFrameList::Slice& aNewChildren)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
mGrid.NeedsRebuild(aState);
|
|
|
|
}
|
|
|
|
|
2008-01-08 23:28:39 -08:00
|
|
|
void
|
2012-08-05 20:00:57 -07:00
|
|
|
nsGridLayout2::ChildrenAppended(nsIFrame* aBox, nsBoxLayoutState& aState,
|
2009-07-30 10:23:32 -07:00
|
|
|
const nsFrameList::Slice& aNewChildren)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
mGrid.NeedsRebuild(aState);
|
|
|
|
}
|
|
|
|
|
2008-01-08 23:28:39 -08:00
|
|
|
void
|
2012-08-05 20:00:57 -07:00
|
|
|
nsGridLayout2::ChildrenRemoved(nsIFrame* aBox, nsBoxLayoutState& aState,
|
|
|
|
nsIFrame* aChildList)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
mGrid.NeedsRebuild(aState);
|
|
|
|
}
|
|
|
|
|
2008-01-08 23:28:39 -08:00
|
|
|
void
|
2012-08-05 20:00:57 -07:00
|
|
|
nsGridLayout2::ChildrenSet(nsIFrame* aBox, nsBoxLayoutState& aState,
|
|
|
|
nsIFrame* aChildList)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
mGrid.NeedsRebuild(aState);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF_INHERITED(nsGridLayout2, nsStackLayout)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(nsGridLayout2, nsStackLayout)
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN(nsGridLayout2)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIGridPart)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIGridPart)
|
|
|
|
NS_INTERFACE_MAP_END_INHERITING(nsStackLayout)
|