layout/generic/nsFlexContainerFrame.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/layout/generic/nsFlexContainerFrame.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,155 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* vim: set ts=2 et sw=2 tw=80: */
     1.6 +
     1.7 +/* This Source Code is subject to the terms of the Mozilla Public License
     1.8 + * version 2.0 (the "License"). You can obtain a copy of the License at
     1.9 + * http://mozilla.org/MPL/2.0/. */
    1.10 +
    1.11 +/* rendering object for CSS "display: flex" */
    1.12 +
    1.13 +#ifndef nsFlexContainerFrame_h___
    1.14 +#define nsFlexContainerFrame_h___
    1.15 +
    1.16 +#include "nsContainerFrame.h"
    1.17 +
    1.18 +namespace mozilla {
    1.19 +template <class T> class LinkedList;
    1.20 +}
    1.21 +
    1.22 +nsIFrame* NS_NewFlexContainerFrame(nsIPresShell* aPresShell,
    1.23 +                                   nsStyleContext* aContext);
    1.24 +
    1.25 +typedef nsContainerFrame nsFlexContainerFrameSuper;
    1.26 +
    1.27 +class nsFlexContainerFrame : public nsFlexContainerFrameSuper {
    1.28 +public:
    1.29 +  NS_DECL_FRAMEARENA_HELPERS
    1.30 +  NS_DECL_QUERYFRAME_TARGET(nsFlexContainerFrame)
    1.31 +  NS_DECL_QUERYFRAME
    1.32 +
    1.33 +  // Factory method:
    1.34 +  friend nsIFrame* NS_NewFlexContainerFrame(nsIPresShell* aPresShell,
    1.35 +                                            nsStyleContext* aContext);
    1.36 +
    1.37 +  // Forward-decls of helper classes
    1.38 +  class FlexItem;
    1.39 +  class FlexLine;
    1.40 +  class FlexboxAxisTracker;
    1.41 +  class StrutInfo;
    1.42 +
    1.43 +  // nsIFrame overrides
    1.44 +  virtual void BuildDisplayList(nsDisplayListBuilder*   aBuilder,
    1.45 +                                const nsRect&           aDirtyRect,
    1.46 +                                const nsDisplayListSet& aLists) MOZ_OVERRIDE;
    1.47 +
    1.48 +  virtual nsresult Reflow(nsPresContext*           aPresContext,
    1.49 +                          nsHTMLReflowMetrics&     aDesiredSize,
    1.50 +                          const nsHTMLReflowState& aReflowState,
    1.51 +                          nsReflowStatus&          aStatus) MOZ_OVERRIDE;
    1.52 +
    1.53 +  virtual nscoord
    1.54 +    GetMinWidth(nsRenderingContext* aRenderingContext) MOZ_OVERRIDE;
    1.55 +  virtual nscoord
    1.56 +    GetPrefWidth(nsRenderingContext* aRenderingContext) MOZ_OVERRIDE;
    1.57 +
    1.58 +  virtual nsIAtom* GetType() const MOZ_OVERRIDE;
    1.59 +#ifdef DEBUG_FRAME_DUMP
    1.60 +  virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE;
    1.61 +#endif
    1.62 +  // Flexbox-specific public methods
    1.63 +  bool IsHorizontal();
    1.64 +
    1.65 +protected:
    1.66 +  // Protected constructor & destructor
    1.67 +  nsFlexContainerFrame(nsStyleContext* aContext) :
    1.68 +    nsFlexContainerFrameSuper(aContext)
    1.69 +  {}
    1.70 +  virtual ~nsFlexContainerFrame();
    1.71 +
    1.72 +  /*
    1.73 +   * This method does the bulk of the flex layout, implementing the algorithm
    1.74 +   * described at:
    1.75 +   *   http://dev.w3.org/csswg/css-flexbox/#layout-algorithm
    1.76 +   * (with a few initialization pieces happening in the caller, Reflow().
    1.77 +   *
    1.78 +   * Since this is a helper for Reflow(), this takes all the same parameters
    1.79 +   * as Reflow(), plus a few more parameters that Reflow() sets up for us.
    1.80 +   *
    1.81 +   * (The logic behind the division of work between Reflow and DoFlexLayout is
    1.82 +   * as follows: DoFlexLayout() begins at the step that we have to jump back
    1.83 +   * to, if we find any visibility:collapse children, and Reflow() does
    1.84 +   * everything before that point.)
    1.85 +   */
    1.86 +  nsresult DoFlexLayout(nsPresContext*           aPresContext,
    1.87 +                        nsHTMLReflowMetrics&     aDesiredSize,
    1.88 +                        const nsHTMLReflowState& aReflowState,
    1.89 +                        nsReflowStatus&          aStatus,
    1.90 +                        nscoord aContentBoxMainSize,
    1.91 +                        nscoord aAvailableHeightForContent,
    1.92 +                        nsTArray<StrutInfo>& aStruts,
    1.93 +                        const FlexboxAxisTracker& aAxisTracker);
    1.94 +
    1.95 +  /**
    1.96 +   * Checks whether our child-frame list "mFrames" is sorted, using the given
    1.97 +   * IsLessThanOrEqual function, and sorts it if it's not already sorted.
    1.98 +   *
    1.99 +   * XXXdholbert Once we support pagination, we need to make this function
   1.100 +   * check our continuations as well (or wrap it in a function that does).
   1.101 +   *
   1.102 +   * @return true if we had to sort mFrames, false if it was already sorted.
   1.103 +   */
   1.104 +  template<bool IsLessThanOrEqual(nsIFrame*, nsIFrame*)>
   1.105 +  bool SortChildrenIfNeeded();
   1.106 +
   1.107 +  // Protected flex-container-specific methods / member-vars
   1.108 +#ifdef DEBUG
   1.109 +  void SanityCheckAnonymousFlexItems() const;
   1.110 +#endif // DEBUG
   1.111 +
   1.112 +  // Returns a new FlexItem for the given child frame, allocated on the heap.
   1.113 +  // Caller is responsible for managing the FlexItem's lifetime.
   1.114 +  FlexItem* GenerateFlexItemForChild(nsPresContext* aPresContext,
   1.115 +                                     nsIFrame* aChildFrame,
   1.116 +                                     const nsHTMLReflowState& aParentReflowState,
   1.117 +                                     const FlexboxAxisTracker& aAxisTracker);
   1.118 +
   1.119 +  // Returns nsresult because we might have to reflow aFlexItem.Frame() (to
   1.120 +  // get its vertical intrinsic size in a vertical flexbox), and if that
   1.121 +  // reflow fails (returns a failure nsresult), we want to bail out.
   1.122 +  nsresult ResolveFlexItemMaxContentSizing(nsPresContext* aPresContext,
   1.123 +                                           FlexItem& aFlexItem,
   1.124 +                                           const nsHTMLReflowState& aParentReflowState,
   1.125 +                                           const FlexboxAxisTracker& aAxisTracker);
   1.126 +
   1.127 +  // Creates FlexItems for all of our child frames, arranged in a list of
   1.128 +  // FlexLines.  These are returned by reference in |aLines|. Our actual
   1.129 +  // return value has to be |nsresult|, in case we have to reflow a child
   1.130 +  // to establish its flex base size and that reflow fails.
   1.131 +  nsresult GenerateFlexLines(nsPresContext* aPresContext,
   1.132 +                             const nsHTMLReflowState& aReflowState,
   1.133 +                             nscoord aContentBoxMainSize,
   1.134 +                             nscoord aAvailableHeightForContent,
   1.135 +                             const nsTArray<StrutInfo>& aStruts,
   1.136 +                             const FlexboxAxisTracker& aAxisTracker,
   1.137 +                             mozilla::LinkedList<FlexLine>& aLines);
   1.138 +
   1.139 +  nscoord GetMainSizeFromReflowState(const nsHTMLReflowState& aReflowState,
   1.140 +                                     const FlexboxAxisTracker& aAxisTracker);
   1.141 +
   1.142 +  nscoord ComputeCrossSize(const nsHTMLReflowState& aReflowState,
   1.143 +                           const FlexboxAxisTracker& aAxisTracker,
   1.144 +                           nscoord aSumLineCrossSizes,
   1.145 +                           nscoord aAvailableHeightForContent,
   1.146 +                           bool* aIsDefinite,
   1.147 +                           nsReflowStatus& aStatus);
   1.148 +
   1.149 +  nsresult SizeItemInCrossAxis(nsPresContext* aPresContext,
   1.150 +                               const FlexboxAxisTracker& aAxisTracker,
   1.151 +                               nsHTMLReflowState& aChildReflowState,
   1.152 +                               FlexItem& aItem);
   1.153 +
   1.154 +  bool mChildrenHaveBeenReordered; // Have we ever had to reorder our kids
   1.155 +                                   // to satisfy their 'order' values?
   1.156 +};
   1.157 +
   1.158 +#endif /* nsFlexContainerFrame_h___ */

mercurial