layout/tables/nsTableCellFrame.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/layout/tables/nsTableCellFrame.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,333 @@
     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 nsTableCellFrame_h__
     1.9 +#define nsTableCellFrame_h__
    1.10 +
    1.11 +#include "mozilla/Attributes.h"
    1.12 +#include "celldata.h"
    1.13 +#include "nsITableCellLayout.h"
    1.14 +#include "nscore.h"
    1.15 +#include "nsContainerFrame.h"
    1.16 +#include "nsStyleContext.h"
    1.17 +#include "nsIPercentHeightObserver.h"
    1.18 +#include "nsGkAtoms.h"
    1.19 +#include "nsLayoutUtils.h"
    1.20 +#include "nsTArray.h"
    1.21 +
    1.22 +class nsTableFrame;
    1.23 +
    1.24 +/**
    1.25 + * nsTableCellFrame
    1.26 + * data structure to maintain information about a single table cell's frame
    1.27 + *
    1.28 + * NOTE:  frames are not ref counted.  We expose addref and release here
    1.29 + * so we can change that decsion in the future.  Users of nsITableCellLayout
    1.30 + * should refcount correctly as if this object is being ref counted, though
    1.31 + * no actual support is under the hood.
    1.32 + *
    1.33 + * @author  sclark
    1.34 + */
    1.35 +class nsTableCellFrame : public nsContainerFrame,
    1.36 +                         public nsITableCellLayout,
    1.37 +                         public nsIPercentHeightObserver
    1.38 +{
    1.39 +public:
    1.40 +  NS_DECL_QUERYFRAME_TARGET(nsTableCellFrame)
    1.41 +  NS_DECL_QUERYFRAME
    1.42 +  NS_DECL_FRAMEARENA_HELPERS
    1.43 +
    1.44 +  // default constructor supplied by the compiler
    1.45 +
    1.46 +  nsTableCellFrame(nsStyleContext* aContext);
    1.47 +  ~nsTableCellFrame();
    1.48 +
    1.49 +  virtual void Init(nsIContent*      aContent,
    1.50 +                    nsIFrame*        aParent,
    1.51 +                    nsIFrame*        aPrevInFlow) MOZ_OVERRIDE;
    1.52 +
    1.53 +  virtual void DestroyFrom(nsIFrame* aDestructRoot) MOZ_OVERRIDE;
    1.54 +
    1.55 +#ifdef ACCESSIBILITY
    1.56 +  virtual mozilla::a11y::AccType AccessibleType() MOZ_OVERRIDE;
    1.57 +#endif
    1.58 +
    1.59 +  virtual nsresult  AttributeChanged(int32_t         aNameSpaceID,
    1.60 +                                     nsIAtom*        aAttribute,
    1.61 +                                     int32_t         aModType) MOZ_OVERRIDE;
    1.62 +
    1.63 +  /** @see nsIFrame::DidSetStyleContext */
    1.64 +  virtual void DidSetStyleContext(nsStyleContext* aOldStyleContext) MOZ_OVERRIDE;
    1.65 +
    1.66 +  // table cells contain a block frame which does most of the work, and
    1.67 +  // so these functions should never be called. They assert and return
    1.68 +  // NS_ERROR_NOT_IMPLEMENTED
    1.69 +  virtual nsresult AppendFrames(ChildListID     aListID,
    1.70 +                                nsFrameList&    aFrameList) MOZ_OVERRIDE;
    1.71 +  virtual nsresult InsertFrames(ChildListID     aListID,
    1.72 +                                nsIFrame*       aPrevFrame,
    1.73 +                                nsFrameList&    aFrameList) MOZ_OVERRIDE;
    1.74 +  virtual nsresult RemoveFrame(ChildListID     aListID,
    1.75 +                               nsIFrame*       aOldFrame) MOZ_OVERRIDE;
    1.76 +
    1.77 +  virtual nsIFrame* GetContentInsertionFrame() MOZ_OVERRIDE {
    1.78 +    return GetFirstPrincipalChild()->GetContentInsertionFrame();
    1.79 +  }
    1.80 +
    1.81 +  virtual nsMargin GetUsedMargin() const MOZ_OVERRIDE;
    1.82 +
    1.83 +  virtual void NotifyPercentHeight(const nsHTMLReflowState& aReflowState) MOZ_OVERRIDE;
    1.84 +
    1.85 +  virtual bool NeedsToObserve(const nsHTMLReflowState& aReflowState) MOZ_OVERRIDE;
    1.86 +
    1.87 +  /** instantiate a new instance of nsTableRowFrame.
    1.88 +    * @param aPresShell the pres shell for this frame
    1.89 +    *
    1.90 +    * @return           the frame that was created
    1.91 +    */
    1.92 +  friend nsIFrame* NS_NewTableCellFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
    1.93 +
    1.94 +  virtual void BuildDisplayList(nsDisplayListBuilder*   aBuilder,
    1.95 +                                const nsRect&           aDirtyRect,
    1.96 +                                const nsDisplayListSet& aLists) MOZ_OVERRIDE;
    1.97 +
    1.98 +  void PaintCellBackground(nsRenderingContext& aRenderingContext,
    1.99 +                           const nsRect& aDirtyRect, nsPoint aPt,
   1.100 +                           uint32_t aFlags);
   1.101 +
   1.102 + 
   1.103 +  virtual nsresult ProcessBorders(nsTableFrame* aFrame,
   1.104 +                                  nsDisplayListBuilder* aBuilder,
   1.105 +                                  const nsDisplayListSet& aLists);
   1.106 +
   1.107 +  virtual nscoord GetMinWidth(nsRenderingContext *aRenderingContext) MOZ_OVERRIDE;
   1.108 +  virtual nscoord GetPrefWidth(nsRenderingContext *aRenderingContext) MOZ_OVERRIDE;
   1.109 +  virtual IntrinsicWidthOffsetData
   1.110 +    IntrinsicWidthOffsets(nsRenderingContext* aRenderingContext) MOZ_OVERRIDE;
   1.111 +
   1.112 +  virtual nsresult Reflow(nsPresContext*      aPresContext,
   1.113 +                          nsHTMLReflowMetrics& aDesiredSize,
   1.114 +                          const nsHTMLReflowState& aReflowState,
   1.115 +                          nsReflowStatus&      aStatus) MOZ_OVERRIDE;
   1.116 +
   1.117 +  /**
   1.118 +   * Get the "type" of the frame
   1.119 +   *
   1.120 +   * @see nsLayoutAtoms::tableCellFrame
   1.121 +   */
   1.122 +  virtual nsIAtom* GetType() const MOZ_OVERRIDE;
   1.123 +
   1.124 +#ifdef DEBUG_FRAME_DUMP
   1.125 +  virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE;
   1.126 +#endif
   1.127 +
   1.128 +  void VerticallyAlignChild(nscoord aMaxAscent);
   1.129 +
   1.130 +  /*
   1.131 +   * Get the value of vertical-align adjusted for CSS 2's rules for a
   1.132 +   * table cell, which means the result is always
   1.133 +   * NS_STYLE_VERTICAL_ALIGN_{TOP,MIDDLE,BOTTOM,BASELINE}.
   1.134 +   */
   1.135 +  virtual uint8_t GetVerticalAlign() const;
   1.136 +
   1.137 +  bool HasVerticalAlignBaseline() const {
   1.138 +    return GetVerticalAlign() == NS_STYLE_VERTICAL_ALIGN_BASELINE;
   1.139 +  }
   1.140 +
   1.141 +  bool CellHasVisibleContent(nscoord       height,
   1.142 +                               nsTableFrame* tableFrame,
   1.143 +                               nsIFrame*     kidFrame);
   1.144 +
   1.145 +  /**
   1.146 +   * Get the first-line baseline of the cell relative to its top border
   1.147 +   * edge, as if the cell were vertically aligned to the top of the row.
   1.148 +   */
   1.149 +  nscoord GetCellBaseline() const;
   1.150 +
   1.151 +  /**
   1.152 +   * return the cell's specified row span. this is what was specified in the
   1.153 +   * content model or in the style info, and is always >= 1.
   1.154 +   * to get the effective row span (the actual value that applies), use GetEffectiveRowSpan()
   1.155 +   * @see nsTableFrame::GetEffectiveRowSpan()
   1.156 +   */
   1.157 +  virtual int32_t GetRowSpan();
   1.158 +
   1.159 +  // there is no set row index because row index depends on the cell's parent row only
   1.160 +
   1.161 +  /*---------------- nsITableCellLayout methods ------------------------*/
   1.162 +
   1.163 +  /**
   1.164 +   * return the cell's starting row index (starting at 0 for the first row).
   1.165 +   * for continued cell frames the row index is that of the cell's first-in-flow
   1.166 +   * and the column index (starting at 0 for the first column
   1.167 +   */
   1.168 +  NS_IMETHOD GetCellIndexes(int32_t &aRowIndex, int32_t &aColIndex) MOZ_OVERRIDE;
   1.169 +
   1.170 +  /** return the mapped cell's row index (starting at 0 for the first row) */
   1.171 +  virtual nsresult GetRowIndex(int32_t &aRowIndex) const MOZ_OVERRIDE;
   1.172 +
   1.173 +  /**
   1.174 +   * return the cell's specified col span. this is what was specified in the
   1.175 +   * content model or in the style info, and is always >= 1.
   1.176 +   * to get the effective col span (the actual value that applies), use GetEffectiveColSpan()
   1.177 +   * @see nsTableFrame::GetEffectiveColSpan()
   1.178 +   */
   1.179 +  virtual int32_t GetColSpan();
   1.180 +
   1.181 +  /** return the cell's column index (starting at 0 for the first column) */
   1.182 +  virtual nsresult GetColIndex(int32_t &aColIndex) const MOZ_OVERRIDE;
   1.183 +  void SetColIndex(int32_t aColIndex);
   1.184 +
   1.185 +  /** return the available width given to this frame during its last reflow */
   1.186 +  inline nscoord GetPriorAvailWidth();
   1.187 +
   1.188 +  /** set the available width given to this frame during its last reflow */
   1.189 +  inline void SetPriorAvailWidth(nscoord aPriorAvailWidth);
   1.190 +
   1.191 +  /** return the desired size returned by this frame during its last reflow */
   1.192 +  inline nsSize GetDesiredSize();
   1.193 +
   1.194 +  /** set the desired size returned by this frame during its last reflow */
   1.195 +  inline void SetDesiredSize(const nsHTMLReflowMetrics & aDesiredSize);
   1.196 +
   1.197 +  bool GetContentEmpty();
   1.198 +  void SetContentEmpty(bool aContentEmpty);
   1.199 +
   1.200 +  bool HasPctOverHeight();
   1.201 +  void SetHasPctOverHeight(bool aValue);
   1.202 +
   1.203 +  nsTableCellFrame* GetNextCell() const;
   1.204 +
   1.205 +  virtual nsMargin* GetBorderWidth(nsMargin& aBorder) const;
   1.206 +
   1.207 +  virtual void PaintBackground(nsRenderingContext& aRenderingContext,
   1.208 +                               const nsRect&        aDirtyRect,
   1.209 +                               nsPoint              aPt,
   1.210 +                               uint32_t             aFlags);
   1.211 +
   1.212 +  void DecorateForSelection(nsRenderingContext& aRenderingContext,
   1.213 +                            nsPoint              aPt);
   1.214 +
   1.215 +  virtual bool UpdateOverflow() MOZ_OVERRIDE;
   1.216 +
   1.217 +  virtual bool IsFrameOfType(uint32_t aFlags) const MOZ_OVERRIDE
   1.218 +  {
   1.219 +    return nsContainerFrame::IsFrameOfType(aFlags & ~(nsIFrame::eTablePart));
   1.220 +  }
   1.221 +  
   1.222 +  virtual void InvalidateFrame(uint32_t aDisplayItemKey = 0) MOZ_OVERRIDE;
   1.223 +  virtual void InvalidateFrameWithRect(const nsRect& aRect, uint32_t aDisplayItemKey = 0) MOZ_OVERRIDE;
   1.224 +  virtual void InvalidateFrameForRemoval() MOZ_OVERRIDE { InvalidateFrameSubtree(); }
   1.225 +
   1.226 +protected:
   1.227 +  virtual int GetLogicalSkipSides(const nsHTMLReflowState* aReflowState= nullptr) const MOZ_OVERRIDE;
   1.228 +
   1.229 +  /**
   1.230 +   * GetBorderOverflow says how far the cell's own borders extend
   1.231 +   * outside its own bounds.  In the separated borders model this should
   1.232 +   * just be zero (as it is for most frames), but in the collapsed
   1.233 +   * borders model (for which nsBCTableCellFrame overrides this virtual
   1.234 +   * method), it considers the extents of the collapsed border.
   1.235 +   */
   1.236 +  virtual nsMargin GetBorderOverflow();
   1.237 +
   1.238 +  friend class nsTableRowFrame;
   1.239 +
   1.240 +  uint32_t     mColIndex;             // the starting column for this cell
   1.241 +
   1.242 +  nscoord      mPriorAvailWidth;      // the avail width during the last reflow
   1.243 +  nsSize       mDesiredSize;          // the last desired width & height
   1.244 +};
   1.245 +
   1.246 +inline nscoord nsTableCellFrame::GetPriorAvailWidth()
   1.247 +{ return mPriorAvailWidth;}
   1.248 +
   1.249 +inline void nsTableCellFrame::SetPriorAvailWidth(nscoord aPriorAvailWidth)
   1.250 +{ mPriorAvailWidth = aPriorAvailWidth;}
   1.251 +
   1.252 +inline nsSize nsTableCellFrame::GetDesiredSize()
   1.253 +{ return mDesiredSize; }
   1.254 +
   1.255 +inline void nsTableCellFrame::SetDesiredSize(const nsHTMLReflowMetrics & aDesiredSize)
   1.256 +{
   1.257 +  mDesiredSize.width = aDesiredSize.Width();
   1.258 +  mDesiredSize.height = aDesiredSize.Height();
   1.259 +}
   1.260 +
   1.261 +inline bool nsTableCellFrame::GetContentEmpty()
   1.262 +{
   1.263 +  return (mState & NS_TABLE_CELL_CONTENT_EMPTY) ==
   1.264 +         NS_TABLE_CELL_CONTENT_EMPTY;
   1.265 +}
   1.266 +
   1.267 +inline void nsTableCellFrame::SetContentEmpty(bool aContentEmpty)
   1.268 +{
   1.269 +  if (aContentEmpty) {
   1.270 +    mState |= NS_TABLE_CELL_CONTENT_EMPTY;
   1.271 +  } else {
   1.272 +    mState &= ~NS_TABLE_CELL_CONTENT_EMPTY;
   1.273 +  }
   1.274 +}
   1.275 +
   1.276 +inline bool nsTableCellFrame::HasPctOverHeight()
   1.277 +{
   1.278 +  return (mState & NS_TABLE_CELL_HAS_PCT_OVER_HEIGHT) ==
   1.279 +         NS_TABLE_CELL_HAS_PCT_OVER_HEIGHT;
   1.280 +}
   1.281 +
   1.282 +inline void nsTableCellFrame::SetHasPctOverHeight(bool aValue)
   1.283 +{
   1.284 +  if (aValue) {
   1.285 +    mState |= NS_TABLE_CELL_HAS_PCT_OVER_HEIGHT;
   1.286 +  } else {
   1.287 +    mState &= ~NS_TABLE_CELL_HAS_PCT_OVER_HEIGHT;
   1.288 +  }
   1.289 +}
   1.290 +
   1.291 +// nsBCTableCellFrame
   1.292 +class nsBCTableCellFrame : public nsTableCellFrame
   1.293 +{
   1.294 +public:
   1.295 +  NS_DECL_FRAMEARENA_HELPERS
   1.296 +
   1.297 +  nsBCTableCellFrame(nsStyleContext* aContext);
   1.298 +
   1.299 +  ~nsBCTableCellFrame();
   1.300 +
   1.301 +  virtual nsIAtom* GetType() const MOZ_OVERRIDE;
   1.302 +
   1.303 +  virtual nsMargin GetUsedBorder() const MOZ_OVERRIDE;
   1.304 +  virtual bool GetBorderRadii(nscoord aRadii[8]) const MOZ_OVERRIDE;
   1.305 +
   1.306 +  // Get the *inner half of the border only*, in twips.
   1.307 +  virtual nsMargin* GetBorderWidth(nsMargin& aBorder) const MOZ_OVERRIDE;
   1.308 +
   1.309 +  // Get the *inner half of the border only*, in pixels.
   1.310 +  BCPixelSize GetBorderWidth(mozilla::css::Side aSide) const;
   1.311 +
   1.312 +  // Set the full (both halves) width of the border
   1.313 +  void SetBorderWidth(mozilla::css::Side aSide, BCPixelSize aPixelValue);
   1.314 +
   1.315 +  virtual nsMargin GetBorderOverflow() MOZ_OVERRIDE;
   1.316 +
   1.317 +#ifdef DEBUG_FRAME_DUMP
   1.318 +  virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE;
   1.319 +#endif
   1.320 +
   1.321 +  virtual void PaintBackground(nsRenderingContext& aRenderingContext,
   1.322 +                               const nsRect&        aDirtyRect,
   1.323 +                               nsPoint              aPt,
   1.324 +                               uint32_t             aFlags) MOZ_OVERRIDE;
   1.325 +
   1.326 +private:
   1.327 +
   1.328 +  // These are the entire width of the border (the cell edge contains only
   1.329 +  // the inner half, per the macros in nsTablePainter.h).
   1.330 +  BCPixelSize mTopBorder;
   1.331 +  BCPixelSize mRightBorder;
   1.332 +  BCPixelSize mBottomBorder;
   1.333 +  BCPixelSize mLeftBorder;
   1.334 +};
   1.335 +
   1.336 +#endif

mercurial