1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
// vim:cindent:ts=2:et:sw=2:
3
/* ***** BEGIN LICENSE BLOCK *****
4
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
6
* The contents of this file are subject to the Netscape Public License
7
* Version 1.1 (the "License"); you may not use this file except in
8
* compliance with the License. You may obtain a copy of the License at
9
* http://www.mozilla.org/NPL/
11
* Software distributed under the License is distributed on an "AS IS" basis,
12
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13
* for the specific language governing rights and limitations under the
16
* The Original Code is mozilla.org code.
18
* The Initial Developer of the Original Code is
19
* Netscape Communications Corporation.
20
* Portions created by the Initial Developer are Copyright (C) 1998
21
* the Initial Developer. All Rights Reserved.
25
* Alternatively, the contents of this file may be used under the terms of
26
* either the GNU General Public License Version 2 or later (the "GPL"), or
27
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28
* in which case the provisions of the GPL or the LGPL are applicable instead
29
* of those above. If you wish to allow use of your version of this file only
30
* under the terms of either the GPL or the LGPL, and not to allow others to
31
* use your version of this file under the terms of the NPL, indicate your
32
* decision by deleting the provisions above and replace them with the notice
33
* and other provisions required by the GPL or the LGPL. If you do not delete
34
* the provisions above, a recipient may use your version of this file under
35
* the terms of any one of the NPL, the GPL or the LGPL.
37
* ***** END LICENSE BLOCK ***** */
40
#include "nsIContent.h"
41
#include "nsIDOMNodeList.h"
42
#include "nsIDOMNode.h"
45
* Helper class for iterating children during frame construction.
46
* This class should always be used in lieu of the straight content
47
* node APIs, since it handles XBL-generated anonymous content as
53
nsCOMPtr<nsIContent> mContent;
55
nsCOMPtr<nsIDOMNodeList> mNodes;
61
ChildIterator(const ChildIterator& aOther)
62
: mContent(aOther.mContent),
63
mIndex(aOther.mIndex),
64
mNodes(aOther.mNodes) {}
66
ChildIterator& operator=(const ChildIterator& aOther) {
67
mContent = aOther.mContent;
68
mIndex = aOther.mIndex;
69
mNodes = aOther.mNodes;
73
ChildIterator& operator++() {
78
ChildIterator operator++(int) {
79
ChildIterator result(*this);
84
ChildIterator& operator--() {
89
ChildIterator operator--(int) {
90
ChildIterator result(*this);
95
already_AddRefed<nsIContent> get() const {
96
nsIContent* result = nsnull;
98
nsCOMPtr<nsIDOMNode> node;
99
mNodes->Item(mIndex, getter_AddRefs(node));
100
CallQueryInterface(node, &result);
102
result = mContent->GetChildAt(PRInt32(mIndex));
103
NS_IF_ADDREF(result);
109
already_AddRefed<nsIContent> operator*() const { return get(); }
111
PRBool operator==(const ChildIterator& aOther) const {
112
return mContent == aOther.mContent && mIndex == aOther.mIndex;
115
PRBool operator!=(const ChildIterator& aOther) const {
116
return !aOther.operator==(*this);
123
void seek(PRUint32 aIndex) {
124
// Make sure that aIndex is reasonable. This should be |#ifdef
125
// DEBUG|, but we need these numbers for the temporary workaround
129
mNodes->GetLength(&length);
131
length = mContent->GetChildCount();
133
NS_ASSERTION(PRInt32(aIndex) >= 0 && aIndex <= length, "out of bounds");
135
// Temporary workaround for bug 133219.
143
* Create a pair of ChildIterators for a content node. aFirst will
144
* point to the first child of aContent; aLast will point one past
145
* the last child of aContent.
147
static nsresult Init(nsIContent* aContent,
148
ChildIterator* aFirst,
149
ChildIterator* aLast);