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
|
|
|
}
|
2019-08-06 21:16:44 +03:00
|
|
|
nsFrame::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
|
2017-11-07 03:20:33 +03:00
|
|
|
nsFrame::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 {
|
2012-07-30 18:20:58 +04:00
|
|
|
return (GetStateBits() & 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 {
|
2017-07-06 15:00:35 +03:00
|
|
|
return mNextContinuation && (mNextContinuation->GetStateBits() &
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2017-01-04 02:56:19 +03:00
|
|
|
nscoord nsSplittableFrame::ConsumedBSize(WritingMode aWM) const {
|
2017-01-04 02:56:19 +03:00
|
|
|
nscoord bSize = 0;
|
2019-07-30 21:03:25 +03:00
|
|
|
for (nsIFrame* prev = GetPrevContinuation(); prev;
|
|
|
|
prev = prev->GetPrevContinuation()) {
|
2017-01-04 02:56:19 +03:00
|
|
|
bSize += prev->ContentBSize(aWM);
|
2013-07-25 19:34:12 +04:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2019-06-05 02:41:20 +03:00
|
|
|
if (aConsumedBSize == NS_UNCONSTRAINEDSIZE) {
|
2017-01-04 02:56:19 +03:00
|
|
|
aConsumedBSize = ConsumedBSize(aReflowInput.GetWritingMode());
|
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?
|
|
|
|
if (IS_TRUE_OVERFLOW_CONTAINER(this) &&
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2016-07-21 13:36:39 +03:00
|
|
|
nsIFrame::LogicalSides nsSplittableFrame::GetLogicalSkipSides(
|
|
|
|
const ReflowInput* aReflowInput) const {
|
2013-07-25 19:34:27 +04:00
|
|
|
if (IS_TRUE_OVERFLOW_CONTAINER(this)) {
|
2014-06-28 14:13:14 +04:00
|
|
|
return LogicalSides(eLogicalSideBitsBBoth);
|
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)) {
|
2014-06-28 14:13:13 +04:00
|
|
|
return LogicalSides();
|
2014-05-05 21:55:54 +04:00
|
|
|
}
|
2014-04-20 23:39:24 +04:00
|
|
|
|
2014-06-28 14:13:13 +04:00
|
|
|
LogicalSides skip;
|
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
|
|
|
}
|
|
|
|
|
2016-07-21 13:36:39 +03:00
|
|
|
if (aReflowInput) {
|
2013-07-25 19:34:27 +04:00
|
|
|
// We're in the midst of reflow right now, so it's possible that we haven't
|
2019-10-03 20:26:06 +03:00
|
|
|
// created a next-in-flow yet. If our content block-size is going to exceed
|
|
|
|
// our available block-size, though, then we're going to need a
|
|
|
|
// next-in-flow, it just hasn't been created yet.
|
2016-07-21 13:36:39 +03:00
|
|
|
if (NS_UNCONSTRAINEDSIZE != aReflowInput->AvailableBSize()) {
|
2019-10-03 20:26:06 +03:00
|
|
|
nscoord effectiveBSize = GetEffectiveComputedBSize(*aReflowInput);
|
|
|
|
if (effectiveBSize != NS_UNCONSTRAINEDSIZE &&
|
|
|
|
effectiveBSize > aReflowInput->AvailableBSize()) {
|
|
|
|
// Our computed block-size is going to exceed our available block-size,
|
|
|
|
// so we're going to need a next-in-flow.
|
2014-06-28 14:13:14 +04:00
|
|
|
skip |= eLogicalSideBitsBEnd;
|
2013-07-25 19:34:27 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2019-09-09 20:42:14 +03:00
|
|
|
nsIFrame* nif = GetNextContinuation();
|
2013-07-25 19:34:27 +04:00
|
|
|
if (nif && !IS_TRUE_OVERFLOW_CONTAINER(nif)) {
|
2014-06-28 14:13:14 +04:00
|
|
|
skip |= eLogicalSideBitsBEnd;
|
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;
|
|
|
|
}
|
|
|
|
|
2013-07-25 19:34:27 +04:00
|
|
|
return skip;
|
|
|
|
}
|
|
|
|
|
2016-03-11 19:39:26 +03:00
|
|
|
LogicalSides nsSplittableFrame::PreReflowBlockLevelLogicalSkipSides() const {
|
|
|
|
if (MOZ_UNLIKELY(IS_TRUE_OVERFLOW_CONTAINER(this))) {
|
|
|
|
return LogicalSides(mozilla::eLogicalSideBitsBBoth);
|
|
|
|
}
|
|
|
|
if (MOZ_LIKELY(StyleBorder()->mBoxDecorationBreak !=
|
2016-08-26 10:14:32 +03:00
|
|
|
StyleBoxDecorationBreak::Clone) &&
|
2016-03-11 19:39:26 +03:00
|
|
|
GetPrevInFlow()) {
|
|
|
|
return LogicalSides(mozilla::eLogicalSideBitsBStart);
|
|
|
|
}
|
|
|
|
return LogicalSides();
|
|
|
|
}
|