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 *****
|
|
|
|
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
1998-12-01 19:13:49 +03:00
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* 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-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.
|
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* 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):
|
2001-10-25 05:08:40 +04:00
|
|
|
* L. David Baron <dbaron@fas.harvard.edu>
|
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
|
|
|
|
* either 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"),
|
|
|
|
* 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
|
|
|
|
* use your version of this file under the terms of the NPL, indicate your
|
|
|
|
* 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
|
|
|
|
* the terms of any one of the NPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
1998-12-01 19:13:49 +03:00
|
|
|
#include "nsLineBox.h"
|
2001-10-26 09:06:07 +04:00
|
|
|
#include "nsSpaceManager.h"
|
1998-12-05 19:01:11 +03:00
|
|
|
#include "nsIStyleContext.h"
|
|
|
|
#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"
|
|
|
|
#include "nsITextContent.h"
|
|
|
|
#include "nsLayoutAtoms.h"
|
1998-12-01 19:13:49 +03:00
|
|
|
|
1999-10-02 06:51:03 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
#include "nsISizeOfHandler.h"
|
|
|
|
#endif
|
|
|
|
|
1999-10-20 03:04:19 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
static PRInt32 ctorCount;
|
|
|
|
PRInt32 nsLineBox::GetCtorCount() { return ctorCount; }
|
|
|
|
#endif
|
|
|
|
|
2001-01-28 02:06:33 +03:00
|
|
|
MOZ_DECL_CTOR_COUNTER(nsLineBox)
|
1999-10-09 00:41:19 +04:00
|
|
|
|
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),
|
|
|
|
mMaxElementWidth(0),
|
2001-10-25 05:08:40 +04:00
|
|
|
mMaximumWidth(-1),
|
|
|
|
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;
|
|
|
|
#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.
|
|
|
|
void*
|
|
|
|
nsLineBox::operator new(size_t sz, nsIPresShell* aPresShell)
|
|
|
|
{
|
|
|
|
void* result = nsnull;
|
|
|
|
aPresShell->AllocateFrame(sz, &result);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Overloaded delete operator. Doesn't actually free the memory, because we
|
|
|
|
// use an arena
|
|
|
|
void
|
|
|
|
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
|
|
|
|
aPresShell->FreeFrame(sizeof(*this), (void*)this);
|
|
|
|
}
|
|
|
|
|
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
|
1999-09-15 04:28:10 +04:00
|
|
|
ListFloaters(FILE* out, PRInt32 aIndent, const nsFloaterCacheList& aFloaters)
|
1998-12-01 19:13:49 +03:00
|
|
|
{
|
1999-03-19 00:03:25 +03:00
|
|
|
nsAutoString frameName;
|
1999-09-15 04:28:10 +04:00
|
|
|
nsFloaterCache* fc = aFloaters.Head();
|
|
|
|
while (fc) {
|
|
|
|
nsFrame::IndentBy(out, aIndent);
|
|
|
|
nsPlaceholderFrame* ph = fc->mPlaceholder;
|
1998-12-01 19:13:49 +03:00
|
|
|
if (nsnull != ph) {
|
2001-10-25 05:08:40 +04:00
|
|
|
fprintf(out, "placeholder@%p ", NS_STATIC_CAST(void*, ph));
|
1999-04-23 18:34:48 +04:00
|
|
|
nsIFrame* frame = ph->GetOutOfFlowFrame();
|
1998-12-01 19:13:49 +03:00
|
|
|
if (nsnull != frame) {
|
1999-11-02 01:12:45 +03:00
|
|
|
nsIFrameDebug* frameDebug;
|
|
|
|
|
2000-02-03 01:24:56 +03:00
|
|
|
if (NS_SUCCEEDED(frame->QueryInterface(NS_GET_IID(nsIFrameDebug), (void**)&frameDebug))) {
|
1999-11-02 01:12:45 +03:00
|
|
|
frameDebug->GetFrameName(frameName);
|
2001-10-16 07:53:44 +04:00
|
|
|
fputs(NS_LossyConvertUCS2toASCII(frameName).get(), out);
|
1999-11-02 01:12:45 +03:00
|
|
|
}
|
1998-12-01 19:13:49 +03:00
|
|
|
}
|
1999-09-21 04:12:27 +04:00
|
|
|
fprintf(out, " %s region={%d,%d,%d,%d} combinedArea={%d,%d,%d,%d}",
|
1999-09-15 04:28:10 +04:00
|
|
|
fc->mIsCurrentLineFloater ? "cl" : "bcl",
|
|
|
|
fc->mRegion.x, fc->mRegion.y,
|
1999-09-21 04:12:27 +04:00
|
|
|
fc->mRegion.width, fc->mRegion.height,
|
|
|
|
fc->mCombinedArea.x, fc->mCombinedArea.y,
|
|
|
|
fc->mCombinedArea.width, fc->mCombinedArea.height);
|
|
|
|
|
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
|
1998-12-01 19:13:49 +03:00
|
|
|
char*
|
|
|
|
nsLineBox::StateToString(char* aBuf, PRInt32 aBufSize) const
|
|
|
|
{
|
1999-10-15 03:10:03 +04:00
|
|
|
PR_snprintf(aBuf, aBufSize, "%s,%s,%s,%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",
|
2000-03-23 02:19:10 +03:00
|
|
|
IsImpactedByFloater() ? "IMPACTED" : "NOT Impacted",
|
1999-10-13 03:24:22 +04:00
|
|
|
mAllFlags);
|
1998-12-01 19:13:49 +03:00
|
|
|
return aBuf;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1999-10-26 08:44:41 +04:00
|
|
|
nsLineBox::List(nsIPresContext* aPresContext, 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 ",
|
2001-10-25 05:08:40 +04:00
|
|
|
NS_STATIC_CAST(const void*, this), GetChildCount(),
|
|
|
|
StateToString(cbuf, sizeof(cbuf)));
|
|
|
|
if (IsBlock() && !GetCarriedOutBottomMargin().IsZero()) {
|
|
|
|
fprintf(out, "bm=%d ", GetCarriedOutBottomMargin().get());
|
1999-01-16 03:00:50 +03:00
|
|
|
}
|
1999-09-21 04:12:27 +04:00
|
|
|
if (0 != mMaxElementWidth) {
|
|
|
|
fprintf(out, "mew=%d ", mMaxElementWidth);
|
|
|
|
}
|
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) {
|
1999-11-02 01:12:45 +03:00
|
|
|
nsIFrameDebug* frameDebug;
|
|
|
|
|
2000-02-03 01:24:56 +03:00
|
|
|
if (NS_SUCCEEDED(frame->QueryInterface(NS_GET_IID(nsIFrameDebug), (void**)&frameDebug))) {
|
1999-11-02 01:12:45 +03:00
|
|
|
frameDebug->List(aPresContext, out, aIndent + 1);
|
|
|
|
}
|
1999-02-10 09:13:38 +03:00
|
|
|
frame->GetNextSibling(&frame);
|
1998-12-01 19:13:49 +03:00
|
|
|
}
|
|
|
|
|
1999-01-16 03:00:50 +03:00
|
|
|
for (i = aIndent; --i >= 0; ) fputs(" ", out);
|
1999-10-15 03:10:03 +04:00
|
|
|
if (HasFloaters()) {
|
1999-01-16 03:00:50 +03:00
|
|
|
fputs("> floaters <\n", out);
|
1999-10-15 03:10:03 +04:00
|
|
|
ListFloaters(out, aIndent + 1, mInlineData->mFloaters);
|
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) {
|
1999-02-10 09:13:38 +03:00
|
|
|
frame->GetNextSibling(&frame);
|
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
|
|
|
}
|
1999-02-10 09:13:38 +03:00
|
|
|
frame->GetNextSibling(&frame);
|
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
|
|
|
}
|
|
|
|
|
2001-10-25 05:08:40 +04:00
|
|
|
nsresult
|
|
|
|
nsLineBox::IsEmpty(PRBool aIsQuirkMode, PRBool aParentIsPre,
|
|
|
|
PRBool *aResult) const
|
|
|
|
{
|
|
|
|
if (IsBlock())
|
|
|
|
return mFirstChild->IsEmpty(aIsQuirkMode, aParentIsPre, aResult);
|
|
|
|
|
|
|
|
*aResult = PR_TRUE;
|
|
|
|
PRInt32 n;
|
|
|
|
nsIFrame *kid;
|
|
|
|
for (n = GetChildCount(), kid = mFirstChild;
|
|
|
|
n > 0;
|
|
|
|
--n, kid->GetNextSibling(&kid))
|
|
|
|
{
|
|
|
|
kid->IsEmpty(aIsQuirkMode, aParentIsPre, aResult);
|
|
|
|
if (! *aResult)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-12-01 19:13:49 +03:00
|
|
|
void
|
2001-10-25 05:08:40 +04:00
|
|
|
nsLineBox::DeleteLineList(nsIPresContext* 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; ) {
|
1998-12-01 19:13:49 +03:00
|
|
|
nsIFrame* nextChild;
|
1999-02-10 09:13:38 +03:00
|
|
|
child->GetNextSibling(&nextChild);
|
1999-11-24 09:03:41 +03:00
|
|
|
child->Destroy(aPresContext);
|
1998-12-01 19:13:49 +03:00
|
|
|
child = nextChild;
|
|
|
|
}
|
|
|
|
|
2001-10-25 05:08:40 +04:00
|
|
|
while (! aLines.empty()) {
|
|
|
|
nsLineBox* line = aLines.front();
|
|
|
|
aLines.pop_front();
|
|
|
|
delete line;
|
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
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2001-10-25 05:08:40 +04:00
|
|
|
nsLineBox::SetCarriedOutBottomMargin(nsCollapsingMargin aValue)
|
1999-10-15 03:10:03 +04:00
|
|
|
{
|
|
|
|
if (IsBlock()) {
|
2001-10-25 05:08:40 +04:00
|
|
|
if (! aValue.IsZero()) {
|
1999-10-15 03:10:03 +04:00
|
|
|
if (!mBlockData) {
|
|
|
|
mBlockData = new ExtraBlockData(mBounds);
|
|
|
|
}
|
|
|
|
if (mBlockData) {
|
|
|
|
mBlockData->mCarriedOutBottomMargin = aValue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (mBlockData) {
|
|
|
|
mBlockData->mCarriedOutBottomMargin = aValue;
|
|
|
|
MaybeFreeData();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsLineBox::MaybeFreeData()
|
|
|
|
{
|
|
|
|
if (mData && (mData->mCombinedArea == mBounds)) {
|
|
|
|
if (IsInline()) {
|
|
|
|
if (mInlineData->mFloaters.IsEmpty()) {
|
|
|
|
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???
|
|
|
|
nsFloaterCache*
|
|
|
|
nsLineBox::GetFirstFloater()
|
|
|
|
{
|
1999-10-29 18:35:36 +04:00
|
|
|
NS_ABORT_IF_FALSE(IsInline(), "block line can't have floaters");
|
1999-10-15 03:10:03 +04:00
|
|
|
return mInlineData ? mInlineData->mFloaters.Head() : nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
// XXX this might be too eager to free memory
|
|
|
|
void
|
|
|
|
nsLineBox::FreeFloaters(nsFloaterCacheFreeList& aFreeList)
|
|
|
|
{
|
1999-10-29 18:35:36 +04:00
|
|
|
NS_ABORT_IF_FALSE(IsInline(), "block line can't have floaters");
|
1999-10-15 03:10:03 +04:00
|
|
|
if (IsInline()) {
|
|
|
|
if (mInlineData) {
|
|
|
|
aFreeList.Append(mInlineData->mFloaters);
|
|
|
|
MaybeFreeData();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-01-08 06:58:27 +03:00
|
|
|
void
|
2001-10-26 09:06:07 +04:00
|
|
|
nsLineBox::RemoveFloatersFromSpaceManager(nsSpaceManager* aSpaceManager)
|
2000-03-23 02:19:10 +03:00
|
|
|
{
|
2000-01-08 06:58:27 +03:00
|
|
|
if (IsInline()) {
|
|
|
|
if (mInlineData) {
|
|
|
|
nsFloaterCache* floaterCache = mInlineData->mFloaters.Head();
|
|
|
|
|
|
|
|
while (floaterCache) {
|
|
|
|
nsIFrame* floater = floaterCache->mPlaceholder->GetOutOfFlowFrame();
|
|
|
|
aSpaceManager->RemoveRegion(floater);
|
2000-03-23 02:19:10 +03:00
|
|
|
floaterCache = floaterCache->Next();
|
2000-01-08 06:58:27 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-10-15 03:10:03 +04:00
|
|
|
void
|
|
|
|
nsLineBox::AppendFloaters(nsFloaterCacheFreeList& aFreeList)
|
2000-03-23 02:19:10 +03:00
|
|
|
{
|
1999-10-29 18:35:36 +04:00
|
|
|
NS_ABORT_IF_FALSE(IsInline(), "block line can't have floaters");
|
1999-10-15 03:10:03 +04:00
|
|
|
if (IsInline()) {
|
|
|
|
if (aFreeList.NotEmpty()) {
|
|
|
|
if (!mInlineData) {
|
|
|
|
mInlineData = new ExtraInlineData(mBounds);
|
|
|
|
}
|
|
|
|
if (mInlineData) {
|
|
|
|
mInlineData->mFloaters.Append(aFreeList);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-12-05 19:01:11 +03:00
|
|
|
PRBool
|
1999-10-15 03:10:03 +04:00
|
|
|
nsLineBox::RemoveFloater(nsIFrame* aFrame)
|
1998-12-05 19:01:11 +03:00
|
|
|
{
|
1999-10-29 18:35:36 +04:00
|
|
|
NS_ABORT_IF_FALSE(IsInline(), "block line can't have floaters");
|
1999-10-15 03:10:03 +04:00
|
|
|
if (IsInline() && mInlineData) {
|
|
|
|
nsFloaterCache* fc = mInlineData->mFloaters.Find(aFrame);
|
|
|
|
if (fc) {
|
|
|
|
// Note: the placeholder is part of the line's child list
|
|
|
|
// and will be removed later.
|
|
|
|
fc->mPlaceholder->SetOutOfFlowFrame(nsnull);
|
|
|
|
mInlineData->mFloaters.Remove(fc);
|
|
|
|
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();
|
|
|
|
}
|
2000-10-29 02:17:53 +04:00
|
|
|
#ifdef VERY_NOISY_REFLOW
|
|
|
|
printf("nsLB::SetCombinedArea(1) %p (%d, %d, %d, %d)\n",
|
2000-03-23 02:19:10 +03:00
|
|
|
this, aCombinedArea.x, aCombinedArea.y, aCombinedArea.width, aCombinedArea.height);
|
2000-10-29 02:17:53 +04:00
|
|
|
#endif
|
1999-10-15 03:10:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsLineBox::GetCombinedArea(nsRect* aResult)
|
|
|
|
{
|
2000-03-23 02:19:10 +03:00
|
|
|
NS_ASSERTION(aResult, "null arg");
|
1999-10-15 03:10:03 +04:00
|
|
|
if (aResult) {
|
|
|
|
*aResult = mData ? mData->mCombinedArea : mBounds;
|
2000-10-29 02:17:53 +04:00
|
|
|
#ifdef VERY_NOISY_REFLOW
|
2001-12-18 01:39:59 +03:00
|
|
|
printf("nsLineBox::GetCombinedArea(1) %p (%d,%d,%d,%d)\n",
|
2000-10-29 02:17:53 +04:00
|
|
|
this, aResult->x, aResult->y, aResult->width, aResult->height);
|
|
|
|
#endif
|
1999-10-15 03:10:03 +04:00
|
|
|
}
|
1998-12-05 19:01:11 +03:00
|
|
|
}
|
1999-05-11 02:28:49 +04:00
|
|
|
|
1999-10-02 06:51:03 +04:00
|
|
|
#ifdef DEBUG
|
1999-10-15 03:10:03 +04:00
|
|
|
nsIAtom*
|
1999-10-02 06:51:03 +04:00
|
|
|
nsLineBox::SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aResult, "null OUT parameter pointer");
|
|
|
|
*aResult = sizeof(*this);
|
|
|
|
|
1999-10-15 03:10:03 +04:00
|
|
|
nsIAtom* atom;
|
|
|
|
if (IsBlock()) {
|
|
|
|
atom = nsLayoutAtoms::lineBoxBlockSmall;
|
|
|
|
if (mBlockData) {
|
|
|
|
atom = nsLayoutAtoms::lineBoxBlockBig;
|
|
|
|
*aResult += sizeof(*mBlockData);
|
|
|
|
}
|
1999-10-13 03:24:22 +04:00
|
|
|
}
|
1999-10-15 03:10:03 +04:00
|
|
|
else {
|
|
|
|
atom = nsLayoutAtoms::lineBoxSmall;
|
|
|
|
if (mInlineData) {
|
|
|
|
atom = nsLayoutAtoms::lineBoxBig;
|
|
|
|
*aResult += sizeof(*mInlineData);
|
|
|
|
|
|
|
|
// Add in the size needed for floaters associated with this line
|
|
|
|
if (HasFloaters()) {
|
|
|
|
PRUint32 floatersSize;
|
|
|
|
mInlineData->mFloaters.SizeOf(aHandler, &floatersSize);
|
|
|
|
|
|
|
|
// Base size of embedded object was included in sizeof(*this) above
|
|
|
|
floatersSize -= sizeof(mInlineData->mFloaters);
|
|
|
|
aHandler->AddSize(nsLayoutAtoms::lineBoxFloaters, floatersSize);
|
|
|
|
}
|
|
|
|
}
|
1999-10-02 06:51:03 +04:00
|
|
|
}
|
1999-10-13 03:24:22 +04:00
|
|
|
|
1999-10-15 03:10:03 +04:00
|
|
|
return atom;
|
1999-10-02 06:51:03 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
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
|
|
|
NS_INIT_REFCNT();
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2000-05-16 12:11:14 +04:00
|
|
|
NS_IMPL_ISUPPORTS2(nsLineIterator, nsILineIterator, nsILineIteratorNavigator)
|
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;
|
|
|
|
}
|
|
|
|
|
1999-05-13 04:54:28 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLineIterator::GetNumLines(PRInt32* aResult)
|
1999-05-11 02:28:49 +04:00
|
|
|
{
|
1999-05-13 04:54:28 +04:00
|
|
|
NS_PRECONDITION(aResult, "null OUT ptr");
|
|
|
|
if (!aResult) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
*aResult = mNumLines;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLineIterator::GetDirection(PRBool* aIsRightToLeft)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aIsRightToLeft, "null OUT ptr");
|
|
|
|
if (!aIsRightToLeft) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
*aIsRightToLeft = mRightToLeft;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
|
|
|
if (line->HasBreak())
|
|
|
|
flags |= NS_LINE_FLAG_ENDS_IN_BREAK;
|
|
|
|
}
|
|
|
|
*aLineFlags = flags;
|
|
|
|
|
1999-05-13 04:54:28 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLineIterator::FindLineContaining(nsIFrame* aFrame,
|
|
|
|
PRInt32* aLineNumberResult)
|
|
|
|
{
|
|
|
|
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)) {
|
|
|
|
*aLineNumberResult = lineNumber;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-10-25 05:08:40 +04:00
|
|
|
line = mLines[++lineNumber];
|
1999-05-13 04:54:28 +04:00
|
|
|
}
|
|
|
|
*aLineNumberResult = -1;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLineIterator::FindLineAt(nscoord aY,
|
|
|
|
PRInt32* aLineNumberResult)
|
|
|
|
{
|
|
|
|
nsLineBox* line = mLines[0];
|
|
|
|
if (!line || (aY < line->mBounds.y)) {
|
|
|
|
*aLineNumberResult = -1;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
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())) {
|
|
|
|
*aLineNumberResult = lineNumber;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-10-25 05:08:40 +04:00
|
|
|
line = mLines[++lineNumber];
|
1999-05-11 02:28:49 +04:00
|
|
|
}
|
1999-05-13 04:54:28 +04:00
|
|
|
*aLineNumberResult = mNumLines;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-03-09 06:29:00 +03:00
|
|
|
#ifdef IBMBIDI
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLineIterator::CheckLineOrder(PRInt32 aLine,
|
|
|
|
PRBool *aIsReordered,
|
|
|
|
nsIFrame **aFirstVisual,
|
|
|
|
nsIFrame **aLastVisual)
|
|
|
|
{
|
|
|
|
nsRect checkRect;
|
|
|
|
PRInt32 currentLine, saveLine, testLine;
|
|
|
|
nscoord saveX;
|
|
|
|
nsIFrame *checkFrame;
|
|
|
|
nsIFrame *firstFrame;
|
|
|
|
nsIFrame *leftmostFrame;
|
|
|
|
nsIFrame *rightmostFrame;
|
|
|
|
nscoord minX, maxX;
|
|
|
|
PRInt32 lineFrameCount;
|
|
|
|
PRUint32 lineFlags;
|
|
|
|
|
2001-10-25 05:08:40 +04:00
|
|
|
nsresult result = NS_OK;
|
2001-03-09 06:29:00 +03:00
|
|
|
|
|
|
|
// an RTL paragraph is always considered as reordered
|
|
|
|
// in an LTR paragraph, find out by examining the coordinates of each frame in the line
|
|
|
|
if (mRightToLeft)
|
|
|
|
*aIsReordered = PR_TRUE;
|
|
|
|
else {
|
|
|
|
*aIsReordered = PR_FALSE;
|
|
|
|
|
|
|
|
// Check the preceding and following line, since we might be moving into them
|
|
|
|
for (currentLine = PR_MAX(0, aLine-1); currentLine < aLine+1; currentLine++) {
|
|
|
|
|
|
|
|
nsLineBox* line = mLines[currentLine];
|
|
|
|
if (!line)
|
|
|
|
break;
|
|
|
|
|
|
|
|
checkFrame = line->mFirstChild;
|
|
|
|
|
|
|
|
checkFrame->GetRect(checkRect);
|
|
|
|
result = FindLineContaining(checkFrame, &saveLine);
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
saveX = checkRect.x;
|
|
|
|
lineFrameCount = line->GetChildCount();
|
|
|
|
|
|
|
|
for (; checkFrame; result = checkFrame->GetNextSibling(&checkFrame)) {
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
break;
|
|
|
|
result = FindLineContaining(checkFrame, &testLine);
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
if (testLine != saveLine) {
|
|
|
|
*aIsReordered = PR_TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
checkFrame->GetRect(checkRect);
|
|
|
|
// If the origin of any frame is less than the previous frame, the line is reordered
|
|
|
|
if (checkRect.x < saveX) {
|
|
|
|
*aIsReordered = PR_TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
saveX = checkRect.x;
|
|
|
|
lineFrameCount--;
|
|
|
|
if (0 == lineFrameCount)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (*aIsReordered)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the line is reordered, identify the first and last frames on the line
|
|
|
|
if (*aIsReordered) {
|
|
|
|
nsRect nonUsedRect;
|
|
|
|
result = GetLine(aLine, &firstFrame, &lineFrameCount, nonUsedRect, &lineFlags);
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
leftmostFrame = rightmostFrame = firstFrame;
|
|
|
|
firstFrame->GetRect(checkRect);
|
|
|
|
maxX = checkRect.x;
|
|
|
|
minX = checkRect.x;
|
|
|
|
|
|
|
|
for (;lineFrameCount > 1;lineFrameCount--) {
|
|
|
|
result = firstFrame->GetNextSibling(&firstFrame);
|
|
|
|
|
|
|
|
if (NS_FAILED(result)){
|
|
|
|
NS_ASSERTION(0,"should not be reached nsLineBox\n");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
firstFrame->GetRect(checkRect);
|
|
|
|
if (checkRect.x > maxX) {
|
|
|
|
maxX = checkRect.x;
|
|
|
|
rightmostFrame = firstFrame;
|
|
|
|
}
|
|
|
|
if (checkRect.x < minX) {
|
|
|
|
minX = checkRect.x;
|
|
|
|
leftmostFrame = firstFrame;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (mRightToLeft) {
|
|
|
|
*aFirstVisual = rightmostFrame;
|
|
|
|
*aLastVisual = leftmostFrame;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
*aFirstVisual = leftmostFrame;
|
|
|
|
*aLastVisual = rightmostFrame;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
#endif // IBMBIDI
|
|
|
|
|
1999-05-13 04:54:28 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLineIterator::FindFrameAt(PRInt32 aLineNumber,
|
|
|
|
nscoord aX,
|
2001-03-09 06:29:00 +03:00
|
|
|
#ifdef IBMBIDI
|
|
|
|
PRBool aCouldBeReordered,
|
|
|
|
#endif // IBMBIDI
|
1999-05-13 04:54:28 +04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aX < line->mBounds.x) {
|
|
|
|
nsIFrame* frame;
|
|
|
|
if (mRightToLeft) {
|
|
|
|
frame = line->LastChild();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
frame = line->mFirstChild;
|
|
|
|
}
|
|
|
|
*aFrameFound = frame;
|
|
|
|
*aXIsBeforeFirstFrame = PR_TRUE;
|
|
|
|
*aXIsAfterLastFrame = PR_FALSE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
else if (aX >= line->mBounds.XMost()) {
|
|
|
|
nsIFrame* frame;
|
|
|
|
if (mRightToLeft) {
|
|
|
|
frame = line->mFirstChild;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
frame = line->LastChild();
|
|
|
|
}
|
|
|
|
*aFrameFound = frame;
|
|
|
|
*aXIsBeforeFirstFrame = PR_FALSE;
|
|
|
|
*aXIsAfterLastFrame = PR_TRUE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Find the frame closest to the X coordinate. Gaps can occur
|
|
|
|
// between frames (because of margins) so we split the gap in two
|
|
|
|
// when checking.
|
|
|
|
*aXIsBeforeFirstFrame = PR_FALSE;
|
|
|
|
*aXIsAfterLastFrame = PR_FALSE;
|
2001-03-09 06:29:00 +03:00
|
|
|
#ifdef IBMBIDI
|
|
|
|
PRBool isReordered = PR_FALSE;
|
|
|
|
nsIFrame *firstVisual, *lastVisual;
|
|
|
|
if (aCouldBeReordered)
|
|
|
|
CheckLineOrder(aLineNumber, &isReordered, &firstVisual, &lastVisual);
|
|
|
|
#endif
|
1999-05-13 04:54:28 +04:00
|
|
|
nsRect r1, r2;
|
|
|
|
nsIFrame* frame = line->mFirstChild;
|
2001-03-09 06:29:00 +03:00
|
|
|
#ifdef IBMBIDI
|
|
|
|
if (isReordered)
|
|
|
|
frame = firstVisual;
|
|
|
|
#endif // IBMBIDI
|
1999-10-15 03:10:03 +04:00
|
|
|
PRInt32 n = line->GetChildCount();
|
1999-05-13 04:54:28 +04:00
|
|
|
if (mRightToLeft) {
|
|
|
|
while (--n >= 0) {
|
|
|
|
nsIFrame* nextFrame;
|
2001-03-09 06:29:00 +03:00
|
|
|
#ifdef IBMBIDI
|
2001-05-03 02:13:29 +04:00
|
|
|
if (!frame)
|
|
|
|
break;
|
2001-03-09 06:29:00 +03:00
|
|
|
if (isReordered) {
|
|
|
|
nscoord maxX, limX;
|
|
|
|
PRInt32 testLine;
|
|
|
|
nsRect tempRect;
|
|
|
|
nsIFrame* tempFrame;
|
|
|
|
|
|
|
|
maxX = -0x7fffffff;
|
|
|
|
frame->GetRect(tempRect);
|
|
|
|
|
|
|
|
limX = tempRect.x;
|
|
|
|
tempFrame = line->mFirstChild;
|
|
|
|
nextFrame = nsnull;
|
|
|
|
|
|
|
|
while (tempFrame) {
|
|
|
|
if (NS_SUCCEEDED(FindLineContaining(tempFrame, &testLine))
|
|
|
|
&& testLine == aLineNumber) {
|
|
|
|
tempFrame->GetRect(tempRect);
|
|
|
|
if (tempRect.x > maxX && tempRect.x < limX) { // we are looking for the highest value less than the current one
|
|
|
|
maxX = tempRect.x;
|
|
|
|
nextFrame = tempFrame;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
tempFrame->GetNextSibling(&tempFrame);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif // IBMBIDI
|
|
|
|
frame->GetNextSibling(&nextFrame);
|
1999-05-13 04:54:28 +04:00
|
|
|
frame->GetRect(r1);
|
|
|
|
if (aX > r1.x) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (nextFrame) {
|
|
|
|
nextFrame->GetRect(r2);
|
|
|
|
if (aX > r2.XMost()) {
|
|
|
|
nscoord rightEdge = r2.XMost();
|
|
|
|
nscoord delta = r1.x - rightEdge;
|
|
|
|
if (aX < rightEdge + delta/2) {
|
|
|
|
frame = nextFrame;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
*aXIsBeforeFirstFrame = PR_TRUE;
|
|
|
|
}
|
|
|
|
frame = nextFrame;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
while (--n >= 0) {
|
|
|
|
nsIFrame* nextFrame;
|
2001-03-09 06:29:00 +03:00
|
|
|
#ifdef IBMBIDI
|
2001-05-03 02:13:29 +04:00
|
|
|
if (!frame)
|
|
|
|
break;
|
2001-03-09 06:29:00 +03:00
|
|
|
if (isReordered) {
|
|
|
|
nsRect tempRect;
|
|
|
|
nsIFrame* tempFrame;
|
2001-04-17 01:32:19 +04:00
|
|
|
nscoord minX, limX;
|
2001-03-09 06:29:00 +03:00
|
|
|
PRInt32 testLine;
|
|
|
|
|
|
|
|
minX = 0x7fffffff;
|
|
|
|
frame->GetRect(tempRect);
|
|
|
|
|
|
|
|
limX = tempRect.x;
|
|
|
|
tempFrame = line->mFirstChild;
|
|
|
|
nextFrame = nsnull;
|
|
|
|
|
|
|
|
while (tempFrame) {
|
|
|
|
if (NS_SUCCEEDED(FindLineContaining(tempFrame, &testLine))
|
|
|
|
&& testLine == aLineNumber) {
|
|
|
|
tempFrame->GetRect(tempRect);
|
|
|
|
if (tempRect.x < minX && tempRect.x > limX) { // we are looking for the lowest value greater than the current one
|
|
|
|
minX = tempRect.x;
|
|
|
|
nextFrame = tempFrame;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
tempFrame->GetNextSibling(&tempFrame);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif // IBMBIDI
|
1999-05-13 04:54:28 +04:00
|
|
|
frame->GetNextSibling(&nextFrame);
|
|
|
|
frame->GetRect(r1);
|
|
|
|
if (aX < r1.XMost()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (nextFrame) {
|
|
|
|
nextFrame->GetRect(r2);
|
|
|
|
if (aX < r2.x) {
|
|
|
|
nscoord rightEdge = r1.XMost();
|
|
|
|
nscoord delta = r2.x - rightEdge;
|
|
|
|
if (aX >= rightEdge + delta/2) {
|
|
|
|
frame = nextFrame;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
*aXIsAfterLastFrame = PR_TRUE;
|
|
|
|
}
|
|
|
|
frame = nextFrame;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*aFrameFound = frame;
|
|
|
|
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
|
|
|
{
|
|
|
|
return aFrame->GetNextSibling(&aFrame);
|
|
|
|
}
|
|
|
|
|
1999-09-15 04:28:10 +04:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
nsFloaterCacheList::~nsFloaterCacheList()
|
|
|
|
{
|
|
|
|
nsFloaterCache* floater = mHead;
|
|
|
|
while (floater) {
|
|
|
|
nsFloaterCache* next = floater->mNext;
|
|
|
|
delete floater;
|
|
|
|
floater = next;
|
|
|
|
}
|
1999-10-15 03:10:03 +04:00
|
|
|
mHead = nsnull;
|
1999-09-15 04:28:10 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsFloaterCache*
|
|
|
|
nsFloaterCacheList::Tail() const
|
|
|
|
{
|
|
|
|
nsFloaterCache* fc = mHead;
|
|
|
|
while (fc) {
|
|
|
|
if (!fc->mNext) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
fc = fc->mNext;
|
|
|
|
}
|
|
|
|
return fc;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsFloaterCacheList::Append(nsFloaterCacheFreeList& aList)
|
|
|
|
{
|
|
|
|
nsFloaterCache* tail = Tail();
|
|
|
|
if (tail) {
|
|
|
|
tail->mNext = aList.mHead;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mHead = aList.mHead;
|
|
|
|
}
|
|
|
|
aList.mHead = nsnull;
|
|
|
|
aList.mTail = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsFloaterCache*
|
|
|
|
nsFloaterCacheList::Find(nsIFrame* aOutOfFlowFrame)
|
|
|
|
{
|
|
|
|
nsFloaterCache* fc = mHead;
|
|
|
|
while (fc) {
|
|
|
|
if (fc->mPlaceholder->GetOutOfFlowFrame() == aOutOfFlowFrame) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
fc = fc->Next();
|
|
|
|
}
|
|
|
|
return fc;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsFloaterCacheList::Remove(nsFloaterCache* aElement)
|
|
|
|
{
|
|
|
|
nsFloaterCache** fcp = &mHead;
|
|
|
|
nsFloaterCache* fc;
|
|
|
|
while (nsnull != (fc = *fcp)) {
|
|
|
|
if (fc == aElement) {
|
|
|
|
*fcp = fc->mNext;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
fcp = &fc->mNext;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-10-02 06:51:03 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
void
|
|
|
|
nsFloaterCacheList::SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aResult, "null OUT parameter pointer");
|
|
|
|
*aResult = sizeof(*this);
|
|
|
|
|
|
|
|
// Add in the space for each floater
|
|
|
|
for (nsFloaterCache* cache = Head(); cache; cache = cache->Next()) {
|
|
|
|
*aResult += sizeof(*cache);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1999-09-15 04:28:10 +04:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
void
|
|
|
|
nsFloaterCacheFreeList::Append(nsFloaterCacheList& aList)
|
|
|
|
{
|
|
|
|
if (mTail) {
|
|
|
|
mTail->mNext = aList.mHead;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mHead = aList.mHead;
|
|
|
|
}
|
|
|
|
mTail = aList.Tail();
|
|
|
|
aList.mHead = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsFloaterCache*
|
|
|
|
nsFloaterCacheFreeList::Alloc()
|
|
|
|
{
|
|
|
|
nsFloaterCache* fc = mHead;
|
|
|
|
if (mHead) {
|
|
|
|
if (mHead == mTail) {
|
|
|
|
mHead = mTail = nsnull;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mHead = fc->mNext;
|
|
|
|
}
|
|
|
|
fc->mNext = nsnull;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
fc = new nsFloaterCache();
|
|
|
|
}
|
|
|
|
return fc;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsFloaterCacheFreeList::Append(nsFloaterCache* aFloater)
|
|
|
|
{
|
|
|
|
aFloater->mNext = nsnull;
|
|
|
|
if (mTail) {
|
|
|
|
mTail->mNext = aFloater;
|
|
|
|
mTail = aFloater;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mHead = mTail = aFloater;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2001-01-28 02:06:33 +03:00
|
|
|
MOZ_DECL_CTOR_COUNTER(nsFloaterCache)
|
1999-10-09 00:41:19 +04:00
|
|
|
|
1999-09-15 04:28:10 +04:00
|
|
|
nsFloaterCache::nsFloaterCache()
|
|
|
|
: mPlaceholder(nsnull),
|
|
|
|
mIsCurrentLineFloater(PR_TRUE),
|
|
|
|
mMargins(0, 0, 0, 0),
|
|
|
|
mOffsets(0, 0, 0, 0),
|
|
|
|
mCombinedArea(0, 0, 0, 0),
|
|
|
|
mNext(nsnull)
|
|
|
|
{
|
1999-10-09 00:41:19 +04:00
|
|
|
MOZ_COUNT_CTOR(nsFloaterCache);
|
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
|
1999-10-09 00:41:19 +04:00
|
|
|
nsFloaterCache::~nsFloaterCache()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(nsFloaterCache);
|
|
|
|
}
|
|
|
|
#endif
|