2 * Copyright (C) 2011 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #ifndef RenderFlexibleBox_h
32 #define RenderFlexibleBox_h
34 #include "OrderIterator.h"
35 #include "RenderBlock.h"
39 class RenderFlexibleBox : public RenderBlock {
41 RenderFlexibleBox(Element&, RenderStyle&&);
42 RenderFlexibleBox(Document&, RenderStyle&&);
43 virtual ~RenderFlexibleBox();
45 const char* renderName() const override;
47 bool avoidsFloats() const final { return true; }
48 bool canDropAnonymousBlockChild() const final { return false; }
49 void layoutBlock(bool relayoutChildren, LayoutUnit pageLogicalHeight = 0) override;
51 int baselinePosition(FontBaseline, bool firstLine, LineDirectionMode, LinePositionMode = PositionOnContainingLine) const override;
52 Optional<int> firstLineBaseline() const override;
53 Optional<int> inlineBlockBaseline(LineDirectionMode) const override;
55 void paintChildren(PaintInfo& forSelf, const LayoutPoint&, PaintInfo& forChild, bool usePrintRect) override;
57 bool isHorizontalFlow() const;
59 bool isTopLayoutOverflowAllowed() const override;
60 bool isLeftLayoutOverflowAllowed() const override;
63 void computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, LayoutUnit& maxLogicalWidth) const override;
64 void computePreferredLogicalWidths() override;
66 void styleDidChange(StyleDifference, const RenderStyle* oldStyle) override;
74 enum PositionedLayoutMode {
79 typedef HashMap<const RenderBox*, LayoutUnit> InflexibleFlexItemSize;
80 typedef Vector<RenderBox*> OrderedFlexItemList;
85 // Use an inline capacity of 8, since flexbox containers usually have less than 8 children.
86 typedef Vector<LayoutRect, 8> ChildFrameRects;
88 bool isFlexibleBox() const final { return true; }
89 bool hasOrthogonalFlow(const RenderBox& child) const;
90 bool isColumnFlow() const;
91 bool isLeftToRightFlow() const;
92 bool isMultiline() const;
93 Length flexBasisForChild(RenderBox& child) const;
94 void setCrossAxisExtent(LayoutUnit);
95 LayoutUnit crossAxisExtentForChild(RenderBox& child) const;
96 LayoutUnit mainAxisExtentForChild(RenderBox& child) const;
97 LayoutUnit crossAxisExtent() const;
98 LayoutUnit mainAxisExtent() const;
99 LayoutUnit crossAxisContentExtent() const;
100 LayoutUnit mainAxisContentExtent(LayoutUnit contentLogicalHeight);
101 Optional<LayoutUnit> computeMainAxisExtentForChild(const RenderBox& child, SizeType, const Length& size);
102 WritingMode transformedWritingMode() const;
103 LayoutUnit flowAwareBorderStart() const;
104 LayoutUnit flowAwareBorderEnd() const;
105 LayoutUnit flowAwareBorderBefore() const;
106 LayoutUnit flowAwareBorderAfter() const;
107 LayoutUnit flowAwarePaddingStart() const;
108 LayoutUnit flowAwarePaddingEnd() const;
109 LayoutUnit flowAwarePaddingBefore() const;
110 LayoutUnit flowAwarePaddingAfter() const;
111 LayoutUnit flowAwareMarginStartForChild(RenderBox& child) const;
112 LayoutUnit flowAwareMarginEndForChild(RenderBox& child) const;
113 LayoutUnit flowAwareMarginBeforeForChild(RenderBox& child) const;
114 LayoutUnit flowAwareMarginAfterForChild(RenderBox& child) const;
115 LayoutUnit crossAxisMarginExtentForChild(RenderBox& child) const;
116 LayoutUnit crossAxisScrollbarExtent() const;
117 LayoutPoint flowAwareLocationForChild(RenderBox& child) const;
118 // FIXME: Supporting layout deltas.
119 void setFlowAwareLocationForChild(RenderBox& child, const LayoutPoint&);
120 void adjustAlignmentForChild(RenderBox& child, LayoutUnit);
121 ItemPosition alignmentForChild(RenderBox& child) const;
122 LayoutUnit mainAxisBorderAndPaddingExtentForChild(RenderBox& child) const;
123 LayoutUnit mainAxisScrollbarExtentForChild(RenderBox& child) const;
124 LayoutUnit preferredMainAxisContentExtentForChild(RenderBox& child, bool hasInfiniteLineLength);
125 EOverflow mainAxisOverflowForChild(const RenderBox&) const;
127 void layoutFlexItems(bool relayoutChildren, Vector<LineContext>&);
128 LayoutUnit autoMarginOffsetInMainAxis(const OrderedFlexItemList&, LayoutUnit& availableFreeSpace);
129 void updateAutoMarginsInMainAxis(RenderBox& child, LayoutUnit autoMarginOffset);
130 bool hasAutoMarginsInCrossAxis(RenderBox& child) const;
131 bool updateAutoMarginsInCrossAxis(RenderBox& child, LayoutUnit availableAlignmentSpace);
132 void repositionLogicalHeightDependentFlexItems(Vector<LineContext>&);
133 LayoutUnit clientLogicalBottomAfterRepositioning();
134 void appendChildFrameRects(ChildFrameRects&);
135 void repaintChildrenDuringLayoutIfMoved(const ChildFrameRects&);
137 LayoutUnit availableAlignmentSpaceForChild(LayoutUnit lineCrossAxisExtent, RenderBox&);
138 LayoutUnit marginBoxAscentForChild(RenderBox&);
140 LayoutUnit computeChildMarginValue(const Length& margin);
141 void prepareOrderIteratorAndMargins();
142 LayoutUnit adjustChildSizeForMinAndMax(const RenderBox&, LayoutUnit childSize);
143 LayoutUnit adjustChildSizeForAspectRatioCrossAxisMinAndMax(const RenderBox&, LayoutUnit childSize);
144 bool computeNextFlexLine(OrderedFlexItemList& orderedChildren, LayoutUnit& preferredMainAxisExtent, double& totalFlexGrow, double& totalWeightedFlexShrink, LayoutUnit& minMaxAppliedMainAxisExtent, bool& hasInfiniteLineLength);
146 bool resolveFlexibleLengths(FlexSign, const OrderedFlexItemList&, LayoutUnit& availableFreeSpace, double& totalFlexGrow, double& totalWeightedFlexShrink, InflexibleFlexItemSize&, Vector<LayoutUnit>& childSizes, bool hasInfiniteLineLength);
147 void freezeViolations(const Vector<Violation>&, LayoutUnit& availableFreeSpace, double& totalFlexGrow, double& totalWeightedFlexShrink, InflexibleFlexItemSize&, bool hasInfiniteLineLength);
149 void resetAutoMarginsAndLogicalTopInCrossAxis(RenderBox&);
150 bool needToStretchChild(RenderBox&);
151 void setLogicalOverrideSize(RenderBox& child, LayoutUnit childPreferredSize);
152 void prepareChildForPositionedLayout(RenderBox& child, LayoutUnit mainAxisOffset, LayoutUnit crossAxisOffset, PositionedLayoutMode);
153 size_t numberOfInFlowPositionedChildren(const OrderedFlexItemList&) const;
154 void layoutAndPlaceChildren(LayoutUnit& crossAxisOffset, const OrderedFlexItemList&, const Vector<LayoutUnit>& childSizes, LayoutUnit availableFreeSpace, bool relayoutChildren, Vector<LineContext>&);
155 void layoutColumnReverse(const OrderedFlexItemList&, LayoutUnit crossAxisOffset, LayoutUnit availableFreeSpace);
156 void alignFlexLines(Vector<LineContext>&);
157 void alignChildren(const Vector<LineContext>&);
158 void applyStretchAlignmentToChild(RenderBox&, LayoutUnit lineCrossAxisExtent);
159 void flipForRightToLeftColumn();
160 void flipForWrapReverse(const Vector<LineContext>&, LayoutUnit crossAxisStartEdge);
162 bool mainAxisLengthIsDefinite(const RenderBox&, const Length&) const;
163 bool crossAxisLengthIsDefinite(const RenderBox&, const Length&) const;
164 bool useChildAspectRatio(const RenderBox&) const;
165 Optional<LayoutUnit> computeMainSizeFromAspectRatioUsing(const RenderBox& child, Length crossSizeLength) const;
167 virtual bool isFlexibleBoxImpl() const { return false; };
169 mutable OrderIterator m_orderIterator;
170 int m_numberOfInFlowChildrenOnFirstLine;
173 } // namespace WebCore
175 SPECIALIZE_TYPE_TRAITS_RENDER_OBJECT(RenderFlexibleBox, isFlexibleBox())
177 #endif // RenderFlexibleBox_h