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
|
|
|
|
//
|
|
|
|
|
2001-10-10 01:02:29 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The nsGridRowGroupLayout implements the <rows> or <columns> tag in a grid.
|
|
|
|
*/
|
|
|
|
|
2001-10-09 00:37:56 +04:00
|
|
|
#include "nsGridRowGroupLayout.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsIScrollableFrame.h"
|
2014-05-25 02:20:41 +04:00
|
|
|
#include "nsBox.h"
|
2001-10-09 00:37:56 +04:00
|
|
|
#include "nsBoxLayoutState.h"
|
|
|
|
#include "nsGridLayout2.h"
|
|
|
|
#include "nsGridRow.h"
|
2012-08-06 07:00:56 +04:00
|
|
|
#include "nsHTMLReflowState.h"
|
2001-10-09 00:37:56 +04:00
|
|
|
|
2011-07-11 18:05:10 +04:00
|
|
|
already_AddRefed<nsBoxLayout> NS_NewGridRowGroupLayout()
|
2001-10-09 00:37:56 +04:00
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsBoxLayout> layout = new nsGridRowGroupLayout();
|
2013-04-22 15:15:59 +04:00
|
|
|
return layout.forget();
|
2001-10-09 00:37:56 +04:00
|
|
|
}
|
|
|
|
|
2009-01-19 21:31:33 +03:00
|
|
|
nsGridRowGroupLayout::nsGridRowGroupLayout():nsGridRowLayout(), mRowCount(0)
|
2001-10-09 00:37:56 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsGridRowGroupLayout::~nsGridRowGroupLayout()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2006-12-18 21:25:48 +03:00
|
|
|
void
|
2012-08-06 07:00:57 +04:00
|
|
|
nsGridRowGroupLayout::ChildAddedOrRemoved(nsIFrame* aBox, nsBoxLayoutState& aState)
|
2001-10-09 00:37:56 +04:00
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t index = 0;
|
2006-12-18 21:25:48 +03:00
|
|
|
nsGrid* grid = GetGrid(aBox, &index);
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isHorizontal = IsHorizontal(aBox);
|
2001-10-09 00:37:56 +04:00
|
|
|
|
|
|
|
if (grid)
|
2001-10-26 06:41:06 +04:00
|
|
|
grid->RowAddedOrRemoved(aState, index, isHorizontal);
|
2001-10-09 00:37:56 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-09-29 10:19:26 +04:00
|
|
|
nsGridRowGroupLayout::AddWidth(nsSize& aSize, nscoord aSize2, bool aIsHorizontal)
|
2001-10-09 00:37:56 +04:00
|
|
|
{
|
2001-10-26 06:41:06 +04:00
|
|
|
nscoord& size = GET_WIDTH(aSize, aIsHorizontal);
|
2001-10-09 00:37:56 +04:00
|
|
|
|
|
|
|
if (size == NS_INTRINSICSIZE || aSize2 == NS_INTRINSICSIZE)
|
|
|
|
size = NS_INTRINSICSIZE;
|
|
|
|
else
|
|
|
|
size += aSize2;
|
|
|
|
}
|
|
|
|
|
2008-01-09 10:28:39 +03:00
|
|
|
nsSize
|
2012-08-06 07:00:57 +04:00
|
|
|
nsGridRowGroupLayout::GetPrefSize(nsIFrame* aBox, nsBoxLayoutState& aState)
|
2001-10-09 00:37:56 +04:00
|
|
|
{
|
2008-01-09 10:28:39 +03:00
|
|
|
nsSize vpref = nsGridRowLayout::GetPrefSize(aBox, aState);
|
2001-10-09 00:37:56 +04:00
|
|
|
|
2001-10-10 01:02:29 +04:00
|
|
|
|
|
|
|
/* It is possible that we could have some extra columns. This is when less columns in XUL were
|
|
|
|
* defined that needed. And example might be a grid with 3 defined columns but a row with 4 cells in
|
|
|
|
* it. We would need an extra column to make the grid work. But because that extra column does not
|
|
|
|
* have a box associated with it we must add its size in manually. Remember we could have extra rows
|
|
|
|
* as well.
|
|
|
|
*/
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t index = 0;
|
2006-12-18 21:25:48 +03:00
|
|
|
nsGrid* grid = GetGrid(aBox, &index);
|
2001-10-09 00:37:56 +04:00
|
|
|
|
|
|
|
if (grid)
|
|
|
|
{
|
|
|
|
// make sure we add in extra columns sizes as well
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isHorizontal = IsHorizontal(aBox);
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t extraColumns = grid->GetExtraColumnCount(isHorizontal);
|
|
|
|
int32_t start = grid->GetColumnCount(isHorizontal) - grid->GetExtraColumnCount(isHorizontal);
|
|
|
|
for (int32_t i=0; i < extraColumns; i++)
|
2001-10-09 00:37:56 +04:00
|
|
|
{
|
2006-12-15 15:18:37 +03:00
|
|
|
nscoord pref =
|
|
|
|
grid->GetPrefRowHeight(aState, i+start, !isHorizontal); // GetPrefColumnWidth
|
2001-10-09 00:37:56 +04:00
|
|
|
|
2008-01-09 10:28:39 +03:00
|
|
|
AddWidth(vpref, pref, isHorizontal);
|
2001-10-09 00:37:56 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-09 10:28:39 +03:00
|
|
|
return vpref;
|
2001-10-09 00:37:56 +04:00
|
|
|
}
|
|
|
|
|
2008-01-09 10:28:39 +03:00
|
|
|
nsSize
|
2012-08-06 07:00:57 +04:00
|
|
|
nsGridRowGroupLayout::GetMaxSize(nsIFrame* aBox, nsBoxLayoutState& aState)
|
2001-10-09 00:37:56 +04:00
|
|
|
{
|
2008-01-09 10:28:39 +03:00
|
|
|
nsSize maxSize = nsGridRowLayout::GetMaxSize(aBox, aState);
|
2001-10-09 00:37:56 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t index = 0;
|
2006-12-18 21:25:48 +03:00
|
|
|
nsGrid* grid = GetGrid(aBox, &index);
|
2001-10-09 00:37:56 +04:00
|
|
|
|
|
|
|
if (grid)
|
|
|
|
{
|
|
|
|
// make sure we add in extra columns sizes as well
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isHorizontal = IsHorizontal(aBox);
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t extraColumns = grid->GetExtraColumnCount(isHorizontal);
|
|
|
|
int32_t start = grid->GetColumnCount(isHorizontal) - grid->GetExtraColumnCount(isHorizontal);
|
|
|
|
for (int32_t i=0; i < extraColumns; i++)
|
2001-10-09 00:37:56 +04:00
|
|
|
{
|
2006-12-15 15:18:37 +03:00
|
|
|
nscoord max =
|
|
|
|
grid->GetMaxRowHeight(aState, i+start, !isHorizontal); // GetMaxColumnWidth
|
2001-10-09 00:37:56 +04:00
|
|
|
|
2008-01-09 10:28:39 +03:00
|
|
|
AddWidth(maxSize, max, isHorizontal);
|
2001-10-09 00:37:56 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-09 10:28:39 +03:00
|
|
|
return maxSize;
|
2001-10-09 00:37:56 +04:00
|
|
|
}
|
|
|
|
|
2008-01-09 10:28:39 +03:00
|
|
|
nsSize
|
2012-08-06 07:00:57 +04:00
|
|
|
nsGridRowGroupLayout::GetMinSize(nsIFrame* aBox, nsBoxLayoutState& aState)
|
2001-10-09 00:37:56 +04:00
|
|
|
{
|
2008-01-09 10:28:39 +03:00
|
|
|
nsSize minSize = nsGridRowLayout::GetMinSize(aBox, aState);
|
2001-10-09 00:37:56 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t index = 0;
|
2006-12-18 21:25:48 +03:00
|
|
|
nsGrid* grid = GetGrid(aBox, &index);
|
2001-10-09 00:37:56 +04:00
|
|
|
|
|
|
|
if (grid)
|
|
|
|
{
|
|
|
|
// make sure we add in extra columns sizes as well
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isHorizontal = IsHorizontal(aBox);
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t extraColumns = grid->GetExtraColumnCount(isHorizontal);
|
|
|
|
int32_t start = grid->GetColumnCount(isHorizontal) - grid->GetExtraColumnCount(isHorizontal);
|
|
|
|
for (int32_t i=0; i < extraColumns; i++)
|
2001-10-09 00:37:56 +04:00
|
|
|
{
|
2006-12-15 15:18:37 +03:00
|
|
|
nscoord min =
|
|
|
|
grid->GetMinRowHeight(aState, i+start, !isHorizontal); // GetMinColumnWidth
|
2008-01-09 10:28:39 +03:00
|
|
|
AddWidth(minSize, min, isHorizontal);
|
2001-10-09 00:37:56 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-09 10:28:39 +03:00
|
|
|
return minSize;
|
2001-10-09 00:37:56 +04:00
|
|
|
}
|
|
|
|
|
2001-10-10 01:02:29 +04:00
|
|
|
/*
|
|
|
|
* Run down through our children dirtying them recursively.
|
|
|
|
*/
|
2006-12-18 21:25:48 +03:00
|
|
|
void
|
2012-08-06 07:00:57 +04:00
|
|
|
nsGridRowGroupLayout::DirtyRows(nsIFrame* aBox, nsBoxLayoutState& aState)
|
2001-10-09 00:37:56 +04:00
|
|
|
{
|
|
|
|
if (aBox) {
|
|
|
|
// mark us dirty
|
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 probably don't want to walk up the ancestor chain
|
2014-07-24 21:03:26 +04:00
|
|
|
// calling MarkIntrinsicISizesDirty for every row group.
|
2007-05-06 23:16:51 +04:00
|
|
|
aState.PresShell()->FrameNeedsReflow(aBox, nsIPresShell::eTreeChange,
|
|
|
|
NS_FRAME_IS_DIRTY);
|
2014-05-25 02:20:41 +04:00
|
|
|
nsIFrame* child = nsBox::GetChildBox(aBox);
|
2001-10-09 00:37:56 +04:00
|
|
|
|
|
|
|
while(child) {
|
|
|
|
|
|
|
|
// walk into scrollframes
|
2012-08-06 07:00:57 +04:00
|
|
|
nsIFrame* deepChild = nsGrid::GetScrolledBox(child);
|
2001-10-09 00:37:56 +04:00
|
|
|
|
|
|
|
// walk into other monuments
|
2011-07-04 18:39:10 +04:00
|
|
|
nsIGridPart* monument = nsGrid::GetPartFromBox(deepChild);
|
|
|
|
if (monument)
|
|
|
|
monument->DirtyRows(deepChild, aState);
|
2001-10-09 00:37:56 +04:00
|
|
|
|
2014-05-25 02:20:41 +04:00
|
|
|
child = nsBox::GetNextBox(child);
|
2001-10-09 00:37:56 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-12-18 21:25:48 +03:00
|
|
|
void
|
2012-08-22 19:56:38 +04:00
|
|
|
nsGridRowGroupLayout::CountRowsColumns(nsIFrame* aBox, int32_t& aRowCount, int32_t& aComputedColumnCount)
|
2001-10-09 00:37:56 +04:00
|
|
|
{
|
|
|
|
if (aBox) {
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t startCount = aRowCount;
|
2001-10-20 00:47:36 +04:00
|
|
|
|
2014-05-25 02:20:41 +04:00
|
|
|
nsIFrame* child = nsBox::GetChildBox(aBox);
|
2001-10-09 00:37:56 +04:00
|
|
|
|
|
|
|
while(child) {
|
|
|
|
|
|
|
|
// first see if it is a scrollframe. If so walk down into it and get the scrolled child
|
2012-08-06 07:00:57 +04:00
|
|
|
nsIFrame* deepChild = nsGrid::GetScrolledBox(child);
|
2001-10-09 00:37:56 +04:00
|
|
|
|
2011-07-04 18:39:10 +04:00
|
|
|
nsIGridPart* monument = nsGrid::GetPartFromBox(deepChild);
|
|
|
|
if (monument) {
|
|
|
|
monument->CountRowsColumns(deepChild, aRowCount, aComputedColumnCount);
|
2014-05-25 02:20:41 +04:00
|
|
|
child = nsBox::GetNextBox(child);
|
2011-07-04 18:39:10 +04:00
|
|
|
deepChild = child;
|
|
|
|
continue;
|
2001-10-09 00:37:56 +04:00
|
|
|
}
|
|
|
|
|
2014-05-25 02:20:41 +04:00
|
|
|
child = nsBox::GetNextBox(child);
|
2001-10-09 00:37:56 +04:00
|
|
|
|
|
|
|
// if not a monument. Then count it. It will be a bogus row
|
|
|
|
aRowCount++;
|
|
|
|
}
|
2001-10-20 00:47:36 +04:00
|
|
|
|
|
|
|
mRowCount = aRowCount - startCount;
|
2001-10-09 00:37:56 +04:00
|
|
|
}
|
2001-10-20 00:47:36 +04:00
|
|
|
}
|
|
|
|
|
2001-10-09 00:37:56 +04:00
|
|
|
|
2001-10-10 01:02:29 +04:00
|
|
|
/**
|
|
|
|
* Fill out the given row structure recursively
|
|
|
|
*/
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t
|
2012-08-06 07:00:57 +04:00
|
|
|
nsGridRowGroupLayout::BuildRows(nsIFrame* aBox, nsGridRow* aRows)
|
2001-10-09 00:37:56 +04:00
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t rowCount = 0;
|
2001-10-09 00:37:56 +04:00
|
|
|
|
|
|
|
if (aBox) {
|
2014-05-25 02:20:41 +04:00
|
|
|
nsIFrame* child = nsBox::GetChildBox(aBox);
|
2001-10-09 00:37:56 +04:00
|
|
|
|
|
|
|
while(child) {
|
|
|
|
|
|
|
|
// first see if it is a scrollframe. If so walk down into it and get the scrolled child
|
2012-08-06 07:00:57 +04:00
|
|
|
nsIFrame* deepChild = nsGrid::GetScrolledBox(child);
|
2001-10-09 00:37:56 +04:00
|
|
|
|
2011-07-04 18:39:10 +04:00
|
|
|
nsIGridPart* monument = nsGrid::GetPartFromBox(deepChild);
|
|
|
|
if (monument) {
|
|
|
|
rowCount += monument->BuildRows(deepChild, &aRows[rowCount]);
|
2014-05-25 02:20:41 +04:00
|
|
|
child = nsBox::GetNextBox(child);
|
2011-07-04 18:39:10 +04:00
|
|
|
deepChild = child;
|
|
|
|
continue;
|
2001-10-09 00:37:56 +04:00
|
|
|
}
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
aRows[rowCount].Init(child, true);
|
2001-10-09 00:37:56 +04:00
|
|
|
|
2014-05-25 02:20:41 +04:00
|
|
|
child = nsBox::GetNextBox(child);
|
2001-10-09 00:37:56 +04:00
|
|
|
|
|
|
|
// if not a monument. Then count it. It will be a bogus row
|
|
|
|
rowCount++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-12-18 21:25:48 +03:00
|
|
|
return rowCount;
|
2001-10-09 00:37:56 +04:00
|
|
|
}
|
|
|
|
|
2006-12-18 21:25:48 +03:00
|
|
|
nsMargin
|
2012-08-06 07:00:57 +04:00
|
|
|
nsGridRowGroupLayout::GetTotalMargin(nsIFrame* aBox, bool aIsHorizontal)
|
2001-10-20 00:47:36 +04:00
|
|
|
{
|
|
|
|
// group have border and padding added to the total margin
|
|
|
|
|
2006-12-18 21:25:48 +03:00
|
|
|
nsMargin margin = nsGridRowLayout::GetTotalMargin(aBox, aIsHorizontal);
|
2001-10-20 00:47:36 +04:00
|
|
|
|
|
|
|
// make sure we have the scrollframe on the outside if it has one.
|
2005-11-21 01:05:24 +03:00
|
|
|
// that's where the border is.
|
2001-10-20 00:47:36 +04:00
|
|
|
aBox = nsGrid::GetScrollBox(aBox);
|
|
|
|
|
|
|
|
// add our border/padding to it
|
|
|
|
nsMargin borderPadding(0,0,0,0);
|
|
|
|
aBox->GetBorderAndPadding(borderPadding);
|
2006-12-18 21:25:48 +03:00
|
|
|
margin += borderPadding;
|
2001-10-20 00:47:36 +04:00
|
|
|
|
2006-12-18 21:25:48 +03:00
|
|
|
return margin;
|
2001-10-20 00:47:36 +04:00
|
|
|
}
|
|
|
|
|
2001-10-09 00:37:56 +04:00
|
|
|
|