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