2001-09-25 01:32:19 +00: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
|
1998-07-22 23:32:19 +00:00
|
|
|
*
|
2001-09-25 01:32:19 +00: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-07-22 23:32:19 +00:00
|
|
|
*
|
2001-09-25 01:32:19 +00: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-07-22 23:32:19 +00:00
|
|
|
*
|
1999-11-06 03:40:37 +00:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2001-09-25 01:32:19 +00: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 03:40:37 +00:00
|
|
|
*
|
2001-09-25 01:32:19 +00:00
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* 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-07-22 23:32:19 +00:00
|
|
|
#ifndef nsContentList_h___
|
|
|
|
#define nsContentList_h___
|
|
|
|
|
|
|
|
#include "nsISupports.h"
|
|
|
|
#include "nsVoidArray.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsIDOMHTMLCollection.h"
|
|
|
|
#include "nsIDOMNodeList.h"
|
|
|
|
#include "nsIDocumentObserver.h"
|
2001-05-30 11:26:21 +00:00
|
|
|
#include "nsIContentList.h"
|
1998-07-22 23:32:19 +00:00
|
|
|
|
2001-03-22 08:51:52 +00:00
|
|
|
typedef PRBool (*nsContentListMatchFunc)(nsIContent* aContent,
|
|
|
|
nsString* aData);
|
1998-07-22 23:32:19 +00:00
|
|
|
|
|
|
|
class nsIDocument;
|
2001-03-22 08:51:52 +00:00
|
|
|
class nsIDOMHTMLFormElement;
|
1998-07-22 23:32:19 +00:00
|
|
|
|
2001-03-22 08:51:52 +00:00
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
class nsBaseContentList : public nsIDOMNodeList
|
2001-03-22 08:51:52 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsBaseContentList();
|
|
|
|
virtual ~nsBaseContentList();
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
// nsIDOMNodeList
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
NS_DECL_NSIDOMNODELIST
|
2001-03-22 08:51:52 +00:00
|
|
|
|
|
|
|
NS_IMETHOD AppendElement(nsIContent *aContent);
|
|
|
|
NS_IMETHOD RemoveElement(nsIContent *aContent);
|
|
|
|
NS_IMETHOD IndexOf(nsIContent *aContent, PRInt32& aIndex);
|
|
|
|
NS_IMETHOD Reset();
|
|
|
|
|
|
|
|
protected:
|
2001-09-06 19:16:03 +00:00
|
|
|
nsAutoVoidArray mElements;
|
2001-03-22 08:51:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// This class is used only by form element code and this is a static
|
|
|
|
// list of elements. NOTE! This list holds strong references to
|
|
|
|
// the elements in the list.
|
|
|
|
class nsFormContentList : public nsBaseContentList
|
|
|
|
{
|
1998-07-22 23:32:19 +00:00
|
|
|
public:
|
2001-03-22 08:51:52 +00:00
|
|
|
nsFormContentList(nsIDOMHTMLFormElement *aForm,
|
|
|
|
nsBaseContentList& aContentList);
|
|
|
|
virtual ~nsFormContentList();
|
|
|
|
|
|
|
|
NS_IMETHOD AppendElement(nsIContent *aContent);
|
|
|
|
NS_IMETHOD RemoveElement(nsIContent *aContent);
|
|
|
|
|
|
|
|
NS_IMETHOD Reset();
|
|
|
|
};
|
|
|
|
|
2002-05-08 20:48:19 +00:00
|
|
|
class nsContentListKey
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsContentListKey(nsIDocument *aDocument,
|
|
|
|
nsIAtom* aMatchAtom,
|
|
|
|
PRInt32 aMatchNameSpaceId,
|
|
|
|
nsIContent* aRootContent)
|
|
|
|
: mMatchAtom(aMatchAtom),
|
|
|
|
mMatchNameSpaceId(aMatchNameSpaceId),
|
|
|
|
mDocument(aDocument),
|
|
|
|
mRootContent(aRootContent)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsContentListKey(const nsContentListKey& aContentListKey)
|
|
|
|
: mMatchAtom(aContentListKey.mMatchAtom),
|
|
|
|
mMatchNameSpaceId(aContentListKey.mMatchNameSpaceId),
|
|
|
|
mDocument(aContentListKey.mDocument),
|
|
|
|
mRootContent(aContentListKey.mRootContent)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool Equals(const nsContentListKey& aContentListKey) const
|
|
|
|
{
|
|
|
|
return
|
|
|
|
mMatchAtom == aContentListKey.mMatchAtom &&
|
|
|
|
mMatchNameSpaceId == aContentListKey.mMatchNameSpaceId &&
|
|
|
|
mDocument == aContentListKey.mDocument &&
|
|
|
|
mRootContent == aContentListKey.mRootContent;
|
|
|
|
}
|
|
|
|
inline PRUint32 GetHash(void) const
|
|
|
|
{
|
|
|
|
return
|
|
|
|
NS_PTR_TO_INT32(mMatchAtom.get()) ^
|
|
|
|
(NS_PTR_TO_INT32(mRootContent) << 8) ^
|
|
|
|
(NS_PTR_TO_INT32(mDocument) << 16) ^
|
|
|
|
(mMatchNameSpaceId << 24);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
nsCOMPtr<nsIAtom> mMatchAtom;
|
|
|
|
PRInt32 mMatchNameSpaceId;
|
|
|
|
nsIDocument* mDocument; // Weak ref
|
|
|
|
nsIContent* mRootContent; // Weak ref
|
|
|
|
};
|
|
|
|
|
2001-03-22 08:51:52 +00:00
|
|
|
class nsContentList : public nsBaseContentList,
|
2002-05-08 20:48:19 +00:00
|
|
|
protected nsContentListKey,
|
2001-03-22 08:51:52 +00:00
|
|
|
public nsIDOMHTMLCollection,
|
2001-05-30 11:26:21 +00:00
|
|
|
public nsIDocumentObserver,
|
|
|
|
public nsIContentList
|
2001-03-22 08:51:52 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
|
|
|
|
nsContentList(const nsContentList& aContentList);
|
2000-06-01 22:55:19 +00:00
|
|
|
nsContentList(nsIDocument *aDocument);
|
1999-01-15 19:18:30 +00:00
|
|
|
nsContentList(nsIDocument *aDocument,
|
|
|
|
nsIAtom* aMatchAtom,
|
|
|
|
PRInt32 aMatchNameSpaceId,
|
|
|
|
nsIContent* aRootContent=nsnull);
|
|
|
|
nsContentList(nsIDocument *aDocument,
|
|
|
|
nsContentListMatchFunc aFunc,
|
2002-03-23 23:54:46 +00:00
|
|
|
const nsAString& aData,
|
1999-01-15 19:18:30 +00:00
|
|
|
nsIContent* aRootContent=nsnull);
|
1998-07-22 23:32:19 +00:00
|
|
|
virtual ~nsContentList();
|
|
|
|
|
1999-01-18 03:43:43 +00:00
|
|
|
// nsIDOMHTMLCollection
|
1998-07-22 23:32:19 +00:00
|
|
|
NS_IMETHOD GetLength(PRUint32* aLength);
|
|
|
|
NS_IMETHOD Item(PRUint32 aIndex, nsIDOMNode** aReturn);
|
2002-03-23 23:54:46 +00:00
|
|
|
NS_IMETHOD NamedItem(const nsAString& aName, nsIDOMNode** aReturn);
|
1998-07-22 23:32:19 +00:00
|
|
|
|
2001-05-30 11:26:21 +00:00
|
|
|
/// nsIContentList
|
|
|
|
NS_IMETHOD GetLength(PRUint32* aLength, PRBool aDoFlush);
|
|
|
|
NS_IMETHOD Item(PRUint32 aIndex, nsIDOMNode** aReturn,
|
|
|
|
PRBool aDoFlush);
|
2002-03-23 23:54:46 +00:00
|
|
|
NS_IMETHOD NamedItem(const nsAString& aName, nsIDOMNode** aReturn,
|
2001-05-30 11:26:21 +00:00
|
|
|
PRBool aDoFlush);
|
|
|
|
NS_IMETHOD IndexOf(nsIContent *aContent, PRInt32& aIndex,
|
|
|
|
PRBool aDoFlush);
|
|
|
|
|
1999-01-18 03:43:43 +00:00
|
|
|
// nsIDocumentObserver
|
1998-07-22 23:32:19 +00:00
|
|
|
NS_IMETHOD BeginUpdate(nsIDocument *aDocument) { return NS_OK; }
|
|
|
|
NS_IMETHOD EndUpdate(nsIDocument *aDocument) { return NS_OK; }
|
|
|
|
NS_IMETHOD BeginLoad(nsIDocument *aDocument) { return NS_OK; }
|
|
|
|
NS_IMETHOD EndLoad(nsIDocument *aDocument) { return NS_OK; }
|
|
|
|
NS_IMETHOD BeginReflow(nsIDocument *aDocument,
|
1998-09-18 19:53:27 +00:00
|
|
|
nsIPresShell* aShell) { return NS_OK; }
|
1998-07-22 23:32:19 +00:00
|
|
|
NS_IMETHOD EndReflow(nsIDocument *aDocument,
|
1998-09-18 19:53:27 +00:00
|
|
|
nsIPresShell* aShell) { return NS_OK; }
|
1998-07-22 23:32:19 +00:00
|
|
|
NS_IMETHOD ContentChanged(nsIDocument *aDocument,
|
1998-09-18 19:53:27 +00:00
|
|
|
nsIContent* aContent,
|
1998-07-22 23:32:19 +00:00
|
|
|
nsISupports* aSubContent) { return NS_OK; }
|
1999-04-20 00:02:22 +00:00
|
|
|
NS_IMETHOD ContentStatesChanged(nsIDocument* aDocument,
|
|
|
|
nsIContent* aContent1,
|
2002-03-07 03:34:29 +00:00
|
|
|
nsIContent* aContent2,
|
2002-04-11 03:49:30 +00:00
|
|
|
PRInt32 aStateMask) { return NS_OK; }
|
1998-09-18 19:53:27 +00:00
|
|
|
NS_IMETHOD AttributeChanged(nsIDocument *aDocument,
|
|
|
|
nsIContent* aContent,
|
1999-10-15 23:16:45 +00:00
|
|
|
PRInt32 aNameSpaceID,
|
1998-09-29 23:43:39 +00:00
|
|
|
nsIAtom* aAttribute,
|
2001-08-25 02:01:08 +00:00
|
|
|
PRInt32 aModType,
|
1998-09-29 23:43:39 +00:00
|
|
|
PRInt32 aHint) { return NS_OK; }
|
1998-07-22 23:32:19 +00:00
|
|
|
NS_IMETHOD ContentAppended(nsIDocument *aDocument,
|
1998-09-18 19:53:27 +00:00
|
|
|
nsIContent* aContainer,
|
|
|
|
PRInt32 aNewIndexInContainer);
|
1998-07-22 23:32:19 +00:00
|
|
|
NS_IMETHOD ContentInserted(nsIDocument *aDocument,
|
1998-09-18 19:53:27 +00:00
|
|
|
nsIContent* aContainer,
|
1998-07-22 23:32:19 +00:00
|
|
|
nsIContent* aChild,
|
|
|
|
PRInt32 aIndexInContainer);
|
|
|
|
NS_IMETHOD ContentReplaced(nsIDocument *aDocument,
|
1998-09-18 19:53:27 +00:00
|
|
|
nsIContent* aContainer,
|
1998-07-22 23:32:19 +00:00
|
|
|
nsIContent* aOldChild,
|
|
|
|
nsIContent* aNewChild,
|
|
|
|
PRInt32 aIndexInContainer);
|
1998-09-24 21:39:47 +00:00
|
|
|
NS_IMETHOD ContentRemoved(nsIDocument *aDocument,
|
|
|
|
nsIContent* aContainer,
|
|
|
|
nsIContent* aChild,
|
|
|
|
PRInt32 aIndexInContainer);
|
1998-07-22 23:32:19 +00:00
|
|
|
NS_IMETHOD StyleSheetAdded(nsIDocument *aDocument,
|
1998-11-17 02:14:38 +00:00
|
|
|
nsIStyleSheet* aStyleSheet) { return NS_OK; }
|
1999-02-03 19:38:16 +00:00
|
|
|
NS_IMETHOD StyleSheetRemoved(nsIDocument *aDocument,
|
|
|
|
nsIStyleSheet* aStyleSheet) { return NS_OK; }
|
1998-11-17 02:14:38 +00:00
|
|
|
NS_IMETHOD StyleSheetDisabledStateChanged(nsIDocument *aDocument,
|
|
|
|
nsIStyleSheet* aStyleSheet,
|
|
|
|
PRBool aDisabled) { return NS_OK; }
|
1998-11-26 01:34:53 +00:00
|
|
|
NS_IMETHOD StyleRuleChanged(nsIDocument *aDocument,
|
|
|
|
nsIStyleSheet* aStyleSheet,
|
|
|
|
nsIStyleRule* aStyleRule,
|
|
|
|
PRInt32 aHint) { return NS_OK; }
|
|
|
|
NS_IMETHOD StyleRuleAdded(nsIDocument *aDocument,
|
|
|
|
nsIStyleSheet* aStyleSheet,
|
|
|
|
nsIStyleRule* aStyleRule) { return NS_OK; }
|
|
|
|
NS_IMETHOD StyleRuleRemoved(nsIDocument *aDocument,
|
|
|
|
nsIStyleSheet* aStyleSheet,
|
|
|
|
nsIStyleRule* aStyleRule) { return NS_OK; }
|
1998-07-22 23:32:19 +00:00
|
|
|
NS_IMETHOD DocumentWillBeDestroyed(nsIDocument *aDocument);
|
|
|
|
|
2002-05-08 20:48:19 +00:00
|
|
|
// Other public methods
|
|
|
|
nsContentListKey* GetKey() {
|
|
|
|
return NS_STATIC_CAST(nsContentListKey*, this);
|
|
|
|
}
|
|
|
|
|
2000-06-01 22:55:19 +00:00
|
|
|
protected:
|
|
|
|
nsresult Match(nsIContent *aContent, PRBool *aMatch);
|
1998-07-22 23:32:19 +00:00
|
|
|
void Init(nsIDocument *aDocument);
|
1999-01-18 03:43:43 +00:00
|
|
|
void PopulateWith(nsIContent *aContent, PRBool aIncludeRoot);
|
1998-07-22 23:32:19 +00:00
|
|
|
PRBool MatchSelf(nsIContent *aContent);
|
1999-01-18 03:43:43 +00:00
|
|
|
void PopulateSelf();
|
|
|
|
void DisconnectFromDocument();
|
|
|
|
PRBool IsDescendantOfRoot(nsIContent* aContainer);
|
|
|
|
PRBool ContainsRoot(nsIContent* aContent);
|
|
|
|
nsresult CheckDocumentExistence();
|
2002-05-08 20:48:19 +00:00
|
|
|
void RemoveFromHashtable();
|
1998-07-22 23:32:19 +00:00
|
|
|
|
|
|
|
nsContentListMatchFunc mFunc;
|
1999-05-04 20:53:44 +00:00
|
|
|
nsString* mData;
|
1999-01-15 19:18:30 +00:00
|
|
|
PRBool mMatchAll;
|
1998-07-22 23:32:19 +00:00
|
|
|
};
|
|
|
|
|
2002-05-08 20:48:19 +00:00
|
|
|
extern nsresult
|
|
|
|
NS_GetContentList(nsIDocument* aDocument, nsIAtom* aMatchAtom,
|
|
|
|
PRInt32 aMatchNameSpaceId, nsIContent* aRootContent,
|
|
|
|
nsIContentList** aInstancePtrResult);
|
|
|
|
|
1998-07-22 23:32:19 +00:00
|
|
|
#endif // nsContentList_h___
|