1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/layout/mathml/nsMathMLmtableFrame.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,268 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#ifndef nsMathMLmtableFrame_h___ 1.10 +#define nsMathMLmtableFrame_h___ 1.11 + 1.12 +#include "mozilla/Attributes.h" 1.13 +#include "nsMathMLContainerFrame.h" 1.14 +#include "nsBlockFrame.h" 1.15 +#include "nsTableOuterFrame.h" 1.16 +#include "nsTableRowFrame.h" 1.17 +#include "nsTableCellFrame.h" 1.18 + 1.19 +// 1.20 +// <mtable> -- table or matrix 1.21 +// 1.22 + 1.23 +class nsMathMLmtableOuterFrame : public nsTableOuterFrame, 1.24 + public nsMathMLFrame 1.25 +{ 1.26 +public: 1.27 + friend nsIFrame* NS_NewMathMLmtableOuterFrame(nsIPresShell* aPresShell, nsStyleContext* aContext); 1.28 + 1.29 + NS_DECL_QUERYFRAME 1.30 + NS_DECL_FRAMEARENA_HELPERS 1.31 + 1.32 + // overloaded nsTableOuterFrame methods 1.33 + 1.34 + virtual nsresult 1.35 + Reflow(nsPresContext* aPresContext, 1.36 + nsHTMLReflowMetrics& aDesiredSize, 1.37 + const nsHTMLReflowState& aReflowState, 1.38 + nsReflowStatus& aStatus) MOZ_OVERRIDE; 1.39 + 1.40 + virtual nsresult 1.41 + AttributeChanged(int32_t aNameSpaceID, 1.42 + nsIAtom* aAttribute, 1.43 + int32_t aModType) MOZ_OVERRIDE; 1.44 + 1.45 + virtual bool IsFrameOfType(uint32_t aFlags) const MOZ_OVERRIDE 1.46 + { 1.47 + return nsTableOuterFrame::IsFrameOfType(aFlags & ~(nsIFrame::eMathML)); 1.48 + } 1.49 + 1.50 +protected: 1.51 + nsMathMLmtableOuterFrame(nsStyleContext* aContext) : nsTableOuterFrame(aContext) {} 1.52 + virtual ~nsMathMLmtableOuterFrame(); 1.53 + 1.54 + // helper to find the row frame at a given index, positive or negative, e.g., 1.55 + // 1..n means the first row down to the last row, -1..-n means the last row 1.56 + // up to the first row. Used for alignments that are relative to a given row 1.57 + nsIFrame* 1.58 + GetRowFrameAt(nsPresContext* aPresContext, 1.59 + int32_t aRowIndex); 1.60 +}; // class nsMathMLmtableOuterFrame 1.61 + 1.62 +// -------------- 1.63 + 1.64 +class nsMathMLmtableFrame : public nsTableFrame 1.65 +{ 1.66 +public: 1.67 + NS_DECL_FRAMEARENA_HELPERS 1.68 + 1.69 + friend nsIFrame* NS_NewMathMLmtableFrame(nsIPresShell* aPresShell, nsStyleContext* aContext); 1.70 + 1.71 + // Overloaded nsTableFrame methods 1.72 + 1.73 + virtual nsresult 1.74 + SetInitialChildList(ChildListID aListID, 1.75 + nsFrameList& aChildList) MOZ_OVERRIDE; 1.76 + 1.77 + virtual nsresult 1.78 + AppendFrames(ChildListID aListID, 1.79 + nsFrameList& aFrameList) MOZ_OVERRIDE 1.80 + { 1.81 + nsresult rv = nsTableFrame::AppendFrames(aListID, aFrameList); 1.82 + RestyleTable(); 1.83 + return rv; 1.84 + } 1.85 + 1.86 + virtual nsresult 1.87 + InsertFrames(ChildListID aListID, 1.88 + nsIFrame* aPrevFrame, 1.89 + nsFrameList& aFrameList) MOZ_OVERRIDE 1.90 + { 1.91 + nsresult rv = nsTableFrame::InsertFrames(aListID, aPrevFrame, aFrameList); 1.92 + RestyleTable(); 1.93 + return rv; 1.94 + } 1.95 + 1.96 + virtual nsresult 1.97 + RemoveFrame(ChildListID aListID, 1.98 + nsIFrame* aOldFrame) MOZ_OVERRIDE 1.99 + { 1.100 + nsresult rv = nsTableFrame::RemoveFrame(aListID, aOldFrame); 1.101 + RestyleTable(); 1.102 + return rv; 1.103 + } 1.104 + 1.105 + virtual bool IsFrameOfType(uint32_t aFlags) const MOZ_OVERRIDE 1.106 + { 1.107 + return nsTableFrame::IsFrameOfType(aFlags & ~(nsIFrame::eMathML)); 1.108 + } 1.109 + 1.110 + // helper to restyle and reflow the table when a row is changed -- since MathML 1.111 + // attributes are inter-dependent and row/colspan can affect the table, it is 1.112 + // safer (albeit grossly suboptimal) to just relayout the whole thing. 1.113 + void RestyleTable(); 1.114 + 1.115 +protected: 1.116 + nsMathMLmtableFrame(nsStyleContext* aContext) : nsTableFrame(aContext) {} 1.117 + virtual ~nsMathMLmtableFrame(); 1.118 +}; // class nsMathMLmtableFrame 1.119 + 1.120 +// -------------- 1.121 + 1.122 +class nsMathMLmtrFrame : public nsTableRowFrame 1.123 +{ 1.124 +public: 1.125 + NS_DECL_FRAMEARENA_HELPERS 1.126 + 1.127 + friend nsIFrame* NS_NewMathMLmtrFrame(nsIPresShell* aPresShell, nsStyleContext* aContext); 1.128 + 1.129 + // overloaded nsTableRowFrame methods 1.130 + 1.131 + virtual nsresult 1.132 + AttributeChanged(int32_t aNameSpaceID, 1.133 + nsIAtom* aAttribute, 1.134 + int32_t aModType) MOZ_OVERRIDE; 1.135 + 1.136 + virtual nsresult 1.137 + AppendFrames(ChildListID aListID, 1.138 + nsFrameList& aFrameList) MOZ_OVERRIDE 1.139 + { 1.140 + nsresult rv = nsTableRowFrame::AppendFrames(aListID, aFrameList); 1.141 + RestyleTable(); 1.142 + return rv; 1.143 + } 1.144 + 1.145 + virtual nsresult 1.146 + InsertFrames(ChildListID aListID, 1.147 + nsIFrame* aPrevFrame, 1.148 + nsFrameList& aFrameList) MOZ_OVERRIDE 1.149 + { 1.150 + nsresult rv = nsTableRowFrame::InsertFrames(aListID, aPrevFrame, aFrameList); 1.151 + RestyleTable(); 1.152 + return rv; 1.153 + } 1.154 + 1.155 + virtual nsresult 1.156 + RemoveFrame(ChildListID aListID, 1.157 + nsIFrame* aOldFrame) MOZ_OVERRIDE 1.158 + { 1.159 + nsresult rv = nsTableRowFrame::RemoveFrame(aListID, aOldFrame); 1.160 + RestyleTable(); 1.161 + return rv; 1.162 + } 1.163 + 1.164 + virtual bool IsFrameOfType(uint32_t aFlags) const MOZ_OVERRIDE 1.165 + { 1.166 + return nsTableRowFrame::IsFrameOfType(aFlags & ~(nsIFrame::eMathML)); 1.167 + } 1.168 + 1.169 + // helper to restyle and reflow the table -- @see nsMathMLmtableFrame. 1.170 + void RestyleTable() 1.171 + { 1.172 + nsTableFrame* tableFrame = nsTableFrame::GetTableFrame(this); 1.173 + if (tableFrame && tableFrame->IsFrameOfType(nsIFrame::eMathML)) { 1.174 + // relayout the table 1.175 + ((nsMathMLmtableFrame*)tableFrame)->RestyleTable(); 1.176 + } 1.177 + } 1.178 + 1.179 +protected: 1.180 + nsMathMLmtrFrame(nsStyleContext* aContext) : nsTableRowFrame(aContext) {} 1.181 + virtual ~nsMathMLmtrFrame(); 1.182 +}; // class nsMathMLmtrFrame 1.183 + 1.184 +// -------------- 1.185 + 1.186 +class nsMathMLmtdFrame : public nsTableCellFrame 1.187 +{ 1.188 +public: 1.189 + NS_DECL_FRAMEARENA_HELPERS 1.190 + 1.191 + friend nsIFrame* NS_NewMathMLmtdFrame(nsIPresShell* aPresShell, nsStyleContext* aContext); 1.192 + 1.193 + // overloaded nsTableCellFrame methods 1.194 + 1.195 + virtual nsresult 1.196 + AttributeChanged(int32_t aNameSpaceID, 1.197 + nsIAtom* aAttribute, 1.198 + int32_t aModType) MOZ_OVERRIDE; 1.199 + 1.200 + virtual uint8_t GetVerticalAlign() const MOZ_OVERRIDE; 1.201 + virtual nsresult ProcessBorders(nsTableFrame* aFrame, 1.202 + nsDisplayListBuilder* aBuilder, 1.203 + const nsDisplayListSet& aLists) MOZ_OVERRIDE; 1.204 + 1.205 + virtual int32_t GetRowSpan() MOZ_OVERRIDE; 1.206 + virtual int32_t GetColSpan() MOZ_OVERRIDE; 1.207 + virtual bool IsFrameOfType(uint32_t aFlags) const MOZ_OVERRIDE 1.208 + { 1.209 + return nsTableCellFrame::IsFrameOfType(aFlags & ~(nsIFrame::eMathML)); 1.210 + } 1.211 + 1.212 + virtual nsMargin* GetBorderWidth(nsMargin& aBorder) const MOZ_OVERRIDE; 1.213 + 1.214 +protected: 1.215 + nsMathMLmtdFrame(nsStyleContext* aContext) : nsTableCellFrame(aContext) {} 1.216 + virtual ~nsMathMLmtdFrame(); 1.217 +}; // class nsMathMLmtdFrame 1.218 + 1.219 +// -------------- 1.220 + 1.221 +class nsMathMLmtdInnerFrame : public nsBlockFrame, 1.222 + public nsMathMLFrame { 1.223 +public: 1.224 + friend nsIFrame* NS_NewMathMLmtdInnerFrame(nsIPresShell* aPresShell, nsStyleContext* aContext); 1.225 + 1.226 + NS_DECL_QUERYFRAME 1.227 + NS_DECL_FRAMEARENA_HELPERS 1.228 + 1.229 + // Overloaded nsIMathMLFrame methods 1.230 + 1.231 + NS_IMETHOD 1.232 + UpdatePresentationDataFromChildAt(int32_t aFirstIndex, 1.233 + int32_t aLastIndex, 1.234 + uint32_t aFlagsValues, 1.235 + uint32_t aFlagsToUpdate) MOZ_OVERRIDE 1.236 + { 1.237 + nsMathMLContainerFrame::PropagatePresentationDataFromChildAt(this, 1.238 + aFirstIndex, aLastIndex, aFlagsValues, aFlagsToUpdate); 1.239 + return NS_OK; 1.240 + } 1.241 + 1.242 + virtual nsresult 1.243 + Reflow(nsPresContext* aPresContext, 1.244 + nsHTMLReflowMetrics& aDesiredSize, 1.245 + const nsHTMLReflowState& aReflowState, 1.246 + nsReflowStatus& aStatus) MOZ_OVERRIDE; 1.247 + 1.248 + virtual bool IsFrameOfType(uint32_t aFlags) const MOZ_OVERRIDE 1.249 + { 1.250 + return nsBlockFrame::IsFrameOfType(aFlags & 1.251 + ~(nsIFrame::eMathML | nsIFrame::eExcludesIgnorableWhitespace)); 1.252 + } 1.253 + 1.254 + virtual const nsStyleText* StyleTextForLineLayout() MOZ_OVERRIDE; 1.255 + virtual void DidSetStyleContext(nsStyleContext* aOldStyleContext) MOZ_OVERRIDE; 1.256 + 1.257 + bool 1.258 + IsMrowLike() MOZ_OVERRIDE { 1.259 + return mFrames.FirstChild() != mFrames.LastChild() || 1.260 + !mFrames.FirstChild(); 1.261 + } 1.262 + 1.263 +protected: 1.264 + nsMathMLmtdInnerFrame(nsStyleContext* aContext); 1.265 + virtual ~nsMathMLmtdInnerFrame(); 1.266 + 1.267 + nsStyleText* mUniqueStyleText; 1.268 + 1.269 +}; // class nsMathMLmtdInnerFrame 1.270 + 1.271 +#endif /* nsMathMLmtableFrame_h___ */