2001-10-09 00:37:56 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04: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/. */
|
2001-10-09 00:37:56 +04:00
|
|
|
|
|
|
|
//
|
|
|
|
// Eric Vaughan
|
|
|
|
// Netscape Communications
|
|
|
|
//
|
|
|
|
// See documentation in associated header file
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "nsGridLayout2.h"
|
|
|
|
#include "nsGridRowGroupLayout.h"
|
2007-08-22 00:08:58 +04:00
|
|
|
#include "nsGridRow.h"
|
2001-10-09 00:37:56 +04:00
|
|
|
#include "nsBox.h"
|
|
|
|
#include "nsIScrollableFrame.h"
|
|
|
|
#include "nsSprocketLayout.h"
|
2016-07-21 13:36:34 +03:00
|
|
|
#include "mozilla/ReflowInput.h"
|
2001-10-09 00:37:56 +04:00
|
|
|
|
|
|
|
nsresult
|
2011-07-11 18:05:10 +04:00
|
|
|
NS_NewGridLayout2( nsIPresShell* aPresShell, nsBoxLayout** aNewLayout)
|
2001-10-09 00:37:56 +04:00
|
|
|
{
|
|
|
|
*aNewLayout = new nsGridLayout2(aPresShell);
|
|
|
|
NS_IF_ADDREF(*aNewLayout);
|
|
|
|
|
|
|
|
return NS_OK;
|
2017-07-06 15:00:35 +03:00
|
|
|
|
|
|
|
}
|
2001-10-09 00:37:56 +04:00
|
|
|
|
|
|
|
nsGridLayout2::nsGridLayout2(nsIPresShell* aPresShell):nsStackLayout()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-07-09 01:23:18 +04:00
|
|
|
nsGridLayout2::~nsGridLayout2()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-09-14 01:13:54 +04:00
|
|
|
// static
|
|
|
|
void
|
2015-12-07 21:17:47 +03:00
|
|
|
nsGridLayout2::AddOffset(nsIFrame* aChild, nsSize& aSize)
|
2009-09-14 01:13:54 +04:00
|
|
|
{
|
|
|
|
nsMargin offset;
|
2015-12-07 21:17:47 +03:00
|
|
|
GetOffset(aChild, offset);
|
2009-09-14 01:13:54 +04:00
|
|
|
aSize.width += offset.left;
|
|
|
|
aSize.height += offset.top;
|
|
|
|
}
|
|
|
|
|
2001-10-09 00:37:56 +04:00
|
|
|
NS_IMETHODIMP
|
2016-04-21 07:28:32 +03:00
|
|
|
nsGridLayout2::XULLayout(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState)
|
2001-10-09 00:37:56 +04:00
|
|
|
{
|
2005-11-22 08:52:34 +03:00
|
|
|
// XXX This should be set a better way!
|
2001-10-09 00:37:56 +04:00
|
|
|
mGrid.SetBox(aBox);
|
2016-04-21 07:28:33 +03:00
|
|
|
NS_ASSERTION(aBox->GetXULLayoutManager() == this, "setting incorrect box");
|
2005-11-22 08:52:34 +03:00
|
|
|
|
2016-04-21 07:28:32 +03:00
|
|
|
nsresult rv = nsStackLayout::XULLayout(aBox, aBoxLayoutState);
|
2001-10-10 01:02:29 +04:00
|
|
|
#ifdef DEBUG_grid
|
2001-10-09 00:37:56 +04:00
|
|
|
mGrid.PrintCellMap();
|
2001-10-10 01:02:29 +04:00
|
|
|
#endif
|
2001-10-09 00:37:56 +04:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2008-01-09 10:28:39 +03:00
|
|
|
void
|
2014-07-24 21:03:26 +04:00
|
|
|
nsGridLayout2::IntrinsicISizesDirty(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState)
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
{
|
2014-07-24 21:03:26 +04:00
|
|
|
nsStackLayout::IntrinsicISizesDirty(aBox, aBoxLayoutState);
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03: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);
|
|
|
|
}
|
|
|
|
|
2006-12-18 21:25:48 +03:00
|
|
|
nsGrid*
|
2012-08-22 19:56:38 +04:00
|
|
|
nsGridLayout2::GetGrid(nsIFrame* aBox, int32_t* aIndex, nsGridRowLayout* aRequestor)
|
2001-10-09 00:37:56 +04:00
|
|
|
{
|
2005-11-22 08:52:34 +03:00
|
|
|
// XXX This should be set a better way!
|
2001-10-10 01:02:29 +04:00
|
|
|
mGrid.SetBox(aBox);
|
2016-04-21 07:28:33 +03:00
|
|
|
NS_ASSERTION(aBox->GetXULLayoutManager() == this, "setting incorrect box");
|
2006-12-18 21:25:48 +03:00
|
|
|
return &mGrid;
|
2001-10-09 00:37:56 +04:00
|
|
|
}
|
|
|
|
|
2001-11-08 23:46:02 +03:00
|
|
|
void
|
2011-09-29 10:19:26 +04:00
|
|
|
nsGridLayout2::AddWidth(nsSize& aSize, nscoord aSize2, bool aIsHorizontal)
|
2001-11-08 23:46:02 +03:00
|
|
|
{
|
|
|
|
nscoord& size = GET_WIDTH(aSize, aIsHorizontal);
|
|
|
|
|
|
|
|
if (size != NS_INTRINSICSIZE) {
|
|
|
|
if (aSize2 == NS_INTRINSICSIZE)
|
|
|
|
size = NS_INTRINSICSIZE;
|
|
|
|
else
|
|
|
|
size += aSize2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-09 10:28:39 +03:00
|
|
|
nsSize
|
2016-04-21 07:28:31 +03:00
|
|
|
nsGridLayout2::GetXULMinSize(nsIFrame* aBox, nsBoxLayoutState& aState)
|
2001-10-09 00:37:56 +04:00
|
|
|
{
|
2017-07-06 15:00:35 +03:00
|
|
|
nsSize minSize = nsStackLayout::GetXULMinSize(aBox, aState);
|
2001-11-08 23:46:02 +03:00
|
|
|
|
|
|
|
// if there are no <rows> tags that will sum up our columns,
|
|
|
|
// sum up our columns here.
|
|
|
|
nsSize total(0,0);
|
2012-08-06 07:00:57 +04:00
|
|
|
nsIFrame* rowsBox = mGrid.GetRowsBox();
|
|
|
|
nsIFrame* columnsBox = mGrid.GetColumnsBox();
|
2006-12-15 15:18:37 +03:00
|
|
|
if (!rowsBox || !columnsBox) {
|
|
|
|
if (!rowsBox) {
|
2001-11-08 23:46:02 +03:00
|
|
|
// max height is the sum of our rows
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t rows = mGrid.GetRowCount();
|
|
|
|
for (int32_t i=0; i < rows; i++)
|
2001-11-08 23:46:02 +03:00
|
|
|
{
|
2017-07-06 15:00:35 +03:00
|
|
|
nscoord height = mGrid.GetMinRowHeight(aState, i, true);
|
2011-10-17 18:59:28 +04:00
|
|
|
AddWidth(total, height, false); // AddHeight
|
2001-11-08 23:46:02 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-12-15 15:18:37 +03:00
|
|
|
if (!columnsBox) {
|
2001-11-08 23:46:02 +03:00
|
|
|
// max height is the sum of our rows
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t columns = mGrid.GetColumnCount();
|
|
|
|
for (int32_t i=0; i < columns; i++)
|
2001-11-08 23:46:02 +03:00
|
|
|
{
|
2017-07-06 15:00:35 +03:00
|
|
|
nscoord width = mGrid.GetMinRowHeight(aState, i, false);
|
2011-10-17 18:59:28 +04:00
|
|
|
AddWidth(total, width, true); // AddWidth
|
2001-11-08 23:46:02 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
AddMargin(aBox, total);
|
2015-12-07 21:17:47 +03:00
|
|
|
AddOffset(aBox, total);
|
2008-01-09 10:28:39 +03:00
|
|
|
AddLargestSize(minSize, total);
|
2001-11-08 23:46:02 +03:00
|
|
|
}
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2008-01-09 10:28:39 +03:00
|
|
|
return minSize;
|
2001-10-09 00:37:56 +04:00
|
|
|
}
|
|
|
|
|
2008-01-09 10:28:39 +03:00
|
|
|
nsSize
|
2016-04-21 07:28:31 +03:00
|
|
|
nsGridLayout2::GetXULPrefSize(nsIFrame* aBox, nsBoxLayoutState& aState)
|
2001-10-09 00:37:56 +04:00
|
|
|
{
|
2017-07-06 15:00:35 +03:00
|
|
|
nsSize pref = nsStackLayout::GetXULPrefSize(aBox, aState);
|
2001-11-08 23:46:02 +03:00
|
|
|
|
|
|
|
// if there are no <rows> tags that will sum up our columns,
|
|
|
|
// sum up our columns here.
|
|
|
|
nsSize total(0,0);
|
2012-08-06 07:00:57 +04:00
|
|
|
nsIFrame* rowsBox = mGrid.GetRowsBox();
|
|
|
|
nsIFrame* columnsBox = mGrid.GetColumnsBox();
|
2006-12-15 15:18:37 +03:00
|
|
|
if (!rowsBox || !columnsBox) {
|
|
|
|
if (!rowsBox) {
|
2001-11-08 23:46:02 +03:00
|
|
|
// max height is the sum of our rows
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t rows = mGrid.GetRowCount();
|
|
|
|
for (int32_t i=0; i < rows; i++)
|
2001-11-08 23:46:02 +03:00
|
|
|
{
|
2017-07-06 15:00:35 +03:00
|
|
|
nscoord height = mGrid.GetPrefRowHeight(aState, i, true);
|
2011-10-17 18:59:28 +04:00
|
|
|
AddWidth(total, height, false); // AddHeight
|
2001-11-08 23:46:02 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-12-15 15:18:37 +03:00
|
|
|
if (!columnsBox) {
|
2001-11-08 23:46:02 +03:00
|
|
|
// max height is the sum of our rows
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t columns = mGrid.GetColumnCount();
|
|
|
|
for (int32_t i=0; i < columns; i++)
|
2001-11-08 23:46:02 +03:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
nscoord width = mGrid.GetPrefRowHeight(aState, i, false);
|
|
|
|
AddWidth(total, width, true); // AddWidth
|
2001-11-08 23:46:02 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
AddMargin(aBox, total);
|
2015-12-07 21:17:47 +03:00
|
|
|
AddOffset(aBox, total);
|
2008-01-09 10:28:39 +03:00
|
|
|
AddLargestSize(pref, total);
|
2001-11-08 23:46:02 +03:00
|
|
|
}
|
|
|
|
|
2008-01-09 10:28:39 +03:00
|
|
|
return pref;
|
2001-10-09 00:37:56 +04:00
|
|
|
}
|
|
|
|
|
2008-01-09 10:28:39 +03:00
|
|
|
nsSize
|
2016-04-21 07:28:31 +03:00
|
|
|
nsGridLayout2::GetXULMaxSize(nsIFrame* aBox, nsBoxLayoutState& aState)
|
2001-10-09 00:37:56 +04:00
|
|
|
{
|
2017-07-06 15:00:35 +03:00
|
|
|
nsSize maxSize = nsStackLayout::GetXULMaxSize(aBox, aState);
|
2001-11-08 23:46:02 +03: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-06 07:00:57 +04:00
|
|
|
nsIFrame* rowsBox = mGrid.GetRowsBox();
|
|
|
|
nsIFrame* columnsBox = mGrid.GetColumnsBox();
|
2006-12-15 15:18:37 +03:00
|
|
|
if (!rowsBox || !columnsBox) {
|
|
|
|
if (!rowsBox) {
|
2001-11-08 23:46:02 +03:00
|
|
|
total.height = 0;
|
|
|
|
// max height is the sum of our rows
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t rows = mGrid.GetRowCount();
|
|
|
|
for (int32_t i=0; i < rows; i++)
|
2001-11-08 23:46:02 +03:00
|
|
|
{
|
2017-07-06 15:00:35 +03:00
|
|
|
nscoord height = mGrid.GetMaxRowHeight(aState, i, true);
|
2011-10-17 18:59:28 +04:00
|
|
|
AddWidth(total, height, false); // AddHeight
|
2001-11-08 23:46:02 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-12-15 15:18:37 +03:00
|
|
|
if (!columnsBox) {
|
2001-11-08 23:46:02 +03:00
|
|
|
total.width = 0;
|
|
|
|
// max height is the sum of our rows
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t columns = mGrid.GetColumnCount();
|
|
|
|
for (int32_t i=0; i < columns; i++)
|
2001-11-08 23:46:02 +03:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
nscoord width = mGrid.GetMaxRowHeight(aState, i, false);
|
|
|
|
AddWidth(total, width, true); // AddWidth
|
2001-11-08 23:46:02 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
AddMargin(aBox, total);
|
2015-12-07 21:17:47 +03:00
|
|
|
AddOffset(aBox, total);
|
2008-01-09 10:28:39 +03:00
|
|
|
AddSmallestSize(maxSize, total);
|
2001-11-08 23:46:02 +03:00
|
|
|
}
|
|
|
|
|
2008-01-09 10:28:39 +03:00
|
|
|
return maxSize;
|
2001-10-09 00:37:56 +04:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t
|
2012-08-06 07:00:57 +04:00
|
|
|
nsGridLayout2::BuildRows(nsIFrame* aBox, nsGridRow* aRows)
|
2007-08-22 00:08:58 +04:00
|
|
|
{
|
|
|
|
if (aBox) {
|
2011-10-17 18:59:28 +04:00
|
|
|
aRows[0].Init(aBox, true);
|
2007-08-22 00:08:58 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-12-18 21:25:48 +03:00
|
|
|
nsMargin
|
2012-08-06 07:00:57 +04:00
|
|
|
nsGridLayout2::GetTotalMargin(nsIFrame* aBox, bool aIsHorizontal)
|
2001-10-09 00:37:56 +04:00
|
|
|
{
|
2006-12-18 21:25:48 +03:00
|
|
|
nsMargin margin(0,0,0,0);
|
|
|
|
return margin;
|
2005-11-22 21:14:17 +03:00
|
|
|
}
|
|
|
|
|
2008-01-09 10:28:39 +03:00
|
|
|
void
|
2012-08-06 07:00:57 +04:00
|
|
|
nsGridLayout2::ChildrenInserted(nsIFrame* aBox, nsBoxLayoutState& aState,
|
|
|
|
nsIFrame* aPrevBox,
|
2009-07-30 21:23:32 +04:00
|
|
|
const nsFrameList::Slice& aNewChildren)
|
2005-10-21 21:29:06 +04:00
|
|
|
{
|
|
|
|
mGrid.NeedsRebuild(aState);
|
|
|
|
}
|
|
|
|
|
2008-01-09 10:28:39 +03:00
|
|
|
void
|
2012-08-06 07:00:57 +04:00
|
|
|
nsGridLayout2::ChildrenAppended(nsIFrame* aBox, nsBoxLayoutState& aState,
|
2009-07-30 21:23:32 +04:00
|
|
|
const nsFrameList::Slice& aNewChildren)
|
2005-10-21 21:29:06 +04:00
|
|
|
{
|
|
|
|
mGrid.NeedsRebuild(aState);
|
|
|
|
}
|
|
|
|
|
2008-01-09 10:28:39 +03:00
|
|
|
void
|
2012-08-06 07:00:57 +04:00
|
|
|
nsGridLayout2::ChildrenRemoved(nsIFrame* aBox, nsBoxLayoutState& aState,
|
|
|
|
nsIFrame* aChildList)
|
2005-10-21 21:29:06 +04:00
|
|
|
{
|
|
|
|
mGrid.NeedsRebuild(aState);
|
|
|
|
}
|
|
|
|
|
2008-01-09 10:28:39 +03:00
|
|
|
void
|
2012-08-06 07:00:57 +04:00
|
|
|
nsGridLayout2::ChildrenSet(nsIFrame* aBox, nsBoxLayoutState& aState,
|
|
|
|
nsIFrame* aChildList)
|
2005-10-21 21:29:06 +04:00
|
|
|
{
|
|
|
|
mGrid.NeedsRebuild(aState);
|
|
|
|
}
|
2001-10-20 00:47:36 +04:00
|
|
|
|
2003-09-08 02:37:27 +04:00
|
|
|
NS_IMPL_ADDREF_INHERITED(nsGridLayout2, nsStackLayout)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(nsGridLayout2, nsStackLayout)
|
2001-10-09 00:37:56 +04:00
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN(nsGridLayout2)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIGridPart)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIGridPart)
|
|
|
|
NS_INTERFACE_MAP_END_INHERITING(nsStackLayout)
|