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 "nsGridRowLayout.h"
|
|
|
|
#include "nsBoxLayoutState.h"
|
|
|
|
#include "nsIScrollableFrame.h"
|
|
|
|
#include "nsBox.h"
|
|
|
|
#include "nsStackLayout.h"
|
|
|
|
#include "nsGrid.h"
|
|
|
|
|
2009-01-19 10:31:33 -08:00
|
|
|
nsGridRowLayout::nsGridRowLayout():nsSprocketLayout()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-07-08 14:23:18 -07:00
|
|
|
nsGridRowLayout::~nsGridRowLayout()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-01-08 23:28:39 -08:00
|
|
|
void
|
2012-08-05 20:00:57 -07:00
|
|
|
nsGridRowLayout::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
|
|
|
{
|
|
|
|
ChildAddedOrRemoved(aBox, aState);
|
|
|
|
}
|
|
|
|
|
2008-01-08 23:28:39 -08:00
|
|
|
void
|
2012-08-05 20:00:57 -07:00
|
|
|
nsGridRowLayout::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
|
|
|
{
|
|
|
|
ChildAddedOrRemoved(aBox, aState);
|
|
|
|
}
|
|
|
|
|
2008-01-08 23:28:39 -08:00
|
|
|
void
|
2012-08-05 20:00:57 -07:00
|
|
|
nsGridRowLayout::ChildrenRemoved(nsIFrame* aBox, nsBoxLayoutState& aState, nsIFrame* aChildList)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
ChildAddedOrRemoved(aBox, aState);
|
|
|
|
}
|
|
|
|
|
2008-01-08 23:28:39 -08:00
|
|
|
void
|
2012-08-05 20:00:57 -07:00
|
|
|
nsGridRowLayout::ChildrenSet(nsIFrame* aBox, nsBoxLayoutState& aState, nsIFrame* aChildList)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
ChildAddedOrRemoved(aBox, aState);
|
|
|
|
}
|
|
|
|
|
2011-07-04 07:39:10 -07:00
|
|
|
nsIGridPart*
|
2012-08-05 20:00:57 -07:00
|
|
|
nsGridRowLayout::GetParentGridPart(nsIFrame* aBox, nsIFrame** aParentBox)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// go up and find our parent gridRow. Skip and non gridRow
|
|
|
|
// parents.
|
2012-07-30 07:20:58 -07:00
|
|
|
*aParentBox = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// walk up through any scrollboxes
|
|
|
|
aBox = nsGrid::GetScrollBox(aBox);
|
|
|
|
|
|
|
|
// get the parent
|
|
|
|
if (aBox)
|
2014-05-24 15:20:41 -07:00
|
|
|
aBox = nsBox::GetParentBox(aBox);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (aBox)
|
|
|
|
{
|
2011-07-04 07:39:10 -07:00
|
|
|
nsIGridPart* parentGridRow = nsGrid::GetPartFromBox(aBox);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (parentGridRow && parentGridRow->CanContain(this)) {
|
|
|
|
*aParentBox = aBox;
|
2011-07-04 07:39:10 -07:00
|
|
|
return parentGridRow;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
2011-07-04 07:39:10 -07:00
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsGrid*
|
2012-08-22 08:56:38 -07:00
|
|
|
nsGridRowLayout::GetGrid(nsIFrame* aBox, int32_t* aIndex, nsGridRowLayout* aRequestor)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
if (aRequestor == nullptr)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-08-05 20:00:57 -07:00
|
|
|
nsIFrame* parentBox; // nsIFrame is implemented by nsIFrame and is not refcounted.
|
2011-07-04 07:39:10 -07:00
|
|
|
nsIGridPart* parent = GetParentGridPart(aBox, &parentBox);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (parent)
|
|
|
|
return parent->GetGrid(parentBox, aIndex, this);
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t index = -1;
|
2014-05-24 15:20:41 -07:00
|
|
|
nsIFrame* child = nsBox::GetChildBox(aBox);
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t count = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
while(child)
|
|
|
|
{
|
|
|
|
// if there is a scrollframe walk inside it to its child
|
2012-08-05 20:00:57 -07:00
|
|
|
nsIFrame* childBox = nsGrid::GetScrolledBox(child);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-07-11 07:05:10 -07:00
|
|
|
nsBoxLayout* layout = childBox->GetLayoutManager();
|
2011-07-04 07:39:10 -07:00
|
|
|
nsIGridPart* gridRow = nsGrid::GetPartFromBox(childBox);
|
|
|
|
if (gridRow)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (layout == aRequestor) {
|
|
|
|
index = count;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
count += gridRow->GetRowCount();
|
|
|
|
} else
|
|
|
|
count++;
|
|
|
|
|
2014-05-24 15:20:41 -07:00
|
|
|
child = nsBox::GetNextBox(child);
|
2007-03-22 10:30:00 -07: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 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
(*aIndex) += index;
|
|
|
|
|
2012-08-05 20:00:57 -07:00
|
|
|
nsIFrame* parentBox; // nsIFrame is implemented by nsIFrame and is not refcounted.
|
2011-07-04 07:39:10 -07:00
|
|
|
nsIGridPart* parent = GetParentGridPart(aBox, &parentBox);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (parent)
|
|
|
|
return parent->GetGrid(parentBox, aIndex, this);
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsMargin
|
2012-08-05 20:00:57 -07:00
|
|
|
nsGridRowLayout::GetTotalMargin(nsIFrame* aBox, bool aIsHorizontal)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// get our parents margin
|
|
|
|
nsMargin margin(0,0,0,0);
|
2012-08-05 20:00:57 -07:00
|
|
|
nsIFrame* parent = nullptr;
|
2011-07-04 07:39:10 -07:00
|
|
|
nsIGridPart* part = GetParentGridPart(aBox, &parent);
|
2007-03-22 10:30:00 -07: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-24 15:20:41 -07:00
|
|
|
nsIFrame* next = nsBox::GetNextBox(aBox);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// get the parent first child to see if we are first
|
2014-05-24 15:20:41 -07:00
|
|
|
nsIFrame* child = nsBox::GetChildBox(parent);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
margin = part->GetTotalMargin(parent, aIsHorizontal);
|
|
|
|
|
|
|
|
// if first or last
|
2012-07-30 07:20:58 -07:00
|
|
|
if (child == aBox || next == nullptr) {
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// if it's not the first child remove the top margin
|
|
|
|
// we don't need it.
|
|
|
|
if (child != aBox)
|
|
|
|
{
|
|
|
|
if (aIsHorizontal)
|
|
|
|
margin.top = 0;
|
|
|
|
else
|
|
|
|
margin.left = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// if it's not the last child remove the bottom margin
|
|
|
|
// we don't need it.
|
2012-07-30 07:20:58 -07:00
|
|
|
if (next != nullptr)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (aIsHorizontal)
|
|
|
|
margin.bottom = 0;
|
|
|
|
else
|
|
|
|
margin.right = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// add ours to it.
|
|
|
|
nsMargin ourMargin;
|
|
|
|
aBox->GetMargin(ourMargin);
|
|
|
|
margin += ourMargin;
|
|
|
|
|
|
|
|
return margin;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF_INHERITED(nsGridRowLayout, nsBoxLayout)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(nsGridRowLayout, nsBoxLayout)
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN(nsGridRowLayout)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIGridPart)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIGridPart)
|
|
|
|
NS_INTERFACE_MAP_END_INHERITING(nsBoxLayout)
|