nsTableColGroupFrame.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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. #include "mozilla/Attributes.h"
  8. #include "nscore.h"
  9. #include "nsContainerFrame.h"
  10. #include "nsTableFrame.h"
  11. #include "mozilla/WritingModes.h"
  12. class nsTableColFrame;
  13. /**
  14. * nsTableColGroupFrame
  15. * data structure to maintain information about a single table cell's frame
  16. *
  17. * @author sclark
  18. */
  19. class nsTableColGroupFrame final : public nsContainerFrame
  20. {
  21. public:
  22. NS_DECL_FRAMEARENA_HELPERS
  23. // default constructor supplied by the compiler
  24. /** instantiate a new instance of nsTableRowFrame.
  25. * @param aPresShell the pres shell for this frame
  26. *
  27. * @return the frame that was created
  28. */
  29. friend nsTableColGroupFrame* NS_NewTableColGroupFrame(nsIPresShell* aPresShell,
  30. nsStyleContext* aContext);
  31. nsTableFrame* GetTableFrame() const
  32. {
  33. nsIFrame* parent = GetParent();
  34. MOZ_ASSERT(parent && parent->GetType() == nsGkAtoms::tableFrame);
  35. MOZ_ASSERT(!parent->GetPrevInFlow(),
  36. "Col group should always be in a first-in-flow table frame");
  37. return static_cast<nsTableFrame*>(parent);
  38. }
  39. virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder,
  40. const nsDisplayListSet& aLists) override;
  41. /** A colgroup can be caused by three things:
  42. * 1) An element with table-column-group display
  43. * 2) An element with a table-column display without a
  44. * table-column-group parent
  45. * 3) Cells that are not in a column (and hence get an anonymous
  46. * column and colgroup).
  47. * @return colgroup type
  48. */
  49. nsTableColGroupType GetColType() const;
  50. /** Set the colgroup type based on the creation cause
  51. * @param aType - the reason why this colgroup is needed
  52. */
  53. void SetColType(nsTableColGroupType aType);
  54. /** Real in this context are colgroups that come from an element
  55. * with table-column-group display or wrap around columns that
  56. * come from an element with table-column display. Colgroups
  57. * that are the result of wrapping cells in an anonymous
  58. * column and colgroup are not considered real here.
  59. * @param aTableFrame - the table parent of the colgroups
  60. * @return the last real colgroup
  61. */
  62. static nsTableColGroupFrame* GetLastRealColGroup(nsTableFrame* aTableFrame);
  63. /** @see nsIFrame::DidSetStyleContext */
  64. virtual void DidSetStyleContext(nsStyleContext* aOldStyleContext) override;
  65. virtual void SetInitialChildList(ChildListID aListID,
  66. nsFrameList& aChildList) override;
  67. virtual void AppendFrames(ChildListID aListID,
  68. nsFrameList& aFrameList) override;
  69. virtual void InsertFrames(ChildListID aListID,
  70. nsIFrame* aPrevFrame,
  71. nsFrameList& aFrameList) override;
  72. virtual void RemoveFrame(ChildListID aListID,
  73. nsIFrame* aOldFrame) override;
  74. /** remove the column aChild from the column group, if requested renumber
  75. * the subsequent columns in this column group and all following column
  76. * groups. see also ResetColIndices for this
  77. * @param aChild - the column frame that needs to be removed
  78. * @param aResetSubsequentColIndices - if true the columns that follow
  79. * after aChild will be reenumerated
  80. */
  81. void RemoveChild(nsTableColFrame& aChild,
  82. bool aResetSubsequentColIndices);
  83. /** reflow of a column group is a trivial matter of reflowing
  84. * the col group's children (columns), and setting this frame
  85. * to 0-size. Since tables are row-centric, column group frames
  86. * don't play directly in the rendering game. They do however
  87. * maintain important state that effects table and cell layout.
  88. */
  89. virtual void Reflow(nsPresContext* aPresContext,
  90. ReflowOutput& aDesiredSize,
  91. const ReflowInput& aReflowInput,
  92. nsReflowStatus& aStatus) override;
  93. /**
  94. * Get the "type" of the frame
  95. *
  96. * @see nsGkAtoms::tableColGroupFrame
  97. */
  98. virtual nsIAtom* GetType() const override;
  99. virtual mozilla::WritingMode GetWritingMode() const override
  100. { return GetTableFrame()->GetWritingMode(); }
  101. /** Add column frames to the table storages: colframe cache and cellmap
  102. * this doesn't change the mFrames of the colgroup frame.
  103. * @param aFirstColIndex - the index at which aFirstFrame should be inserted
  104. * into the colframe cache.
  105. * @param aResetSubsequentColIndices - the indices of the col frames
  106. * after the insertion might need
  107. * an update
  108. * @param aCols - an iterator that can be used to iterate over the col
  109. * frames to be added. Once this is done, the frames on the
  110. * sbling chain of its .get() at that point will still need
  111. * their col indices updated.
  112. * @result - if there is no table frame or the table frame is not
  113. * the first in flow it will return an error
  114. */
  115. nsresult AddColsToTable(int32_t aFirstColIndex,
  116. bool aResetSubsequentColIndices,
  117. const nsFrameList::Slice& aCols);
  118. #ifdef DEBUG_FRAME_DUMP
  119. virtual nsresult GetFrameName(nsAString& aResult) const override;
  120. void Dump(int32_t aIndent);
  121. #endif
  122. /** returns the number of columns represented by this group.
  123. * if there are col children, count them (taking into account the span of each)
  124. * else, check my own span attribute.
  125. */
  126. virtual int32_t GetColCount() const;
  127. /** first column on the child list */
  128. nsTableColFrame * GetFirstColumn();
  129. /** next sibling to aChildFrame that is a column frame, first column frame
  130. * in the column group if aChildFrame is null
  131. */
  132. nsTableColFrame * GetNextColumn(nsIFrame *aChildFrame);
  133. /** @return - the position of the first column in this colgroup in the table
  134. * colframe cache.
  135. */
  136. int32_t GetStartColumnIndex();
  137. /** set the position of the first column in this colgroup in the table
  138. * colframe cache.
  139. */
  140. void SetStartColumnIndex(int32_t aIndex);
  141. /** helper method to get the span attribute for this colgroup */
  142. int32_t GetSpan();
  143. /** provide access to the mFrames list
  144. */
  145. nsFrameList& GetWritableChildList();
  146. /** set the column index for all frames starting at aStartColFrame, it
  147. * will also reset the column indices in all subsequent colgroups
  148. * @param aFirstColGroup - start the reset operation inside this colgroup
  149. * @param aFirstColIndex - first column that is reset should get this index
  150. * @param aStartColFrame - if specified the reset starts with this column
  151. * inside the colgroup; if not specified, the reset
  152. * starts with the first column
  153. */
  154. static void ResetColIndices(nsIFrame* aFirstColGroup,
  155. int32_t aFirstColIndex,
  156. nsIFrame* aStartColFrame = nullptr);
  157. /**
  158. * Gets inner border widths before collapsing with cell borders
  159. * Caller must get istart border from previous column
  160. * GetContinuousBCBorderWidth will not overwrite aBorder.IStart
  161. * see nsTablePainter about continuous borders
  162. */
  163. void GetContinuousBCBorderWidth(mozilla::WritingMode aWM,
  164. mozilla::LogicalMargin& aBorder);
  165. /**
  166. * Set full border widths before collapsing with cell borders
  167. * @param aForSide - side to set; only accepts bstart and bend
  168. */
  169. void SetContinuousBCBorderWidth(mozilla::LogicalSide aForSide,
  170. BCPixelSize aPixelValue);
  171. virtual bool IsFrameOfType(uint32_t aFlags) const override
  172. {
  173. return nsContainerFrame::IsFrameOfType(aFlags & ~(nsIFrame::eTablePart));
  174. }
  175. virtual void InvalidateFrame(uint32_t aDisplayItemKey = 0) override;
  176. virtual void InvalidateFrameWithRect(const nsRect& aRect, uint32_t aDisplayItemKey = 0) override;
  177. virtual void InvalidateFrameForRemoval() override { InvalidateFrameSubtree(); }
  178. protected:
  179. explicit nsTableColGroupFrame(nsStyleContext* aContext);
  180. void InsertColsReflow(int32_t aColIndex,
  181. const nsFrameList::Slice& aCols);
  182. virtual LogicalSides GetLogicalSkipSides(const ReflowInput* aReflowInput = nullptr) const override;
  183. // data members
  184. int32_t mColCount;
  185. // the starting column index this col group represents. Must be >= 0.
  186. int32_t mStartColIndex;
  187. // border width in pixels
  188. BCPixelSize mBStartContBorderWidth;
  189. BCPixelSize mBEndContBorderWidth;
  190. };
  191. inline nsTableColGroupFrame::nsTableColGroupFrame(nsStyleContext *aContext)
  192. : nsContainerFrame(aContext), mColCount(0), mStartColIndex(0)
  193. {
  194. SetColType(eColGroupContent);
  195. }
  196. inline int32_t nsTableColGroupFrame::GetStartColumnIndex()
  197. {
  198. return mStartColIndex;
  199. }
  200. inline void nsTableColGroupFrame::SetStartColumnIndex (int32_t aIndex)
  201. {
  202. mStartColIndex = aIndex;
  203. }
  204. inline int32_t nsTableColGroupFrame::GetColCount() const
  205. {
  206. return mColCount;
  207. }
  208. inline nsFrameList& nsTableColGroupFrame::GetWritableChildList()
  209. {
  210. return mFrames;
  211. }
  212. #endif