layout/tables/nsTableCellFrame.h

Fri, 16 Jan 2015 18:13:44 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 18:13:44 +0100
branch
TOR_BUG_9701
changeset 14
925c144e1f1f
permissions
-rw-r--r--

Integrate suggestion from review to improve consistency with existing code.

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5 #ifndef nsTableCellFrame_h__
michael@0 6 #define nsTableCellFrame_h__
michael@0 7
michael@0 8 #include "mozilla/Attributes.h"
michael@0 9 #include "celldata.h"
michael@0 10 #include "nsITableCellLayout.h"
michael@0 11 #include "nscore.h"
michael@0 12 #include "nsContainerFrame.h"
michael@0 13 #include "nsStyleContext.h"
michael@0 14 #include "nsIPercentHeightObserver.h"
michael@0 15 #include "nsGkAtoms.h"
michael@0 16 #include "nsLayoutUtils.h"
michael@0 17 #include "nsTArray.h"
michael@0 18
michael@0 19 class nsTableFrame;
michael@0 20
michael@0 21 /**
michael@0 22 * nsTableCellFrame
michael@0 23 * data structure to maintain information about a single table cell's frame
michael@0 24 *
michael@0 25 * NOTE: frames are not ref counted. We expose addref and release here
michael@0 26 * so we can change that decsion in the future. Users of nsITableCellLayout
michael@0 27 * should refcount correctly as if this object is being ref counted, though
michael@0 28 * no actual support is under the hood.
michael@0 29 *
michael@0 30 * @author sclark
michael@0 31 */
michael@0 32 class nsTableCellFrame : public nsContainerFrame,
michael@0 33 public nsITableCellLayout,
michael@0 34 public nsIPercentHeightObserver
michael@0 35 {
michael@0 36 public:
michael@0 37 NS_DECL_QUERYFRAME_TARGET(nsTableCellFrame)
michael@0 38 NS_DECL_QUERYFRAME
michael@0 39 NS_DECL_FRAMEARENA_HELPERS
michael@0 40
michael@0 41 // default constructor supplied by the compiler
michael@0 42
michael@0 43 nsTableCellFrame(nsStyleContext* aContext);
michael@0 44 ~nsTableCellFrame();
michael@0 45
michael@0 46 virtual void Init(nsIContent* aContent,
michael@0 47 nsIFrame* aParent,
michael@0 48 nsIFrame* aPrevInFlow) MOZ_OVERRIDE;
michael@0 49
michael@0 50 virtual void DestroyFrom(nsIFrame* aDestructRoot) MOZ_OVERRIDE;
michael@0 51
michael@0 52 #ifdef ACCESSIBILITY
michael@0 53 virtual mozilla::a11y::AccType AccessibleType() MOZ_OVERRIDE;
michael@0 54 #endif
michael@0 55
michael@0 56 virtual nsresult AttributeChanged(int32_t aNameSpaceID,
michael@0 57 nsIAtom* aAttribute,
michael@0 58 int32_t aModType) MOZ_OVERRIDE;
michael@0 59
michael@0 60 /** @see nsIFrame::DidSetStyleContext */
michael@0 61 virtual void DidSetStyleContext(nsStyleContext* aOldStyleContext) MOZ_OVERRIDE;
michael@0 62
michael@0 63 // table cells contain a block frame which does most of the work, and
michael@0 64 // so these functions should never be called. They assert and return
michael@0 65 // NS_ERROR_NOT_IMPLEMENTED
michael@0 66 virtual nsresult AppendFrames(ChildListID aListID,
michael@0 67 nsFrameList& aFrameList) MOZ_OVERRIDE;
michael@0 68 virtual nsresult InsertFrames(ChildListID aListID,
michael@0 69 nsIFrame* aPrevFrame,
michael@0 70 nsFrameList& aFrameList) MOZ_OVERRIDE;
michael@0 71 virtual nsresult RemoveFrame(ChildListID aListID,
michael@0 72 nsIFrame* aOldFrame) MOZ_OVERRIDE;
michael@0 73
michael@0 74 virtual nsIFrame* GetContentInsertionFrame() MOZ_OVERRIDE {
michael@0 75 return GetFirstPrincipalChild()->GetContentInsertionFrame();
michael@0 76 }
michael@0 77
michael@0 78 virtual nsMargin GetUsedMargin() const MOZ_OVERRIDE;
michael@0 79
michael@0 80 virtual void NotifyPercentHeight(const nsHTMLReflowState& aReflowState) MOZ_OVERRIDE;
michael@0 81
michael@0 82 virtual bool NeedsToObserve(const nsHTMLReflowState& aReflowState) MOZ_OVERRIDE;
michael@0 83
michael@0 84 /** instantiate a new instance of nsTableRowFrame.
michael@0 85 * @param aPresShell the pres shell for this frame
michael@0 86 *
michael@0 87 * @return the frame that was created
michael@0 88 */
michael@0 89 friend nsIFrame* NS_NewTableCellFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
michael@0 90
michael@0 91 virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder,
michael@0 92 const nsRect& aDirtyRect,
michael@0 93 const nsDisplayListSet& aLists) MOZ_OVERRIDE;
michael@0 94
michael@0 95 void PaintCellBackground(nsRenderingContext& aRenderingContext,
michael@0 96 const nsRect& aDirtyRect, nsPoint aPt,
michael@0 97 uint32_t aFlags);
michael@0 98
michael@0 99
michael@0 100 virtual nsresult ProcessBorders(nsTableFrame* aFrame,
michael@0 101 nsDisplayListBuilder* aBuilder,
michael@0 102 const nsDisplayListSet& aLists);
michael@0 103
michael@0 104 virtual nscoord GetMinWidth(nsRenderingContext *aRenderingContext) MOZ_OVERRIDE;
michael@0 105 virtual nscoord GetPrefWidth(nsRenderingContext *aRenderingContext) MOZ_OVERRIDE;
michael@0 106 virtual IntrinsicWidthOffsetData
michael@0 107 IntrinsicWidthOffsets(nsRenderingContext* aRenderingContext) MOZ_OVERRIDE;
michael@0 108
michael@0 109 virtual nsresult Reflow(nsPresContext* aPresContext,
michael@0 110 nsHTMLReflowMetrics& aDesiredSize,
michael@0 111 const nsHTMLReflowState& aReflowState,
michael@0 112 nsReflowStatus& aStatus) MOZ_OVERRIDE;
michael@0 113
michael@0 114 /**
michael@0 115 * Get the "type" of the frame
michael@0 116 *
michael@0 117 * @see nsLayoutAtoms::tableCellFrame
michael@0 118 */
michael@0 119 virtual nsIAtom* GetType() const MOZ_OVERRIDE;
michael@0 120
michael@0 121 #ifdef DEBUG_FRAME_DUMP
michael@0 122 virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE;
michael@0 123 #endif
michael@0 124
michael@0 125 void VerticallyAlignChild(nscoord aMaxAscent);
michael@0 126
michael@0 127 /*
michael@0 128 * Get the value of vertical-align adjusted for CSS 2's rules for a
michael@0 129 * table cell, which means the result is always
michael@0 130 * NS_STYLE_VERTICAL_ALIGN_{TOP,MIDDLE,BOTTOM,BASELINE}.
michael@0 131 */
michael@0 132 virtual uint8_t GetVerticalAlign() const;
michael@0 133
michael@0 134 bool HasVerticalAlignBaseline() const {
michael@0 135 return GetVerticalAlign() == NS_STYLE_VERTICAL_ALIGN_BASELINE;
michael@0 136 }
michael@0 137
michael@0 138 bool CellHasVisibleContent(nscoord height,
michael@0 139 nsTableFrame* tableFrame,
michael@0 140 nsIFrame* kidFrame);
michael@0 141
michael@0 142 /**
michael@0 143 * Get the first-line baseline of the cell relative to its top border
michael@0 144 * edge, as if the cell were vertically aligned to the top of the row.
michael@0 145 */
michael@0 146 nscoord GetCellBaseline() const;
michael@0 147
michael@0 148 /**
michael@0 149 * return the cell's specified row span. this is what was specified in the
michael@0 150 * content model or in the style info, and is always >= 1.
michael@0 151 * to get the effective row span (the actual value that applies), use GetEffectiveRowSpan()
michael@0 152 * @see nsTableFrame::GetEffectiveRowSpan()
michael@0 153 */
michael@0 154 virtual int32_t GetRowSpan();
michael@0 155
michael@0 156 // there is no set row index because row index depends on the cell's parent row only
michael@0 157
michael@0 158 /*---------------- nsITableCellLayout methods ------------------------*/
michael@0 159
michael@0 160 /**
michael@0 161 * return the cell's starting row index (starting at 0 for the first row).
michael@0 162 * for continued cell frames the row index is that of the cell's first-in-flow
michael@0 163 * and the column index (starting at 0 for the first column
michael@0 164 */
michael@0 165 NS_IMETHOD GetCellIndexes(int32_t &aRowIndex, int32_t &aColIndex) MOZ_OVERRIDE;
michael@0 166
michael@0 167 /** return the mapped cell's row index (starting at 0 for the first row) */
michael@0 168 virtual nsresult GetRowIndex(int32_t &aRowIndex) const MOZ_OVERRIDE;
michael@0 169
michael@0 170 /**
michael@0 171 * return the cell's specified col span. this is what was specified in the
michael@0 172 * content model or in the style info, and is always >= 1.
michael@0 173 * to get the effective col span (the actual value that applies), use GetEffectiveColSpan()
michael@0 174 * @see nsTableFrame::GetEffectiveColSpan()
michael@0 175 */
michael@0 176 virtual int32_t GetColSpan();
michael@0 177
michael@0 178 /** return the cell's column index (starting at 0 for the first column) */
michael@0 179 virtual nsresult GetColIndex(int32_t &aColIndex) const MOZ_OVERRIDE;
michael@0 180 void SetColIndex(int32_t aColIndex);
michael@0 181
michael@0 182 /** return the available width given to this frame during its last reflow */
michael@0 183 inline nscoord GetPriorAvailWidth();
michael@0 184
michael@0 185 /** set the available width given to this frame during its last reflow */
michael@0 186 inline void SetPriorAvailWidth(nscoord aPriorAvailWidth);
michael@0 187
michael@0 188 /** return the desired size returned by this frame during its last reflow */
michael@0 189 inline nsSize GetDesiredSize();
michael@0 190
michael@0 191 /** set the desired size returned by this frame during its last reflow */
michael@0 192 inline void SetDesiredSize(const nsHTMLReflowMetrics & aDesiredSize);
michael@0 193
michael@0 194 bool GetContentEmpty();
michael@0 195 void SetContentEmpty(bool aContentEmpty);
michael@0 196
michael@0 197 bool HasPctOverHeight();
michael@0 198 void SetHasPctOverHeight(bool aValue);
michael@0 199
michael@0 200 nsTableCellFrame* GetNextCell() const;
michael@0 201
michael@0 202 virtual nsMargin* GetBorderWidth(nsMargin& aBorder) const;
michael@0 203
michael@0 204 virtual void PaintBackground(nsRenderingContext& aRenderingContext,
michael@0 205 const nsRect& aDirtyRect,
michael@0 206 nsPoint aPt,
michael@0 207 uint32_t aFlags);
michael@0 208
michael@0 209 void DecorateForSelection(nsRenderingContext& aRenderingContext,
michael@0 210 nsPoint aPt);
michael@0 211
michael@0 212 virtual bool UpdateOverflow() MOZ_OVERRIDE;
michael@0 213
michael@0 214 virtual bool IsFrameOfType(uint32_t aFlags) const MOZ_OVERRIDE
michael@0 215 {
michael@0 216 return nsContainerFrame::IsFrameOfType(aFlags & ~(nsIFrame::eTablePart));
michael@0 217 }
michael@0 218
michael@0 219 virtual void InvalidateFrame(uint32_t aDisplayItemKey = 0) MOZ_OVERRIDE;
michael@0 220 virtual void InvalidateFrameWithRect(const nsRect& aRect, uint32_t aDisplayItemKey = 0) MOZ_OVERRIDE;
michael@0 221 virtual void InvalidateFrameForRemoval() MOZ_OVERRIDE { InvalidateFrameSubtree(); }
michael@0 222
michael@0 223 protected:
michael@0 224 virtual int GetLogicalSkipSides(const nsHTMLReflowState* aReflowState= nullptr) const MOZ_OVERRIDE;
michael@0 225
michael@0 226 /**
michael@0 227 * GetBorderOverflow says how far the cell's own borders extend
michael@0 228 * outside its own bounds. In the separated borders model this should
michael@0 229 * just be zero (as it is for most frames), but in the collapsed
michael@0 230 * borders model (for which nsBCTableCellFrame overrides this virtual
michael@0 231 * method), it considers the extents of the collapsed border.
michael@0 232 */
michael@0 233 virtual nsMargin GetBorderOverflow();
michael@0 234
michael@0 235 friend class nsTableRowFrame;
michael@0 236
michael@0 237 uint32_t mColIndex; // the starting column for this cell
michael@0 238
michael@0 239 nscoord mPriorAvailWidth; // the avail width during the last reflow
michael@0 240 nsSize mDesiredSize; // the last desired width & height
michael@0 241 };
michael@0 242
michael@0 243 inline nscoord nsTableCellFrame::GetPriorAvailWidth()
michael@0 244 { return mPriorAvailWidth;}
michael@0 245
michael@0 246 inline void nsTableCellFrame::SetPriorAvailWidth(nscoord aPriorAvailWidth)
michael@0 247 { mPriorAvailWidth = aPriorAvailWidth;}
michael@0 248
michael@0 249 inline nsSize nsTableCellFrame::GetDesiredSize()
michael@0 250 { return mDesiredSize; }
michael@0 251
michael@0 252 inline void nsTableCellFrame::SetDesiredSize(const nsHTMLReflowMetrics & aDesiredSize)
michael@0 253 {
michael@0 254 mDesiredSize.width = aDesiredSize.Width();
michael@0 255 mDesiredSize.height = aDesiredSize.Height();
michael@0 256 }
michael@0 257
michael@0 258 inline bool nsTableCellFrame::GetContentEmpty()
michael@0 259 {
michael@0 260 return (mState & NS_TABLE_CELL_CONTENT_EMPTY) ==
michael@0 261 NS_TABLE_CELL_CONTENT_EMPTY;
michael@0 262 }
michael@0 263
michael@0 264 inline void nsTableCellFrame::SetContentEmpty(bool aContentEmpty)
michael@0 265 {
michael@0 266 if (aContentEmpty) {
michael@0 267 mState |= NS_TABLE_CELL_CONTENT_EMPTY;
michael@0 268 } else {
michael@0 269 mState &= ~NS_TABLE_CELL_CONTENT_EMPTY;
michael@0 270 }
michael@0 271 }
michael@0 272
michael@0 273 inline bool nsTableCellFrame::HasPctOverHeight()
michael@0 274 {
michael@0 275 return (mState & NS_TABLE_CELL_HAS_PCT_OVER_HEIGHT) ==
michael@0 276 NS_TABLE_CELL_HAS_PCT_OVER_HEIGHT;
michael@0 277 }
michael@0 278
michael@0 279 inline void nsTableCellFrame::SetHasPctOverHeight(bool aValue)
michael@0 280 {
michael@0 281 if (aValue) {
michael@0 282 mState |= NS_TABLE_CELL_HAS_PCT_OVER_HEIGHT;
michael@0 283 } else {
michael@0 284 mState &= ~NS_TABLE_CELL_HAS_PCT_OVER_HEIGHT;
michael@0 285 }
michael@0 286 }
michael@0 287
michael@0 288 // nsBCTableCellFrame
michael@0 289 class nsBCTableCellFrame : public nsTableCellFrame
michael@0 290 {
michael@0 291 public:
michael@0 292 NS_DECL_FRAMEARENA_HELPERS
michael@0 293
michael@0 294 nsBCTableCellFrame(nsStyleContext* aContext);
michael@0 295
michael@0 296 ~nsBCTableCellFrame();
michael@0 297
michael@0 298 virtual nsIAtom* GetType() const MOZ_OVERRIDE;
michael@0 299
michael@0 300 virtual nsMargin GetUsedBorder() const MOZ_OVERRIDE;
michael@0 301 virtual bool GetBorderRadii(nscoord aRadii[8]) const MOZ_OVERRIDE;
michael@0 302
michael@0 303 // Get the *inner half of the border only*, in twips.
michael@0 304 virtual nsMargin* GetBorderWidth(nsMargin& aBorder) const MOZ_OVERRIDE;
michael@0 305
michael@0 306 // Get the *inner half of the border only*, in pixels.
michael@0 307 BCPixelSize GetBorderWidth(mozilla::css::Side aSide) const;
michael@0 308
michael@0 309 // Set the full (both halves) width of the border
michael@0 310 void SetBorderWidth(mozilla::css::Side aSide, BCPixelSize aPixelValue);
michael@0 311
michael@0 312 virtual nsMargin GetBorderOverflow() MOZ_OVERRIDE;
michael@0 313
michael@0 314 #ifdef DEBUG_FRAME_DUMP
michael@0 315 virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE;
michael@0 316 #endif
michael@0 317
michael@0 318 virtual void PaintBackground(nsRenderingContext& aRenderingContext,
michael@0 319 const nsRect& aDirtyRect,
michael@0 320 nsPoint aPt,
michael@0 321 uint32_t aFlags) MOZ_OVERRIDE;
michael@0 322
michael@0 323 private:
michael@0 324
michael@0 325 // These are the entire width of the border (the cell edge contains only
michael@0 326 // the inner half, per the macros in nsTablePainter.h).
michael@0 327 BCPixelSize mTopBorder;
michael@0 328 BCPixelSize mRightBorder;
michael@0 329 BCPixelSize mBottomBorder;
michael@0 330 BCPixelSize mLeftBorder;
michael@0 331 };
michael@0 332
michael@0 333 #endif

mercurial