1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef nsMathMLmtableFrame_h___
8 #define nsMathMLmtableFrame_h___
10 #include "mozilla/Attributes.h"
11 #include "mozilla/UniquePtr.h"
12 #include "nsMathMLContainerFrame.h"
13 #include "nsBlockFrame.h"
14 #include "nsTableWrapperFrame.h"
15 #include "nsTableRowFrame.h"
16 #include "nsTableCellFrame.h"
19 class nsDisplayListBuilder
;
20 class nsDisplayListSet
;
22 } // namespace mozilla
25 // <mtable> -- table or matrix
28 class nsMathMLmtableWrapperFrame final
: public nsTableWrapperFrame
,
29 public nsMathMLFrame
{
31 friend nsContainerFrame
* NS_NewMathMLmtableOuterFrame(
32 mozilla::PresShell
* aPresShell
, ComputedStyle
* aStyle
);
35 NS_DECL_FRAMEARENA_HELPERS(nsMathMLmtableWrapperFrame
)
37 // overloaded nsTableWrapperFrame methods
39 void Reflow(nsPresContext
* aPresContext
, ReflowOutput
& aDesiredSize
,
40 const ReflowInput
& aReflowInput
,
41 nsReflowStatus
& aStatus
) override
;
43 nsresult
AttributeChanged(int32_t aNameSpaceID
, nsAtom
* aAttribute
,
44 int32_t aModType
) override
;
47 explicit nsMathMLmtableWrapperFrame(ComputedStyle
* aStyle
,
48 nsPresContext
* aPresContext
)
49 : nsTableWrapperFrame(aStyle
, aPresContext
, kClassID
) {}
51 virtual ~nsMathMLmtableWrapperFrame();
53 // helper to find the row frame at a given index, positive or negative, e.g.,
54 // 1..n means the first row down to the last row, -1..-n means the last row
55 // up to the first row. Used for alignments that are relative to a given row
56 nsIFrame
* GetRowFrameAt(int32_t aRowIndex
);
57 }; // class nsMathMLmtableWrapperFrame
61 class nsMathMLmtableFrame final
: public nsTableFrame
{
64 NS_DECL_FRAMEARENA_HELPERS(nsMathMLmtableFrame
)
66 friend nsContainerFrame
* NS_NewMathMLmtableFrame(
67 mozilla::PresShell
* aPresShell
, ComputedStyle
* aStyle
);
69 // Overloaded nsTableFrame methods
71 void SetInitialChildList(ChildListID aListID
,
72 nsFrameList
&& aChildList
) override
;
74 void AppendFrames(ChildListID aListID
, nsFrameList
&& aFrameList
) override
{
75 nsTableFrame::AppendFrames(aListID
, std::move(aFrameList
));
79 void InsertFrames(ChildListID aListID
, nsIFrame
* aPrevFrame
,
80 const nsLineList::iterator
* aPrevFrameLine
,
81 nsFrameList
&& aFrameList
) override
{
82 nsTableFrame::InsertFrames(aListID
, aPrevFrame
, aPrevFrameLine
,
83 std::move(aFrameList
));
87 void RemoveFrame(DestroyContext
& aContext
, ChildListID aListID
,
88 nsIFrame
* aOldFrame
) override
{
89 nsTableFrame::RemoveFrame(aContext
, aListID
, aOldFrame
);
93 // helper to restyle and reflow the table when a row is changed -- since
94 // MathML attributes are inter-dependent and row/colspan can affect the table,
95 // it is safer (albeit grossly suboptimal) to just relayout the whole thing.
98 /** helper to get the column spacing style value */
99 nscoord
GetColSpacing(int32_t aColIndex
) override
;
101 /** Sums the combined cell spacing between the columns aStartColIndex to
104 nscoord
GetColSpacing(int32_t aStartColIndex
, int32_t aEndColIndex
) override
;
106 /** helper to get the row spacing style value */
107 nscoord
GetRowSpacing(int32_t aRowIndex
) override
;
109 /** Sums the combined cell spacing between the rows aStartRowIndex to
112 nscoord
GetRowSpacing(int32_t aStartRowIndex
, int32_t aEndRowIndex
) override
;
114 void SetColSpacingArray(const nsTArray
<nscoord
>& aColSpacing
) {
115 mColSpacing
= aColSpacing
.Clone();
118 void SetRowSpacingArray(const nsTArray
<nscoord
>& aRowSpacing
) {
119 mRowSpacing
= aRowSpacing
.Clone();
122 void SetFrameSpacing(nscoord aSpacingX
, nscoord aSpacingY
) {
123 mFrameSpacingX
= aSpacingX
;
124 mFrameSpacingY
= aSpacingY
;
127 /** Determines whether the placement of table cells is determined by CSS
128 * spacing based on padding and border-spacing, or one based upon the
129 * rowspacing, columnspacing and framespacing attributes. The second
130 * approach is used if the user specifies at least one of those attributes.
132 void SetUseCSSSpacing();
133 bool GetUseCSSSpacing() { return mUseCSSSpacing
; }
136 explicit nsMathMLmtableFrame(ComputedStyle
* aStyle
,
137 nsPresContext
* aPresContext
)
138 : nsTableFrame(aStyle
, aPresContext
, kClassID
),
141 mUseCSSSpacing(false) {}
143 virtual ~nsMathMLmtableFrame();
146 nsTArray
<nscoord
> mColSpacing
;
147 nsTArray
<nscoord
> mRowSpacing
;
148 nscoord mFrameSpacingX
;
149 nscoord mFrameSpacingY
;
151 }; // class nsMathMLmtableFrame
155 class nsMathMLmtrFrame final
: public nsTableRowFrame
{
157 NS_DECL_FRAMEARENA_HELPERS(nsMathMLmtrFrame
)
159 friend nsContainerFrame
* NS_NewMathMLmtrFrame(mozilla::PresShell
* aPresShell
,
160 ComputedStyle
* aStyle
);
162 // overloaded nsTableRowFrame methods
164 nsresult
AttributeChanged(int32_t aNameSpaceID
, nsAtom
* aAttribute
,
165 int32_t aModType
) override
;
167 void AppendFrames(ChildListID aListID
, nsFrameList
&& aFrameList
) override
{
168 nsTableRowFrame::AppendFrames(aListID
, std::move(aFrameList
));
172 void InsertFrames(ChildListID aListID
, nsIFrame
* aPrevFrame
,
173 const nsLineList::iterator
* aPrevFrameLine
,
174 nsFrameList
&& aFrameList
) override
{
175 nsTableRowFrame::InsertFrames(aListID
, aPrevFrame
, aPrevFrameLine
,
176 std::move(aFrameList
));
180 void RemoveFrame(DestroyContext
& aContext
, ChildListID aListID
,
181 nsIFrame
* aOldFrame
) override
{
182 nsTableRowFrame::RemoveFrame(aContext
, aListID
, aOldFrame
);
186 // helper to restyle and reflow the table -- @see nsMathMLmtableFrame.
187 void RestyleTable() {
188 nsTableFrame
* tableFrame
= GetTableFrame();
189 if (tableFrame
&& tableFrame
->IsMathMLFrame()) {
190 // relayout the table
191 ((nsMathMLmtableFrame
*)tableFrame
)->RestyleTable();
196 explicit nsMathMLmtrFrame(ComputedStyle
* aStyle
, nsPresContext
* aPresContext
)
197 : nsTableRowFrame(aStyle
, aPresContext
, kClassID
) {}
199 virtual ~nsMathMLmtrFrame();
200 }; // class nsMathMLmtrFrame
204 class nsMathMLmtdFrame final
: public nsTableCellFrame
{
206 NS_DECL_FRAMEARENA_HELPERS(nsMathMLmtdFrame
)
208 friend nsContainerFrame
* NS_NewMathMLmtdFrame(mozilla::PresShell
* aPresShell
,
209 ComputedStyle
* aStyle
,
210 nsTableFrame
* aTableFrame
);
212 // overloaded nsTableCellFrame methods
214 void Init(nsIContent
* aContent
, nsContainerFrame
* aParent
,
215 nsIFrame
* aPrevInFlow
) override
;
217 nsresult
AttributeChanged(int32_t aNameSpaceID
, nsAtom
* aAttribute
,
218 int32_t aModType
) override
;
220 mozilla::StyleVerticalAlignKeyword
GetVerticalAlign() const override
;
221 void ProcessBorders(nsTableFrame
* aFrame
,
222 mozilla::nsDisplayListBuilder
* aBuilder
,
223 const mozilla::nsDisplayListSet
& aLists
) override
;
225 mozilla::LogicalMargin
GetBorderWidth(
226 mozilla::WritingMode aWM
) const override
;
228 nsMargin
GetBorderOverflow() override
;
231 nsMathMLmtdFrame(ComputedStyle
* aStyle
, nsTableFrame
* aTableFrame
)
232 : nsTableCellFrame(aStyle
, aTableFrame
, kClassID
) {}
234 virtual ~nsMathMLmtdFrame();
235 }; // class nsMathMLmtdFrame
239 class nsMathMLmtdInnerFrame final
: public nsBlockFrame
, public nsMathMLFrame
{
241 friend nsContainerFrame
* NS_NewMathMLmtdInnerFrame(
242 mozilla::PresShell
* aPresShell
, ComputedStyle
* aStyle
);
245 NS_DECL_FRAMEARENA_HELPERS(nsMathMLmtdInnerFrame
)
247 // Overloaded nsIMathMLFrame methods
250 UpdatePresentationDataFromChildAt(int32_t aFirstIndex
, int32_t aLastIndex
,
251 uint32_t aFlagsValues
,
252 uint32_t aFlagsToUpdate
) override
{
253 nsMathMLContainerFrame::PropagatePresentationDataFromChildAt(
254 this, aFirstIndex
, aLastIndex
, aFlagsValues
, aFlagsToUpdate
);
258 void Reflow(nsPresContext
* aPresContext
, ReflowOutput
& aDesiredSize
,
259 const ReflowInput
& aReflowInput
,
260 nsReflowStatus
& aStatus
) override
;
262 const nsStyleText
* StyleTextForLineLayout() override
;
263 void DidSetComputedStyle(ComputedStyle
* aOldComputedStyle
) override
;
265 bool IsMrowLike() override
{
266 return mFrames
.FirstChild() != mFrames
.LastChild() || !mFrames
.FirstChild();
270 explicit nsMathMLmtdInnerFrame(ComputedStyle
* aStyle
,
271 nsPresContext
* aPresContext
);
272 virtual ~nsMathMLmtdInnerFrame() = default;
274 mozilla::UniquePtr
<nsStyleText
> mUniqueStyleText
;
276 }; // class nsMathMLmtdInnerFrame
278 #endif /* nsMathMLmtableFrame_h___ */