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
63 // default constructor supplied by the compiler
65 /** instantiate a new instance of nsTableRowFrame.
66 * @param aPresShell the pres shell for this frame
68 * @return the frame that was created
70 friend nsIFrame
* NS_NewTableColGroupFrame(nsIPresShell
* aPresShell
, nsStyleContext
* aContext
);
72 /** Initialize the colgroup frame with a set of children.
73 * @see nsIFrame::SetInitialChildList
75 NS_IMETHOD
SetInitialChildList(nsIAtom
* aListName
,
76 nsIFrame
* aChildList
);
79 * ColGroups never paint anything, nor receive events.
81 NS_IMETHOD
BuildDisplayList(nsDisplayListBuilder
* aBuilder
,
82 const nsRect
& aDirtyRect
,
83 const nsDisplayListSet
& aLists
) { return NS_OK
; }
85 /** A colgroup can be caused by three things:
86 * 1) An element with table-column-group display
87 * 2) An element with a table-column display without a
88 * table-column-group parent
89 * 3) Cells that are not in a column (and hence get an anonymous
90 * column and colgroup).
91 * @return colgroup type
93 nsTableColGroupType
GetColType() const;
95 /** Set the colgroup type based on the creation cause
96 * @param aType - the reason why this colgroup is needed
98 void SetColType(nsTableColGroupType aType
);
100 /** Real in this context are colgroups that come from an element
101 * with table-column-group display or wrap around columns that
102 * come from an element with table-column display. Colgroups
103 * that are the result of wrapping cells in an anonymous
104 * column and colgroup are not considered real here.
105 * @param aTableFrame - the table parent of the colgroups
106 * @param aLastColgroup - the last real colgroup
107 * @return is false if there is a non real colgroup at the end
109 static PRBool
GetLastRealColGroup(nsTableFrame
* aTableFrame
,
110 nsIFrame
** aLastColGroup
);
112 /** @see nsIFrame::DidSetStyleContext */
113 virtual void DidSetStyleContext(nsStyleContext
* aOldStyleContext
);
115 /** @see nsIFrame::AppendFrames, InsertFrames, RemoveFrame
117 NS_IMETHOD
AppendFrames(nsIAtom
* aListName
,
118 nsIFrame
* aFrameList
);
119 NS_IMETHOD
InsertFrames(nsIAtom
* aListName
,
120 nsIFrame
* aPrevFrame
,
121 nsIFrame
* aFrameList
);
122 NS_IMETHOD
RemoveFrame(nsIAtom
* aListName
,
123 nsIFrame
* aOldFrame
);
125 /** remove the column aChild from the column group, if requested renumber
126 * the subsequent columns in this column group and all following column
127 * groups. see also ResetColIndices for this
128 * @param aChild - the column frame that needs to be removed
129 * @param aResetSubsequentColIndices - if true the columns that follow
130 * after aChild will be reenumerated
132 void RemoveChild(nsTableColFrame
& aChild
,
133 PRBool aResetSubsequentColIndices
);
135 /** reflow of a column group is a trivial matter of reflowing
136 * the col group's children (columns), and setting this frame
137 * to 0-size. Since tables are row-centric, column group frames
138 * don't play directly in the rendering game. They do however
139 * maintain important state that effects table and cell layout.
141 NS_IMETHOD
Reflow(nsPresContext
* aPresContext
,
142 nsHTMLReflowMetrics
& aDesiredSize
,
143 const nsHTMLReflowState
& aReflowState
,
144 nsReflowStatus
& aStatus
);
146 /* needed only because we use Reflow in a hacky way, see
147 nsTableFrame::ReflowColGroups */
148 virtual PRBool
IsContainingBlock() const;
150 virtual PRBool
IsFrameOfType(PRUint32 aFlags
) const
152 return nsHTMLContainerFrame::IsFrameOfType(aFlags
&
153 ~nsIFrame::eExcludesIgnorableWhitespace
);
157 * Get the "type" of the frame
159 * @see nsGkAtoms::tableColGroupFrame
161 virtual nsIAtom
* GetType() const;
163 /** Add column frames to the table storages: colframe cache and cellmap
164 * this doesn't change the mFrames of the colgroup frame.
165 * @param aFirstColIndex - the index at which aFirstFrame should be inserted
166 * into the colframe cache.
167 * @param aResetSubsequentColIndices - the indices of the col frames
168 * after the insertion might need
170 * @param aFirstFrame - first frame that needs to be added to the table,
171 * the frame should have a correctly set sibling
172 * @param aLastFrame - last frame that needs to be added. It can be either
173 * null or should be in the sibling chain of
175 * @result - if there is no table frame or the table frame is not
176 * the first in flow it will return an error
178 nsresult
AddColsToTable(PRInt32 aFirstColIndex
,
179 PRBool aResetSubsequentColIndices
,
180 nsIFrame
* aFirstFrame
,
181 nsIFrame
* aLastFrame
= nsnull
);
184 NS_IMETHOD
GetFrameName(nsAString
& aResult
) const;
185 void Dump(PRInt32 aIndent
);
188 /** returns the number of columns represented by this group.
189 * if there are col children, count them (taking into account the span of each)
190 * else, check my own span attribute.
192 virtual PRInt32
GetColCount() const;
194 /** first column on the child list */
195 nsTableColFrame
* GetFirstColumn();
196 /** next sibling to aChildFrame that is a column frame, first column frame
197 * in the column group if aChildFrame is null
199 nsTableColFrame
* GetNextColumn(nsIFrame
*aChildFrame
);
201 /** @return - the position of the first column in this colgroup in the table
204 PRInt32
GetStartColumnIndex();
206 /** set the position of the first column in this colgroup in the table
209 void SetStartColumnIndex(PRInt32 aIndex
);
211 /** helper method to get the span attribute for this colgroup */
214 /** provide access to the mFrames list
216 nsFrameList
& GetChildList();
218 /** set the column index for all frames starting at aStartColFrame, it
219 * will also reset the column indices in all subsequent colgroups
220 * @param aFirstColGroup - start the reset operation inside this colgroup
221 * @param aFirstColIndex - first column that is reset should get this index
222 * @param aStartColFrame - if specified the reset starts with this column
223 * inside the colgroup; if not specified, the reset
224 * starts with the first column
226 static void ResetColIndices(nsIFrame
* aFirstColGroup
,
227 PRInt32 aFirstColIndex
,
228 nsIFrame
* aStartColFrame
= nsnull
);
231 * Gets inner border widths before collapsing with cell borders
232 * Caller must get left border from previous column
233 * GetContinuousBCBorderWidth will not overwrite aBorder.left
234 * see nsTablePainter about continuous borders
236 void GetContinuousBCBorderWidth(nsMargin
& aBorder
);
238 * Set full border widths before collapsing with cell borders
239 * @param aForSide - side to set; only accepts top and bottom
241 void SetContinuousBCBorderWidth(PRUint8 aForSide
,
242 BCPixelSize aPixelValue
);
244 nsTableColGroupFrame(nsStyleContext
* aContext
);
246 void InsertColsReflow(PRInt32 aColIndex
,
247 nsIFrame
* aFirstFrame
,
248 nsIFrame
* aLastFrame
= nsnull
);
250 /** implement abstract method on nsHTMLContainerFrame */
251 virtual PRIntn
GetSkipSides() const;
255 // the starting column index this col group represents. Must be >= 0.
256 PRInt32 mStartColIndex
;
258 // border width in pixels
259 BCPixelSize mTopContBorderWidth
;
260 BCPixelSize mBottomContBorderWidth
;
263 inline nsTableColGroupFrame::nsTableColGroupFrame(nsStyleContext
*aContext
)
264 : nsHTMLContainerFrame(aContext
), mColCount(0), mStartColIndex(0)
266 SetColType(eColGroupContent
);
269 inline PRInt32
nsTableColGroupFrame::GetStartColumnIndex()
271 return mStartColIndex
;
274 inline void nsTableColGroupFrame::SetStartColumnIndex (PRInt32 aIndex
)
276 mStartColIndex
= aIndex
;
279 inline PRInt32
nsTableColGroupFrame::GetColCount() const
284 inline nsFrameList
& nsTableColGroupFrame::GetChildList()