2001-09-29 00:14:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2001-10-25 05:08:40 +04:00
|
|
|
// vim:cindent:ts=2:et:sw=2:
|
2001-09-29 00:14:13 +04:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-18 18:30:37 +04:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
1998-12-01 19:13:49 +03: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-12-01 19:13:49 +03: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-12-01 19:13:49 +03:00
|
|
|
*
|
|
|
|
* The Original Code is Mozilla Communicator client 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):
|
2003-01-02 02:53:20 +03:00
|
|
|
* L. David Baron <dbaron@dbaron.org>
|
2000-02-03 01:24:56 +03:00
|
|
|
* Pierre Phaneuf <pp@ludusdesign.com>
|
2001-09-29 00:14:13 +04:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
|
|
|
/* representation of one line within a block frame, a CSS line box */
|
|
|
|
|
1998-12-01 19:13:49 +03:00
|
|
|
#include "nsLineBox.h"
|
1998-12-05 19:01:11 +03:00
|
|
|
#include "nsLineLayout.h"
|
1998-12-01 19:13:49 +03:00
|
|
|
#include "prprf.h"
|
2001-10-25 05:08:40 +04:00
|
|
|
#include "nsBlockFrame.h"
|
2007-01-30 03:06:41 +03:00
|
|
|
#include "nsGkAtoms.h"
|
2005-03-23 06:35:08 +03:00
|
|
|
#include "nsFrameManager.h"
|
2006-03-12 12:49:48 +03:00
|
|
|
#ifdef IBMBIDI
|
|
|
|
#include "nsBidiPresUtils.h"
|
|
|
|
#endif
|
1998-12-01 19:13:49 +03:00
|
|
|
|
1999-10-20 03:04:19 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
static PRInt32 ctorCount;
|
|
|
|
PRInt32 nsLineBox::GetCtorCount() { return ctorCount; }
|
|
|
|
#endif
|
|
|
|
|
1999-10-13 03:24:22 +04:00
|
|
|
nsLineBox::nsLineBox(nsIFrame* aFrame, PRInt32 aCount, PRBool aIsBlock)
|
1999-10-15 03:10:03 +04:00
|
|
|
: mFirstChild(aFrame),
|
|
|
|
mBounds(0, 0, 0, 0),
|
2009-05-05 09:01:47 +04:00
|
|
|
mAscent(0),
|
2001-10-25 05:08:40 +04:00
|
|
|
mData(nsnull)
|
1998-12-01 19:13:49 +03:00
|
|
|
{
|
1999-10-09 00:41:19 +04:00
|
|
|
MOZ_COUNT_CTOR(nsLineBox);
|
1999-10-20 03:04:19 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
++ctorCount;
|
2005-03-23 06:35:08 +03:00
|
|
|
NS_ASSERTION(!aIsBlock || aCount == 1, "Blocks must have exactly one child");
|
|
|
|
nsIFrame* f = aFrame;
|
|
|
|
for (PRInt32 n = aCount; n > 0; f = f->GetNextSibling(), --n) {
|
2007-06-27 06:31:35 +04:00
|
|
|
NS_ASSERTION(aIsBlock == f->GetStyleDisplay()->IsBlockOutside(),
|
2005-03-23 06:35:08 +03:00
|
|
|
"wrong kind of child frame");
|
|
|
|
}
|
1999-10-20 03:04:19 +04:00
|
|
|
#endif
|
1999-10-15 03:10:03 +04:00
|
|
|
|
1999-10-13 03:24:22 +04:00
|
|
|
mAllFlags = 0;
|
1999-10-15 03:10:03 +04:00
|
|
|
#if NS_STYLE_CLEAR_NONE > 0
|
1999-10-13 03:24:22 +04:00
|
|
|
mFlags.mBreakType = NS_STYLE_CLEAR_NONE;
|
1999-10-15 03:10:03 +04:00
|
|
|
#endif
|
|
|
|
SetChildCount(aCount);
|
|
|
|
MarkDirty();
|
|
|
|
mFlags.mBlock = aIsBlock;
|
1998-12-01 19:13:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsLineBox::~nsLineBox()
|
|
|
|
{
|
1999-10-09 00:41:19 +04:00
|
|
|
MOZ_COUNT_DTOR(nsLineBox);
|
1999-10-20 03:04:19 +04:00
|
|
|
Cleanup();
|
|
|
|
}
|
1999-10-15 03:10:03 +04:00
|
|
|
|
2000-03-12 06:00:51 +03:00
|
|
|
nsLineBox*
|
|
|
|
NS_NewLineBox(nsIPresShell* aPresShell, nsIFrame* aFrame,
|
|
|
|
PRInt32 aCount, PRBool aIsBlock)
|
|
|
|
{
|
|
|
|
return new (aPresShell)nsLineBox(aFrame, aCount, aIsBlock);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Overloaded new operator. Uses an arena (which comes from the presShell)
|
|
|
|
// to perform the allocation.
|
2009-08-18 07:21:06 +04:00
|
|
|
void*
|
2002-07-03 00:25:30 +04:00
|
|
|
nsLineBox::operator new(size_t sz, nsIPresShell* aPresShell) CPP_THROW_NEW
|
2000-03-12 06:00:51 +03:00
|
|
|
{
|
2009-08-18 07:21:06 +04:00
|
|
|
return aPresShell->AllocateMisc(sz);
|
2000-03-12 06:00:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Overloaded delete operator. Doesn't actually free the memory, because we
|
|
|
|
// use an arena
|
2009-08-18 07:21:06 +04:00
|
|
|
void
|
2000-03-12 06:00:51 +03:00
|
|
|
nsLineBox::operator delete(void* aPtr, size_t sz)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsLineBox::Destroy(nsIPresShell* aPresShell)
|
|
|
|
{
|
|
|
|
// Destroy the object. This won't actually free the memory, though
|
|
|
|
delete this;
|
|
|
|
|
|
|
|
// Have the pres shell recycle the memory
|
2009-08-18 07:21:06 +04:00
|
|
|
aPresShell->FreeMisc(sizeof(*this), (void*)this);
|
2000-03-12 06:00:51 +03:00
|
|
|
}
|
|
|
|
|
1999-10-20 03:04:19 +04:00
|
|
|
void
|
|
|
|
nsLineBox::Cleanup()
|
|
|
|
{
|
1999-10-29 18:35:36 +04:00
|
|
|
if (mData) {
|
|
|
|
if (IsBlock()) {
|
1999-10-15 03:10:03 +04:00
|
|
|
delete mBlockData;
|
|
|
|
}
|
1999-10-29 18:35:36 +04:00
|
|
|
else {
|
1999-10-15 03:10:03 +04:00
|
|
|
delete mInlineData;
|
|
|
|
}
|
1999-10-29 18:35:36 +04:00
|
|
|
mData = nsnull;
|
1999-10-15 03:10:03 +04:00
|
|
|
}
|
1999-10-20 03:04:19 +04:00
|
|
|
}
|
|
|
|
|
1999-11-02 01:12:45 +03:00
|
|
|
#ifdef DEBUG
|
1998-12-01 19:13:49 +03:00
|
|
|
static void
|
2003-10-14 01:51:02 +04:00
|
|
|
ListFloats(FILE* out, PRInt32 aIndent, const nsFloatCacheList& aFloats)
|
1998-12-01 19:13:49 +03:00
|
|
|
{
|
2003-10-14 01:51:02 +04:00
|
|
|
nsFloatCache* fc = aFloats.Head();
|
1999-09-15 04:28:10 +04:00
|
|
|
while (fc) {
|
|
|
|
nsFrame::IndentBy(out, aIndent);
|
|
|
|
nsPlaceholderFrame* ph = fc->mPlaceholder;
|
2007-07-22 17:37:36 +04:00
|
|
|
if (ph) {
|
2007-07-08 11:08:04 +04:00
|
|
|
fprintf(out, "placeholder@%p ", static_cast<void*>(ph));
|
1999-04-23 18:34:48 +04:00
|
|
|
nsIFrame* frame = ph->GetOutOfFlowFrame();
|
2007-07-22 17:37:36 +04:00
|
|
|
if (frame) {
|
2009-08-21 01:52:48 +04:00
|
|
|
nsAutoString frameName;
|
|
|
|
frame->GetFrameName(frameName);
|
|
|
|
fputs(NS_LossyConvertUTF16toASCII(frameName).get(), out);
|
1998-12-01 19:13:49 +03:00
|
|
|
}
|
1999-09-21 04:12:27 +04:00
|
|
|
|
2007-07-22 17:37:36 +04:00
|
|
|
if (!frame) {
|
|
|
|
fputs("\n###!!! NULL out-of-flow frame", out);
|
|
|
|
}
|
1999-03-19 00:03:25 +03:00
|
|
|
fprintf(out, "\n");
|
1998-12-01 19:13:49 +03:00
|
|
|
}
|
1999-09-15 04:28:10 +04:00
|
|
|
fc = fc->Next();
|
1998-12-01 19:13:49 +03:00
|
|
|
}
|
|
|
|
}
|
1999-11-02 01:12:45 +03:00
|
|
|
#endif
|
1998-12-01 19:13:49 +03:00
|
|
|
|
2001-10-25 05:08:40 +04:00
|
|
|
#ifdef DEBUG
|
2002-01-09 06:04:29 +03:00
|
|
|
const char *
|
|
|
|
BreakTypeToString(PRUint8 aBreakType)
|
|
|
|
{
|
|
|
|
switch (aBreakType) {
|
|
|
|
case NS_STYLE_CLEAR_NONE: return "nobr";
|
|
|
|
case NS_STYLE_CLEAR_LEFT: return "leftbr";
|
|
|
|
case NS_STYLE_CLEAR_RIGHT: return "rightbr";
|
|
|
|
case NS_STYLE_CLEAR_LEFT_AND_RIGHT: return "leftbr+rightbr";
|
|
|
|
case NS_STYLE_CLEAR_LINE: return "linebr";
|
|
|
|
case NS_STYLE_CLEAR_BLOCK: return "blockbr";
|
|
|
|
case NS_STYLE_CLEAR_COLUMN: return "columnbr";
|
|
|
|
case NS_STYLE_CLEAR_PAGE: return "pagebr";
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return "unknown";
|
|
|
|
}
|
|
|
|
|
1998-12-01 19:13:49 +03:00
|
|
|
char*
|
|
|
|
nsLineBox::StateToString(char* aBuf, PRInt32 aBufSize) const
|
|
|
|
{
|
2004-11-25 17:51:00 +03:00
|
|
|
PR_snprintf(aBuf, aBufSize, "%s,%s,%s,%s,%s,before:%s,after:%s[0x%x]",
|
1999-10-13 03:24:22 +04:00
|
|
|
IsBlock() ? "block" : "inline",
|
2000-03-23 02:19:10 +03:00
|
|
|
IsDirty() ? "dirty" : "clean",
|
2001-10-25 05:08:40 +04:00
|
|
|
IsPreviousMarginDirty() ? "prevmargindirty" : "prevmarginclean",
|
2003-10-14 01:51:02 +04:00
|
|
|
IsImpactedByFloat() ? "impacted" : "not impacted",
|
2002-01-09 06:04:29 +03:00
|
|
|
IsLineWrapped() ? "wrapped" : "not wrapped",
|
2004-11-25 17:51:00 +03:00
|
|
|
BreakTypeToString(GetBreakTypeBefore()),
|
|
|
|
BreakTypeToString(GetBreakTypeAfter()),
|
1999-10-13 03:24:22 +04:00
|
|
|
mAllFlags);
|
1998-12-01 19:13:49 +03:00
|
|
|
return aBuf;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2005-09-07 01:34:50 +04:00
|
|
|
nsLineBox::List(FILE* out, PRInt32 aIndent) const
|
1998-12-01 19:13:49 +03:00
|
|
|
{
|
|
|
|
PRInt32 i;
|
|
|
|
|
1999-01-16 03:00:50 +03:00
|
|
|
for (i = aIndent; --i >= 0; ) fputs(" ", out);
|
|
|
|
char cbuf[100];
|
|
|
|
fprintf(out, "line %p: count=%d state=%s ",
|
2007-07-08 11:08:04 +04:00
|
|
|
static_cast<const void*>(this), GetChildCount(),
|
2001-10-25 05:08:40 +04:00
|
|
|
StateToString(cbuf, sizeof(cbuf)));
|
|
|
|
if (IsBlock() && !GetCarriedOutBottomMargin().IsZero()) {
|
|
|
|
fprintf(out, "bm=%d ", GetCarriedOutBottomMargin().get());
|
1999-01-16 03:00:50 +03:00
|
|
|
}
|
1999-10-15 03:10:03 +04:00
|
|
|
fprintf(out, "{%d,%d,%d,%d} ",
|
|
|
|
mBounds.x, mBounds.y, mBounds.width, mBounds.height);
|
|
|
|
if (mData) {
|
|
|
|
fprintf(out, "ca={%d,%d,%d,%d} ",
|
|
|
|
mData->mCombinedArea.x, mData->mCombinedArea.y,
|
|
|
|
mData->mCombinedArea.width, mData->mCombinedArea.height);
|
|
|
|
}
|
|
|
|
fprintf(out, "<\n");
|
1998-12-01 19:13:49 +03:00
|
|
|
|
|
|
|
nsIFrame* frame = mFirstChild;
|
1999-10-15 03:10:03 +04:00
|
|
|
PRInt32 n = GetChildCount();
|
1998-12-01 19:13:49 +03:00
|
|
|
while (--n >= 0) {
|
2009-08-21 01:52:48 +04:00
|
|
|
frame->List(out, aIndent + 1);
|
2003-06-30 14:46:59 +04:00
|
|
|
frame = frame->GetNextSibling();
|
1998-12-01 19:13:49 +03:00
|
|
|
}
|
|
|
|
|
1999-01-16 03:00:50 +03:00
|
|
|
for (i = aIndent; --i >= 0; ) fputs(" ", out);
|
2003-10-14 01:51:02 +04:00
|
|
|
if (HasFloats()) {
|
|
|
|
fputs("> floats <\n", out);
|
|
|
|
ListFloats(out, aIndent + 1, mInlineData->mFloats);
|
1998-12-01 19:13:49 +03:00
|
|
|
for (i = aIndent; --i >= 0; ) fputs(" ", out);
|
|
|
|
}
|
1999-01-16 03:00:50 +03:00
|
|
|
fputs(">\n", out);
|
1998-12-01 19:13:49 +03:00
|
|
|
}
|
1999-11-02 01:12:45 +03:00
|
|
|
#endif
|
1998-12-01 19:13:49 +03:00
|
|
|
|
|
|
|
nsIFrame*
|
|
|
|
nsLineBox::LastChild() const
|
|
|
|
{
|
|
|
|
nsIFrame* frame = mFirstChild;
|
1999-10-15 03:10:03 +04:00
|
|
|
PRInt32 n = GetChildCount() - 1;
|
1998-12-01 19:13:49 +03:00
|
|
|
while (--n >= 0) {
|
2003-06-30 14:46:59 +04:00
|
|
|
frame = frame->GetNextSibling();
|
1998-12-01 19:13:49 +03:00
|
|
|
}
|
|
|
|
return frame;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsLineBox::IsLastChild(nsIFrame* aFrame) const
|
|
|
|
{
|
|
|
|
nsIFrame* lastFrame = LastChild();
|
|
|
|
return aFrame == lastFrame;
|
|
|
|
}
|
|
|
|
|
1999-04-21 01:52:22 +04:00
|
|
|
PRInt32
|
|
|
|
nsLineBox::IndexOf(nsIFrame* aFrame) const
|
1998-12-01 19:13:49 +03:00
|
|
|
{
|
1999-10-15 03:10:03 +04:00
|
|
|
PRInt32 i, n = GetChildCount();
|
1998-12-01 19:13:49 +03:00
|
|
|
nsIFrame* frame = mFirstChild;
|
1999-04-21 01:52:22 +04:00
|
|
|
for (i = 0; i < n; i++) {
|
1998-12-01 19:13:49 +03:00
|
|
|
if (frame == aFrame) {
|
1999-04-21 01:52:22 +04:00
|
|
|
return i;
|
1998-12-01 19:13:49 +03:00
|
|
|
}
|
2003-06-30 14:46:59 +04:00
|
|
|
frame = frame->GetNextSibling();
|
1998-12-01 19:13:49 +03:00
|
|
|
}
|
1999-04-21 01:52:22 +04:00
|
|
|
return -1;
|
1998-12-01 19:13:49 +03:00
|
|
|
}
|
|
|
|
|
2003-11-11 02:36:06 +03:00
|
|
|
PRBool
|
|
|
|
nsLineBox::IsEmpty() const
|
2001-10-25 05:08:40 +04:00
|
|
|
{
|
|
|
|
if (IsBlock())
|
2003-11-11 02:36:06 +03:00
|
|
|
return mFirstChild->IsEmpty();
|
2001-10-25 05:08:40 +04:00
|
|
|
|
|
|
|
PRInt32 n;
|
|
|
|
nsIFrame *kid;
|
|
|
|
for (n = GetChildCount(), kid = mFirstChild;
|
|
|
|
n > 0;
|
2003-06-30 14:46:59 +04:00
|
|
|
--n, kid = kid->GetNextSibling())
|
2001-10-25 05:08:40 +04:00
|
|
|
{
|
2003-11-11 02:36:06 +03:00
|
|
|
if (!kid->IsEmpty())
|
|
|
|
return PR_FALSE;
|
2001-10-25 05:08:40 +04:00
|
|
|
}
|
2009-08-11 06:48:42 +04:00
|
|
|
if (HasBullet()) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2003-11-11 02:36:06 +03:00
|
|
|
return PR_TRUE;
|
2001-10-25 05:08:40 +04:00
|
|
|
}
|
|
|
|
|
2004-11-24 16:22:10 +03:00
|
|
|
PRBool
|
|
|
|
nsLineBox::CachedIsEmpty()
|
|
|
|
{
|
|
|
|
if (mFlags.mDirty) {
|
|
|
|
return IsEmpty();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mFlags.mEmptyCacheValid) {
|
|
|
|
return mFlags.mEmptyCacheState;
|
|
|
|
}
|
|
|
|
|
2006-02-27 07:15:05 +03:00
|
|
|
PRBool result;
|
|
|
|
if (IsBlock()) {
|
|
|
|
result = mFirstChild->CachedIsEmpty();
|
|
|
|
} else {
|
|
|
|
PRInt32 n;
|
|
|
|
nsIFrame *kid;
|
|
|
|
result = PR_TRUE;
|
|
|
|
for (n = GetChildCount(), kid = mFirstChild;
|
|
|
|
n > 0;
|
|
|
|
--n, kid = kid->GetNextSibling())
|
|
|
|
{
|
|
|
|
if (!kid->CachedIsEmpty()) {
|
|
|
|
result = PR_FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2009-08-11 06:48:42 +04:00
|
|
|
if (HasBullet()) {
|
|
|
|
result = PR_FALSE;
|
|
|
|
}
|
2006-02-27 07:15:05 +03:00
|
|
|
}
|
|
|
|
|
2004-11-24 16:22:10 +03:00
|
|
|
mFlags.mEmptyCacheValid = PR_TRUE;
|
|
|
|
mFlags.mEmptyCacheState = result;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1998-12-01 19:13:49 +03:00
|
|
|
void
|
2004-08-01 03:15:21 +04:00
|
|
|
nsLineBox::DeleteLineList(nsPresContext* aPresContext, nsLineList& aLines)
|
1998-12-01 19:13:49 +03:00
|
|
|
{
|
2001-10-25 05:08:40 +04:00
|
|
|
if (! aLines.empty()) {
|
1998-12-01 19:13:49 +03:00
|
|
|
// Delete our child frames before doing anything else. In particular
|
|
|
|
// we do all of this before our base class releases it's hold on the
|
|
|
|
// view.
|
2001-10-25 05:08:40 +04:00
|
|
|
for (nsIFrame* child = aLines.front()->mFirstChild; child; ) {
|
2003-06-30 14:46:59 +04:00
|
|
|
nsIFrame* nextChild = child->GetNextSibling();
|
2006-04-10 04:16:29 +04:00
|
|
|
child->Destroy();
|
1998-12-01 19:13:49 +03:00
|
|
|
child = nextChild;
|
|
|
|
}
|
|
|
|
|
2003-12-21 08:36:36 +03:00
|
|
|
nsIPresShell *shell = aPresContext->PresShell();
|
2002-04-13 22:54:40 +04:00
|
|
|
|
|
|
|
do {
|
2001-10-25 05:08:40 +04:00
|
|
|
nsLineBox* line = aLines.front();
|
|
|
|
aLines.pop_front();
|
2002-04-13 22:54:40 +04:00
|
|
|
line->Destroy(shell);
|
|
|
|
} while (! aLines.empty());
|
1998-12-01 19:13:49 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsLineBox*
|
2001-10-25 05:08:40 +04:00
|
|
|
nsLineBox::FindLineContaining(nsLineList& aLines, nsIFrame* aFrame,
|
|
|
|
PRInt32* aFrameIndexInLine)
|
1998-12-01 19:13:49 +03:00
|
|
|
{
|
2001-10-25 05:08:40 +04:00
|
|
|
NS_PRECONDITION(aFrameIndexInLine && !aLines.empty() && aFrame, "null ptr");
|
|
|
|
for (nsLineList::iterator line = aLines.begin(),
|
|
|
|
line_end = aLines.end();
|
|
|
|
line != line_end;
|
|
|
|
++line)
|
|
|
|
{
|
|
|
|
PRInt32 ix = line->IndexOf(aFrame);
|
|
|
|
if (ix >= 0) {
|
|
|
|
*aFrameIndexInLine = ix;
|
|
|
|
return line;
|
1998-12-01 19:13:49 +03:00
|
|
|
}
|
|
|
|
}
|
2001-10-25 05:08:40 +04:00
|
|
|
*aFrameIndexInLine = -1;
|
|
|
|
return nsnull;
|
1998-12-01 19:13:49 +03:00
|
|
|
}
|
|
|
|
|
2001-10-25 05:08:40 +04:00
|
|
|
PRBool
|
|
|
|
nsLineBox::RFindLineContaining(nsIFrame* aFrame,
|
|
|
|
const nsLineList::iterator& aBegin,
|
|
|
|
nsLineList::iterator& aEnd,
|
|
|
|
PRInt32* aFrameIndexInLine)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aFrame, "null ptr");
|
|
|
|
while (aBegin != aEnd) {
|
|
|
|
--aEnd;
|
|
|
|
PRInt32 ix = aEnd->IndexOf(aFrame);
|
1999-04-21 01:52:22 +04:00
|
|
|
if (ix >= 0) {
|
|
|
|
*aFrameIndexInLine = ix;
|
2001-10-25 05:08:40 +04:00
|
|
|
return PR_TRUE;
|
1998-12-01 19:13:49 +03:00
|
|
|
}
|
|
|
|
}
|
1999-04-21 01:52:22 +04:00
|
|
|
*aFrameIndexInLine = -1;
|
2001-10-25 05:08:40 +04:00
|
|
|
return PR_FALSE;
|
1998-12-01 19:13:49 +03:00
|
|
|
}
|
|
|
|
|
2001-10-25 05:08:40 +04:00
|
|
|
nsCollapsingMargin
|
1999-10-15 03:10:03 +04:00
|
|
|
nsLineBox::GetCarriedOutBottomMargin() const
|
|
|
|
{
|
2001-10-25 05:08:40 +04:00
|
|
|
NS_ASSERTION(IsBlock(),
|
|
|
|
"GetCarriedOutBottomMargin called on non-block line.");
|
|
|
|
return (IsBlock() && mBlockData)
|
|
|
|
? mBlockData->mCarriedOutBottomMargin
|
|
|
|
: nsCollapsingMargin();
|
1999-10-15 03:10:03 +04:00
|
|
|
}
|
|
|
|
|
2004-09-18 18:39:07 +04:00
|
|
|
PRBool
|
2001-10-25 05:08:40 +04:00
|
|
|
nsLineBox::SetCarriedOutBottomMargin(nsCollapsingMargin aValue)
|
1999-10-15 03:10:03 +04:00
|
|
|
{
|
2004-09-18 18:39:07 +04:00
|
|
|
PRBool changed = PR_FALSE;
|
1999-10-15 03:10:03 +04:00
|
|
|
if (IsBlock()) {
|
2004-09-18 18:39:07 +04:00
|
|
|
if (!aValue.IsZero()) {
|
1999-10-15 03:10:03 +04:00
|
|
|
if (!mBlockData) {
|
|
|
|
mBlockData = new ExtraBlockData(mBounds);
|
|
|
|
}
|
|
|
|
if (mBlockData) {
|
2004-09-18 18:39:07 +04:00
|
|
|
changed = aValue != mBlockData->mCarriedOutBottomMargin;
|
1999-10-15 03:10:03 +04:00
|
|
|
mBlockData->mCarriedOutBottomMargin = aValue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (mBlockData) {
|
2004-09-18 18:39:07 +04:00
|
|
|
changed = aValue != mBlockData->mCarriedOutBottomMargin;
|
1999-10-15 03:10:03 +04:00
|
|
|
mBlockData->mCarriedOutBottomMargin = aValue;
|
|
|
|
MaybeFreeData();
|
|
|
|
}
|
|
|
|
}
|
2004-09-18 18:39:07 +04:00
|
|
|
return changed;
|
1999-10-15 03:10:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsLineBox::MaybeFreeData()
|
|
|
|
{
|
|
|
|
if (mData && (mData->mCombinedArea == mBounds)) {
|
|
|
|
if (IsInline()) {
|
2003-10-14 01:51:02 +04:00
|
|
|
if (mInlineData->mFloats.IsEmpty()) {
|
1999-10-15 03:10:03 +04:00
|
|
|
delete mInlineData;
|
|
|
|
mInlineData = nsnull;
|
|
|
|
}
|
|
|
|
}
|
2001-10-25 05:08:40 +04:00
|
|
|
else if (mBlockData->mCarriedOutBottomMargin.IsZero()) {
|
1999-10-15 03:10:03 +04:00
|
|
|
delete mBlockData;
|
|
|
|
mBlockData = nsnull;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// XXX get rid of this???
|
2003-10-14 01:51:02 +04:00
|
|
|
nsFloatCache*
|
|
|
|
nsLineBox::GetFirstFloat()
|
1999-10-15 03:10:03 +04:00
|
|
|
{
|
2003-10-14 01:51:02 +04:00
|
|
|
NS_ABORT_IF_FALSE(IsInline(), "block line can't have floats");
|
|
|
|
return mInlineData ? mInlineData->mFloats.Head() : nsnull;
|
1999-10-15 03:10:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// XXX this might be too eager to free memory
|
|
|
|
void
|
2003-10-14 01:51:02 +04:00
|
|
|
nsLineBox::FreeFloats(nsFloatCacheFreeList& aFreeList)
|
1999-10-15 03:10:03 +04:00
|
|
|
{
|
2003-10-14 01:51:02 +04:00
|
|
|
NS_ABORT_IF_FALSE(IsInline(), "block line can't have floats");
|
2006-04-17 05:47:11 +04:00
|
|
|
if (IsInline() && mInlineData) {
|
|
|
|
if (mInlineData->mFloats.NotEmpty()) {
|
2003-10-14 01:51:02 +04:00
|
|
|
aFreeList.Append(mInlineData->mFloats);
|
1999-10-15 03:10:03 +04:00
|
|
|
}
|
2006-04-17 05:47:11 +04:00
|
|
|
MaybeFreeData();
|
1999-10-15 03:10:03 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2003-10-14 01:51:02 +04:00
|
|
|
nsLineBox::AppendFloats(nsFloatCacheFreeList& aFreeList)
|
2000-03-23 02:19:10 +03:00
|
|
|
{
|
2003-10-14 01:51:02 +04:00
|
|
|
NS_ABORT_IF_FALSE(IsInline(), "block line can't have floats");
|
1999-10-15 03:10:03 +04:00
|
|
|
if (IsInline()) {
|
|
|
|
if (aFreeList.NotEmpty()) {
|
|
|
|
if (!mInlineData) {
|
|
|
|
mInlineData = new ExtraInlineData(mBounds);
|
|
|
|
}
|
|
|
|
if (mInlineData) {
|
2003-10-14 01:51:02 +04:00
|
|
|
mInlineData->mFloats.Append(aFreeList);
|
1999-10-15 03:10:03 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-12-05 19:01:11 +03:00
|
|
|
PRBool
|
2003-10-14 01:51:02 +04:00
|
|
|
nsLineBox::RemoveFloat(nsIFrame* aFrame)
|
1998-12-05 19:01:11 +03:00
|
|
|
{
|
2003-10-14 01:51:02 +04:00
|
|
|
NS_ABORT_IF_FALSE(IsInline(), "block line can't have floats");
|
1999-10-15 03:10:03 +04:00
|
|
|
if (IsInline() && mInlineData) {
|
2003-10-14 01:51:02 +04:00
|
|
|
nsFloatCache* fc = mInlineData->mFloats.Find(aFrame);
|
1999-10-15 03:10:03 +04:00
|
|
|
if (fc) {
|
|
|
|
// Note: the placeholder is part of the line's child list
|
|
|
|
// and will be removed later.
|
2003-10-14 01:51:02 +04:00
|
|
|
mInlineData->mFloats.Remove(fc);
|
2005-10-22 02:23:28 +04:00
|
|
|
delete fc;
|
1999-10-15 03:10:03 +04:00
|
|
|
MaybeFreeData();
|
2000-01-29 03:17:04 +03:00
|
|
|
return PR_TRUE;
|
1999-10-15 03:10:03 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsLineBox::SetCombinedArea(const nsRect& aCombinedArea)
|
2000-03-23 02:19:10 +03:00
|
|
|
{
|
2000-02-23 01:05:04 +03:00
|
|
|
NS_ASSERTION(aCombinedArea.width >= 0, "illegal width for combined area");
|
|
|
|
NS_ASSERTION(aCombinedArea.height >= 0, "illegal height for combined area");
|
1999-10-15 03:10:03 +04:00
|
|
|
if (aCombinedArea != mBounds) {
|
|
|
|
if (mData) {
|
|
|
|
mData->mCombinedArea = aCombinedArea;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (IsInline()) {
|
|
|
|
mInlineData = new ExtraInlineData(aCombinedArea);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mBlockData = new ExtraBlockData(aCombinedArea);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (mData) {
|
|
|
|
// Store away new value so that MaybeFreeData compares against
|
|
|
|
// the right value.
|
|
|
|
mData->mCombinedArea = aCombinedArea;
|
|
|
|
}
|
|
|
|
MaybeFreeData();
|
|
|
|
}
|
1998-12-05 19:01:11 +03:00
|
|
|
}
|
1999-05-11 02:28:49 +04:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
1999-05-13 04:54:28 +04:00
|
|
|
|
1999-05-11 02:28:49 +04:00
|
|
|
static nsLineBox* gDummyLines[1];
|
|
|
|
|
|
|
|
nsLineIterator::nsLineIterator()
|
|
|
|
{
|
1999-05-13 04:54:28 +04:00
|
|
|
mLines = gDummyLines;
|
1999-05-11 02:28:49 +04:00
|
|
|
mNumLines = 0;
|
|
|
|
mIndex = 0;
|
1999-05-13 04:54:28 +04:00
|
|
|
mRightToLeft = PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsLineIterator::~nsLineIterator()
|
|
|
|
{
|
|
|
|
if (mLines != gDummyLines) {
|
|
|
|
delete [] mLines;
|
|
|
|
}
|
1999-05-11 02:28:49 +04:00
|
|
|
}
|
|
|
|
|
2008-10-30 22:17:59 +03:00
|
|
|
/* virtual */ void
|
|
|
|
nsLineIterator::DisposeLineIterator()
|
|
|
|
{
|
|
|
|
delete this;
|
|
|
|
}
|
1999-05-13 04:54:28 +04:00
|
|
|
|
1999-05-11 02:28:49 +04:00
|
|
|
nsresult
|
2001-10-25 05:08:40 +04:00
|
|
|
nsLineIterator::Init(nsLineList& aLines, PRBool aRightToLeft)
|
1999-05-11 02:28:49 +04:00
|
|
|
{
|
1999-05-13 04:54:28 +04:00
|
|
|
mRightToLeft = aRightToLeft;
|
|
|
|
|
1999-05-11 02:28:49 +04:00
|
|
|
// Count the lines
|
2001-10-25 05:08:40 +04:00
|
|
|
PRInt32 numLines = aLines.size();
|
1999-05-11 02:28:49 +04:00
|
|
|
if (0 == numLines) {
|
|
|
|
// Use gDummyLines so that we don't need null pointer checks in
|
|
|
|
// the accessor methods
|
|
|
|
mLines = gDummyLines;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make a linear array of the lines
|
|
|
|
mLines = new nsLineBox*[numLines];
|
|
|
|
if (!mLines) {
|
|
|
|
// Use gDummyLines so that we don't need null pointer checks in
|
|
|
|
// the accessor methods
|
|
|
|
mLines = gDummyLines;
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
nsLineBox** lp = mLines;
|
2001-10-25 05:08:40 +04:00
|
|
|
for (nsLineList::iterator line = aLines.begin(), line_end = aLines.end() ;
|
|
|
|
line != line_end;
|
|
|
|
++line)
|
|
|
|
{
|
1999-05-11 02:28:49 +04:00
|
|
|
*lp++ = line;
|
|
|
|
}
|
|
|
|
mNumLines = numLines;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-10-30 22:17:59 +03:00
|
|
|
PRInt32
|
|
|
|
nsLineIterator::GetNumLines()
|
1999-05-11 02:28:49 +04:00
|
|
|
{
|
2008-10-30 22:17:59 +03:00
|
|
|
return mNumLines;
|
1999-05-13 04:54:28 +04:00
|
|
|
}
|
|
|
|
|
2008-10-30 22:17:59 +03:00
|
|
|
PRBool
|
|
|
|
nsLineIterator::GetDirection()
|
1999-05-13 04:54:28 +04:00
|
|
|
{
|
2008-10-30 22:17:59 +03:00
|
|
|
return mRightToLeft;
|
1999-05-13 04:54:28 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLineIterator::GetLine(PRInt32 aLineNumber,
|
|
|
|
nsIFrame** aFirstFrameOnLine,
|
|
|
|
PRInt32* aNumFramesOnLine,
|
1999-10-13 03:24:22 +04:00
|
|
|
nsRect& aLineBounds,
|
|
|
|
PRUint32* aLineFlags)
|
1999-05-13 04:54:28 +04:00
|
|
|
{
|
1999-10-13 03:24:22 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aFirstFrameOnLine);
|
|
|
|
NS_ENSURE_ARG_POINTER(aNumFramesOnLine);
|
|
|
|
NS_ENSURE_ARG_POINTER(aLineFlags);
|
|
|
|
|
1999-05-13 04:54:28 +04:00
|
|
|
if ((aLineNumber < 0) || (aLineNumber >= mNumLines)) {
|
|
|
|
*aFirstFrameOnLine = nsnull;
|
|
|
|
*aNumFramesOnLine = 0;
|
|
|
|
aLineBounds.SetRect(0, 0, 0, 0);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
nsLineBox* line = mLines[aLineNumber];
|
|
|
|
*aFirstFrameOnLine = line->mFirstChild;
|
1999-10-15 03:10:03 +04:00
|
|
|
*aNumFramesOnLine = line->GetChildCount();
|
1999-05-13 04:54:28 +04:00
|
|
|
aLineBounds = line->mBounds;
|
1999-10-13 03:24:22 +04:00
|
|
|
|
|
|
|
PRUint32 flags = 0;
|
|
|
|
if (line->IsBlock()) {
|
|
|
|
flags |= NS_LINE_FLAG_IS_BLOCK;
|
|
|
|
}
|
|
|
|
else {
|
2004-11-25 17:51:00 +03:00
|
|
|
if (line->HasBreakAfter())
|
1999-10-13 03:24:22 +04:00
|
|
|
flags |= NS_LINE_FLAG_ENDS_IN_BREAK;
|
|
|
|
}
|
|
|
|
*aLineFlags = flags;
|
|
|
|
|
1999-05-13 04:54:28 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-10-30 22:17:59 +03:00
|
|
|
PRInt32
|
|
|
|
nsLineIterator::FindLineContaining(nsIFrame* aFrame)
|
1999-05-13 04:54:28 +04:00
|
|
|
{
|
|
|
|
nsLineBox* line = mLines[0];
|
|
|
|
PRInt32 lineNumber = 0;
|
2001-10-25 05:08:40 +04:00
|
|
|
while (lineNumber != mNumLines) {
|
1999-05-13 04:54:28 +04:00
|
|
|
if (line->Contains(aFrame)) {
|
2008-10-30 22:17:59 +03:00
|
|
|
return lineNumber;
|
1999-05-13 04:54:28 +04:00
|
|
|
}
|
2001-10-25 05:08:40 +04:00
|
|
|
line = mLines[++lineNumber];
|
1999-05-13 04:54:28 +04:00
|
|
|
}
|
2008-10-30 22:17:59 +03:00
|
|
|
return -1;
|
1999-05-13 04:54:28 +04:00
|
|
|
}
|
|
|
|
|
2008-10-30 22:17:59 +03:00
|
|
|
/* virtual */ PRInt32
|
|
|
|
nsLineIterator::FindLineAt(nscoord aY)
|
1999-05-13 04:54:28 +04:00
|
|
|
{
|
|
|
|
nsLineBox* line = mLines[0];
|
|
|
|
if (!line || (aY < line->mBounds.y)) {
|
2008-10-30 22:17:59 +03:00
|
|
|
return -1;
|
1999-05-13 04:54:28 +04:00
|
|
|
}
|
|
|
|
PRInt32 lineNumber = 0;
|
2001-10-25 05:08:40 +04:00
|
|
|
while (lineNumber != mNumLines) {
|
1999-05-13 04:54:28 +04:00
|
|
|
if ((aY >= line->mBounds.y) && (aY < line->mBounds.YMost())) {
|
2008-10-30 22:17:59 +03:00
|
|
|
return lineNumber;
|
1999-05-13 04:54:28 +04:00
|
|
|
}
|
2001-10-25 05:08:40 +04:00
|
|
|
line = mLines[++lineNumber];
|
1999-05-11 02:28:49 +04:00
|
|
|
}
|
2008-10-30 22:17:59 +03:00
|
|
|
return mNumLines;
|
1999-05-13 04:54:28 +04:00
|
|
|
}
|
|
|
|
|
2001-03-09 06:29:00 +03:00
|
|
|
#ifdef IBMBIDI
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLineIterator::CheckLineOrder(PRInt32 aLine,
|
|
|
|
PRBool *aIsReordered,
|
|
|
|
nsIFrame **aFirstVisual,
|
|
|
|
nsIFrame **aLastVisual)
|
|
|
|
{
|
2006-03-20 12:20:49 +03:00
|
|
|
NS_ASSERTION (aLine >= 0 && aLine < mNumLines, "aLine out of range!");
|
2006-03-12 12:49:48 +03:00
|
|
|
nsLineBox* line = mLines[aLine];
|
2006-03-20 12:20:49 +03:00
|
|
|
|
|
|
|
if (!line->mFirstChild) { // empty line
|
|
|
|
*aIsReordered = PR_FALSE;
|
2006-08-04 09:40:57 +04:00
|
|
|
*aFirstVisual = nsnull;
|
|
|
|
*aLastVisual = nsnull;
|
2006-03-20 12:20:49 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2006-03-12 12:49:48 +03:00
|
|
|
|
2007-03-31 01:11:41 +04:00
|
|
|
nsPresContext* presContext = line->mFirstChild->PresContext();
|
2001-03-09 06:29:00 +03:00
|
|
|
|
2006-03-12 12:49:48 +03:00
|
|
|
nsBidiPresUtils* bidiUtils = presContext->GetBidiUtils();
|
2001-03-09 06:29:00 +03:00
|
|
|
|
2006-03-12 12:49:48 +03:00
|
|
|
nsIFrame* leftmostFrame;
|
|
|
|
nsIFrame* rightmostFrame;
|
|
|
|
*aIsReordered = bidiUtils->CheckLineOrder(line->mFirstChild, line->GetChildCount(), &leftmostFrame, &rightmostFrame);
|
2001-03-09 06:29:00 +03:00
|
|
|
|
2006-03-12 12:49:48 +03:00
|
|
|
// map leftmost/rightmost to first/last according to paragraph direction
|
|
|
|
*aFirstVisual = mRightToLeft ? rightmostFrame : leftmostFrame;
|
|
|
|
*aLastVisual = mRightToLeft ? leftmostFrame : rightmostFrame;
|
2001-03-09 06:29:00 +03:00
|
|
|
|
2006-03-12 12:49:48 +03:00
|
|
|
return NS_OK;
|
2001-03-09 06:29:00 +03:00
|
|
|
}
|
|
|
|
#endif // IBMBIDI
|
|
|
|
|
1999-05-13 04:54:28 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLineIterator::FindFrameAt(PRInt32 aLineNumber,
|
|
|
|
nscoord aX,
|
|
|
|
nsIFrame** aFrameFound,
|
|
|
|
PRBool* aXIsBeforeFirstFrame,
|
|
|
|
PRBool* aXIsAfterLastFrame)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aFrameFound && aXIsBeforeFirstFrame && aXIsAfterLastFrame,
|
|
|
|
"null OUT ptr");
|
|
|
|
if (!aFrameFound || !aXIsBeforeFirstFrame || !aXIsAfterLastFrame) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
if ((aLineNumber < 0) || (aLineNumber >= mNumLines)) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsLineBox* line = mLines[aLineNumber];
|
|
|
|
if (!line) {
|
|
|
|
*aFrameFound = nsnull;
|
|
|
|
*aXIsBeforeFirstFrame = PR_TRUE;
|
|
|
|
*aXIsAfterLastFrame = PR_FALSE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-10-30 16:05:45 +03:00
|
|
|
if (line->mBounds.width == 0 && line->mBounds.height == 0)
|
2003-04-02 16:05:43 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
1999-05-13 04:54:28 +04:00
|
|
|
nsIFrame* frame = line->mFirstChild;
|
2005-08-03 01:55:55 +04:00
|
|
|
nsIFrame* closestFromLeft = nsnull;
|
|
|
|
nsIFrame* closestFromRight = nsnull;
|
1999-10-15 03:10:03 +04:00
|
|
|
PRInt32 n = line->GetChildCount();
|
2005-08-03 01:55:55 +04:00
|
|
|
while (n--) {
|
|
|
|
nsRect rect = frame->GetRect();
|
|
|
|
if (rect.width > 0) {
|
|
|
|
// If aX is inside this frame - this is it
|
|
|
|
if (rect.x <= aX && rect.XMost() > aX) {
|
|
|
|
closestFromLeft = closestFromRight = frame;
|
1999-05-13 04:54:28 +04:00
|
|
|
break;
|
|
|
|
}
|
2005-08-03 01:55:55 +04:00
|
|
|
if (rect.x < aX) {
|
|
|
|
if (!closestFromLeft ||
|
|
|
|
rect.XMost() > closestFromLeft->GetRect().XMost())
|
|
|
|
closestFromLeft = frame;
|
1999-05-13 04:54:28 +04:00
|
|
|
}
|
|
|
|
else {
|
2005-08-03 01:55:55 +04:00
|
|
|
if (!closestFromRight ||
|
|
|
|
rect.x < closestFromRight->GetRect().x)
|
|
|
|
closestFromRight = frame;
|
1999-05-13 04:54:28 +04:00
|
|
|
}
|
|
|
|
}
|
2005-08-03 01:55:55 +04:00
|
|
|
frame = frame->GetNextSibling();
|
1999-05-13 04:54:28 +04:00
|
|
|
}
|
2005-08-03 01:55:55 +04:00
|
|
|
if (!closestFromLeft && !closestFromRight) {
|
|
|
|
// All frames were zero-width. Just take the first one.
|
|
|
|
closestFromLeft = closestFromRight = line->mFirstChild;
|
|
|
|
}
|
|
|
|
*aXIsBeforeFirstFrame = mRightToLeft ? !closestFromRight : !closestFromLeft;
|
|
|
|
*aXIsAfterLastFrame = mRightToLeft ? !closestFromLeft : !closestFromRight;
|
|
|
|
if (closestFromLeft == closestFromRight) {
|
|
|
|
*aFrameFound = closestFromLeft;
|
|
|
|
}
|
|
|
|
else if (!closestFromLeft) {
|
|
|
|
*aFrameFound = closestFromRight;
|
|
|
|
}
|
|
|
|
else if (!closestFromRight) {
|
|
|
|
*aFrameFound = closestFromLeft;
|
|
|
|
}
|
|
|
|
else { // we're between two frames
|
|
|
|
nscoord delta = closestFromRight->GetRect().x - closestFromLeft->GetRect().XMost();
|
|
|
|
if (aX < closestFromLeft->GetRect().XMost() + delta/2)
|
|
|
|
*aFrameFound = closestFromLeft;
|
|
|
|
else
|
|
|
|
*aFrameFound = closestFromRight;
|
1999-05-13 04:54:28 +04:00
|
|
|
}
|
|
|
|
return NS_OK;
|
1999-05-11 02:28:49 +04:00
|
|
|
}
|
1999-09-15 04:28:10 +04:00
|
|
|
|
2000-05-11 05:04:39 +04:00
|
|
|
NS_IMETHODIMP
|
2000-06-17 02:28:10 +04:00
|
|
|
nsLineIterator::GetNextSiblingOnLine(nsIFrame*& aFrame, PRInt32 aLineNumber)
|
2000-05-11 05:04:39 +04:00
|
|
|
{
|
2003-06-30 14:46:59 +04:00
|
|
|
aFrame = aFrame->GetNextSibling();
|
|
|
|
return NS_OK;
|
2000-05-11 05:04:39 +04:00
|
|
|
}
|
|
|
|
|
1999-09-15 04:28:10 +04:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2005-10-22 02:23:28 +04:00
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
nsFloatCacheList::nsFloatCacheList() :
|
|
|
|
mHead(nsnull)
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(nsFloatCacheList);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2003-10-14 01:51:02 +04:00
|
|
|
nsFloatCacheList::~nsFloatCacheList()
|
1999-09-15 04:28:10 +04:00
|
|
|
{
|
2006-06-29 05:19:48 +04:00
|
|
|
DeleteAll();
|
|
|
|
MOZ_COUNT_DTOR(nsFloatCacheList);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsFloatCacheList::DeleteAll()
|
|
|
|
{
|
|
|
|
nsFloatCache* c = mHead;
|
|
|
|
while (c) {
|
|
|
|
nsFloatCache* next = c->Next();
|
|
|
|
delete c;
|
|
|
|
c = next;
|
1999-09-15 04:28:10 +04:00
|
|
|
}
|
1999-10-15 03:10:03 +04:00
|
|
|
mHead = nsnull;
|
1999-09-15 04:28:10 +04:00
|
|
|
}
|
|
|
|
|
2003-10-14 01:51:02 +04:00
|
|
|
nsFloatCache*
|
|
|
|
nsFloatCacheList::Tail() const
|
1999-09-15 04:28:10 +04:00
|
|
|
{
|
2003-10-14 01:51:02 +04:00
|
|
|
nsFloatCache* fc = mHead;
|
1999-09-15 04:28:10 +04:00
|
|
|
while (fc) {
|
|
|
|
if (!fc->mNext) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
fc = fc->mNext;
|
|
|
|
}
|
|
|
|
return fc;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2003-10-14 01:51:02 +04:00
|
|
|
nsFloatCacheList::Append(nsFloatCacheFreeList& aList)
|
1999-09-15 04:28:10 +04:00
|
|
|
{
|
2006-04-17 05:47:11 +04:00
|
|
|
NS_PRECONDITION(aList.NotEmpty(), "Appending empty list will fail");
|
|
|
|
|
2003-10-14 01:51:02 +04:00
|
|
|
nsFloatCache* tail = Tail();
|
1999-09-15 04:28:10 +04:00
|
|
|
if (tail) {
|
2005-10-22 02:23:28 +04:00
|
|
|
NS_ASSERTION(!tail->mNext, "Bogus!");
|
1999-09-15 04:28:10 +04:00
|
|
|
tail->mNext = aList.mHead;
|
|
|
|
}
|
|
|
|
else {
|
2005-10-22 02:23:28 +04:00
|
|
|
NS_ASSERTION(!mHead, "Bogus!");
|
1999-09-15 04:28:10 +04:00
|
|
|
mHead = aList.mHead;
|
|
|
|
}
|
|
|
|
aList.mHead = nsnull;
|
|
|
|
aList.mTail = nsnull;
|
|
|
|
}
|
|
|
|
|
2003-10-14 01:51:02 +04:00
|
|
|
nsFloatCache*
|
|
|
|
nsFloatCacheList::Find(nsIFrame* aOutOfFlowFrame)
|
1999-09-15 04:28:10 +04:00
|
|
|
{
|
2003-10-14 01:51:02 +04:00
|
|
|
nsFloatCache* fc = mHead;
|
1999-09-15 04:28:10 +04:00
|
|
|
while (fc) {
|
|
|
|
if (fc->mPlaceholder->GetOutOfFlowFrame() == aOutOfFlowFrame) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
fc = fc->Next();
|
|
|
|
}
|
|
|
|
return fc;
|
|
|
|
}
|
|
|
|
|
2006-06-29 05:19:48 +04:00
|
|
|
nsFloatCache*
|
|
|
|
nsFloatCacheList::RemoveAndReturnPrev(nsFloatCache* aElement)
|
1999-09-15 04:28:10 +04:00
|
|
|
{
|
2006-06-29 05:19:48 +04:00
|
|
|
nsFloatCache* fc = mHead;
|
|
|
|
nsFloatCache* prev = nsnull;
|
|
|
|
while (fc) {
|
1999-09-15 04:28:10 +04:00
|
|
|
if (fc == aElement) {
|
2006-06-29 05:19:48 +04:00
|
|
|
if (prev) {
|
|
|
|
prev->mNext = fc->mNext;
|
|
|
|
} else {
|
|
|
|
mHead = fc->mNext;
|
|
|
|
}
|
|
|
|
return prev;
|
1999-09-15 04:28:10 +04:00
|
|
|
}
|
2006-06-29 05:19:48 +04:00
|
|
|
prev = fc;
|
|
|
|
fc = fc->mNext;
|
1999-09-15 04:28:10 +04:00
|
|
|
}
|
2006-07-24 22:57:42 +04:00
|
|
|
return nsnull;
|
1999-09-15 04:28:10 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2005-10-22 02:23:28 +04:00
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
nsFloatCacheFreeList::nsFloatCacheFreeList() :
|
|
|
|
mTail(nsnull)
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(nsFloatCacheFreeList);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsFloatCacheFreeList::~nsFloatCacheFreeList()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(nsFloatCacheFreeList);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1999-09-15 04:28:10 +04:00
|
|
|
void
|
2003-10-14 01:51:02 +04:00
|
|
|
nsFloatCacheFreeList::Append(nsFloatCacheList& aList)
|
1999-09-15 04:28:10 +04:00
|
|
|
{
|
2006-04-17 05:47:11 +04:00
|
|
|
NS_PRECONDITION(aList.NotEmpty(), "Appending empty list will fail");
|
|
|
|
|
1999-09-15 04:28:10 +04:00
|
|
|
if (mTail) {
|
2005-10-22 02:23:28 +04:00
|
|
|
NS_ASSERTION(!mTail->mNext, "Bogus");
|
1999-09-15 04:28:10 +04:00
|
|
|
mTail->mNext = aList.mHead;
|
|
|
|
}
|
|
|
|
else {
|
2005-10-22 02:23:28 +04:00
|
|
|
NS_ASSERTION(!mHead, "Bogus");
|
1999-09-15 04:28:10 +04:00
|
|
|
mHead = aList.mHead;
|
|
|
|
}
|
|
|
|
mTail = aList.Tail();
|
|
|
|
aList.mHead = nsnull;
|
|
|
|
}
|
|
|
|
|
2006-06-29 05:19:48 +04:00
|
|
|
void
|
|
|
|
nsFloatCacheFreeList::Remove(nsFloatCache* aElement)
|
|
|
|
{
|
|
|
|
nsFloatCache* prev = nsFloatCacheList::RemoveAndReturnPrev(aElement);
|
|
|
|
if (mTail == aElement) {
|
|
|
|
mTail = prev;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsFloatCacheFreeList::DeleteAll()
|
|
|
|
{
|
|
|
|
nsFloatCacheList::DeleteAll();
|
|
|
|
mTail = nsnull;
|
|
|
|
}
|
|
|
|
|
2003-10-14 01:51:02 +04:00
|
|
|
nsFloatCache*
|
|
|
|
nsFloatCacheFreeList::Alloc()
|
1999-09-15 04:28:10 +04:00
|
|
|
{
|
2003-10-14 01:51:02 +04:00
|
|
|
nsFloatCache* fc = mHead;
|
1999-09-15 04:28:10 +04:00
|
|
|
if (mHead) {
|
|
|
|
if (mHead == mTail) {
|
|
|
|
mHead = mTail = nsnull;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mHead = fc->mNext;
|
|
|
|
}
|
|
|
|
fc->mNext = nsnull;
|
|
|
|
}
|
|
|
|
else {
|
2003-10-14 01:51:02 +04:00
|
|
|
fc = new nsFloatCache();
|
1999-09-15 04:28:10 +04:00
|
|
|
}
|
|
|
|
return fc;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2003-10-14 01:51:02 +04:00
|
|
|
nsFloatCacheFreeList::Append(nsFloatCache* aFloat)
|
1999-09-15 04:28:10 +04:00
|
|
|
{
|
2005-10-22 02:23:28 +04:00
|
|
|
NS_ASSERTION(!aFloat->mNext, "Bogus!");
|
2003-10-14 01:51:02 +04:00
|
|
|
aFloat->mNext = nsnull;
|
1999-09-15 04:28:10 +04:00
|
|
|
if (mTail) {
|
2005-10-22 02:23:28 +04:00
|
|
|
NS_ASSERTION(!mTail->mNext, "Bogus!");
|
2003-10-14 01:51:02 +04:00
|
|
|
mTail->mNext = aFloat;
|
|
|
|
mTail = aFloat;
|
1999-09-15 04:28:10 +04:00
|
|
|
}
|
|
|
|
else {
|
2005-10-22 02:23:28 +04:00
|
|
|
NS_ASSERTION(!mHead, "Bogus!");
|
2003-10-14 01:51:02 +04:00
|
|
|
mHead = mTail = aFloat;
|
1999-09-15 04:28:10 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2003-10-14 01:51:02 +04:00
|
|
|
nsFloatCache::nsFloatCache()
|
1999-09-15 04:28:10 +04:00
|
|
|
: mPlaceholder(nsnull),
|
|
|
|
mNext(nsnull)
|
|
|
|
{
|
2003-10-14 01:51:02 +04:00
|
|
|
MOZ_COUNT_CTOR(nsFloatCache);
|
1999-09-15 04:28:10 +04:00
|
|
|
}
|
1999-10-09 00:41:19 +04:00
|
|
|
|
2000-12-16 21:56:06 +03:00
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
2003-10-14 01:51:02 +04:00
|
|
|
nsFloatCache::~nsFloatCache()
|
1999-10-09 00:41:19 +04:00
|
|
|
{
|
2003-10-14 01:51:02 +04:00
|
|
|
MOZ_COUNT_DTOR(nsFloatCache);
|
1999-10-09 00:41:19 +04:00
|
|
|
}
|
|
|
|
#endif
|