layout/xul/grid/nsGridLayout2.cpp

Wed, 31 Dec 2014 07:16:47 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:16:47 +0100
branch
TOR_BUG_9701
changeset 3
141e0f1194b1
permissions
-rw-r--r--

Revert simplistic fix pending revisit of Mozilla integration attempt.

     1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 //
     7 // Eric Vaughan
     8 // Netscape Communications
     9 //
    10 // See documentation in associated header file
    11 //
    13 #include "nsGridLayout2.h"
    14 #include "nsGridRowGroupLayout.h"
    15 #include "nsGridRow.h"
    16 #include "nsBox.h"
    17 #include "nsIScrollableFrame.h"
    18 #include "nsSprocketLayout.h"
    19 #include "nsHTMLReflowState.h"
    21 nsresult
    22 NS_NewGridLayout2( nsIPresShell* aPresShell, nsBoxLayout** aNewLayout)
    23 {
    24   *aNewLayout = new nsGridLayout2(aPresShell);
    25   NS_IF_ADDREF(*aNewLayout);
    27   return NS_OK;
    29 } 
    31 nsGridLayout2::nsGridLayout2(nsIPresShell* aPresShell):nsStackLayout()
    32 {
    33 }
    35 // static
    36 void
    37 nsGridLayout2::AddOffset(nsBoxLayoutState& aState, nsIFrame* aChild, nsSize& aSize)
    38 {
    39   nsMargin offset;
    40   GetOffset(aState, aChild, offset);
    41   aSize.width += offset.left;
    42   aSize.height += offset.top;
    43 }
    45 NS_IMETHODIMP
    46 nsGridLayout2::Layout(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState)
    47 {
    48   // XXX This should be set a better way!
    49   mGrid.SetBox(aBox);
    50   NS_ASSERTION(aBox->GetLayoutManager() == this, "setting incorrect box");
    52   nsresult rv = nsStackLayout::Layout(aBox, aBoxLayoutState);
    53 #ifdef DEBUG_grid
    54   mGrid.PrintCellMap();
    55 #endif
    56   return rv;
    57 }
    59 void
    60 nsGridLayout2::IntrinsicWidthsDirty(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState)
    61 {
    62   nsStackLayout::IntrinsicWidthsDirty(aBox, aBoxLayoutState);
    63   // XXXldb We really don't need to do all the work that NeedsRebuild
    64   // does; we just need to mark intrinsic widths dirty on the
    65   // (row/column)(s/-groups).
    66   mGrid.NeedsRebuild(aBoxLayoutState);
    67 }
    69 nsGrid*
    70 nsGridLayout2::GetGrid(nsIFrame* aBox, int32_t* aIndex, nsGridRowLayout* aRequestor)
    71 {
    72   // XXX This should be set a better way!
    73   mGrid.SetBox(aBox);
    74   NS_ASSERTION(aBox->GetLayoutManager() == this, "setting incorrect box");
    75   return &mGrid;
    76 }
    78 void
    79 nsGridLayout2::AddWidth(nsSize& aSize, nscoord aSize2, bool aIsHorizontal)
    80 {
    81   nscoord& size = GET_WIDTH(aSize, aIsHorizontal);
    83   if (size != NS_INTRINSICSIZE) {
    84     if (aSize2 == NS_INTRINSICSIZE)
    85       size = NS_INTRINSICSIZE;
    86     else
    87       size += aSize2;
    88   }
    89 }
    91 nsSize
    92 nsGridLayout2::GetMinSize(nsIFrame* aBox, nsBoxLayoutState& aState)
    93 {
    94   nsSize minSize = nsStackLayout::GetMinSize(aBox, aState); 
    96   // if there are no <rows> tags that will sum up our columns,
    97   // sum up our columns here.
    98   nsSize total(0,0);
    99   nsIFrame* rowsBox = mGrid.GetRowsBox();
   100   nsIFrame* columnsBox = mGrid.GetColumnsBox();
   101   if (!rowsBox || !columnsBox) {
   102     if (!rowsBox) {
   103       // max height is the sum of our rows
   104       int32_t rows = mGrid.GetRowCount();
   105       for (int32_t i=0; i < rows; i++)
   106       {
   107         nscoord height = mGrid.GetMinRowHeight(aState, i, true); 
   108         AddWidth(total, height, false); // AddHeight
   109       }
   110     }
   112     if (!columnsBox) {
   113       // max height is the sum of our rows
   114       int32_t columns = mGrid.GetColumnCount();
   115       for (int32_t i=0; i < columns; i++)
   116       {
   117         nscoord width = mGrid.GetMinRowHeight(aState, i, false); 
   118         AddWidth(total, width, true); // AddWidth
   119       }
   120     }
   122     AddMargin(aBox, total);
   123     AddOffset(aState, aBox, total);
   124     AddLargestSize(minSize, total);
   125   }
   127   return minSize;
   128 }
   130 nsSize
   131 nsGridLayout2::GetPrefSize(nsIFrame* aBox, nsBoxLayoutState& aState)
   132 {
   133   nsSize pref = nsStackLayout::GetPrefSize(aBox, aState); 
   135   // if there are no <rows> tags that will sum up our columns,
   136   // sum up our columns here.
   137   nsSize total(0,0);
   138   nsIFrame* rowsBox = mGrid.GetRowsBox();
   139   nsIFrame* columnsBox = mGrid.GetColumnsBox();
   140   if (!rowsBox || !columnsBox) {
   141     if (!rowsBox) {
   142       // max height is the sum of our rows
   143       int32_t rows = mGrid.GetRowCount();
   144       for (int32_t i=0; i < rows; i++)
   145       {
   146         nscoord height = mGrid.GetPrefRowHeight(aState, i, true); 
   147         AddWidth(total, height, false); // AddHeight
   148       }
   149     }
   151     if (!columnsBox) {
   152       // max height is the sum of our rows
   153       int32_t columns = mGrid.GetColumnCount();
   154       for (int32_t i=0; i < columns; i++)
   155       {
   156         nscoord width = mGrid.GetPrefRowHeight(aState, i, false);
   157         AddWidth(total, width, true); // AddWidth
   158       }
   159     }
   161     AddMargin(aBox, total);
   162     AddOffset(aState, aBox, total);
   163     AddLargestSize(pref, total);
   164   }
   166   return pref;
   167 }
   169 nsSize
   170 nsGridLayout2::GetMaxSize(nsIFrame* aBox, nsBoxLayoutState& aState)
   171 {
   172   nsSize maxSize = nsStackLayout::GetMaxSize(aBox, aState); 
   174   // if there are no <rows> tags that will sum up our columns,
   175   // sum up our columns here.
   176   nsSize total(NS_INTRINSICSIZE, NS_INTRINSICSIZE);
   177   nsIFrame* rowsBox = mGrid.GetRowsBox();
   178   nsIFrame* columnsBox = mGrid.GetColumnsBox();
   179   if (!rowsBox || !columnsBox) {
   180     if (!rowsBox) {
   181       total.height = 0;
   182       // max height is the sum of our rows
   183       int32_t rows = mGrid.GetRowCount();
   184       for (int32_t i=0; i < rows; i++)
   185       {
   186         nscoord height = mGrid.GetMaxRowHeight(aState, i, true); 
   187         AddWidth(total, height, false); // AddHeight
   188       }
   189     }
   191     if (!columnsBox) {
   192       total.width = 0;
   193       // max height is the sum of our rows
   194       int32_t columns = mGrid.GetColumnCount();
   195       for (int32_t i=0; i < columns; i++)
   196       {
   197         nscoord width = mGrid.GetMaxRowHeight(aState, i, false);
   198         AddWidth(total, width, true); // AddWidth
   199       }
   200     }
   202     AddMargin(aBox, total);
   203     AddOffset(aState, aBox, total);
   204     AddSmallestSize(maxSize, total);
   205   }
   207   return maxSize;
   208 }
   210 int32_t
   211 nsGridLayout2::BuildRows(nsIFrame* aBox, nsGridRow* aRows)
   212 {
   213   if (aBox) {
   214     aRows[0].Init(aBox, true);
   215     return 1;
   216   }
   217   return 0;
   218 }
   220 nsMargin
   221 nsGridLayout2::GetTotalMargin(nsIFrame* aBox, bool aIsHorizontal)
   222 {
   223   nsMargin margin(0,0,0,0);
   224   return margin;
   225 }
   227 void
   228 nsGridLayout2::ChildrenInserted(nsIFrame* aBox, nsBoxLayoutState& aState,
   229                                 nsIFrame* aPrevBox,
   230                                 const nsFrameList::Slice& aNewChildren)
   231 {
   232   mGrid.NeedsRebuild(aState);
   233 }
   235 void
   236 nsGridLayout2::ChildrenAppended(nsIFrame* aBox, nsBoxLayoutState& aState,
   237                                 const nsFrameList::Slice& aNewChildren)
   238 {
   239   mGrid.NeedsRebuild(aState);
   240 }
   242 void
   243 nsGridLayout2::ChildrenRemoved(nsIFrame* aBox, nsBoxLayoutState& aState,
   244                                nsIFrame* aChildList)
   245 {
   246   mGrid.NeedsRebuild(aState);
   247 }
   249 void
   250 nsGridLayout2::ChildrenSet(nsIFrame* aBox, nsBoxLayoutState& aState,
   251                            nsIFrame* aChildList)
   252 {
   253   mGrid.NeedsRebuild(aState);
   254 }
   256 NS_IMPL_ADDREF_INHERITED(nsGridLayout2, nsStackLayout)
   257 NS_IMPL_RELEASE_INHERITED(nsGridLayout2, nsStackLayout)
   259 NS_INTERFACE_MAP_BEGIN(nsGridLayout2)
   260   NS_INTERFACE_MAP_ENTRY(nsIGridPart)
   261   NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIGridPart)
   262 NS_INTERFACE_MAP_END_INHERITING(nsStackLayout)

mercurial