layout/tables/nsTableColGroupFrame.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/layout/tables/nsTableColGroupFrame.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,254 @@
     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 nsTableColGroupFrame_h__
     1.9 +#define nsTableColGroupFrame_h__
    1.10 +
    1.11 +#include "mozilla/Attributes.h"
    1.12 +#include "nscore.h"
    1.13 +#include "nsContainerFrame.h"
    1.14 +#include "nsTableColFrame.h"
    1.15 +
    1.16 +class nsTableFrame;
    1.17 +class nsTableColFrame;
    1.18 +
    1.19 +enum nsTableColGroupType {
    1.20 +  eColGroupContent            = 0, // there is real col group content associated   
    1.21 +  eColGroupAnonymousCol       = 1, // the result of a col
    1.22 +  eColGroupAnonymousCell      = 2  // the result of a cell alone
    1.23 +};
    1.24 +
    1.25 +/**
    1.26 + * nsTableColGroupFrame
    1.27 + * data structure to maintain information about a single table cell's frame
    1.28 + *
    1.29 + * @author  sclark
    1.30 + */
    1.31 +class nsTableColGroupFrame : public nsContainerFrame
    1.32 +{
    1.33 +public:
    1.34 +  NS_DECL_FRAMEARENA_HELPERS
    1.35 +
    1.36 +  // default constructor supplied by the compiler
    1.37 +
    1.38 +  /** instantiate a new instance of nsTableRowFrame.
    1.39 +    * @param aPresShell the pres shell for this frame
    1.40 +    *
    1.41 +    * @return           the frame that was created
    1.42 +    */
    1.43 +  friend nsIFrame* NS_NewTableColGroupFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
    1.44 +
    1.45 +  /** Initialize the colgroup frame with a set of children.
    1.46 +    * @see nsIFrame::SetInitialChildList
    1.47 +    */
    1.48 +  virtual nsresult SetInitialChildList(ChildListID     aListID,
    1.49 +                                       nsFrameList&    aChildList) MOZ_OVERRIDE;
    1.50 +
    1.51 +  /**
    1.52 +   * ColGroups never paint anything, nor receive events.
    1.53 +   */
    1.54 +  virtual void BuildDisplayList(nsDisplayListBuilder*   aBuilder,
    1.55 +                                const nsRect&           aDirtyRect,
    1.56 +                                const nsDisplayListSet& aLists) MOZ_OVERRIDE {}
    1.57 +
    1.58 +  /** A colgroup can be caused by three things:
    1.59 +    * 1)	An element with table-column-group display
    1.60 +    * 2)	An element with a table-column display without a
    1.61 +	   *    table-column-group parent
    1.62 +    * 3)	Cells that are not in a column (and hence get an anonymous
    1.63 +	   *    column and colgroup).
    1.64 +    * @return colgroup type
    1.65 +    */
    1.66 +  nsTableColGroupType GetColType() const;
    1.67 +
    1.68 +  /** Set the colgroup type based on the creation cause
    1.69 +    * @param aType - the reason why this colgroup is needed
    1.70 +    */
    1.71 +  void SetColType(nsTableColGroupType aType);
    1.72 +  
    1.73 +  /** Real in this context are colgroups that come from an element
    1.74 +    * with table-column-group display or wrap around columns that
    1.75 +    * come from an element with table-column display. Colgroups
    1.76 +    * that are the result of wrapping cells in an anonymous
    1.77 +    * column and colgroup are not considered real here.
    1.78 +    * @param aTableFrame - the table parent of the colgroups
    1.79 +    * @return the last real colgroup
    1.80 +    */
    1.81 +  static nsTableColGroupFrame* GetLastRealColGroup(nsTableFrame* aTableFrame);
    1.82 +
    1.83 +  /** @see nsIFrame::DidSetStyleContext */
    1.84 +  virtual void DidSetStyleContext(nsStyleContext* aOldStyleContext) MOZ_OVERRIDE;
    1.85 +
    1.86 +  /** @see nsIFrame::AppendFrames, InsertFrames, RemoveFrame
    1.87 +    */
    1.88 +  virtual nsresult AppendFrames(ChildListID     aListID,
    1.89 +                                nsFrameList&    aFrameList) MOZ_OVERRIDE;
    1.90 +  virtual nsresult InsertFrames(ChildListID     aListID,
    1.91 +                                nsIFrame*       aPrevFrame,
    1.92 +                                nsFrameList&    aFrameList) MOZ_OVERRIDE;
    1.93 +  virtual nsresult RemoveFrame(ChildListID     aListID,
    1.94 +                               nsIFrame*       aOldFrame) MOZ_OVERRIDE;
    1.95 +
    1.96 +  /** remove the column aChild from the column group, if requested renumber
    1.97 +    * the subsequent columns in this column group and all following column
    1.98 +    * groups. see also ResetColIndices for this
    1.99 +    * @param aChild       - the column frame that needs to be removed
   1.100 +    * @param aResetSubsequentColIndices - if true the columns that follow
   1.101 +    *                                     after aChild will be reenumerated
   1.102 +    */
   1.103 +  void RemoveChild(nsTableColFrame& aChild,
   1.104 +                   bool             aResetSubsequentColIndices);
   1.105 +
   1.106 +  /** reflow of a column group is a trivial matter of reflowing
   1.107 +    * the col group's children (columns), and setting this frame
   1.108 +    * to 0-size.  Since tables are row-centric, column group frames
   1.109 +    * don't play directly in the rendering game.  They do however
   1.110 +    * maintain important state that effects table and cell layout.
   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 nsGkAtoms::tableColGroupFrame
   1.121 +   */
   1.122 +  virtual nsIAtom* GetType() const MOZ_OVERRIDE;
   1.123 +
   1.124 +  /** Add column frames to the table storages: colframe cache and cellmap
   1.125 +    * this doesn't change the mFrames of the colgroup frame.
   1.126 +    * @param aFirstColIndex - the index at which aFirstFrame should be inserted
   1.127 +    *                         into the colframe cache.
   1.128 +    * @param aResetSubsequentColIndices - the indices of the col frames
   1.129 +    *                                     after the insertion might need
   1.130 +    *                                     an update
   1.131 +    * @param aCols - an iterator that can be used to iterate over the col
   1.132 +    *                frames to be added.  Once this is done, the frames on the
   1.133 +    *                sbling chain of its .get() at that point will still need
   1.134 +    *                their col indices updated.
   1.135 +    * @result            - if there is no table frame or the table frame is not
   1.136 +    *                      the first in flow it will return an error
   1.137 +    */
   1.138 +  nsresult AddColsToTable(int32_t                   aFirstColIndex,
   1.139 +                          bool                      aResetSubsequentColIndices,
   1.140 +                          const nsFrameList::Slice& aCols);
   1.141 +
   1.142 +#ifdef DEBUG_FRAME_DUMP
   1.143 +  virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE;
   1.144 +  void Dump(int32_t aIndent);
   1.145 +#endif
   1.146 +
   1.147 +  /** returns the number of columns represented by this group.
   1.148 +    * if there are col children, count them (taking into account the span of each)
   1.149 +    * else, check my own span attribute.
   1.150 +    */
   1.151 +  virtual int32_t GetColCount() const;
   1.152 +
   1.153 +  /** first column on the child list */
   1.154 +  nsTableColFrame * GetFirstColumn();
   1.155 +  /** next sibling to aChildFrame that is a column frame, first column frame
   1.156 +    * in the column group if aChildFrame is null
   1.157 +    */
   1.158 +  nsTableColFrame * GetNextColumn(nsIFrame *aChildFrame);
   1.159 +
   1.160 +  /** @return - the position of the first column in this colgroup in the table
   1.161 +    * colframe cache.
   1.162 +    */
   1.163 +  int32_t GetStartColumnIndex();
   1.164 +  
   1.165 +  /** set the position of the first column in this colgroup in the table
   1.166 +    * colframe cache.
   1.167 +    */
   1.168 +  void SetStartColumnIndex(int32_t aIndex);
   1.169 +
   1.170 +  /** helper method to get the span attribute for this colgroup */
   1.171 +  int32_t GetSpan();
   1.172 +
   1.173 +  /** provide access to the mFrames list
   1.174 +    */
   1.175 +  nsFrameList& GetWritableChildList();
   1.176 +
   1.177 +  /** set the column index for all frames starting at aStartColFrame, it
   1.178 +    * will also reset the column indices in all subsequent colgroups
   1.179 +    * @param aFirstColGroup - start the reset operation inside this colgroup
   1.180 +    * @param aFirstColIndex - first column that is reset should get this index
   1.181 +    * @param aStartColFrame - if specified the reset starts with this column
   1.182 +    *                         inside the colgroup; if not specified, the reset
   1.183 +    *                         starts with the first column
   1.184 +    */
   1.185 +  static void ResetColIndices(nsIFrame*       aFirstColGroup,
   1.186 +                              int32_t         aFirstColIndex,
   1.187 +                              nsIFrame*       aStartColFrame = nullptr);
   1.188 +
   1.189 +  /**
   1.190 +   * Gets inner border widths before collapsing with cell borders
   1.191 +   * Caller must get left border from previous column
   1.192 +   * GetContinuousBCBorderWidth will not overwrite aBorder.left
   1.193 +   * see nsTablePainter about continuous borders
   1.194 +   */
   1.195 +  void GetContinuousBCBorderWidth(nsMargin& aBorder);
   1.196 +  /**
   1.197 +   * Set full border widths before collapsing with cell borders
   1.198 +   * @param aForSide - side to set; only accepts top and bottom
   1.199 +   */
   1.200 +  void SetContinuousBCBorderWidth(uint8_t     aForSide,
   1.201 +                                  BCPixelSize aPixelValue);
   1.202 +
   1.203 +  virtual bool IsFrameOfType(uint32_t aFlags) const MOZ_OVERRIDE
   1.204 +  {
   1.205 +    return nsContainerFrame::IsFrameOfType(aFlags & ~(nsIFrame::eTablePart));
   1.206 +  }
   1.207 +  
   1.208 +  virtual void InvalidateFrame(uint32_t aDisplayItemKey = 0) MOZ_OVERRIDE;
   1.209 +  virtual void InvalidateFrameWithRect(const nsRect& aRect, uint32_t aDisplayItemKey = 0) MOZ_OVERRIDE;
   1.210 +  virtual void InvalidateFrameForRemoval() MOZ_OVERRIDE { InvalidateFrameSubtree(); }
   1.211 +
   1.212 +protected:
   1.213 +  nsTableColGroupFrame(nsStyleContext* aContext);
   1.214 +
   1.215 +  void InsertColsReflow(int32_t                   aColIndex,
   1.216 +                        const nsFrameList::Slice& aCols);
   1.217 +
   1.218 +  virtual int GetLogicalSkipSides(const nsHTMLReflowState* aReflowState = nullptr) const MOZ_OVERRIDE;
   1.219 +
   1.220 +  // data members
   1.221 +  int32_t mColCount;
   1.222 +  // the starting column index this col group represents. Must be >= 0. 
   1.223 +  int32_t mStartColIndex;
   1.224 +
   1.225 +  // border width in pixels
   1.226 +  BCPixelSize mTopContBorderWidth;
   1.227 +  BCPixelSize mBottomContBorderWidth;
   1.228 +};
   1.229 +
   1.230 +inline nsTableColGroupFrame::nsTableColGroupFrame(nsStyleContext *aContext)
   1.231 +: nsContainerFrame(aContext), mColCount(0), mStartColIndex(0)
   1.232 +{ 
   1.233 +  SetColType(eColGroupContent);
   1.234 +}
   1.235 +  
   1.236 +inline int32_t nsTableColGroupFrame::GetStartColumnIndex()
   1.237 +{  
   1.238 +  return mStartColIndex;
   1.239 +}
   1.240 +
   1.241 +inline void nsTableColGroupFrame::SetStartColumnIndex (int32_t aIndex)
   1.242 +{
   1.243 +  mStartColIndex = aIndex;
   1.244 +}
   1.245 +
   1.246 +inline int32_t nsTableColGroupFrame::GetColCount() const
   1.247 +{  
   1.248 +  return mColCount;
   1.249 +}
   1.250 +
   1.251 +inline nsFrameList& nsTableColGroupFrame::GetWritableChildList()
   1.252 +{  
   1.253 +  return mFrames;
   1.254 +}
   1.255 +
   1.256 +#endif
   1.257 +

mercurial