1 | /* |
2 | * Copyright (C) 2018 Apple Inc. All rights reserved. |
3 | * |
4 | * Redistribution and use in source and binary forms, with or without |
5 | * modification, are permitted provided that the following conditions |
6 | * are met: |
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. |
12 | * |
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. |
24 | */ |
25 | |
26 | #pragma once |
27 | |
28 | #if ENABLE(LAYOUT_FORMATTING_CONTEXT) |
29 | |
30 | #include "DisplayBox.h" |
31 | #include "LayoutBox.h" |
32 | #include "LayoutUnit.h" |
33 | #include <wtf/IsoMalloc.h> |
34 | #include <wtf/WeakPtr.h> |
35 | |
36 | namespace WebCore { |
37 | |
38 | namespace Layout { |
39 | |
40 | class FloatingState; |
41 | class LayoutState; |
42 | |
43 | class FloatAvoider { |
44 | WTF_MAKE_ISO_ALLOCATED(FloatAvoider); |
45 | public: |
46 | FloatAvoider(const Box&, const FloatingState&, const LayoutState&); |
47 | virtual ~FloatAvoider() = default; |
48 | |
49 | virtual Display::Box::Rect rect() const { return m_absoluteDisplayBox.rect(); } |
50 | Display::Box::Rect rectInContainingBlock() const; |
51 | |
52 | struct HorizontalConstraints { |
53 | Optional<PositionInContextRoot> left; |
54 | Optional<PositionInContextRoot> right; |
55 | }; |
56 | void setHorizontalConstraints(HorizontalConstraints); |
57 | void setVerticalConstraint(PositionInContextRoot); |
58 | |
59 | bool overflowsContainingBlock() const; |
60 | |
61 | protected: |
62 | virtual bool isLeftAligned() const { return layoutBox().style().isLeftToRightDirection(); } |
63 | PositionInContextRoot initialHorizontalPosition() const; |
64 | |
65 | void resetHorizontalConstraints(); |
66 | |
67 | virtual PositionInContextRoot horizontalPositionCandidate(HorizontalConstraints); |
68 | virtual PositionInContextRoot verticalPositionCandidate(PositionInContextRoot); |
69 | |
70 | LayoutUnit marginBefore() const { return displayBox().marginBefore(); } |
71 | LayoutUnit marginAfter() const { return displayBox().marginAfter(); } |
72 | // Do not use the used values here because they computed as if this box was not a float avoider. |
73 | LayoutUnit marginStart() const { return displayBox().computedMarginStart().valueOr(0); } |
74 | LayoutUnit marginEnd() const { return displayBox().computedMarginEnd().valueOr(0); } |
75 | |
76 | LayoutUnit marginBoxWidth() const { return marginStart() + displayBox().width() + marginEnd(); } |
77 | |
78 | const FloatingState& floatingState() const { return m_floatingState; } |
79 | const Box& layoutBox() const { return *m_layoutBox; } |
80 | const Display::Box& displayBox() const { return m_absoluteDisplayBox; } |
81 | Display::Box& displayBox() { return m_absoluteDisplayBox; } |
82 | |
83 | private: |
84 | WeakPtr<const Box> m_layoutBox; |
85 | const FloatingState& m_floatingState; |
86 | Display::Box m_absoluteDisplayBox; |
87 | Display::Box m_containingBlockAbsoluteDisplayBox; |
88 | }; |
89 | |
90 | } |
91 | } |
92 | #endif |
93 | |