Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/layout/xul/grid/nsGridLayout2.cpp
Line
Count
Source (jump to first uncovered line)
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 "nsGridLayout2.h"
15
#include "nsGridRowGroupLayout.h"
16
#include "nsGridRow.h"
17
#include "nsBox.h"
18
#include "nsIScrollableFrame.h"
19
#include "nsSprocketLayout.h"
20
#include "mozilla/ReflowInput.h"
21
22
nsresult
23
NS_NewGridLayout2( nsIPresShell* aPresShell, nsBoxLayout** aNewLayout)
24
0
{
25
0
  *aNewLayout = new nsGridLayout2(aPresShell);
26
0
  NS_IF_ADDREF(*aNewLayout);
27
0
28
0
  return NS_OK;
29
0
30
0
}
31
32
nsGridLayout2::nsGridLayout2(nsIPresShell* aPresShell):nsStackLayout()
33
0
{
34
0
}
35
36
nsGridLayout2::~nsGridLayout2()
37
0
{
38
0
}
39
40
// static
41
void
42
nsGridLayout2::AddOffset(nsIFrame* aChild, nsSize& aSize)
43
0
{
44
0
  nsMargin offset;
45
0
  GetOffset(aChild, offset);
46
0
  aSize.width += offset.left;
47
0
  aSize.height += offset.top;
48
0
}
49
50
NS_IMETHODIMP
51
nsGridLayout2::XULLayout(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState)
52
0
{
53
0
  // XXX This should be set a better way!
54
0
  mGrid.SetBox(aBox);
55
0
  NS_ASSERTION(aBox->GetXULLayoutManager() == this, "setting incorrect box");
56
0
57
0
  nsresult rv = nsStackLayout::XULLayout(aBox, aBoxLayoutState);
58
#ifdef DEBUG_grid
59
  mGrid.PrintCellMap();
60
#endif
61
  return rv;
62
0
}
63
64
void
65
nsGridLayout2::IntrinsicISizesDirty(nsIFrame* aBox, nsBoxLayoutState& aBoxLayoutState)
66
0
{
67
0
  nsStackLayout::IntrinsicISizesDirty(aBox, aBoxLayoutState);
68
0
  // XXXldb We really don't need to do all the work that NeedsRebuild
69
0
  // does; we just need to mark intrinsic widths dirty on the
70
0
  // (row/column)(s/-groups).
71
0
  mGrid.NeedsRebuild(aBoxLayoutState);
72
0
}
73
74
nsGrid*
75
nsGridLayout2::GetGrid(nsIFrame* aBox, int32_t* aIndex, nsGridRowLayout* aRequestor)
76
0
{
77
0
  // XXX This should be set a better way!
78
0
  mGrid.SetBox(aBox);
79
0
  NS_ASSERTION(aBox->GetXULLayoutManager() == this, "setting incorrect box");
80
0
  return &mGrid;
81
0
}
82
83
void
84
nsGridLayout2::AddWidth(nsSize& aSize, nscoord aSize2, bool aIsHorizontal)
85
0
{
86
0
  nscoord& size = GET_WIDTH(aSize, aIsHorizontal);
87
0
88
0
  if (size != NS_INTRINSICSIZE) {
89
0
    if (aSize2 == NS_INTRINSICSIZE)
90
0
      size = NS_INTRINSICSIZE;
91
0
    else
92
0
      size += aSize2;
93
0
  }
94
0
}
95
96
nsSize
97
nsGridLayout2::GetXULMinSize(nsIFrame* aBox, nsBoxLayoutState& aState)
98
0
{
99
0
  nsSize minSize = nsStackLayout::GetXULMinSize(aBox, aState);
100
0
101
0
  // if there are no <rows> tags that will sum up our columns,
102
0
  // sum up our columns here.
103
0
  nsSize total(0,0);
104
0
  nsIFrame* rowsBox = mGrid.GetRowsBox();
105
0
  nsIFrame* columnsBox = mGrid.GetColumnsBox();
106
0
  if (!rowsBox || !columnsBox) {
107
0
    if (!rowsBox) {
108
0
      // max height is the sum of our rows
109
0
      int32_t rows = mGrid.GetRowCount();
110
0
      for (int32_t i=0; i < rows; i++)
111
0
      {
112
0
        nscoord height = mGrid.GetMinRowHeight(aState, i, true);
113
0
        AddWidth(total, height, false); // AddHeight
114
0
      }
115
0
    }
116
0
117
0
    if (!columnsBox) {
118
0
      // max height is the sum of our rows
119
0
      int32_t columns = mGrid.GetColumnCount();
120
0
      for (int32_t i=0; i < columns; i++)
121
0
      {
122
0
        nscoord width = mGrid.GetMinRowHeight(aState, i, false);
123
0
        AddWidth(total, width, true); // AddWidth
124
0
      }
125
0
    }
126
0
127
0
    AddMargin(aBox, total);
128
0
    AddOffset(aBox, total);
129
0
    AddLargestSize(minSize, total);
130
0
  }
131
0
132
0
  return minSize;
133
0
}
134
135
nsSize
136
nsGridLayout2::GetXULPrefSize(nsIFrame* aBox, nsBoxLayoutState& aState)
137
0
{
138
0
  nsSize pref = nsStackLayout::GetXULPrefSize(aBox, aState);
139
0
140
0
  // if there are no <rows> tags that will sum up our columns,
141
0
  // sum up our columns here.
142
0
  nsSize total(0,0);
143
0
  nsIFrame* rowsBox = mGrid.GetRowsBox();
144
0
  nsIFrame* columnsBox = mGrid.GetColumnsBox();
145
0
  if (!rowsBox || !columnsBox) {
146
0
    if (!rowsBox) {
147
0
      // max height is the sum of our rows
148
0
      int32_t rows = mGrid.GetRowCount();
149
0
      for (int32_t i=0; i < rows; i++)
150
0
      {
151
0
        nscoord height = mGrid.GetPrefRowHeight(aState, i, true);
152
0
        AddWidth(total, height, false); // AddHeight
153
0
      }
154
0
    }
155
0
156
0
    if (!columnsBox) {
157
0
      // max height is the sum of our rows
158
0
      int32_t columns = mGrid.GetColumnCount();
159
0
      for (int32_t i=0; i < columns; i++)
160
0
      {
161
0
        nscoord width = mGrid.GetPrefRowHeight(aState, i, false);
162
0
        AddWidth(total, width, true); // AddWidth
163
0
      }
164
0
    }
165
0
166
0
    AddMargin(aBox, total);
167
0
    AddOffset(aBox, total);
168
0
    AddLargestSize(pref, total);
169
0
  }
170
0
171
0
  return pref;
172
0
}
173
174
nsSize
175
nsGridLayout2::GetXULMaxSize(nsIFrame* aBox, nsBoxLayoutState& aState)
176
0
{
177
0
  nsSize maxSize = nsStackLayout::GetXULMaxSize(aBox, aState);
178
0
179
0
  // if there are no <rows> tags that will sum up our columns,
180
0
  // sum up our columns here.
181
0
  nsSize total(NS_INTRINSICSIZE, NS_INTRINSICSIZE);
182
0
  nsIFrame* rowsBox = mGrid.GetRowsBox();
183
0
  nsIFrame* columnsBox = mGrid.GetColumnsBox();
184
0
  if (!rowsBox || !columnsBox) {
185
0
    if (!rowsBox) {
186
0
      total.height = 0;
187
0
      // max height is the sum of our rows
188
0
      int32_t rows = mGrid.GetRowCount();
189
0
      for (int32_t i=0; i < rows; i++)
190
0
      {
191
0
        nscoord height = mGrid.GetMaxRowHeight(aState, i, true);
192
0
        AddWidth(total, height, false); // AddHeight
193
0
      }
194
0
    }
195
0
196
0
    if (!columnsBox) {
197
0
      total.width = 0;
198
0
      // max height is the sum of our rows
199
0
      int32_t columns = mGrid.GetColumnCount();
200
0
      for (int32_t i=0; i < columns; i++)
201
0
      {
202
0
        nscoord width = mGrid.GetMaxRowHeight(aState, i, false);
203
0
        AddWidth(total, width, true); // AddWidth
204
0
      }
205
0
    }
206
0
207
0
    AddMargin(aBox, total);
208
0
    AddOffset(aBox, total);
209
0
    AddSmallestSize(maxSize, total);
210
0
  }
211
0
212
0
  return maxSize;
213
0
}
214
215
int32_t
216
nsGridLayout2::BuildRows(nsIFrame* aBox, nsGridRow* aRows)
217
0
{
218
0
  if (aBox) {
219
0
    aRows[0].Init(aBox, true);
220
0
    return 1;
221
0
  }
222
0
  return 0;
223
0
}
224
225
nsMargin
226
nsGridLayout2::GetTotalMargin(nsIFrame* aBox, bool aIsHorizontal)
227
0
{
228
0
  nsMargin margin(0,0,0,0);
229
0
  return margin;
230
0
}
231
232
void
233
nsGridLayout2::ChildrenInserted(nsIFrame* aBox, nsBoxLayoutState& aState,
234
                                nsIFrame* aPrevBox,
235
                                const nsFrameList::Slice& aNewChildren)
236
0
{
237
0
  mGrid.NeedsRebuild(aState);
238
0
}
239
240
void
241
nsGridLayout2::ChildrenAppended(nsIFrame* aBox, nsBoxLayoutState& aState,
242
                                const nsFrameList::Slice& aNewChildren)
243
0
{
244
0
  mGrid.NeedsRebuild(aState);
245
0
}
246
247
void
248
nsGridLayout2::ChildrenRemoved(nsIFrame* aBox, nsBoxLayoutState& aState,
249
                               nsIFrame* aChildList)
250
0
{
251
0
  mGrid.NeedsRebuild(aState);
252
0
}
253
254
void
255
nsGridLayout2::ChildrenSet(nsIFrame* aBox, nsBoxLayoutState& aState,
256
                           nsIFrame* aChildList)
257
0
{
258
0
  mGrid.NeedsRebuild(aState);
259
0
}
260
261
NS_IMPL_ADDREF_INHERITED(nsGridLayout2, nsStackLayout)
262
NS_IMPL_RELEASE_INHERITED(nsGridLayout2, nsStackLayout)
263
264
0
NS_INTERFACE_MAP_BEGIN(nsGridLayout2)
265
0
  NS_INTERFACE_MAP_ENTRY(nsIGridPart)
266
0
  NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIGridPart)
267
0
NS_INTERFACE_MAP_END_INHERITING(nsStackLayout)