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&, PassRef<RenderStyle>);
42 RenderFlexibleBox(Document&, PassRef<RenderStyle>);
43 virtual ~RenderFlexibleBox();
45 virtual const char* renderName() const override;
47 virtual bool isFlexibleBox() const override final { return true; }
48 virtual bool avoidsFloats() const override final { return true; }
49 virtual bool canCollapseAnonymousBlockChild() const override final { return false; }
50 virtual void layoutBlock(bool relayoutChildren, LayoutUnit pageLogicalHeight = 0) override final;
52 virtual int baselinePosition(FontBaseline, bool firstLine, LineDirectionMode, LinePositionMode = PositionOnContainingLine) const override;
53 virtual int firstLineBaseline() const override;
54 virtual int inlineBlockBaseline(LineDirectionMode) const override;
56 virtual void paintChildren(PaintInfo& forSelf, const LayoutPoint&, PaintInfo& forChild, bool usePrintRect) override;
58 bool isHorizontalFlow() const;
60 bool isTopLayoutOverflowAllowed() const override;
61 bool isLeftLayoutOverflowAllowed() const override;
63 void removeChild(RenderObject&) override;
66 virtual void computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, LayoutUnit& maxLogicalWidth) const override;
67 virtual void computePreferredLogicalWidths() override;
69 virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle) override;
77 enum PositionedLayoutMode {
82 typedef HashMap<const RenderBox*, LayoutUnit> InflexibleFlexItemSize;
83 typedef Vector<RenderBox*> OrderedFlexItemList;
88 // Use an inline capacity of 8, since flexbox containers usually have less than 8 children.
89 typedef Vector<LayoutRect, 8> ChildFrameRects;
91 bool hasOrthogonalFlow(RenderBox& child) const;
92 bool isColumnFlow() const;
93 bool isLeftToRightFlow() const;
94 bool isMultiline() const;
95 Length flexBasisForChild(RenderBox& child) const;
96 void setCrossAxisExtent(LayoutUnit);
97 LayoutUnit crossAxisExtentForChild(RenderBox& child) const;
98 LayoutUnit mainAxisExtentForChild(RenderBox& child) const;
99 LayoutUnit crossAxisExtent() const;
100 LayoutUnit mainAxisExtent() const;
101 LayoutUnit crossAxisContentExtent() const;
102 LayoutUnit mainAxisContentExtent(LayoutUnit contentLogicalHeight);
103 LayoutUnit computeMainAxisExtentForChild(RenderBox& child, SizeType, const Length& size);
104 WritingMode transformedWritingMode() const;
105 LayoutUnit flowAwareBorderStart() const;
106 LayoutUnit flowAwareBorderEnd() const;
107 LayoutUnit flowAwareBorderBefore() const;
108 LayoutUnit flowAwareBorderAfter() const;
109 LayoutUnit flowAwarePaddingStart() const;
110 LayoutUnit flowAwarePaddingEnd() const;
111 LayoutUnit flowAwarePaddingBefore() const;
112 LayoutUnit flowAwarePaddingAfter() const;
113 LayoutUnit flowAwareMarginStartForChild(RenderBox& child) const;
114 LayoutUnit flowAwareMarginEndForChild(RenderBox& child) const;
115 LayoutUnit flowAwareMarginBeforeForChild(RenderBox& child) const;
116 LayoutUnit flowAwareMarginAfterForChild(RenderBox& child) const;
117 LayoutUnit crossAxisMarginExtentForChild(RenderBox& child) const;
118 LayoutUnit crossAxisScrollbarExtent() const;
119 LayoutPoint flowAwareLocationForChild(RenderBox& child) const;
120 // FIXME: Supporting layout deltas.
121 void setFlowAwareLocationForChild(RenderBox& child, const LayoutPoint&);
122 void adjustAlignmentForChild(RenderBox& child, LayoutUnit);
123 EAlignItems alignmentForChild(RenderBox& child) const;
124 LayoutUnit mainAxisBorderAndPaddingExtentForChild(RenderBox& child) const;
125 LayoutUnit mainAxisScrollbarExtentForChild(RenderBox& child) const;
126 LayoutUnit preferredMainAxisContentExtentForChild(RenderBox& child, bool hasInfiniteLineLength);
128 void layoutFlexItems(bool relayoutChildren, Vector<LineContext>&);
129 LayoutUnit autoMarginOffsetInMainAxis(const OrderedFlexItemList&, LayoutUnit& availableFreeSpace);
130 void updateAutoMarginsInMainAxis(RenderBox& child, LayoutUnit autoMarginOffset);
131 bool hasAutoMarginsInCrossAxis(RenderBox& child) const;
132 bool updateAutoMarginsInCrossAxis(RenderBox& child, LayoutUnit availableAlignmentSpace);
133 void repositionLogicalHeightDependentFlexItems(Vector<LineContext>&);
134 LayoutUnit clientLogicalBottomAfterRepositioning();
135 void appendChildFrameRects(ChildFrameRects&);
136 void repaintChildrenDuringLayoutIfMoved(const ChildFrameRects&);
138 LayoutUnit availableAlignmentSpaceForChild(LayoutUnit lineCrossAxisExtent, RenderBox&);
139 LayoutUnit marginBoxAscentForChild(RenderBox&);
141 LayoutUnit computeChildMarginValue(const Length& margin);
142 void prepareOrderIteratorAndMargins();
143 LayoutUnit adjustChildSizeForMinAndMax(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 mutable OrderIterator m_orderIterator;
163 int m_numberOfInFlowChildrenOnFirstLine;
166 RENDER_OBJECT_TYPE_CASTS(RenderFlexibleBox, isFlexibleBox())
168 } // namespace WebCore
170 #endif // RenderFlexibleBox_h