1999-02-22 06:19:24 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
1999-11-06 06:40:37 +03: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-02-22 06:19:24 +03:00
|
|
|
*
|
1999-11-06 06:40:37 +03: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-22 06:19:24 +03:00
|
|
|
*
|
1999-11-06 06:40:37 +03:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape
|
1999-02-22 06:19:24 +03:00
|
|
|
* Communications Corporation. Portions created by Netscape are
|
1999-11-06 06:40:37 +03:00
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
1999-02-22 06:19:24 +03:00
|
|
|
*/
|
1999-02-10 21:55:25 +03:00
|
|
|
#include "nsFrameTraversal.h"
|
|
|
|
#include "nsFrameList.h"
|
|
|
|
|
|
|
|
|
|
|
|
static NS_DEFINE_IID(kIEnumeratorIID, NS_IENUMERATOR_IID);
|
|
|
|
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
|
|
|
|
|
|
|
|
1999-02-23 11:10:24 +03:00
|
|
|
class nsFrameIterator: public nsIBidirectionalEnumerator
|
1999-02-10 21:55:25 +03:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
1999-02-20 02:47:36 +03:00
|
|
|
NS_IMETHOD First();
|
1999-02-10 21:55:25 +03:00
|
|
|
|
1999-02-20 02:47:36 +03:00
|
|
|
NS_IMETHOD Last();
|
1999-02-10 21:55:25 +03:00
|
|
|
|
1999-02-20 02:47:36 +03:00
|
|
|
NS_IMETHOD Next()=0;
|
1999-02-10 21:55:25 +03:00
|
|
|
|
1999-02-20 02:47:36 +03:00
|
|
|
NS_IMETHOD Prev()=0;
|
1999-02-10 21:55:25 +03:00
|
|
|
|
1999-02-20 02:47:36 +03:00
|
|
|
NS_IMETHOD CurrentItem(nsISupports **aItem);
|
1999-02-10 21:55:25 +03:00
|
|
|
|
1999-02-20 02:47:36 +03:00
|
|
|
NS_IMETHOD IsDone();//what does this mean??off edge? yes
|
1999-02-10 21:55:25 +03:00
|
|
|
|
|
|
|
nsFrameIterator();
|
1999-10-09 00:41:19 +04:00
|
|
|
|
1999-02-10 21:55:25 +03:00
|
|
|
protected:
|
|
|
|
void setCurrent(nsIFrame *aFrame){mCurrent = aFrame;}
|
|
|
|
nsIFrame *getCurrent(){return mCurrent;}
|
|
|
|
void setStart(nsIFrame *aFrame){mStart = aFrame;}
|
|
|
|
nsIFrame *getStart(){return mStart;}
|
|
|
|
nsIFrame *getLast(){return mLast;}
|
|
|
|
void setLast(nsIFrame *aFrame){mLast = aFrame;}
|
|
|
|
PRInt8 getOffEdge(){return mOffEdge;}
|
|
|
|
void setOffEdge(PRInt8 aOffEdge){mOffEdge = aOffEdge;}
|
|
|
|
private:
|
|
|
|
nsIFrame *mStart;
|
|
|
|
nsIFrame *mCurrent;
|
|
|
|
nsIFrame *mLast; //the last one that was in current;
|
|
|
|
PRInt8 mOffEdge; //0= no -1 to far prev, 1 to far next;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
class nsFastFrameIterator: public nsFrameIterator
|
|
|
|
{
|
|
|
|
nsFastFrameIterator(nsIFrame *start);
|
|
|
|
private :
|
|
|
|
|
|
|
|
virtual nsresult Next();
|
|
|
|
|
|
|
|
virtual nsresult Prev();
|
|
|
|
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
class nsLeafIterator: public nsFrameIterator
|
|
|
|
{
|
|
|
|
public:
|
2000-01-22 04:16:50 +03:00
|
|
|
nsLeafIterator(nsIPresContext* aPresContext, nsIFrame *start);
|
1999-02-10 21:55:25 +03:00
|
|
|
private :
|
|
|
|
|
1999-02-20 02:47:36 +03:00
|
|
|
NS_IMETHOD Next();
|
1999-02-10 21:55:25 +03:00
|
|
|
|
1999-02-20 02:47:36 +03:00
|
|
|
NS_IMETHOD Prev();
|
1999-02-10 21:55:25 +03:00
|
|
|
|
2000-01-22 04:16:50 +03:00
|
|
|
nsIPresContext* mPresContext;
|
1999-02-10 21:55:25 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/************IMPLEMENTATIONS**************/
|
|
|
|
|
|
|
|
nsresult
|
2000-01-22 04:16:50 +03:00
|
|
|
NS_NewFrameTraversal(nsIBidirectionalEnumerator **aEnumerator,
|
|
|
|
nsTraversalType aType,
|
|
|
|
nsIPresContext* aPresContext,
|
|
|
|
nsIFrame *aStart)
|
1999-02-10 21:55:25 +03:00
|
|
|
{
|
|
|
|
if (!aEnumerator || !aStart)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
switch(aType)
|
|
|
|
{
|
|
|
|
case LEAF: {
|
2000-01-22 04:16:50 +03:00
|
|
|
nsLeafIterator *trav = new nsLeafIterator(aPresContext, aStart);
|
1999-02-10 21:55:25 +03:00
|
|
|
if (!trav)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
1999-02-23 11:10:24 +03:00
|
|
|
*aEnumerator = NS_STATIC_CAST(nsIBidirectionalEnumerator*, trav);
|
1999-02-10 21:55:25 +03:00
|
|
|
NS_ADDREF(trav);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
#if 0
|
|
|
|
case EXTENSIVE:{
|
|
|
|
nsExtensiveTraversal *trav = new nsExtensiveTraversal(aStart);
|
|
|
|
if (!trav)
|
|
|
|
return NS_ERROR_NOMEMORY;
|
1999-02-23 11:10:24 +03:00
|
|
|
*aEnumerator = NS_STATIC_CAST(nsIBidirectionalEnumerator*, trav);
|
1999-02-10 21:55:25 +03:00
|
|
|
NS_ADDREF(trav);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case FASTEST:{
|
|
|
|
nsFastestTraversal *trav = new nsFastestTraversal(aStart);
|
|
|
|
if (!trav)
|
|
|
|
return NS_ERROR_NOMEMORY;
|
1999-02-23 11:10:24 +03:00
|
|
|
*aEnumerator = NS_STATIC_CAST(nsIBidirectionalEnumerator*, trav);
|
1999-02-10 21:55:25 +03:00
|
|
|
NS_ADDREF(trav);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*********nsFrameIterator************/
|
2000-01-29 22:59:53 +03:00
|
|
|
NS_IMPL_ISUPPORTS2(nsFrameIterator, nsIEnumerator, nsIBidirectionalEnumerator)
|
1999-02-10 21:55:25 +03:00
|
|
|
|
|
|
|
nsFrameIterator::nsFrameIterator()
|
|
|
|
{
|
|
|
|
mOffEdge = 0;
|
|
|
|
mLast = nsnull;
|
|
|
|
mCurrent = nsnull;
|
|
|
|
mStart = nsnull;
|
|
|
|
NS_INIT_REFCNT();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
1999-02-20 02:47:36 +03:00
|
|
|
NS_IMETHODIMP
|
1999-02-10 21:55:25 +03:00
|
|
|
nsFrameIterator::CurrentItem(nsISupports **aItem)
|
|
|
|
{
|
|
|
|
if (!aItem)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
*aItem = mCurrent;
|
1999-03-03 04:51:21 +03:00
|
|
|
if (mOffEdge)
|
1999-10-28 07:16:48 +04:00
|
|
|
return NS_ENUMERATOR_FALSE;
|
1999-02-10 21:55:25 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
1999-02-20 02:47:36 +03:00
|
|
|
NS_IMETHODIMP
|
1999-02-10 21:55:25 +03:00
|
|
|
nsFrameIterator::IsDone()//what does this mean??off edge? yes
|
|
|
|
{
|
|
|
|
if (mOffEdge != 0)
|
|
|
|
return NS_OK;
|
1999-10-28 07:16:48 +04:00
|
|
|
return NS_ENUMERATOR_FALSE;
|
1999-02-10 21:55:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
1999-02-20 02:47:36 +03:00
|
|
|
NS_IMETHODIMP
|
1999-02-10 21:55:25 +03:00
|
|
|
nsFrameIterator::First()
|
|
|
|
{
|
|
|
|
mCurrent = mStart;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
1999-02-20 02:47:36 +03:00
|
|
|
NS_IMETHODIMP
|
1999-02-10 21:55:25 +03:00
|
|
|
nsFrameIterator::Last()
|
|
|
|
{
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*********LEAFITERATOR**********/
|
|
|
|
|
|
|
|
|
2000-01-22 04:16:50 +03:00
|
|
|
nsLeafIterator::nsLeafIterator(nsIPresContext* aPresContext, nsIFrame *aStart)
|
|
|
|
: mPresContext(aPresContext)
|
1999-02-10 21:55:25 +03:00
|
|
|
{
|
|
|
|
setStart(aStart);
|
|
|
|
setCurrent(aStart);
|
|
|
|
setLast(aStart);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
1999-02-20 02:47:36 +03:00
|
|
|
NS_IMETHODIMP
|
1999-02-10 21:55:25 +03:00
|
|
|
nsLeafIterator::Next()
|
|
|
|
{
|
|
|
|
//recursive-oid method to get next frame
|
|
|
|
nsIFrame *result;
|
|
|
|
nsIFrame *parent = getCurrent();
|
|
|
|
if (!parent)
|
|
|
|
parent = getLast();
|
2000-01-22 04:16:50 +03:00
|
|
|
while(NS_SUCCEEDED(parent->FirstChild(mPresContext, nsnull,&result)) && result)
|
1999-02-10 21:55:25 +03:00
|
|
|
{
|
|
|
|
parent = result;
|
|
|
|
}
|
|
|
|
if (parent != getCurrent())
|
|
|
|
{
|
|
|
|
result = parent;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
while(parent){
|
|
|
|
if (NS_SUCCEEDED(parent->GetNextSibling(&result)) && result){
|
|
|
|
parent = result;
|
2000-01-22 04:16:50 +03:00
|
|
|
while(NS_SUCCEEDED(parent->FirstChild(mPresContext, nsnull,&result)) && result)
|
1999-02-10 21:55:25 +03:00
|
|
|
{
|
|
|
|
parent = result;
|
|
|
|
}
|
|
|
|
result = parent;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if (NS_FAILED(parent->GetParent(&result)) || !result){
|
|
|
|
result = nsnull;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
parent = result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
setCurrent(result);
|
|
|
|
if (!result)
|
|
|
|
setOffEdge(1);
|
1999-03-03 04:51:21 +03:00
|
|
|
return NS_OK;
|
1999-02-10 21:55:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1999-02-20 02:47:36 +03:00
|
|
|
NS_IMETHODIMP
|
1999-02-10 21:55:25 +03:00
|
|
|
nsLeafIterator::Prev()
|
|
|
|
{
|
|
|
|
//recursive-oid method to get prev frame
|
|
|
|
nsIFrame *result;
|
|
|
|
nsIFrame *parent = getCurrent();
|
|
|
|
if (!parent)
|
1999-03-03 04:51:21 +03:00
|
|
|
parent = getLast();
|
1999-02-10 21:55:25 +03:00
|
|
|
while(parent){
|
1999-03-03 04:51:21 +03:00
|
|
|
nsIFrame *grandParent;
|
|
|
|
if (NS_SUCCEEDED(parent->GetParent(&grandParent)) && grandParent &&
|
2000-01-22 04:16:50 +03:00
|
|
|
NS_SUCCEEDED(grandParent->FirstChild(mPresContext, nsnull,&result))){
|
1999-03-03 04:51:21 +03:00
|
|
|
nsFrameList list(result);
|
1999-07-15 22:19:03 +04:00
|
|
|
result = list.GetPrevSiblingFor(parent);
|
|
|
|
if (result){
|
1999-03-03 04:51:21 +03:00
|
|
|
parent = result;
|
2000-01-22 04:16:50 +03:00
|
|
|
while(NS_SUCCEEDED(parent->FirstChild(mPresContext, nsnull,&result)) && result){
|
1999-03-03 04:51:21 +03:00
|
|
|
parent = result;
|
|
|
|
while(NS_SUCCEEDED(parent->GetNextSibling(&result)) && result){
|
|
|
|
parent = result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
result = parent;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if (NS_FAILED(parent->GetParent(&result)) || !result){
|
|
|
|
result = nsnull;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
parent = result;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
setLast(parent);
|
|
|
|
result = nsnull;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* while(parent){
|
1999-02-10 21:55:25 +03:00
|
|
|
nsIFrame *grandParent;
|
|
|
|
if (NS_SUCCEEDED(parent->GetParent(&grandParent)) && grandParent){
|
|
|
|
nsIFrame * grandFchild;
|
|
|
|
if (NS_SUCCEEDED(grandParent->FirstChild(nsnull,&grandFchild)) && grandFchild){
|
|
|
|
nsFrameList list(grandFchild);
|
1999-03-03 18:35:49 +03:00
|
|
|
if (nsnull != (result = list.GetPrevSiblingFor(parent)) ){
|
1999-02-10 21:55:25 +03:00
|
|
|
parent = result;
|
|
|
|
while(NS_SUCCEEDED(parent->FirstChild(nsnull,&result)) && result){
|
|
|
|
parent = result;
|
|
|
|
while(NS_SUCCEEDED(parent->GetNextSibling(&result)) && result){
|
|
|
|
parent = result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
result = parent;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if (NS_FAILED(parent->GetParent(&result)) || !result){
|
|
|
|
result = nsnull;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
parent = result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-03-03 04:51:21 +03:00
|
|
|
*/
|
1999-02-10 21:55:25 +03:00
|
|
|
setCurrent(result);
|
|
|
|
if (!result)
|
|
|
|
setOffEdge(-1);
|
1999-03-03 04:51:21 +03:00
|
|
|
return NS_OK;
|
1999-02-10 21:55:25 +03:00
|
|
|
}
|