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 struct OrderHashTraits;
66 typedef HashSet<int, DefaultHash<int>::Hash, OrderHashTraits> OrderHashSet;
69 typedef WTF::HashMap<const RenderBox*, LayoutUnit> InflexibleFlexItemSize;
70 typedef WTF::Vector<RenderBox*> OrderedFlexItemList;
75 bool hasOrthogonalFlow(RenderBox* child) const;
76 bool isColumnFlow() const;
77 bool isLeftToRightFlow() const;
78 bool isMultiline() const;
79 Length crossAxisLength() const;
80 Length flexBasisForChild(RenderBox* child) const;
81 void setCrossAxisExtent(LayoutUnit);
82 LayoutUnit crossAxisExtentForChild(RenderBox* child);
83 LayoutUnit mainAxisExtentForChild(RenderBox* child);
84 LayoutUnit crossAxisExtent() const;
85 LayoutUnit mainAxisExtent() const;
86 LayoutUnit crossAxisContentExtent() const;
87 LayoutUnit mainAxisContentExtent();
88 LayoutUnit computeLogicalClientHeight(SizeType, const Length& height);
89 WritingMode transformedWritingMode() const;
90 LayoutUnit flowAwareBorderStart() const;
91 LayoutUnit flowAwareBorderEnd() const;
92 LayoutUnit flowAwareBorderBefore() const;
93 LayoutUnit flowAwareBorderAfter() const;
94 LayoutUnit flowAwarePaddingStart() const;
95 LayoutUnit flowAwarePaddingEnd() const;
96 LayoutUnit flowAwarePaddingBefore() const;
97 LayoutUnit flowAwarePaddingAfter() const;
98 LayoutUnit flowAwareMarginStartForChild(RenderBox* child) const;
99 LayoutUnit flowAwareMarginEndForChild(RenderBox* child) const;
100 LayoutUnit flowAwareMarginBeforeForChild(RenderBox* child) const;
101 LayoutUnit flowAwareMarginAfterForChild(RenderBox* child) const;
102 LayoutUnit crossAxisMarginExtentForChild(RenderBox* child) const;
103 LayoutUnit crossAxisScrollbarExtent() const;
104 LayoutPoint flowAwareLocationForChild(RenderBox* child) const;
105 // FIXME: Supporting layout deltas.
106 void setFlowAwareLocationForChild(RenderBox* child, const LayoutPoint&);
107 void adjustAlignmentForChild(RenderBox* child, LayoutUnit);
108 LayoutUnit mainAxisBorderAndPaddingExtentForChild(RenderBox* child) const;
109 LayoutUnit mainAxisScrollbarExtentForChild(RenderBox* child) const;
110 LayoutUnit preferredMainAxisContentExtentForChild(RenderBox* child);
112 void layoutFlexItems(OrderIterator&, WTF::Vector<LineContext>&);
113 LayoutUnit autoMarginOffsetInMainAxis(const OrderedFlexItemList&, LayoutUnit& availableFreeSpace);
114 void updateAutoMarginsInMainAxis(RenderBox* child, LayoutUnit autoMarginOffset);
115 bool hasAutoMarginsInCrossAxis(RenderBox* child);
116 bool updateAutoMarginsInCrossAxis(RenderBox* child, LayoutUnit availableAlignmentSpace);
117 void repositionLogicalHeightDependentFlexItems(OrderIterator&, WTF::Vector<LineContext>&, LayoutUnit& oldClientAfterEdge);
119 LayoutUnit availableAlignmentSpaceForChild(LayoutUnit lineCrossAxisExtent, RenderBox*);
120 LayoutUnit marginBoxAscentForChild(RenderBox*);
122 void computeMainAxisPreferredSizes(bool relayoutChildren, OrderHashSet&);
123 LayoutUnit lineBreakLength();
124 LayoutUnit adjustChildSizeForMinAndMax(RenderBox*, LayoutUnit childSize, LayoutUnit flexboxAvailableContentExtent);
125 bool computeNextFlexLine(OrderIterator&, OrderedFlexItemList& orderedChildren, LayoutUnit& preferredMainAxisExtent, float& totalFlexGrow, float& totalWeightedFlexShrink, LayoutUnit& minMaxAppliedMainAxisExtent);
126 LayoutUnit computeAvailableFreeSpace(LayoutUnit preferredMainAxisExtent);
128 bool resolveFlexibleLengths(FlexSign, const OrderedFlexItemList&, LayoutUnit& availableFreeSpace, float& totalFlexGrow, float& totalWeightedFlexShrink, InflexibleFlexItemSize&, WTF::Vector<LayoutUnit>& childSizes);
129 void freezeViolations(const WTF::Vector<Violation>&, LayoutUnit& availableFreeSpace, float& totalFlexGrow, float& totalWeightedFlexShrink, InflexibleFlexItemSize&);
131 void setLogicalOverrideSize(RenderBox* child, LayoutUnit childPreferredSize);
132 void prepareChildForPositionedLayout(RenderBox* child, LayoutUnit mainAxisOffset, LayoutUnit crossAxisOffset, PositionedLayoutMode);
133 void layoutAndPlaceChildren(LayoutUnit& crossAxisOffset, const OrderedFlexItemList&, const WTF::Vector<LayoutUnit>& childSizes, LayoutUnit availableFreeSpace, WTF::Vector<LineContext>&);
134 void layoutColumnReverse(const OrderedFlexItemList&, const WTF::Vector<LayoutUnit>& childSizes, LayoutUnit crossAxisOffset, LayoutUnit availableFreeSpace);
135 void alignFlexLines(OrderIterator&, WTF::Vector<LineContext>&);
136 void alignChildren(OrderIterator&, const WTF::Vector<LineContext>&);
137 void applyStretchAlignmentToChild(RenderBox*, LayoutUnit lineCrossAxisExtent);
138 void flipForRightToLeftColumn(OrderIterator&);
139 void flipForWrapReverse(OrderIterator&, const WTF::Vector<LineContext>&, LayoutUnit crossAxisStartEdge);
141 OwnPtr<OrderIterator> m_orderIterator;
144 } // namespace WebCore
146 #endif // RenderFlexibleBox_h