~ubuntu-branches/ubuntu/precise/kompozer/precise

« back to all changes in this revision

Viewing changes to mozilla/layout/html/base/src/nsReflowPath.h

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Yarusso
  • Date: 2007-08-27 01:11:03 UTC
  • Revision ID: james.westby@ubuntu.com-20070827011103-2jgf4s6532gqu2ka
Tags: upstream-0.7.10
ImportĀ upstreamĀ versionĀ 0.7.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 
2
/* ***** BEGIN LICENSE BLOCK *****
 
3
 * Version: NPL 1.1/GPL 2.0/LGPL 2.1
 
4
 *
 
5
 * The contents of this file are subject to the Netscape Public License
 
6
 * Version 1.1 (the "License"); you may not use this file except in
 
7
 * compliance with the License. You may obtain a copy of the License at
 
8
 * http://www.mozilla.org/NPL/
 
9
 *
 
10
 * Software distributed under the License is distributed on an "AS IS" basis,
 
11
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 
12
 * for the specific language governing rights and limitations under the
 
13
 * License.
 
14
 *
 
15
 * The Original Code is mozilla.org code.
 
16
 *
 
17
 * The Initial Developer of the Original Code is
 
18
 * Netscape Communications Corporation.
 
19
 * Portions created by the Initial Developer are Copyright (C) 2002
 
20
 * the Initial Developer. All Rights Reserved.
 
21
 *
 
22
 * Contributor(s):
 
23
 *    Mike Shaver <shaver@mozilla.org>
 
24
 *    Randell Jesup <rjesup@wgate.com>
 
25
 *    Chris Waterson <waterson@netscape.com>
 
26
 *
 
27
 * Alternatively, the contents of this file may be used under the terms of
 
28
 * either the GNU General Public License Version 2 or later (the "GPL"), or
 
29
 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 
30
 * in which case the provisions of the GPL or the LGPL are applicable instead
 
31
 * of those above. If you wish to allow use of your version of this file only
 
32
 * under the terms of either the GPL or the LGPL, and not to allow others to
 
33
 * use your version of this file under the terms of the NPL, indicate your
 
34
 * decision by deleting the provisions above and replace them with the notice
 
35
 * and other provisions required by the GPL or the LGPL. If you do not delete
 
36
 * the provisions above, a recipient may use your version of this file under
 
37
 * the terms of any one of the NPL, the GPL or the LGPL.
 
38
 *
 
39
 * ***** END LICENSE BLOCK ***** */
 
40
 
 
41
#ifndef nsReflowPath_h__
 
42
#define nsReflowPath_h__
 
43
 
 
44
#include "nscore.h"
 
45
#include "pldhash.h"
 
46
#include "nsReflowType.h"
 
47
#include "nsVoidArray.h"
 
48
 
 
49
#ifdef DEBUG
 
50
#include <stdio.h>
 
51
#endif
 
52
 
 
53
class nsIFrame;
 
54
class nsHTMLReflowCommand;
 
55
class nsIPresContext;
 
56
 
 
57
/**
 
58
 * A reflow `path' that is a sparse tree the parallels the frame
 
59
 * hierarchy. This is used during an incremental reflow to record the
 
60
 * path which the reflow must trace through the frame hierarchy.
 
61
 */
 
62
class nsReflowPath
 
63
{
 
64
public:
 
65
    /**
 
66
     * Construct a reflow path object that parallels the specified
 
67
     * frame.
 
68
     */
 
69
    nsReflowPath(nsIFrame *aFrame)
 
70
        : mFrame(aFrame),
 
71
          mReflowCommand(nsnull) {}
 
72
 
 
73
    ~nsReflowPath();
 
74
 
 
75
    /**
 
76
     * An iterator for enumerating the reflow path's immediate
 
77
     * children.
 
78
     */
 
79
    class iterator
 
80
    {
 
81
    protected:
 
82
        nsReflowPath *mNode;
 
83
        PRInt32 mIndex;
 
84
 
 
85
        friend class nsReflowPath;
 
86
 
 
87
        iterator(nsReflowPath *aNode, PRInt32 aIndex)
 
88
            : mNode(aNode), mIndex(aIndex) {}
 
89
 
 
90
        void
 
91
        Advance() { --mIndex; }
 
92
 
 
93
    public:
 
94
        iterator()
 
95
            : mNode(nsnull) {}
 
96
 
 
97
        iterator(const iterator &iter)
 
98
            : mNode(iter.mNode), mIndex(iter.mIndex) {}
 
99
 
 
100
        iterator &
 
101
        operator=(const iterator &iter) {
 
102
            mNode = iter.mNode;
 
103
            mIndex = iter.mIndex;
 
104
            return *this; }
 
105
 
 
106
        nsReflowPath *
 
107
        get() const {
 
108
            return NS_STATIC_CAST(nsReflowPath *, mNode->mChildren[mIndex]); }
 
109
 
 
110
        nsReflowPath *
 
111
        get() {
 
112
            return NS_STATIC_CAST(nsReflowPath *, mNode->mChildren[mIndex]); }
 
113
 
 
114
        nsIFrame *
 
115
        operator*() const {
 
116
            return get()->mFrame; }
 
117
 
 
118
        nsIFrame *&
 
119
        operator*() {
 
120
            return get()->mFrame; }
 
121
 
 
122
        iterator &
 
123
        operator++() { Advance(); return *this; }
 
124
 
 
125
        iterator
 
126
        operator++(int) {
 
127
            iterator temp(*this);
 
128
            Advance();
 
129
            return temp; }
 
130
 
 
131
        PRBool
 
132
        operator==(const iterator &iter) const {
 
133
            return (mNode == iter.mNode) && (mIndex == iter.mIndex); }
 
134
 
 
135
        PRBool
 
136
        operator!=(const iterator &iter) const {
 
137
            return !iter.operator==(*this); }
 
138
    };
 
139
 
 
140
    /**
 
141
     * Return an iterator that points to the first immediate child of
 
142
     * the reflow path.
 
143
     */
 
144
    iterator FirstChild() { return iterator(this, mChildren.Count() - 1); }
 
145
 
 
146
    /**
 
147
     * Return an iterator that points `one past the end' of the
 
148
     * immediate children of the reflow path.
 
149
     */
 
150
    iterator EndChildren() { return iterator(this, -1); }
 
151
 
 
152
    /**
 
153
     * Determine if the reflow path contains the specified frame as
 
154
     * one of its immediate children.
 
155
     */
 
156
    PRBool
 
157
    HasChild(nsIFrame *aFrame) const {
 
158
        return GetSubtreeFor(aFrame) != nsnull; }
 
159
 
 
160
    /**
 
161
     * Return an iterator over the current reflow path that
 
162
     * corresponds to the specified child frame. Returns EndChildren
 
163
     * if aFrame is not an immediate child of the reflow path.
 
164
     */
 
165
    iterator
 
166
    FindChild(nsIFrame *aFrame);
 
167
 
 
168
    /**
 
169
     * Remove the specified child frame from the reflow path, along
 
170
     * with any of its descendants. Does nothing if aFrame is not an
 
171
     * immediate child of the reflow path.
 
172
     */
 
173
    void
 
174
    RemoveChild(nsIFrame *aFrame) { 
 
175
        iterator iter = FindChild(aFrame);
 
176
        Remove(iter); }
 
177
 
 
178
    /**
 
179
     * Return the child reflow path that corresponds to the specified
 
180
     * frame, or null if the frame is not an immediate descendant.
 
181
     */
 
182
    nsReflowPath *
 
183
    GetSubtreeFor(nsIFrame *aFrame) const;
 
184
 
 
185
    /**
 
186
     * Return the child reflow path that corresponds to the specified
 
187
     * frame, constructing a new child reflow path if one doesn't
 
188
     * exist already.
 
189
     */
 
190
    nsReflowPath *
 
191
    EnsureSubtreeFor(nsIFrame *aFrame);
 
192
 
 
193
    /**
 
194
     * Remove the child reflow path that corresponds to the specified
 
195
     * iterator.
 
196
     */
 
197
    void
 
198
    Remove(iterator &aIterator);
 
199
 
 
200
#ifdef DEBUG
 
201
    /**
 
202
     * Recursively dump the reflow path object and its descendants.
 
203
     */
 
204
    void
 
205
    Dump(nsIPresContext *aPresContext, FILE *aFile, int aDepth);
 
206
#endif
 
207
 
 
208
    /**
 
209
     * The frame that this reflow path object is associated with.
 
210
     */
 
211
    nsIFrame            *mFrame;
 
212
 
 
213
    /**
 
214
     * If mFrame is the immediate target of an incremental reflow,
 
215
     * this contains the reflow command that targeted it. Otherwise,
 
216
     * this is null (and mFrame simply lies along the path to a target
 
217
     * frame). The reflow path object assumes ownership of the reflow
 
218
     * command.
 
219
     */
 
220
    nsHTMLReflowCommand *mReflowCommand;
 
221
 
 
222
protected:
 
223
    /**
 
224
     * The children of this reflow path; also contains pointers to
 
225
     * nsReflowPath objects.
 
226
     */
 
227
    nsSmallVoidArray     mChildren;
 
228
 
 
229
    friend class iterator;
 
230
};
 
231
 
 
232
#endif