2001-09-29 00:14:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-18 18:30:37 +04:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
1999-02-19 03:21:22 +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/
|
1999-02-19 03:21:22 +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-02-19 03:21:22 +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):
|
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
|
|
|
|
|
|
|
/* class for maintaining a linked list of child frames */
|
|
|
|
|
1999-02-19 03:21:22 +03:00
|
|
|
#include "nsFrameList.h"
|
2009-07-28 16:51:08 +04:00
|
|
|
#include "nsIFrame.h"
|
|
|
|
#ifdef DEBUG
|
1999-11-02 01:12:45 +03:00
|
|
|
#include "nsIFrameDebug.h"
|
|
|
|
#endif
|
2005-03-23 06:35:08 +03:00
|
|
|
#include "nsLayoutUtils.h"
|
1999-02-19 03:21:22 +03:00
|
|
|
|
2001-03-21 04:16:22 +03:00
|
|
|
#ifdef IBMBIDI
|
|
|
|
#include "nsCOMPtr.h"
|
2007-01-30 03:06:41 +03:00
|
|
|
#include "nsGkAtoms.h"
|
2001-03-21 04:16:22 +03:00
|
|
|
#include "nsILineIterator.h"
|
2006-03-12 12:49:48 +03:00
|
|
|
#include "nsBidiPresUtils.h"
|
2001-03-21 04:16:22 +03:00
|
|
|
#endif // IBMBIDI
|
|
|
|
|
2009-07-28 16:51:09 +04:00
|
|
|
const nsFrameList* nsFrameList::sEmptyList;
|
|
|
|
|
|
|
|
/* static */
|
|
|
|
nsresult
|
|
|
|
nsFrameList::Init()
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(!sEmptyList, "Shouldn't be allocated");
|
|
|
|
sEmptyList = new nsFrameList();
|
|
|
|
if (!sEmptyList)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-07-26 08:03:29 +04:00
|
|
|
void
|
|
|
|
nsFrameList::Destroy()
|
|
|
|
{
|
|
|
|
DestroyFrames();
|
|
|
|
delete this;
|
|
|
|
}
|
|
|
|
|
1999-02-19 03:21:22 +03:00
|
|
|
void
|
2006-04-10 04:16:29 +04:00
|
|
|
nsFrameList::DestroyFrames()
|
1999-02-19 03:21:22 +03:00
|
|
|
{
|
2003-07-02 14:30:00 +04:00
|
|
|
nsIFrame* next;
|
|
|
|
for (nsIFrame* frame = mFirstChild; frame; frame = next) {
|
|
|
|
next = frame->GetNextSibling();
|
2006-04-10 04:16:29 +04:00
|
|
|
frame->Destroy();
|
2003-07-02 14:30:00 +04:00
|
|
|
mFirstChild = next;
|
1999-02-19 03:21:22 +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);
|
|
|
|
}
|
2003-07-02 14:30:00 +04:00
|
|
|
if (aParent) {
|
|
|
|
for (nsIFrame* frame = aFrameList; frame;
|
|
|
|
frame = frame->GetNextSibling()) {
|
1999-02-19 03:21:22 +03:00
|
|
|
frame->SetParent(aParent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-10-30 22:35:53 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
CheckForLoops();
|
|
|
|
#endif
|
1999-02-19 03:21:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsFrameList::AppendFrame(nsIFrame* aParent, nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aFrame, "null ptr");
|
|
|
|
if (nsnull != aFrame) {
|
2005-03-23 06:35:08 +03:00
|
|
|
NS_PRECONDITION(!aFrame->GetNextSibling(), "Can only append one frame here");
|
1999-02-19 03:21:22 +03:00
|
|
|
nsIFrame* lastChild = LastChild();
|
|
|
|
if (nsnull == lastChild) {
|
|
|
|
mFirstChild = aFrame;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
lastChild->SetNextSibling(aFrame);
|
|
|
|
}
|
|
|
|
if (nsnull != aParent) {
|
|
|
|
aFrame->SetParent(aParent);
|
|
|
|
}
|
|
|
|
}
|
2004-10-30 22:35:53 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
CheckForLoops();
|
|
|
|
#endif
|
1999-02-19 03:21:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
2005-02-16 23:02:14 +03:00
|
|
|
nsFrameList::RemoveFrame(nsIFrame* aFrame, nsIFrame* aPrevSiblingHint)
|
1999-02-19 03:21:22 +03:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aFrame, "null ptr");
|
2005-03-23 06:35:08 +03:00
|
|
|
if (aFrame) {
|
2003-07-02 14:30:00 +04:00
|
|
|
nsIFrame* nextFrame = aFrame->GetNextSibling();
|
1999-02-19 03:21:22 +03:00
|
|
|
if (aFrame == mFirstChild) {
|
|
|
|
mFirstChild = nextFrame;
|
2005-03-23 06:35:08 +03:00
|
|
|
aFrame->SetNextSibling(nsnull);
|
1999-02-19 03:21:22 +03:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
else {
|
2005-02-16 23:02:14 +03:00
|
|
|
nsIFrame* prevSibling = aPrevSiblingHint;
|
|
|
|
if (!prevSibling || prevSibling->GetNextSibling() != aFrame) {
|
|
|
|
prevSibling = GetPrevSiblingFor(aFrame);
|
|
|
|
}
|
2003-07-02 14:30:00 +04:00
|
|
|
if (prevSibling) {
|
1999-02-19 03:21:22 +03:00
|
|
|
prevSibling->SetNextSibling(nextFrame);
|
2005-03-23 06:35:08 +03:00
|
|
|
aFrame->SetNextSibling(nsnull);
|
1999-02-19 03:21:22 +03:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-03-04 18:48:56 +03:00
|
|
|
// aFrame was not in the list.
|
1999-02-19 03:21:22 +03:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsFrameList::RemoveFirstChild()
|
|
|
|
{
|
2003-07-02 14:30:00 +04:00
|
|
|
if (mFirstChild) {
|
|
|
|
nsIFrame* nextFrame = mFirstChild->GetNextSibling();
|
1999-02-19 03:21:22 +03:00
|
|
|
mFirstChild->SetNextSibling(nsnull);
|
|
|
|
mFirstChild = nextFrame;
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
2009-07-28 16:53:18 +04:00
|
|
|
nsFrameList::DestroyFrame(nsIFrame* aFrame, nsIFrame* aPrevSiblingHint)
|
1999-02-19 03:21:22 +03:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aFrame, "null ptr");
|
2009-07-28 16:53:18 +04:00
|
|
|
if (RemoveFrame(aFrame, aPrevSiblingHint)) {
|
2006-04-10 04:16:29 +04:00
|
|
|
aFrame->Destroy();
|
1999-02-19 03:21:22 +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) {
|
2008-09-27 15:07:29 +04:00
|
|
|
NS_ASSERTION(!aNewFrame->GetNextSibling(),
|
|
|
|
"the pointer to this sibling will be overwritten");
|
2006-06-29 06:32:36 +04:00
|
|
|
if (aParent) {
|
|
|
|
aNewFrame->SetParent(aParent);
|
|
|
|
}
|
1999-02-19 03:21:22 +03:00
|
|
|
if (nsnull == aPrevSibling) {
|
|
|
|
aNewFrame->SetNextSibling(mFirstChild);
|
|
|
|
mFirstChild = aNewFrame;
|
|
|
|
}
|
|
|
|
else {
|
2006-06-29 06:32:36 +04:00
|
|
|
NS_ASSERTION(aNewFrame->GetParent() == aPrevSibling->GetParent(),
|
|
|
|
"prev sibling has different parent");
|
2003-07-02 14:30:00 +04:00
|
|
|
nsIFrame* nextFrame = aPrevSibling->GetNextSibling();
|
2006-06-29 06:32:36 +04:00
|
|
|
NS_ASSERTION(!nextFrame ||
|
|
|
|
aNewFrame->GetParent() == nextFrame->GetParent(),
|
|
|
|
"next sibling has different parent");
|
1999-02-19 03:21:22 +03:00
|
|
|
aPrevSibling->SetNextSibling(aNewFrame);
|
|
|
|
aNewFrame->SetNextSibling(nextFrame);
|
|
|
|
}
|
|
|
|
}
|
2004-10-30 22:35:53 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
CheckForLoops();
|
|
|
|
#endif
|
1999-02-19 03:21:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsFrameList::InsertFrames(nsIFrame* aParent,
|
|
|
|
nsIFrame* aPrevSibling,
|
|
|
|
nsIFrame* aFrameList)
|
|
|
|
{
|
2009-07-28 16:51:09 +04:00
|
|
|
// XXXbz once we have fast access to last frames (and have an nsFrameList
|
|
|
|
// here, not an nsIFrame*), we should clean up this method significantly.
|
1999-02-19 03:21:22 +03:00
|
|
|
NS_PRECONDITION(nsnull != aFrameList, "null ptr");
|
|
|
|
if (nsnull != aFrameList) {
|
2000-03-12 06:07:52 +03:00
|
|
|
nsIFrame* lastNewFrame = nsnull;
|
2003-07-02 14:30:00 +04:00
|
|
|
if (aParent) {
|
|
|
|
for (nsIFrame* frame = aFrameList; frame;
|
|
|
|
frame = frame->GetNextSibling()) {
|
1999-02-19 03:21:22 +03:00
|
|
|
frame->SetParent(aParent);
|
2000-03-12 06:07:52 +03:00
|
|
|
lastNewFrame = frame;
|
1999-02-19 03:21:22 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-03-12 06:07:52 +03:00
|
|
|
// Get the last new frame if necessary
|
2009-07-28 16:51:09 +04:00
|
|
|
if (!lastNewFrame &&
|
|
|
|
((aPrevSibling && aPrevSibling->GetNextSibling()) ||
|
|
|
|
mFirstChild)) {
|
2000-03-12 06:07:52 +03:00
|
|
|
nsFrameList tmp(aFrameList);
|
|
|
|
lastNewFrame = tmp.LastChild();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Link the new frames into the child list
|
2009-07-28 16:51:09 +04:00
|
|
|
if (!aPrevSibling) {
|
|
|
|
NS_ASSERTION(lastNewFrame || !mFirstChild,
|
|
|
|
"Should have lastNewFrame here");
|
|
|
|
if (lastNewFrame) {
|
|
|
|
lastNewFrame->SetNextSibling(mFirstChild);
|
|
|
|
}
|
1999-02-19 03:21:22 +03:00
|
|
|
mFirstChild = aFrameList;
|
|
|
|
}
|
|
|
|
else {
|
2006-06-29 06:32:36 +04:00
|
|
|
NS_ASSERTION(aFrameList->GetParent() == aPrevSibling->GetParent(),
|
|
|
|
"prev sibling has different parent");
|
2003-07-02 14:30:00 +04:00
|
|
|
nsIFrame* nextFrame = aPrevSibling->GetNextSibling();
|
2006-06-29 06:32:36 +04:00
|
|
|
NS_ASSERTION(!nextFrame ||
|
|
|
|
aFrameList->GetParent() == nextFrame->GetParent(),
|
|
|
|
"next sibling has different parent");
|
1999-02-19 03:21:22 +03:00
|
|
|
aPrevSibling->SetNextSibling(aFrameList);
|
2009-07-28 16:51:09 +04:00
|
|
|
NS_ASSERTION(lastNewFrame || !nextFrame, "Should have lastNewFrame here");
|
|
|
|
if (lastNewFrame) {
|
|
|
|
lastNewFrame->SetNextSibling(nextFrame);
|
|
|
|
}
|
1999-02-19 03:21:22 +03:00
|
|
|
}
|
|
|
|
}
|
2004-10-30 22:35:53 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
CheckForLoops();
|
|
|
|
#endif
|
1999-02-19 03:21:22 +03:00
|
|
|
}
|
|
|
|
|
2009-07-28 16:53:19 +04:00
|
|
|
nsFrameList
|
|
|
|
nsFrameList::ExtractHead(FrameLinkEnumerator& aLink)
|
1999-02-19 03:21:22 +03:00
|
|
|
{
|
2009-07-28 16:53:19 +04:00
|
|
|
NS_PRECONDITION(&aLink.List() == this, "Unexpected list");
|
|
|
|
NS_PRECONDITION(!aLink.PrevFrame() ||
|
|
|
|
aLink.PrevFrame()->GetNextSibling() ==
|
|
|
|
aLink.NextFrame(),
|
|
|
|
"Unexpected PrevFrame()");
|
1999-02-19 03:21:22 +03:00
|
|
|
|
2009-07-28 16:53:19 +04:00
|
|
|
nsIFrame* prev = aLink.PrevFrame();
|
|
|
|
nsIFrame* newFirstFrame = nsnull;
|
|
|
|
if (prev) {
|
|
|
|
// Truncate the list after |prev| and hand the first part to our new list.
|
|
|
|
prev->SetNextSibling(nsnull);
|
|
|
|
newFirstFrame = mFirstChild;
|
|
|
|
mFirstChild = aLink.NextFrame();
|
|
|
|
|
|
|
|
// Now make sure aLink doesn't point to a frame we no longer have.
|
|
|
|
aLink.mPrev = nsnull;
|
1999-02-19 03:21:22 +03:00
|
|
|
}
|
2009-07-28 16:53:19 +04:00
|
|
|
// else aLink is pointing to before our first frame. Nothing to do.
|
|
|
|
|
|
|
|
return nsFrameList(newFirstFrame);
|
1999-02-19 03:21:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame*
|
|
|
|
nsFrameList::LastChild() const
|
|
|
|
{
|
|
|
|
nsIFrame* frame = mFirstChild;
|
2003-07-02 14:30:00 +04:00
|
|
|
if (!frame) {
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame* next = frame->GetNextSibling();
|
|
|
|
while (next) {
|
1999-02-19 03:21:22 +03:00
|
|
|
frame = next;
|
2003-07-02 14:30:00 +04:00
|
|
|
next = frame->GetNextSibling();
|
1999-02-19 03:21:22 +03:00
|
|
|
}
|
|
|
|
return frame;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame*
|
|
|
|
nsFrameList::FrameAt(PRInt32 aIndex) const
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aIndex >= 0, "invalid arg");
|
|
|
|
if (aIndex < 0) return nsnull;
|
|
|
|
nsIFrame* frame = mFirstChild;
|
2003-07-02 14:30:00 +04:00
|
|
|
while ((aIndex-- > 0) && frame) {
|
|
|
|
frame = frame->GetNextSibling();
|
1999-02-19 03:21:22 +03:00
|
|
|
}
|
|
|
|
return frame;
|
|
|
|
}
|
|
|
|
|
2009-04-25 12:33:32 +04:00
|
|
|
PRInt32
|
|
|
|
nsFrameList::IndexOf(nsIFrame* aFrame) const
|
|
|
|
{
|
|
|
|
PRInt32 count = 0;
|
|
|
|
for (nsIFrame* f = mFirstChild; f; f = f->GetNextSibling()) {
|
|
|
|
if (f == aFrame)
|
|
|
|
return count;
|
|
|
|
++count;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
1999-02-19 03:21:22 +03:00
|
|
|
PRBool
|
|
|
|
nsFrameList::ContainsFrame(const nsIFrame* aFrame) const
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aFrame, "null ptr");
|
|
|
|
nsIFrame* frame = mFirstChild;
|
2003-07-02 14:30:00 +04:00
|
|
|
while (frame) {
|
1999-02-19 03:21:22 +03:00
|
|
|
if (frame == aFrame) {
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
2003-07-02 14:30:00 +04:00
|
|
|
frame = frame->GetNextSibling();
|
1999-02-19 03:21:22 +03:00
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2008-01-30 02:39:39 +03:00
|
|
|
PRBool
|
|
|
|
nsFrameList::ContainsFrameBefore(const nsIFrame* aFrame, const nsIFrame* aEnd) const
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aFrame, "null ptr");
|
|
|
|
nsIFrame* frame = mFirstChild;
|
|
|
|
while (frame) {
|
|
|
|
if (frame == aEnd) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
if (frame == aFrame) {
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
frame = frame->GetNextSibling();
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
1999-02-19 03:21:22 +03:00
|
|
|
PRInt32
|
|
|
|
nsFrameList::GetLength() const
|
|
|
|
{
|
|
|
|
PRInt32 count = 0;
|
|
|
|
nsIFrame* frame = mFirstChild;
|
2003-07-02 14:30:00 +04:00
|
|
|
while (frame) {
|
1999-02-19 03:21:22 +03:00
|
|
|
count++;
|
2003-07-02 14:30:00 +04:00
|
|
|
frame = frame->GetNextSibling();
|
1999-02-19 03:21:22 +03:00
|
|
|
}
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2009-02-03 17:42:18 +03:00
|
|
|
static int CompareByContentOrder(const nsIFrame* aF1, const nsIFrame* aF2)
|
2005-03-23 06:35:08 +03:00
|
|
|
{
|
2009-02-03 17:42:18 +03:00
|
|
|
if (aF1->GetContent() != aF2->GetContent()) {
|
|
|
|
return nsLayoutUtils::CompareTreePosition(aF1->GetContent(), aF2->GetContent());
|
2005-03-23 06:35:08 +03:00
|
|
|
}
|
|
|
|
|
2009-02-03 17:42:18 +03:00
|
|
|
if (aF1 == aF2) {
|
2005-03-23 06:35:08 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
const nsIFrame* f;
|
2009-02-03 17:42:18 +03:00
|
|
|
for (f = aF2; f; f = f->GetPrevInFlow()) {
|
|
|
|
if (f == aF1) {
|
2005-03-23 06:35:08 +03:00
|
|
|
// f1 comes before f2 in the flow
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
2009-02-03 17:42:18 +03:00
|
|
|
for (f = aF1; f; f = f->GetPrevInFlow()) {
|
|
|
|
if (f == aF2) {
|
2005-03-23 06:35:08 +03:00
|
|
|
// f1 comes after f2 in the flow
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION(PR_FALSE, "Frames for same content but not in relative flow order");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-02-03 17:42:18 +03:00
|
|
|
class CompareByContentOrderComparator
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
PRBool Equals(const nsIFrame* aA, const nsIFrame* aB) const {
|
|
|
|
return aA == aB;
|
|
|
|
}
|
|
|
|
PRBool LessThan(const nsIFrame* aA, const nsIFrame* aB) const {
|
|
|
|
return CompareByContentOrder(aA, aB) < 0;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2005-03-23 06:35:08 +03:00
|
|
|
void
|
|
|
|
nsFrameList::SortByContentOrder()
|
|
|
|
{
|
|
|
|
if (!mFirstChild)
|
|
|
|
return;
|
|
|
|
|
2009-02-03 17:42:18 +03:00
|
|
|
nsAutoTArray<nsIFrame*, 8> array;
|
2005-03-23 06:35:08 +03:00
|
|
|
nsIFrame* f;
|
|
|
|
for (f = mFirstChild; f; f = f->GetNextSibling()) {
|
|
|
|
array.AppendElement(f);
|
|
|
|
}
|
2009-02-03 17:42:18 +03:00
|
|
|
array.Sort(CompareByContentOrderComparator());
|
|
|
|
f = mFirstChild = array.ElementAt(0);
|
|
|
|
for (PRUint32 i = 1; i < array.Length(); ++i) {
|
|
|
|
nsIFrame* ff = array.ElementAt(i);
|
2005-03-23 06:35:08 +03:00
|
|
|
f->SetNextSibling(ff);
|
|
|
|
f = ff;
|
|
|
|
}
|
|
|
|
f->SetNextSibling(nsnull);
|
|
|
|
}
|
|
|
|
|
1999-02-19 03:21:22 +03:00
|
|
|
nsIFrame*
|
|
|
|
nsFrameList::GetPrevSiblingFor(nsIFrame* aFrame) const
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aFrame, "null ptr");
|
|
|
|
if (aFrame == mFirstChild) {
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
nsIFrame* frame = mFirstChild;
|
2003-07-02 14:30:00 +04:00
|
|
|
while (frame) {
|
|
|
|
nsIFrame* next = frame->GetNextSibling();
|
1999-02-19 03:21:22 +03:00
|
|
|
if (next == aFrame) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
frame = next;
|
|
|
|
}
|
|
|
|
return frame;
|
|
|
|
}
|
|
|
|
|
2009-07-28 16:51:08 +04:00
|
|
|
#ifdef DEBUG
|
1999-02-19 03:21:22 +03:00
|
|
|
void
|
2005-09-07 01:34:50 +04:00
|
|
|
nsFrameList::List(FILE* out) const
|
1999-02-19 03:21:22 +03:00
|
|
|
{
|
|
|
|
fputs("<\n", out);
|
2003-07-02 14:30:00 +04:00
|
|
|
for (nsIFrame* frame = mFirstChild; frame;
|
|
|
|
frame = frame->GetNextSibling()) {
|
2009-01-12 22:20:59 +03:00
|
|
|
nsIFrameDebug *frameDebug = do_QueryFrame(frame);
|
|
|
|
if (frameDebug) {
|
2005-09-07 01:34:50 +04:00
|
|
|
frameDebug->List(out, 1);
|
1999-11-02 01:12:45 +03:00
|
|
|
}
|
1999-02-19 03:21:22 +03:00
|
|
|
}
|
1999-03-24 18:40:44 +03:00
|
|
|
fputs(">\n", out);
|
1999-02-19 03:21:22 +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
|
|
|
|
{
|
2006-03-14 12:16:40 +03:00
|
|
|
if (!mFirstChild)
|
|
|
|
return nsnull;
|
|
|
|
|
|
|
|
nsIFrame* parent = mFirstChild->GetParent();
|
|
|
|
if (!parent)
|
|
|
|
return aFrame ? GetPrevSiblingFor(aFrame) : LastChild();
|
2005-10-22 00:08:50 +04:00
|
|
|
|
2007-01-13 21:20:28 +03:00
|
|
|
nsBidiLevel baseLevel = nsBidiPresUtils::GetFrameBaseLevel(mFirstChild);
|
2007-03-31 01:11:41 +04:00
|
|
|
nsBidiPresUtils* bidiUtils = mFirstChild->PresContext()->GetBidiUtils();
|
2007-01-13 21:20:28 +03:00
|
|
|
|
2008-10-30 22:17:59 +03:00
|
|
|
nsAutoLineIterator iter = parent->GetLineIterator();
|
|
|
|
if (!iter) {
|
2007-01-13 21:20:28 +03:00
|
|
|
// Parent is not a block Frame
|
|
|
|
if (parent->GetType() == nsGkAtoms::lineFrame) {
|
|
|
|
// Line frames are not bidi-splittable, so need to consider bidi reordering
|
|
|
|
if (baseLevel == NSBIDI_LTR) {
|
|
|
|
return bidiUtils->GetFrameToLeftOf(aFrame, mFirstChild, -1);
|
|
|
|
} else { // RTL
|
|
|
|
return bidiUtils->GetFrameToRightOf(aFrame, mFirstChild, -1);
|
|
|
|
}
|
2006-03-12 12:49:48 +03:00
|
|
|
} else {
|
2007-01-13 21:20:28 +03:00
|
|
|
// Just get the next or prev sibling, depending on block and frame direction.
|
|
|
|
nsBidiLevel frameEmbeddingLevel = nsBidiPresUtils::GetFrameEmbeddingLevel(mFirstChild);
|
|
|
|
if ((frameEmbeddingLevel & 1) == (baseLevel & 1)) {
|
|
|
|
return aFrame ? GetPrevSiblingFor(aFrame) : LastChild();
|
|
|
|
} else {
|
|
|
|
return aFrame ? aFrame->GetNextSibling() : mFirstChild;
|
|
|
|
}
|
|
|
|
}
|
2001-03-21 04:16:22 +03:00
|
|
|
}
|
|
|
|
|
2007-01-13 21:20:28 +03:00
|
|
|
// Parent is a block frame, so use the LineIterator to find the previous visual
|
|
|
|
// sibling on this line, or the last one on the previous line.
|
2001-03-21 04:16:22 +03:00
|
|
|
|
2006-03-12 12:49:48 +03:00
|
|
|
PRInt32 thisLine;
|
2006-03-14 12:16:40 +03:00
|
|
|
if (aFrame) {
|
2008-10-30 22:17:59 +03:00
|
|
|
thisLine = iter->FindLineContaining(aFrame);
|
|
|
|
if (thisLine < 0)
|
2006-03-14 12:16:40 +03:00
|
|
|
return nsnull;
|
|
|
|
} else {
|
2008-10-30 22:17:59 +03:00
|
|
|
thisLine = iter->GetNumLines();
|
2006-03-14 12:16:40 +03:00
|
|
|
}
|
2007-01-13 21:20:28 +03:00
|
|
|
|
2006-03-14 12:16:40 +03:00
|
|
|
nsIFrame* frame = nsnull;
|
2006-03-12 12:49:48 +03:00
|
|
|
nsIFrame* firstFrameOnLine;
|
|
|
|
PRInt32 numFramesOnLine;
|
|
|
|
nsRect lineBounds;
|
|
|
|
PRUint32 lineFlags;
|
|
|
|
|
2006-03-14 12:16:40 +03:00
|
|
|
if (aFrame) {
|
|
|
|
iter->GetLine(thisLine, &firstFrameOnLine, &numFramesOnLine, lineBounds, &lineFlags);
|
|
|
|
|
|
|
|
if (baseLevel == NSBIDI_LTR) {
|
|
|
|
frame = bidiUtils->GetFrameToLeftOf(aFrame, firstFrameOnLine, numFramesOnLine);
|
|
|
|
} else { // RTL
|
|
|
|
frame = bidiUtils->GetFrameToRightOf(aFrame, firstFrameOnLine, numFramesOnLine);
|
|
|
|
}
|
2006-03-12 12:49:48 +03:00
|
|
|
}
|
2001-03-21 04:16:22 +03:00
|
|
|
|
2006-03-12 12:49:48 +03:00
|
|
|
if (!frame && thisLine > 0) {
|
|
|
|
// Get the last frame of the previous line
|
|
|
|
iter->GetLine(thisLine - 1, &firstFrameOnLine, &numFramesOnLine, lineBounds, &lineFlags);
|
|
|
|
|
|
|
|
if (baseLevel == NSBIDI_LTR) {
|
|
|
|
frame = bidiUtils->GetFrameToLeftOf(nsnull, firstFrameOnLine, numFramesOnLine);
|
|
|
|
} else { // RTL
|
|
|
|
frame = bidiUtils->GetFrameToRightOf(nsnull, firstFrameOnLine, numFramesOnLine);
|
2001-03-21 04:16:22 +03:00
|
|
|
}
|
|
|
|
}
|
2006-03-12 12:49:48 +03:00
|
|
|
return frame;
|
2001-03-21 04:16:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame*
|
|
|
|
nsFrameList::GetNextVisualFor(nsIFrame* aFrame) const
|
|
|
|
{
|
2006-03-14 12:16:40 +03:00
|
|
|
if (!mFirstChild)
|
|
|
|
return nsnull;
|
|
|
|
|
|
|
|
nsIFrame* parent = mFirstChild->GetParent();
|
|
|
|
if (!parent)
|
|
|
|
return aFrame ? GetPrevSiblingFor(aFrame) : mFirstChild;
|
2005-10-22 00:08:50 +04:00
|
|
|
|
2006-03-14 12:16:40 +03:00
|
|
|
nsBidiLevel baseLevel = nsBidiPresUtils::GetFrameBaseLevel(mFirstChild);
|
2007-03-31 01:11:41 +04:00
|
|
|
nsBidiPresUtils* bidiUtils = mFirstChild->PresContext()->GetBidiUtils();
|
2005-10-22 00:08:50 +04:00
|
|
|
|
2008-10-30 22:17:59 +03:00
|
|
|
nsAutoLineIterator iter = parent->GetLineIterator();
|
|
|
|
if (!iter) {
|
2007-01-13 21:20:28 +03:00
|
|
|
// Parent is not a block Frame
|
|
|
|
if (parent->GetType() == nsGkAtoms::lineFrame) {
|
|
|
|
// Line frames are not bidi-splittable, so need to consider bidi reordering
|
|
|
|
if (baseLevel == NSBIDI_LTR) {
|
|
|
|
return bidiUtils->GetFrameToRightOf(aFrame, mFirstChild, -1);
|
|
|
|
} else { // RTL
|
|
|
|
return bidiUtils->GetFrameToLeftOf(aFrame, mFirstChild, -1);
|
|
|
|
}
|
2006-03-12 12:49:48 +03:00
|
|
|
} else {
|
2007-01-13 21:20:28 +03:00
|
|
|
// Just get the next or prev sibling, depending on block and frame direction.
|
|
|
|
nsBidiLevel frameEmbeddingLevel = nsBidiPresUtils::GetFrameEmbeddingLevel(mFirstChild);
|
|
|
|
if ((frameEmbeddingLevel & 1) == (baseLevel & 1)) {
|
|
|
|
return aFrame ? aFrame->GetNextSibling() : mFirstChild;
|
|
|
|
} else {
|
|
|
|
return aFrame ? GetPrevSiblingFor(aFrame) : LastChild();
|
|
|
|
}
|
|
|
|
}
|
2006-03-12 12:49:48 +03:00
|
|
|
}
|
|
|
|
|
2007-01-13 21:20:28 +03:00
|
|
|
// Parent is a block frame, so use the LineIterator to find the next visual
|
|
|
|
// sibling on this line, or the first one on the next line.
|
2006-03-12 12:49:48 +03:00
|
|
|
|
|
|
|
PRInt32 thisLine;
|
2006-03-14 12:16:40 +03:00
|
|
|
if (aFrame) {
|
2008-10-30 22:17:59 +03:00
|
|
|
thisLine = iter->FindLineContaining(aFrame);
|
|
|
|
if (thisLine < 0)
|
2006-03-14 12:16:40 +03:00
|
|
|
return nsnull;
|
|
|
|
} else {
|
|
|
|
thisLine = -1;
|
|
|
|
}
|
2007-01-13 21:20:28 +03:00
|
|
|
|
2006-03-14 12:16:40 +03:00
|
|
|
nsIFrame* frame = nsnull;
|
2006-03-12 12:49:48 +03:00
|
|
|
nsIFrame* firstFrameOnLine;
|
|
|
|
PRInt32 numFramesOnLine;
|
|
|
|
nsRect lineBounds;
|
|
|
|
PRUint32 lineFlags;
|
2006-03-14 12:16:40 +03:00
|
|
|
|
|
|
|
if (aFrame) {
|
|
|
|
iter->GetLine(thisLine, &firstFrameOnLine, &numFramesOnLine, lineBounds, &lineFlags);
|
|
|
|
|
|
|
|
if (baseLevel == NSBIDI_LTR) {
|
|
|
|
frame = bidiUtils->GetFrameToRightOf(aFrame, firstFrameOnLine, numFramesOnLine);
|
|
|
|
} else { // RTL
|
|
|
|
frame = bidiUtils->GetFrameToLeftOf(aFrame, firstFrameOnLine, numFramesOnLine);
|
|
|
|
}
|
2006-03-12 12:49:48 +03:00
|
|
|
}
|
|
|
|
|
2008-10-30 22:17:59 +03:00
|
|
|
PRInt32 numLines = iter->GetNumLines();
|
2006-03-12 12:49:48 +03:00
|
|
|
if (!frame && thisLine < numLines - 1) {
|
|
|
|
// Get the first frame of the next line
|
|
|
|
iter->GetLine(thisLine + 1, &firstFrameOnLine, &numFramesOnLine, lineBounds, &lineFlags);
|
|
|
|
|
|
|
|
if (baseLevel == NSBIDI_LTR) {
|
|
|
|
frame = bidiUtils->GetFrameToRightOf(nsnull, firstFrameOnLine, numFramesOnLine);
|
|
|
|
} else { // RTL
|
|
|
|
frame = bidiUtils->GetFrameToLeftOf(nsnull, firstFrameOnLine, numFramesOnLine);
|
2001-03-21 04:16:22 +03:00
|
|
|
}
|
|
|
|
}
|
2006-03-12 12:49:48 +03:00
|
|
|
return frame;
|
2001-03-21 04:16:22 +03:00
|
|
|
}
|
|
|
|
#endif
|
2004-10-30 22:35:53 +04:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
void
|
|
|
|
nsFrameList::CheckForLoops()
|
|
|
|
{
|
|
|
|
if (!mFirstChild) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Simple algorithm to find a loop in a linked list -- advance pointers
|
|
|
|
// through it at speeds of 1 and 2, and if they ever get to be equal bail
|
|
|
|
nsIFrame *first = mFirstChild, *second = mFirstChild;
|
|
|
|
do {
|
|
|
|
first = first->GetNextSibling();
|
|
|
|
second = second->GetNextSibling();
|
|
|
|
if (!second) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
second = second->GetNextSibling();
|
|
|
|
if (first == second) {
|
|
|
|
// Loop detected! Since second advances faster, they can't both be null;
|
|
|
|
// we would have broken out of the loop long ago.
|
|
|
|
NS_ERROR("loop in frame list. This will probably hang soon.");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while (first && second);
|
|
|
|
}
|
|
|
|
#endif
|