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 "nsGridRowLeafLayout.h"
|
|
|
|
#include "nsGridRowGroupLayout.h"
|
|
|
|
#include "nsGridRow.h"
|
|
|
|
#include "nsBoxLayoutState.h"
|
|
|
|
#include "nsBox.h"
|
|
|
|
#include "nsIScrollableFrame.h"
|
|
|
|
#include "nsBoxFrame.h"
|
|
|
|
#include "nsGridLayout2.h"
|
2013-01-15 04:22:03 -08:00
|
|
|
#include <algorithm>
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-07-11 07:05:10 -07:00
|
|
|
already_AddRefed<nsBoxLayout> NS_NewGridRowLeafLayout()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-07-11 07:05:10 -07:00
|
|
|
nsBoxLayout* layout = new nsGridRowLeafLayout();
|
2009-01-19 10:31:33 -08:00
|
|
|
NS_IF_ADDREF(layout);
|
|
|
|
return layout;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-01-19 10:31:33 -08:00
|
|
|
nsGridRowLeafLayout::nsGridRowLeafLayout():nsGridRowLayout()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsGridRowLeafLayout::~nsGridRowLeafLayout()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-01-08 23:28:39 -08:00
|
|
|
nsSize
|
2012-08-05 20:00:57 -07:00
|
|
|
nsGridRowLeafLayout::GetPrefSize(nsIFrame* aBox, nsBoxLayoutState& aState)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t index = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsGrid* grid = GetGrid(aBox, &index);
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isHorizontal = IsHorizontal(aBox);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// If we are not in a grid. Then we just work like a box. But if we are in a grid
|
|
|
|
// ask the grid for our size.
|
2008-01-08 23:28:39 -08:00
|
|
|
if (!grid) {
|
|
|
|
return nsGridRowLayout::GetPrefSize(aBox, aState);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
else {
|
2008-01-08 23:28:39 -08:00
|
|
|
return grid->GetPrefRowSize(aState, index, isHorizontal);
|
|
|
|
//AddBorderAndPadding(aBox, 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
|
|
|
nsGridRowLeafLayout::GetMinSize(nsIFrame* aBox, nsBoxLayoutState& aState)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t index = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsGrid* grid = GetGrid(aBox, &index);
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isHorizontal = IsHorizontal(aBox);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (!grid)
|
2008-01-08 23:28:39 -08:00
|
|
|
return nsGridRowLayout::GetMinSize(aBox, aState);
|
2007-03-22 10:30:00 -07:00
|
|
|
else {
|
2008-01-08 23:28:39 -08:00
|
|
|
nsSize minSize = grid->GetMinRowSize(aState, index, isHorizontal);
|
|
|
|
AddBorderAndPadding(aBox, minSize);
|
|
|
|
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
|
|
|
nsGridRowLeafLayout::GetMaxSize(nsIFrame* aBox, nsBoxLayoutState& aState)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t index = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsGrid* grid = GetGrid(aBox, &index);
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isHorizontal = IsHorizontal(aBox);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (!grid)
|
2008-01-08 23:28:39 -08:00
|
|
|
return nsGridRowLayout::GetMaxSize(aBox, aState);
|
2007-03-22 10:30:00 -07:00
|
|
|
else {
|
2008-01-08 23:28:39 -08:00
|
|
|
nsSize maxSize;
|
|
|
|
maxSize = grid->GetMaxRowSize(aState, index, isHorizontal);
|
|
|
|
AddBorderAndPadding(aBox, maxSize);
|
|
|
|
return maxSize;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** If a child is added or removed or changes size
|
|
|
|
*/
|
|
|
|
void
|
2012-08-05 20:00:57 -07:00
|
|
|
nsGridRowLeafLayout::ChildAddedOrRemoved(nsIFrame* aBox, nsBoxLayoutState& aState)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t index = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsGrid* grid = GetGrid(aBox, &index);
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isHorizontal = IsHorizontal(aBox);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (grid)
|
|
|
|
grid->CellAddedOrRemoved(aState, index, isHorizontal);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-08-22 08:56:38 -07:00
|
|
|
nsGridRowLeafLayout::PopulateBoxSizes(nsIFrame* aBox, nsBoxLayoutState& aState, nsBoxSize*& aBoxSizes, nscoord& aMinSize, nscoord& aMaxSize, int32_t& aFlexes)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t index = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsGrid* grid = GetGrid(aBox, &index);
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isHorizontal = IsHorizontal(aBox);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Our base class SprocketLayout is giving us a chance to change the box sizes before layout
|
|
|
|
// If we are a row lets change the sizes to match our columns. If we are a column then do the opposite
|
|
|
|
// and make them match or rows.
|
|
|
|
if (grid) {
|
2008-04-09 15:15:59 -07:00
|
|
|
nsGridRow* column;
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t count = grid->GetColumnCount(isHorizontal);
|
2012-07-30 07:20:58 -07:00
|
|
|
nsBoxSize* start = nullptr;
|
|
|
|
nsBoxSize* last = nullptr;
|
|
|
|
nsBoxSize* current = nullptr;
|
2012-08-05 20:00:57 -07:00
|
|
|
nsIFrame* child = aBox->GetChildBox();
|
2008-04-09 15:15:59 -07:00
|
|
|
for (int i=0; i < count; i++)
|
|
|
|
{
|
|
|
|
column = grid->GetColumnAt(i,isHorizontal);
|
|
|
|
|
|
|
|
// make sure the value was computed before we use it.
|
|
|
|
// !isHorizontal is passed in to invert the behavior of these methods.
|
|
|
|
nscoord pref =
|
|
|
|
grid->GetPrefRowHeight(aState, i, !isHorizontal); // GetPrefColumnWidth
|
|
|
|
nscoord min =
|
|
|
|
grid->GetMinRowHeight(aState, i, !isHorizontal); // GetMinColumnWidth
|
|
|
|
nscoord max =
|
|
|
|
grid->GetMaxRowHeight(aState, i, !isHorizontal); // GetMaxColumnWidth
|
|
|
|
nscoord flex =
|
|
|
|
grid->GetRowFlex(aState, i, !isHorizontal); // GetColumnFlex
|
|
|
|
nscoord left = 0;
|
|
|
|
nscoord right = 0;
|
|
|
|
grid->GetRowOffsets(aState, i, left, right, !isHorizontal); // GetColumnOffsets
|
2012-08-05 20:00:57 -07:00
|
|
|
nsIFrame* box = column->GetBox();
|
2011-09-28 23:19:26 -07:00
|
|
|
bool collapsed = false;
|
2008-04-09 15:15:59 -07:00
|
|
|
nscoord topMargin = column->mTopMargin;
|
|
|
|
nscoord bottomMargin = column->mBottomMargin;
|
|
|
|
|
|
|
|
if (box)
|
2011-06-15 14:03:49 -07:00
|
|
|
collapsed = box->IsCollapsed();
|
2008-04-09 15:15:59 -07:00
|
|
|
|
|
|
|
pref = pref - (left + right);
|
|
|
|
if (pref < 0)
|
|
|
|
pref = 0;
|
|
|
|
|
|
|
|
// if this is the first or last column. Take into account that
|
|
|
|
// our row could have a border that could affect our left or right
|
|
|
|
// padding from our columns. If the row has padding subtract it.
|
|
|
|
// would should always be able to garentee that our margin is smaller
|
|
|
|
// or equal to our left or right
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t firstIndex = 0;
|
|
|
|
int32_t lastIndex = 0;
|
2012-07-30 07:20:58 -07:00
|
|
|
nsGridRow* firstRow = nullptr;
|
|
|
|
nsGridRow* lastRow = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
grid->GetFirstAndLastRow(aState, firstIndex, lastIndex, firstRow, lastRow, !isHorizontal);
|
|
|
|
|
|
|
|
if (i == firstIndex || i == lastIndex) {
|
|
|
|
nsMargin offset = GetTotalMargin(aBox, isHorizontal);
|
|
|
|
|
|
|
|
nsMargin border(0,0,0,0);
|
|
|
|
// can't call GetBorderPadding we will get into recursion
|
|
|
|
aBox->GetBorder(border);
|
|
|
|
offset += border;
|
|
|
|
aBox->GetPadding(border);
|
|
|
|
offset += border;
|
|
|
|
|
|
|
|
// subtract from out left and right
|
|
|
|
if (i == firstIndex)
|
|
|
|
{
|
|
|
|
if (isHorizontal)
|
|
|
|
left -= offset.left;
|
|
|
|
else
|
|
|
|
left -= offset.top;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i == lastIndex)
|
|
|
|
{
|
|
|
|
if (isHorizontal)
|
|
|
|
right -= offset.right;
|
|
|
|
else
|
|
|
|
right -= offset.bottom;
|
|
|
|
}
|
|
|
|
}
|
2007-09-17 16:10:23 -07:00
|
|
|
|
2008-04-09 15:15:59 -07:00
|
|
|
// initialize the box size here
|
2013-01-15 04:22:03 -08:00
|
|
|
max = std::max(min, max);
|
2008-04-09 15:15:59 -07:00
|
|
|
pref = nsBox::BoundsCheck(min, pref, max);
|
2007-09-17 16:10:23 -07:00
|
|
|
|
2008-04-09 15:15:59 -07:00
|
|
|
current = new (aState) nsBoxSize();
|
|
|
|
current->pref = pref;
|
|
|
|
current->min = min;
|
|
|
|
current->max = max;
|
|
|
|
current->flex = flex;
|
|
|
|
current->bogus = column->mIsBogus;
|
|
|
|
current->left = left + topMargin;
|
|
|
|
current->right = right + bottomMargin;
|
|
|
|
current->collapsed = collapsed;
|
|
|
|
|
|
|
|
if (!start) {
|
2007-03-22 10:30:00 -07:00
|
|
|
start = current;
|
|
|
|
last = start;
|
2008-04-09 15:15:59 -07:00
|
|
|
} else {
|
2007-03-22 10:30:00 -07:00
|
|
|
last->next = current;
|
|
|
|
last = current;
|
2008-04-09 15:15:59 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-04-09 15:15:59 -07:00
|
|
|
if (child && !column->mIsBogus)
|
|
|
|
child = child->GetNextBox();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-04-09 15:15:59 -07:00
|
|
|
}
|
|
|
|
aBoxSizes = start;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-10-21 17:05:25 -07:00
|
|
|
nsSprocketLayout::PopulateBoxSizes(aBox, aState, aBoxSizes, aMinSize, aMaxSize, aFlexes);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-08-05 20:00:57 -07:00
|
|
|
nsGridRowLeafLayout::ComputeChildSizes(nsIFrame* aBox,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsBoxLayoutState& aState,
|
|
|
|
nscoord& aGivenSize,
|
|
|
|
nsBoxSize* aBoxSizes,
|
|
|
|
nsComputedBoxSize*& aComputedBoxSizes)
|
|
|
|
{
|
|
|
|
// see if we are in a scrollable frame. If we are then there could be scrollbars present
|
|
|
|
// if so we need to subtract them out to make sure our columns line up.
|
|
|
|
if (aBox) {
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isHorizontal = aBox->IsHorizontal();
|
2008-04-09 15:15:59 -07:00
|
|
|
|
|
|
|
// go up the parent chain looking for scrollframes
|
|
|
|
nscoord diff = 0;
|
2012-08-05 20:00:57 -07:00
|
|
|
nsIFrame* parentBox;
|
2011-12-19 19:46:39 -08:00
|
|
|
(void)GetParentGridPart(aBox, &parentBox);
|
2008-04-09 15:15:59 -07:00
|
|
|
while (parentBox) {
|
2012-08-05 20:00:57 -07:00
|
|
|
nsIFrame* scrollbox = nsGrid::GetScrollBox(parentBox);
|
2009-01-12 11:20:59 -08:00
|
|
|
nsIScrollableFrame *scrollable = do_QueryFrame(scrollbox);
|
2008-04-09 15:15:59 -07:00
|
|
|
if (scrollable) {
|
2010-01-14 05:00:00 -08:00
|
|
|
// Don't call GetActualScrollbarSizes here because it's not safe
|
|
|
|
// to call that while we're reflowing the contents of the scrollframe,
|
|
|
|
// which we are here.
|
|
|
|
nsMargin scrollbarSizes = scrollable->GetDesiredScrollbarSizes(&aState);
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t visible = scrollable->GetScrollbarVisibility();
|
2008-04-09 15:15:59 -07:00
|
|
|
|
2010-01-14 05:00:00 -08:00
|
|
|
if (isHorizontal && (visible & nsIScrollableFrame::VERTICAL)) {
|
2008-04-09 15:15:59 -07:00
|
|
|
diff += scrollbarSizes.left + scrollbarSizes.right;
|
2010-01-14 05:00:00 -08:00
|
|
|
} else if (!isHorizontal && (visible & nsIScrollableFrame::HORIZONTAL)) {
|
2008-04-09 15:15:59 -07:00
|
|
|
diff += scrollbarSizes.top + scrollbarSizes.bottom;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-19 19:46:39 -08:00
|
|
|
(void)GetParentGridPart(parentBox, &parentBox);
|
2008-04-09 15:15:59 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (diff > 0) {
|
|
|
|
aGivenSize += diff;
|
|
|
|
|
|
|
|
nsSprocketLayout::ComputeChildSizes(aBox, aState, aGivenSize, aBoxSizes, aComputedBoxSizes);
|
|
|
|
|
|
|
|
aGivenSize -= diff;
|
|
|
|
|
|
|
|
nsComputedBoxSize* s = aComputedBoxSizes;
|
|
|
|
nsComputedBoxSize* last = aComputedBoxSizes;
|
|
|
|
while(s)
|
|
|
|
{
|
|
|
|
last = s;
|
|
|
|
s = s->next;
|
|
|
|
}
|
2007-09-17 16:10:23 -07:00
|
|
|
|
2008-04-09 15:15:59 -07:00
|
|
|
if (last)
|
|
|
|
last->size -= diff;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2007-09-17 16:10:23 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsSprocketLayout::ComputeChildSizes(aBox, aState, aGivenSize, aBoxSizes, aComputedBoxSizes);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-05 20:00:57 -07:00
|
|
|
nsGridRowLeafLayout::Layout(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return nsGridRowLayout::Layout(aBox, aBoxLayoutState);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-08-05 20:00:57 -07:00
|
|
|
nsGridRowLeafLayout::DirtyRows(nsIFrame* aBox, nsBoxLayoutState& aState)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (aBox) {
|
|
|
|
// mark us dirty
|
|
|
|
// XXXldb We probably don't want to walk up the ancestor chain
|
|
|
|
// calling MarkIntrinsicWidthsDirty for every row.
|
2007-05-06 12:16:51 -07:00
|
|
|
aState.PresShell()->FrameNeedsReflow(aBox, nsIPresShell::eTreeChange,
|
|
|
|
NS_FRAME_IS_DIRTY);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-08-22 08:56:38 -07:00
|
|
|
nsGridRowLeafLayout::CountRowsColumns(nsIFrame* aBox, int32_t& aRowCount, int32_t& aComputedColumnCount)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (aBox) {
|
2012-08-05 20:00:57 -07:00
|
|
|
nsIFrame* child = aBox->GetChildBox();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// count the children
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t columnCount = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
while(child) {
|
|
|
|
child = child->GetNextBox();
|
|
|
|
columnCount++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// if our count is greater than the current column count
|
|
|
|
if (columnCount > aComputedColumnCount)
|
|
|
|
aComputedColumnCount = columnCount;
|
|
|
|
|
|
|
|
aRowCount++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t
|
2012-08-05 20:00:57 -07:00
|
|
|
nsGridRowLeafLayout::BuildRows(nsIFrame* aBox, nsGridRow* aRows)
|
|
|
|
{
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aBox) {
|
2011-10-17 07:59:28 -07:00
|
|
|
aRows[0].Init(aBox, false);
|
2007-03-22 10:30:00 -07:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|