nsTableColGroupFrame.h (8702B)
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* This Source Code Form is subject to the terms of the Mozilla Public 3 * License, v. 2.0. If a copy of the MPL was not distributed with this 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 5 #ifndef nsTableColGroupFrame_h__ 6 #define nsTableColGroupFrame_h__ 7 8 #include "mozilla/WritingModes.h" 9 #include "nsContainerFrame.h" 10 #include "nsTableFrame.h" 11 #include "nscore.h" 12 13 class nsTableColFrame; 14 15 namespace mozilla { 16 class PresShell; 17 } // namespace mozilla 18 19 /** 20 * nsTableColGroupFrame 21 * data structure to maintain information about a single table cell's frame 22 */ 23 class nsTableColGroupFrame final : public nsContainerFrame { 24 public: 25 NS_DECL_FRAMEARENA_HELPERS(nsTableColGroupFrame) 26 27 /** 28 * instantiate a new instance of nsTableRowFrame. 29 * 30 * @param aPresShell the pres shell for this frame 31 * 32 * @return the frame that was created 33 */ 34 friend nsTableColGroupFrame* NS_NewTableColGroupFrame( 35 mozilla::PresShell* aPresShell, ComputedStyle* aStyle); 36 37 // nsIFrame overrides 38 void Init(nsIContent* aContent, nsContainerFrame* aParent, 39 nsIFrame* aPrevInFlow) override { 40 nsContainerFrame::Init(aContent, aParent, aPrevInFlow); 41 if (!aPrevInFlow) { 42 mWritingMode = GetTableFrame()->GetWritingMode(); 43 } 44 } 45 46 nsTableFrame* GetTableFrame() const { 47 nsIFrame* parent = GetParent(); 48 MOZ_ASSERT(parent && parent->IsTableFrame()); 49 MOZ_ASSERT(!parent->GetPrevInFlow(), 50 "Col group should always be in a first-in-flow table frame"); 51 return static_cast<nsTableFrame*>(parent); 52 } 53 54 void BuildDisplayList(nsDisplayListBuilder* aBuilder, 55 const nsDisplayListSet& aLists) override; 56 57 /** A colgroup can be caused by three things: 58 * 1) An element with table-column-group display 59 * 2) An element with a table-column display without a 60 * table-column-group parent 61 * 3) Cells that are not in a column (and hence get an anonymous 62 * column and colgroup). 63 * 64 * In practice, we don't need to differentiate between cases (1) and (2), 65 * because they both correspond to table-column-group boxes in the spec and 66 * hence have observably identical behavior. Case three is flagged as a 67 * synthetic colgroup, because it may need to have different behavior in some 68 * cases. 69 */ 70 bool IsSynthetic() const; 71 void SetIsSynthetic(); 72 73 /** Real in this context are colgroups that come from an element 74 * with table-column-group display or wrap around columns that 75 * come from an element with table-column display. Colgroups 76 * that are the result of wrapping cells in an anonymous 77 * column and colgroup are not considered real here. 78 * @param aTableFrame - the table parent of the colgroups 79 * @return the last real colgroup 80 */ 81 static nsTableColGroupFrame* GetLastRealColGroup(nsTableFrame* aTableFrame); 82 83 /** @see nsIFrame::DidSetComputedStyle */ 84 void DidSetComputedStyle(ComputedStyle* aOldComputedStyle) override; 85 86 void SetInitialChildList(ChildListID aListID, 87 nsFrameList&& aChildList) override; 88 void AppendFrames(ChildListID aListID, nsFrameList&& aFrameList) override; 89 void InsertFrames(ChildListID aListID, nsIFrame* aPrevFrame, 90 const nsLineList::iterator* aPrevFrameLine, 91 nsFrameList&& aFrameList) override; 92 void RemoveFrame(DestroyContext&, ChildListID, nsIFrame*) override; 93 94 /** remove the column aChild from the column group, if requested renumber 95 * the subsequent columns in this column group and all following column 96 * groups. see also ResetColIndices for this 97 * @param aChild - the column frame that needs to be removed 98 * @param aResetSubsequentColIndices - if true the columns that follow 99 * after aChild will be reenumerated 100 */ 101 void RemoveChild(DestroyContext& aContext, nsTableColFrame& aChild, 102 bool aResetSubsequentColIndices); 103 104 /** reflow of a column group is a trivial matter of reflowing 105 * the col group's children (columns), and setting this frame 106 * to 0-size. Since tables are row-centric, column group frames 107 * don't play directly in the rendering game. They do however 108 * maintain important state that effects table and cell layout. 109 */ 110 void Reflow(nsPresContext* aPresContext, ReflowOutput& aDesiredSize, 111 const ReflowInput& aReflowInput, 112 nsReflowStatus& aStatus) override; 113 114 /** Add column frames to the table storages: colframe cache and cellmap 115 * this doesn't change the mFrames of the colgroup frame. 116 * @param aFirstColIndex - the index at which aFirstFrame should be inserted 117 * into the colframe cache. 118 * @param aResetSubsequentColIndices - the indices of the col frames 119 * after the insertion might need 120 * an update 121 * @param aCols - an iterator that can be used to iterate over the col 122 * frames to be added. Once this is done, the frames on the 123 * sbling chain of its .get() at that point will still need 124 * their col indices updated. 125 * @result - if there is no table frame or the table frame is not 126 * the first in flow it will return an error 127 */ 128 nsresult AddColsToTable(int32_t aFirstColIndex, 129 bool aResetSubsequentColIndices, 130 const nsFrameList::Slice& aCols); 131 132 #ifdef DEBUG_FRAME_DUMP 133 nsresult GetFrameName(nsAString& aResult) const override; 134 void Dump(int32_t aIndent); 135 #endif 136 137 /** returns the number of columns represented by this group. 138 * if there are col children, count them (taking into account the span of 139 * each) else, check my own span attribute. 140 */ 141 int32_t GetColCount() const; 142 143 /** first column on the child list */ 144 nsTableColFrame* GetFirstColumn(); 145 /** next sibling to aChildFrame that is a column frame, first column frame 146 * in the column group if aChildFrame is null 147 */ 148 nsTableColFrame* GetNextColumn(nsIFrame* aChildFrame); 149 150 /** @return - the position of the first column in this colgroup in the table 151 * colframe cache. 152 */ 153 int32_t GetStartColumnIndex(); 154 155 /** set the position of the first column in this colgroup in the table 156 * colframe cache. 157 */ 158 void SetStartColumnIndex(int32_t aIndex); 159 160 /** helper method to get the span attribute for this colgroup */ 161 int32_t GetSpan(); 162 163 /** provide access to the mFrames list 164 */ 165 nsFrameList& GetWritableChildList(); 166 167 /** set the column index for all frames starting at aStartColFrame, it 168 * will also reset the column indices in all subsequent colgroups 169 * @param aFirstColGroup - start the reset operation inside this colgroup 170 * @param aFirstColIndex - first column that is reset should get this index 171 * @param aStartColFrame - if specified the reset starts with this column 172 * inside the colgroup; if not specified, the reset 173 * starts with the first column 174 */ 175 static void ResetColIndices(nsIFrame* aFirstColGroup, int32_t aFirstColIndex, 176 nsIFrame* aStartColFrame = nullptr); 177 178 void InvalidateFrame(uint32_t aDisplayItemKey = 0, 179 bool aRebuildDisplayItems = true) override; 180 void InvalidateFrameWithRect(const nsRect& aRect, 181 uint32_t aDisplayItemKey = 0, 182 bool aRebuildDisplayItems = true) override; 183 void InvalidateFrameForRemoval() override { InvalidateFrameSubtree(); } 184 185 protected: 186 nsTableColGroupFrame(ComputedStyle* aStyle, nsPresContext* aPresContext); 187 188 void InsertColsReflow(int32_t aColIndex, const nsFrameList::Slice& aCols); 189 190 LogicalSides GetLogicalSkipSides() const override; 191 192 // data members 193 int32_t mColCount; 194 // the starting column index this col group represents. Must be >= 0. 195 int32_t mStartColIndex; 196 }; 197 198 inline nsTableColGroupFrame::nsTableColGroupFrame(ComputedStyle* aStyle, 199 nsPresContext* aPresContext) 200 : nsContainerFrame(aStyle, aPresContext, kClassID), 201 mColCount(0), 202 mStartColIndex(0) {} 203 204 inline int32_t nsTableColGroupFrame::GetStartColumnIndex() { 205 return mStartColIndex; 206 } 207 208 inline void nsTableColGroupFrame::SetStartColumnIndex(int32_t aIndex) { 209 mStartColIndex = aIndex; 210 } 211 212 inline int32_t nsTableColGroupFrame::GetColCount() const { return mColCount; } 213 214 inline nsFrameList& nsTableColGroupFrame::GetWritableChildList() { 215 return mFrames; 216 } 217 218 #endif