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