1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* ***** BEGIN LICENSE BLOCK *****
3 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 : *
5 : * The contents of this file are subject to the Mozilla Public License Version
6 : * 1.1 (the "License"); you may not use this file except in compliance with
7 : * the License. You may obtain a copy of the License at
8 : * http://www.mozilla.org/MPL/
9 : *
10 : * Software distributed under the License is distributed on an "AS IS" basis,
11 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : * for the specific language governing rights and limitations under the
13 : * License.
14 : *
15 : * The Original Code is Mozilla Communicator client code.
16 : *
17 : * The Initial Developer of the Original Code is
18 : * Netscape Communications Corporation.
19 : * Portions created by the Initial Developer are Copyright (C) 1998
20 : * the Initial Developer. All Rights Reserved.
21 : *
22 : * Contributor(s):
23 : *
24 : * Alternatively, the contents of this file may be used under the terms of
25 : * either of the GNU General Public License Version 2 or later (the "GPL"),
26 : * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 : * in which case the provisions of the GPL or the LGPL are applicable instead
28 : * of those above. If you wish to allow use of your version of this file only
29 : * under the terms of either the GPL or the LGPL, and not to allow others to
30 : * use your version of this file under the terms of the MPL, indicate your
31 : * decision by deleting the provisions above and replace them with the notice
32 : * and other provisions required by the GPL or the LGPL. If you do not delete
33 : * the provisions above, a recipient may use your version of this file under
34 : * the terms of any one of the MPL, the GPL or the LGPL.
35 : *
36 : * ***** END LICENSE BLOCK ***** */
37 :
38 : //
39 : // Eric Vaughan
40 : // Netscape Communications
41 : //
42 : // See documentation in associated header file
43 : //
44 :
45 : #include "nsGridRowLeafFrame.h"
46 : #include "nsGridRowLeafLayout.h"
47 : #include "nsGridRow.h"
48 : #include "nsBoxLayoutState.h"
49 : #include "nsGridLayout2.h"
50 :
51 : already_AddRefed<nsBoxLayout> NS_NewGridRowLeafLayout();
52 :
53 : nsIFrame*
54 0 : NS_NewGridRowLeafFrame(nsIPresShell* aPresShell,
55 : nsStyleContext* aContext)
56 : {
57 0 : nsCOMPtr<nsBoxLayout> layout = NS_NewGridRowLeafLayout();
58 0 : if (!layout) {
59 0 : return nsnull;
60 : }
61 :
62 : return new (aPresShell) nsGridRowLeafFrame(aPresShell, aContext, false,
63 0 : layout);
64 : }
65 :
66 0 : NS_IMPL_FRAMEARENA_HELPERS(nsGridRowLeafFrame)
67 :
68 : /*
69 : * Our border and padding could be affected by our columns or rows.
70 : * Let's go check it out.
71 : */
72 : NS_IMETHODIMP
73 0 : nsGridRowLeafFrame::GetBorderAndPadding(nsMargin& aBorderAndPadding)
74 : {
75 : // if our columns have made our padding larger add it in.
76 0 : nsresult rv = nsBoxFrame::GetBorderAndPadding(aBorderAndPadding);
77 :
78 0 : nsIGridPart* part = nsGrid::GetPartFromBox(this);
79 0 : if (!part)
80 0 : return rv;
81 :
82 0 : PRInt32 index = 0;
83 0 : nsGrid* grid = part->GetGrid(this, &index);
84 :
85 0 : if (!grid)
86 0 : return rv;
87 :
88 0 : bool isHorizontal = IsHorizontal();
89 :
90 0 : nsBoxLayoutState state(PresContext());
91 :
92 0 : PRInt32 firstIndex = 0;
93 0 : PRInt32 lastIndex = 0;
94 0 : nsGridRow* firstRow = nsnull;
95 0 : nsGridRow* lastRow = nsnull;
96 0 : grid->GetFirstAndLastRow(state, firstIndex, lastIndex, firstRow, lastRow, isHorizontal);
97 :
98 : // only the first and last rows can be affected.
99 0 : if (firstRow && firstRow->GetBox() == this) {
100 :
101 0 : nscoord top = 0;
102 0 : nscoord bottom = 0;
103 0 : grid->GetRowOffsets(state, firstIndex, top, bottom, isHorizontal);
104 :
105 0 : if (isHorizontal) {
106 0 : if (top > aBorderAndPadding.top)
107 0 : aBorderAndPadding.top = top;
108 : } else {
109 0 : if (top > aBorderAndPadding.left)
110 0 : aBorderAndPadding.left = top;
111 : }
112 : }
113 :
114 0 : if (lastRow && lastRow->GetBox() == this) {
115 :
116 0 : nscoord top = 0;
117 0 : nscoord bottom = 0;
118 0 : grid->GetRowOffsets(state, lastIndex, top, bottom, isHorizontal);
119 :
120 0 : if (isHorizontal) {
121 0 : if (bottom > aBorderAndPadding.bottom)
122 0 : aBorderAndPadding.bottom = bottom;
123 : } else {
124 0 : if (bottom > aBorderAndPadding.right)
125 0 : aBorderAndPadding.right = bottom;
126 : }
127 :
128 : }
129 :
130 0 : return rv;
131 : }
132 :
133 :
|