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 "core/rendering/OrderIterator.h"
35 #include "core/rendering/RenderBlock.h"
39 class RenderFlexibleBox : public RenderBlock {
41 RenderFlexibleBox(Element*);
42 virtual ~RenderFlexibleBox();
44 static RenderFlexibleBox* createAnonymous(Document*);
46 virtual const char* renderName() const OVERRIDE;
48 virtual bool isFlexibleBox() const OVERRIDE FINAL { return true; }
49 virtual bool avoidsFloats() const OVERRIDE FINAL { return true; }
50 virtual bool canCollapseAnonymousBlockChild() const OVERRIDE { return false; }
51 virtual void layoutBlock(bool relayoutChildren) OVERRIDE FINAL;
53 virtual int baselinePosition(FontBaseline, bool firstLine, LineDirectionMode, LinePositionMode = PositionOnContainingLine) const OVERRIDE;
54 virtual int firstLineBoxBaseline() const OVERRIDE;
55 virtual int inlineBlockBaseline(LineDirectionMode) const OVERRIDE;
57 virtual void paintChildren(PaintInfo&, const LayoutPoint&) OVERRIDE FINAL;
59 bool isHorizontalFlow() const;
62 virtual void computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, LayoutUnit& maxLogicalWidth) const OVERRIDE;
64 virtual bool supportsPartialLayout() const OVERRIDE { return false; }
66 virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle) OVERRIDE;
67 virtual void removeChild(RenderObject*) OVERRIDE;
75 enum PositionedLayoutMode {
80 typedef HashMap<const RenderBox*, LayoutUnit> InflexibleFlexItemSize;
81 typedef Vector<RenderBox*> OrderedFlexItemList;
86 // Use an inline capacity of 8, since flexbox containers usually have less than 8 children.
87 typedef Vector<LayoutRect, 8> ChildFrameRects;
89 bool hasOrthogonalFlow(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 LayoutUnit computeMainAxisExtentForChild(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, bool relayoutChildren = false);
125 bool childPreferredMainAxisContentExtentRequiresLayout(RenderBox* child, bool hasInfiniteLineLength) 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(Length margin);
141 void prepareOrderIteratorAndMargins();
142 LayoutUnit adjustChildSizeForMinAndMax(RenderBox*, LayoutUnit childSize);
143 // The hypothetical main size of an item is the flex base size clamped according to its min and max main size properties
144 bool computeNextFlexLine(OrderedFlexItemList& orderedChildren, LayoutUnit& sumFlexBaseSize, double& totalFlexGrow, double& totalWeightedFlexShrink, LayoutUnit& sumHypotheticalMainSize, bool& hasInfiniteLineLength, bool relayoutChildren);
146 bool resolveFlexibleLengths(FlexSign, const OrderedFlexItemList&, LayoutUnit& availableFreeSpace, double& totalFlexGrow, double& totalWeightedFlexShrink, InflexibleFlexItemSize&, Vector<LayoutUnit, 16>& childSizes, bool hasInfiniteLineLength);
147 void freezeViolations(const Vector<Violation>&, LayoutUnit& availableFreeSpace, double& totalFlexGrow, double& totalWeightedFlexShrink, InflexibleFlexItemSize&, bool hasInfiniteLineLength);
149 void resetAutoMarginsAndLogicalTopInCrossAxis(RenderBox*);
150 void setLogicalOverrideSize(RenderBox* child, LayoutUnit childPreferredSize);
151 void prepareChildForPositionedLayout(RenderBox* child, LayoutUnit mainAxisOffset, LayoutUnit crossAxisOffset, PositionedLayoutMode);
152 size_t numberOfInFlowPositionedChildren(const OrderedFlexItemList&) const;
153 void layoutAndPlaceChildren(LayoutUnit& crossAxisOffset, const OrderedFlexItemList&, const Vector<LayoutUnit, 16>& childSizes, LayoutUnit availableFreeSpace, bool relayoutChildren, Vector<LineContext>&, bool hasInfiniteLineLength);
154 void layoutColumnReverse(const OrderedFlexItemList&, LayoutUnit crossAxisOffset, LayoutUnit availableFreeSpace);
155 void alignFlexLines(Vector<LineContext>&);
156 void alignChildren(const Vector<LineContext>&);
157 void applyStretchAlignmentToChild(RenderBox*, LayoutUnit lineCrossAxisExtent);
158 void flipForRightToLeftColumn();
159 void flipForWrapReverse(const Vector<LineContext>&, LayoutUnit crossAxisStartEdge);
161 // This is used to cache the preferred size for orthogonal flow children so we don't have to relayout to get it
162 HashMap<const RenderObject*, LayoutUnit> m_intrinsicSizeAlongMainAxis;
164 mutable OrderIterator m_orderIterator;
165 int m_numberOfInFlowChildrenOnFirstLine;
168 DEFINE_RENDER_OBJECT_TYPE_CASTS(RenderFlexibleBox, isFlexibleBox());
170 } // namespace WebCore
172 #endif // RenderFlexibleBox_h