1998-09-15 04:19:49 +04: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.0 (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/
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* The Original Code is Mozilla Communicator client code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape Communications
|
|
|
|
* Corporation. Portions created by Netscape are Copyright (C) 1998
|
|
|
|
* Netscape Communications Corporation. All Rights Reserved.
|
|
|
|
*/
|
|
|
|
#include "nsLineLayout.h"
|
1998-10-10 02:58:25 +04:00
|
|
|
#include "nsInlineReflow.h"
|
1998-09-15 04:19:49 +04:00
|
|
|
#include "nsStyleConsts.h"
|
|
|
|
#include "nsIStyleContext.h"
|
1998-09-23 06:31:16 +04:00
|
|
|
#include "nsIPresContext.h"
|
|
|
|
#include "nsIFontMetrics.h"
|
1998-09-15 04:19:49 +04:00
|
|
|
|
1998-10-20 04:23:11 +04:00
|
|
|
nsTextRun::nsTextRun()
|
|
|
|
{
|
|
|
|
mNext = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsTextRun::~nsTextRun()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
1998-09-15 04:19:49 +04:00
|
|
|
void
|
|
|
|
nsTextRun::List(FILE* out, PRInt32 aIndent)
|
|
|
|
{
|
|
|
|
PRInt32 i;
|
|
|
|
for (i = aIndent; --i >= 0; ) fputs(" ", out);
|
|
|
|
PRInt32 n = mArray.Count();
|
|
|
|
fprintf(out, "%p: count=%d <", this, n);
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
nsIFrame* text = (nsIFrame*) mArray.ElementAt(i);
|
1998-11-19 20:22:29 +03:00
|
|
|
nsAutoString tmp;
|
|
|
|
text->GetFrameName(tmp);
|
|
|
|
fputs(tmp, out);
|
1998-09-15 04:19:49 +04:00
|
|
|
printf(" ");
|
|
|
|
}
|
|
|
|
fputs(">\n", out);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
1998-09-23 06:31:16 +04:00
|
|
|
nsLineLayout::nsLineLayout(nsIPresContext& aPresContext,
|
|
|
|
nsISpaceManager* aSpaceManager)
|
|
|
|
: mPresContext(aPresContext)
|
1998-09-15 04:19:49 +04:00
|
|
|
{
|
|
|
|
mSpaceManager = aSpaceManager;
|
|
|
|
mListPositionOutside = PR_FALSE;
|
|
|
|
mLineNumber = 0;
|
|
|
|
mColumn = 0;
|
1998-11-01 01:48:56 +03:00
|
|
|
mUnderstandsWhiteSpace = PR_FALSE;
|
|
|
|
mEndsInWhiteSpace = PR_TRUE;
|
1998-09-15 04:19:49 +04:00
|
|
|
|
|
|
|
mTextRuns = nsnull;
|
|
|
|
ResetTextRuns();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsLineLayout::~nsLineLayout()
|
|
|
|
{
|
|
|
|
nsTextRun::DeleteTextRuns(mTextRuns);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsLineLayout::ResetTextRuns()
|
|
|
|
{
|
|
|
|
nsTextRun::DeleteTextRuns(mTextRuns);
|
|
|
|
mTextRuns = nsnull;
|
|
|
|
mTextRunP = &mTextRuns;
|
|
|
|
mNewTextRun = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsTextRun*
|
|
|
|
nsLineLayout::TakeTextRuns()
|
|
|
|
{
|
|
|
|
nsTextRun* result = mTextRuns;
|
|
|
|
mTextRuns = nsnull;
|
|
|
|
ResetTextRuns();
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsLineLayout::EndTextRun()
|
|
|
|
{
|
|
|
|
mNewTextRun = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsLineLayout::AddText(nsIFrame* aTextFrame)
|
|
|
|
{
|
|
|
|
if (nsnull == mNewTextRun) {
|
|
|
|
mNewTextRun = new nsTextRun();
|
|
|
|
if (nsnull == mNewTextRun) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
*mTextRunP = mNewTextRun;
|
|
|
|
mTextRunP = &mNewTextRun->mNext;
|
|
|
|
}
|
|
|
|
mNewTextRun->mArray.AppendElement(aTextFrame);
|
|
|
|
return NS_OK;/* XXX */
|
|
|
|
}
|
|
|
|
|
1998-10-20 04:23:11 +04:00
|
|
|
nsTextRun*
|
|
|
|
nsLineLayout::FindTextRunFor(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
// Only the first-in-flows are present in the text run list so
|
|
|
|
// backup from the argument frame to its first-in-flow.
|
|
|
|
for (;;) {
|
|
|
|
nsIFrame* prevInFlow;
|
|
|
|
aFrame->GetPrevInFlow(prevInFlow);
|
|
|
|
if (nsnull == prevInFlow) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
aFrame = prevInFlow;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now look for the frame in each run
|
|
|
|
nsTextRun* run = mReflowTextRuns;
|
|
|
|
while (nsnull != run) {
|
|
|
|
PRInt32 ix = run->mArray.IndexOf(aFrame);
|
|
|
|
if (ix >= 0) {
|
|
|
|
return run;
|
|
|
|
}
|
|
|
|
run = run->mNext;
|
|
|
|
}
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
1998-10-10 08:35:01 +04:00
|
|
|
nsIFrame*
|
|
|
|
nsLineLayout::FindNextText(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
// Only the first-in-flows are present in the text run list so
|
|
|
|
// backup from the argument frame to its first-in-flow.
|
|
|
|
for (;;) {
|
|
|
|
nsIFrame* prevInFlow;
|
|
|
|
aFrame->GetPrevInFlow(prevInFlow);
|
|
|
|
if (nsnull == prevInFlow) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
aFrame = prevInFlow;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now look for the frame that follows aFrame's first-in-flow
|
|
|
|
nsTextRun* run = mReflowTextRuns;
|
|
|
|
while (nsnull != run) {
|
|
|
|
PRInt32 ix = run->mArray.IndexOf(aFrame);
|
|
|
|
if (ix >= 0) {
|
|
|
|
if (ix < run->mArray.Count() - 1) {
|
|
|
|
return (nsIFrame*) run->mArray[ix + 1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
run = run->mNext;
|
|
|
|
}
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsLineLayout::IsNextWordFrame(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
if (0 != mWordFrames.Count()) {
|
|
|
|
nsIFrame* next = (nsIFrame*) mWordFrames[0];
|
|
|
|
return next == aFrame;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsLineLayout::IsLastWordFrame(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
PRInt32 n = mWordFrames.Count();
|
|
|
|
if (0 != n) {
|
|
|
|
nsIFrame* next = (nsIFrame*) mWordFrames[0];
|
|
|
|
return (next == aFrame) && (1 == n);
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsLineLayout::ForgetWordFrame(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
NS_ASSERTION((void*)aFrame == mWordFrames[0], "forget-word-frame");
|
|
|
|
if (0 != mWordFrames.Count()) {
|
|
|
|
mWordFrames.RemoveElementAt(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-09-15 04:19:49 +04:00
|
|
|
// XXX move this somewhere else!!!
|
|
|
|
PRBool
|
|
|
|
nsLineLayout::TreatFrameAsBlock(const nsStyleDisplay* aDisplay,
|
1998-09-23 06:31:16 +04:00
|
|
|
const nsStylePosition* aPosition)
|
1998-09-15 04:19:49 +04:00
|
|
|
{
|
|
|
|
if (NS_STYLE_POSITION_ABSOLUTE == aPosition->mPosition) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
if (NS_STYLE_FLOAT_NONE != aDisplay->mFloats) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
switch (aDisplay->mDisplay) {
|
|
|
|
case NS_STYLE_DISPLAY_BLOCK:
|
|
|
|
case NS_STYLE_DISPLAY_LIST_ITEM:
|
1998-11-11 06:54:47 +03:00
|
|
|
case NS_STYLE_DISPLAY_RUN_IN:
|
|
|
|
case NS_STYLE_DISPLAY_COMPACT:
|
1998-09-15 04:19:49 +04:00
|
|
|
case NS_STYLE_DISPLAY_TABLE:
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
1998-10-10 02:58:25 +04:00
|
|
|
|
1999-02-01 20:32:49 +03:00
|
|
|
PRBool
|
|
|
|
nsLineLayout::TreatFrameAsBlock(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
const nsStyleDisplay* display;
|
|
|
|
const nsStylePosition* position;
|
|
|
|
aFrame->GetStyleData(eStyleStruct_Display, (const nsStyleStruct*&) display);
|
|
|
|
aFrame->GetStyleData(eStyleStruct_Position,(const nsStyleStruct*&) position);
|
|
|
|
return TreatFrameAsBlock(display, position);
|
|
|
|
}
|
|
|
|
|
1998-10-10 02:58:25 +04:00
|
|
|
void
|
|
|
|
nsLineLayout::UpdateInlines(nscoord aX, nscoord aY,
|
|
|
|
nscoord aWidth, nscoord aHeight,
|
|
|
|
PRBool aIsLeftFloater)
|
|
|
|
{
|
|
|
|
PRInt32 i, n = mInlineStack.Count();
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
nsInlineReflow* ir = (nsInlineReflow*) mInlineStack[i];
|
|
|
|
ir->UpdateBand(aX, aY, aWidth, aHeight, aIsLeftFloater);
|
|
|
|
|
|
|
|
// After the first inline is updated the remainder are relative to
|
|
|
|
// their parent therefore zap the x,y coordinates.
|
|
|
|
|
|
|
|
// XXX border/padding adjustments need to be re-applied for inlines
|
|
|
|
aX = 0;
|
|
|
|
aY = 0;
|
|
|
|
}
|
|
|
|
}
|