1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* ***** BEGIN LICENSE BLOCK *****
3 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 : *
5 : * The contents of this file are subject to the Mozilla Public License Version
6 : * 1.1 (the "License"); you may not use this file except in compliance with
7 : * the License. You may obtain a copy of the License at
8 : * http://www.mozilla.org/MPL/
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) 1998
20 : * the Initial Developer. All Rights Reserved.
21 : *
22 : * Contributor(s):
23 : *
24 : * Alternatively, the contents of this file may be used under the terms of
25 : * either of the GNU General Public License Version 2 or later (the "GPL"),
26 : * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 : * in which case the provisions of the GPL or the LGPL are applicable instead
28 : * of those above. If you wish to allow use of your version of this file only
29 : * under the terms of either the GPL or the LGPL, and not to allow others to
30 : * use your version of this file under the terms of the MPL, indicate your
31 : * decision by deleting the provisions above and replace them with the notice
32 : * and other provisions required by the GPL or the LGPL. If you do not delete
33 : * the provisions above, a recipient may use your version of this file under
34 : * the terms of any one of the MPL, the GPL or the LGPL.
35 : *
36 : * ***** END LICENSE BLOCK ***** */
37 :
38 : /*
39 : * code for managing absolutely positioned children of a rendering
40 : * object that is a containing block for them
41 : */
42 :
43 : #ifndef nsAbsoluteContainingBlock_h___
44 : #define nsAbsoluteContainingBlock_h___
45 :
46 : #include "nsFrameList.h"
47 : #include "nsHTMLReflowState.h"
48 : #include "nsGkAtoms.h"
49 : #include "nsContainerFrame.h"
50 :
51 : class nsIAtom;
52 : class nsIFrame;
53 : class nsPresContext;
54 :
55 : /**
56 : * This class contains the logic for being an absolute containing block. This
57 : * class is used within viewport frames (for frames representing content with
58 : * fixed position) and blocks (for frames representing absolutely positioned
59 : * content), since each set of frames is absolutely positioned with respect to
60 : * its parent.
61 : *
62 : * There is no principal child list, just a named child list which contains
63 : * the absolutely positioned frames (kAbsoluteList or kFixedList).
64 : *
65 : * All functions include as the first argument the frame that is delegating
66 : * the request.
67 : *
68 : */
69 : class nsAbsoluteContainingBlock
70 0 : {
71 : public:
72 : typedef nsIFrame::ChildListID ChildListID;
73 :
74 0 : nsAbsoluteContainingBlock(ChildListID aChildListID)
75 : #ifdef DEBUG
76 0 : : mChildListID(aChildListID)
77 : #endif
78 : {
79 0 : NS_ASSERTION(mChildListID == nsIFrame::kAbsoluteList ||
80 : mChildListID == nsIFrame::kFixedList,
81 : "should either represent position:fixed or absolute content");
82 0 : }
83 :
84 : #ifdef DEBUG
85 0 : ChildListID GetChildListID() const { return mChildListID; }
86 : #endif
87 :
88 0 : const nsFrameList& GetChildList() const { return mAbsoluteFrames; }
89 : void AppendChildList(nsTArray<nsIFrame::ChildList>* aLists,
90 : ChildListID aListID) const
91 : {
92 : NS_ASSERTION(aListID == GetChildListID(), "wrong list ID");
93 : GetChildList().AppendIfNonempty(aLists, aListID);
94 : }
95 :
96 : nsresult SetInitialChildList(nsIFrame* aDelegatingFrame,
97 : ChildListID aListID,
98 : nsFrameList& aChildList);
99 : nsresult AppendFrames(nsIFrame* aDelegatingFrame,
100 : ChildListID aListID,
101 : nsFrameList& aFrameList);
102 : nsresult InsertFrames(nsIFrame* aDelegatingFrame,
103 : ChildListID aListID,
104 : nsIFrame* aPrevFrame,
105 : nsFrameList& aFrameList);
106 : void RemoveFrame(nsIFrame* aDelegatingFrame,
107 : ChildListID aListID,
108 : nsIFrame* aOldFrame);
109 :
110 : // Called by the delegating frame after it has done its reflow first. This
111 : // function will reflow any absolutely positioned child frames that need to
112 : // be reflowed, e.g., because the absolutely positioned child frame has
113 : // 'auto' for an offset, or a percentage based width or height.
114 : // aOverflowAreas, if non-null, is unioned with (in the local
115 : // coordinate space) the overflow areas of the absolutely positioned
116 : // children.
117 : // @param aForceReflow if this is false, reflow for some absolutely
118 : // positioned frames may be skipped based on whether they use
119 : // placeholders for positioning and on whether the containing block
120 : // width or height changed.
121 : nsresult Reflow(nsContainerFrame* aDelegatingFrame,
122 : nsPresContext* aPresContext,
123 : const nsHTMLReflowState& aReflowState,
124 : nsReflowStatus& aReflowStatus,
125 : nscoord aContainingBlockWidth,
126 : nscoord aContainingBlockHeight,
127 : bool aConstrainHeight,
128 : bool aCBWidthChanged,
129 : bool aCBHeightChanged,
130 : nsOverflowAreas* aOverflowAreas);
131 :
132 :
133 : void DestroyFrames(nsIFrame* aDelegatingFrame,
134 : nsIFrame* aDestructRoot);
135 :
136 0 : bool HasAbsoluteFrames() {return mAbsoluteFrames.NotEmpty();}
137 :
138 : // Mark our size-dependent absolute frames with NS_FRAME_HAS_DIRTY_CHILDREN
139 : // so that we'll make sure to reflow them.
140 : void MarkSizeDependentFramesDirty();
141 :
142 : // Mark all our absolute frames with NS_FRAME_IS_DIRTY
143 : void MarkAllFramesDirty();
144 :
145 : protected:
146 : // Returns true if the position of f depends on the position of
147 : // its placeholder or if the position or size of f depends on a
148 : // containing block dimension that changed.
149 : bool FrameDependsOnContainer(nsIFrame* f, bool aCBWidthChanged,
150 : bool aCBHeightChanged);
151 :
152 : nsresult ReflowAbsoluteFrame(nsIFrame* aDelegatingFrame,
153 : nsPresContext* aPresContext,
154 : const nsHTMLReflowState& aReflowState,
155 : nscoord aContainingBlockWidth,
156 : nscoord aContainingBlockHeight,
157 : bool aConstrainHeight,
158 : nsIFrame* aKidFrame,
159 : nsReflowStatus& aStatus,
160 : nsOverflowAreas* aOverflowAreas);
161 :
162 : // Mark our absolute frames dirty. If aMarkAllDirty is true, all will be
163 : // marked with NS_FRAME_IS_DIRTY. Otherwise, the size-dependant ones will be
164 : // marked with NS_FRAME_HAS_DIRTY_CHILDREN.
165 : void DoMarkFramesDirty(bool aMarkAllDirty);
166 :
167 : protected:
168 : nsFrameList mAbsoluteFrames; // additional named child list
169 :
170 : #ifdef DEBUG
171 : ChildListID const mChildListID; // kFixedList or kAbsoluteList
172 :
173 : // helper routine for debug printout
174 : void PrettyUC(nscoord aSize,
175 : char* aBuf);
176 : #endif
177 : };
178 :
179 : #endif /* nsnsAbsoluteContainingBlock_h___ */
180 :
|