Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/layout/generic/nsSplittableFrame.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
 * base class for rendering objects that can be split across lines,
9
 * columns, or pages
10
 */
11
12
#include "nsSplittableFrame.h"
13
#include "nsContainerFrame.h"
14
#include "nsIFrameInlines.h"
15
16
using namespace mozilla;
17
18
void
19
nsSplittableFrame::Init(nsIContent*       aContent,
20
                        nsContainerFrame* aParent,
21
                        nsIFrame*         aPrevInFlow)
22
0
{
23
0
  nsFrame::Init(aContent, aParent, aPrevInFlow);
24
0
25
0
  if (aPrevInFlow) {
26
0
    // Hook the frame into the flow
27
0
    SetPrevInFlow(aPrevInFlow);
28
0
    aPrevInFlow->SetNextInFlow(this);
29
0
  }
30
0
}
31
32
void
33
nsSplittableFrame::DestroyFrom(nsIFrame* aDestructRoot, PostDestroyData& aPostDestroyData)
34
0
{
35
0
  // Disconnect from the flow list
36
0
  if (mPrevContinuation || mNextContinuation) {
37
0
    RemoveFromFlow(this);
38
0
  }
39
0
40
0
  // Let the base class destroy the frame
41
0
  nsFrame::DestroyFrom(aDestructRoot, aPostDestroyData);
42
0
}
43
44
nsSplittableType
45
nsSplittableFrame::GetSplittableType() const
46
0
{
47
0
  return NS_FRAME_SPLITTABLE;
48
0
}
49
50
nsIFrame* nsSplittableFrame::GetPrevContinuation() const
51
0
{
52
0
  return mPrevContinuation;
53
0
}
54
55
void
56
nsSplittableFrame::SetPrevContinuation(nsIFrame* aFrame)
57
0
{
58
0
  NS_ASSERTION(!aFrame || Type() == aFrame->Type(),
59
0
               "setting a prev continuation with incorrect type!");
60
0
  NS_ASSERTION(!IsInPrevContinuationChain(aFrame, this),
61
0
               "creating a loop in continuation chain!");
62
0
  mPrevContinuation = aFrame;
63
0
  RemoveStateBits(NS_FRAME_IS_FLUID_CONTINUATION);
64
0
}
65
66
nsIFrame* nsSplittableFrame::GetNextContinuation() const
67
0
{
68
0
  return mNextContinuation;
69
0
}
70
71
void
72
nsSplittableFrame::SetNextContinuation(nsIFrame* aFrame)
73
0
{
74
0
  NS_ASSERTION(!aFrame || Type() == aFrame->Type(),
75
0
              "setting a next continuation with incorrect type!");
76
0
  NS_ASSERTION (!IsInNextContinuationChain(aFrame, this), "creating a loop in continuation chain!");
77
0
  mNextContinuation = aFrame;
78
0
  if (aFrame)
79
0
    aFrame->RemoveStateBits(NS_FRAME_IS_FLUID_CONTINUATION);
80
0
}
81
82
nsIFrame*
83
nsSplittableFrame::FirstContinuation() const
84
0
{
85
0
  nsSplittableFrame* firstContinuation = const_cast<nsSplittableFrame*>(this);
86
0
  while (firstContinuation->mPrevContinuation)  {
87
0
    firstContinuation = static_cast<nsSplittableFrame*>(firstContinuation->mPrevContinuation);
88
0
  }
89
0
  MOZ_ASSERT(firstContinuation, "post-condition failed");
90
0
  return firstContinuation;
91
0
}
92
93
nsIFrame*
94
nsSplittableFrame::LastContinuation() const
95
0
{
96
0
  nsSplittableFrame* lastContinuation = const_cast<nsSplittableFrame*>(this);
97
0
  while (lastContinuation->mNextContinuation)  {
98
0
    lastContinuation = static_cast<nsSplittableFrame*>(lastContinuation->mNextContinuation);
99
0
  }
100
0
  MOZ_ASSERT(lastContinuation, "post-condition failed");
101
0
  return lastContinuation;
102
0
}
103
104
#ifdef DEBUG
105
bool nsSplittableFrame::IsInPrevContinuationChain(nsIFrame* aFrame1, nsIFrame* aFrame2)
106
{
107
  int32_t iterations = 0;
108
  while (aFrame1 && iterations < 10) {
109
    // Bail out after 10 iterations so we don't bog down debug builds too much
110
    if (aFrame1 == aFrame2)
111
      return true;
112
    aFrame1 = aFrame1->GetPrevContinuation();
113
    ++iterations;
114
  }
115
  return false;
116
}
117
118
bool nsSplittableFrame::IsInNextContinuationChain(nsIFrame* aFrame1, nsIFrame* aFrame2)
119
{
120
  int32_t iterations = 0;
121
  while (aFrame1 && iterations < 10) {
122
    // Bail out after 10 iterations so we don't bog down debug builds too much
123
    if (aFrame1 == aFrame2)
124
      return true;
125
    aFrame1 = aFrame1->GetNextContinuation();
126
    ++iterations;
127
  }
128
  return false;
129
}
130
#endif
131
132
nsIFrame* nsSplittableFrame::GetPrevInFlow() const
133
0
{
134
0
  return (GetStateBits() & NS_FRAME_IS_FLUID_CONTINUATION) ? mPrevContinuation : nullptr;
135
0
}
136
137
void
138
nsSplittableFrame::SetPrevInFlow(nsIFrame* aFrame)
139
0
{
140
0
  NS_ASSERTION(!aFrame || Type() == aFrame->Type(),
141
0
               "setting a prev in flow with incorrect type!");
142
0
  NS_ASSERTION(!IsInPrevContinuationChain(aFrame, this),
143
0
               "creating a loop in continuation chain!");
144
0
  mPrevContinuation = aFrame;
145
0
  AddStateBits(NS_FRAME_IS_FLUID_CONTINUATION);
146
0
}
147
148
nsIFrame* nsSplittableFrame::GetNextInFlow() const
149
0
{
150
0
  return mNextContinuation && (mNextContinuation->GetStateBits() & NS_FRAME_IS_FLUID_CONTINUATION) ?
151
0
    mNextContinuation : nullptr;
152
0
}
153
154
void
155
nsSplittableFrame::SetNextInFlow(nsIFrame* aFrame)
156
0
{
157
0
  NS_ASSERTION(!aFrame || Type() == aFrame->Type(),
158
0
               "setting a next in flow with incorrect type!");
159
0
  NS_ASSERTION(!IsInNextContinuationChain(aFrame, this),
160
0
               "creating a loop in continuation chain!");
161
0
  mNextContinuation = aFrame;
162
0
  if (aFrame)
163
0
    aFrame->AddStateBits(NS_FRAME_IS_FLUID_CONTINUATION);
164
0
}
165
166
nsIFrame*
167
nsSplittableFrame::FirstInFlow() const
168
0
{
169
0
  nsSplittableFrame* firstInFlow = const_cast<nsSplittableFrame*>(this);
170
0
  while (nsIFrame* prev = firstInFlow->GetPrevInFlow())  {
171
0
    firstInFlow = static_cast<nsSplittableFrame*>(prev);
172
0
  }
173
0
  MOZ_ASSERT(firstInFlow, "post-condition failed");
174
0
  return firstInFlow;
175
0
}
176
177
nsIFrame*
178
nsSplittableFrame::LastInFlow() const
179
0
{
180
0
  nsSplittableFrame* lastInFlow = const_cast<nsSplittableFrame*>(this);
181
0
  while (nsIFrame* next = lastInFlow->GetNextInFlow())  {
182
0
    lastInFlow = static_cast<nsSplittableFrame*>(next);
183
0
  }
184
0
  MOZ_ASSERT(lastInFlow, "post-condition failed");
185
0
  return lastInFlow;
186
0
}
187
188
// Remove this frame from the flow. Connects prev in flow and next in flow
189
void
190
nsSplittableFrame::RemoveFromFlow(nsIFrame* aFrame)
191
0
{
192
0
  nsIFrame* prevContinuation = aFrame->GetPrevContinuation();
193
0
  nsIFrame* nextContinuation = aFrame->GetNextContinuation();
194
0
195
0
  // The new continuation is fluid only if the continuation on both sides
196
0
  // of the removed frame was fluid
197
0
  if (aFrame->GetPrevInFlow() && aFrame->GetNextInFlow()) {
198
0
    if (prevContinuation) {
199
0
      prevContinuation->SetNextInFlow(nextContinuation);
200
0
    }
201
0
    if (nextContinuation) {
202
0
      nextContinuation->SetPrevInFlow(prevContinuation);
203
0
    }
204
0
  } else {
205
0
    if (prevContinuation) {
206
0
      prevContinuation->SetNextContinuation(nextContinuation);
207
0
    }
208
0
    if (nextContinuation) {
209
0
      nextContinuation->SetPrevContinuation(prevContinuation);
210
0
    }
211
0
  }
212
0
213
0
  aFrame->SetPrevInFlow(nullptr);
214
0
  aFrame->SetNextInFlow(nullptr);
215
0
}
216
217
nscoord
218
nsSplittableFrame::ConsumedBSize(WritingMode aWM) const
219
0
{
220
0
  nscoord bSize = 0;
221
0
  for (nsIFrame* prev = GetPrevInFlow(); prev; prev = prev->GetPrevInFlow()) {
222
0
    bSize += prev->ContentBSize(aWM);
223
0
  }
224
0
  return bSize;
225
0
}
226
227
nscoord
228
nsSplittableFrame::GetEffectiveComputedBSize(const ReflowInput& aReflowInput,
229
                                              nscoord aConsumedBSize) const
230
0
{
231
0
  nscoord bSize = aReflowInput.ComputedBSize();
232
0
  if (bSize == NS_INTRINSICSIZE) {
233
0
    return NS_INTRINSICSIZE;
234
0
  }
235
0
236
0
  if (aConsumedBSize == NS_INTRINSICSIZE) {
237
0
    aConsumedBSize = ConsumedBSize(aReflowInput.GetWritingMode());
238
0
  }
239
0
240
0
  bSize -= aConsumedBSize;
241
0
242
0
  // We may have stretched the frame beyond its computed height. Oh well.
243
0
  return std::max(0, bSize);
244
0
}
245
246
nsIFrame::LogicalSides
247
nsSplittableFrame::GetLogicalSkipSides(const ReflowInput* aReflowInput) const
248
0
{
249
0
  if (IS_TRUE_OVERFLOW_CONTAINER(this)) {
250
0
    return LogicalSides(eLogicalSideBitsBBoth);
251
0
  }
252
0
253
0
  if (MOZ_UNLIKELY(StyleBorder()->mBoxDecorationBreak ==
254
0
                     StyleBoxDecorationBreak::Clone)) {
255
0
    return LogicalSides();
256
0
  }
257
0
258
0
  LogicalSides skip;
259
0
  if (GetPrevInFlow()) {
260
0
    skip |= eLogicalSideBitsBStart;
261
0
  }
262
0
263
0
  if (aReflowInput) {
264
0
    // We're in the midst of reflow right now, so it's possible that we haven't
265
0
    // created a nif yet. If our content height is going to exceed our available
266
0
    // height, though, then we're going to need a next-in-flow, it just hasn't
267
0
    // been created yet.
268
0
269
0
    if (NS_UNCONSTRAINEDSIZE != aReflowInput->AvailableBSize()) {
270
0
      nscoord effectiveCH = this->GetEffectiveComputedBSize(*aReflowInput);
271
0
      if (effectiveCH != NS_INTRINSICSIZE &&
272
0
          effectiveCH > aReflowInput->AvailableBSize()) {
273
0
        // Our content height is going to exceed our available height, so we're
274
0
        // going to need a next-in-flow.
275
0
        skip |= eLogicalSideBitsBEnd;
276
0
      }
277
0
    }
278
0
  } else {
279
0
    nsIFrame* nif = GetNextInFlow();
280
0
    if (nif && !IS_TRUE_OVERFLOW_CONTAINER(nif)) {
281
0
      skip |= eLogicalSideBitsBEnd;
282
0
    }
283
0
  }
284
0
285
0
 return skip;
286
0
}
287
288
LogicalSides
289
nsSplittableFrame::PreReflowBlockLevelLogicalSkipSides() const
290
0
{
291
0
  if (MOZ_UNLIKELY(IS_TRUE_OVERFLOW_CONTAINER(this))) {
292
0
    return LogicalSides(mozilla::eLogicalSideBitsBBoth);
293
0
  }
294
0
  if (MOZ_LIKELY(StyleBorder()->mBoxDecorationBreak !=
295
0
                   StyleBoxDecorationBreak::Clone) &&
296
0
      GetPrevInFlow()) {
297
0
    return LogicalSides(mozilla::eLogicalSideBitsBStart);
298
0
  }
299
0
  return LogicalSides();
300
0
}