Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / Source / core / layout / LayoutFlexibleBox.h
blob4b29cbf52dfe62d94e4a06dbe9018192f633bea0
1 /*
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
6 * met:
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
13 * distribution.
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 LayoutFlexibleBox_h
32 #define LayoutFlexibleBox_h
34 #include "core/CoreExport.h"
35 #include "core/layout/LayoutBlock.h"
36 #include "core/layout/OrderIterator.h"
38 namespace blink {
40 class CORE_EXPORT LayoutFlexibleBox : public LayoutBlock {
41 public:
42 LayoutFlexibleBox(Element*);
43 ~LayoutFlexibleBox() override;
45 static LayoutFlexibleBox* createAnonymous(Document*);
47 const char* name() const override { return "LayoutFlexibleBox"; }
49 bool isFlexibleBox() const final { return true; }
50 bool canCollapseAnonymousBlockChild() const override { return false; }
51 void layoutBlock(bool relayoutChildren) final;
53 int baselinePosition(FontBaseline, bool firstLine, LineDirectionMode, LinePositionMode = PositionOnContainingLine) const override;
54 int firstLineBoxBaseline() const override;
55 int inlineBlockBaseline(LineDirectionMode) const override;
57 void paintChildren(const PaintInfo&, const LayoutPoint&) final;
59 bool isHorizontalFlow() const;
61 OrderIterator& orderIterator() { return m_orderIterator; }
63 protected:
64 void computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, LayoutUnit& maxLogicalWidth) const override;
66 void styleDidChange(StyleDifference, const ComputedStyle* oldStyle) override;
67 void removeChild(LayoutObject*) override;
69 private:
70 enum FlexSign {
71 PositiveFlexibility,
72 NegativeFlexibility,
75 enum PositionedLayoutMode {
76 FlipForRowReverse,
77 NoFlipForRowReverse,
80 enum ChildLayoutType {
81 LayoutIfNeeded,
82 ForceLayout,
83 NeverLayout
86 typedef HashMap<const LayoutBox*, LayoutUnit> InflexibleFlexItemSize;
87 typedef Vector<LayoutBox*> OrderedFlexItemList;
89 struct LineContext;
90 struct Violation;
92 // Use an inline capacity of 8, since flexbox containers usually have less than 8 children.
93 typedef Vector<LayoutRect, 8> ChildFrameRects;
95 bool hasOrthogonalFlow(LayoutBox& child) const;
96 bool isColumnFlow() const;
97 bool isLeftToRightFlow() const;
98 bool isMultiline() const;
99 Length flexBasisForChild(const LayoutBox& child) const;
100 LayoutUnit crossAxisExtentForChild(LayoutBox& child) const;
101 LayoutUnit crossAxisIntrinsicExtentForChild(LayoutBox& child) const;
102 LayoutUnit childIntrinsicHeight(LayoutBox& child) const;
103 LayoutUnit childIntrinsicWidth(LayoutBox& child) const;
104 LayoutUnit mainAxisExtentForChild(LayoutBox& child) const;
105 LayoutUnit crossAxisExtent() const;
106 LayoutUnit mainAxisExtent() const;
107 LayoutUnit crossAxisContentExtent() const;
108 LayoutUnit mainAxisContentExtent(LayoutUnit contentLogicalHeight);
109 LayoutUnit computeMainAxisExtentForChild(LayoutBox& child, SizeType, const Length& size);
110 WritingMode transformedWritingMode() const;
111 LayoutUnit flowAwareBorderStart() const;
112 LayoutUnit flowAwareBorderEnd() const;
113 LayoutUnit flowAwareBorderBefore() const;
114 LayoutUnit flowAwareBorderAfter() const;
115 LayoutUnit flowAwarePaddingStart() const;
116 LayoutUnit flowAwarePaddingEnd() const;
117 LayoutUnit flowAwarePaddingBefore() const;
118 LayoutUnit flowAwarePaddingAfter() const;
119 LayoutUnit flowAwareMarginStartForChild(LayoutBox& child) const;
120 LayoutUnit flowAwareMarginEndForChild(LayoutBox& child) const;
121 LayoutUnit flowAwareMarginBeforeForChild(LayoutBox& child) const;
122 LayoutUnit crossAxisMarginExtentForChild(LayoutBox& child) const;
123 LayoutUnit crossAxisScrollbarExtent() const;
124 LayoutUnit crossAxisScrollbarExtentForChild(LayoutBox& child) const;
125 LayoutPoint flowAwareLocationForChild(LayoutBox& child) const;
126 // FIXME: Supporting layout deltas.
127 void setFlowAwareLocationForChild(LayoutBox& child, const LayoutPoint&);
128 void adjustAlignmentForChild(LayoutBox& child, LayoutUnit);
129 ItemPosition alignmentForChild(LayoutBox& child) const;
130 LayoutUnit mainAxisBorderAndPaddingExtentForChild(LayoutBox& child) const;
131 LayoutUnit computeInnerFlexBaseSizeForChild(LayoutBox& child, ChildLayoutType = LayoutIfNeeded);
132 bool mainAxisLengthIsDefinite(LayoutBox& child, const Length& flexBasis) const;
133 bool childFlexBaseSizeRequiresLayout(LayoutBox& child) const;
134 bool needToStretchChildLogicalHeight(LayoutBox& child) const;
135 bool childHasIntrinsicMainAxisSize(const LayoutBox& child) const;
136 EOverflow mainAxisOverflowForChild(LayoutBox& child) const;
137 EOverflow crossAxisOverflowForChild(LayoutBox& child) const;
139 void layoutFlexItems(bool relayoutChildren, SubtreeLayoutScope&);
140 LayoutUnit autoMarginOffsetInMainAxis(const OrderedFlexItemList&, LayoutUnit& availableFreeSpace);
141 void updateAutoMarginsInMainAxis(LayoutBox& child, LayoutUnit autoMarginOffset);
142 bool hasAutoMarginsInCrossAxis(LayoutBox& child) const;
143 bool updateAutoMarginsInCrossAxis(LayoutBox& child, LayoutUnit availableAlignmentSpace);
144 void repositionLogicalHeightDependentFlexItems(Vector<LineContext>&);
145 LayoutUnit clientLogicalBottomAfterRepositioning();
147 LayoutUnit availableAlignmentSpaceForChild(LayoutUnit lineCrossAxisExtent, LayoutBox& child);
148 LayoutUnit availableAlignmentSpaceForChildBeforeStretching(LayoutUnit lineCrossAxisExtent, LayoutBox& child);
149 LayoutUnit marginBoxAscentForChild(LayoutBox& child);
151 LayoutUnit computeChildMarginValue(Length margin);
152 void prepareOrderIteratorAndMargins();
153 LayoutUnit adjustChildSizeForMinAndMax(LayoutBox& child, LayoutUnit childSize, bool childShrunk = false);
154 // The hypothetical main size of an item is the flex base size clamped according to its min and max main size properties
155 bool computeNextFlexLine(OrderedFlexItemList& orderedChildren, LayoutUnit& sumFlexBaseSize, double& totalFlexGrow, double& totalWeightedFlexShrink, LayoutUnit& sumHypotheticalMainSize, bool relayoutChildren);
157 bool resolveFlexibleLengths(FlexSign, const OrderedFlexItemList&, LayoutUnit& availableFreeSpace, double& totalFlexGrow, double& totalWeightedFlexShrink, InflexibleFlexItemSize&, Vector<LayoutUnit, 16>& childSizes);
158 void freezeViolations(const Vector<Violation>&, LayoutUnit& availableFreeSpace, double& totalFlexGrow, double& totalWeightedFlexShrink, InflexibleFlexItemSize&);
160 void resetAutoMarginsAndLogicalTopInCrossAxis(LayoutBox& child);
161 void setOverrideMainAxisSizeForChild(LayoutBox& child, LayoutUnit childPreferredSize);
162 void prepareChildForPositionedLayout(LayoutBox& child, LayoutUnit mainAxisOffset, LayoutUnit crossAxisOffset, PositionedLayoutMode);
163 size_t numberOfInFlowPositionedChildren(const OrderedFlexItemList&) const;
164 void layoutAndPlaceChildren(LayoutUnit& crossAxisOffset, const OrderedFlexItemList&, const Vector<LayoutUnit, 16>& childSizes, LayoutUnit availableFreeSpace, bool relayoutChildren, SubtreeLayoutScope&, Vector<LineContext>&);
165 void layoutColumnReverse(const OrderedFlexItemList&, LayoutUnit crossAxisOffset, LayoutUnit availableFreeSpace);
166 void alignFlexLines(Vector<LineContext>&);
167 void alignChildren(const Vector<LineContext>&);
168 void applyStretchAlignmentToChild(LayoutBox& child, LayoutUnit lineCrossAxisExtent);
169 void flipForRightToLeftColumn();
170 void flipForWrapReverse(const Vector<LineContext>&, LayoutUnit crossAxisStartEdge);
172 float countIntrinsicSizeForAlgorithmChange(LayoutUnit maxPreferredWidth, LayoutBox* child, float previousMaxContentFlexFraction) const;
174 // This is used to cache the preferred size for orthogonal flow children so we don't have to relayout to get it
175 HashMap<const LayoutObject*, LayoutUnit> m_intrinsicSizeAlongMainAxis;
177 mutable OrderIterator m_orderIterator;
178 int m_numberOfInFlowChildrenOnFirstLine;
181 DEFINE_LAYOUT_OBJECT_TYPE_CASTS(LayoutFlexibleBox, isFlexibleBox());
183 } // namespace blink
185 #endif // LayoutFlexibleBox_h