2 * Copyright (C) 2018 Apple 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
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
28 #if ENABLE(LAYOUT_FORMATTING_CONTEXT)
30 #include "DisplayBox.h"
31 #include <wtf/IsoMalloc.h>
32 #include <wtf/WeakPtr.h>
43 class FormattingState;
46 class FormattingContext {
47 WTF_MAKE_ISO_ALLOCATED(FormattingContext);
49 FormattingContext(const Box& formattingContextRoot, FormattingState&);
50 virtual ~FormattingContext();
52 virtual void layout() const = 0;
53 void layoutOutOfFlowDescendants(const Box&) const;
55 struct InstrinsicWidthConstraints {
59 virtual InstrinsicWidthConstraints instrinsicWidthConstraints() const = 0;
61 static Display::Box mapBoxToAncestor(const LayoutState&, const Box&, const Container& ancestor);
62 static Position mapTopLeftToAncestor(const LayoutState&, const Box&, const Container& ancestor);
63 static Position mapCoordinateToAncestor(const LayoutState&, Position, const Container& containingBlock, const Container& ancestor);
66 using LayoutQueue = Vector<const Box*>;
68 FormattingState& formattingState() const;
69 LayoutState& layoutState() const;
70 const Box& root() const { return *m_root; }
72 void computeBorderAndPadding(const Box&) const;
75 virtual void validateGeometryConstraintsAfterLayout() const;
78 // This class implements generic positioning and sizing.
81 static VerticalGeometry outOfFlowVerticalGeometry(const LayoutState&, const Box&, std::optional<LayoutUnit> usedHeight = { });
82 static HorizontalGeometry outOfFlowHorizontalGeometry(LayoutState&, const Box&, std::optional<LayoutUnit> usedWidth = { });
84 static HeightAndMargin floatingHeightAndMargin(const LayoutState&, const Box&, std::optional<LayoutUnit> usedHeight = { });
85 static WidthAndMargin floatingWidthAndMargin(LayoutState&, const Box&, std::optional<LayoutUnit> usedWidth = { });
87 static HeightAndMargin inlineReplacedHeightAndMargin(const LayoutState&, const Box&, std::optional<LayoutUnit> usedHeight = { });
88 static WidthAndMargin inlineReplacedWidthAndMargin(const LayoutState&, const Box&, std::optional<LayoutUnit> usedWidth = { },
89 std::optional<LayoutUnit> precomputedMarginLeft = { }, std::optional<LayoutUnit> precomputedMarginRight = { });
91 static LayoutSize inFlowPositionedPositionOffset(const LayoutState&, const Box&);
93 static HeightAndMargin complicatedCases(const LayoutState&, const Box&, std::optional<LayoutUnit> usedHeight = { });
94 static LayoutUnit shrinkToFitWidth(LayoutState&, const Box&);
96 static Edges computedBorder(const LayoutState&, const Box&);
97 static std::optional<Edges> computedPadding(const LayoutState&, const Box&);
99 static HorizontalEdges computedNonCollapsedHorizontalMarginValue(const LayoutState&, const Box&);
100 static VerticalEdges computedNonCollapsedVerticalMarginValue(const LayoutState&, const Box&);
102 static std::optional<LayoutUnit> computedValueIfNotAuto(const Length& geometryProperty, LayoutUnit containingBlockWidth);
103 static std::optional<LayoutUnit> fixedValue(const Length& geometryProperty);
105 static std::optional<LayoutUnit> computedMinHeight(const LayoutState&, const Box&);
106 static std::optional<LayoutUnit> computedMaxHeight(const LayoutState&, const Box&);
109 enum class HeightType { Min, Max, Normal };
110 static std::optional<LayoutUnit> computedHeightValue(const LayoutState&, const Box&, HeightType);
113 static VerticalGeometry outOfFlowReplacedVerticalGeometry(const LayoutState&, const Box&, std::optional<LayoutUnit> usedHeight = { });
114 static HorizontalGeometry outOfFlowReplacedHorizontalGeometry(const LayoutState&, const Box&, std::optional<LayoutUnit> usedWidth = { });
116 static VerticalGeometry outOfFlowNonReplacedVerticalGeometry(const LayoutState&, const Box&, std::optional<LayoutUnit> usedHeight = { });
117 static HorizontalGeometry outOfFlowNonReplacedHorizontalGeometry(LayoutState&, const Box&, std::optional<LayoutUnit> usedWidth = { });
119 static HeightAndMargin floatingReplacedHeightAndMargin(const LayoutState&, const Box&, std::optional<LayoutUnit> usedHeight = { });
120 static WidthAndMargin floatingReplacedWidthAndMargin(const LayoutState&, const Box&, std::optional<LayoutUnit> usedWidth = { });
122 static WidthAndMargin floatingNonReplacedWidthAndMargin(LayoutState&, const Box&, std::optional<LayoutUnit> usedWidth = { });
126 void computeOutOfFlowVerticalGeometry(const Box&) const;
127 void computeOutOfFlowHorizontalGeometry(const Box&) const;
129 WeakPtr<const Box> m_root;
130 FormattingState& m_formattingState;