nsMathMLmtableFrame.h (9479B)
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/. */ 6 7 #ifndef nsMathMLmtableFrame_h___ 8 #define nsMathMLmtableFrame_h___ 9 10 #include "mozilla/UniquePtr.h" 11 #include "nsBlockFrame.h" 12 #include "nsMathMLContainerFrame.h" 13 #include "nsTableCellFrame.h" 14 #include "nsTableRowFrame.h" 15 #include "nsTableWrapperFrame.h" 16 17 namespace mozilla { 18 class nsDisplayListBuilder; 19 class nsDisplayListSet; 20 class PresShell; 21 } // namespace mozilla 22 23 // 24 // <mtable> -- table or matrix 25 // 26 27 class nsMathMLmtableWrapperFrame final : public nsTableWrapperFrame, 28 public nsMathMLFrame { 29 public: 30 friend nsContainerFrame* NS_NewMathMLmtableOuterFrame( 31 mozilla::PresShell* aPresShell, ComputedStyle* aStyle); 32 33 NS_DECL_QUERYFRAME 34 NS_DECL_FRAMEARENA_HELPERS(nsMathMLmtableWrapperFrame) 35 36 // overloaded nsTableWrapperFrame methods 37 38 void Reflow(nsPresContext* aPresContext, ReflowOutput& aDesiredSize, 39 const ReflowInput& aReflowInput, 40 nsReflowStatus& aStatus) override; 41 42 nsresult AttributeChanged(int32_t aNameSpaceID, nsAtom* aAttribute, 43 AttrModType aModType) override; 44 45 protected: 46 explicit nsMathMLmtableWrapperFrame(ComputedStyle* aStyle, 47 nsPresContext* aPresContext) 48 : nsTableWrapperFrame(aStyle, aPresContext, kClassID) {} 49 50 virtual ~nsMathMLmtableWrapperFrame(); 51 52 // helper to find the row frame at a given index, positive or negative, e.g., 53 // 1..n means the first row down to the last row, -1..-n means the last row 54 // up to the first row. Used for alignments that are relative to a given row 55 nsIFrame* GetRowFrameAt(int32_t aRowIndex); 56 }; // class nsMathMLmtableWrapperFrame 57 58 // -------------- 59 60 class nsMathMLmtableFrame final : public nsTableFrame { 61 public: 62 NS_DECL_QUERYFRAME 63 NS_DECL_FRAMEARENA_HELPERS(nsMathMLmtableFrame) 64 65 friend nsContainerFrame* NS_NewMathMLmtableFrame( 66 mozilla::PresShell* aPresShell, ComputedStyle* aStyle); 67 68 // Overloaded nsTableFrame methods 69 70 void SetInitialChildList(ChildListID aListID, 71 nsFrameList&& aChildList) override; 72 73 void AppendFrames(ChildListID aListID, nsFrameList&& aFrameList) override { 74 nsTableFrame::AppendFrames(aListID, std::move(aFrameList)); 75 RestyleTable(); 76 } 77 78 void InsertFrames(ChildListID aListID, nsIFrame* aPrevFrame, 79 const nsLineList::iterator* aPrevFrameLine, 80 nsFrameList&& aFrameList) override { 81 nsTableFrame::InsertFrames(aListID, aPrevFrame, aPrevFrameLine, 82 std::move(aFrameList)); 83 RestyleTable(); 84 } 85 86 void RemoveFrame(DestroyContext& aContext, ChildListID aListID, 87 nsIFrame* aOldFrame) override { 88 nsTableFrame::RemoveFrame(aContext, aListID, aOldFrame); 89 RestyleTable(); 90 } 91 92 // helper to restyle and reflow the table when a row is changed -- since 93 // MathML attributes are inter-dependent and row/colspan can affect the table, 94 // it is safer (albeit grossly suboptimal) to just relayout the whole thing. 95 void RestyleTable(); 96 97 /** helper to get the column spacing style value */ 98 nscoord GetColSpacing(int32_t aColIndex) override; 99 100 /** Sums the combined cell spacing between the columns aStartColIndex to 101 * aEndColIndex. 102 */ 103 nscoord GetColSpacing(int32_t aStartColIndex, int32_t aEndColIndex) override; 104 105 /** helper to get the row spacing style value */ 106 nscoord GetRowSpacing(int32_t aRowIndex) override; 107 108 /** Sums the combined cell spacing between the rows aStartRowIndex to 109 * aEndRowIndex. 110 */ 111 nscoord GetRowSpacing(int32_t aStartRowIndex, int32_t aEndRowIndex) override; 112 113 void SetColSpacingArray(const nsTArray<nscoord>& aColSpacing) { 114 mColSpacing = aColSpacing.Clone(); 115 } 116 117 void SetRowSpacingArray(const nsTArray<nscoord>& aRowSpacing) { 118 mRowSpacing = aRowSpacing.Clone(); 119 } 120 121 void SetFrameSpacing(nscoord aSpacingX, nscoord aSpacingY) { 122 mFrameSpacingX = aSpacingX; 123 mFrameSpacingY = aSpacingY; 124 } 125 126 /** Determines whether the placement of table cells is determined by CSS 127 * spacing based on padding and border-spacing, or one based upon the 128 * rowspacing, columnspacing and framespacing attributes. The second 129 * approach is used if the user specifies at least one of those attributes. 130 */ 131 void SetUseCSSSpacing(); 132 bool GetUseCSSSpacing() { return mUseCSSSpacing; } 133 134 protected: 135 explicit nsMathMLmtableFrame(ComputedStyle* aStyle, 136 nsPresContext* aPresContext) 137 : nsTableFrame(aStyle, aPresContext, kClassID), 138 mFrameSpacingX(0), 139 mFrameSpacingY(0), 140 mUseCSSSpacing(false) {} 141 142 virtual ~nsMathMLmtableFrame(); 143 144 private: 145 nsTArray<nscoord> mColSpacing; 146 nsTArray<nscoord> mRowSpacing; 147 nscoord mFrameSpacingX; 148 nscoord mFrameSpacingY; 149 bool mUseCSSSpacing; 150 }; // class nsMathMLmtableFrame 151 152 // -------------- 153 154 class nsMathMLmtrFrame final : public nsTableRowFrame { 155 public: 156 NS_DECL_FRAMEARENA_HELPERS(nsMathMLmtrFrame) 157 158 friend nsContainerFrame* NS_NewMathMLmtrFrame(mozilla::PresShell* aPresShell, 159 ComputedStyle* aStyle); 160 161 // overloaded nsTableRowFrame methods 162 163 nsresult AttributeChanged(int32_t aNameSpaceID, nsAtom* aAttribute, 164 AttrModType aModType) override; 165 166 void AppendFrames(ChildListID aListID, nsFrameList&& aFrameList) override { 167 nsTableRowFrame::AppendFrames(aListID, std::move(aFrameList)); 168 RestyleTable(); 169 } 170 171 void InsertFrames(ChildListID aListID, nsIFrame* aPrevFrame, 172 const nsLineList::iterator* aPrevFrameLine, 173 nsFrameList&& aFrameList) override { 174 nsTableRowFrame::InsertFrames(aListID, aPrevFrame, aPrevFrameLine, 175 std::move(aFrameList)); 176 RestyleTable(); 177 } 178 179 void RemoveFrame(DestroyContext& aContext, ChildListID aListID, 180 nsIFrame* aOldFrame) override { 181 nsTableRowFrame::RemoveFrame(aContext, aListID, aOldFrame); 182 RestyleTable(); 183 } 184 185 // helper to restyle and reflow the table -- @see nsMathMLmtableFrame. 186 void RestyleTable() { 187 nsTableFrame* tableFrame = GetTableFrame(); 188 if (tableFrame && tableFrame->IsMathMLFrame()) { 189 // relayout the table 190 ((nsMathMLmtableFrame*)tableFrame)->RestyleTable(); 191 } 192 } 193 194 protected: 195 explicit nsMathMLmtrFrame(ComputedStyle* aStyle, nsPresContext* aPresContext) 196 : nsTableRowFrame(aStyle, aPresContext, kClassID) {} 197 198 virtual ~nsMathMLmtrFrame(); 199 }; // class nsMathMLmtrFrame 200 201 // -------------- 202 203 class nsMathMLmtdFrame final : public nsTableCellFrame { 204 public: 205 NS_DECL_FRAMEARENA_HELPERS(nsMathMLmtdFrame) 206 207 friend nsContainerFrame* NS_NewMathMLmtdFrame(mozilla::PresShell* aPresShell, 208 ComputedStyle* aStyle, 209 nsTableFrame* aTableFrame); 210 211 // overloaded nsTableCellFrame methods 212 213 void Init(nsIContent* aContent, nsContainerFrame* aParent, 214 nsIFrame* aPrevInFlow) override; 215 216 nsresult AttributeChanged(int32_t aNameSpaceID, nsAtom* aAttribute, 217 AttrModType aModType) override; 218 219 TableCellAlignment GetTableCellAlignment() const override; 220 void ProcessBorders(nsTableFrame* aFrame, 221 mozilla::nsDisplayListBuilder* aBuilder, 222 const mozilla::nsDisplayListSet& aLists) override; 223 224 mozilla::LogicalMargin GetBorderWidth( 225 mozilla::WritingMode aWM) const override; 226 227 nsMargin GetBorderOverflow() override; 228 229 protected: 230 nsMathMLmtdFrame(ComputedStyle* aStyle, nsTableFrame* aTableFrame) 231 : nsTableCellFrame(aStyle, aTableFrame, kClassID) {} 232 233 virtual ~nsMathMLmtdFrame(); 234 }; // class nsMathMLmtdFrame 235 236 // -------------- 237 238 class nsMathMLmtdInnerFrame final : public nsBlockFrame, public nsMathMLFrame { 239 public: 240 friend nsContainerFrame* NS_NewMathMLmtdInnerFrame( 241 mozilla::PresShell* aPresShell, ComputedStyle* aStyle); 242 243 NS_DECL_QUERYFRAME 244 NS_DECL_FRAMEARENA_HELPERS(nsMathMLmtdInnerFrame) 245 246 // Overloaded nsIMathMLFrame methods 247 248 NS_IMETHOD 249 UpdatePresentationDataFromChildAt( 250 int32_t aFirstIndex, int32_t aLastIndex, 251 MathMLPresentationFlags aFlagsValues, 252 MathMLPresentationFlags aFlagsToUpdate) override { 253 nsMathMLContainerFrame::PropagatePresentationDataFromChildAt( 254 this, aFirstIndex, aLastIndex, aFlagsValues, aFlagsToUpdate); 255 return NS_OK; 256 } 257 258 void Reflow(nsPresContext* aPresContext, ReflowOutput& aDesiredSize, 259 const ReflowInput& aReflowInput, 260 nsReflowStatus& aStatus) override; 261 262 const nsStyleText* StyleTextForLineLayout() override; 263 void DidSetComputedStyle(ComputedStyle* aOldComputedStyle) override; 264 265 bool IsMrowLike() override { 266 return mFrames.FirstChild() != mFrames.LastChild() || !mFrames.FirstChild(); 267 } 268 269 protected: 270 explicit nsMathMLmtdInnerFrame(ComputedStyle* aStyle, 271 nsPresContext* aPresContext); 272 virtual ~nsMathMLmtdInnerFrame() = default; 273 274 mozilla::UniquePtr<nsStyleText> mUniqueStyleText; 275 276 }; // class nsMathMLmtdInnerFrame 277 278 #endif /* nsMathMLmtableFrame_h___ */