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/. */
5 
6 //
7 // Eric Vaughan
8 // Netscape Communications
9 //
10 // See documentation in associated header file
11 //
12 
13 #include "nsGridRowLeafFrame.h"
14 #include "nsGridRowLeafLayout.h"
15 #include "nsGridRow.h"
16 #include "nsBoxLayoutState.h"
17 #include "nsGridLayout2.h"
18 
19 already_AddRefed<nsBoxLayout> NS_NewGridRowLeafLayout();
20 
21 nsIFrame*
NS_NewGridRowLeafFrame(nsIPresShell * aPresShell,nsStyleContext * aContext)22 NS_NewGridRowLeafFrame(nsIPresShell* aPresShell,
23                        nsStyleContext* aContext)
24 {
25   nsCOMPtr<nsBoxLayout> layout = NS_NewGridRowLeafLayout();
26   return new (aPresShell) nsGridRowLeafFrame(aContext, false, layout);
27 }
28 
NS_IMPL_FRAMEARENA_HELPERS(nsGridRowLeafFrame)29 NS_IMPL_FRAMEARENA_HELPERS(nsGridRowLeafFrame)
30 
31 /*
32  * Our border and padding could be affected by our columns or rows.
33  * Let's go check it out.
34  */
35 nsresult
36 nsGridRowLeafFrame::GetXULBorderAndPadding(nsMargin& aBorderAndPadding)
37 {
38   // if our columns have made our padding larger add it in.
39   nsresult rv = nsBoxFrame::GetXULBorderAndPadding(aBorderAndPadding);
40 
41   nsIGridPart* part = nsGrid::GetPartFromBox(this);
42   if (!part)
43     return rv;
44 
45   int32_t index = 0;
46   nsGrid* grid = part->GetGrid(this, &index);
47 
48   if (!grid)
49     return rv;
50 
51   bool isHorizontal = IsXULHorizontal();
52 
53   int32_t firstIndex = 0;
54   int32_t lastIndex = 0;
55   nsGridRow* firstRow = nullptr;
56   nsGridRow* lastRow = nullptr;
57   grid->GetFirstAndLastRow(firstIndex, lastIndex, firstRow, lastRow, isHorizontal);
58 
59   // only the first and last rows can be affected.
60   if (firstRow && firstRow->GetBox() == this) {
61 
62     nscoord top = 0;
63     nscoord bottom = 0;
64     grid->GetRowOffsets(firstIndex, top, bottom, isHorizontal);
65 
66     if (isHorizontal) {
67       if (top > aBorderAndPadding.top)
68         aBorderAndPadding.top = top;
69     } else {
70       if (top > aBorderAndPadding.left)
71         aBorderAndPadding.left = top;
72     }
73   }
74 
75   if (lastRow && lastRow->GetBox() == this) {
76 
77     nscoord top = 0;
78     nscoord bottom = 0;
79     grid->GetRowOffsets(lastIndex, top, bottom, isHorizontal);
80 
81     if (isHorizontal) {
82       if (bottom > aBorderAndPadding.bottom)
83         aBorderAndPadding.bottom = bottom;
84     } else {
85       if (bottom > aBorderAndPadding.right)
86         aBorderAndPadding.right = bottom;
87     }
88 
89   }
90 
91   return rv;
92 }
93 
94 
95