layout/xul/grid/nsGridLayout2.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/layout/xul/grid/nsGridLayout2.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,262 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +//
    1.10 +// Eric Vaughan
    1.11 +// Netscape Communications
    1.12 +//
    1.13 +// See documentation in associated header file
    1.14 +//
    1.15 +
    1.16 +#include "nsGridLayout2.h"
    1.17 +#include "nsGridRowGroupLayout.h"
    1.18 +#include "nsGridRow.h"
    1.19 +#include "nsBox.h"
    1.20 +#include "nsIScrollableFrame.h"
    1.21 +#include "nsSprocketLayout.h"
    1.22 +#include "nsHTMLReflowState.h"
    1.23 +
    1.24 +nsresult
    1.25 +NS_NewGridLayout2( nsIPresShell* aPresShell, nsBoxLayout** aNewLayout)
    1.26 +{
    1.27 +  *aNewLayout = new nsGridLayout2(aPresShell);
    1.28 +  NS_IF_ADDREF(*aNewLayout);
    1.29 +
    1.30 +  return NS_OK;
    1.31 +  
    1.32 +} 
    1.33 +
    1.34 +nsGridLayout2::nsGridLayout2(nsIPresShell* aPresShell):nsStackLayout()
    1.35 +{
    1.36 +}
    1.37 +
    1.38 +// static
    1.39 +void
    1.40 +nsGridLayout2::AddOffset(nsBoxLayoutState& aState, nsIFrame* aChild, nsSize& aSize)
    1.41 +{
    1.42 +  nsMargin offset;
    1.43 +  GetOffset(aState, aChild, offset);
    1.44 +  aSize.width += offset.left;
    1.45 +  aSize.height += offset.top;
    1.46 +}
    1.47 +
    1.48 +NS_IMETHODIMP
    1.49 +nsGridLayout2::Layout(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState)
    1.50 +{
    1.51 +  // XXX This should be set a better way!
    1.52 +  mGrid.SetBox(aBox);
    1.53 +  NS_ASSERTION(aBox->GetLayoutManager() == this, "setting incorrect box");
    1.54 +
    1.55 +  nsresult rv = nsStackLayout::Layout(aBox, aBoxLayoutState);
    1.56 +#ifdef DEBUG_grid
    1.57 +  mGrid.PrintCellMap();
    1.58 +#endif
    1.59 +  return rv;
    1.60 +}
    1.61 +
    1.62 +void
    1.63 +nsGridLayout2::IntrinsicWidthsDirty(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState)
    1.64 +{
    1.65 +  nsStackLayout::IntrinsicWidthsDirty(aBox, aBoxLayoutState);
    1.66 +  // XXXldb We really don't need to do all the work that NeedsRebuild
    1.67 +  // does; we just need to mark intrinsic widths dirty on the
    1.68 +  // (row/column)(s/-groups).
    1.69 +  mGrid.NeedsRebuild(aBoxLayoutState);
    1.70 +}
    1.71 +
    1.72 +nsGrid*
    1.73 +nsGridLayout2::GetGrid(nsIFrame* aBox, int32_t* aIndex, nsGridRowLayout* aRequestor)
    1.74 +{
    1.75 +  // XXX This should be set a better way!
    1.76 +  mGrid.SetBox(aBox);
    1.77 +  NS_ASSERTION(aBox->GetLayoutManager() == this, "setting incorrect box");
    1.78 +  return &mGrid;
    1.79 +}
    1.80 +
    1.81 +void
    1.82 +nsGridLayout2::AddWidth(nsSize& aSize, nscoord aSize2, bool aIsHorizontal)
    1.83 +{
    1.84 +  nscoord& size = GET_WIDTH(aSize, aIsHorizontal);
    1.85 +
    1.86 +  if (size != NS_INTRINSICSIZE) {
    1.87 +    if (aSize2 == NS_INTRINSICSIZE)
    1.88 +      size = NS_INTRINSICSIZE;
    1.89 +    else
    1.90 +      size += aSize2;
    1.91 +  }
    1.92 +}
    1.93 +
    1.94 +nsSize
    1.95 +nsGridLayout2::GetMinSize(nsIFrame* aBox, nsBoxLayoutState& aState)
    1.96 +{
    1.97 +  nsSize minSize = nsStackLayout::GetMinSize(aBox, aState); 
    1.98 +
    1.99 +  // if there are no <rows> tags that will sum up our columns,
   1.100 +  // sum up our columns here.
   1.101 +  nsSize total(0,0);
   1.102 +  nsIFrame* rowsBox = mGrid.GetRowsBox();
   1.103 +  nsIFrame* columnsBox = mGrid.GetColumnsBox();
   1.104 +  if (!rowsBox || !columnsBox) {
   1.105 +    if (!rowsBox) {
   1.106 +      // max height is the sum of our rows
   1.107 +      int32_t rows = mGrid.GetRowCount();
   1.108 +      for (int32_t i=0; i < rows; i++)
   1.109 +      {
   1.110 +        nscoord height = mGrid.GetMinRowHeight(aState, i, true); 
   1.111 +        AddWidth(total, height, false); // AddHeight
   1.112 +      }
   1.113 +    }
   1.114 +
   1.115 +    if (!columnsBox) {
   1.116 +      // max height is the sum of our rows
   1.117 +      int32_t columns = mGrid.GetColumnCount();
   1.118 +      for (int32_t i=0; i < columns; i++)
   1.119 +      {
   1.120 +        nscoord width = mGrid.GetMinRowHeight(aState, i, false); 
   1.121 +        AddWidth(total, width, true); // AddWidth
   1.122 +      }
   1.123 +    }
   1.124 +
   1.125 +    AddMargin(aBox, total);
   1.126 +    AddOffset(aState, aBox, total);
   1.127 +    AddLargestSize(minSize, total);
   1.128 +  }
   1.129 +  
   1.130 +  return minSize;
   1.131 +}
   1.132 +
   1.133 +nsSize
   1.134 +nsGridLayout2::GetPrefSize(nsIFrame* aBox, nsBoxLayoutState& aState)
   1.135 +{
   1.136 +  nsSize pref = nsStackLayout::GetPrefSize(aBox, aState); 
   1.137 +
   1.138 +  // if there are no <rows> tags that will sum up our columns,
   1.139 +  // sum up our columns here.
   1.140 +  nsSize total(0,0);
   1.141 +  nsIFrame* rowsBox = mGrid.GetRowsBox();
   1.142 +  nsIFrame* columnsBox = mGrid.GetColumnsBox();
   1.143 +  if (!rowsBox || !columnsBox) {
   1.144 +    if (!rowsBox) {
   1.145 +      // max height is the sum of our rows
   1.146 +      int32_t rows = mGrid.GetRowCount();
   1.147 +      for (int32_t i=0; i < rows; i++)
   1.148 +      {
   1.149 +        nscoord height = mGrid.GetPrefRowHeight(aState, i, true); 
   1.150 +        AddWidth(total, height, false); // AddHeight
   1.151 +      }
   1.152 +    }
   1.153 +
   1.154 +    if (!columnsBox) {
   1.155 +      // max height is the sum of our rows
   1.156 +      int32_t columns = mGrid.GetColumnCount();
   1.157 +      for (int32_t i=0; i < columns; i++)
   1.158 +      {
   1.159 +        nscoord width = mGrid.GetPrefRowHeight(aState, i, false);
   1.160 +        AddWidth(total, width, true); // AddWidth
   1.161 +      }
   1.162 +    }
   1.163 +
   1.164 +    AddMargin(aBox, total);
   1.165 +    AddOffset(aState, aBox, total);
   1.166 +    AddLargestSize(pref, total);
   1.167 +  }
   1.168 +
   1.169 +  return pref;
   1.170 +}
   1.171 +
   1.172 +nsSize
   1.173 +nsGridLayout2::GetMaxSize(nsIFrame* aBox, nsBoxLayoutState& aState)
   1.174 +{
   1.175 +  nsSize maxSize = nsStackLayout::GetMaxSize(aBox, aState); 
   1.176 +
   1.177 +  // if there are no <rows> tags that will sum up our columns,
   1.178 +  // sum up our columns here.
   1.179 +  nsSize total(NS_INTRINSICSIZE, NS_INTRINSICSIZE);
   1.180 +  nsIFrame* rowsBox = mGrid.GetRowsBox();
   1.181 +  nsIFrame* columnsBox = mGrid.GetColumnsBox();
   1.182 +  if (!rowsBox || !columnsBox) {
   1.183 +    if (!rowsBox) {
   1.184 +      total.height = 0;
   1.185 +      // max height is the sum of our rows
   1.186 +      int32_t rows = mGrid.GetRowCount();
   1.187 +      for (int32_t i=0; i < rows; i++)
   1.188 +      {
   1.189 +        nscoord height = mGrid.GetMaxRowHeight(aState, i, true); 
   1.190 +        AddWidth(total, height, false); // AddHeight
   1.191 +      }
   1.192 +    }
   1.193 +
   1.194 +    if (!columnsBox) {
   1.195 +      total.width = 0;
   1.196 +      // max height is the sum of our rows
   1.197 +      int32_t columns = mGrid.GetColumnCount();
   1.198 +      for (int32_t i=0; i < columns; i++)
   1.199 +      {
   1.200 +        nscoord width = mGrid.GetMaxRowHeight(aState, i, false);
   1.201 +        AddWidth(total, width, true); // AddWidth
   1.202 +      }
   1.203 +    }
   1.204 +
   1.205 +    AddMargin(aBox, total);
   1.206 +    AddOffset(aState, aBox, total);
   1.207 +    AddSmallestSize(maxSize, total);
   1.208 +  }
   1.209 +
   1.210 +  return maxSize;
   1.211 +}
   1.212 +
   1.213 +int32_t
   1.214 +nsGridLayout2::BuildRows(nsIFrame* aBox, nsGridRow* aRows)
   1.215 +{
   1.216 +  if (aBox) {
   1.217 +    aRows[0].Init(aBox, true);
   1.218 +    return 1;
   1.219 +  }
   1.220 +  return 0;
   1.221 +}
   1.222 +
   1.223 +nsMargin
   1.224 +nsGridLayout2::GetTotalMargin(nsIFrame* aBox, bool aIsHorizontal)
   1.225 +{
   1.226 +  nsMargin margin(0,0,0,0);
   1.227 +  return margin;
   1.228 +}
   1.229 +
   1.230 +void
   1.231 +nsGridLayout2::ChildrenInserted(nsIFrame* aBox, nsBoxLayoutState& aState,
   1.232 +                                nsIFrame* aPrevBox,
   1.233 +                                const nsFrameList::Slice& aNewChildren)
   1.234 +{
   1.235 +  mGrid.NeedsRebuild(aState);
   1.236 +}
   1.237 +
   1.238 +void
   1.239 +nsGridLayout2::ChildrenAppended(nsIFrame* aBox, nsBoxLayoutState& aState,
   1.240 +                                const nsFrameList::Slice& aNewChildren)
   1.241 +{
   1.242 +  mGrid.NeedsRebuild(aState);
   1.243 +}
   1.244 +
   1.245 +void
   1.246 +nsGridLayout2::ChildrenRemoved(nsIFrame* aBox, nsBoxLayoutState& aState,
   1.247 +                               nsIFrame* aChildList)
   1.248 +{
   1.249 +  mGrid.NeedsRebuild(aState);
   1.250 +}
   1.251 +
   1.252 +void
   1.253 +nsGridLayout2::ChildrenSet(nsIFrame* aBox, nsBoxLayoutState& aState,
   1.254 +                           nsIFrame* aChildList)
   1.255 +{
   1.256 +  mGrid.NeedsRebuild(aState);
   1.257 +}
   1.258 +
   1.259 +NS_IMPL_ADDREF_INHERITED(nsGridLayout2, nsStackLayout)
   1.260 +NS_IMPL_RELEASE_INHERITED(nsGridLayout2, nsStackLayout)
   1.261 +
   1.262 +NS_INTERFACE_MAP_BEGIN(nsGridLayout2)
   1.263 +  NS_INTERFACE_MAP_ENTRY(nsIGridPart)
   1.264 +  NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIGridPart)
   1.265 +NS_INTERFACE_MAP_END_INHERITING(nsStackLayout)

mercurial