1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/layout/tables/nsTableRowFrame.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,435 @@ 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 +#ifndef nsTableRowFrame_h__ 1.9 +#define nsTableRowFrame_h__ 1.10 + 1.11 +#include "mozilla/Attributes.h" 1.12 +#include "nscore.h" 1.13 +#include "nsContainerFrame.h" 1.14 +#include "nsTablePainter.h" 1.15 + 1.16 +class nsTableFrame; 1.17 +class nsTableCellFrame; 1.18 +struct nsTableCellReflowState; 1.19 + 1.20 +/** 1.21 + * nsTableRowFrame is the frame that maps table rows 1.22 + * (HTML tag TR). This class cannot be reused 1.23 + * outside of an nsTableRowGroupFrame. It assumes that its parent is an nsTableRowGroupFrame, 1.24 + * and its children are nsTableCellFrames. 1.25 + * 1.26 + * @see nsTableFrame 1.27 + * @see nsTableRowGroupFrame 1.28 + * @see nsTableCellFrame 1.29 + */ 1.30 +class nsTableRowFrame : public nsContainerFrame 1.31 +{ 1.32 +public: 1.33 + NS_DECL_QUERYFRAME_TARGET(nsTableRowFrame) 1.34 + NS_DECL_QUERYFRAME 1.35 + NS_DECL_FRAMEARENA_HELPERS 1.36 + 1.37 + virtual ~nsTableRowFrame(); 1.38 + 1.39 + virtual void Init(nsIContent* aContent, 1.40 + nsIFrame* aParent, 1.41 + nsIFrame* aPrevInFlow) MOZ_OVERRIDE; 1.42 + 1.43 + virtual void DestroyFrom(nsIFrame* aDestructRoot) MOZ_OVERRIDE; 1.44 + 1.45 + /** @see nsIFrame::DidSetStyleContext */ 1.46 + virtual void DidSetStyleContext(nsStyleContext* aOldStyleContext) MOZ_OVERRIDE; 1.47 + 1.48 + virtual nsresult AppendFrames(ChildListID aListID, 1.49 + nsFrameList& aFrameList) MOZ_OVERRIDE; 1.50 + virtual nsresult InsertFrames(ChildListID aListID, 1.51 + nsIFrame* aPrevFrame, 1.52 + nsFrameList& aFrameList) MOZ_OVERRIDE; 1.53 + virtual nsresult RemoveFrame(ChildListID aListID, 1.54 + nsIFrame* aOldFrame) MOZ_OVERRIDE; 1.55 + 1.56 + /** instantiate a new instance of nsTableRowFrame. 1.57 + * @param aPresShell the pres shell for this frame 1.58 + * 1.59 + * @return the frame that was created 1.60 + */ 1.61 + friend nsIFrame* NS_NewTableRowFrame(nsIPresShell* aPresShell, nsStyleContext* aContext); 1.62 + 1.63 + virtual nsMargin GetUsedMargin() const MOZ_OVERRIDE; 1.64 + virtual nsMargin GetUsedBorder() const MOZ_OVERRIDE; 1.65 + virtual nsMargin GetUsedPadding() const MOZ_OVERRIDE; 1.66 + 1.67 + virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder, 1.68 + const nsRect& aDirtyRect, 1.69 + const nsDisplayListSet& aLists) MOZ_OVERRIDE; 1.70 + 1.71 + nsTableCellFrame* GetFirstCell() ; 1.72 + 1.73 + /** calls Reflow for all of its child cells. 1.74 + * Cells with rowspan=1 are all set to the same height and stacked horizontally. 1.75 + * <P> Cells are not split unless absolutely necessary. 1.76 + * <P> Cells are resized in nsTableFrame::BalanceColumnWidths 1.77 + * and nsTableFrame::ShrinkWrapChildren 1.78 + * 1.79 + * @param aDesiredSize width set to width of the sum of the cells, height set to 1.80 + * height of cells with rowspan=1. 1.81 + * 1.82 + * @see nsIFrame::Reflow 1.83 + * @see nsTableFrame::BalanceColumnWidths 1.84 + * @see nsTableFrame::ShrinkWrapChildren 1.85 + */ 1.86 + virtual nsresult Reflow(nsPresContext* aPresContext, 1.87 + nsHTMLReflowMetrics& aDesiredSize, 1.88 + const nsHTMLReflowState& aReflowState, 1.89 + nsReflowStatus& aStatus) MOZ_OVERRIDE; 1.90 + 1.91 + void DidResize(); 1.92 + 1.93 + /** 1.94 + * Get the "type" of the frame 1.95 + * 1.96 + * @see nsGkAtoms::tableRowFrame 1.97 + */ 1.98 + virtual nsIAtom* GetType() const MOZ_OVERRIDE; 1.99 + 1.100 +#ifdef DEBUG_FRAME_DUMP 1.101 + virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE; 1.102 +#endif 1.103 + 1.104 + void UpdateHeight(nscoord aHeight, 1.105 + nscoord aAscent, 1.106 + nscoord aDescent, 1.107 + nsTableFrame* aTableFrame = nullptr, 1.108 + nsTableCellFrame* aCellFrame = nullptr); 1.109 + 1.110 + void ResetHeight(nscoord aRowStyleHeight); 1.111 + 1.112 + // calculate the height, considering content height of the 1.113 + // cells and the style height of the row and cells, excluding pct heights 1.114 + nscoord CalcHeight(const nsHTMLReflowState& aReflowState); 1.115 + 1.116 + // Support for cells with 'vertical-align: baseline'. 1.117 + 1.118 + /** 1.119 + * returns the max-ascent amongst all the cells that have 1.120 + * 'vertical-align: baseline', *including* cells with rowspans. 1.121 + * returns 0 if we don't have any cell with 'vertical-align: baseline' 1.122 + */ 1.123 + nscoord GetMaxCellAscent() const; 1.124 + 1.125 + /* return the row ascent 1.126 + */ 1.127 + nscoord GetRowBaseline(); 1.128 + 1.129 + /** returns the ordinal position of this row in its table */ 1.130 + virtual int32_t GetRowIndex() const; 1.131 + 1.132 + /** set this row's starting row index */ 1.133 + void SetRowIndex (int aRowIndex); 1.134 + 1.135 + /** used by row group frame code */ 1.136 + nscoord ReflowCellFrame(nsPresContext* aPresContext, 1.137 + const nsHTMLReflowState& aReflowState, 1.138 + bool aIsTopOfPage, 1.139 + nsTableCellFrame* aCellFrame, 1.140 + nscoord aAvailableHeight, 1.141 + nsReflowStatus& aStatus); 1.142 + /** 1.143 + * Collapse the row if required, apply col and colgroup visibility: collapse 1.144 + * info to the cells in the row. 1.145 + * @return he amount to shift up all following rows 1.146 + * @param aRowOffset - shift the row up by this amount 1.147 + * @param aWidth - new width of the row 1.148 + * @param aCollapseGroup - parent rowgroup is collapsed so this row needs 1.149 + * to be collapsed 1.150 + * @param aDidCollapse - the row has been collapsed 1.151 + */ 1.152 + nscoord CollapseRowIfNecessary(nscoord aRowOffset, 1.153 + nscoord aWidth, 1.154 + bool aCollapseGroup, 1.155 + bool& aDidCollapse); 1.156 + 1.157 + /** 1.158 + * Insert a cell frame after the last cell frame that has a col index 1.159 + * that is less than aColIndex. If no such cell frame is found the 1.160 + * frame to insert is prepended to the child list. 1.161 + * @param aFrame the cell frame to insert 1.162 + * @param aColIndex the col index 1.163 + */ 1.164 + void InsertCellFrame(nsTableCellFrame* aFrame, 1.165 + int32_t aColIndex); 1.166 + 1.167 + nsresult CalculateCellActualHeight(nsTableCellFrame* aCellFrame, 1.168 + nscoord& aDesiredHeight); 1.169 + 1.170 + bool IsFirstInserted() const; 1.171 + void SetFirstInserted(bool aValue); 1.172 + 1.173 + nscoord GetContentHeight() const; 1.174 + void SetContentHeight(nscoord aTwipValue); 1.175 + 1.176 + bool HasStyleHeight() const; 1.177 + 1.178 + bool HasFixedHeight() const; 1.179 + void SetHasFixedHeight(bool aValue); 1.180 + 1.181 + bool HasPctHeight() const; 1.182 + void SetHasPctHeight(bool aValue); 1.183 + 1.184 + nscoord GetFixedHeight() const; 1.185 + void SetFixedHeight(nscoord aValue); 1.186 + 1.187 + float GetPctHeight() const; 1.188 + void SetPctHeight(float aPctValue, 1.189 + bool aForce = false); 1.190 + 1.191 + nscoord GetHeight(nscoord aBasis = 0) const; 1.192 + 1.193 + nsTableRowFrame* GetNextRow() const; 1.194 + 1.195 + bool HasUnpaginatedHeight(); 1.196 + void SetHasUnpaginatedHeight(bool aValue); 1.197 + nscoord GetUnpaginatedHeight(nsPresContext* aPresContext); 1.198 + void SetUnpaginatedHeight(nsPresContext* aPresContext, nscoord aValue); 1.199 + 1.200 + nscoord GetTopBCBorderWidth(); 1.201 + void SetTopBCBorderWidth(BCPixelSize aWidth); 1.202 + nscoord GetBottomBCBorderWidth(); 1.203 + void SetBottomBCBorderWidth(BCPixelSize aWidth); 1.204 + nsMargin* GetBCBorderWidth(nsMargin& aBorder); 1.205 + 1.206 + /** 1.207 + * Gets inner border widths before collapsing with cell borders 1.208 + * Caller must get bottom border from next row or from table 1.209 + * GetContinuousBCBorderWidth will not overwrite aBorder.bottom 1.210 + * see nsTablePainter about continuous borders 1.211 + */ 1.212 + void GetContinuousBCBorderWidth(nsMargin& aBorder); 1.213 + /** 1.214 + * @returns outer top bc border == prev row's bottom inner 1.215 + */ 1.216 + nscoord GetOuterTopContBCBorderWidth(); 1.217 + /** 1.218 + * Sets full border widths before collapsing with cell borders 1.219 + * @param aForSide - side to set; only accepts right, left, and top 1.220 + */ 1.221 + void SetContinuousBCBorderWidth(uint8_t aForSide, 1.222 + BCPixelSize aPixelValue); 1.223 + 1.224 + virtual bool IsFrameOfType(uint32_t aFlags) const MOZ_OVERRIDE 1.225 + { 1.226 + return nsContainerFrame::IsFrameOfType(aFlags & ~(nsIFrame::eTablePart)); 1.227 + } 1.228 + 1.229 + virtual void InvalidateFrame(uint32_t aDisplayItemKey = 0) MOZ_OVERRIDE; 1.230 + virtual void InvalidateFrameWithRect(const nsRect& aRect, uint32_t aDisplayItemKey = 0) MOZ_OVERRIDE; 1.231 + virtual void InvalidateFrameForRemoval() MOZ_OVERRIDE { InvalidateFrameSubtree(); } 1.232 + 1.233 +#ifdef ACCESSIBILITY 1.234 + virtual mozilla::a11y::AccType AccessibleType() MOZ_OVERRIDE; 1.235 +#endif 1.236 + 1.237 +protected: 1.238 + 1.239 + /** protected constructor. 1.240 + * @see NewFrame 1.241 + */ 1.242 + nsTableRowFrame(nsStyleContext *aContext); 1.243 + 1.244 + void InitChildReflowState(nsPresContext& aPresContext, 1.245 + const nsSize& aAvailSize, 1.246 + bool aBorderCollapse, 1.247 + nsTableCellReflowState& aReflowState); 1.248 + 1.249 + virtual int GetLogicalSkipSides(const nsHTMLReflowState* aReflowState = nullptr) const MOZ_OVERRIDE; 1.250 + 1.251 + // row-specific methods 1.252 + 1.253 + nscoord ComputeCellXOffset(const nsHTMLReflowState& aState, 1.254 + nsIFrame* aKidFrame, 1.255 + const nsMargin& aKidMargin) const; 1.256 + /** 1.257 + * Called for incremental/dirty and resize reflows. If aDirtyOnly is true then 1.258 + * only reflow dirty cells. 1.259 + */ 1.260 + nsresult ReflowChildren(nsPresContext* aPresContext, 1.261 + nsHTMLReflowMetrics& aDesiredSize, 1.262 + const nsHTMLReflowState& aReflowState, 1.263 + nsTableFrame& aTableFrame, 1.264 + nsReflowStatus& aStatus); 1.265 + 1.266 +private: 1.267 + struct RowBits { 1.268 + unsigned mRowIndex:29; 1.269 + unsigned mHasFixedHeight:1; // set if the dominating style height on the row or any cell is pixel based 1.270 + unsigned mHasPctHeight:1; // set if the dominating style height on the row or any cell is pct based 1.271 + unsigned mFirstInserted:1; // if true, then it was the top most newly inserted row 1.272 + } mBits; 1.273 + 1.274 + // the desired height based on the content of the tallest cell in the row 1.275 + nscoord mContentHeight; 1.276 + // the height based on a style percentage height on either the row or any cell 1.277 + // if mHasPctHeight is set 1.278 + nscoord mStylePctHeight; 1.279 + // the height based on a style pixel height on the row or any 1.280 + // cell if mHasFixedHeight is set 1.281 + nscoord mStyleFixedHeight; 1.282 + 1.283 + // max-ascent and max-descent amongst all cells that have 'vertical-align: baseline' 1.284 + nscoord mMaxCellAscent; // does include cells with rowspan > 1 1.285 + nscoord mMaxCellDescent; // does *not* include cells with rowspan > 1 1.286 + 1.287 + // border widths in pixels in the collapsing border model of the *inner* 1.288 + // half of the border only 1.289 + BCPixelSize mTopBorderWidth; 1.290 + BCPixelSize mBottomBorderWidth; 1.291 + BCPixelSize mRightContBorderWidth; 1.292 + BCPixelSize mTopContBorderWidth; 1.293 + BCPixelSize mLeftContBorderWidth; 1.294 + 1.295 + /** 1.296 + * Sets the NS_ROW_HAS_CELL_WITH_STYLE_HEIGHT bit to indicate whether 1.297 + * this row has any cells that have non-auto-height. (Row-spanning 1.298 + * cells are ignored.) 1.299 + */ 1.300 + void InitHasCellWithStyleHeight(nsTableFrame* aTableFrame); 1.301 + 1.302 +}; 1.303 + 1.304 +inline int32_t nsTableRowFrame::GetRowIndex() const 1.305 +{ 1.306 + return int32_t(mBits.mRowIndex); 1.307 +} 1.308 + 1.309 +inline void nsTableRowFrame::SetRowIndex (int aRowIndex) 1.310 +{ 1.311 + mBits.mRowIndex = aRowIndex; 1.312 +} 1.313 + 1.314 +inline bool nsTableRowFrame::IsFirstInserted() const 1.315 +{ 1.316 + return bool(mBits.mFirstInserted); 1.317 +} 1.318 + 1.319 +inline void nsTableRowFrame::SetFirstInserted(bool aValue) 1.320 +{ 1.321 + mBits.mFirstInserted = aValue; 1.322 +} 1.323 + 1.324 +inline bool nsTableRowFrame::HasStyleHeight() const 1.325 +{ 1.326 + return (bool)mBits.mHasFixedHeight || (bool)mBits.mHasPctHeight; 1.327 +} 1.328 + 1.329 +inline bool nsTableRowFrame::HasFixedHeight() const 1.330 +{ 1.331 + return (bool)mBits.mHasFixedHeight; 1.332 +} 1.333 + 1.334 +inline void nsTableRowFrame::SetHasFixedHeight(bool aValue) 1.335 +{ 1.336 + mBits.mHasFixedHeight = aValue; 1.337 +} 1.338 + 1.339 +inline bool nsTableRowFrame::HasPctHeight() const 1.340 +{ 1.341 + return (bool)mBits.mHasPctHeight; 1.342 +} 1.343 + 1.344 +inline void nsTableRowFrame::SetHasPctHeight(bool aValue) 1.345 +{ 1.346 + mBits.mHasPctHeight = aValue; 1.347 +} 1.348 + 1.349 +inline nscoord nsTableRowFrame::GetContentHeight() const 1.350 +{ 1.351 + return mContentHeight; 1.352 +} 1.353 + 1.354 +inline void nsTableRowFrame::SetContentHeight(nscoord aValue) 1.355 +{ 1.356 + mContentHeight = aValue; 1.357 +} 1.358 + 1.359 +inline nscoord nsTableRowFrame::GetFixedHeight() const 1.360 +{ 1.361 + if (mBits.mHasFixedHeight) 1.362 + return mStyleFixedHeight; 1.363 + else 1.364 + return 0; 1.365 +} 1.366 + 1.367 +inline float nsTableRowFrame::GetPctHeight() const 1.368 +{ 1.369 + if (mBits.mHasPctHeight) 1.370 + return (float)mStylePctHeight / 100.0f; 1.371 + else 1.372 + return 0.0f; 1.373 +} 1.374 + 1.375 +inline bool nsTableRowFrame::HasUnpaginatedHeight() 1.376 +{ 1.377 + return (mState & NS_TABLE_ROW_HAS_UNPAGINATED_HEIGHT) == 1.378 + NS_TABLE_ROW_HAS_UNPAGINATED_HEIGHT; 1.379 +} 1.380 + 1.381 +inline void nsTableRowFrame::SetHasUnpaginatedHeight(bool aValue) 1.382 +{ 1.383 + if (aValue) { 1.384 + mState |= NS_TABLE_ROW_HAS_UNPAGINATED_HEIGHT; 1.385 + } else { 1.386 + mState &= ~NS_TABLE_ROW_HAS_UNPAGINATED_HEIGHT; 1.387 + } 1.388 +} 1.389 + 1.390 +inline nscoord nsTableRowFrame::GetTopBCBorderWidth() 1.391 +{ 1.392 + return mTopBorderWidth; 1.393 +} 1.394 + 1.395 +inline void nsTableRowFrame::SetTopBCBorderWidth(BCPixelSize aWidth) 1.396 +{ 1.397 + mTopBorderWidth = aWidth; 1.398 +} 1.399 + 1.400 +inline nscoord nsTableRowFrame::GetBottomBCBorderWidth() 1.401 +{ 1.402 + return mBottomBorderWidth; 1.403 +} 1.404 + 1.405 +inline void nsTableRowFrame::SetBottomBCBorderWidth(BCPixelSize aWidth) 1.406 +{ 1.407 + mBottomBorderWidth = aWidth; 1.408 +} 1.409 + 1.410 +inline nsMargin* nsTableRowFrame::GetBCBorderWidth(nsMargin& aBorder) 1.411 +{ 1.412 + aBorder.left = aBorder.right = 0; 1.413 + 1.414 + aBorder.top = nsPresContext::CSSPixelsToAppUnits(mTopBorderWidth); 1.415 + aBorder.bottom = nsPresContext::CSSPixelsToAppUnits(mBottomBorderWidth); 1.416 + 1.417 + return &aBorder; 1.418 +} 1.419 + 1.420 +inline void 1.421 +nsTableRowFrame::GetContinuousBCBorderWidth(nsMargin& aBorder) 1.422 +{ 1.423 + int32_t aPixelsToTwips = nsPresContext::AppUnitsPerCSSPixel(); 1.424 + aBorder.right = BC_BORDER_LEFT_HALF_COORD(aPixelsToTwips, 1.425 + mLeftContBorderWidth); 1.426 + aBorder.top = BC_BORDER_BOTTOM_HALF_COORD(aPixelsToTwips, 1.427 + mTopContBorderWidth); 1.428 + aBorder.left = BC_BORDER_RIGHT_HALF_COORD(aPixelsToTwips, 1.429 + mRightContBorderWidth); 1.430 +} 1.431 + 1.432 +inline nscoord nsTableRowFrame::GetOuterTopContBCBorderWidth() 1.433 +{ 1.434 + int32_t aPixelsToTwips = nsPresContext::AppUnitsPerCSSPixel(); 1.435 + return BC_BORDER_TOP_HALF_COORD(aPixelsToTwips, mTopContBorderWidth); 1.436 +} 1.437 + 1.438 +#endif