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 "nsGridRowLayout.h"
|
|
|
|
#include "nsBoxLayoutState.h"
|
|
|
|
#include "nsIScrollableFrame.h"
|
|
|
|
#include "nsBox.h"
|
|
|
|
#include "nsStackLayout.h"
|
2001-10-20 00:47:36 +04:00
|
|
|
#include "nsGrid.h"
|
2001-10-09 00:37:56 +04:00
|
|
|
|
2009-01-19 21:31:33 +03:00
|
|
|
nsGridRowLayout::nsGridRowLayout():nsSprocketLayout()
|
2001-10-09 00:37:56 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-07-09 01:23:18 +04:00
|
|
|
nsGridRowLayout::~nsGridRowLayout()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-01-09 10:28:39 +03:00
|
|
|
void
|
2012-08-06 07:00:57 +04:00
|
|
|
nsGridRowLayout::ChildrenInserted(nsIFrame* aBox, nsBoxLayoutState& aState,
|
|
|
|
nsIFrame* aPrevBox,
|
2009-07-30 21:23:32 +04:00
|
|
|
const nsFrameList::Slice& aNewChildren)
|
2001-10-09 00:37:56 +04:00
|
|
|
{
|
2006-12-18 21:25:48 +03:00
|
|
|
ChildAddedOrRemoved(aBox, aState);
|
2001-10-09 00:37:56 +04:00
|
|
|
}
|
|
|
|
|
2008-01-09 10:28:39 +03:00
|
|
|
void
|
2012-08-06 07:00:57 +04:00
|
|
|
nsGridRowLayout::ChildrenAppended(nsIFrame* aBox, nsBoxLayoutState& aState,
|
2009-07-30 21:23:32 +04:00
|
|
|
const nsFrameList::Slice& aNewChildren)
|
2001-10-09 00:37:56 +04:00
|
|
|
{
|
2006-12-18 21:25:48 +03:00
|
|
|
ChildAddedOrRemoved(aBox, aState);
|
2001-10-09 00:37:56 +04:00
|
|
|
}
|
|
|
|
|
2008-01-09 10:28:39 +03:00
|
|
|
void
|
2012-08-06 07:00:57 +04:00
|
|
|
nsGridRowLayout::ChildrenRemoved(nsIFrame* aBox, nsBoxLayoutState& aState, nsIFrame* aChildList)
|
2001-10-09 00:37:56 +04:00
|
|
|
{
|
2006-12-18 21:25:48 +03:00
|
|
|
ChildAddedOrRemoved(aBox, aState);
|
2001-10-09 00:37:56 +04:00
|
|
|
}
|
|
|
|
|
2008-01-09 10:28:39 +03:00
|
|
|
void
|
2012-08-06 07:00:57 +04:00
|
|
|
nsGridRowLayout::ChildrenSet(nsIFrame* aBox, nsBoxLayoutState& aState, nsIFrame* aChildList)
|
2001-10-09 00:37:56 +04:00
|
|
|
{
|
2006-12-18 21:25:48 +03:00
|
|
|
ChildAddedOrRemoved(aBox, aState);
|
2001-10-09 00:37:56 +04:00
|
|
|
}
|
|
|
|
|
2011-07-04 18:39:10 +04:00
|
|
|
nsIGridPart*
|
2012-08-06 07:00:57 +04:00
|
|
|
nsGridRowLayout::GetParentGridPart(nsIFrame* aBox, nsIFrame** aParentBox)
|
2001-10-09 00:37:56 +04:00
|
|
|
{
|
|
|
|
// go up and find our parent gridRow. Skip and non gridRow
|
|
|
|
// parents.
|
2012-07-30 18:20:58 +04:00
|
|
|
*aParentBox = nullptr;
|
2001-10-09 00:37:56 +04:00
|
|
|
|
2001-10-20 00:47:36 +04:00
|
|
|
// walk up through any scrollboxes
|
|
|
|
aBox = nsGrid::GetScrollBox(aBox);
|
|
|
|
|
|
|
|
// get the parent
|
2005-01-27 00:22:10 +03:00
|
|
|
if (aBox)
|
2014-05-25 02:20:41 +04:00
|
|
|
aBox = nsBox::GetParentBox(aBox);
|
2001-10-20 00:47:36 +04:00
|
|
|
|
|
|
|
if (aBox)
|
|
|
|
{
|
2011-07-04 18:39:10 +04:00
|
|
|
nsIGridPart* parentGridRow = nsGrid::GetPartFromBox(aBox);
|
2006-12-18 21:25:48 +03:00
|
|
|
if (parentGridRow && parentGridRow->CanContain(this)) {
|
|
|
|
*aParentBox = aBox;
|
2011-07-04 18:39:10 +04:00
|
|
|
return parentGridRow;
|
2006-12-18 21:25:48 +03:00
|
|
|
}
|
2001-10-09 00:37:56 +04:00
|
|
|
}
|
2011-07-04 18:39:10 +04:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2001-10-09 00:37:56 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-12-18 21:25:48 +03:00
|
|
|
nsGrid*
|
2012-08-22 19:56:38 +04:00
|
|
|
nsGridRowLayout::GetGrid(nsIFrame* aBox, int32_t* aIndex, nsGridRowLayout* aRequestor)
|
2001-10-09 00:37:56 +04:00
|
|
|
{
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
if (aRequestor == nullptr)
|
2001-10-09 00:37:56 +04:00
|
|
|
{
|
2012-08-06 07:00:57 +04:00
|
|
|
nsIFrame* parentBox; // nsIFrame is implemented by nsIFrame and is not refcounted.
|
2011-07-04 18:39:10 +04:00
|
|
|
nsIGridPart* parent = GetParentGridPart(aBox, &parentBox);
|
2001-10-09 00:37:56 +04:00
|
|
|
if (parent)
|
2006-12-18 21:25:48 +03:00
|
|
|
return parent->GetGrid(parentBox, aIndex, this);
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2001-10-09 00:37:56 +04:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t index = -1;
|
2014-05-25 02:20:41 +04:00
|
|
|
nsIFrame* child = nsBox::GetChildBox(aBox);
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t count = 0;
|
2001-10-09 00:37:56 +04:00
|
|
|
while(child)
|
|
|
|
{
|
|
|
|
// if there is a scrollframe walk inside it to its child
|
2012-08-06 07:00:57 +04:00
|
|
|
nsIFrame* childBox = nsGrid::GetScrolledBox(child);
|
2001-10-09 00:37:56 +04:00
|
|
|
|
2011-07-11 18:05:10 +04:00
|
|
|
nsBoxLayout* layout = childBox->GetLayoutManager();
|
2011-07-04 18:39:10 +04:00
|
|
|
nsIGridPart* gridRow = nsGrid::GetPartFromBox(childBox);
|
|
|
|
if (gridRow)
|
2001-10-09 00:37:56 +04:00
|
|
|
{
|
|
|
|
if (layout == aRequestor) {
|
|
|
|
index = count;
|
|
|
|
break;
|
|
|
|
}
|
2006-12-18 21:25:48 +03:00
|
|
|
count += gridRow->GetRowCount();
|
2001-10-20 00:47:36 +04:00
|
|
|
} else
|
|
|
|
count++;
|
|
|
|
|
2014-05-25 02:20:41 +04:00
|
|
|
child = nsBox::GetNextBox(child);
|
2001-10-09 00:37:56 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// if we didn't find ourselves then the tree isn't properly formed yet
|
|
|
|
// this could happen during initial construction so lets just
|
|
|
|
// fail.
|
|
|
|
if (index == -1) {
|
|
|
|
*aIndex = -1;
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2001-10-09 00:37:56 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
(*aIndex) += index;
|
|
|
|
|
2012-08-06 07:00:57 +04:00
|
|
|
nsIFrame* parentBox; // nsIFrame is implemented by nsIFrame and is not refcounted.
|
2011-07-04 18:39:10 +04:00
|
|
|
nsIGridPart* parent = GetParentGridPart(aBox, &parentBox);
|
2001-10-09 00:37:56 +04:00
|
|
|
if (parent)
|
2006-12-18 21:25:48 +03:00
|
|
|
return parent->GetGrid(parentBox, aIndex, this);
|
2001-10-09 00:37:56 +04:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
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
|
|
|
nsGridRowLayout::GetTotalMargin(nsIFrame* aBox, bool aIsHorizontal)
|
2001-10-20 00:47:36 +04:00
|
|
|
{
|
|
|
|
// get our parents margin
|
|
|
|
nsMargin margin(0,0,0,0);
|
2012-08-06 07:00:57 +04:00
|
|
|
nsIFrame* parent = nullptr;
|
2011-07-04 18:39:10 +04:00
|
|
|
nsIGridPart* part = GetParentGridPart(aBox, &parent);
|
2001-10-20 00:47:36 +04:00
|
|
|
if (part && parent) {
|
|
|
|
// if we are the first or last child walk upward and add margins.
|
|
|
|
|
|
|
|
// make sure we check for a scrollbox
|
|
|
|
aBox = nsGrid::GetScrollBox(aBox);
|
|
|
|
|
|
|
|
// see if we have a next to see if we are last
|
2014-05-25 02:20:41 +04:00
|
|
|
nsIFrame* next = nsBox::GetNextBox(aBox);
|
2001-10-20 00:47:36 +04:00
|
|
|
|
|
|
|
// get the parent first child to see if we are first
|
2014-05-25 02:20:41 +04:00
|
|
|
nsIFrame* child = nsBox::GetChildBox(parent);
|
2001-10-20 00:47:36 +04:00
|
|
|
|
2006-12-18 21:25:48 +03:00
|
|
|
margin = part->GetTotalMargin(parent, aIsHorizontal);
|
2001-10-20 00:47:36 +04:00
|
|
|
|
|
|
|
// if first or last
|
2012-07-30 18:20:58 +04:00
|
|
|
if (child == aBox || next == nullptr) {
|
2001-10-20 00:47:36 +04:00
|
|
|
|
2005-11-21 01:05:24 +03:00
|
|
|
// if it's not the first child remove the top margin
|
2001-10-20 00:47:36 +04:00
|
|
|
// we don't need it.
|
|
|
|
if (child != aBox)
|
|
|
|
{
|
2001-10-26 06:41:06 +04:00
|
|
|
if (aIsHorizontal)
|
2001-10-20 00:47:36 +04:00
|
|
|
margin.top = 0;
|
|
|
|
else
|
|
|
|
margin.left = 0;
|
|
|
|
}
|
|
|
|
|
2005-11-21 01:05:24 +03:00
|
|
|
// if it's not the last child remove the bottom margin
|
2001-10-20 00:47:36 +04:00
|
|
|
// we don't need it.
|
2012-07-30 18:20:58 +04:00
|
|
|
if (next != nullptr)
|
2001-10-20 00:47:36 +04:00
|
|
|
{
|
2001-10-26 06:41:06 +04:00
|
|
|
if (aIsHorizontal)
|
2001-10-20 00:47:36 +04:00
|
|
|
margin.bottom = 0;
|
|
|
|
else
|
|
|
|
margin.right = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// add ours to it.
|
2006-12-18 21:25:48 +03:00
|
|
|
nsMargin ourMargin;
|
|
|
|
aBox->GetMargin(ourMargin);
|
|
|
|
margin += ourMargin;
|
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
|
|
|
}
|
|
|
|
|
2003-09-08 02:37:27 +04:00
|
|
|
NS_IMPL_ADDREF_INHERITED(nsGridRowLayout, nsBoxLayout)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(nsGridRowLayout, nsBoxLayout)
|
2001-10-09 00:37:56 +04:00
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN(nsGridRowLayout)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIGridPart)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIGridPart)
|
|
|
|
NS_INTERFACE_MAP_END_INHERITING(nsBoxLayout)
|