2017-10-27 20:33:53 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2006-03-29 22:29:03 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* base class for rendering objects that can be split across lines,
|
|
|
|
* columns, or pages
|
|
|
|
*/
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
#include "nsSplittableFrame.h"
|
2013-07-25 19:34:16 +04:00
|
|
|
#include "nsContainerFrame.h"
|
2019-11-26 00:45:22 +03:00
|
|
|
#include "nsFieldSetFrame.h"
|
2013-10-02 01:00:38 +04:00
|
|
|
#include "nsIFrameInlines.h"
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2014-06-28 14:13:14 +04:00
|
|
|
using namespace mozilla;
|
|
|
|
|
2014-05-25 02:20:40 +04:00
|
|
|
void nsSplittableFrame::Init(nsIContent* aContent, nsContainerFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow) {
|
1999-02-25 06:27:57 +03:00
|
|
|
if (aPrevInFlow) {
|
|
|
|
// Hook the frame into the flow
|
2006-02-22 00:33:47 +03:00
|
|
|
SetPrevInFlow(aPrevInFlow);
|
1999-10-22 18:53:52 +04:00
|
|
|
aPrevInFlow->SetNextInFlow(this);
|
1999-02-25 06:27:57 +03:00
|
|
|
}
|
2020-07-07 01:29:42 +03:00
|
|
|
nsIFrame::Init(aContent, aParent, aPrevInFlow);
|
1999-02-25 06:27:57 +03:00
|
|
|
}
|
|
|
|
|
2017-11-07 03:20:33 +03:00
|
|
|
void nsSplittableFrame::DestroyFrom(nsIFrame* aDestructRoot,
|
|
|
|
PostDestroyData& aPostDestroyData) {
|
2002-10-30 18:33:36 +03:00
|
|
|
// Disconnect from the flow list
|
2006-02-22 00:33:47 +03:00
|
|
|
if (mPrevContinuation || mNextContinuation) {
|
2002-10-30 18:33:36 +03:00
|
|
|
RemoveFromFlow(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Let the base class destroy the frame
|
2020-07-07 01:29:42 +03:00
|
|
|
nsIFrame::DestroyFrom(aDestructRoot, aPostDestroyData);
|
2002-10-30 18:33:36 +03:00
|
|
|
}
|
|
|
|
|
2006-02-22 00:33:47 +03:00
|
|
|
nsIFrame* nsSplittableFrame::GetPrevContinuation() const {
|
|
|
|
return mPrevContinuation;
|
|
|
|
}
|
|
|
|
|
2013-09-25 21:54:55 +04:00
|
|
|
void nsSplittableFrame::SetPrevContinuation(nsIFrame* aFrame) {
|
2017-04-30 18:30:08 +03:00
|
|
|
NS_ASSERTION(!aFrame || Type() == aFrame->Type(),
|
|
|
|
"setting a prev continuation with incorrect type!");
|
|
|
|
NS_ASSERTION(!IsInPrevContinuationChain(aFrame, this),
|
|
|
|
"creating a loop in continuation chain!");
|
2006-02-22 00:33:47 +03:00
|
|
|
mPrevContinuation = aFrame;
|
|
|
|
RemoveStateBits(NS_FRAME_IS_FLUID_CONTINUATION);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame* nsSplittableFrame::GetNextContinuation() const {
|
|
|
|
return mNextContinuation;
|
|
|
|
}
|
|
|
|
|
2013-09-25 21:54:55 +04:00
|
|
|
void nsSplittableFrame::SetNextContinuation(nsIFrame* aFrame) {
|
2017-04-30 18:30:08 +03:00
|
|
|
NS_ASSERTION(!aFrame || Type() == aFrame->Type(),
|
|
|
|
"setting a next continuation with incorrect type!");
|
2006-02-22 00:33:47 +03:00
|
|
|
NS_ASSERTION(!IsInNextContinuationChain(aFrame, this),
|
|
|
|
"creating a loop in continuation chain!");
|
|
|
|
mNextContinuation = aFrame;
|
|
|
|
if (aFrame) aFrame->RemoveStateBits(NS_FRAME_IS_FLUID_CONTINUATION);
|
|
|
|
}
|
|
|
|
|
2013-09-25 15:42:35 +04:00
|
|
|
nsIFrame* nsSplittableFrame::FirstContinuation() const {
|
2007-07-08 11:08:04 +04:00
|
|
|
nsSplittableFrame* firstContinuation = const_cast<nsSplittableFrame*>(this);
|
2006-02-22 00:33:47 +03:00
|
|
|
while (firstContinuation->mPrevContinuation) {
|
2007-07-08 11:08:04 +04:00
|
|
|
firstContinuation =
|
|
|
|
static_cast<nsSplittableFrame*>(firstContinuation->mPrevContinuation);
|
2006-02-22 00:33:47 +03:00
|
|
|
}
|
2013-09-25 15:42:35 +04:00
|
|
|
MOZ_ASSERT(firstContinuation, "post-condition failed");
|
2006-02-22 00:33:47 +03:00
|
|
|
return firstContinuation;
|
|
|
|
}
|
|
|
|
|
2013-09-25 15:42:35 +04:00
|
|
|
nsIFrame* nsSplittableFrame::LastContinuation() const {
|
2007-07-08 11:08:04 +04:00
|
|
|
nsSplittableFrame* lastContinuation = const_cast<nsSplittableFrame*>(this);
|
2006-02-22 00:33:47 +03:00
|
|
|
while (lastContinuation->mNextContinuation) {
|
2007-07-08 11:08:04 +04:00
|
|
|
lastContinuation =
|
|
|
|
static_cast<nsSplittableFrame*>(lastContinuation->mNextContinuation);
|
2006-02-22 00:33:47 +03:00
|
|
|
}
|
2013-09-25 15:42:35 +04:00
|
|
|
MOZ_ASSERT(lastContinuation, "post-condition failed");
|
2006-02-22 00:33:47 +03:00
|
|
|
return lastContinuation;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
2011-09-29 10:19:26 +04:00
|
|
|
bool nsSplittableFrame::IsInPrevContinuationChain(nsIFrame* aFrame1,
|
|
|
|
nsIFrame* aFrame2) {
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t iterations = 0;
|
2009-07-10 06:03:03 +04:00
|
|
|
while (aFrame1 && iterations < 10) {
|
|
|
|
// Bail out after 10 iterations so we don't bog down debug builds too much
|
2006-02-22 00:33:47 +03:00
|
|
|
if (aFrame1 == aFrame2) return true;
|
|
|
|
aFrame1 = aFrame1->GetPrevContinuation();
|
2009-07-10 06:03:03 +04:00
|
|
|
++iterations;
|
2006-02-22 00:33:47 +03:00
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2006-02-22 00:33:47 +03:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool nsSplittableFrame::IsInNextContinuationChain(nsIFrame* aFrame1,
|
|
|
|
nsIFrame* aFrame2) {
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t iterations = 0;
|
2009-07-10 06:03:03 +04:00
|
|
|
while (aFrame1 && iterations < 10) {
|
|
|
|
// Bail out after 10 iterations so we don't bog down debug builds too much
|
2006-02-22 00:33:47 +03:00
|
|
|
if (aFrame1 == aFrame2) return true;
|
|
|
|
aFrame1 = aFrame1->GetNextContinuation();
|
2009-07-10 06:03:03 +04:00
|
|
|
++iterations;
|
2006-02-22 00:33:47 +03:00
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2006-02-22 00:33:47 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2004-09-14 06:28:03 +04:00
|
|
|
nsIFrame* nsSplittableFrame::GetPrevInFlow() const {
|
2020-06-27 16:17:29 +03:00
|
|
|
return HasAnyStateBits(NS_FRAME_IS_FLUID_CONTINUATION) ? mPrevContinuation
|
|
|
|
: nullptr;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2013-09-25 21:54:55 +04:00
|
|
|
void nsSplittableFrame::SetPrevInFlow(nsIFrame* aFrame) {
|
2017-04-30 18:30:08 +03:00
|
|
|
NS_ASSERTION(!aFrame || Type() == aFrame->Type(),
|
|
|
|
"setting a prev in flow with incorrect type!");
|
|
|
|
NS_ASSERTION(!IsInPrevContinuationChain(aFrame, this),
|
|
|
|
"creating a loop in continuation chain!");
|
2006-02-22 00:33:47 +03:00
|
|
|
mPrevContinuation = aFrame;
|
|
|
|
AddStateBits(NS_FRAME_IS_FLUID_CONTINUATION);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2004-09-14 06:28:03 +04:00
|
|
|
nsIFrame* nsSplittableFrame::GetNextInFlow() const {
|
2020-06-27 16:17:29 +03:00
|
|
|
return mNextContinuation && mNextContinuation->HasAnyStateBits(
|
|
|
|
NS_FRAME_IS_FLUID_CONTINUATION)
|
2012-07-30 18:20:58 +04:00
|
|
|
? mNextContinuation
|
|
|
|
: nullptr;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2013-09-25 21:54:55 +04:00
|
|
|
void nsSplittableFrame::SetNextInFlow(nsIFrame* aFrame) {
|
2017-04-30 18:30:08 +03:00
|
|
|
NS_ASSERTION(!aFrame || Type() == aFrame->Type(),
|
|
|
|
"setting a next in flow with incorrect type!");
|
|
|
|
NS_ASSERTION(!IsInNextContinuationChain(aFrame, this),
|
|
|
|
"creating a loop in continuation chain!");
|
2006-02-22 00:33:47 +03:00
|
|
|
mNextContinuation = aFrame;
|
|
|
|
if (aFrame) aFrame->AddStateBits(NS_FRAME_IS_FLUID_CONTINUATION);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2013-09-25 15:42:35 +04:00
|
|
|
nsIFrame* nsSplittableFrame::FirstInFlow() const {
|
2007-07-08 11:08:04 +04:00
|
|
|
nsSplittableFrame* firstInFlow = const_cast<nsSplittableFrame*>(this);
|
2013-09-25 15:42:35 +04:00
|
|
|
while (nsIFrame* prev = firstInFlow->GetPrevInFlow()) {
|
2007-07-08 11:08:04 +04:00
|
|
|
firstInFlow = static_cast<nsSplittableFrame*>(prev);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
2013-09-25 15:42:35 +04:00
|
|
|
MOZ_ASSERT(firstInFlow, "post-condition failed");
|
1998-04-14 00:24:54 +04:00
|
|
|
return firstInFlow;
|
|
|
|
}
|
|
|
|
|
2013-09-25 15:42:35 +04:00
|
|
|
nsIFrame* nsSplittableFrame::LastInFlow() const {
|
2007-07-08 11:08:04 +04:00
|
|
|
nsSplittableFrame* lastInFlow = const_cast<nsSplittableFrame*>(this);
|
2006-02-22 00:33:47 +03:00
|
|
|
while (nsIFrame* next = lastInFlow->GetNextInFlow()) {
|
2007-07-08 11:08:04 +04:00
|
|
|
lastInFlow = static_cast<nsSplittableFrame*>(next);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
2013-09-25 15:42:35 +04:00
|
|
|
MOZ_ASSERT(lastInFlow, "post-condition failed");
|
1998-04-14 00:24:54 +04:00
|
|
|
return lastInFlow;
|
|
|
|
}
|
|
|
|
|
1999-10-22 18:53:52 +04:00
|
|
|
// Remove this frame from the flow. Connects prev in flow and next in flow
|
|
|
|
void nsSplittableFrame::RemoveFromFlow(nsIFrame* aFrame) {
|
2006-02-22 00:33:47 +03:00
|
|
|
nsIFrame* prevContinuation = aFrame->GetPrevContinuation();
|
|
|
|
nsIFrame* nextContinuation = aFrame->GetNextContinuation();
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2006-02-22 00:33:47 +03:00
|
|
|
// The new continuation is fluid only if the continuation on both sides
|
|
|
|
// of the removed frame was fluid
|
|
|
|
if (aFrame->GetPrevInFlow() && aFrame->GetNextInFlow()) {
|
|
|
|
if (prevContinuation) {
|
|
|
|
prevContinuation->SetNextInFlow(nextContinuation);
|
|
|
|
}
|
|
|
|
if (nextContinuation) {
|
|
|
|
nextContinuation->SetPrevInFlow(prevContinuation);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (prevContinuation) {
|
|
|
|
prevContinuation->SetNextContinuation(nextContinuation);
|
|
|
|
}
|
|
|
|
if (nextContinuation) {
|
|
|
|
nextContinuation->SetPrevContinuation(prevContinuation);
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
aFrame->SetPrevInFlow(nullptr);
|
|
|
|
aFrame->SetNextInFlow(nullptr);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2020-11-18 14:04:35 +03:00
|
|
|
NS_DECLARE_FRAME_PROPERTY_SMALL_VALUE(ConsumedBSizeProperty, nscoord);
|
2020-11-18 09:00:38 +03:00
|
|
|
|
2020-11-18 14:06:29 +03:00
|
|
|
nscoord nsSplittableFrame::CalcAndCacheConsumedBSize() {
|
2020-11-18 14:04:35 +03:00
|
|
|
nsIFrame* prev = GetPrevContinuation();
|
|
|
|
if (!prev) {
|
|
|
|
return 0;
|
|
|
|
}
|
2020-11-18 14:06:29 +03:00
|
|
|
const auto wm = GetWritingMode();
|
2020-11-18 14:04:35 +03:00
|
|
|
nscoord bSize = 0;
|
|
|
|
for (; prev; prev = prev->GetPrevContinuation()) {
|
2021-07-16 12:01:52 +03:00
|
|
|
if (prev->IsTrueOverflowContainer()) {
|
|
|
|
// Overflow containers might not get reflowed, and they have no bSize
|
|
|
|
// anyways.
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-11-18 14:06:29 +03:00
|
|
|
bSize += prev->ContentSize(wm).BSize(wm);
|
2020-11-18 14:04:35 +03:00
|
|
|
bool found = false;
|
|
|
|
nscoord consumed = prev->GetProperty(ConsumedBSizeProperty(), &found);
|
|
|
|
if (found) {
|
|
|
|
bSize += consumed;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
MOZ_ASSERT(!prev->GetPrevContinuation(),
|
|
|
|
"Property should always be set on prev continuation if not "
|
|
|
|
"the first continuation");
|
2013-07-25 19:34:12 +04:00
|
|
|
}
|
2020-11-18 14:04:35 +03:00
|
|
|
SetProperty(ConsumedBSizeProperty(), bSize);
|
2017-01-04 02:56:19 +03:00
|
|
|
return bSize;
|
2013-07-25 19:34:12 +04:00
|
|
|
}
|
|
|
|
|
2016-07-21 13:36:39 +03:00
|
|
|
nscoord nsSplittableFrame::GetEffectiveComputedBSize(
|
2014-06-20 13:55:35 +04:00
|
|
|
const ReflowInput& aReflowInput, nscoord aConsumedBSize) const {
|
2016-07-21 13:36:39 +03:00
|
|
|
nscoord bSize = aReflowInput.ComputedBSize();
|
2019-06-05 02:41:20 +03:00
|
|
|
if (bSize == NS_UNCONSTRAINEDSIZE) {
|
|
|
|
return NS_UNCONSTRAINEDSIZE;
|
2013-07-25 19:34:16 +04:00
|
|
|
}
|
|
|
|
|
2014-06-20 13:55:35 +04:00
|
|
|
bSize -= aConsumedBSize;
|
2013-07-25 19:34:16 +04:00
|
|
|
|
2019-11-26 00:45:22 +03:00
|
|
|
// nsFieldSetFrame's inner frames are special since some of their content-box
|
|
|
|
// BSize may be consumed by positioning it below the legend. So we always
|
|
|
|
// report zero for true overflow containers here.
|
|
|
|
// XXXmats: hmm, can we fix this so that the sizes actually adds up instead?
|
2020-10-01 05:39:40 +03:00
|
|
|
if (IsTrueOverflowContainer() &&
|
2019-11-26 00:45:22 +03:00
|
|
|
Style()->GetPseudoType() == PseudoStyleType::fieldsetContent) {
|
|
|
|
for (nsFieldSetFrame* fieldset = do_QueryFrame(GetParent()); fieldset;
|
|
|
|
fieldset = static_cast<nsFieldSetFrame*>(fieldset->GetPrevInFlow())) {
|
|
|
|
bSize -= fieldset->LegendSpace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-25 19:34:16 +04:00
|
|
|
// We may have stretched the frame beyond its computed height. Oh well.
|
2014-06-20 13:55:35 +04:00
|
|
|
return std::max(0, bSize);
|
2013-07-25 19:34:16 +04:00
|
|
|
}
|
|
|
|
|
2020-11-30 20:49:04 +03:00
|
|
|
LogicalSides nsSplittableFrame::GetBlockLevelLogicalSkipSides(
|
|
|
|
bool aAfterReflow) const {
|
2020-04-23 02:52:08 +03:00
|
|
|
LogicalSides skip(mWritingMode);
|
2020-11-30 20:49:04 +03:00
|
|
|
if (MOZ_UNLIKELY(IsTrueOverflowContainer())) {
|
2020-04-23 02:52:08 +03:00
|
|
|
skip |= eLogicalSideBitsBBoth;
|
|
|
|
return skip;
|
2013-07-25 19:34:27 +04:00
|
|
|
}
|
|
|
|
|
2014-05-05 21:55:54 +04:00
|
|
|
if (MOZ_UNLIKELY(StyleBorder()->mBoxDecorationBreak ==
|
2016-08-26 10:14:32 +03:00
|
|
|
StyleBoxDecorationBreak::Clone)) {
|
2020-04-23 02:52:08 +03:00
|
|
|
return skip;
|
2014-05-05 21:55:54 +04:00
|
|
|
}
|
2014-04-20 23:39:24 +04:00
|
|
|
|
2019-09-09 20:42:14 +03:00
|
|
|
if (GetPrevContinuation()) {
|
2014-06-28 14:13:14 +04:00
|
|
|
skip |= eLogicalSideBitsBStart;
|
2013-07-25 19:34:27 +04:00
|
|
|
}
|
|
|
|
|
2019-10-03 20:26:06 +03:00
|
|
|
// Always skip block-end side if we have a *later* sibling across column-span
|
|
|
|
// split.
|
|
|
|
if (HasColumnSpanSiblings()) {
|
|
|
|
skip |= eLogicalSideBitsBEnd;
|
|
|
|
}
|
|
|
|
|
2020-11-30 20:49:04 +03:00
|
|
|
if (aAfterReflow) {
|
|
|
|
nsIFrame* nif = GetNextContinuation();
|
|
|
|
if (nif && !nif->IsTrueOverflowContainer()) {
|
|
|
|
skip |= eLogicalSideBitsBEnd;
|
|
|
|
}
|
2020-11-21 20:23:33 +03:00
|
|
|
}
|
2020-11-30 20:49:04 +03:00
|
|
|
|
2020-04-23 02:52:08 +03:00
|
|
|
return skip;
|
2016-03-11 19:39:26 +03:00
|
|
|
}
|