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 "FloatingState.h"
32 #include <wtf/IsoMalloc.h>
33 #include <wtf/WeakPtr.h>
44 class FormattingState;
47 class FormattingContext {
48 WTF_MAKE_ISO_ALLOCATED(FormattingContext);
50 FormattingContext(const Box& formattingContextRoot);
51 virtual ~FormattingContext();
53 virtual void layout(LayoutContext&, FormattingState&) const = 0;
54 void layoutOutOfFlowDescendants(LayoutContext&, const Box&) const;
56 struct InstrinsicWidthConstraints {
60 virtual InstrinsicWidthConstraints instrinsicWidthConstraints(LayoutContext&, const Box&) const = 0;
62 static Display::Box mapBoxToAncestor(const LayoutContext&, const Box&, const Container& ancestor);
63 static Position mapTopLeftToAncestor(const LayoutContext&, const Box&, const Container& ancestor);
64 static Position mapCoordinateToAncestor(const LayoutContext&, Position, const Container& containingBlock, const Container& ancestor);
67 using LayoutQueue = Vector<const Box*>;
69 const Box& root() const { return *m_root; }
71 virtual void computeStaticPosition(const LayoutContext&, const Box&) const = 0;
72 virtual void computeInFlowPositionedPosition(const LayoutContext&, const Box&) const = 0;
74 void computeBorderAndPadding(const LayoutContext&, const Box&) const;
76 void placeInFlowPositionedChildren(const LayoutContext&, const Container&) const;
79 virtual void validateGeometryConstraintsAfterLayout(const LayoutContext&) const;
82 // This class implements generic positioning and sizing.
85 static VerticalGeometry outOfFlowVerticalGeometry(const LayoutContext&, const Box&, std::optional<LayoutUnit> precomputedHeight = { });
86 static HorizontalGeometry outOfFlowHorizontalGeometry(LayoutContext&, const FormattingContext&, const Box&, std::optional<LayoutUnit> precomputedWidth = { });
88 static HeightAndMargin floatingHeightAndMargin(const LayoutContext&, const Box&, std::optional<LayoutUnit> precomputedHeight = { });
89 static WidthAndMargin floatingWidthAndMargin(LayoutContext&, const FormattingContext&, const Box&, std::optional<LayoutUnit> precomputedWidth = { });
91 static HeightAndMargin inlineReplacedHeightAndMargin(const LayoutContext&, const Box&, std::optional<LayoutUnit> precomputedHeight = { });
92 static WidthAndMargin inlineReplacedWidthAndMargin(const LayoutContext&, const Box&, std::optional<LayoutUnit> precomputedWidth = { },
93 std::optional<LayoutUnit> precomputedMarginLeft = { }, std::optional<LayoutUnit> precomputedMarginRight = { });
95 static HeightAndMargin complicatedCases(const LayoutContext&, const Box&, std::optional<LayoutUnit> precomputedHeight = { });
97 static Edges computedBorder(const LayoutContext&, const Box&);
98 static std::optional<Edges> computedPadding(const LayoutContext&, const Box&);
100 static HorizontalEdges computedNonCollapsedHorizontalMarginValue(const LayoutContext&, const Box&);
101 static VerticalEdges computedNonCollapsedVerticalMarginValue(const LayoutContext&, const Box&);
103 static std::optional<LayoutUnit> computedValueIfNotAuto(const Length& geometryProperty, LayoutUnit containingBlockWidth);
104 static std::optional<LayoutUnit> fixedValue(const Length& geometryProperty);
107 static VerticalGeometry outOfFlowReplacedVerticalGeometry(const LayoutContext&, const Box&, std::optional<LayoutUnit> precomputedHeight = { });
108 static HorizontalGeometry outOfFlowReplacedHorizontalGeometry(const LayoutContext&, const Box&, std::optional<LayoutUnit> precomputedWidth = { });
110 static VerticalGeometry outOfFlowNonReplacedVerticalGeometry(const LayoutContext&, const Box&, std::optional<LayoutUnit> precomputedHeight = { });
111 static HorizontalGeometry outOfFlowNonReplacedHorizontalGeometry(LayoutContext&, const FormattingContext&, const Box&, std::optional<LayoutUnit> precomputedWidth = { });
113 static HeightAndMargin floatingReplacedHeightAndMargin(const LayoutContext&, const Box&, std::optional<LayoutUnit> precomputedHeight = { });
114 static WidthAndMargin floatingReplacedWidthAndMargin(const LayoutContext&, const Box&, std::optional<LayoutUnit> precomputedWidth = { });
116 static WidthAndMargin floatingNonReplacedWidthAndMargin(LayoutContext&, const FormattingContext&, const Box&, std::optional<LayoutUnit> precomputedWidth = { });
118 static LayoutUnit shrinkToFitWidth(LayoutContext&, const FormattingContext&, const Box&);
122 void computeOutOfFlowVerticalGeometry(const LayoutContext&, const Box&) const;
123 void computeOutOfFlowHorizontalGeometry(LayoutContext&, const Box&) const;
125 WeakPtr<const Box> m_root;