layout/tables/nsTableWrapperFrame.h
author Ting-Yu Lin <tlin@mozilla.com>
Thu, 21 Jul 2016 18:36:39 +0800
changeset 348179 ec9c3a2f2c091f2159edd5753a1b17b4b77189ec
parent 348178 d1a449efbe4446e696311b21f7bdfcd709b82a26
child 366352 c9ee55e916c6b7661c294a57759cac1381e4a758
permissions -rw-r--r--
Bug 1277129 Part 7c - Rename various RS variables to RI. r=dbaron This patch is generated by the following script: function rename() { find layout\ -type f\ ! -path "./obj*"\ ! -path "./.git"\ ! -path "./.hg"\ \( -name "*.cpp" -or\ -name "*.h" \)\ -exec sed -i -r "s/$1/$2/g" "{}" \; } rename aChildRS aChildRI rename aContainingBlockRS aContainingBlockRI rename aFrameRS aFrameRI rename aLastRS aLastRI rename aOuterRS aOuterRI rename aRS aRI rename blockHtmlRS blockHtmlRI rename captionRS captionRI rename cellRS cellRI rename childRS childRI rename firstAncestorRS firstAncestorRI rename flexContainerRS flexContainerRI rename gridRS gridRI rename innerRS innerRI rename lastButOneRS lastButOneRI rename LineContainerRS LineContainerRI rename mBlockRS mBlockRI rename parentRS parentRI rename secondAncestorRS secondAncestorRI rename lastRSSize lastRISize rename lastRSPadding lastRIPadding MozReview-Commit-ID: YEgZs3WMow

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef nsTableWrapperFrame_h__
#define nsTableWrapperFrame_h__

#include "mozilla/Attributes.h"
#include "mozilla/Maybe.h"
#include "nscore.h"
#include "nsContainerFrame.h"
#include "nsCellMap.h"
#include "nsTableFrame.h"

/**
 * Primary frame for a table element,
 * the nsTableWrapperFrame contains 0 or one caption frame, and a nsTableFrame
 * pseudo-frame (referred to as the "inner frame').
 */
class nsTableWrapperFrame : public nsContainerFrame
{
public:
  NS_DECL_QUERYFRAME
  NS_DECL_FRAMEARENA_HELPERS

  NS_DECL_QUERYFRAME_TARGET(nsTableWrapperFrame)

  /** instantiate a new instance of nsTableRowFrame.
    * @param aPresShell the pres shell for this frame
    *
    * @return           the frame that was created
    */
  friend nsTableWrapperFrame* NS_NewTableWrapperFrame(nsIPresShell* aPresShell,
                                                      nsStyleContext* aContext);

  // nsIFrame overrides - see there for a description

  virtual void DestroyFrom(nsIFrame* aDestructRoot) override;

  virtual const nsFrameList& GetChildList(ChildListID aListID) const override;
  virtual void GetChildLists(nsTArray<ChildList>* aLists) const override;

  virtual void SetInitialChildList(ChildListID     aListID,
                                   nsFrameList&    aChildList) override;
  virtual void AppendFrames(ChildListID     aListID,
                            nsFrameList&    aFrameList) override;
  virtual void InsertFrames(ChildListID     aListID,
                            nsIFrame*       aPrevFrame,
                            nsFrameList&    aFrameList) override;
  virtual void RemoveFrame(ChildListID     aListID,
                           nsIFrame*       aOldFrame) override;

  virtual nsContainerFrame* GetContentInsertionFrame() override {
    return PrincipalChildList().FirstChild()->GetContentInsertionFrame();
  }

#ifdef ACCESSIBILITY
  virtual mozilla::a11y::AccType AccessibleType() override;
#endif

  virtual void BuildDisplayList(nsDisplayListBuilder*   aBuilder,
                                const nsRect&           aDirtyRect,
                                const nsDisplayListSet& aLists) override;

  void BuildDisplayListForInnerTable(nsDisplayListBuilder*   aBuilder,
                                     const nsRect&           aDirtyRect,
                                     const nsDisplayListSet& aLists);

  virtual nscoord GetLogicalBaseline(mozilla::WritingMode aWritingMode) const override;

  virtual nscoord GetMinISize(nsRenderingContext *aRenderingContext) override;
  virtual nscoord GetPrefISize(nsRenderingContext *aRenderingContext) override;

  virtual mozilla::LogicalSize
  ComputeAutoSize(nsRenderingContext *aRenderingContext,
                  mozilla::WritingMode aWritingMode,
                  const mozilla::LogicalSize& aCBSize,
                  nscoord aAvailableISize,
                  const mozilla::LogicalSize& aMargin,
                  const mozilla::LogicalSize& aBorder,
                  const mozilla::LogicalSize& aPadding,
                  bool aShrinkWrap) override;

  /** process a reflow command for the table.
    * This involves reflowing the caption and the inner table.
    * @see nsIFrame::Reflow */
  virtual void Reflow(nsPresContext*           aPresContext,
                      ReflowOutput&     aDesiredSize,
                      const ReflowInput& aReflowInput,
                      nsReflowStatus&          aStatus) override;

  /**
   * Get the "type" of the frame
   *
   * @see nsGkAtoms::tableWrapperFrame
   */
  virtual nsIAtom* GetType() const override;

#ifdef DEBUG_FRAME_DUMP
  virtual nsresult GetFrameName(nsAString& aResult) const override;
#endif

  virtual nsStyleContext* GetParentStyleContext(nsIFrame** aProviderFrame) const override;

  /**
   * Return the content for the cell at the given row and column.
   */
  nsIContent* GetCellAt(uint32_t aRowIdx, uint32_t aColIdx) const;

  /**
   * Return the number of rows in the table.
   */
  int32_t GetRowCount() const
  {
    return InnerTableFrame()->GetRowCount();
  }

  /**
   * Return the number of columns in the table.
   */
  int32_t GetColCount() const
  {
    return InnerTableFrame()->GetColCount();
  }

  /**
   * Return the index of the cell at the given row and column.
   */
  int32_t GetIndexByRowAndColumn(int32_t aRowIdx, int32_t aColIdx) const
  {
    nsTableCellMap* cellMap = InnerTableFrame()->GetCellMap();
    if (!cellMap)
      return -1;

    return cellMap->GetIndexByRowAndColumn(aRowIdx, aColIdx);
  }

  /**
   * Get the row and column indices for the cell at the given index.
   */
  void GetRowAndColumnByIndex(int32_t aCellIdx, int32_t* aRowIdx,
                              int32_t* aColIdx) const
  {
    *aRowIdx = *aColIdx = 0;
    nsTableCellMap* cellMap = InnerTableFrame()->GetCellMap();
    if (cellMap) {
      cellMap->GetRowAndColumnByIndex(aCellIdx, aRowIdx, aColIdx);
    }
  }

  /**
   * return the frame for the cell at the given row and column.
   */
  nsTableCellFrame* GetCellFrameAt(uint32_t aRowIdx, uint32_t aColIdx) const
  {
    nsTableCellMap* map = InnerTableFrame()->GetCellMap();
    if (!map) {
      return nullptr;
    }

    return map->GetCellInfoAt(aRowIdx, aColIdx);
  }

  /**
   * Return the col span of the cell at the given row and column indices.
   */
  uint32_t GetEffectiveColSpanAt(uint32_t aRowIdx, uint32_t aColIdx) const
  {
    nsTableCellMap* map = InnerTableFrame()->GetCellMap();
    return map->GetEffectiveColSpan(aRowIdx, aColIdx);
  }

  /**
   * Return the effective row span of the cell at the given row and column.
   */
  uint32_t GetEffectiveRowSpanAt(uint32_t aRowIdx, uint32_t aColIdx) const
  {
    nsTableCellMap* map = InnerTableFrame()->GetCellMap();
    return map->GetEffectiveRowSpan(aRowIdx, aColIdx);
  }

protected:


  explicit nsTableWrapperFrame(nsStyleContext* aContext);
  virtual ~nsTableWrapperFrame();

  void InitChildReflowInput(nsPresContext&     aPresContext,
                            ReflowInput& aReflowInput);

  // Get a NS_STYLE_CAPTION_SIDE_* value, or NO_SIDE if no caption is present.
  // (Remember that caption-side values are interpreted logically, despite
  // having "physical" names.)
  uint8_t GetCaptionSide();

  bool HasSideCaption() {
    uint8_t captionSide = GetCaptionSide();
    return captionSide == NS_STYLE_CAPTION_SIDE_LEFT ||
           captionSide == NS_STYLE_CAPTION_SIDE_RIGHT;
  }
  
  uint8_t GetCaptionVerticalAlign();

  void SetDesiredSize(uint8_t                       aCaptionSide,
                      const mozilla::LogicalSize&   aInnerSize,
                      const mozilla::LogicalSize&   aCaptionSize,
                      const mozilla::LogicalMargin& aInnerMargin,
                      const mozilla::LogicalMargin& aCaptionMargin,
                      nscoord&                      aISize,
                      nscoord&                      aBSize,
                      mozilla::WritingMode          aWM);

  nsresult   GetCaptionOrigin(uint32_t         aCaptionSide,
                              const mozilla::LogicalSize&    aContainBlockSize,
                              const mozilla::LogicalSize&    aInnerSize, 
                              const mozilla::LogicalMargin&  aInnerMargin,
                              const mozilla::LogicalSize&    aCaptionSize,
                              mozilla::LogicalMargin&        aCaptionMargin,
                              mozilla::LogicalPoint&         aOrigin,
                              mozilla::WritingMode           aWM);

  nsresult   GetInnerOrigin(uint32_t         aCaptionSide,
                            const mozilla::LogicalSize&    aContainBlockSize,
                            const mozilla::LogicalSize&    aCaptionSize, 
                            const mozilla::LogicalMargin&  aCaptionMargin,
                            const mozilla::LogicalSize&    aInnerSize,
                            mozilla::LogicalMargin&        aInnerMargin,
                            mozilla::LogicalPoint&         aOrigin,
                            mozilla::WritingMode           aWM);
  
  // reflow the child (caption or innertable frame)
  void OuterBeginReflowChild(nsPresContext*                     aPresContext,
                             nsIFrame*                          aChildFrame,
                             const ReflowInput&           aOuterRI,
                             mozilla::Maybe<ReflowInput>& aChildRI,
                             nscoord                            aAvailISize);

  void OuterDoReflowChild(nsPresContext*           aPresContext,
                          nsIFrame*                aChildFrame,
                          const ReflowInput& aChildRI,
                          ReflowOutput&     aMetrics,
                          nsReflowStatus&          aStatus);

  // Set the overflow areas in our reflow metrics
  void UpdateOverflowAreas(ReflowOutput& aMet);

  // Get the margin.
  void GetChildMargin(nsPresContext*           aPresContext,
                      const ReflowInput& aOuterRI,
                      nsIFrame*                aChildFrame,
                      nscoord                  aAvailableWidth,
                      mozilla::LogicalMargin&  aMargin);

  virtual bool IsFrameOfType(uint32_t aFlags) const override
  {
    return nsContainerFrame::IsFrameOfType(aFlags &
                                           (~eCanContainOverflowContainers));
  }

  nsTableFrame* InnerTableFrame() const
  {
    return static_cast<nsTableFrame*>(mFrames.FirstChild());
  }

private:
  nsFrameList   mCaptionFrames;
};

#endif