Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/layout/xul/grid/nsGridRowLayout.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 "nsGridRowLayout.h"
15
#include "nsBoxLayoutState.h"
16
#include "nsIScrollableFrame.h"
17
#include "nsBox.h"
18
#include "nsStackLayout.h"
19
#include "nsGrid.h"
20
21
nsGridRowLayout::nsGridRowLayout():nsSprocketLayout()
22
0
{
23
0
}
24
25
nsGridRowLayout::~nsGridRowLayout()
26
0
{
27
0
}
28
29
void
30
nsGridRowLayout::ChildrenInserted(nsIFrame* aBox, nsBoxLayoutState& aState,
31
                                  nsIFrame* aPrevBox,
32
                                  const nsFrameList::Slice& aNewChildren)
33
0
{
34
0
  ChildAddedOrRemoved(aBox, aState);
35
0
}
36
37
void
38
nsGridRowLayout::ChildrenAppended(nsIFrame* aBox, nsBoxLayoutState& aState,
39
                                  const nsFrameList::Slice& aNewChildren)
40
0
{
41
0
  ChildAddedOrRemoved(aBox, aState);
42
0
}
43
44
void
45
nsGridRowLayout::ChildrenRemoved(nsIFrame* aBox, nsBoxLayoutState& aState, nsIFrame* aChildList)
46
0
{
47
0
  ChildAddedOrRemoved(aBox, aState);
48
0
}
49
50
void
51
nsGridRowLayout::ChildrenSet(nsIFrame* aBox, nsBoxLayoutState& aState, nsIFrame* aChildList)
52
0
{
53
0
  ChildAddedOrRemoved(aBox, aState);
54
0
}
55
56
nsIGridPart*
57
nsGridRowLayout::GetParentGridPart(nsIFrame* aBox, nsIFrame** aParentBox)
58
0
{
59
0
  // go up and find our parent gridRow. Skip and non gridRow
60
0
  // parents.
61
0
  *aParentBox = nullptr;
62
0
63
0
  // walk up through any scrollboxes
64
0
  aBox = nsGrid::GetScrollBox(aBox);
65
0
66
0
  // get the parent
67
0
  if (aBox)
68
0
    aBox = nsBox::GetParentXULBox(aBox);
69
0
70
0
  if (aBox)
71
0
  {
72
0
    nsIGridPart* parentGridRow = nsGrid::GetPartFromBox(aBox);
73
0
    if (parentGridRow && parentGridRow->CanContain(this)) {
74
0
      *aParentBox = aBox;
75
0
      return parentGridRow;
76
0
    }
77
0
  }
78
0
79
0
  return nullptr;
80
0
}
81
82
83
nsGrid*
84
nsGridRowLayout::GetGrid(nsIFrame* aBox, int32_t* aIndex, nsGridRowLayout* aRequestor)
85
0
{
86
0
87
0
   if (aRequestor == nullptr)
88
0
   {
89
0
      nsIFrame* parentBox; // nsIFrame is implemented by nsIFrame and is not refcounted.
90
0
      nsIGridPart* parent = GetParentGridPart(aBox, &parentBox);
91
0
      if (parent)
92
0
         return parent->GetGrid(parentBox, aIndex, this);
93
0
      return nullptr;
94
0
   }
95
0
96
0
   int32_t index = -1;
97
0
   nsIFrame* child = nsBox::GetChildXULBox(aBox);
98
0
   int32_t count = 0;
99
0
   while(child)
100
0
   {
101
0
     // if there is a scrollframe walk inside it to its child
102
0
     nsIFrame* childBox = nsGrid::GetScrolledBox(child);
103
0
104
0
     nsBoxLayout* layout = childBox->GetXULLayoutManager();
105
0
     nsIGridPart* gridRow = nsGrid::GetPartFromBox(childBox);
106
0
     if (gridRow)
107
0
     {
108
0
       if (layout == aRequestor) {
109
0
          index = count;
110
0
          break;
111
0
       }
112
0
       count += gridRow->GetRowCount();
113
0
     } else
114
0
       count++;
115
0
116
0
     child = nsBox::GetNextXULBox(child);
117
0
   }
118
0
119
0
   // if we didn't find ourselves then the tree isn't properly formed yet
120
0
   // this could happen during initial construction so lets just
121
0
   // fail.
122
0
   if (index == -1) {
123
0
     *aIndex = -1;
124
0
     return nullptr;
125
0
   }
126
0
127
0
   (*aIndex) += index;
128
0
129
0
   nsIFrame* parentBox; // nsIFrame is implemented by nsIFrame and is not refcounted.
130
0
   nsIGridPart* parent = GetParentGridPart(aBox, &parentBox);
131
0
   if (parent)
132
0
     return parent->GetGrid(parentBox, aIndex, this);
133
0
134
0
   return nullptr;
135
0
}
136
137
nsMargin
138
nsGridRowLayout::GetTotalMargin(nsIFrame* aBox, bool aIsHorizontal)
139
0
{
140
0
  // get our parents margin
141
0
  nsMargin margin(0,0,0,0);
142
0
  nsIFrame* parent = nullptr;
143
0
  nsIGridPart* part = GetParentGridPart(aBox, &parent);
144
0
  if (part && parent) {
145
0
    // if we are the first or last child walk upward and add margins.
146
0
147
0
    // make sure we check for a scrollbox
148
0
    aBox = nsGrid::GetScrollBox(aBox);
149
0
150
0
    // see if we have a next to see if we are last
151
0
    nsIFrame* next = nsBox::GetNextXULBox(aBox);
152
0
153
0
    // get the parent first child to see if we are first
154
0
    nsIFrame* child = nsBox::GetChildXULBox(parent);
155
0
156
0
    margin = part->GetTotalMargin(parent, aIsHorizontal);
157
0
158
0
    // if first or last
159
0
    if (child == aBox || next == nullptr) {
160
0
161
0
       // if it's not the first child remove the top margin
162
0
       // we don't need it.
163
0
       if (child != aBox)
164
0
       {
165
0
          if (aIsHorizontal)
166
0
              margin.top = 0;
167
0
          else
168
0
              margin.left = 0;
169
0
       }
170
0
171
0
       // if it's not the last child remove the bottom margin
172
0
       // we don't need it.
173
0
       if (next != nullptr)
174
0
       {
175
0
          if (aIsHorizontal)
176
0
              margin.bottom = 0;
177
0
          else
178
0
              margin.right = 0;
179
0
       }
180
0
181
0
    }
182
0
  }
183
0
184
0
  // add ours to it.
185
0
  nsMargin ourMargin;
186
0
  aBox->GetXULMargin(ourMargin);
187
0
  margin += ourMargin;
188
0
189
0
  return margin;
190
0
}
191
192
NS_IMPL_ADDREF_INHERITED(nsGridRowLayout, nsBoxLayout)
193
NS_IMPL_RELEASE_INHERITED(nsGridRowLayout, nsBoxLayout)
194
195
0
NS_INTERFACE_MAP_BEGIN(nsGridRowLayout)
196
0
  NS_INTERFACE_MAP_ENTRY(nsIGridPart)
197
0
  NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIGridPart)
198
0
NS_INTERFACE_MAP_END_INHERITING(nsBoxLayout)