зеркало из https://github.com/mozilla/gecko-dev.git
Adding new grid code to cvs. NOT IN BUILD.
This commit is contained in:
Родитель
d8be747748
Коммит
3ad6a737b0
|
@ -0,0 +1,77 @@
|
|||
#
|
||||
# The contents of this file are subject to the Netscape Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
# except in compliance with the License. You may obtain a copy of
|
||||
# the License at http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS
|
||||
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
# implied. See the License for the specific language governing
|
||||
# rights and limitations under the License.
|
||||
#
|
||||
# The Original Code is mozilla.org code.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
#
|
||||
|
||||
DEPTH = ../../../../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
MODULE = layout
|
||||
LIBRARY_NAME = gkxuloutliner_s
|
||||
REQUIRES = xpcom \
|
||||
string \
|
||||
dom \
|
||||
content \
|
||||
gfx \
|
||||
widget \
|
||||
timer \
|
||||
locale \
|
||||
view \
|
||||
xultmpl \
|
||||
rdf \
|
||||
necko \
|
||||
gfx2 \
|
||||
imglib2 \
|
||||
$(NULL)
|
||||
|
||||
CPPSRCS = \
|
||||
nsOutlinerBodyFrame.cpp \
|
||||
nsOutlinerBoxObject.cpp \
|
||||
nsOutlinerColFrame.cpp \
|
||||
nsOutlinerSelection.cpp \
|
||||
$(NULL)
|
||||
|
||||
EXPORTS = \
|
||||
nsOutlinerBodyFrame.h \
|
||||
nsOutlinerColFrame.h \
|
||||
nsOutlinerSelection.h \
|
||||
$(NULL)
|
||||
|
||||
DEFINES += -D_IMPL_NS_HTML
|
||||
|
||||
LOCAL_INCLUDES = \
|
||||
-I$(srcdir) \
|
||||
-I$(srcdir)/../../../../base/src \
|
||||
-I$(srcdir)/../../../../../html/style/src \
|
||||
-I$(srcdir)/../../../../../html/base/src \
|
||||
-I$(srcdir)/../../../../../html/forms/src \
|
||||
-I$(srcdir)/../../../../content/src \
|
||||
-I$(srcdir)/../../../../../xml/content/src \
|
||||
-I$(srcdir)/../../../../../base/public \
|
||||
-I$(srcdir)/../../../../../xul/base/src \
|
||||
$(NULL)
|
||||
|
||||
# we don't want the shared lib, but we want to force the creation of a static lib.
|
||||
FORCE_STATIC_LIB = 1
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
|
@ -0,0 +1,97 @@
|
|||
#!nmake
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
# except in compliance with the License. You may obtain a copy of
|
||||
# the License at http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS
|
||||
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
# implied. See the License for the specific language governing
|
||||
# rights and limitations under the License.
|
||||
#
|
||||
# The Original Code is mozilla.org code.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
|
||||
DEPTH=..\..\..\..\..
|
||||
|
||||
LIBRARY_NAME=raptorxulgrid_s
|
||||
MODULE=layout_xul
|
||||
REQUIRES = xpcom \
|
||||
string \
|
||||
dom \
|
||||
widget \
|
||||
timer \
|
||||
locale \
|
||||
view \
|
||||
rdf \
|
||||
necko \
|
||||
gfx2 \
|
||||
imglib2 \
|
||||
gfx \
|
||||
content \
|
||||
content_xul \
|
||||
$(NULL)
|
||||
|
||||
DEFINES=-D_IMPL_NS_HTML -DWIN32_LEAN_AND_MEAN
|
||||
|
||||
CPPSRCS= \
|
||||
nsGridLayout2.cpp \
|
||||
nsGridRowLayout.cpp \
|
||||
nsGridRowLeaf.cpp \
|
||||
nsGridRowGroupLayout.cpp \
|
||||
nsGrid.cpp \
|
||||
nsGridRow.cpp \
|
||||
nsGridCell.cpp \
|
||||
$(NULL)
|
||||
|
||||
CPP_OBJS= \
|
||||
.\$(OBJDIR)\nsGridLayout2.obj \
|
||||
.\$(OBJDIR)\nsGridRowLayout.obj \
|
||||
.\$(OBJDIR)\nsGridRowLeafLayout.obj \
|
||||
.\$(OBJDIR)\nsGridRowGroupLayout.obj \
|
||||
.\$(OBJDIR)\nsGrid.obj \
|
||||
.\$(OBJDIR)\nsGridRow.obj \
|
||||
.\$(OBJDIR)\nsGridCell.obj \
|
||||
$(NULL)
|
||||
|
||||
LINCS= \
|
||||
-I..\.. \
|
||||
-I..\..\..\..\base\src \
|
||||
-I..\..\..\..\html\style\src \
|
||||
-I..\..\..\..\html\base\src \
|
||||
-I..\..\..\content\src \
|
||||
-I..\..\..\..\html\forms\src \
|
||||
-I..\..\..\..\xml\content\src \
|
||||
-I.. \
|
||||
-I..\..\..\..\base\public
|
||||
|
||||
EXPORTS = nsGridLayout2.h \
|
||||
nsGridRowLayout.h \
|
||||
nsGridRowLeafLayout.h \
|
||||
nsGridRowGroupLayout.h \
|
||||
nsIGridPart.h \
|
||||
nsGrid.h \
|
||||
nsGridRow.h \
|
||||
nsGridCell.h \
|
||||
$(NULL)
|
||||
|
||||
|
||||
LCFLAGS = \
|
||||
$(LCFLAGS) \
|
||||
$(DEFINES) \
|
||||
$(NULL)
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
|
||||
install:: $(LIBRARY)
|
||||
$(MAKE_INSTALL) $(LIBRARY) $(DIST)\lib
|
||||
|
||||
clobber::
|
||||
rm -f $(DIST)\lib\$(LIBRARY_NAME).lib
|
|
@ -0,0 +1,869 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.1 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Mozilla Communicator client code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
//
|
||||
// Eric Vaughan
|
||||
// Netscape Communications
|
||||
//
|
||||
// See documentation in associated header file
|
||||
//
|
||||
|
||||
#include "nsGrid.h"
|
||||
#include "nsGridRowGroupLayout.h"
|
||||
#include "nsBox.h"
|
||||
#include "nsIScrollableFrame.h"
|
||||
#include "nsSprocketLayout.h"
|
||||
#include "nsGridRow.h"
|
||||
#include "nsGridCell.h"
|
||||
|
||||
//------ nsGrid ----
|
||||
|
||||
nsGrid::nsGrid():mBox(nsnull),
|
||||
mColumns(nsnull),
|
||||
mRows(nsnull),
|
||||
mRowBox(nsnull),
|
||||
mColumnBox(nsnull),
|
||||
mNeedsRebuild(PR_TRUE),
|
||||
mCellMap(nsnull),
|
||||
mMarkingDirty(PR_FALSE),
|
||||
mColumnCount(0),
|
||||
mRowCount(0),
|
||||
mExtraRowCount(0),
|
||||
mExtraColumnCount(0)
|
||||
{
|
||||
MOZ_COUNT_CTOR(nsGrid);
|
||||
}
|
||||
|
||||
nsGrid::~nsGrid()
|
||||
{
|
||||
FreeMap();
|
||||
MOZ_COUNT_DTOR(nsGrid);
|
||||
}
|
||||
|
||||
void
|
||||
nsGrid::NeedsRebuild(nsBoxLayoutState& aState)
|
||||
{
|
||||
if (mNeedsRebuild)
|
||||
return;
|
||||
|
||||
// iterate through columns and rows and dirty them
|
||||
mNeedsRebuild = PR_TRUE;
|
||||
|
||||
// free the map
|
||||
FreeMap();
|
||||
|
||||
// tell all the rows and columns they are dirty
|
||||
FindRowsAndColumns(&mRowBox, &mColumnBox);
|
||||
|
||||
DirtyRows(mRowBox, aState);
|
||||
DirtyRows(mColumnBox, aState);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
nsGrid::DirtyRows(nsIBox* aRowBox, nsBoxLayoutState& aState)
|
||||
{
|
||||
mMarkingDirty = PR_TRUE;
|
||||
|
||||
if (aRowBox) {
|
||||
nsCOMPtr<nsIBoxLayout> layout;
|
||||
aRowBox->GetLayoutManager(getter_AddRefs(layout));
|
||||
if (layout) {
|
||||
nsCOMPtr<nsIGridPart> monument( do_QueryInterface(layout) );
|
||||
if (monument)
|
||||
monument->DirtyRows(aRowBox, aState);
|
||||
}
|
||||
}
|
||||
|
||||
mMarkingDirty = PR_FALSE;
|
||||
}
|
||||
|
||||
nsGridRow* nsGrid::GetColumns()
|
||||
{
|
||||
RebuildIfNeeded();
|
||||
|
||||
return mColumns;
|
||||
}
|
||||
|
||||
nsGridRow* nsGrid::GetRows()
|
||||
{
|
||||
RebuildIfNeeded();
|
||||
|
||||
return mRows;
|
||||
}
|
||||
|
||||
nsGridRow*
|
||||
nsGrid::GetColumnAt(PRInt32 aIndex, PRBool aIsRow)
|
||||
{
|
||||
RebuildIfNeeded();
|
||||
|
||||
if (aIsRow) {
|
||||
NS_ASSERTION(aIndex < mColumnCount || aIndex >= 0, "Index out of range");
|
||||
return &mColumns[aIndex];
|
||||
} else
|
||||
return GetRowAt(aIndex);
|
||||
}
|
||||
|
||||
nsGridRow*
|
||||
nsGrid::GetRowAt(PRInt32 aIndex, PRBool aIsRow)
|
||||
{
|
||||
RebuildIfNeeded();
|
||||
|
||||
if (aIsRow) {
|
||||
NS_ASSERTION(aIndex < mRowCount || aIndex >= 0, "Index out of range");
|
||||
return &mRows[aIndex];
|
||||
} else {
|
||||
return GetColumnAt(aIndex);
|
||||
}
|
||||
}
|
||||
|
||||
nsGridCell*
|
||||
nsGrid::GetCellAt(PRInt32 aX, PRInt32 aY)
|
||||
{
|
||||
RebuildIfNeeded();
|
||||
|
||||
NS_ASSERTION(aY < mRowCount && aY >= 0, "Index out of range");
|
||||
NS_ASSERTION(aX < mColumnCount && aX >= 0, "Index out of range");
|
||||
return &mCellMap[aY*mColumnCount+aX];
|
||||
}
|
||||
|
||||
PRInt32
|
||||
nsGrid::GetExtraColumnCount(PRBool aIsRow)
|
||||
{
|
||||
return GetExtraRowCount(!aIsRow);
|
||||
}
|
||||
|
||||
PRInt32
|
||||
nsGrid::GetExtraRowCount(PRBool aIsRow)
|
||||
{
|
||||
RebuildIfNeeded();
|
||||
|
||||
if (aIsRow)
|
||||
return mExtraRowCount;
|
||||
else
|
||||
return mExtraColumnCount;
|
||||
}
|
||||
|
||||
void
|
||||
nsGrid::RebuildIfNeeded()
|
||||
{
|
||||
if (!mNeedsRebuild)
|
||||
return;
|
||||
|
||||
mNeedsRebuild = PR_FALSE;
|
||||
|
||||
// find the row and columns frames
|
||||
FindRowsAndColumns(&mRowBox, &mColumnBox);
|
||||
|
||||
// count the rows and columns
|
||||
PRInt32 computedRowCount = 0;
|
||||
PRInt32 computedColumnCount = 0;
|
||||
CountRowsColumns(mRowBox, mRowCount, computedColumnCount);
|
||||
CountRowsColumns(mColumnBox, mColumnCount, computedRowCount);
|
||||
|
||||
// computedRowCount are the actual number of rows as determined by the
|
||||
// columns children.
|
||||
// computedColumnCount are the number of columns as determined by the number
|
||||
// of rows children.
|
||||
// We can use this information to see how many extra columns or rows we need.
|
||||
// This can happen if there are are more children in a row that number of columns
|
||||
// defined. Example:
|
||||
//
|
||||
// <columns>
|
||||
// <column/>
|
||||
// </columns>
|
||||
//
|
||||
// <rows>
|
||||
// <row>
|
||||
// <button/><button/>
|
||||
// </row>
|
||||
// </rows>
|
||||
//
|
||||
// computedColumnCount = 2 // for the 2 buttons in the the row tag
|
||||
// computedRowCount = 0 // there is nothing in the column tag
|
||||
// mColumnCount = 1 // one column defined
|
||||
// mRowCount = 1 // one row defined
|
||||
//
|
||||
// So in this case we need to make 1 extra column.
|
||||
//
|
||||
|
||||
if (computedColumnCount > mColumnCount) {
|
||||
mExtraColumnCount = computedColumnCount - mColumnCount;
|
||||
mColumnCount = computedColumnCount;
|
||||
}
|
||||
|
||||
if (computedRowCount > mRowCount) {
|
||||
mExtraRowCount = computedRowCount - mRowCount;
|
||||
mRowCount = computedRowCount;
|
||||
}
|
||||
|
||||
// build and poplulate row and columns arrays
|
||||
BuildRows(mRowBox, mRowCount, &mRows, PR_TRUE);
|
||||
BuildRows(mColumnBox, mColumnCount, &mColumns, PR_FALSE);
|
||||
|
||||
// build and populate the cell map
|
||||
BuildCellMap(mRowCount, mColumnCount, &mCellMap);
|
||||
|
||||
// populate the cell map from column and row children
|
||||
PopulateCellMap(mRows, mColumns, mRowCount, mColumnCount, PR_TRUE);
|
||||
PopulateCellMap(mColumns, mRows, mColumnCount, mRowCount, PR_FALSE);
|
||||
}
|
||||
|
||||
void
|
||||
nsGrid::FreeMap()
|
||||
{
|
||||
if (mRows)
|
||||
delete[] mRows;
|
||||
|
||||
if (mColumns)
|
||||
delete[] mColumns;
|
||||
|
||||
if (mCellMap)
|
||||
delete[] mCellMap;
|
||||
|
||||
mRows = nsnull;
|
||||
mColumns = nsnull;
|
||||
mCellMap = nsnull;
|
||||
mColumnCount = 0;
|
||||
mRowCount = 0;
|
||||
mExtraColumnCount = 0;
|
||||
mExtraRowCount = 0;
|
||||
mRowBox = nsnull;
|
||||
mColumnBox = nsnull;
|
||||
}
|
||||
|
||||
void
|
||||
nsGrid::FindRowsAndColumns(nsIBox** aRows, nsIBox** aColumns)
|
||||
{
|
||||
*aRows = nsnull;
|
||||
*aColumns = nsnull;
|
||||
|
||||
// find the boxes that contain our rows and columns
|
||||
nsIBox* child = nsnull;
|
||||
mBox->GetChildBox(&child);
|
||||
|
||||
while(child)
|
||||
{
|
||||
nsIBox* oldBox = child;
|
||||
nsresult rv = NS_OK;
|
||||
nsCOMPtr<nsIScrollableFrame> scrollFrame = do_QueryInterface(child, &rv);
|
||||
if (scrollFrame) {
|
||||
nsIFrame* scrolledFrame = nsnull;
|
||||
scrollFrame->GetScrolledFrame(nsnull, scrolledFrame);
|
||||
NS_ASSERTION(scrolledFrame,"Error no scroll frame!!");
|
||||
nsCOMPtr<nsIBox> b = do_QueryInterface(scrolledFrame);
|
||||
child = b;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIBoxLayout> layout;
|
||||
child->GetLayoutManager(getter_AddRefs(layout));
|
||||
|
||||
nsCOMPtr<nsIGridPart> monument( do_QueryInterface(layout) );
|
||||
if (monument)
|
||||
{
|
||||
nsGridRowGroupLayout* rowGroup = nsnull;
|
||||
monument->CastToRowGroupLayout(&rowGroup);
|
||||
if (rowGroup) {
|
||||
PRBool isRow = !nsSprocketLayout::IsHorizontal(child);
|
||||
if (isRow)
|
||||
*aRows = child;
|
||||
else
|
||||
*aColumns = child;
|
||||
|
||||
if (*aRows && *aColumns)
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (scrollFrame) {
|
||||
child = oldBox;
|
||||
}
|
||||
|
||||
child->GetNextBox(&child);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
nsGrid::CountRowsColumns(nsIBox* aRowBox, PRInt32& aRowCount, PRInt32& aComputedColumnCount)
|
||||
{
|
||||
// get the rowboxes layout manager. Then ask it to do the work for us
|
||||
if (aRowBox) {
|
||||
nsCOMPtr<nsIBoxLayout> layout;
|
||||
aRowBox->GetLayoutManager(getter_AddRefs(layout));
|
||||
if (layout) {
|
||||
nsCOMPtr<nsIGridPart> monument( do_QueryInterface(layout) );
|
||||
if (monument)
|
||||
monument->CountRowsColumns(aRowBox, aRowCount, aComputedColumnCount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
nsGrid::BuildRows(nsIBox* aBox, PRBool aRowCount, nsGridRow** aRows, PRBool aIsRow)
|
||||
{
|
||||
// if not rows then return null
|
||||
if (aRowCount == 0) {
|
||||
*aRows = nsnull;
|
||||
return;
|
||||
}
|
||||
|
||||
// create the array
|
||||
PRInt32 count = 0;
|
||||
nsGridRow* row = new nsGridRow[aRowCount];
|
||||
|
||||
// populate it if we can. If not it will contain only dynamic columns
|
||||
if (aBox)
|
||||
{
|
||||
nsCOMPtr<nsIBoxLayout> layout;
|
||||
aBox->GetLayoutManager(getter_AddRefs(layout));
|
||||
if (layout) {
|
||||
nsCOMPtr<nsIGridPart> monument( do_QueryInterface(layout) );
|
||||
if (monument) {
|
||||
PRInt32 count;
|
||||
monument->BuildRows(aBox, row, &count);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*aRows = row;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
nsGrid::BuildCellMap(PRInt32 aRows, PRInt32 aColumns, nsGridCell** aCells)
|
||||
{
|
||||
PRInt32 size = aRows*aColumns;
|
||||
if (size == 0)
|
||||
(*aCells) = nsnull;
|
||||
else
|
||||
(*aCells) = new nsGridCell[size];
|
||||
}
|
||||
|
||||
void
|
||||
nsGrid::PopulateCellMap(nsGridRow* aRows, nsGridRow* aColumns, PRInt32 aRowCount, PRInt32 aColumnCount, PRBool aIsRow)
|
||||
{
|
||||
if (!aRows)
|
||||
return;
|
||||
|
||||
// look through the columns
|
||||
nscoord j = 0;
|
||||
|
||||
for(PRInt32 i=0; i < aRowCount; i++)
|
||||
{
|
||||
nsIBox* child = nsnull;
|
||||
nsGridRow* row = &aRows[i];
|
||||
|
||||
// skip bogus rows. They have no cells
|
||||
if (row->mIsBogus)
|
||||
continue;
|
||||
|
||||
child = row->mBox;
|
||||
if (child) {
|
||||
child->GetChildBox(&child);
|
||||
|
||||
j = 0;
|
||||
|
||||
while(child && j < aColumnCount)
|
||||
{
|
||||
// skip bogus column. They have no cells
|
||||
nsGridRow* column = &aColumns[j];
|
||||
if (column->mIsBogus)
|
||||
{
|
||||
j++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (aIsRow)
|
||||
GetCellAt(j,i)->SetBoxInRow(child);
|
||||
else
|
||||
GetCellAt(i,j)->SetBoxInColumn(child);
|
||||
|
||||
child->GetNextBox(&child);
|
||||
|
||||
j++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* These methods return the preferred, min, max sizes for a given row index.
|
||||
* aIsRow is defaulted to PR_TRUE. If you pass PR_FALSE you will get the inverse.
|
||||
* As if you called GetPrefColumnSize(aState, index, aPref)
|
||||
*/
|
||||
nsresult
|
||||
nsGrid::GetPrefRowSize(nsBoxLayoutState& aState, PRInt32 aRowIndex, nsSize& aSize, PRBool aIsRow)
|
||||
{
|
||||
//NS_ASSERTION(aRowIndex >=0 && aRowIndex < GetRowCount(aIsRow), "Row index out of range!");
|
||||
if (!(aRowIndex >=0 && aRowIndex < GetRowCount(aIsRow)))
|
||||
return NS_OK;
|
||||
|
||||
nscoord height = 0;
|
||||
GetPrefRowHeight(aState, aRowIndex, height, aIsRow);
|
||||
SetLargestSize(aSize, height, aIsRow);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsGrid::GetMinRowSize(nsBoxLayoutState& aState, PRInt32 aRowIndex, nsSize& aSize, PRBool aIsRow)
|
||||
{
|
||||
if (!(aRowIndex >=0 && aRowIndex < GetRowCount(aIsRow)))
|
||||
return NS_OK;
|
||||
|
||||
nscoord height = 0;
|
||||
GetMinRowHeight(aState, aRowIndex, height, aIsRow);
|
||||
SetLargestSize(aSize, height, aIsRow);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsGrid::GetMaxRowSize(nsBoxLayoutState& aState, PRInt32 aRowIndex, nsSize& aSize, PRBool aIsRow)
|
||||
{
|
||||
if (!(aRowIndex >=0 && aRowIndex < GetRowCount(aIsRow)))
|
||||
return NS_OK;
|
||||
|
||||
nscoord height = 0;
|
||||
GetMaxRowHeight(aState, aRowIndex, height, aIsRow);
|
||||
SetSmallestSize(aSize, height, aIsRow);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* These methods return the preferred, min, max coord for a given row index.
|
||||
* aIsRow is defaulted to PR_TRUE. If you pass PR_FALSE you will get the inverse.
|
||||
* As if you called GetPrefColumnHeight(aState, index, aPref)
|
||||
*/
|
||||
nsresult
|
||||
nsGrid::GetPrefRowHeight(nsBoxLayoutState& aState, PRInt32 aIndex, nscoord& aSize, PRBool aIsRow)
|
||||
{
|
||||
RebuildIfNeeded();
|
||||
|
||||
nsGridRow* row = GetRowAt(aIndex, aIsRow);
|
||||
|
||||
if (row->IsPrefSet())
|
||||
{
|
||||
aSize = row->mPref;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsIBox* box = row->mBox;
|
||||
|
||||
// set in CSS?
|
||||
if (box) {
|
||||
nsSize cssSize;
|
||||
cssSize.width = -1;
|
||||
cssSize.height = -1;
|
||||
nsIBox::AddCSSPrefSize(aState, box, cssSize);
|
||||
// TBD subtract our borders and padding place them in
|
||||
// left and right padding
|
||||
|
||||
row->mPref = GET_HEIGHT(cssSize, aIsRow);
|
||||
|
||||
// yep do nothing.
|
||||
if (row->mPref != -1)
|
||||
{
|
||||
aSize = row->mPref;
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
nsSize size(0,0);
|
||||
|
||||
nsGridCell* child;
|
||||
|
||||
PRInt32 count = GetColumnCount(aIsRow);
|
||||
|
||||
PRBool isCollapsed = PR_FALSE;
|
||||
|
||||
for (PRInt32 i=0; i < count; i++)
|
||||
{
|
||||
if (aIsRow)
|
||||
child = GetCellAt(i,aIndex);
|
||||
else
|
||||
child = GetCellAt(aIndex,i);
|
||||
|
||||
// ignore collapsed children
|
||||
child->IsCollapsed(aState, isCollapsed);
|
||||
|
||||
if (!isCollapsed)
|
||||
{
|
||||
nsSize childSize(0,0);
|
||||
|
||||
child->GetPrefSize(aState, childSize);
|
||||
|
||||
nsSprocketLayout::AddLargestSize(size, childSize, aIsRow);
|
||||
}
|
||||
}
|
||||
|
||||
row->mPref = GET_HEIGHT(size, aIsRow);
|
||||
|
||||
aSize = row->mPref;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsGrid::GetMinRowHeight(nsBoxLayoutState& aState, PRInt32 aIndex, nscoord& aSize, PRBool aIsRow)
|
||||
{
|
||||
RebuildIfNeeded();
|
||||
|
||||
nsGridRow* row = GetRowAt(aIndex, aIsRow);
|
||||
|
||||
if (row->IsMinSet())
|
||||
{
|
||||
aSize = row->mMin;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsIBox* box = row->mBox;
|
||||
|
||||
// set in CSS?
|
||||
if (box) {
|
||||
nsSize cssSize;
|
||||
cssSize.width = -1;
|
||||
cssSize.height = -1;
|
||||
nsIBox::AddCSSMinSize(aState, box, cssSize);
|
||||
// TBD subtract our borders and padding place them in
|
||||
// left and right padding
|
||||
|
||||
row->mMin = GET_HEIGHT(cssSize, aIsRow);
|
||||
|
||||
// yep do nothing.
|
||||
if (row->mMin != -1)
|
||||
{
|
||||
aSize = row->mMin;
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
nsSize size(0,0);
|
||||
|
||||
nsGridCell* child;
|
||||
|
||||
PRInt32 count = GetColumnCount(aIsRow);
|
||||
|
||||
PRBool isCollapsed = PR_FALSE;
|
||||
|
||||
for (PRInt32 i=0; i < count; i++)
|
||||
{
|
||||
if (aIsRow)
|
||||
child = GetCellAt(i,aIndex);
|
||||
else
|
||||
child = GetCellAt(aIndex,i);
|
||||
|
||||
// ignore collapsed children
|
||||
child->IsCollapsed(aState, isCollapsed);
|
||||
|
||||
if (!isCollapsed)
|
||||
{
|
||||
nsSize childSize(0,0);
|
||||
|
||||
child->GetMinSize(aState, childSize);
|
||||
|
||||
nsSprocketLayout::AddLargestSize(size, childSize, aIsRow);
|
||||
}
|
||||
}
|
||||
|
||||
row->mMin = GET_HEIGHT(size, aIsRow);
|
||||
|
||||
aSize = row->mMin;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsGrid::GetMaxRowHeight(nsBoxLayoutState& aState, PRInt32 aIndex, nscoord& aSize, PRBool aIsRow)
|
||||
{
|
||||
RebuildIfNeeded();
|
||||
|
||||
nsGridRow* row = GetRowAt(aIndex, aIsRow);
|
||||
|
||||
if (row->IsMaxSet())
|
||||
{
|
||||
aSize = row->mMax;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsIBox* box = row->mBox;
|
||||
|
||||
// set in CSS?
|
||||
if (box) {
|
||||
nsSize cssSize;
|
||||
cssSize.width = -1;
|
||||
cssSize.height = -1;
|
||||
nsIBox::AddCSSMaxSize(aState, box, cssSize);
|
||||
// TBD subtract our borders and padding place them in
|
||||
// left and right padding
|
||||
|
||||
row->mMax = GET_HEIGHT(cssSize, aIsRow);
|
||||
|
||||
// yep do nothing.
|
||||
if (row->mMax != -1)
|
||||
{
|
||||
aSize = row->mMax;
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
nsSize size(NS_INTRINSICSIZE,NS_INTRINSICSIZE);
|
||||
|
||||
nsGridCell* child;
|
||||
|
||||
PRInt32 count = GetColumnCount(aIsRow);
|
||||
|
||||
PRBool isCollapsed = PR_FALSE;
|
||||
|
||||
for (PRInt32 i=0; i < count; i++)
|
||||
{
|
||||
if (aIsRow)
|
||||
child = GetCellAt(i,aIndex);
|
||||
else
|
||||
child = GetCellAt(aIndex,i);
|
||||
|
||||
// ignore collapsed children
|
||||
child->IsCollapsed(aState, isCollapsed);
|
||||
|
||||
if (!isCollapsed)
|
||||
{
|
||||
nsSize childSize(0,0);
|
||||
|
||||
child->GetMaxSize(aState, childSize);
|
||||
|
||||
nsSprocketLayout::AddLargestSize(size, childSize, aIsRow);
|
||||
}
|
||||
}
|
||||
|
||||
row->mMax = GET_HEIGHT(size, aIsRow);
|
||||
|
||||
aSize = row->mMax;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsGrid::GetRowFlex(nsBoxLayoutState& aState, PRInt32 aIndex, nscoord& aFlex, PRBool aIsRow)
|
||||
{
|
||||
RebuildIfNeeded();
|
||||
|
||||
nsGridRow* row = GetRowAt(aIndex, aIsRow);
|
||||
|
||||
if (row->IsFlexSet())
|
||||
{
|
||||
aFlex = row->mFlex;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsIBox* box = row->mBox;
|
||||
row->mFlex = 0;
|
||||
|
||||
if (box) {
|
||||
box->GetFlex(aState, row->mFlex);
|
||||
nsIBox::AddCSSFlex(aState, box, row->mFlex);
|
||||
}
|
||||
|
||||
aFlex = row->mFlex;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
nsGrid::SetLargestSize(nsSize& aSize, nscoord aHeight, PRBool aIsRow)
|
||||
{
|
||||
if (aIsRow) {
|
||||
if (aSize.height < aHeight)
|
||||
aSize.height = aHeight;
|
||||
} else {
|
||||
if (aSize.width < aHeight)
|
||||
aSize.width = aHeight;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
nsGrid::SetSmallestSize(nsSize& aSize, nscoord aHeight, PRBool aIsRow)
|
||||
{
|
||||
if (aIsRow) {
|
||||
if (aSize.height > aHeight)
|
||||
aSize.height = aHeight;
|
||||
} else {
|
||||
if (aSize.width < aHeight)
|
||||
aSize.width = aHeight;
|
||||
}
|
||||
}
|
||||
|
||||
PRInt32
|
||||
nsGrid::GetRowCount(PRInt32 aIsRow)
|
||||
{
|
||||
RebuildIfNeeded();
|
||||
|
||||
if (aIsRow)
|
||||
return mRowCount;
|
||||
else
|
||||
return mColumnCount;
|
||||
}
|
||||
|
||||
PRInt32
|
||||
nsGrid::GetColumnCount(PRInt32 aIsRow)
|
||||
{
|
||||
return GetRowCount(!aIsRow);
|
||||
}
|
||||
|
||||
void
|
||||
nsGrid::RowChildIsDirty(nsBoxLayoutState& aState, PRInt32 aRowIndex, PRInt32 aColumnIndex, PRBool aIsRow)
|
||||
{
|
||||
// if we are already dirty do nothing.
|
||||
if (mNeedsRebuild || mMarkingDirty)
|
||||
return;
|
||||
|
||||
mMarkingDirty = PR_TRUE;
|
||||
|
||||
// index out of range. Rebuild it all
|
||||
if (aRowIndex >= GetRowCount(aIsRow) || aColumnIndex >= GetColumnCount(aIsRow))
|
||||
{
|
||||
NeedsRebuild(aState);
|
||||
return;
|
||||
}
|
||||
|
||||
// dirty our 2 outer nsGridRowGroups. (one for columns and one for rows)
|
||||
// we need to do this because the rows and column we are given may be Extra ones
|
||||
// and may not have any Box associated with them. If you dirtied them then
|
||||
// corresponding nsGridRowGroup around them would never get dirty. So lets just
|
||||
// do it manually here.
|
||||
|
||||
if (mRowBox)
|
||||
mRowBox->MarkDirty(aState);
|
||||
|
||||
if (mColumnBox)
|
||||
mColumnBox->MarkDirty(aState);
|
||||
|
||||
// dirty just our row and column that we were given
|
||||
nsGridRow* row = GetRowAt(aRowIndex, aIsRow);
|
||||
row->MarkDirty(aState);
|
||||
|
||||
nsGridRow* column = GetColumnAt(aColumnIndex, aIsRow);
|
||||
column->MarkDirty(aState);
|
||||
|
||||
|
||||
mMarkingDirty = PR_FALSE;
|
||||
}
|
||||
|
||||
void
|
||||
nsGrid::RowIsDirty(nsBoxLayoutState& aState, PRInt32 aIndex, PRBool aIsRow)
|
||||
{
|
||||
if (mMarkingDirty)
|
||||
return;
|
||||
|
||||
NeedsRebuild(aState);
|
||||
}
|
||||
|
||||
void
|
||||
nsGrid::CellAddedOrRemoved(nsBoxLayoutState& aState, PRInt32 aIndex, PRBool aIsRow)
|
||||
{
|
||||
// see if the cell will fit in our current row. If it will
|
||||
// just add it. If not rebuild everything.
|
||||
if (mMarkingDirty)
|
||||
return;
|
||||
|
||||
NeedsRebuild(aState);
|
||||
}
|
||||
|
||||
void
|
||||
nsGrid::RowAddedOrRemoved(nsBoxLayoutState& aState, PRInt32 aIndex, PRBool aIsRow)
|
||||
{
|
||||
// see if we have extra room in the table and just add the new row in
|
||||
if (mMarkingDirty)
|
||||
return;
|
||||
|
||||
NeedsRebuild(aState);
|
||||
}
|
||||
|
||||
/*
|
||||
void
|
||||
nsGrid::PrintCellMap()
|
||||
{
|
||||
printf("-----CellMap------\n");
|
||||
for (int y=0; y < mRowCount; y++)
|
||||
{
|
||||
for (int x=0; x < mColumnCount; x++)
|
||||
{
|
||||
nsGridCell* cell = GetCellAt(x,y);
|
||||
//printf("(%d)@%p[@%p,@%p] ", y*mColumnCount+x, cell, cell->GetBoxInRow(), cell->GetBoxInColumn());
|
||||
printf("p=%d, ", y*mColumnCount+x, cell, cell->GetBoxInRow(), cell->GetBoxInColumn());
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
void
|
||||
nsGrid::PrintCellMap()
|
||||
{
|
||||
|
||||
printf("-----Columns------\n");
|
||||
for (int x=0; x < mColumnCount; x++)
|
||||
{
|
||||
nsGridRow* column = GetColumnAt(x);
|
||||
printf("%d(pf=%d, mn=%d, mx=%d) ", x, column->mPref, column->mMin, column->mMax);
|
||||
}
|
||||
|
||||
printf("\n-----Rows------\n");
|
||||
for (x=0; x < mRowCount; x++)
|
||||
{
|
||||
nsGridRow* column = GetRowAt(x);
|
||||
printf("%d(pf=%d, mn=%d, mx=%d) ", x, column->mPref, column->mMin, column->mMax);
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
|
||||
|
||||
|
||||
/*
|
||||
for (int y=0; y < mRowCount; y++)
|
||||
{
|
||||
for (int x=0; x < mColumnCount; x++)
|
||||
{
|
||||
nsGridCell* cell = GetCellAt(x,y);
|
||||
printf("p=%d, ", y*mColumnCount+x, cell, cell->GetBoxInRow(), cell->GetBoxInColumn());
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
|
@ -0,0 +1,121 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.1 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Mozilla Communicator client code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
/**
|
||||
|
||||
Author:
|
||||
Eric D Vaughan
|
||||
|
||||
**/
|
||||
|
||||
#ifndef nsGrid_h___
|
||||
#define nsGrid_h___
|
||||
|
||||
#include "nsStackLayout.h"
|
||||
#include "nsIGridPart.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIBox.h"
|
||||
|
||||
class nsGridRowGroupLayout;
|
||||
class nsGridRowLayout;
|
||||
class nsBoxLayoutState;
|
||||
class nsGridCell;
|
||||
|
||||
class nsGrid
|
||||
{
|
||||
public:
|
||||
nsGrid();
|
||||
~nsGrid();
|
||||
|
||||
virtual void FreeMap();
|
||||
virtual PRInt32 GetRowCount(PRInt32 aIsRow = PR_TRUE);
|
||||
virtual PRInt32 GetColumnCount(PRInt32 aIsRow = PR_TRUE);
|
||||
virtual void NeedsRebuild(nsBoxLayoutState& aBoxLayoutState);
|
||||
virtual nsGridRow* GetColumnAt(PRInt32 aIndex, PRBool aIsRow = PR_TRUE);
|
||||
virtual nsGridRow* GetRowAt(PRInt32 aIndex, PRBool aIsRow = PR_TRUE);
|
||||
virtual nsGridCell* GetCellAt(PRInt32 aX, PRInt32 aY);
|
||||
virtual void RebuildIfNeeded();
|
||||
|
||||
virtual nsresult GetPrefRowSize(nsBoxLayoutState& aBoxLayoutState, PRInt32 aRowIndex, nsSize& aSize, PRBool aIsRow);
|
||||
virtual nsresult GetMinRowSize(nsBoxLayoutState& aBoxLayoutState, PRInt32 aRowIndex, nsSize& aSize, PRBool aIsRow);
|
||||
virtual nsresult GetMaxRowSize(nsBoxLayoutState& aBoxLayoutState, PRInt32 aRowIndex, nsSize& aSize, PRBool aIsRow);
|
||||
virtual nsresult GetRowFlex(nsBoxLayoutState& aBoxLayoutState, PRInt32 aRowIndex, nscoord& aSize, PRBool aIsRow);
|
||||
|
||||
virtual nsresult GetPrefRowHeight(nsBoxLayoutState& aBoxLayoutState, PRInt32 aRowIndex, nscoord& aHeight, PRBool aIsRow = PR_TRUE);
|
||||
virtual nsresult GetMinRowHeight(nsBoxLayoutState& aBoxLayoutState, PRInt32 aRowIndex, nscoord& aHeight, PRBool aIsRow = PR_TRUE);
|
||||
virtual nsresult GetMaxRowHeight(nsBoxLayoutState& aBoxLayoutState, PRInt32 aRowIndex, nscoord& aHeight, PRBool aIsRow = PR_TRUE);
|
||||
|
||||
virtual void RowChildIsDirty(nsBoxLayoutState& aBoxLayoutState, PRInt32 aRowIndex, PRInt32 aColumnIndex, PRBool aIsRow = PR_TRUE);
|
||||
virtual void RowIsDirty(nsBoxLayoutState& aBoxLayoutState, PRInt32 aIndex, PRBool aIsRow = PR_TRUE);
|
||||
virtual void RowAddedOrRemoved(nsBoxLayoutState& aBoxLayoutState, PRInt32 aIndex, PRBool aIsRow = PR_TRUE);
|
||||
virtual void CellAddedOrRemoved(nsBoxLayoutState& aBoxLayoutState, PRInt32 aIndex, PRBool aIsRow = PR_TRUE);
|
||||
virtual void DirtyRows(nsIBox* aRowBox, nsBoxLayoutState& aState);
|
||||
virtual void PrintCellMap();
|
||||
virtual PRInt32 GetExtraColumnCount(PRBool aIsRow = PR_TRUE);
|
||||
virtual PRInt32 GetExtraRowCount(PRBool aIsRow = PR_TRUE);
|
||||
|
||||
// accessors
|
||||
virtual void SetBox(nsIBox* aBox) { mBox = aBox; }
|
||||
virtual nsGridRow* GetColumns();
|
||||
virtual nsGridRow* GetRows();
|
||||
|
||||
protected:
|
||||
virtual void FindRowsAndColumns(nsIBox** aRows, nsIBox** aColumns);
|
||||
virtual void BuildRows(nsIBox* aBox, PRBool aSize, nsGridRow** aColumnsRows, PRBool aIsRow = PR_TRUE);
|
||||
virtual void BuildCellMap(PRInt32 aRows, PRInt32 aColumns, nsGridCell** aCells);
|
||||
virtual void PopulateCellMap(nsGridRow* aRows, nsGridRow* aColumns, PRInt32 aRowCount, PRInt32 aColumnCount, PRBool aIsRow = PR_TRUE);
|
||||
virtual void CountRowsColumns(nsIBox* aBox, PRInt32& aRowCount, PRInt32& aComputedColumnCount);
|
||||
virtual void SetLargestSize(nsSize& aSize, nscoord aHeight, PRBool aIsRow);
|
||||
virtual void SetSmallestSize(nsSize& aSize, nscoord aHeight, PRBool aIsRow);
|
||||
|
||||
public:
|
||||
|
||||
nsIBox* mBox;
|
||||
nsGridRow* mRows;
|
||||
nsGridRow* mColumns;
|
||||
nsIBox* mRowBox;
|
||||
nsIBox* mColumnBox;
|
||||
PRBool mNeedsRebuild;
|
||||
PRInt32 mRowCount;
|
||||
PRInt32 mColumnCount;
|
||||
PRInt32 mExtraRowCount;
|
||||
PRInt32 mExtraColumnCount;
|
||||
nsGridCell* mCellMap;
|
||||
PRBool mMarkingDirty;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,178 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.1 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Mozilla Communicator client code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
//
|
||||
// Eric Vaughan
|
||||
// Netscape Communications
|
||||
//
|
||||
// See documentation in associated header file
|
||||
//
|
||||
|
||||
#include "nsGridCell.h"
|
||||
#include "nsFrame.h"
|
||||
#include "nsIBox.h"
|
||||
#include "nsBoxLayout.h"
|
||||
#include "nsStackLayout.h"
|
||||
|
||||
|
||||
nsGridCell::nsGridCell():mBoxInRow(nsnull),mBoxInColumn(nsnull)
|
||||
{
|
||||
MOZ_COUNT_CTOR(nsGridCell);
|
||||
}
|
||||
|
||||
nsGridCell::~nsGridCell()
|
||||
{
|
||||
MOZ_COUNT_DTOR(nsGridCell);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsGridCell::GetPrefSize(nsBoxLayoutState& aState, nsSize& aPref)
|
||||
{
|
||||
aPref.width = 0;
|
||||
aPref.height = 0;
|
||||
|
||||
// take ours 2 children and add them up.
|
||||
// we are as wide as the widest child plus its left offset
|
||||
// we are tall as the tallest child plus its top offset
|
||||
|
||||
nsSize pref(0,0);
|
||||
|
||||
if (mBoxInColumn) {
|
||||
mBoxInColumn->GetPrefSize(aState, pref);
|
||||
nsBoxLayout::AddMargin(mBoxInColumn, pref);
|
||||
nsStackLayout::AddOffset(aState, mBoxInColumn, pref);
|
||||
|
||||
nsBoxLayout::AddLargestSize(aPref, pref);
|
||||
}
|
||||
|
||||
if (mBoxInRow) {
|
||||
mBoxInRow->GetPrefSize(aState, pref);
|
||||
|
||||
nsBoxLayout::AddMargin(mBoxInRow, pref);
|
||||
nsStackLayout::AddOffset(aState, mBoxInRow, pref);
|
||||
|
||||
nsBoxLayout::AddLargestSize(aPref, pref);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsGridCell::GetMinSize(nsBoxLayoutState& aState, nsSize& aMin)
|
||||
{
|
||||
aMin.width = 0;
|
||||
aMin.height = 0;
|
||||
|
||||
// take ours 2 children and add them up.
|
||||
// we are as wide as the widest child plus its left offset
|
||||
// we are tall as the tallest child plus its top offset
|
||||
|
||||
nsSize min(0,0);
|
||||
|
||||
if (mBoxInColumn) {
|
||||
mBoxInColumn->GetMinSize(aState, min);
|
||||
|
||||
nsBoxLayout::AddMargin(mBoxInColumn, min);
|
||||
nsStackLayout::AddOffset(aState, mBoxInColumn, min);
|
||||
|
||||
nsBoxLayout::AddLargestSize(aMin, min);
|
||||
}
|
||||
|
||||
if (mBoxInRow) {
|
||||
mBoxInRow->GetMinSize(aState, min);
|
||||
|
||||
nsBoxLayout::AddMargin(mBoxInRow, min);
|
||||
nsStackLayout::AddOffset(aState, mBoxInRow, min);
|
||||
|
||||
nsBoxLayout::AddLargestSize(aMin, min);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsGridCell::GetMaxSize(nsBoxLayoutState& aState, nsSize& aMax)
|
||||
{
|
||||
aMax.width = NS_INTRINSICSIZE;
|
||||
aMax.height = NS_INTRINSICSIZE;
|
||||
|
||||
// take ours 2 children and add them up.
|
||||
// we are as wide as the widest child plus its left offset
|
||||
// we are tall as the tallest child plus its top offset
|
||||
|
||||
nsSize max(NS_INTRINSICSIZE,NS_INTRINSICSIZE);
|
||||
|
||||
if (mBoxInColumn) {
|
||||
mBoxInColumn->GetMaxSize(aState, max);
|
||||
|
||||
|
||||
nsBoxLayout::AddMargin(mBoxInColumn, max);
|
||||
nsStackLayout::AddOffset(aState, mBoxInColumn, max);
|
||||
|
||||
nsBoxLayout::AddSmallestSize(aMax, max);
|
||||
}
|
||||
|
||||
if (mBoxInRow) {
|
||||
mBoxInRow->GetMaxSize(aState, max);
|
||||
|
||||
nsBoxLayout::AddMargin(mBoxInRow, max);
|
||||
nsStackLayout::AddOffset(aState, mBoxInRow, max);
|
||||
|
||||
nsBoxLayout::AddSmallestSize(aMax, max);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsGridCell::IsCollapsed(nsBoxLayoutState& aState, PRBool& aIsCollapsed)
|
||||
{
|
||||
PRBool c1 = PR_FALSE, c2 = PR_FALSE;
|
||||
|
||||
if (mBoxInColumn)
|
||||
mBoxInColumn->IsCollapsed(aState, c1);
|
||||
|
||||
if (mBoxInRow)
|
||||
mBoxInRow->IsCollapsed(aState, c2);
|
||||
|
||||
aIsCollapsed = (c1 || c2);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,77 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.1 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Mozilla Communicator client code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
/**
|
||||
|
||||
Author:
|
||||
Eric D Vaughan
|
||||
|
||||
**/
|
||||
|
||||
#ifndef nsGridCell_h___
|
||||
#define nsGridCell_h___
|
||||
|
||||
#include "nsIFrame.h"
|
||||
|
||||
class nsBoxLayoutState;
|
||||
struct nsSize;
|
||||
class nsIBox;
|
||||
|
||||
class nsGridCell
|
||||
{
|
||||
public:
|
||||
nsGridCell();
|
||||
virtual ~nsGridCell();
|
||||
|
||||
virtual nsresult GetPrefSize(nsBoxLayoutState& aBoxLayoutState, nsSize& aPref);
|
||||
virtual nsresult GetMinSize(nsBoxLayoutState& aBoxLayoutState, nsSize& aMin);
|
||||
virtual nsresult GetMaxSize(nsBoxLayoutState& aBoxLayoutState, nsSize& aMax);
|
||||
virtual nsresult IsCollapsed(nsBoxLayoutState& aBoxLayoutState, PRBool& aIsCollapsed);
|
||||
|
||||
// accessors
|
||||
virtual nsIBox* GetBoxInColumn() { return mBoxInColumn; }
|
||||
virtual nsIBox* GetBoxInRow() { return mBoxInRow; }
|
||||
virtual void SetBoxInRow(nsIBox* aBox) { mBoxInRow = aBox; }
|
||||
virtual void SetBoxInColumn(nsIBox* aBox) { mBoxInColumn = aBox; }
|
||||
|
||||
private:
|
||||
nsIBox* mBoxInColumn;
|
||||
nsIBox* mBoxInRow;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,148 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.1 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Mozilla Communicator client code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
//
|
||||
// Eric Vaughan
|
||||
// Netscape Communications
|
||||
//
|
||||
// See documentation in associated header file
|
||||
//
|
||||
|
||||
#include "nsGridLayout2.h"
|
||||
#include "nsGridRowGroupLayout.h"
|
||||
#include "nsBox.h"
|
||||
#include "nsIScrollableFrame.h"
|
||||
#include "nsSprocketLayout.h"
|
||||
|
||||
nsresult
|
||||
NS_NewGridLayout2( nsIPresShell* aPresShell, nsIBoxLayout** aNewLayout)
|
||||
{
|
||||
*aNewLayout = new nsGridLayout2(aPresShell);
|
||||
NS_IF_ADDREF(*aNewLayout);
|
||||
|
||||
return NS_OK;
|
||||
|
||||
}
|
||||
|
||||
nsGridLayout2::nsGridLayout2(nsIPresShell* aPresShell):nsStackLayout()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGridLayout2::Layout(nsIBox* aBox, nsBoxLayoutState& aBoxLayoutState)
|
||||
{
|
||||
mGrid.SetBox(aBox);
|
||||
nsresult rv = nsStackLayout::Layout(aBox, aBoxLayoutState);
|
||||
mGrid.PrintCellMap();
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGridLayout2::GetGrid(nsIBox* aBox, nsGrid** aGrid, PRInt32* aIndex, nsGridRowLayout* aRequestor)
|
||||
{
|
||||
mGrid.mBox = aBox;
|
||||
*aGrid = &mGrid;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGridLayout2::GetParentGridPart(nsIBox* aBox, nsCOMPtr<nsIBox>& aParentBox, nsIGridPart** aParentGridRow)
|
||||
{
|
||||
NS_ERROR("Should not be called");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGridLayout2::GetMinSize(nsIBox* aBox, nsBoxLayoutState& aState, nsSize& aSize)
|
||||
{
|
||||
return nsStackLayout::GetMinSize(aBox, aState, aSize);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGridLayout2::GetPrefSize(nsIBox* aBox, nsBoxLayoutState& aState, nsSize& aSize)
|
||||
{
|
||||
return nsStackLayout::GetPrefSize(aBox, aState, aSize);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGridLayout2::GetMaxSize(nsIBox* aBox, nsBoxLayoutState& aState, nsSize& aSize)
|
||||
{
|
||||
return nsStackLayout::GetMaxSize(aBox, aState, aSize);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGridLayout2::CountRowsColumns(nsIBox* aRowBox, PRInt32& aRowCount, PRInt32& aComputedColumnCount)
|
||||
{
|
||||
NS_ERROR("Should not be called");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGridLayout2::DirtyRows(nsIBox* aBox, nsBoxLayoutState& aState)
|
||||
{
|
||||
NS_ERROR("Should not be called");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGridLayout2::BuildRows(nsIBox* aBox, nsGridRow* aRows, PRInt32* aCount)
|
||||
{
|
||||
NS_ERROR("Should not be called");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGridLayout2::CastToRowGroupLayout(nsGridRowGroupLayout** aRowGroup)
|
||||
{
|
||||
(*aRowGroup) = nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGridLayout2::CastToGridLayout(nsGridLayout2** aGridLayout)
|
||||
{
|
||||
(*aGridLayout) = this;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF_INHERITED(nsGridLayout2, nsStackLayout);
|
||||
NS_IMPL_RELEASE_INHERITED(nsGridLayout2, nsStackLayout);
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN(nsGridLayout2)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIGridPart)
|
||||
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIGridPart)
|
||||
NS_INTERFACE_MAP_END_INHERITING(nsStackLayout)
|
|
@ -0,0 +1,90 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.1 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Mozilla Communicator client code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
/**
|
||||
|
||||
Author:
|
||||
Eric D Vaughan
|
||||
|
||||
**/
|
||||
|
||||
#ifndef nsGridLayout2_h___
|
||||
#define nsGridLayout2_h___
|
||||
|
||||
#include "nsStackLayout.h"
|
||||
#include "nsIGridPart.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIBox.h"
|
||||
#include "nsGrid.h"
|
||||
|
||||
class nsGridRowGroupLayout;
|
||||
class nsGridRowLayout;
|
||||
class nsGridRow;
|
||||
class nsBoxLayoutState;
|
||||
class nsGridCell;
|
||||
|
||||
class nsGridLayout2 : public nsStackLayout,
|
||||
public nsIGridPart
|
||||
{
|
||||
public:
|
||||
|
||||
friend nsresult NS_NewGridLayout2(nsIPresShell* aPresShell, nsIBoxLayout** aNewLayout);
|
||||
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
|
||||
NS_IMETHOD Layout(nsIBox* aBox, nsBoxLayoutState& aBoxLayoutState);
|
||||
|
||||
NS_IMETHOD CastToRowGroupLayout(nsGridRowGroupLayout** aRowGroup);
|
||||
NS_IMETHOD CastToGridLayout(nsGridLayout2** aGrid);
|
||||
NS_IMETHOD GetGrid(nsIBox* aBox, nsGrid** aList, PRInt32* aIndex, nsGridRowLayout* aRequestor=nsnull);
|
||||
NS_IMETHOD GetParentGridPart(nsIBox* aBox, nsCOMPtr<nsIBox>& aParentBox, nsIGridPart** aParentGridPart);
|
||||
NS_IMETHOD GetMinSize(nsIBox* aBox, nsBoxLayoutState& aBoxLayoutState, nsSize& aSize);
|
||||
NS_IMETHOD GetPrefSize(nsIBox* aBox, nsBoxLayoutState& aBoxLayoutState, nsSize& aSize);
|
||||
NS_IMETHOD GetMaxSize(nsIBox* aBox, nsBoxLayoutState& aBoxLayoutState, nsSize& aSize);
|
||||
NS_IMETHOD CountRowsColumns(nsIBox* aBox, PRInt32& aRowCount, PRInt32& aComputedColumnCount);
|
||||
NS_IMETHOD DirtyRows(nsIBox* aBox, nsBoxLayoutState& aState);
|
||||
NS_IMETHOD BuildRows(nsIBox* aBox, nsGridRow* aRows, PRInt32* aCount);
|
||||
|
||||
protected:
|
||||
nsGridLayout2(nsIPresShell* aShell);
|
||||
|
||||
nsGrid mGrid;
|
||||
|
||||
}; // class nsGridLayout2
|
||||
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,81 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.1 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Mozilla Communicator client code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
//
|
||||
// Eric Vaughan
|
||||
// Netscape Communications
|
||||
//
|
||||
// See documentation in associated header file
|
||||
//
|
||||
|
||||
#include "nsGridRow.h"
|
||||
#include "nsIBox.h"
|
||||
|
||||
nsGridRow::nsGridRow():mBox(nsnull),
|
||||
mIsBogus(PR_FALSE),
|
||||
mFlex(-1),
|
||||
mPref(-1),
|
||||
mMin(-1),
|
||||
mMax(-1)
|
||||
|
||||
{
|
||||
MOZ_COUNT_CTOR(nsGridRow);
|
||||
}
|
||||
|
||||
void
|
||||
nsGridRow::Init(nsIBox* aBox, PRBool aIsBogus)
|
||||
{
|
||||
mBox = aBox;
|
||||
mIsBogus = aIsBogus;
|
||||
}
|
||||
|
||||
nsGridRow::~nsGridRow()
|
||||
{
|
||||
MOZ_COUNT_DTOR(nsGridRow);
|
||||
}
|
||||
|
||||
void
|
||||
nsGridRow::MarkDirty(nsBoxLayoutState& aState)
|
||||
{
|
||||
mPref = -1;
|
||||
mMin = -1;
|
||||
mMax = -1;
|
||||
|
||||
if (mBox)
|
||||
mBox->MarkDirty(aState);
|
||||
}
|
||||
|
|
@ -0,0 +1,82 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.1 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Mozilla Communicator client code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
/**
|
||||
|
||||
Author:
|
||||
Eric D Vaughan
|
||||
|
||||
**/
|
||||
|
||||
#ifndef nsGridRow_h___
|
||||
#define nsGridRow_h___
|
||||
|
||||
#include "nsIFrame.h"
|
||||
|
||||
class nsIBox;
|
||||
class nsGridLayout2;
|
||||
class nsBoxLayoutState;
|
||||
|
||||
class nsGridRow
|
||||
{
|
||||
public:
|
||||
nsGridRow();
|
||||
virtual ~nsGridRow();
|
||||
|
||||
virtual void Init(nsIBox* aBox, PRBool aIsBogus);
|
||||
virtual void MarkDirty(nsBoxLayoutState& aState);
|
||||
|
||||
// accessors
|
||||
virtual nsIBox* GetBox() { return mBox; }
|
||||
virtual PRBool IsPrefSet() { return (mPref != -1); }
|
||||
virtual PRBool IsMinSet() { return (mMin != -1); }
|
||||
virtual PRBool IsMaxSet() { return (mMax != -1); }
|
||||
virtual PRBool IsFlexSet() { return (mFlex != -1); }
|
||||
|
||||
public:
|
||||
|
||||
PRBool mIsBogus;
|
||||
nsIBox* mBox;
|
||||
nscoord mFlex;
|
||||
nscoord mPref;
|
||||
nscoord mMin;
|
||||
nscoord mMax;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,325 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.1 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Mozilla Communicator client code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
//
|
||||
// Eric Vaughan
|
||||
// Netscape Communications
|
||||
//
|
||||
// See documentation in associated header file
|
||||
//
|
||||
|
||||
#include "nsGridRowGroupLayout.h"
|
||||
#include "nsIBox.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIScrollableFrame.h"
|
||||
#include "nsBoxLayoutState.h"
|
||||
#include "nsGridLayout2.h"
|
||||
#include "nsGridRow.h"
|
||||
|
||||
nsresult
|
||||
NS_NewGridRowGroupLayout( nsIPresShell* aPresShell, nsIBoxLayout** aNewLayout)
|
||||
{
|
||||
*aNewLayout = new nsGridRowGroupLayout(aPresShell);
|
||||
NS_IF_ADDREF(*aNewLayout);
|
||||
|
||||
return NS_OK;
|
||||
|
||||
}
|
||||
|
||||
nsGridRowGroupLayout::nsGridRowGroupLayout(nsIPresShell* aPresShell):nsGridRowLayout(aPresShell)
|
||||
{
|
||||
}
|
||||
|
||||
nsGridRowGroupLayout::~nsGridRowGroupLayout()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGridRowGroupLayout::ChildAddedOrRemoved(nsIBox* aBox, nsBoxLayoutState& aState)
|
||||
{
|
||||
nsGrid* grid = nsnull;
|
||||
PRInt32 index = 0;
|
||||
GetGrid(aBox, &grid, &index);
|
||||
PRInt32 isRow = IsHorizontal(aBox);
|
||||
|
||||
if (grid)
|
||||
grid->RowAddedOrRemoved(aState, index, isRow);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
nsGridRowGroupLayout::AddWidth(nsSize& aSize, nscoord aSize2, PRBool aIsRow)
|
||||
{
|
||||
nscoord& size = GET_WIDTH(aSize, aIsRow);
|
||||
|
||||
if (size == NS_INTRINSICSIZE || aSize2 == NS_INTRINSICSIZE)
|
||||
size = NS_INTRINSICSIZE;
|
||||
else
|
||||
size += aSize2;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGridRowGroupLayout::GetPrefSize(nsIBox* aBox, nsBoxLayoutState& aState, nsSize& aSize)
|
||||
{
|
||||
nsresult rv = nsGridRowLayout::GetPrefSize(aBox, aState, aSize);
|
||||
|
||||
nsGrid* grid = nsnull;
|
||||
PRInt32 index = 0;
|
||||
GetGrid(aBox, &grid, &index);
|
||||
|
||||
if (grid)
|
||||
{
|
||||
// make sure we add in extra columns sizes as well
|
||||
PRInt32 isRow = IsHorizontal(aBox);
|
||||
PRInt32 extraColumns = grid->GetExtraColumnCount(isRow);
|
||||
PRInt32 start = grid->GetColumnCount(isRow) - grid->GetExtraColumnCount(isRow);
|
||||
for (PRInt32 i=0; i < extraColumns; i++)
|
||||
{
|
||||
nsGridRow* column = grid->GetColumnAt(i+start, isRow);
|
||||
nscoord size = 0;
|
||||
grid->GetPrefRowHeight(aState, i+start, size, !isRow); // GetPrefColumnWidth
|
||||
|
||||
AddWidth(aSize, size, isRow);
|
||||
}
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGridRowGroupLayout::GetMaxSize(nsIBox* aBox, nsBoxLayoutState& aState, nsSize& aSize)
|
||||
{
|
||||
nsresult rv = nsGridRowLayout::GetMaxSize(aBox, aState, aSize);
|
||||
|
||||
nsGrid* grid = nsnull;
|
||||
PRInt32 index = 0;
|
||||
GetGrid(aBox, &grid, &index);
|
||||
|
||||
if (grid)
|
||||
{
|
||||
// make sure we add in extra columns sizes as well
|
||||
PRInt32 isRow = IsHorizontal(aBox);
|
||||
PRInt32 extraColumns = grid->GetExtraColumnCount(isRow);
|
||||
PRInt32 start = grid->GetColumnCount(isRow) - grid->GetExtraColumnCount(isRow);
|
||||
for (PRInt32 i=0; i < extraColumns; i++)
|
||||
{
|
||||
nsGridRow* column = grid->GetColumnAt(i+start, isRow);
|
||||
nscoord size = 0;
|
||||
grid->GetMaxRowHeight(aState, i+start, size, !isRow); // GetMaxColumnWidth
|
||||
|
||||
AddWidth(aSize, size, isRow);
|
||||
}
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGridRowGroupLayout::GetMinSize(nsIBox* aBox, nsBoxLayoutState& aState, nsSize& aSize)
|
||||
{
|
||||
nsresult rv = nsGridRowLayout::GetMinSize(aBox, aState, aSize);
|
||||
|
||||
nsGrid* grid = nsnull;
|
||||
PRInt32 index = 0;
|
||||
GetGrid(aBox, &grid, &index);
|
||||
|
||||
if (grid)
|
||||
{
|
||||
// make sure we add in extra columns sizes as well
|
||||
PRInt32 isRow = IsHorizontal(aBox);
|
||||
PRInt32 extraColumns = grid->GetExtraColumnCount(isRow);
|
||||
PRInt32 start = grid->GetColumnCount(isRow) - grid->GetExtraColumnCount(isRow);
|
||||
for (PRInt32 i=0; i < extraColumns; i++)
|
||||
{
|
||||
nsGridRow* column = grid->GetColumnAt(i+start, isRow);
|
||||
nscoord size = 0;
|
||||
grid->GetMinRowHeight(aState, i+start, size, !isRow); // GetMinColumnWidth
|
||||
|
||||
AddWidth(aSize, size, isRow);
|
||||
}
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGridRowGroupLayout::Layout(nsIBox* aBox, nsBoxLayoutState& aBoxLayoutState)
|
||||
{
|
||||
return nsGridRowLayout::Layout(aBox, aBoxLayoutState);
|
||||
}
|
||||
|
||||
nsIBox*
|
||||
nsGridRowGroupLayout::CheckForScrollFrame(nsIBox* aChild)
|
||||
{
|
||||
// first see if it is a scrollframe. If so walk down into it and get the scrolled child
|
||||
nsCOMPtr<nsIScrollableFrame> scrollFrame = do_QueryInterface(aChild);
|
||||
if (scrollFrame) {
|
||||
nsIFrame* scrolledFrame = nsnull;
|
||||
scrollFrame->GetScrolledFrame(nsnull, scrolledFrame);
|
||||
NS_ASSERTION(scrolledFrame,"Error no scroll frame!!");
|
||||
nsCOMPtr<nsIBox> box = do_QueryInterface(scrolledFrame);
|
||||
return box;
|
||||
}
|
||||
|
||||
return aChild;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGridRowGroupLayout::DirtyRows(nsIBox* aBox, nsBoxLayoutState& aState)
|
||||
{
|
||||
if (aBox) {
|
||||
// mark us dirty
|
||||
aBox->MarkDirty(aState);
|
||||
nsIBox* child = nsnull;
|
||||
aBox->GetChildBox(&child);
|
||||
nsIBox* deepChild = child;
|
||||
PRInt32 rowCount = 0;
|
||||
|
||||
while(child) {
|
||||
|
||||
// walk into scrollframes
|
||||
deepChild = CheckForScrollFrame(child);
|
||||
|
||||
// walk into other monuments
|
||||
nsCOMPtr<nsIBoxLayout> layout;
|
||||
deepChild->GetLayoutManager(getter_AddRefs(layout));
|
||||
if (layout) {
|
||||
nsCOMPtr<nsIGridPart> monument( do_QueryInterface(layout) );
|
||||
if (monument)
|
||||
monument->DirtyRows(deepChild, aState);
|
||||
}
|
||||
|
||||
child->GetNextBox(&child);
|
||||
deepChild = child;
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGridRowGroupLayout::CountRowsColumns(nsIBox* aBox, PRInt32& aRowCount, PRInt32& aComputedColumnCount)
|
||||
{
|
||||
if (aBox) {
|
||||
nsIBox* child = nsnull;
|
||||
aBox->GetChildBox(&child);
|
||||
nsIBox* deepChild = child;
|
||||
PRInt32 rowCount = 0;
|
||||
|
||||
while(child) {
|
||||
|
||||
// first see if it is a scrollframe. If so walk down into it and get the scrolled child
|
||||
deepChild = CheckForScrollFrame(child);
|
||||
|
||||
nsCOMPtr<nsIBoxLayout> layout;
|
||||
deepChild->GetLayoutManager(getter_AddRefs(layout));
|
||||
if (layout) {
|
||||
nsCOMPtr<nsIGridPart> monument( do_QueryInterface(layout) );
|
||||
if (monument) {
|
||||
monument->CountRowsColumns(deepChild, aRowCount, aComputedColumnCount);
|
||||
child->GetNextBox(&child);
|
||||
deepChild = child;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
child->GetNextBox(&child);
|
||||
deepChild = child;
|
||||
|
||||
// if not a monument. Then count it. It will be a bogus row
|
||||
aRowCount++;
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGridRowGroupLayout::BuildRows(nsIBox* aBox, nsGridRow* aRows, PRInt32* aCount)
|
||||
{
|
||||
PRInt32 rowCount = 0;
|
||||
|
||||
if (aBox) {
|
||||
nsIBox* child = nsnull;
|
||||
aBox->GetChildBox(&child);
|
||||
nsIBox* deepChild = child;
|
||||
|
||||
while(child) {
|
||||
|
||||
// first see if it is a scrollframe. If so walk down into it and get the scrolled child
|
||||
deepChild = CheckForScrollFrame(child);
|
||||
|
||||
nsCOMPtr<nsIBoxLayout> layout;
|
||||
deepChild->GetLayoutManager(getter_AddRefs(layout));
|
||||
if (layout) {
|
||||
nsCOMPtr<nsIGridPart> monument( do_QueryInterface(layout) );
|
||||
if (monument) {
|
||||
PRInt32 count = 0;
|
||||
monument->BuildRows(deepChild, &aRows[rowCount], &count);
|
||||
rowCount += count;
|
||||
child->GetNextBox(&child);
|
||||
deepChild = child;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
aRows[rowCount].Init(child, PR_TRUE);
|
||||
|
||||
child->GetNextBox(&child);
|
||||
deepChild = child;
|
||||
|
||||
// if not a monument. Then count it. It will be a bogus row
|
||||
rowCount++;
|
||||
}
|
||||
}
|
||||
|
||||
*aCount = rowCount;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGridRowGroupLayout::CastToRowGroupLayout(nsGridRowGroupLayout** aRowGroup)
|
||||
{
|
||||
(*aRowGroup) = this;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,78 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.1 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Mozilla Communicator client code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
/**
|
||||
|
||||
Author:
|
||||
Eric D Vaughan
|
||||
|
||||
**/
|
||||
|
||||
#ifndef nsGridRowGroupLayout_h___
|
||||
#define nsGridRowGroupLayout_h___
|
||||
|
||||
#include "nsGridRowLayout.h"
|
||||
|
||||
class nsGridRowGroupLayout : public nsGridRowLayout
|
||||
{
|
||||
public:
|
||||
|
||||
friend nsresult NS_NewGridRowGroupLayout(nsIPresShell* aPresShell, nsIBoxLayout** aNewLayout);
|
||||
|
||||
NS_IMETHOD CastToRowGroupLayout(nsGridRowGroupLayout** aRowGroup);
|
||||
NS_IMETHOD GetMinSize(nsIBox* aBox, nsBoxLayoutState& aBoxLayoutState, nsSize& aSize);
|
||||
NS_IMETHOD GetPrefSize(nsIBox* aBox, nsBoxLayoutState& aBoxLayoutState, nsSize& aSize);
|
||||
NS_IMETHOD GetMaxSize(nsIBox* aBox, nsBoxLayoutState& aBoxLayoutState, nsSize& aSize);
|
||||
NS_IMETHOD Layout(nsIBox* aBox, nsBoxLayoutState& aBoxLayoutState);
|
||||
NS_IMETHOD CountRowsColumns(nsIBox* aBox, PRInt32& aRowCount, PRInt32& aComputedColumnCount);
|
||||
NS_IMETHOD DirtyRows(nsIBox* aBox, nsBoxLayoutState& aState);
|
||||
NS_IMETHOD BuildRows(nsIBox* aBox, nsGridRow* aRows, PRInt32* aCount);
|
||||
|
||||
protected:
|
||||
nsGridRowGroupLayout(nsIPresShell* aShell);
|
||||
virtual ~nsGridRowGroupLayout();
|
||||
|
||||
NS_IMETHOD ChildAddedOrRemoved(nsIBox* aBox, nsBoxLayoutState& aState);
|
||||
virtual nsIBox* CheckForScrollFrame(nsIBox* aChild);
|
||||
virtual void AddWidth(nsSize& aSize, nscoord aSize2, PRBool aIsRow);
|
||||
|
||||
private:
|
||||
nsGridRow* mRowColumn;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,202 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.1 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Mozilla Communicator client code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
//
|
||||
// Eric Vaughan
|
||||
// Netscape Communications
|
||||
//
|
||||
// See documentation in associated header file
|
||||
//
|
||||
|
||||
#include "nsGridRowLayout.h"
|
||||
#include "nsBoxLayoutState.h"
|
||||
#include "nsIBox.h"
|
||||
#include "nsIScrollableFrame.h"
|
||||
#include "nsBox.h"
|
||||
#include "nsStackLayout.h"
|
||||
|
||||
nsGridRowLayout::nsGridRowLayout(nsIPresShell* aPresShell):nsSprocketLayout()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGridRowLayout::ChildrenInserted(nsIBox* aBox, nsBoxLayoutState& aState, nsIBox* aPrevBox, nsIBox* aChildList)
|
||||
{
|
||||
return ChildAddedOrRemoved(aBox, aState);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGridRowLayout::ChildrenAppended(nsIBox* aBox, nsBoxLayoutState& aState, nsIBox* aChildList)
|
||||
{
|
||||
return ChildAddedOrRemoved(aBox, aState);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGridRowLayout::ChildrenRemoved(nsIBox* aBox, nsBoxLayoutState& aState, nsIBox* aChildList)
|
||||
{
|
||||
return ChildAddedOrRemoved(aBox, aState);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGridRowLayout::ChildrenSet(nsIBox* aBox, nsBoxLayoutState& aState, nsIBox* aChildList)
|
||||
{
|
||||
return ChildAddedOrRemoved(aBox, aState);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGridRowLayout::GetParentGridPart(nsIBox* aBox, nsCOMPtr<nsIBox>& aParentBox, nsIGridPart** aParentGridPart)
|
||||
{
|
||||
// go up and find our parent gridRow. Skip and non gridRow
|
||||
// parents.
|
||||
nsCOMPtr<nsIBoxLayout> layout;
|
||||
nsCOMPtr<nsIGridPart> parentGridRow;
|
||||
nsresult rv = NS_OK;
|
||||
*aParentGridPart = nsnull;
|
||||
aBox->GetParentBox(&aBox);
|
||||
|
||||
while (aBox) {
|
||||
aBox->GetLayoutManager(getter_AddRefs(layout));
|
||||
parentGridRow = do_QueryInterface(layout, &rv);
|
||||
if (NS_SUCCEEDED(rv) && parentGridRow) {
|
||||
aParentBox = aBox;
|
||||
*aParentGridPart = parentGridRow.get();
|
||||
NS_IF_ADDREF(*aParentGridPart);
|
||||
return rv;
|
||||
}
|
||||
aBox->GetParentBox(&aBox);
|
||||
}
|
||||
|
||||
aParentBox = nsnull;
|
||||
*aParentGridPart = nsnull;
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGridRowLayout::GetGrid(nsIBox* aBox, nsGrid** aList, PRInt32* aIndex, nsGridRowLayout* aRequestor)
|
||||
{
|
||||
|
||||
if (aRequestor == nsnull)
|
||||
{
|
||||
nsCOMPtr<nsIGridPart> parent;
|
||||
nsCOMPtr<nsIBox> parentBox;
|
||||
GetParentGridPart(aBox, parentBox, getter_AddRefs(parent));
|
||||
if (parent)
|
||||
return parent->GetGrid(parentBox, aList, aIndex, this);
|
||||
else
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
PRInt32 index = -1;
|
||||
nsIBox* child = nsnull;
|
||||
aBox->GetChildBox(&child);
|
||||
PRInt32 count = 0;
|
||||
while(child)
|
||||
{
|
||||
// if there is a scrollframe walk inside it to its child
|
||||
nsCOMPtr<nsIBox> childBox = child;
|
||||
nsCOMPtr<nsIScrollableFrame> scrollFrame = do_QueryInterface(child, &rv);
|
||||
if (scrollFrame) {
|
||||
nsIFrame* childFrame = nsnull;
|
||||
scrollFrame->GetScrolledFrame(nsnull, childFrame);
|
||||
if (!childFrame)
|
||||
return NS_ERROR_FAILURE;
|
||||
childBox = do_QueryInterface(childFrame);
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIBoxLayout> layout;
|
||||
childBox->GetLayoutManager(getter_AddRefs(layout));
|
||||
|
||||
// find our requester
|
||||
nsCOMPtr<nsIGridPart> gridRow = do_QueryInterface(layout, &rv);
|
||||
if (NS_SUCCEEDED(rv) && gridRow)
|
||||
{
|
||||
if (layout == aRequestor) {
|
||||
index = count;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// add the index.
|
||||
count++;
|
||||
child->GetNextBox(&child);
|
||||
}
|
||||
|
||||
// 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) {
|
||||
*aList = nsnull;
|
||||
*aIndex = -1;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
(*aIndex) += index;
|
||||
|
||||
nsCOMPtr<nsIGridPart> parent;
|
||||
nsCOMPtr<nsIBox> parentBox;
|
||||
GetParentGridPart(aBox, parentBox, getter_AddRefs(parent));
|
||||
|
||||
if (parent)
|
||||
parent->GetGrid(parentBox, aList, aIndex, this);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGridRowLayout::CastToRowGroupLayout(nsGridRowGroupLayout** aRowGroup)
|
||||
{
|
||||
(*aRowGroup) = nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGridRowLayout::CastToGridLayout(nsGridLayout2** aGridLayout)
|
||||
{
|
||||
(*aGridLayout) = nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
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)
|
|
@ -0,0 +1,78 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.1 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Mozilla Communicator client code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
/**
|
||||
|
||||
Author:
|
||||
Eric D Vaughan
|
||||
|
||||
**/
|
||||
|
||||
#ifndef nsGridRowLayout_h___
|
||||
#define nsGridRowLayout_h___
|
||||
|
||||
#include "nsSprocketLayout.h"
|
||||
#include "nsIGridPart.h"
|
||||
class nsGridRowGroupLayout;
|
||||
class nsGridLayout2;
|
||||
class nsBoxLayoutState;
|
||||
class nsIPresShell;
|
||||
class nsGrid;
|
||||
|
||||
class nsGridRowLayout : public nsSprocketLayout,
|
||||
public nsIGridPart
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
|
||||
NS_IMETHOD CastToRowGroupLayout(nsGridRowGroupLayout** aRowGroup);
|
||||
NS_IMETHOD CastToGridLayout(nsGridLayout2** aGrid);
|
||||
NS_IMETHOD GetGrid(nsIBox* aBox, nsGrid** aList, PRInt32* aIndex, nsGridRowLayout* aRequestor=nsnull);
|
||||
NS_IMETHOD GetParentGridPart(nsIBox* aBox, nsCOMPtr<nsIBox>& aParentBox, nsIGridPart** aParentGridRow);
|
||||
NS_IMETHOD ChildrenInserted(nsIBox* aBox, nsBoxLayoutState& aState, nsIBox* aPrevBox, nsIBox* aChildList);
|
||||
NS_IMETHOD ChildrenAppended(nsIBox* aBox, nsBoxLayoutState& aState, nsIBox* aChildList);
|
||||
NS_IMETHOD ChildrenRemoved(nsIBox* aBox, nsBoxLayoutState& aState, nsIBox* aChildList);
|
||||
NS_IMETHOD ChildrenSet(nsIBox* aBox, nsBoxLayoutState& aState, nsIBox* aChildList);
|
||||
|
||||
protected:
|
||||
NS_IMETHOD ChildAddedOrRemoved(nsIBox* aBox, nsBoxLayoutState& aState)=0;
|
||||
|
||||
nsGridRowLayout(nsIPresShell* aShell);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,378 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.1 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Mozilla Communicator client code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
//
|
||||
// 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"
|
||||
|
||||
nsresult
|
||||
NS_NewGridRowLeafLayout( nsIPresShell* aPresShell, nsIBoxLayout** aNewLayout)
|
||||
{
|
||||
*aNewLayout = new nsGridRowLeafLayout(aPresShell);
|
||||
NS_IF_ADDREF(*aNewLayout);
|
||||
|
||||
return NS_OK;
|
||||
|
||||
}
|
||||
|
||||
nsGridRowLeafLayout::nsGridRowLeafLayout(nsIPresShell* aPresShell):nsGridRowLayout(aPresShell)
|
||||
{
|
||||
}
|
||||
|
||||
nsGridRowLeafLayout::~nsGridRowLeafLayout()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGridRowLeafLayout::CastToGridRowLeaf(nsGridRowLeafLayout** aGridRowLeaf)
|
||||
{
|
||||
*aGridRowLeaf = this;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGridRowLeafLayout::GetPrefSize(nsIBox* aBox, nsBoxLayoutState& aState, nsSize& aSize)
|
||||
{
|
||||
nsGrid* grid = nsnull;
|
||||
PRInt32 index = 0;
|
||||
GetGrid(aBox, &grid, &index);
|
||||
PRInt32 isRow = IsHorizontal(aBox);
|
||||
|
||||
if (!grid)
|
||||
return nsGridRowLayout::GetPrefSize(aBox, aState, aSize);
|
||||
else {
|
||||
nsresult rv = grid->GetPrefRowSize(aState, index, aSize, isRow);
|
||||
AddBorderAndPadding(aBox, aSize);
|
||||
AddInset(aBox, aSize);
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGridRowLeafLayout::GetMinSize(nsIBox* aBox, nsBoxLayoutState& aState, nsSize& aSize)
|
||||
{
|
||||
nsGrid* grid = nsnull;
|
||||
PRInt32 index = 0;
|
||||
GetGrid(aBox, &grid, &index);
|
||||
PRInt32 isRow = IsHorizontal(aBox);
|
||||
|
||||
if (!grid)
|
||||
return nsGridRowLayout::GetMinSize(aBox, aState, aSize);
|
||||
else {
|
||||
nsresult rv = grid->GetMinRowSize(aState, index, aSize, isRow);
|
||||
AddBorderAndPadding(aBox, aSize);
|
||||
AddInset(aBox, aSize);
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGridRowLeafLayout::GetMaxSize(nsIBox* aBox, nsBoxLayoutState& aState, nsSize& aSize)
|
||||
{
|
||||
nsGrid* grid = nsnull;
|
||||
PRInt32 index = 0;
|
||||
GetGrid(aBox, &grid, &index);
|
||||
PRInt32 isRow = IsHorizontal(aBox);
|
||||
|
||||
if (!grid)
|
||||
return nsGridRowLayout::GetMaxSize(aBox, aState, aSize);
|
||||
else {
|
||||
nsresult rv = grid->GetMaxRowSize(aState, index, aSize, isRow);
|
||||
AddBorderAndPadding(aBox, aSize);
|
||||
AddInset(aBox, aSize);
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGridRowLeafLayout::ChildBecameDirty(nsIBox* aBox, nsBoxLayoutState& aState, nsIBox* aChild)
|
||||
{
|
||||
nsGrid* grid = nsnull;
|
||||
PRInt32 index = 0;
|
||||
GetGrid(aBox, &grid, &index);
|
||||
PRInt32 isRow = IsHorizontal(aBox);
|
||||
|
||||
if (grid) {
|
||||
PRInt32 columnIndex = -1;
|
||||
aBox->GetIndexOf(aChild, &columnIndex);
|
||||
grid->RowChildIsDirty(aState, index, columnIndex, isRow);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGridRowLeafLayout::BecameDirty(nsIBox* aBox, nsBoxLayoutState& aState)
|
||||
{
|
||||
nsGrid* grid = nsnull;
|
||||
PRInt32 index = 0;
|
||||
GetGrid(aBox, &grid, &index);
|
||||
PRInt32 isRow = IsHorizontal(aBox);
|
||||
|
||||
if (grid)
|
||||
grid->RowIsDirty(aState, index, isRow);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/** If a child is added or removed or changes size
|
||||
*/
|
||||
NS_IMETHODIMP
|
||||
nsGridRowLeafLayout::ChildAddedOrRemoved(nsIBox* aBox, nsBoxLayoutState& aState)
|
||||
{
|
||||
nsGrid* grid = nsnull;
|
||||
PRInt32 index = 0;
|
||||
GetGrid(aBox, &grid, &index);
|
||||
PRInt32 isRow = IsHorizontal(aBox);
|
||||
|
||||
if (grid)
|
||||
grid->CellAddedOrRemoved(aState, index, isRow);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
nsGridRowLeafLayout::PopulateBoxSizes(nsIBox* aBox, nsBoxLayoutState& aState, nsBoxSize*& aBoxSizes, nsComputedBoxSize*& aComputedBoxSizes, nscoord& aMinSize, nscoord& aMaxSize, PRInt32& aFlexes)
|
||||
{
|
||||
nsGrid* grid = nsnull;
|
||||
PRInt32 index = 0;
|
||||
GetGrid(aBox, &grid, &index);
|
||||
PRInt32 isRow = IsHorizontal(aBox);
|
||||
|
||||
// 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) {
|
||||
nsGridRow* column;
|
||||
PRInt32 count = grid->GetColumnCount(isRow);
|
||||
nsBoxSize* start = nsnull;
|
||||
nsBoxSize* last = nsnull;
|
||||
nsBoxSize* current = nsnull;
|
||||
nsIBox* child = nsnull;
|
||||
aBox->GetChildBox(&child);
|
||||
for (int i=0; i < count; i++)
|
||||
{
|
||||
column = grid->GetColumnAt(i,isRow);
|
||||
|
||||
// make sure the value was computed before we use it.
|
||||
nscoord pref = 0;
|
||||
nscoord min = 0;
|
||||
nscoord max = 0;
|
||||
nscoord flex = 0;
|
||||
|
||||
// !isRow is passed in to invert the behavor of these methods.
|
||||
grid->GetPrefRowHeight(aState, i, pref, !isRow); // GetPrefColumnWidth
|
||||
grid->GetMinRowHeight(aState, i, min, !isRow); // GetMinColumnWidth
|
||||
grid->GetMaxRowHeight(aState, i, max, !isRow); // GetMaxColumnWidth
|
||||
grid->GetRowFlex(aState, i, flex, !isRow); // GetColumnFlex
|
||||
|
||||
current = new (aState) nsBoxSize();
|
||||
|
||||
// initialize the box size here
|
||||
nsBox::BoundsCheck(min, pref, max);
|
||||
|
||||
current->pref = pref;
|
||||
current->min = min;
|
||||
current->max = max;
|
||||
current->flex = flex;
|
||||
current->bogus = column->mIsBogus;
|
||||
|
||||
|
||||
if (!start) {
|
||||
start = current;
|
||||
last = start;
|
||||
} else {
|
||||
last->next = current;
|
||||
last = current;
|
||||
}
|
||||
|
||||
}
|
||||
aBoxSizes = start;
|
||||
}
|
||||
|
||||
nsSprocketLayout::PopulateBoxSizes(aBox, aState, aBoxSizes, aComputedBoxSizes, aMinSize, aMaxSize, aFlexes);
|
||||
}
|
||||
|
||||
void
|
||||
nsGridRowLeafLayout::ComputeChildSizes(nsIBox* aBox,
|
||||
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) {
|
||||
|
||||
// go up the parent chain looking for scrollframes
|
||||
PRBool isRow = PR_FALSE;
|
||||
aBox->GetOrientation(isRow);
|
||||
|
||||
aBox->GetParentBox(&aBox);
|
||||
|
||||
while (aBox)
|
||||
{
|
||||
|
||||
nsCOMPtr<nsIScrollableFrame> scrollable = do_QueryInterface(aBox);
|
||||
if (scrollable) {
|
||||
|
||||
// get the clip rect and compare its size to the scrollframe.
|
||||
// we just need to subtract out the difference.
|
||||
nsSize clipSize(0,0);
|
||||
scrollable->GetClipSize(nsnull, &clipSize.width, &clipSize.height);
|
||||
|
||||
nscoord diff = 0;
|
||||
|
||||
nsRect ourRect;
|
||||
aBox->GetBounds(ourRect);
|
||||
|
||||
if (isRow) {
|
||||
diff = ourRect.width - clipSize.width;
|
||||
} else {
|
||||
diff = ourRect.height - clipSize.height;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
if (last)
|
||||
last->size -= diff;
|
||||
}
|
||||
} else {
|
||||
nsCOMPtr<nsIBoxLayout> layout;
|
||||
aBox->GetLayoutManager(getter_AddRefs(layout));
|
||||
nsCOMPtr<nsIGridPart> part = do_QueryInterface(layout);
|
||||
if (part) {
|
||||
nsGridLayout2* gridLayout = nsnull;
|
||||
part->CastToGridLayout(&gridLayout);
|
||||
|
||||
if (gridLayout)
|
||||
{
|
||||
nsSprocketLayout::ComputeChildSizes(aBox, aState, aGivenSize, aBoxSizes, aComputedBoxSizes);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
aBox->GetParentBox(&aBox);
|
||||
}
|
||||
}
|
||||
|
||||
nsSprocketLayout::ComputeChildSizes(aBox, aState, aGivenSize, aBoxSizes, aComputedBoxSizes);
|
||||
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGridRowLeafLayout::Layout(nsIBox* aBox, nsBoxLayoutState& aBoxLayoutState)
|
||||
{
|
||||
return nsGridRowLayout::Layout(aBox, aBoxLayoutState);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGridRowLeafLayout::DirtyRows(nsIBox* aBox, nsBoxLayoutState& aState)
|
||||
{
|
||||
if (aBox) {
|
||||
// mark us dirty
|
||||
aBox->MarkDirty(aState);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGridRowLeafLayout::CountRowsColumns(nsIBox* aBox, PRInt32& aRowCount, PRInt32& aComputedColumnCount)
|
||||
{
|
||||
if (aBox) {
|
||||
nsIBox* child = nsnull;
|
||||
aBox->GetChildBox(&child);
|
||||
|
||||
// count the children
|
||||
PRInt32 columnCount = 0;
|
||||
while(child) {
|
||||
child->GetNextBox(&child);
|
||||
columnCount++;
|
||||
}
|
||||
|
||||
// if our count is greater than the current column count
|
||||
if (columnCount > aComputedColumnCount)
|
||||
aComputedColumnCount = columnCount;
|
||||
|
||||
aRowCount++;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGridRowLeafLayout::BuildRows(nsIBox* aBox, nsGridRow* aRows, PRInt32* aCount)
|
||||
{
|
||||
if (aBox) {
|
||||
aRows[0].Init(aBox, PR_FALSE);
|
||||
*aCount = 1;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
*aCount = 0;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,87 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.1 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Mozilla Communicator client code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
/**
|
||||
|
||||
Author:
|
||||
Eric D Vaughan
|
||||
|
||||
**/
|
||||
|
||||
#ifndef nsGridRowLeafLayout_h___
|
||||
#define nsGridRowLeafLayout_h___
|
||||
|
||||
#include "nsGridRowLayout.h"
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
class nsGridRowLeafLayout : public nsGridRowLayout
|
||||
{
|
||||
public:
|
||||
|
||||
friend nsresult NS_NewGridRowLeafLayout(nsIPresShell* aPresShell, nsIBoxLayout** aNewLayout);
|
||||
|
||||
NS_IMETHOD GetPrefSize(nsIBox* aBox, nsBoxLayoutState& aBoxLayoutState, nsSize& aSize);
|
||||
NS_IMETHOD GetMinSize(nsIBox* aBox, nsBoxLayoutState& aBoxLayoutState, nsSize& aSize);
|
||||
NS_IMETHOD GetMaxSize(nsIBox* aBox, nsBoxLayoutState& aBoxLayoutState, nsSize& aSize);
|
||||
NS_IMETHOD CastToGridRowLeaf(nsGridRowLeafLayout** aGridRowLeaf);
|
||||
NS_IMETHOD ChildBecameDirty(nsIBox* aBox, nsBoxLayoutState& aState, nsIBox* aChild);
|
||||
NS_IMETHOD BecameDirty(nsIBox* aBox, nsBoxLayoutState& aState);
|
||||
NS_IMETHOD ChildAddedOrRemoved(nsIBox* aBox, nsBoxLayoutState& aState);
|
||||
NS_IMETHOD Layout(nsIBox* aBox, nsBoxLayoutState& aBoxLayoutState);
|
||||
NS_IMETHOD CountRowsColumns(nsIBox* aBox, PRInt32& aRowCount, PRInt32& aComputedColumnCount);
|
||||
NS_IMETHOD DirtyRows(nsIBox* aBox, nsBoxLayoutState& aState);
|
||||
NS_IMETHOD BuildRows(nsIBox* aBox, nsGridRow* aRows, PRInt32* aCount);
|
||||
|
||||
protected:
|
||||
|
||||
virtual void PopulateBoxSizes(nsIBox* aBox, nsBoxLayoutState& aBoxLayoutState, nsBoxSize*& aBoxSizes, nsComputedBoxSize*& aComputedBoxSizes, nscoord& aMinSize, nscoord& aMaxSize, PRInt32& aFlexes);
|
||||
virtual void ComputeChildSizes(nsIBox* aBox,
|
||||
nsBoxLayoutState& aState,
|
||||
nscoord& aGivenSize,
|
||||
nsBoxSize* aBoxSizes,
|
||||
nsComputedBoxSize*& aComputedBoxSizes);
|
||||
|
||||
|
||||
nsGridRowLeafLayout(nsIPresShell* aShell);
|
||||
virtual ~nsGridRowLeafLayout();
|
||||
|
||||
private:
|
||||
|
||||
}; // class nsGridRowLeafLayout
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,71 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.1 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Mozilla Communicator client code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef nsIGridPart_h___
|
||||
#define nsIGridPart_h___
|
||||
|
||||
#include "nsISupports.h"
|
||||
#include "nsFrame.h"
|
||||
#include "nsIBox.h"
|
||||
|
||||
class nsGridRowGroupLayout;
|
||||
class nsGrid;
|
||||
class nsGridRowLayout;
|
||||
class nsGridRow;
|
||||
class nsGridLayout2;
|
||||
|
||||
|
||||
// {AF0C1603-06C3-11d4-BA07-001083023C1E}
|
||||
#define NS_IMONUMENT_IID { 0xaf0c1603, 0x6c3, 0x11d4, { 0xba, 0x7, 0x0, 0x10, 0x83, 0x2, 0x3c, 0x1e } };
|
||||
|
||||
class nsIGridPart : public nsISupports {
|
||||
|
||||
public:
|
||||
|
||||
static const nsIID& GetIID() { static nsIID iid = NS_IMONUMENT_IID; return iid; }
|
||||
|
||||
NS_IMETHOD CastToRowGroupLayout(nsGridRowGroupLayout** aRowGroup)=0;
|
||||
NS_IMETHOD CastToGridLayout(nsGridLayout2** aGrid)=0;
|
||||
NS_IMETHOD GetGrid(nsIBox* aBox, nsGrid** aList, PRInt32* aIndex, nsGridRowLayout* aRequestor=nsnull)=0;
|
||||
NS_IMETHOD GetParentGridPart(nsIBox* aBox, nsCOMPtr<nsIBox>& aParentBox, nsIGridPart** aParentGridRow)=0;
|
||||
NS_IMETHOD CountRowsColumns(nsIBox* aBox, PRInt32& aRowCount, PRInt32& aComputedColumnCount)=0;
|
||||
NS_IMETHOD DirtyRows(nsIBox* aBox, nsBoxLayoutState& aState)=0;
|
||||
NS_IMETHOD BuildRows(nsIBox* aBox, nsGridRow* aRows, PRInt32* aCount)=0;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Загрузка…
Ссылка в новой задаче