2001-09-29 00:14:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-18 18:30:37 +04:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
1998-10-01 01:01:11 +04:00
|
|
|
*
|
2004-04-18 18:30:37 +04:00
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
1998-10-01 01:01:11 +04:00
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
1998-10-01 01:01:11 +04:00
|
|
|
*
|
1999-11-06 06:40:37 +03:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2004-04-18 18:30:37 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-29 00:14:13 +04:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 06:40:37 +03:00
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-18 18:30:37 +04:00
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
2001-09-29 00:14:13 +04:00
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
2004-04-18 18:30:37 +04:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-29 00:14:13 +04:00
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
2004-04-18 18:30:37 +04:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-09-29 00:14:13 +04:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
2006-03-29 22:29:03 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* base class for rendering objects that can be split across lines,
|
|
|
|
* columns, or pages
|
|
|
|
*/
|
|
|
|
|
1998-10-01 01:01:11 +04:00
|
|
|
#include "nsSplittableFrame.h"
|
|
|
|
#include "nsIContent.h"
|
2004-08-01 03:15:21 +04:00
|
|
|
#include "nsPresContext.h"
|
2003-02-22 03:32:13 +03:00
|
|
|
#include "nsStyleContext.h"
|
1998-10-01 01:01:11 +04:00
|
|
|
|
2009-09-12 20:49:24 +04:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsSplittableFrame)
|
|
|
|
|
1999-02-25 06:27:57 +03:00
|
|
|
NS_IMETHODIMP
|
2006-03-09 21:55:21 +03:00
|
|
|
nsSplittableFrame::Init(nsIContent* aContent,
|
1999-02-25 06:27:57 +03:00
|
|
|
nsIFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow)
|
|
|
|
{
|
2006-03-27 01:30:36 +04:00
|
|
|
nsresult rv = nsFrame::Init(aContent, aParent, 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
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2006-04-10 04:16:29 +04:00
|
|
|
void
|
2009-12-24 08:21:15 +03:00
|
|
|
nsSplittableFrame::DestroyFrom(nsIFrame* aDestructRoot)
|
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
|
2009-12-24 08:21:15 +03:00
|
|
|
nsFrame::DestroyFrom(aDestructRoot);
|
2002-10-30 18:33:36 +03:00
|
|
|
}
|
|
|
|
|
2006-12-20 06:52:34 +03:00
|
|
|
nsSplittableType
|
|
|
|
nsSplittableFrame::GetSplittableType() const
|
1998-10-01 01:01:11 +04:00
|
|
|
{
|
2006-12-20 06:52:34 +03:00
|
|
|
return NS_FRAME_SPLITTABLE;
|
1998-10-01 01:01:11 +04:00
|
|
|
}
|
|
|
|
|
2006-02-22 00:33:47 +03:00
|
|
|
nsIFrame* nsSplittableFrame::GetPrevContinuation() const
|
|
|
|
{
|
|
|
|
return mPrevContinuation;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_METHOD nsSplittableFrame::SetPrevContinuation(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame* nsSplittableFrame::GetNextContinuation() const
|
|
|
|
{
|
|
|
|
return mNextContinuation;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_METHOD nsSplittableFrame::SetNextContinuation(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame* nsSplittableFrame::GetFirstContinuation() 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
|
|
|
}
|
|
|
|
NS_POSTCONDITION(firstContinuation, "illegal state in continuation chain.");
|
|
|
|
return firstContinuation;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame* nsSplittableFrame::GetLastContinuation() 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
|
|
|
}
|
|
|
|
NS_POSTCONDITION(lastContinuation, "illegal state in continuation chain.");
|
|
|
|
return lastContinuation;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
PRBool nsSplittableFrame::IsInPrevContinuationChain(nsIFrame* aFrame1, nsIFrame* aFrame2)
|
|
|
|
{
|
2009-07-10 06:03:03 +04:00
|
|
|
PRInt32 iterations = 0;
|
|
|
|
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 PR_TRUE;
|
|
|
|
aFrame1 = aFrame1->GetPrevContinuation();
|
2009-07-10 06:03:03 +04:00
|
|
|
++iterations;
|
2006-02-22 00:33:47 +03:00
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool nsSplittableFrame::IsInNextContinuationChain(nsIFrame* aFrame1, nsIFrame* aFrame2)
|
|
|
|
{
|
2009-07-10 06:03:03 +04:00
|
|
|
PRInt32 iterations = 0;
|
|
|
|
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 PR_TRUE;
|
|
|
|
aFrame1 = aFrame1->GetNextContinuation();
|
2009-07-10 06:03:03 +04:00
|
|
|
++iterations;
|
2006-02-22 00:33:47 +03:00
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2004-09-14 06:28:03 +04:00
|
|
|
nsIFrame* nsSplittableFrame::GetPrevInFlow() const
|
1998-10-01 01:01:11 +04:00
|
|
|
{
|
2006-02-22 00:33:47 +03:00
|
|
|
return (GetStateBits() & NS_FRAME_IS_FLUID_CONTINUATION) ? mPrevContinuation : nsnull;
|
1998-10-01 01:01:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_METHOD nsSplittableFrame::SetPrevInFlow(nsIFrame* aFrame)
|
|
|
|
{
|
2006-02-22 00:33:47 +03: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);
|
1998-10-01 01:01:11 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2004-09-14 06:28:03 +04:00
|
|
|
nsIFrame* nsSplittableFrame::GetNextInFlow() const
|
1998-10-01 01:01:11 +04:00
|
|
|
{
|
2006-02-22 00:33:47 +03:00
|
|
|
return mNextContinuation && (mNextContinuation->GetStateBits() & NS_FRAME_IS_FLUID_CONTINUATION) ?
|
|
|
|
mNextContinuation : nsnull;
|
1998-10-01 01:01:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_METHOD nsSplittableFrame::SetNextInFlow(nsIFrame* aFrame)
|
|
|
|
{
|
2006-02-22 00:33:47 +03: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);
|
1998-10-01 01:01:11 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame* nsSplittableFrame::GetFirstInFlow() const
|
|
|
|
{
|
2007-07-08 11:08:04 +04:00
|
|
|
nsSplittableFrame* firstInFlow = const_cast<nsSplittableFrame*>(this);
|
2006-02-22 00:33:47 +03:00
|
|
|
while (nsIFrame *prev = firstInFlow->GetPrevInFlow()) {
|
2007-07-08 11:08:04 +04:00
|
|
|
firstInFlow = static_cast<nsSplittableFrame*>(prev);
|
1998-10-01 01:01:11 +04:00
|
|
|
}
|
2003-01-16 05:59:04 +03:00
|
|
|
NS_POSTCONDITION(firstInFlow, "illegal state in flow chain.");
|
1998-10-01 01:01:11 +04:00
|
|
|
return firstInFlow;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame* nsSplittableFrame::GetLastInFlow() 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-10-01 01:01:11 +04:00
|
|
|
}
|
2003-01-16 05:59:04 +03:00
|
|
|
NS_POSTCONDITION(lastInFlow, "illegal state in flow chain.");
|
1998-10-01 01:01:11 +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)
|
1998-10-01 01:01:11 +04:00
|
|
|
{
|
2006-02-22 00:33:47 +03:00
|
|
|
nsIFrame* prevContinuation = aFrame->GetPrevContinuation();
|
|
|
|
nsIFrame* nextContinuation = aFrame->GetNextContinuation();
|
1998-10-01 01:01:11 +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-10-01 01:01:11 +04:00
|
|
|
}
|
|
|
|
|
1999-10-22 18:53:52 +04:00
|
|
|
aFrame->SetPrevInFlow(nsnull);
|
|
|
|
aFrame->SetNextInFlow(nsnull);
|
1998-10-01 01:01:11 +04:00
|
|
|
}
|
|
|
|
|
1999-11-02 01:12:45 +03:00
|
|
|
#ifdef DEBUG
|
1998-11-19 21:51:53 +03:00
|
|
|
void
|
2009-02-10 07:36:54 +03:00
|
|
|
nsSplittableFrame::DumpBaseRegressionData(nsPresContext* aPresContext, FILE* out, PRInt32 aIndent)
|
1998-11-19 21:51:53 +03:00
|
|
|
{
|
2009-02-10 07:36:54 +03:00
|
|
|
nsFrame::DumpBaseRegressionData(aPresContext, out, aIndent);
|
2006-02-22 00:33:47 +03:00
|
|
|
if (nsnull != mNextContinuation) {
|
1998-11-19 21:51:53 +03:00
|
|
|
IndentBy(out, aIndent);
|
2006-02-22 00:33:47 +03:00
|
|
|
fprintf(out, "<next-continuation va=\"%ld\"/>\n", PRUptrdiff(mNextContinuation));
|
1998-11-19 21:51:53 +03:00
|
|
|
}
|
2006-02-22 00:33:47 +03:00
|
|
|
if (nsnull != mPrevContinuation) {
|
1998-11-19 21:51:53 +03:00
|
|
|
IndentBy(out, aIndent);
|
2006-02-22 00:33:47 +03:00
|
|
|
fprintf(out, "<prev-continuation va=\"%ld\"/>\n", PRUptrdiff(mPrevContinuation));
|
1998-11-19 21:51:53 +03:00
|
|
|
}
|
1999-08-31 07:09:40 +04:00
|
|
|
|
|
|
|
}
|
1999-09-01 05:02:16 +04:00
|
|
|
#endif
|