gecko-dev/layout/generic/nsSplittableFrame.cpp

187 lines
4.8 KiB
C++
Raw Normal View History

1998-04-13 20:24:54 +00:00
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape 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/NPL/
1998-04-13 20:24:54 +00: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-04-13 20:24:54 +00:00
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
1998-04-13 20:24:54 +00:00
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
1998-04-13 20:24:54 +00:00
*/
#include "nsSplittableFrame.h"
#include "nsIContent.h"
#include "nsIPresContext.h"
#include "nsIStyleContext.h"
1998-06-05 21:06:24 +00:00
#include "nsISizeOfHandler.h"
1998-04-13 20:24:54 +00:00
NS_IMETHODIMP
nsSplittableFrame::Init(nsIPresContext* aPresContext,
nsIContent* aContent,
nsIFrame* aParent,
nsIStyleContext* aContext,
nsIFrame* aPrevInFlow)
{
nsresult rv;
rv = nsFrame::Init(aPresContext, aContent, aParent, aContext, aPrevInFlow);
if (aPrevInFlow) {
// Hook the frame into the flow
mPrevInFlow = aPrevInFlow;
aPrevInFlow->SetNextInFlow(this);
// Make sure the general flags bits are the same
nsFrameState state;
aPrevInFlow->GetFrameState(&state);
if ((state & NS_FRAME_SYNC_FRAME_AND_VIEW) == 0) {
mState &= ~NS_FRAME_SYNC_FRAME_AND_VIEW;
}
if (state & NS_FRAME_REPLACED_ELEMENT) {
mState |= NS_FRAME_REPLACED_ELEMENT;
}
if (state & NS_FRAME_SELECTED_CONTENT) {
mState |= NS_FRAME_SELECTED_CONTENT;
}
}
return rv;
}
1998-06-05 21:06:24 +00:00
NS_IMETHODIMP
nsSplittableFrame::IsSplittable(nsSplittableType& aIsSplittable) const
1998-04-13 20:24:54 +00:00
{
aIsSplittable = NS_FRAME_SPLITTABLE;
return NS_OK;
1998-04-13 20:24:54 +00:00
}
NS_METHOD nsSplittableFrame::GetPrevInFlow(nsIFrame** aPrevInFlow) const
1998-04-13 20:24:54 +00:00
{
*aPrevInFlow = mPrevInFlow;
return NS_OK;
1998-04-13 20:24:54 +00:00
}
NS_METHOD nsSplittableFrame::SetPrevInFlow(nsIFrame* aFrame)
1998-04-13 20:24:54 +00:00
{
mPrevInFlow = aFrame;
return NS_OK;
1998-04-13 20:24:54 +00:00
}
NS_METHOD nsSplittableFrame::GetNextInFlow(nsIFrame** aNextInFlow) const
1998-04-13 20:24:54 +00:00
{
*aNextInFlow = mNextInFlow;
return NS_OK;
1998-04-13 20:24:54 +00:00
}
NS_METHOD nsSplittableFrame::SetNextInFlow(nsIFrame* aFrame)
1998-04-13 20:24:54 +00:00
{
mNextInFlow = aFrame;
return NS_OK;
1998-04-13 20:24:54 +00:00
}
nsIFrame* nsSplittableFrame::GetFirstInFlow() const
{
nsSplittableFrame* firstInFlow;
nsSplittableFrame* prevInFlow = (nsSplittableFrame*)this;
while (nsnull!=prevInFlow) {
firstInFlow = prevInFlow;
prevInFlow = (nsSplittableFrame*)firstInFlow->mPrevInFlow;
}
NS_POSTCONDITION(nsnull!=firstInFlow, "illegal state in flow chain.");
return firstInFlow;
}
nsIFrame* nsSplittableFrame::GetLastInFlow() const
{
nsSplittableFrame* lastInFlow;
nsSplittableFrame* nextInFlow = (nsSplittableFrame*)this;
while (nsnull!=nextInFlow) {
lastInFlow = nextInFlow;
nextInFlow = (nsSplittableFrame*)lastInFlow->mNextInFlow;
}
NS_POSTCONDITION(nsnull!=lastInFlow, "illegal state in flow chain.");
return lastInFlow;
}
// Remove this frame from the flow. Connects prev in flow and next in flow
void
nsSplittableFrame::RemoveFromFlow(nsIFrame* aFrame)
1998-04-13 20:24:54 +00:00
{
nsIFrame* prevInFlow;
nsIFrame* nextInFlow;
1998-04-13 20:24:54 +00:00
aFrame->GetPrevInFlow(&prevInFlow);
aFrame->GetNextInFlow(&nextInFlow);
1998-04-13 20:24:54 +00:00
if (prevInFlow) {
prevInFlow->SetNextInFlow(nextInFlow);
1998-04-13 20:24:54 +00:00
}
if (nextInFlow) {
nextInFlow->SetPrevInFlow(prevInFlow);
1998-04-13 20:24:54 +00:00
}
aFrame->SetPrevInFlow(nsnull);
aFrame->SetNextInFlow(nsnull);
1998-04-13 20:24:54 +00:00
}
// Detach from previous frame in flow
void
nsSplittableFrame::BreakFromPrevFlow(nsIFrame* aFrame)
1998-04-13 20:24:54 +00:00
{
nsIFrame* prevInFlow;
1998-04-13 20:24:54 +00:00
aFrame->GetPrevInFlow(&prevInFlow);
if (prevInFlow) {
prevInFlow->SetNextInFlow(nsnull);
aFrame->SetPrevInFlow(nsnull);
1998-04-13 20:24:54 +00:00
}
}
nsIFrame * nsSplittableFrame::GetPrevInFlow()
{
return mPrevInFlow;
}
nsIFrame * nsSplittableFrame::GetNextInFlow()
{
return mNextInFlow;
}
#ifdef DEBUG
void
nsSplittableFrame::DumpBaseRegressionData(nsIPresContext* aPresContext, FILE* out, PRInt32 aIndent, PRBool aIncludeStyleData)
{
nsFrame::DumpBaseRegressionData(aPresContext, out, aIndent, aIncludeStyleData);
if (nsnull != mNextInFlow) {
IndentBy(out, aIndent);
fprintf(out, "<next-in-flow va=\"%ld\"/>\n", PRUptrdiff(mNextInFlow));
}
if (nsnull != mPrevInFlow) {
IndentBy(out, aIndent);
fprintf(out, "<prev-in-flow va=\"%ld\"/>\n", PRUptrdiff(mPrevInFlow));
}
}
NS_IMETHODIMP
nsSplittableFrame::SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const
{
if (!aResult) {
return NS_ERROR_NULL_POINTER;
}
*aResult = sizeof(*this);
return NS_OK;
}
#endif