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 "RenderBlock.h"
35 #include <wtf/OwnPtr.h>
39 class RenderFlexibleBox : public RenderBlock {
41 RenderFlexibleBox(Node*);
42 virtual ~RenderFlexibleBox();
44 virtual const char* renderName() const OVERRIDE;
46 virtual bool isFlexibleBox() const OVERRIDE { return true; }
47 virtual void computePreferredLogicalWidths() OVERRIDE;
48 virtual void layoutBlock(bool relayoutChildren, LayoutUnit pageLogicalHeight = 0) OVERRIDE;
50 virtual void paintChildren(PaintInfo& forSelf, const LayoutPoint&, PaintInfo& forChild, bool usePrintRect) OVERRIDE;
52 bool isHorizontalFlow() const;
60 enum PositionedLayoutMode {
65 typedef HashSet<float> OrderHashSet;
68 typedef WTF::HashMap<const RenderBox*, LayoutUnit> InflexibleFlexItemSize;
69 typedef WTF::Vector<RenderBox*> OrderedFlexItemList;
74 bool hasOrthogonalFlow(RenderBox* child) const;
75 bool isColumnFlow() const;
76 bool isLeftToRightFlow() const;
77 bool isMultiline() const;
78 Length crossAxisLength() const;
79 Length flexBasisForChild(RenderBox* child) const;
80 void setCrossAxisExtent(LayoutUnit);
81 LayoutUnit crossAxisExtentForChild(RenderBox* child);
82 LayoutUnit mainAxisExtentForChild(RenderBox* child);
83 LayoutUnit crossAxisExtent() const;
84 LayoutUnit mainAxisExtent() const;
85 LayoutUnit crossAxisContentExtent() const;
86 LayoutUnit mainAxisContentExtent();
87 WritingMode transformedWritingMode() const;
88 LayoutUnit flowAwareBorderStart() const;
89 LayoutUnit flowAwareBorderEnd() const;
90 LayoutUnit flowAwareBorderBefore() const;
91 LayoutUnit flowAwareBorderAfter() const;
92 LayoutUnit flowAwarePaddingStart() const;
93 LayoutUnit flowAwarePaddingEnd() const;
94 LayoutUnit flowAwarePaddingBefore() const;
95 LayoutUnit flowAwarePaddingAfter() const;
96 LayoutUnit flowAwareMarginStartForChild(RenderBox* child) const;
97 LayoutUnit flowAwareMarginEndForChild(RenderBox* child) const;
98 LayoutUnit flowAwareMarginBeforeForChild(RenderBox* child) const;
99 LayoutUnit flowAwareMarginAfterForChild(RenderBox* child) const;
100 LayoutUnit crossAxisMarginExtentForChild(RenderBox* child) const;
101 LayoutUnit crossAxisScrollbarExtent() const;
102 LayoutPoint flowAwareLocationForChild(RenderBox* child) const;
103 // FIXME: Supporting layout deltas.
104 void setFlowAwareLocationForChild(RenderBox* child, const LayoutPoint&);
105 void adjustAlignmentForChild(RenderBox* child, LayoutUnit);
106 LayoutUnit mainAxisBorderAndPaddingExtentForChild(RenderBox* child) const;
107 LayoutUnit mainAxisScrollbarExtentForChild(RenderBox* child) const;
108 LayoutUnit preferredMainAxisContentExtentForChild(RenderBox* child);
110 void layoutFlexItems(OrderIterator&, WTF::Vector<LineContext>&);
111 LayoutUnit autoMarginOffsetInMainAxis(const OrderedFlexItemList&, LayoutUnit& availableFreeSpace);
112 void updateAutoMarginsInMainAxis(RenderBox* child, LayoutUnit autoMarginOffset);
113 bool hasAutoMarginsInCrossAxis(RenderBox* child);
114 bool updateAutoMarginsInCrossAxis(RenderBox* child, LayoutUnit availableAlignmentSpace);
115 void repositionLogicalHeightDependentFlexItems(OrderIterator&, WTF::Vector<LineContext>&, LayoutUnit& oldClientAfterEdge);
117 LayoutUnit availableAlignmentSpaceForChild(LayoutUnit lineCrossAxisExtent, RenderBox*);
118 LayoutUnit marginBoxAscentForChild(RenderBox*);
120 void computeMainAxisPreferredSizes(bool relayoutChildren, OrderHashSet&);
121 LayoutUnit lineBreakLength();
122 LayoutUnit adjustChildSizeForMinAndMax(RenderBox*, LayoutUnit childSize, LayoutUnit flexboxAvailableContentExtent);
123 bool computeNextFlexLine(OrderIterator&, OrderedFlexItemList& orderedChildren, LayoutUnit& preferredMainAxisExtent, float& totalFlexGrow, float& totalWeightedFlexShrink, LayoutUnit& minMaxAppliedMainAxisExtent);
124 LayoutUnit computeAvailableFreeSpace(LayoutUnit preferredMainAxisExtent);
126 bool resolveFlexibleLengths(FlexSign, const OrderedFlexItemList&, LayoutUnit& availableFreeSpace, float& totalFlexGrow, float& totalWeightedFlexShrink, InflexibleFlexItemSize&, WTF::Vector<LayoutUnit>& childSizes);
127 void freezeViolations(const WTF::Vector<Violation>&, LayoutUnit& availableFreeSpace, float& totalFlexGrow, float& totalWeightedFlexShrink, InflexibleFlexItemSize&);
129 void setLogicalOverrideSize(RenderBox* child, LayoutUnit childPreferredSize);
130 void prepareChildForPositionedLayout(RenderBox* child, LayoutUnit mainAxisOffset, LayoutUnit crossAxisOffset, PositionedLayoutMode);
131 void layoutAndPlaceChildren(LayoutUnit& crossAxisOffset, const OrderedFlexItemList&, const WTF::Vector<LayoutUnit>& childSizes, LayoutUnit availableFreeSpace, WTF::Vector<LineContext>&);
132 void layoutColumnReverse(const OrderedFlexItemList&, const WTF::Vector<LayoutUnit>& childSizes, LayoutUnit crossAxisOffset, LayoutUnit availableFreeSpace);
133 void alignFlexLines(OrderIterator&, WTF::Vector<LineContext>&);
134 void alignChildren(OrderIterator&, const WTF::Vector<LineContext>&);
135 void applyStretchAlignmentToChild(RenderBox*, LayoutUnit lineCrossAxisExtent);
136 void flipForRightToLeftColumn(OrderIterator&);
137 void flipForWrapReverse(OrderIterator&, const WTF::Vector<LineContext>&, LayoutUnit crossAxisStartEdge);
139 OwnPtr<OrderIterator> m_orderIterator;
142 } // namespace WebCore
144 #endif // RenderFlexibleBox_h