2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07: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/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* base class for rendering objects that can be split across lines,
|
|
|
|
* columns, or pages
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "nsSplittableFrame.h"
|
2013-07-25 08:34:16 -07:00
|
|
|
#include "nsContainerFrame.h"
|
2013-10-01 14:00:38 -07:00
|
|
|
#include "nsIFrameInlines.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-09-12 09:49:24 -07:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsSplittableFrame)
|
|
|
|
|
2013-03-19 18:47:48 -07:00
|
|
|
void
|
2014-05-24 15:20:40 -07:00
|
|
|
nsSplittableFrame::Init(nsIContent* aContent,
|
|
|
|
nsContainerFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-03-19 18:47:48 -07:00
|
|
|
nsFrame::Init(aContent, aParent, aPrevInFlow);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (aPrevInFlow) {
|
|
|
|
// Hook the frame into the flow
|
|
|
|
SetPrevInFlow(aPrevInFlow);
|
|
|
|
aPrevInFlow->SetNextInFlow(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-12-23 21:21:15 -08:00
|
|
|
nsSplittableFrame::DestroyFrom(nsIFrame* aDestructRoot)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// Disconnect from the flow list
|
|
|
|
if (mPrevContinuation || mNextContinuation) {
|
|
|
|
RemoveFromFlow(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Let the base class destroy the frame
|
2009-12-23 21:21:15 -08:00
|
|
|
nsFrame::DestroyFrom(aDestructRoot);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsSplittableType
|
|
|
|
nsSplittableFrame::GetSplittableType() const
|
|
|
|
{
|
|
|
|
return NS_FRAME_SPLITTABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame* nsSplittableFrame::GetPrevContinuation() const
|
|
|
|
{
|
|
|
|
return mPrevContinuation;
|
|
|
|
}
|
|
|
|
|
2013-09-25 10:54:55 -07:00
|
|
|
void
|
|
|
|
nsSplittableFrame::SetPrevContinuation(nsIFrame* aFrame)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION (!aFrame || GetType() == aFrame->GetType(), "setting a prev continuation with incorrect type!");
|
|
|
|
NS_ASSERTION (!IsInPrevContinuationChain(aFrame, this), "creating a loop in continuation chain!");
|
|
|
|
mPrevContinuation = aFrame;
|
|
|
|
RemoveStateBits(NS_FRAME_IS_FLUID_CONTINUATION);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame* nsSplittableFrame::GetNextContinuation() const
|
|
|
|
{
|
|
|
|
return mNextContinuation;
|
|
|
|
}
|
|
|
|
|
2013-09-25 10:54:55 -07:00
|
|
|
void
|
|
|
|
nsSplittableFrame::SetNextContinuation(nsIFrame* aFrame)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION (!aFrame || GetType() == aFrame->GetType(), "setting a next continuation with incorrect type!");
|
|
|
|
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 04:42:35 -07:00
|
|
|
nsIFrame*
|
|
|
|
nsSplittableFrame::FirstContinuation() const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-07-08 00:08:04 -07:00
|
|
|
nsSplittableFrame* firstContinuation = const_cast<nsSplittableFrame*>(this);
|
2007-03-22 10:30:00 -07:00
|
|
|
while (firstContinuation->mPrevContinuation) {
|
2007-07-08 00:08:04 -07:00
|
|
|
firstContinuation = static_cast<nsSplittableFrame*>(firstContinuation->mPrevContinuation);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2013-09-25 04:42:35 -07:00
|
|
|
MOZ_ASSERT(firstContinuation, "post-condition failed");
|
2007-03-22 10:30:00 -07:00
|
|
|
return firstContinuation;
|
|
|
|
}
|
|
|
|
|
2013-09-25 04:42:35 -07:00
|
|
|
nsIFrame*
|
|
|
|
nsSplittableFrame::LastContinuation() const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-07-08 00:08:04 -07:00
|
|
|
nsSplittableFrame* lastContinuation = const_cast<nsSplittableFrame*>(this);
|
2007-03-22 10:30:00 -07:00
|
|
|
while (lastContinuation->mNextContinuation) {
|
2007-07-08 00:08:04 -07:00
|
|
|
lastContinuation = static_cast<nsSplittableFrame*>(lastContinuation->mNextContinuation);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2013-09-25 04:42:35 -07:00
|
|
|
MOZ_ASSERT(lastContinuation, "post-condition failed");
|
2007-03-22 10:30:00 -07:00
|
|
|
return lastContinuation;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
2011-09-28 23:19:26 -07:00
|
|
|
bool nsSplittableFrame::IsInPrevContinuationChain(nsIFrame* aFrame1, nsIFrame* aFrame2)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t iterations = 0;
|
2009-07-09 19:03:03 -07:00
|
|
|
while (aFrame1 && iterations < 10) {
|
|
|
|
// Bail out after 10 iterations so we don't bog down debug builds too much
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aFrame1 == aFrame2)
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
aFrame1 = aFrame1->GetPrevContinuation();
|
2009-07-09 19:03:03 -07:00
|
|
|
++iterations;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool nsSplittableFrame::IsInNextContinuationChain(nsIFrame* aFrame1, nsIFrame* aFrame2)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t iterations = 0;
|
2009-07-09 19:03:03 -07:00
|
|
|
while (aFrame1 && iterations < 10) {
|
|
|
|
// Bail out after 10 iterations so we don't bog down debug builds too much
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aFrame1 == aFrame2)
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
aFrame1 = aFrame1->GetNextContinuation();
|
2009-07-09 19:03:03 -07:00
|
|
|
++iterations;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
nsIFrame* nsSplittableFrame::GetPrevInFlow() const
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
return (GetStateBits() & NS_FRAME_IS_FLUID_CONTINUATION) ? mPrevContinuation : nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-09-25 10:54:55 -07:00
|
|
|
void
|
|
|
|
nsSplittableFrame::SetPrevInFlow(nsIFrame* aFrame)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION (!aFrame || GetType() == aFrame->GetType(), "setting a prev in flow with incorrect type!");
|
|
|
|
NS_ASSERTION (!IsInPrevContinuationChain(aFrame, this), "creating a loop in continuation chain!");
|
|
|
|
mPrevContinuation = aFrame;
|
|
|
|
AddStateBits(NS_FRAME_IS_FLUID_CONTINUATION);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame* nsSplittableFrame::GetNextInFlow() const
|
|
|
|
{
|
|
|
|
return mNextContinuation && (mNextContinuation->GetStateBits() & NS_FRAME_IS_FLUID_CONTINUATION) ?
|
2012-07-30 07:20:58 -07:00
|
|
|
mNextContinuation : nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-09-25 10:54:55 -07:00
|
|
|
void
|
|
|
|
nsSplittableFrame::SetNextInFlow(nsIFrame* aFrame)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION (!aFrame || GetType() == aFrame->GetType(), "setting a next in flow with incorrect type!");
|
|
|
|
NS_ASSERTION (!IsInNextContinuationChain(aFrame, this), "creating a loop in continuation chain!");
|
|
|
|
mNextContinuation = aFrame;
|
|
|
|
if (aFrame)
|
|
|
|
aFrame->AddStateBits(NS_FRAME_IS_FLUID_CONTINUATION);
|
|
|
|
}
|
|
|
|
|
2013-09-25 04:42:35 -07:00
|
|
|
nsIFrame*
|
|
|
|
nsSplittableFrame::FirstInFlow() const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-07-08 00:08:04 -07:00
|
|
|
nsSplittableFrame* firstInFlow = const_cast<nsSplittableFrame*>(this);
|
2013-09-25 04:42:35 -07:00
|
|
|
while (nsIFrame* prev = firstInFlow->GetPrevInFlow()) {
|
2007-07-08 00:08:04 -07:00
|
|
|
firstInFlow = static_cast<nsSplittableFrame*>(prev);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2013-09-25 04:42:35 -07:00
|
|
|
MOZ_ASSERT(firstInFlow, "post-condition failed");
|
2007-03-22 10:30:00 -07:00
|
|
|
return firstInFlow;
|
|
|
|
}
|
|
|
|
|
2013-09-25 04:42:35 -07:00
|
|
|
nsIFrame*
|
|
|
|
nsSplittableFrame::LastInFlow() const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-07-08 00:08:04 -07:00
|
|
|
nsSplittableFrame* lastInFlow = const_cast<nsSplittableFrame*>(this);
|
2007-03-22 10:30:00 -07:00
|
|
|
while (nsIFrame* next = lastInFlow->GetNextInFlow()) {
|
2007-07-08 00:08:04 -07:00
|
|
|
lastInFlow = static_cast<nsSplittableFrame*>(next);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2013-09-25 04:42:35 -07:00
|
|
|
MOZ_ASSERT(lastInFlow, "post-condition failed");
|
2007-03-22 10:30:00 -07:00
|
|
|
return lastInFlow;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove this frame from the flow. Connects prev in flow and next in flow
|
|
|
|
void
|
|
|
|
nsSplittableFrame::RemoveFromFlow(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
nsIFrame* prevContinuation = aFrame->GetPrevContinuation();
|
|
|
|
nsIFrame* nextContinuation = aFrame->GetNextContinuation();
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
aFrame->SetPrevInFlow(nullptr);
|
|
|
|
aFrame->SetNextInFlow(nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-07-25 08:34:12 -07:00
|
|
|
nscoord
|
|
|
|
nsSplittableFrame::GetConsumedHeight() const
|
|
|
|
{
|
|
|
|
nscoord height = 0;
|
|
|
|
for (nsIFrame* prev = GetPrevInFlow(); prev; prev = prev->GetPrevInFlow()) {
|
2014-05-12 04:45:28 -07:00
|
|
|
height += prev->GetContentRectRelativeToSelf().height;
|
2013-07-25 08:34:12 -07:00
|
|
|
}
|
|
|
|
return height;
|
|
|
|
}
|
|
|
|
|
2013-07-25 08:34:16 -07:00
|
|
|
nscoord
|
|
|
|
nsSplittableFrame::GetEffectiveComputedHeight(const nsHTMLReflowState& aReflowState,
|
|
|
|
nscoord aConsumedHeight) const
|
|
|
|
{
|
|
|
|
nscoord height = aReflowState.ComputedHeight();
|
|
|
|
if (height == NS_INTRINSICSIZE) {
|
|
|
|
return NS_INTRINSICSIZE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aConsumedHeight == NS_INTRINSICSIZE) {
|
|
|
|
aConsumedHeight = GetConsumedHeight();
|
|
|
|
}
|
|
|
|
|
|
|
|
height -= aConsumedHeight;
|
|
|
|
|
|
|
|
// We may have stretched the frame beyond its computed height. Oh well.
|
2014-05-12 04:45:28 -07:00
|
|
|
return std::max(0, height);
|
2013-07-25 08:34:16 -07:00
|
|
|
}
|
|
|
|
|
2013-07-25 08:34:27 -07:00
|
|
|
int
|
2014-03-13 00:39:33 -07:00
|
|
|
nsSplittableFrame::GetLogicalSkipSides(const nsHTMLReflowState* aReflowState) const
|
2013-07-25 08:34:27 -07:00
|
|
|
{
|
|
|
|
if (IS_TRUE_OVERFLOW_CONTAINER(this)) {
|
2014-03-13 00:39:33 -07:00
|
|
|
return LOGICAL_SIDES_B_BOTH;
|
2013-07-25 08:34:27 -07:00
|
|
|
}
|
|
|
|
|
2014-05-05 10:55:54 -07:00
|
|
|
if (MOZ_UNLIKELY(StyleBorder()->mBoxDecorationBreak ==
|
|
|
|
NS_STYLE_BOX_DECORATION_BREAK_CLONE)) {
|
|
|
|
return 0;
|
|
|
|
}
|
2014-04-20 12:39:24 -07:00
|
|
|
|
2014-05-05 10:55:54 -07:00
|
|
|
int skip = 0;
|
2013-07-25 08:34:27 -07:00
|
|
|
if (GetPrevInFlow()) {
|
2014-03-13 00:39:33 -07:00
|
|
|
skip |= LOGICAL_SIDE_B_START;
|
2013-07-25 08:34:27 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (aReflowState) {
|
|
|
|
// We're in the midst of reflow right now, so it's possible that we haven't
|
|
|
|
// created a nif yet. If our content height is going to exceed our available
|
|
|
|
// height, though, then we're going to need a next-in-flow, it just hasn't
|
|
|
|
// been created yet.
|
|
|
|
|
2013-12-27 09:59:21 -08:00
|
|
|
if (NS_UNCONSTRAINEDSIZE != aReflowState->AvailableHeight()) {
|
2013-07-25 08:34:27 -07:00
|
|
|
nscoord effectiveCH = this->GetEffectiveComputedHeight(*aReflowState);
|
2014-05-12 04:45:28 -07:00
|
|
|
if (effectiveCH != NS_INTRINSICSIZE &&
|
|
|
|
effectiveCH > aReflowState->AvailableHeight()) {
|
2013-07-25 08:34:27 -07:00
|
|
|
// Our content height is going to exceed our available height, so we're
|
|
|
|
// going to need a next-in-flow.
|
2014-03-13 00:39:33 -07:00
|
|
|
skip |= LOGICAL_SIDE_B_END;
|
2013-07-25 08:34:27 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
nsIFrame* nif = GetNextInFlow();
|
|
|
|
if (nif && !IS_TRUE_OVERFLOW_CONTAINER(nif)) {
|
2014-03-13 00:39:33 -07:00
|
|
|
skip |= LOGICAL_SIDE_B_END;
|
2013-07-25 08:34:27 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return skip;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#ifdef DEBUG
|
|
|
|
void
|
2012-08-22 08:56:38 -07:00
|
|
|
nsSplittableFrame::DumpBaseRegressionData(nsPresContext* aPresContext, FILE* out, int32_t aIndent)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-02-09 20:36:54 -08:00
|
|
|
nsFrame::DumpBaseRegressionData(aPresContext, out, aIndent);
|
2012-07-30 07:20:58 -07:00
|
|
|
if (nullptr != mNextContinuation) {
|
2007-03-22 10:30:00 -07:00
|
|
|
IndentBy(out, aIndent);
|
2012-09-14 13:09:52 -07:00
|
|
|
fprintf(out, "<next-continuation va=\"%p\"/>\n", (void*)mNextContinuation);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2012-07-30 07:20:58 -07:00
|
|
|
if (nullptr != mPrevContinuation) {
|
2007-03-22 10:30:00 -07:00
|
|
|
IndentBy(out, aIndent);
|
2012-09-14 13:09:52 -07:00
|
|
|
fprintf(out, "<prev-continuation va=\"%p\"/>\n", (void*)mPrevContinuation);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
#endif
|