layout/tables/nsTableOuterFrame.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/layout/tables/nsTableOuterFrame.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,294 @@
     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 nsTableOuterFrame_h__
     1.9 +#define nsTableOuterFrame_h__
    1.10 +
    1.11 +#include "mozilla/Attributes.h"
    1.12 +#include "nscore.h"
    1.13 +#include "nsContainerFrame.h"
    1.14 +#include "nsCellMap.h"
    1.15 +#include "nsBlockFrame.h"
    1.16 +#include "nsTableFrame.h"
    1.17 +
    1.18 +class nsTableCaptionFrame : public nsBlockFrame
    1.19 +{
    1.20 +public:
    1.21 +  NS_DECL_FRAMEARENA_HELPERS
    1.22 +
    1.23 +  // nsISupports
    1.24 +  virtual nsIAtom* GetType() const MOZ_OVERRIDE;
    1.25 +  friend nsIFrame* NS_NewTableCaptionFrame(nsIPresShell* aPresShell, nsStyleContext*  aContext);
    1.26 +
    1.27 +  virtual nsSize ComputeAutoSize(nsRenderingContext *aRenderingContext,
    1.28 +                                 nsSize aCBSize, nscoord aAvailableWidth,
    1.29 +                                 nsSize aMargin, nsSize aBorder,
    1.30 +                                 nsSize aPadding, bool aShrinkWrap) MOZ_OVERRIDE;
    1.31 +
    1.32 +  virtual nsIFrame* GetParentStyleContextFrame() const MOZ_OVERRIDE;
    1.33 +
    1.34 +#ifdef ACCESSIBILITY
    1.35 +  virtual mozilla::a11y::AccType AccessibleType() MOZ_OVERRIDE;
    1.36 +#endif
    1.37 +
    1.38 +#ifdef DEBUG_FRAME_DUMP
    1.39 +  virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE;
    1.40 +#endif
    1.41 +
    1.42 +protected:
    1.43 +  nsTableCaptionFrame(nsStyleContext*  aContext);
    1.44 +  virtual ~nsTableCaptionFrame();
    1.45 +};
    1.46 +
    1.47 +
    1.48 +/* TODO
    1.49 +1. decide if we'll allow subclassing.  If so, decide which methods really need to be virtual.
    1.50 +*/
    1.51 +
    1.52 +/**
    1.53 + * main frame for an nsTable content object, 
    1.54 + * the nsTableOuterFrame contains 0 or one caption frame, and a nsTableFrame
    1.55 + * pseudo-frame (referred to as the "inner frame').
    1.56 + */
    1.57 +class nsTableOuterFrame : public nsContainerFrame
    1.58 +{
    1.59 +public:
    1.60 +  NS_DECL_QUERYFRAME
    1.61 +  NS_DECL_FRAMEARENA_HELPERS
    1.62 +
    1.63 +  NS_DECL_QUERYFRAME_TARGET(nsTableOuterFrame)
    1.64 +
    1.65 +  /** instantiate a new instance of nsTableRowFrame.
    1.66 +    * @param aPresShell the pres shell for this frame
    1.67 +    *
    1.68 +    * @return           the frame that was created
    1.69 +    */
    1.70 +  friend nsIFrame* NS_NewTableOuterFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
    1.71 +  
    1.72 +  // nsIFrame overrides - see there for a description
    1.73 +
    1.74 +  virtual void DestroyFrom(nsIFrame* aDestructRoot) MOZ_OVERRIDE;
    1.75 +
    1.76 +  virtual nsresult SetInitialChildList(ChildListID     aListID,
    1.77 +                                       nsFrameList&    aChildList) MOZ_OVERRIDE;
    1.78 + 
    1.79 +  virtual const nsFrameList& GetChildList(ChildListID aListID) const MOZ_OVERRIDE;
    1.80 +  virtual void GetChildLists(nsTArray<ChildList>* aLists) const MOZ_OVERRIDE;
    1.81 +
    1.82 +  virtual nsresult AppendFrames(ChildListID     aListID,
    1.83 +                                nsFrameList&    aFrameList) MOZ_OVERRIDE;
    1.84 +
    1.85 +  virtual nsresult InsertFrames(ChildListID     aListID,
    1.86 +                                nsIFrame*       aPrevFrame,
    1.87 +                                nsFrameList&    aFrameList) MOZ_OVERRIDE;
    1.88 +
    1.89 +  virtual nsresult RemoveFrame(ChildListID     aListID,
    1.90 +                               nsIFrame*       aOldFrame) MOZ_OVERRIDE;
    1.91 +
    1.92 +  virtual nsIFrame* GetContentInsertionFrame() MOZ_OVERRIDE {
    1.93 +    return GetFirstPrincipalChild()->GetContentInsertionFrame();
    1.94 +  }
    1.95 +
    1.96 +#ifdef ACCESSIBILITY
    1.97 +  virtual mozilla::a11y::AccType AccessibleType() MOZ_OVERRIDE;
    1.98 +#endif
    1.99 +
   1.100 +  virtual void BuildDisplayList(nsDisplayListBuilder*   aBuilder,
   1.101 +                                const nsRect&           aDirtyRect,
   1.102 +                                const nsDisplayListSet& aLists) MOZ_OVERRIDE;
   1.103 +
   1.104 +  void BuildDisplayListForInnerTable(nsDisplayListBuilder*   aBuilder,
   1.105 +                                     const nsRect&           aDirtyRect,
   1.106 +                                     const nsDisplayListSet& aLists);
   1.107 +
   1.108 +  virtual nscoord GetBaseline() const MOZ_OVERRIDE;
   1.109 +
   1.110 +  virtual nscoord GetMinWidth(nsRenderingContext *aRenderingContext) MOZ_OVERRIDE;
   1.111 +  virtual nscoord GetPrefWidth(nsRenderingContext *aRenderingContext) MOZ_OVERRIDE;
   1.112 +  virtual nsSize ComputeAutoSize(nsRenderingContext *aRenderingContext,
   1.113 +                                 nsSize aCBSize, nscoord aAvailableWidth,
   1.114 +                                 nsSize aMargin, nsSize aBorder,
   1.115 +                                 nsSize aPadding, bool aShrinkWrap) MOZ_OVERRIDE;
   1.116 +
   1.117 +  /** process a reflow command for the table.
   1.118 +    * This involves reflowing the caption and the inner table.
   1.119 +    * @see nsIFrame::Reflow */
   1.120 +  virtual nsresult Reflow(nsPresContext*          aPresContext,
   1.121 +                          nsHTMLReflowMetrics&     aDesiredSize,
   1.122 +                          const nsHTMLReflowState& aReflowState,
   1.123 +                          nsReflowStatus&          aStatus) MOZ_OVERRIDE;
   1.124 +
   1.125 +  /**
   1.126 +   * Get the "type" of the frame
   1.127 +   *
   1.128 +   * @see nsGkAtoms::tableOuterFrame
   1.129 +   */
   1.130 +  virtual nsIAtom* GetType() const MOZ_OVERRIDE;
   1.131 +
   1.132 +#ifdef DEBUG_FRAME_DUMP
   1.133 +  virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE;
   1.134 +#endif
   1.135 +
   1.136 +  virtual nsIFrame* GetParentStyleContextFrame() const MOZ_OVERRIDE;
   1.137 +
   1.138 +  /**
   1.139 +   * Return the content for the cell at the given row and column.
   1.140 +   */
   1.141 +  nsIContent* GetCellAt(uint32_t aRowIdx, uint32_t aColIdx) const;
   1.142 +
   1.143 +  /**
   1.144 +   * Return the number of rows in the table.
   1.145 +   */
   1.146 +  int32_t GetRowCount() const
   1.147 +  {
   1.148 +    return InnerTableFrame()->GetRowCount();
   1.149 +  }
   1.150 +
   1.151 +  /**
   1.152 +   * Return the number of columns in the table.
   1.153 +   */
   1.154 +  int32_t GetColCount() const
   1.155 +  {
   1.156 +    return InnerTableFrame()->GetColCount();
   1.157 +  }
   1.158 +
   1.159 +  /**
   1.160 +   * Return the index of the cell at the given row and column.
   1.161 +   */
   1.162 +  int32_t GetIndexByRowAndColumn(int32_t aRowIdx, int32_t aColIdx) const
   1.163 +  {
   1.164 +    nsTableCellMap* cellMap = InnerTableFrame()->GetCellMap();
   1.165 +    if (!cellMap)
   1.166 +      return -1;
   1.167 +
   1.168 +    return cellMap->GetIndexByRowAndColumn(aRowIdx, aColIdx);
   1.169 +  }
   1.170 +
   1.171 +  /**
   1.172 +   * Get the row and column indices for the cell at the given index.
   1.173 +   */
   1.174 +  void GetRowAndColumnByIndex(int32_t aCellIdx, int32_t* aRowIdx,
   1.175 +                              int32_t* aColIdx) const
   1.176 +  {
   1.177 +    *aRowIdx = *aColIdx = 0;
   1.178 +    nsTableCellMap* cellMap = InnerTableFrame()->GetCellMap();
   1.179 +    if (cellMap) {
   1.180 +      cellMap->GetRowAndColumnByIndex(aCellIdx, aRowIdx, aColIdx);
   1.181 +    }
   1.182 +  }
   1.183 +
   1.184 +  /**
   1.185 +   * return the frame for the cell at the given row and column.
   1.186 +   */
   1.187 +  nsTableCellFrame* GetCellFrameAt(uint32_t aRowIdx, uint32_t aColIdx) const
   1.188 +  {
   1.189 +    nsTableCellMap* map = InnerTableFrame()->GetCellMap();
   1.190 +    if (!map) {
   1.191 +      return nullptr;
   1.192 +    }
   1.193 +
   1.194 +    return map->GetCellInfoAt(aRowIdx, aColIdx);
   1.195 +  }
   1.196 +
   1.197 +  /**
   1.198 +   * Return the col span of the cell at the given row and column indices.
   1.199 +   */
   1.200 +  uint32_t GetEffectiveColSpanAt(uint32_t aRowIdx, uint32_t aColIdx) const
   1.201 +  {
   1.202 +    nsTableCellMap* map = InnerTableFrame()->GetCellMap();
   1.203 +    return map->GetEffectiveColSpan(aRowIdx, aColIdx);
   1.204 +  }
   1.205 +
   1.206 +  /**
   1.207 +   * Return the effective row span of the cell at the given row and column.
   1.208 +   */
   1.209 +  uint32_t GetEffectiveRowSpanAt(uint32_t aRowIdx, uint32_t aColIdx) const
   1.210 +  {
   1.211 +    nsTableCellMap* map = InnerTableFrame()->GetCellMap();
   1.212 +    return map->GetEffectiveRowSpan(aRowIdx, aColIdx);
   1.213 +  }
   1.214 +
   1.215 +protected:
   1.216 +
   1.217 +
   1.218 +  nsTableOuterFrame(nsStyleContext* aContext);
   1.219 +  virtual ~nsTableOuterFrame();
   1.220 +
   1.221 +  void InitChildReflowState(nsPresContext&    aPresContext,                     
   1.222 +                            nsHTMLReflowState& aReflowState);
   1.223 +
   1.224 +  uint8_t GetCaptionSide(); // NS_STYLE_CAPTION_SIDE_* or NO_SIDE
   1.225 +
   1.226 +  bool HasSideCaption() {
   1.227 +    uint8_t captionSide = GetCaptionSide();
   1.228 +    return captionSide == NS_STYLE_CAPTION_SIDE_LEFT ||
   1.229 +           captionSide == NS_STYLE_CAPTION_SIDE_RIGHT;
   1.230 +  }
   1.231 +  
   1.232 +  uint8_t GetCaptionVerticalAlign();
   1.233 +
   1.234 +  void SetDesiredSize(uint8_t         aCaptionSide,
   1.235 +                      const nsMargin& aInnerMargin,
   1.236 +                      const nsMargin& aCaptionMargin,
   1.237 +                      nscoord&        aWidth,
   1.238 +                      nscoord&        aHeight);
   1.239 +
   1.240 +  nsresult   GetCaptionOrigin(uint32_t         aCaptionSide,
   1.241 +                              const nsSize&    aContainBlockSize,
   1.242 +                              const nsSize&    aInnerSize, 
   1.243 +                              const nsMargin&  aInnerMargin,
   1.244 +                              const nsSize&    aCaptionSize,
   1.245 +                              nsMargin&        aCaptionMargin,
   1.246 +                              nsPoint&         aOrigin);
   1.247 +
   1.248 +  nsresult   GetInnerOrigin(uint32_t         aCaptionSide,
   1.249 +                            const nsSize&    aContainBlockSize,
   1.250 +                            const nsSize&    aCaptionSize, 
   1.251 +                            const nsMargin&  aCaptionMargin,
   1.252 +                            const nsSize&    aInnerSize,
   1.253 +                            nsMargin&        aInnerMargin,
   1.254 +                            nsPoint&         aOrigin);
   1.255 +  
   1.256 +  // reflow the child (caption or innertable frame)
   1.257 +  void OuterBeginReflowChild(nsPresContext*           aPresContext,
   1.258 +                             nsIFrame*                aChildFrame,
   1.259 +                             const nsHTMLReflowState& aOuterRS,
   1.260 +                             void*                    aChildRSSpace,
   1.261 +                             nscoord                  aAvailWidth);
   1.262 +
   1.263 +  nsresult OuterDoReflowChild(nsPresContext*           aPresContext,
   1.264 +                              nsIFrame*                aChildFrame,
   1.265 +                              const nsHTMLReflowState& aChildRS,
   1.266 +                              nsHTMLReflowMetrics&     aMetrics,
   1.267 +                              nsReflowStatus&          aStatus);
   1.268 +
   1.269 +  // Set the reflow metrics
   1.270 +  void UpdateReflowMetrics(uint8_t              aCaptionSide,
   1.271 +                           nsHTMLReflowMetrics& aMet,
   1.272 +                           const nsMargin&      aInnerMargin,
   1.273 +                           const nsMargin&      aCaptionMargin);
   1.274 +
   1.275 +  // Get the margin.  aMarginNoAuto is aMargin, but with auto 
   1.276 +  // margins set to 0
   1.277 +  void GetChildMargin(nsPresContext*           aPresContext,
   1.278 +                      const nsHTMLReflowState& aOuterRS,
   1.279 +                      nsIFrame*                aChildFrame,
   1.280 +                      nscoord                  aAvailableWidth,
   1.281 +                      nsMargin&                aMargin);
   1.282 +
   1.283 +  virtual bool IsFrameOfType(uint32_t aFlags) const MOZ_OVERRIDE
   1.284 +  {
   1.285 +    return nsContainerFrame::IsFrameOfType(aFlags &
   1.286 +                                           (~eCanContainOverflowContainers));
   1.287 +  }
   1.288 +
   1.289 +  nsTableFrame* InnerTableFrame() const {
   1.290 +    return static_cast<nsTableFrame*>(mFrames.FirstChild());
   1.291 +  }
   1.292 +  
   1.293 +private:
   1.294 +  nsFrameList   mCaptionFrames;
   1.295 +};
   1.296 +
   1.297 +#endif

mercurial