nsTableWrapperFrame.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  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 nsTableWrapperFrame_h__
  6. #define nsTableWrapperFrame_h__
  7. #include "mozilla/Attributes.h"
  8. #include "mozilla/Maybe.h"
  9. #include "nscore.h"
  10. #include "nsContainerFrame.h"
  11. #include "nsCellMap.h"
  12. #include "nsTableFrame.h"
  13. /**
  14. * Primary frame for a table element,
  15. * the nsTableWrapperFrame contains 0 or one caption frame, and a nsTableFrame
  16. * pseudo-frame (referred to as the "inner frame').
  17. */
  18. class nsTableWrapperFrame : public nsContainerFrame
  19. {
  20. public:
  21. NS_DECL_QUERYFRAME
  22. NS_DECL_FRAMEARENA_HELPERS
  23. NS_DECL_QUERYFRAME_TARGET(nsTableWrapperFrame)
  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 nsTableWrapperFrame* NS_NewTableWrapperFrame(nsIPresShell* aPresShell,
  30. nsStyleContext* aContext);
  31. // nsIFrame overrides - see there for a description
  32. virtual void DestroyFrom(nsIFrame* aDestructRoot) override;
  33. virtual const nsFrameList& GetChildList(ChildListID aListID) const override;
  34. virtual void GetChildLists(nsTArray<ChildList>* aLists) const override;
  35. virtual void SetInitialChildList(ChildListID aListID,
  36. nsFrameList& aChildList) override;
  37. virtual void AppendFrames(ChildListID aListID,
  38. nsFrameList& aFrameList) override;
  39. virtual void InsertFrames(ChildListID aListID,
  40. nsIFrame* aPrevFrame,
  41. nsFrameList& aFrameList) override;
  42. virtual void RemoveFrame(ChildListID aListID,
  43. nsIFrame* aOldFrame) override;
  44. virtual nsContainerFrame* GetContentInsertionFrame() override {
  45. return PrincipalChildList().FirstChild()->GetContentInsertionFrame();
  46. }
  47. #ifdef ACCESSIBILITY
  48. virtual mozilla::a11y::AccType AccessibleType() override;
  49. #endif
  50. virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder,
  51. const nsDisplayListSet& aLists) override;
  52. void BuildDisplayListForInnerTable(nsDisplayListBuilder* aBuilder,
  53. const nsDisplayListSet& aLists);
  54. virtual nscoord GetLogicalBaseline(mozilla::WritingMode aWritingMode) const override;
  55. bool GetNaturalBaselineBOffset(mozilla::WritingMode aWM,
  56. BaselineSharingGroup aBaselineGroup,
  57. nscoord* aBaseline) const override
  58. {
  59. auto innerTable = InnerTableFrame();
  60. nscoord offset;
  61. if (innerTable->GetNaturalBaselineBOffset(aWM, aBaselineGroup, &offset)) {
  62. auto bStart = innerTable->BStart(aWM, mRect.Size());
  63. if (aBaselineGroup == BaselineSharingGroup::eFirst) {
  64. *aBaseline = offset + bStart;
  65. } else {
  66. auto bEnd = bStart + innerTable->BSize(aWM);
  67. *aBaseline = BSize(aWM) - (bEnd - offset);
  68. }
  69. return true;
  70. }
  71. return false;
  72. }
  73. virtual nscoord GetMinISize(nsRenderingContext *aRenderingContext) override;
  74. virtual nscoord GetPrefISize(nsRenderingContext *aRenderingContext) override;
  75. virtual mozilla::LogicalSize
  76. ComputeAutoSize(nsRenderingContext* aRenderingContext,
  77. mozilla::WritingMode aWM,
  78. const mozilla::LogicalSize& aCBSize,
  79. nscoord aAvailableISize,
  80. const mozilla::LogicalSize& aMargin,
  81. const mozilla::LogicalSize& aBorder,
  82. const mozilla::LogicalSize& aPadding,
  83. ComputeSizeFlags aFlags) override;
  84. /** process a reflow command for the table.
  85. * This involves reflowing the caption and the inner table.
  86. * @see nsIFrame::Reflow */
  87. virtual void Reflow(nsPresContext* aPresContext,
  88. ReflowOutput& aDesiredSize,
  89. const ReflowInput& aReflowInput,
  90. nsReflowStatus& aStatus) override;
  91. /**
  92. * Get the "type" of the frame
  93. *
  94. * @see nsGkAtoms::tableWrapperFrame
  95. */
  96. virtual nsIAtom* GetType() const override;
  97. #ifdef DEBUG_FRAME_DUMP
  98. virtual nsresult GetFrameName(nsAString& aResult) const override;
  99. #endif
  100. virtual nsStyleContext* GetParentStyleContext(nsIFrame** aProviderFrame) const override;
  101. /**
  102. * Return the content for the cell at the given row and column.
  103. */
  104. nsIContent* GetCellAt(uint32_t aRowIdx, uint32_t aColIdx) const;
  105. /**
  106. * Return the number of rows in the table.
  107. */
  108. int32_t GetRowCount() const
  109. {
  110. return InnerTableFrame()->GetRowCount();
  111. }
  112. /**
  113. * Return the number of columns in the table.
  114. */
  115. int32_t GetColCount() const
  116. {
  117. return InnerTableFrame()->GetColCount();
  118. }
  119. /**
  120. * Return the index of the cell at the given row and column.
  121. */
  122. int32_t GetIndexByRowAndColumn(int32_t aRowIdx, int32_t aColIdx) const
  123. {
  124. nsTableCellMap* cellMap = InnerTableFrame()->GetCellMap();
  125. if (!cellMap)
  126. return -1;
  127. return cellMap->GetIndexByRowAndColumn(aRowIdx, aColIdx);
  128. }
  129. /**
  130. * Get the row and column indices for the cell at the given index.
  131. */
  132. void GetRowAndColumnByIndex(int32_t aCellIdx, int32_t* aRowIdx,
  133. int32_t* aColIdx) const
  134. {
  135. *aRowIdx = *aColIdx = 0;
  136. nsTableCellMap* cellMap = InnerTableFrame()->GetCellMap();
  137. if (cellMap) {
  138. cellMap->GetRowAndColumnByIndex(aCellIdx, aRowIdx, aColIdx);
  139. }
  140. }
  141. /**
  142. * return the frame for the cell at the given row and column.
  143. */
  144. nsTableCellFrame* GetCellFrameAt(uint32_t aRowIdx, uint32_t aColIdx) const
  145. {
  146. nsTableCellMap* map = InnerTableFrame()->GetCellMap();
  147. if (!map) {
  148. return nullptr;
  149. }
  150. return map->GetCellInfoAt(aRowIdx, aColIdx);
  151. }
  152. /**
  153. * Return the col span of the cell at the given row and column indices.
  154. */
  155. uint32_t GetEffectiveColSpanAt(uint32_t aRowIdx, uint32_t aColIdx) const
  156. {
  157. nsTableCellMap* map = InnerTableFrame()->GetCellMap();
  158. return map->GetEffectiveColSpan(aRowIdx, aColIdx);
  159. }
  160. /**
  161. * Return the effective row span of the cell at the given row and column.
  162. */
  163. uint32_t GetEffectiveRowSpanAt(uint32_t aRowIdx, uint32_t aColIdx) const
  164. {
  165. nsTableCellMap* map = InnerTableFrame()->GetCellMap();
  166. return map->GetEffectiveRowSpan(aRowIdx, aColIdx);
  167. }
  168. /**
  169. * The CB size to use for the inner table frame if we're a grid item.
  170. */
  171. NS_DECLARE_FRAME_PROPERTY_DELETABLE(GridItemCBSizeProperty, mozilla::LogicalSize);
  172. protected:
  173. explicit nsTableWrapperFrame(nsStyleContext* aContext);
  174. virtual ~nsTableWrapperFrame();
  175. void InitChildReflowInput(nsPresContext& aPresContext,
  176. ReflowInput& aReflowInput);
  177. // Get a NS_STYLE_CAPTION_SIDE_* value, or NO_SIDE if no caption is present.
  178. // (Remember that caption-side values are interpreted logically, despite
  179. // having "physical" names.)
  180. uint8_t GetCaptionSide();
  181. bool HasSideCaption() {
  182. uint8_t captionSide = GetCaptionSide();
  183. return captionSide == NS_STYLE_CAPTION_SIDE_LEFT ||
  184. captionSide == NS_STYLE_CAPTION_SIDE_RIGHT;
  185. }
  186. uint8_t GetCaptionVerticalAlign();
  187. void SetDesiredSize(uint8_t aCaptionSide,
  188. const mozilla::LogicalSize& aInnerSize,
  189. const mozilla::LogicalSize& aCaptionSize,
  190. const mozilla::LogicalMargin& aInnerMargin,
  191. const mozilla::LogicalMargin& aCaptionMargin,
  192. nscoord& aISize,
  193. nscoord& aBSize,
  194. mozilla::WritingMode aWM);
  195. nsresult GetCaptionOrigin(uint32_t aCaptionSide,
  196. const mozilla::LogicalSize& aContainBlockSize,
  197. const mozilla::LogicalSize& aInnerSize,
  198. const mozilla::LogicalMargin& aInnerMargin,
  199. const mozilla::LogicalSize& aCaptionSize,
  200. mozilla::LogicalMargin& aCaptionMargin,
  201. mozilla::LogicalPoint& aOrigin,
  202. mozilla::WritingMode aWM);
  203. nsresult GetInnerOrigin(uint32_t aCaptionSide,
  204. const mozilla::LogicalSize& aContainBlockSize,
  205. const mozilla::LogicalSize& aCaptionSize,
  206. const mozilla::LogicalMargin& aCaptionMargin,
  207. const mozilla::LogicalSize& aInnerSize,
  208. mozilla::LogicalMargin& aInnerMargin,
  209. mozilla::LogicalPoint& aOrigin,
  210. mozilla::WritingMode aWM);
  211. // reflow the child (caption or innertable frame)
  212. void OuterBeginReflowChild(nsPresContext* aPresContext,
  213. nsIFrame* aChildFrame,
  214. const ReflowInput& aOuterRI,
  215. mozilla::Maybe<ReflowInput>& aChildRI,
  216. nscoord aAvailISize);
  217. void OuterDoReflowChild(nsPresContext* aPresContext,
  218. nsIFrame* aChildFrame,
  219. const ReflowInput& aChildRI,
  220. ReflowOutput& aMetrics,
  221. nsReflowStatus& aStatus);
  222. // Set the overflow areas in our reflow metrics
  223. void UpdateOverflowAreas(ReflowOutput& aMet);
  224. // Get the margin.
  225. void GetChildMargin(nsPresContext* aPresContext,
  226. const ReflowInput& aOuterRI,
  227. nsIFrame* aChildFrame,
  228. nscoord aAvailableWidth,
  229. mozilla::LogicalMargin& aMargin);
  230. virtual bool IsFrameOfType(uint32_t aFlags) const override
  231. {
  232. return nsContainerFrame::IsFrameOfType(aFlags &
  233. (~eCanContainOverflowContainers));
  234. }
  235. nsTableFrame* InnerTableFrame() const
  236. {
  237. return static_cast<nsTableFrame*>(mFrames.FirstChild());
  238. }
  239. /**
  240. * Helper for ComputeAutoSize.
  241. * Compute the margin-box inline size of aChildFrame given the inputs.
  242. * If aMarginResult is non-null, fill it with the part of the
  243. * margin-isize that was contributed by the margin.
  244. */
  245. nscoord ChildShrinkWrapISize(nsRenderingContext* aRenderingContext,
  246. nsIFrame* aChildFrame,
  247. mozilla::WritingMode aWM,
  248. mozilla::LogicalSize aCBSize,
  249. nscoord aAvailableISize,
  250. nscoord* aMarginResult = nullptr) const;
  251. private:
  252. nsFrameList mCaptionFrames;
  253. };
  254. #endif