2001-09-29 00:14:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
1999-01-15 04:28:07 +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/
|
1999-01-15 04:28:07 +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.
|
1999-01-15 04:28:07 +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):
|
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 ***** */
|
1999-01-15 04:28:07 +03:00
|
|
|
#include "nsFrameList.h"
|
1999-11-02 01:12:45 +03:00
|
|
|
#ifdef NS_DEBUG
|
|
|
|
#include "nsIFrameDebug.h"
|
|
|
|
#endif
|
1999-01-15 04:28:07 +03:00
|
|
|
|
2001-03-21 04:16:22 +03:00
|
|
|
#ifdef IBMBIDI
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsLayoutAtoms.h"
|
|
|
|
#include "nsILineIterator.h"
|
2001-05-15 16:29:10 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper class for comparing the location of frames. Used by
|
|
|
|
* GetPrevVisualFor() and GetNextVisualFor()
|
|
|
|
*/
|
|
|
|
#define LINE_MIN 0
|
|
|
|
#define XCOORD_MIN 0x80000000
|
2001-05-15 18:34:23 +04:00
|
|
|
#define MY_LINE_MAX 0x7fffffff
|
2001-05-15 16:29:10 +04:00
|
|
|
#define XCOORD_MAX 0x7fffffff
|
|
|
|
class nsFrameOrigin {
|
|
|
|
public:
|
|
|
|
// default constructor
|
|
|
|
nsFrameOrigin() {
|
|
|
|
mLine = 0;
|
|
|
|
mXCoord = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsFrameOrigin(PRInt32 line, nscoord xCoord) {
|
|
|
|
mLine = line;
|
|
|
|
mXCoord = xCoord;
|
|
|
|
}
|
|
|
|
|
|
|
|
// copy constructor
|
|
|
|
nsFrameOrigin(const nsFrameOrigin& aFrameOrigin) {
|
|
|
|
mLine = aFrameOrigin.mLine;
|
|
|
|
mXCoord = aFrameOrigin.mXCoord;
|
|
|
|
}
|
|
|
|
|
|
|
|
~nsFrameOrigin() {
|
|
|
|
}
|
|
|
|
|
|
|
|
nsFrameOrigin& operator=(const nsFrameOrigin& aFrameOrigin) {
|
|
|
|
mLine = aFrameOrigin.mLine;
|
|
|
|
mXCoord = aFrameOrigin.mXCoord;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool operator<(const nsFrameOrigin& aFrameOrigin) {
|
|
|
|
if (mLine < aFrameOrigin.mLine) {
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
if (mLine > aFrameOrigin.mLine) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
if (mXCoord < aFrameOrigin.mXCoord) {
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool operator>(const nsFrameOrigin& aFrameOrigin) {
|
|
|
|
if (mLine > aFrameOrigin.mLine) {
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
if (mLine < aFrameOrigin.mLine) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
if (mXCoord > aFrameOrigin.mXCoord) {
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool operator==(const nsFrameOrigin& aFrameOrigin) {
|
|
|
|
if (aFrameOrigin.mLine == mLine && aFrameOrigin.mXCoord == mXCoord) {
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
PRInt32 mLine;
|
|
|
|
nscoord mXCoord;
|
|
|
|
};
|
2001-03-21 04:16:22 +03:00
|
|
|
#endif // IBMBIDI
|
|
|
|
|
1999-01-15 04:28:07 +03:00
|
|
|
void
|
1999-11-24 09:03:41 +03:00
|
|
|
nsFrameList::DestroyFrames(nsIPresContext* aPresContext)
|
1999-01-15 04:28:07 +03:00
|
|
|
{
|
|
|
|
nsIFrame* frame = mFirstChild;
|
|
|
|
while (nsnull != frame) {
|
|
|
|
nsIFrame* next;
|
1999-02-10 09:13:38 +03:00
|
|
|
frame->GetNextSibling(&next);
|
1999-07-22 06:24:52 +04:00
|
|
|
frame->Destroy(aPresContext);
|
1999-01-16 01:53:39 +03:00
|
|
|
mFirstChild = frame = next;
|
1999-01-15 04:28:07 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsFrameList::AppendFrames(nsIFrame* aParent, nsIFrame* aFrameList)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aFrameList, "null ptr");
|
|
|
|
if (nsnull != aFrameList) {
|
|
|
|
nsIFrame* lastChild = LastChild();
|
|
|
|
if (nsnull == lastChild) {
|
|
|
|
mFirstChild = aFrameList;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
lastChild->SetNextSibling(aFrameList);
|
|
|
|
}
|
|
|
|
if (nsnull != aParent) {
|
|
|
|
nsIFrame* frame = aFrameList;
|
|
|
|
while (nsnull != frame) {
|
|
|
|
frame->SetParent(aParent);
|
1999-02-10 09:13:38 +03:00
|
|
|
frame->GetNextSibling(&frame);
|
1999-01-15 04:28:07 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsFrameList::AppendFrame(nsIFrame* aParent, nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aFrame, "null ptr");
|
|
|
|
if (nsnull != aFrame) {
|
|
|
|
nsIFrame* lastChild = LastChild();
|
|
|
|
if (nsnull == lastChild) {
|
|
|
|
mFirstChild = aFrame;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
lastChild->SetNextSibling(aFrame);
|
|
|
|
}
|
|
|
|
if (nsnull != aParent) {
|
|
|
|
aFrame->SetParent(aParent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsFrameList::RemoveFrame(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aFrame, "null ptr");
|
|
|
|
if (nsnull != aFrame) {
|
|
|
|
nsIFrame* nextFrame;
|
1999-02-10 09:13:38 +03:00
|
|
|
aFrame->GetNextSibling(&nextFrame);
|
1999-02-01 20:32:05 +03:00
|
|
|
aFrame->SetNextSibling(nsnull);
|
1999-01-15 04:28:07 +03:00
|
|
|
if (aFrame == mFirstChild) {
|
|
|
|
mFirstChild = nextFrame;
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
nsIFrame* prevSibling = GetPrevSiblingFor(aFrame);
|
|
|
|
if (nsnull != prevSibling) {
|
|
|
|
prevSibling->SetNextSibling(nextFrame);
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-03-04 18:48:56 +03:00
|
|
|
// aFrame was not in the list.
|
1999-01-15 04:28:07 +03:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
1999-01-16 01:53:39 +03:00
|
|
|
PRBool
|
|
|
|
nsFrameList::RemoveFirstChild()
|
|
|
|
{
|
|
|
|
if (nsnull != mFirstChild) {
|
|
|
|
nsIFrame* nextFrame;
|
1999-02-10 09:13:38 +03:00
|
|
|
mFirstChild->GetNextSibling(&nextFrame);
|
1999-02-01 20:32:05 +03:00
|
|
|
mFirstChild->SetNextSibling(nsnull);
|
1999-01-16 01:53:39 +03:00
|
|
|
mFirstChild = nextFrame;
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
1999-01-15 04:28:07 +03:00
|
|
|
PRBool
|
1999-11-24 09:03:41 +03:00
|
|
|
nsFrameList::DestroyFrame(nsIPresContext* aPresContext, nsIFrame* aFrame)
|
1999-01-15 04:28:07 +03:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aFrame, "null ptr");
|
|
|
|
if (RemoveFrame(aFrame)) {
|
1999-07-22 06:24:52 +04:00
|
|
|
aFrame->Destroy(aPresContext);
|
1999-01-15 04:28:07 +03:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsFrameList::InsertFrame(nsIFrame* aParent,
|
|
|
|
nsIFrame* aPrevSibling,
|
|
|
|
nsIFrame* aNewFrame)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aNewFrame, "null ptr");
|
|
|
|
if (nsnull != aNewFrame) {
|
|
|
|
if (nsnull == aPrevSibling) {
|
|
|
|
aNewFrame->SetNextSibling(mFirstChild);
|
|
|
|
mFirstChild = aNewFrame;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
nsIFrame* nextFrame;
|
1999-02-10 09:13:38 +03:00
|
|
|
aPrevSibling->GetNextSibling(&nextFrame);
|
1999-01-15 04:28:07 +03:00
|
|
|
aPrevSibling->SetNextSibling(aNewFrame);
|
|
|
|
aNewFrame->SetNextSibling(nextFrame);
|
|
|
|
}
|
|
|
|
if (nsnull != aParent) {
|
|
|
|
aNewFrame->SetParent(aParent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsFrameList::InsertFrames(nsIFrame* aParent,
|
|
|
|
nsIFrame* aPrevSibling,
|
|
|
|
nsIFrame* aFrameList)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aFrameList, "null ptr");
|
|
|
|
if (nsnull != aFrameList) {
|
2000-03-12 06:07:52 +03:00
|
|
|
nsIFrame* lastNewFrame = nsnull;
|
1999-01-15 04:28:07 +03:00
|
|
|
if (nsnull != aParent) {
|
|
|
|
nsIFrame* frame = aFrameList;
|
|
|
|
while (nsnull != frame) {
|
|
|
|
frame->SetParent(aParent);
|
2000-03-12 06:07:52 +03:00
|
|
|
lastNewFrame = frame;
|
1999-02-10 09:13:38 +03:00
|
|
|
frame->GetNextSibling(&frame);
|
1999-01-15 04:28:07 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-03-12 06:07:52 +03:00
|
|
|
// Get the last new frame if necessary
|
|
|
|
if (!lastNewFrame) {
|
|
|
|
nsFrameList tmp(aFrameList);
|
|
|
|
lastNewFrame = tmp.LastChild();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Link the new frames into the child list
|
1999-01-15 04:28:07 +03:00
|
|
|
if (nsnull == aPrevSibling) {
|
|
|
|
lastNewFrame->SetNextSibling(mFirstChild);
|
|
|
|
mFirstChild = aFrameList;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
nsIFrame* nextFrame;
|
1999-02-10 09:13:38 +03:00
|
|
|
aPrevSibling->GetNextSibling(&nextFrame);
|
1999-01-15 04:28:07 +03:00
|
|
|
aPrevSibling->SetNextSibling(aFrameList);
|
|
|
|
lastNewFrame->SetNextSibling(nextFrame);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
2002-11-12 06:30:13 +03:00
|
|
|
nsFrameList::DoReplaceFrame(nsIFrame* aParent,
|
|
|
|
nsIFrame* aOldFrame,
|
|
|
|
nsIFrame* aNewFrame)
|
1999-01-15 04:28:07 +03:00
|
|
|
{
|
2002-11-12 06:30:13 +03:00
|
|
|
NS_PRECONDITION(aOldFrame, "null ptr");
|
|
|
|
NS_PRECONDITION(aNewFrame, "null ptr");
|
|
|
|
if (!aOldFrame || !aNewFrame) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame* nextFrame;
|
|
|
|
aOldFrame->GetNextSibling(&nextFrame);
|
|
|
|
if (aOldFrame == mFirstChild) {
|
|
|
|
mFirstChild = aNewFrame;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
nsIFrame* prevSibling = GetPrevSiblingFor(aOldFrame);
|
|
|
|
if (!prevSibling) {
|
|
|
|
NS_WARNING("nsFrameList::ReplaceFrame: aOldFrame not found in list");
|
|
|
|
return PR_FALSE;
|
1999-01-15 04:28:07 +03:00
|
|
|
}
|
2002-11-12 06:30:13 +03:00
|
|
|
prevSibling->SetNextSibling(aNewFrame);
|
1999-01-15 04:28:07 +03:00
|
|
|
}
|
2002-11-12 06:30:13 +03:00
|
|
|
|
|
|
|
aNewFrame->SetNextSibling(nextFrame);
|
|
|
|
|
|
|
|
if (aParent) {
|
|
|
|
aNewFrame->SetParent(aParent);
|
|
|
|
}
|
|
|
|
return PR_TRUE;
|
1999-01-15 04:28:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
2002-11-12 06:30:13 +03:00
|
|
|
nsFrameList::ReplaceFrame(nsIPresContext* aPresContext,
|
|
|
|
nsIFrame* aParent,
|
|
|
|
nsIFrame* aOldFrame,
|
|
|
|
nsIFrame* aNewFrame,
|
|
|
|
PRBool aDestroy)
|
1999-01-15 04:28:07 +03:00
|
|
|
{
|
2002-11-12 06:30:13 +03:00
|
|
|
NS_PRECONDITION(aOldFrame, "null ptr");
|
|
|
|
NS_PRECONDITION(aNewFrame, "null ptr");
|
|
|
|
if (DoReplaceFrame(aParent, aOldFrame, aNewFrame)) {
|
|
|
|
if (aDestroy) {
|
|
|
|
aOldFrame->Destroy(aPresContext);
|
|
|
|
}
|
1999-01-15 04:28:07 +03:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsFrameList::Split(nsIFrame* aAfterFrame, nsIFrame** aNextFrameResult)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aAfterFrame, "null ptr");
|
|
|
|
NS_PRECONDITION(nsnull != aNextFrameResult, "null ptr");
|
|
|
|
NS_ASSERTION(ContainsFrame(aAfterFrame), "split after unknown frame");
|
|
|
|
|
1999-02-01 20:32:05 +03:00
|
|
|
if ((nsnull != aNextFrameResult) && (nsnull != aAfterFrame)) {
|
1999-01-15 04:28:07 +03:00
|
|
|
nsIFrame* nextFrame;
|
1999-02-10 09:13:38 +03:00
|
|
|
aAfterFrame->GetNextSibling(&nextFrame);
|
1999-01-15 04:28:07 +03:00
|
|
|
aAfterFrame->SetNextSibling(nsnull);
|
|
|
|
*aNextFrameResult = nextFrame;
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
1999-02-01 20:32:05 +03:00
|
|
|
nsIFrame*
|
1999-01-15 04:28:07 +03:00
|
|
|
nsFrameList::PullFrame(nsIFrame* aParent,
|
1999-02-01 20:32:05 +03:00
|
|
|
nsIFrame* aLastChild,
|
|
|
|
nsFrameList& aFromList)
|
1999-01-15 04:28:07 +03:00
|
|
|
{
|
1999-02-01 20:32:05 +03:00
|
|
|
NS_PRECONDITION(nsnull != aParent, "null ptr");
|
|
|
|
|
|
|
|
nsIFrame* pulledFrame = nsnull;
|
|
|
|
if (nsnull != aParent) {
|
|
|
|
pulledFrame = aFromList.FirstChild();
|
1999-01-15 04:28:07 +03:00
|
|
|
if (nsnull != pulledFrame) {
|
1999-02-01 20:32:05 +03:00
|
|
|
// Take frame off old list
|
|
|
|
aFromList.RemoveFirstChild();
|
|
|
|
|
|
|
|
// Put it on the end of this list
|
|
|
|
if (nsnull == aLastChild) {
|
|
|
|
NS_ASSERTION(nsnull == mFirstChild, "bad aLastChild");
|
|
|
|
mFirstChild = pulledFrame;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
aLastChild->SetNextSibling(pulledFrame);
|
|
|
|
}
|
|
|
|
pulledFrame->SetParent(aParent);
|
1999-01-15 04:28:07 +03:00
|
|
|
}
|
|
|
|
}
|
1999-02-01 20:32:05 +03:00
|
|
|
return pulledFrame;
|
1999-01-15 04:28:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame*
|
|
|
|
nsFrameList::LastChild() const
|
|
|
|
{
|
|
|
|
nsIFrame* frame = mFirstChild;
|
|
|
|
while (nsnull != frame) {
|
|
|
|
nsIFrame* next;
|
1999-02-10 09:13:38 +03:00
|
|
|
frame->GetNextSibling(&next);
|
1999-01-15 04:28:07 +03:00
|
|
|
if (nsnull == next) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
frame = next;
|
|
|
|
}
|
|
|
|
return frame;
|
|
|
|
}
|
|
|
|
|
1999-01-16 01:53:39 +03:00
|
|
|
nsIFrame*
|
|
|
|
nsFrameList::FrameAt(PRInt32 aIndex) const
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aIndex >= 0, "invalid arg");
|
|
|
|
if (aIndex < 0) return nsnull;
|
|
|
|
nsIFrame* frame = mFirstChild;
|
|
|
|
while ((aIndex-- > 0) && (nsnull != frame)) {
|
1999-02-10 09:13:38 +03:00
|
|
|
frame->GetNextSibling(&frame);
|
1999-01-16 01:53:39 +03:00
|
|
|
}
|
|
|
|
return frame;
|
|
|
|
}
|
|
|
|
|
1999-01-15 04:28:07 +03:00
|
|
|
PRBool
|
1999-01-16 01:53:39 +03:00
|
|
|
nsFrameList::ContainsFrame(const nsIFrame* aFrame) const
|
1999-01-15 04:28:07 +03:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aFrame, "null ptr");
|
|
|
|
nsIFrame* frame = mFirstChild;
|
|
|
|
while (nsnull != frame) {
|
|
|
|
if (frame == aFrame) {
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
1999-02-10 09:13:38 +03:00
|
|
|
frame->GetNextSibling(&frame);
|
1999-01-15 04:28:07 +03:00
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32
|
|
|
|
nsFrameList::GetLength() const
|
|
|
|
{
|
|
|
|
PRInt32 count = 0;
|
|
|
|
nsIFrame* frame = mFirstChild;
|
|
|
|
while (nsnull != frame) {
|
|
|
|
count++;
|
1999-02-10 09:13:38 +03:00
|
|
|
frame->GetNextSibling(&frame);
|
1999-01-15 04:28:07 +03:00
|
|
|
}
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame*
|
|
|
|
nsFrameList::GetPrevSiblingFor(nsIFrame* aFrame) const
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aFrame, "null ptr");
|
|
|
|
if (aFrame == mFirstChild) {
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
nsIFrame* frame = mFirstChild;
|
|
|
|
while (nsnull != frame) {
|
|
|
|
nsIFrame* next;
|
1999-02-10 09:13:38 +03:00
|
|
|
frame->GetNextSibling(&next);
|
1999-01-15 04:28:07 +03:00
|
|
|
if (next == aFrame) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
frame = next;
|
|
|
|
}
|
|
|
|
return frame;
|
|
|
|
}
|
1999-02-01 20:32:05 +03:00
|
|
|
|
|
|
|
void
|
|
|
|
nsFrameList::VerifyParent(nsIFrame* aParent) const
|
|
|
|
{
|
|
|
|
#ifdef NS_DEBUG
|
|
|
|
nsIFrame* frame = mFirstChild;
|
|
|
|
while (nsnull != frame) {
|
|
|
|
nsIFrame* parent;
|
1999-02-10 04:36:30 +03:00
|
|
|
frame->GetParent(&parent);
|
1999-02-01 20:32:05 +03:00
|
|
|
NS_ASSERTION(parent == aParent, "bad parent");
|
1999-02-10 09:13:38 +03:00
|
|
|
frame->GetNextSibling(&frame);
|
1999-02-01 20:32:05 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
1999-02-03 22:10:26 +03:00
|
|
|
|
1999-11-02 01:12:45 +03:00
|
|
|
#ifdef NS_DEBUG
|
1999-02-03 22:10:26 +03:00
|
|
|
void
|
1999-10-26 08:44:41 +04:00
|
|
|
nsFrameList::List(nsIPresContext* aPresContext, FILE* out) const
|
1999-02-03 22:10:26 +03:00
|
|
|
{
|
|
|
|
fputs("<\n", out);
|
|
|
|
nsIFrame* frame = mFirstChild;
|
|
|
|
while (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->List(aPresContext, out, 1);
|
|
|
|
}
|
1999-02-10 09:13:38 +03:00
|
|
|
frame->GetNextSibling(&frame);
|
1999-02-03 22:10:26 +03:00
|
|
|
}
|
1999-03-24 18:40:44 +03:00
|
|
|
fputs(">\n", out);
|
1999-02-03 22:10:26 +03:00
|
|
|
}
|
1999-11-02 01:12:45 +03:00
|
|
|
#endif
|
2001-03-21 04:16:22 +03:00
|
|
|
|
|
|
|
#ifdef IBMBIDI
|
|
|
|
nsIFrame*
|
|
|
|
nsFrameList::GetPrevVisualFor(nsIFrame* aFrame) const
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aFrame, "null ptr");
|
|
|
|
nsILineIterator* iter;
|
|
|
|
nsCOMPtr<nsIAtom>atom;
|
|
|
|
|
|
|
|
aFrame->GetFrameType(getter_AddRefs(atom));
|
|
|
|
if (atom.get() == nsLayoutAtoms::blockFrame)
|
|
|
|
return GetPrevSiblingFor(aFrame);
|
|
|
|
|
|
|
|
nsRect tempRect;
|
|
|
|
nsIFrame* blockFrame;
|
|
|
|
nsIFrame* frame;
|
|
|
|
nsIFrame* furthestFrame = nsnull;
|
|
|
|
|
|
|
|
frame = mFirstChild;
|
|
|
|
|
|
|
|
nsresult result = aFrame->GetParent(&blockFrame);
|
|
|
|
if (NS_FAILED(result) || !blockFrame)
|
|
|
|
return GetPrevSiblingFor(aFrame);
|
|
|
|
result = blockFrame->QueryInterface(NS_GET_IID(nsILineIterator), (void**)&iter);
|
|
|
|
if (NS_FAILED(result) || !iter) { // If the parent is not a block frame, just check all the siblings
|
|
|
|
|
|
|
|
PRInt32 maxX, limX;
|
|
|
|
maxX = -0x7fffffff;
|
|
|
|
aFrame->GetRect(tempRect);
|
|
|
|
limX = tempRect.x;
|
|
|
|
while (frame) {
|
|
|
|
frame->GetRect(tempRect);
|
|
|
|
if (tempRect.x > maxX && tempRect.x < limX) { // we are looking for the highest value less than the current one
|
|
|
|
maxX = tempRect.x;
|
|
|
|
furthestFrame = frame;
|
|
|
|
}
|
|
|
|
frame->GetNextSibling(&frame);
|
|
|
|
}
|
|
|
|
return furthestFrame;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise use the LineIterator to check the siblings on this line and the previous line
|
|
|
|
if (!blockFrame || !iter)
|
|
|
|
return nsnull;
|
|
|
|
|
2001-05-15 16:29:10 +04:00
|
|
|
nsFrameOrigin maxOrig(LINE_MIN, XCOORD_MIN);
|
2001-03-21 04:16:22 +03:00
|
|
|
PRInt32 testLine, thisLine;
|
|
|
|
|
|
|
|
aFrame->GetRect(tempRect);
|
|
|
|
result = iter->FindLineContaining(aFrame, &thisLine);
|
|
|
|
if (NS_FAILED(result) || thisLine < 0)
|
|
|
|
return nsnull;
|
|
|
|
|
2001-05-15 16:29:10 +04:00
|
|
|
nsFrameOrigin limOrig(thisLine, tempRect.x);
|
2001-03-21 04:16:22 +03:00
|
|
|
|
|
|
|
while (frame) {
|
|
|
|
if (NS_SUCCEEDED(iter->FindLineContaining(frame, &testLine))
|
|
|
|
&& testLine >= 0
|
|
|
|
&& (testLine == thisLine || testLine == thisLine - 1)) {
|
|
|
|
frame->GetRect(tempRect);
|
2001-05-15 16:29:10 +04:00
|
|
|
nsFrameOrigin testOrig(testLine, tempRect.x);
|
|
|
|
if (testOrig > maxOrig && testOrig < limOrig) { // we are looking for the highest value less than the current one
|
2001-03-21 04:16:22 +03:00
|
|
|
maxOrig = testOrig;
|
|
|
|
furthestFrame = frame;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
frame->GetNextSibling(&frame);
|
|
|
|
}
|
|
|
|
return furthestFrame;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame*
|
|
|
|
nsFrameList::GetNextVisualFor(nsIFrame* aFrame) const
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aFrame, "null ptr");
|
|
|
|
nsILineIterator* iter;
|
|
|
|
nsCOMPtr<nsIAtom>atom;
|
|
|
|
|
|
|
|
aFrame->GetFrameType(getter_AddRefs(atom));
|
|
|
|
if (atom.get() == nsLayoutAtoms::blockFrame) {
|
|
|
|
nsIFrame* frame;
|
|
|
|
aFrame->GetNextSibling(&frame);
|
|
|
|
return frame;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRect tempRect;
|
|
|
|
nsIFrame* blockFrame;
|
|
|
|
nsIFrame* frame;
|
|
|
|
nsIFrame* nearestFrame = nsnull;
|
|
|
|
|
|
|
|
frame = mFirstChild;
|
|
|
|
|
|
|
|
nsresult result = aFrame->GetParent(&blockFrame);
|
|
|
|
if (NS_FAILED(result) || !blockFrame)
|
|
|
|
return GetPrevSiblingFor(aFrame);
|
|
|
|
result = blockFrame->QueryInterface(NS_GET_IID(nsILineIterator), (void**)&iter);
|
|
|
|
if (NS_FAILED(result) || !iter) { // If the parent is not a block frame, just check all the siblings
|
|
|
|
|
|
|
|
PRInt32 minX, limX;
|
|
|
|
minX = 0x7fffffff;
|
|
|
|
aFrame->GetRect(tempRect);
|
|
|
|
limX = tempRect.x;
|
|
|
|
while (frame) {
|
|
|
|
frame->GetRect(tempRect);
|
|
|
|
if (tempRect.x < minX && tempRect.x > limX) { // we are looking for the lowest value greater than the current one
|
|
|
|
minX = tempRect.x;
|
|
|
|
nearestFrame = frame;
|
|
|
|
}
|
|
|
|
frame->GetNextSibling(&frame);
|
|
|
|
}
|
|
|
|
return nearestFrame;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise use the LineIterator to check the siblings on this line and the previous line
|
|
|
|
if (!blockFrame || !iter)
|
|
|
|
return nsnull;
|
|
|
|
|
2001-05-15 18:34:23 +04:00
|
|
|
nsFrameOrigin minOrig(MY_LINE_MAX, XCOORD_MAX);
|
2001-03-21 04:16:22 +03:00
|
|
|
PRInt32 testLine, thisLine;
|
|
|
|
|
|
|
|
aFrame->GetRect(tempRect);
|
|
|
|
result = iter->FindLineContaining(aFrame, &thisLine);
|
|
|
|
if (NS_FAILED(result) || thisLine < 0)
|
|
|
|
return nsnull;
|
|
|
|
|
2001-05-15 16:29:10 +04:00
|
|
|
nsFrameOrigin limOrig(thisLine, tempRect.x);
|
2001-03-21 04:16:22 +03:00
|
|
|
|
|
|
|
while (frame) {
|
|
|
|
if (NS_SUCCEEDED(iter->FindLineContaining(frame, &testLine))
|
|
|
|
&& testLine >= 0
|
|
|
|
&& (testLine == thisLine || testLine == thisLine + 1)) {
|
|
|
|
frame->GetRect(tempRect);
|
2001-05-15 16:29:10 +04:00
|
|
|
nsFrameOrigin testOrig(testLine, tempRect.x);
|
|
|
|
if (testOrig < minOrig && testOrig > limOrig) { // we are looking for the lowest value greater than the current one
|
2001-03-21 04:16:22 +03:00
|
|
|
minOrig = testOrig;
|
|
|
|
nearestFrame = frame;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
frame->GetNextSibling(&frame);
|
|
|
|
}
|
|
|
|
return nearestFrame;
|
|
|
|
}
|
|
|
|
#endif
|