Back to index

lightning-sunbird  0.9+nobinonly
nsGridLayout2.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is Mozilla Communicator client code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either of the GNU General Public License Version 2 or later (the "GPL"),
00026  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 //
00039 // Eric Vaughan
00040 // Netscape Communications
00041 //
00042 // See documentation in associated header file
00043 //
00044 
00045 #include "nsGridLayout2.h"
00046 #include "nsGridRowGroupLayout.h"
00047 #include "nsBox.h"
00048 #include "nsIScrollableFrame.h"
00049 #include "nsSprocketLayout.h"
00050 
00051 nsresult
00052 NS_NewGridLayout2( nsIPresShell* aPresShell, nsIBoxLayout** aNewLayout)
00053 {
00054   *aNewLayout = new nsGridLayout2(aPresShell);
00055   NS_IF_ADDREF(*aNewLayout);
00056 
00057   return NS_OK;
00058   
00059 } 
00060 
00061 nsGridLayout2::nsGridLayout2(nsIPresShell* aPresShell):nsStackLayout()
00062 {
00063 }
00064 
00065 NS_IMETHODIMP
00066 nsGridLayout2::Layout(nsIBox* aBox, nsBoxLayoutState& aBoxLayoutState)
00067 {
00068   mGrid.SetBox(aBox);
00069   nsresult rv = nsStackLayout::Layout(aBox, aBoxLayoutState);
00070 #ifdef DEBUG_grid
00071   mGrid.PrintCellMap();
00072 #endif
00073   return rv;
00074 }
00075 
00076 NS_IMETHODIMP
00077 nsGridLayout2::GetGrid(nsIBox* aBox, nsGrid** aGrid, PRInt32* aIndex, nsGridRowLayout* aRequestor)
00078 {
00079   mGrid.SetBox(aBox);
00080   *aGrid = &mGrid;
00081   return NS_OK;
00082 }
00083 
00084 NS_IMETHODIMP
00085 nsGridLayout2::GetParentGridPart(nsIBox* aBox, nsIBox** aParentBox, nsIGridPart** aParentGridRow)
00086 {
00087   NS_ERROR("Should not be called");
00088   return NS_ERROR_FAILURE;
00089 }
00090 
00091 void
00092 nsGridLayout2::AddWidth(nsSize& aSize, nscoord aSize2, PRBool aIsHorizontal)
00093 {
00094   nscoord& size = GET_WIDTH(aSize, aIsHorizontal);
00095 
00096   if (size != NS_INTRINSICSIZE) {
00097     if (aSize2 == NS_INTRINSICSIZE)
00098       size = NS_INTRINSICSIZE;
00099     else
00100       size += aSize2;
00101   }
00102 }
00103 
00104 NS_IMETHODIMP
00105 nsGridLayout2::GetMinSize(nsIBox* aBox, nsBoxLayoutState& aState, nsSize& aSize)
00106 {
00107   nsresult rv = nsStackLayout::GetMinSize(aBox, aState, aSize); 
00108   if (NS_FAILED(rv))
00109     return rv;
00110 
00111   // if there are no <rows> tags that will sum up our columns,
00112   // sum up our columns here.
00113   nsSize total(0,0);
00114   nsIBox* rowBox = mGrid.GetRowBox();
00115   nsIBox* columnBox = mGrid.GetColumnBox();
00116   if (!rowBox || !columnBox) {
00117     if (!rowBox) {
00118       // max height is the sum of our rows
00119       PRInt32 rows = mGrid.GetRowCount();
00120       for (PRInt32 i=0; i < rows; i++)
00121       {
00122         nscoord size = 0;
00123         mGrid.GetMinRowHeight(aState, i, size, PR_TRUE); 
00124         AddWidth(total, size, PR_FALSE); // AddHeight
00125       }
00126     }
00127 
00128     if (!columnBox) {
00129       // max height is the sum of our rows
00130       PRInt32 columns = mGrid.GetColumnCount();
00131       for (PRInt32 i=0; i < columns; i++)
00132       {
00133         nscoord size = 0;
00134         mGrid.GetMinRowHeight(aState, i, size, PR_FALSE); // GetPrefRowWidth
00135         AddWidth(total, size, PR_TRUE); // AddWidth
00136       }
00137     }
00138 
00139     AddMargin(aBox, total);
00140     AddOffset(aState, aBox, total);
00141     AddLargestSize(aSize, total);
00142   }
00143   
00144   return rv;
00145 }
00146 
00147 NS_IMETHODIMP
00148 nsGridLayout2::GetPrefSize(nsIBox* aBox, nsBoxLayoutState& aState, nsSize& aSize)
00149 {
00150   nsresult rv = nsStackLayout::GetPrefSize(aBox, aState, aSize); 
00151   if (NS_FAILED(rv))
00152     return rv;
00153 
00154   // if there are no <rows> tags that will sum up our columns,
00155   // sum up our columns here.
00156   nsSize total(0,0);
00157   nsIBox* rowBox = mGrid.GetRowBox();
00158   nsIBox* columnBox = mGrid.GetColumnBox();
00159   if (!rowBox || !columnBox) {
00160     if (!rowBox) {
00161       // max height is the sum of our rows
00162       PRInt32 rows = mGrid.GetRowCount();
00163       for (PRInt32 i=0; i < rows; i++)
00164       {
00165         nscoord size = 0;
00166         mGrid.GetPrefRowHeight(aState, i, size, PR_TRUE); 
00167         AddWidth(total, size, PR_FALSE); // AddHeight
00168       }
00169     }
00170 
00171     if (!columnBox) {
00172       // max height is the sum of our rows
00173       PRInt32 columns = mGrid.GetColumnCount();
00174       for (PRInt32 i=0; i < columns; i++)
00175       {
00176         nscoord size = 0;
00177         mGrid.GetPrefRowHeight(aState, i, size, PR_FALSE); // GetPrefRowWidth
00178         AddWidth(total, size, PR_TRUE); // AddWidth
00179       }
00180     }
00181 
00182     AddMargin(aBox, total);
00183     AddOffset(aState, aBox, total);
00184     AddLargestSize(aSize, total);
00185   }
00186 
00187   return rv;
00188 }
00189 
00190 NS_IMETHODIMP
00191 nsGridLayout2::GetMaxSize(nsIBox* aBox, nsBoxLayoutState& aState, nsSize& aSize)
00192 {
00193   nsresult rv = nsStackLayout::GetMaxSize(aBox, aState, aSize); 
00194    if (NS_FAILED(rv))
00195     return rv;
00196 
00197   // if there are no <rows> tags that will sum up our columns,
00198   // sum up our columns here.
00199   nsSize total(NS_INTRINSICSIZE, NS_INTRINSICSIZE);
00200   nsIBox* rowBox = mGrid.GetRowBox();
00201   nsIBox* columnBox = mGrid.GetColumnBox();
00202   if (!rowBox || !columnBox) {
00203     if (!rowBox) {
00204       total.height = 0;
00205       // max height is the sum of our rows
00206       PRInt32 rows = mGrid.GetRowCount();
00207       for (PRInt32 i=0; i < rows; i++)
00208       {
00209         nscoord size = 0;
00210         mGrid.GetMaxRowHeight(aState, i, size, PR_TRUE); 
00211         AddWidth(total, size, PR_FALSE); // AddHeight
00212       }
00213     }
00214 
00215     if (!columnBox) {
00216       total.width = 0;
00217       // max height is the sum of our rows
00218       PRInt32 columns = mGrid.GetColumnCount();
00219       for (PRInt32 i=0; i < columns; i++)
00220       {
00221         nscoord size = 0;
00222         mGrid.GetMaxRowHeight(aState, i, size, PR_FALSE); // GetPrefRowWidth
00223         AddWidth(total, size, PR_TRUE); // AddWidth
00224       }
00225     }
00226 
00227     AddMargin(aBox, total);
00228     AddOffset(aState, aBox, total);
00229     AddSmallestSize(aSize, total);
00230   }
00231 
00232   return rv;
00233 }
00234 
00235 NS_IMETHODIMP
00236 nsGridLayout2::CountRowsColumns(nsIBox* aRowBox, PRInt32& aRowCount, PRInt32& aComputedColumnCount)
00237 {
00238   NS_ERROR("Should not be called");
00239   return NS_ERROR_FAILURE;
00240 }
00241 
00242 NS_IMETHODIMP
00243 nsGridLayout2::DirtyRows(nsIBox* aBox, nsBoxLayoutState& aState)
00244 {
00245   NS_ERROR("Should not be called");
00246   return NS_ERROR_FAILURE;
00247 }
00248 
00249 NS_IMETHODIMP
00250 nsGridLayout2::BuildRows(nsIBox* aBox, nsGridRow* aRows, PRInt32* aCount)
00251 {
00252   NS_ERROR("Should not be called");
00253   return NS_ERROR_FAILURE;
00254 }
00255 
00256 NS_IMETHODIMP
00257 nsGridLayout2::CastToRowGroupLayout(nsGridRowGroupLayout** aRowGroup)
00258 {
00259   (*aRowGroup) = nsnull;
00260   return NS_OK;
00261 }
00262 
00263 NS_IMETHODIMP
00264 nsGridLayout2::CastToGridLayout(nsGridLayout2** aGridLayout)
00265 {
00266   (*aGridLayout) = this;
00267   return NS_OK;
00268 }
00269 
00270 NS_IMETHODIMP
00271 nsGridLayout2::GetTotalMargin(nsIBox* aBox, nsMargin& aMargin, PRBool aIsHorizontal)
00272 {
00273   aMargin.left = 0;
00274   aMargin.right = 0;
00275   aMargin.top = 0;
00276   aMargin.bottom = 0;
00277 
00278   return NS_OK;
00279 }
00280 
00281 NS_IMETHODIMP
00282 nsGridLayout2::GetRowCount(PRInt32& aRowCount)
00283 {
00284   NS_ERROR("Should not be called");
00285   return NS_OK;
00286 }
00287 
00288 NS_IMETHODIMP
00289 nsGridLayout2::ChildrenInserted(nsIBox* aBox, nsBoxLayoutState& aState,
00290                                 nsIBox* aPrevBox, nsIBox* aChildList)
00291 {
00292   mGrid.NeedsRebuild(aState);
00293   return NS_OK;
00294 }
00295 
00296 NS_IMETHODIMP
00297 nsGridLayout2::ChildrenAppended(nsIBox* aBox, nsBoxLayoutState& aState,
00298                                 nsIBox* aChildList)
00299 {
00300   mGrid.NeedsRebuild(aState);
00301   return NS_OK;
00302 }
00303 
00304 
00305 NS_IMETHODIMP
00306 nsGridLayout2::ChildrenRemoved(nsIBox* aBox, nsBoxLayoutState& aState,
00307                                nsIBox* aChildList)
00308 {
00309   mGrid.NeedsRebuild(aState);
00310   return NS_OK;
00311 }
00312 
00313 
00314 NS_IMETHODIMP
00315 nsGridLayout2::ChildrenSet(nsIBox* aBox, nsBoxLayoutState& aState,
00316                            nsIBox* aChildList)
00317 {
00318   mGrid.NeedsRebuild(aState);
00319   return NS_OK;
00320 }
00321 
00322 NS_IMPL_ADDREF_INHERITED(nsGridLayout2, nsStackLayout)
00323 NS_IMPL_RELEASE_INHERITED(nsGridLayout2, nsStackLayout)
00324 
00325 NS_INTERFACE_MAP_BEGIN(nsGridLayout2)
00326   NS_INTERFACE_MAP_ENTRY(nsIGridPart)
00327   NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIGridPart)
00328 NS_INTERFACE_MAP_END_INHERITING(nsStackLayout)