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
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/
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
15 * The Original Code is mozilla.org code.
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.
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.
36 * ***** END LICENSE BLOCK ***** */
37 #ifndef nsTableColGroupFrame_h__
38 #define nsTableColGroupFrame_h__
41 #include "nsHTMLContainerFrame.h"
42 #include "nsTableColFrame.h"
43 #include "nsTablePainter.h"
45 class nsTableColFrame
;
47 enum nsTableColGroupType
{
48 eColGroupContent
= 0, // there is real col group content associated
49 eColGroupAnonymousCol
= 1, // the result of a col
50 eColGroupAnonymousCell
= 2 // the result of a cell alone
54 * nsTableColGroupFrame
55 * data structure to maintain information about a single table cell's frame
59 class nsTableColGroupFrame
: public nsHTMLContainerFrame
62 NS_DECL_FRAMEARENA_HELPERS
64 // default constructor supplied by the compiler
66 /** instantiate a new instance of nsTableRowFrame.
67 * @param aPresShell the pres shell for this frame
69 * @return the frame that was created
71 friend nsIFrame
* NS_NewTableColGroupFrame(nsIPresShell
* aPresShell
, nsStyleContext
* aContext
);
73 /** Initialize the colgroup frame with a set of children.
74 * @see nsIFrame::SetInitialChildList
76 NS_IMETHOD
SetInitialChildList(nsIAtom
* aListName
,
77 nsFrameList
& aChildList
);
80 * ColGroups never paint anything, nor receive events.
82 NS_IMETHOD
BuildDisplayList(nsDisplayListBuilder
* aBuilder
,
83 const nsRect
& aDirtyRect
,
84 const nsDisplayListSet
& aLists
) { return NS_OK
; }
86 /** A colgroup can be caused by three things:
87 * 1) An element with table-column-group display
88 * 2) An element with a table-column display without a
89 * table-column-group parent
90 * 3) Cells that are not in a column (and hence get an anonymous
91 * column and colgroup).
92 * @return colgroup type
94 nsTableColGroupType
GetColType() const;
96 /** Set the colgroup type based on the creation cause
97 * @param aType - the reason why this colgroup is needed
99 void SetColType(nsTableColGroupType aType
);
101 /** Real in this context are colgroups that come from an element
102 * with table-column-group display or wrap around columns that
103 * come from an element with table-column display. Colgroups
104 * that are the result of wrapping cells in an anonymous
105 * column and colgroup are not considered real here.
106 * @param aTableFrame - the table parent of the colgroups
107 * @return the last real colgroup
109 static nsTableColGroupFrame
* GetLastRealColGroup(nsTableFrame
* aTableFrame
);
111 /** @see nsIFrame::DidSetStyleContext */
112 virtual void DidSetStyleContext(nsStyleContext
* aOldStyleContext
);
114 /** @see nsIFrame::AppendFrames, InsertFrames, RemoveFrame
116 NS_IMETHOD
AppendFrames(nsIAtom
* aListName
,
117 nsFrameList
& aFrameList
);
118 NS_IMETHOD
InsertFrames(nsIAtom
* aListName
,
119 nsIFrame
* aPrevFrame
,
120 nsFrameList
& aFrameList
);
121 NS_IMETHOD
RemoveFrame(nsIAtom
* aListName
,
122 nsIFrame
* aOldFrame
);
124 /** remove the column aChild from the column group, if requested renumber
125 * the subsequent columns in this column group and all following column
126 * groups. see also ResetColIndices for this
127 * @param aChild - the column frame that needs to be removed
128 * @param aResetSubsequentColIndices - if true the columns that follow
129 * after aChild will be reenumerated
131 void RemoveChild(nsTableColFrame
& aChild
,
132 PRBool aResetSubsequentColIndices
);
134 /** reflow of a column group is a trivial matter of reflowing
135 * the col group's children (columns), and setting this frame
136 * to 0-size. Since tables are row-centric, column group frames
137 * don't play directly in the rendering game. They do however
138 * maintain important state that effects table and cell layout.
140 NS_IMETHOD
Reflow(nsPresContext
* aPresContext
,
141 nsHTMLReflowMetrics
& aDesiredSize
,
142 const nsHTMLReflowState
& aReflowState
,
143 nsReflowStatus
& aStatus
);
145 /* needed only because we use Reflow in a hacky way, see
146 nsTableFrame::ReflowColGroups */
147 virtual PRBool
IsContainingBlock() const;
150 * Get the "type" of the frame
152 * @see nsGkAtoms::tableColGroupFrame
154 virtual nsIAtom
* GetType() const;
156 /** Add column frames to the table storages: colframe cache and cellmap
157 * this doesn't change the mFrames of the colgroup frame.
158 * @param aFirstColIndex - the index at which aFirstFrame should be inserted
159 * into the colframe cache.
160 * @param aResetSubsequentColIndices - the indices of the col frames
161 * after the insertion might need
163 * @param aCols - an iterator that can be used to iterate over the col
164 * frames to be added. Once this is done, the frames on the
165 * sbling chain of its .get() at that point will still need
166 * their col indices updated.
167 * @result - if there is no table frame or the table frame is not
168 * the first in flow it will return an error
170 nsresult
AddColsToTable(PRInt32 aFirstColIndex
,
171 PRBool aResetSubsequentColIndices
,
172 const nsFrameList::Slice
& aCols
);
175 NS_IMETHOD
GetFrameName(nsAString
& aResult
) const;
176 void Dump(PRInt32 aIndent
);
179 /** returns the number of columns represented by this group.
180 * if there are col children, count them (taking into account the span of each)
181 * else, check my own span attribute.
183 virtual PRInt32
GetColCount() const;
185 /** first column on the child list */
186 nsTableColFrame
* GetFirstColumn();
187 /** next sibling to aChildFrame that is a column frame, first column frame
188 * in the column group if aChildFrame is null
190 nsTableColFrame
* GetNextColumn(nsIFrame
*aChildFrame
);
192 /** @return - the position of the first column in this colgroup in the table
195 PRInt32
GetStartColumnIndex();
197 /** set the position of the first column in this colgroup in the table
200 void SetStartColumnIndex(PRInt32 aIndex
);
202 /** helper method to get the span attribute for this colgroup */
205 /** provide access to the mFrames list
207 nsFrameList
& GetWritableChildList();
209 /** set the column index for all frames starting at aStartColFrame, it
210 * will also reset the column indices in all subsequent colgroups
211 * @param aFirstColGroup - start the reset operation inside this colgroup
212 * @param aFirstColIndex - first column that is reset should get this index
213 * @param aStartColFrame - if specified the reset starts with this column
214 * inside the colgroup; if not specified, the reset
215 * starts with the first column
217 static void ResetColIndices(nsIFrame
* aFirstColGroup
,
218 PRInt32 aFirstColIndex
,
219 nsIFrame
* aStartColFrame
= nsnull
);
222 * Gets inner border widths before collapsing with cell borders
223 * Caller must get left border from previous column
224 * GetContinuousBCBorderWidth will not overwrite aBorder.left
225 * see nsTablePainter about continuous borders
227 void GetContinuousBCBorderWidth(nsMargin
& aBorder
);
229 * Set full border widths before collapsing with cell borders
230 * @param aForSide - side to set; only accepts top and bottom
232 void SetContinuousBCBorderWidth(PRUint8 aForSide
,
233 BCPixelSize aPixelValue
);
235 nsTableColGroupFrame(nsStyleContext
* aContext
);
237 void InsertColsReflow(PRInt32 aColIndex
,
238 const nsFrameList::Slice
& aCols
);
240 /** implement abstract method on nsHTMLContainerFrame */
241 virtual PRIntn
GetSkipSides() const;
245 // the starting column index this col group represents. Must be >= 0.
246 PRInt32 mStartColIndex
;
248 // border width in pixels
249 BCPixelSize mTopContBorderWidth
;
250 BCPixelSize mBottomContBorderWidth
;
253 inline nsTableColGroupFrame::nsTableColGroupFrame(nsStyleContext
*aContext
)
254 : nsHTMLContainerFrame(aContext
), mColCount(0), mStartColIndex(0)
256 SetColType(eColGroupContent
);
259 inline PRInt32
nsTableColGroupFrame::GetStartColumnIndex()
261 return mStartColIndex
;
264 inline void nsTableColGroupFrame::SetStartColumnIndex (PRInt32 aIndex
)
266 mStartColIndex
= aIndex
;
269 inline PRInt32
nsTableColGroupFrame::GetColCount() const
274 inline nsFrameList
& nsTableColGroupFrame::GetWritableChildList()