1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4  * License, v. 2.0. If a copy of the MPL was not distributed with this
5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 
7 //
8 // Eric Vaughan
9 // Netscape Communications
10 //
11 // See documentation in associated header file
12 //
13 
14 #include "nsGridRowGroupFrame.h"
15 #include "nsGridRowLeafLayout.h"
16 #include "nsGridRow.h"
17 #include "nsBoxLayoutState.h"
18 #include "nsGridLayout2.h"
19 
20 already_AddRefed<nsBoxLayout> NS_NewGridRowGroupLayout();
21 
NS_NewGridRowGroupFrame(nsIPresShell * aPresShell,nsStyleContext * aContext)22 nsIFrame* NS_NewGridRowGroupFrame(nsIPresShell* aPresShell,
23                                   nsStyleContext* aContext) {
24   nsCOMPtr<nsBoxLayout> layout = NS_NewGridRowGroupLayout();
25   return new (aPresShell) nsGridRowGroupFrame(aContext, layout);
26 }
27 
NS_IMPL_FRAMEARENA_HELPERS(nsGridRowGroupFrame)28 NS_IMPL_FRAMEARENA_HELPERS(nsGridRowGroupFrame)
29 
30 /**
31  * This is redefined because row groups have a funny property. If they are
32  * flexible then their flex must be equal to the sum of their children's flexes.
33  */
34 nscoord nsGridRowGroupFrame::GetXULFlex() {
35   // if we are flexible out flexibility is determined by our columns.
36   // so first get the our flex. If not 0 then our flex is the sum of
37   // our columns flexes.
38 
39   if (!DoesNeedRecalc(mFlex)) return mFlex;
40 
41   if (nsBoxFrame::GetXULFlex() == 0) return 0;
42 
43   // ok we are flexible add up our children
44   nscoord totalFlex = 0;
45   nsIFrame* child = nsBox::GetChildXULBox(this);
46   while (child) {
47     totalFlex += child->GetXULFlex();
48     child = GetNextXULBox(child);
49   }
50 
51   mFlex = totalFlex;
52 
53   return totalFlex;
54 }
55