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 | #include "config.h" |
27 | #include "LayoutContainer.h" |
28 | |
29 | #if ENABLE(LAYOUT_FORMATTING_CONTEXT) |
30 | |
31 | #include "RenderStyle.h" |
32 | #include <wtf/IsoMallocInlines.h> |
33 | |
34 | namespace WebCore { |
35 | namespace Layout { |
36 | |
37 | WTF_MAKE_ISO_ALLOCATED_IMPL(Container); |
38 | |
39 | Container::Container(Optional<ElementAttributes> attributes, RenderStyle&& style, BaseTypeFlags baseTypeFlags) |
40 | : Box(attributes, WTFMove(style), baseTypeFlags | ContainerFlag) |
41 | { |
42 | } |
43 | |
44 | const Box* Container::firstInFlowChild() const |
45 | { |
46 | if (auto* firstChild = this->firstChild()) { |
47 | if (firstChild->isInFlow()) |
48 | return firstChild; |
49 | return firstChild->nextInFlowSibling(); |
50 | } |
51 | return nullptr; |
52 | } |
53 | |
54 | const Box* Container::firstInFlowOrFloatingChild() const |
55 | { |
56 | if (auto* firstChild = this->firstChild()) { |
57 | if (firstChild->isInFlow() || firstChild->isFloatingPositioned()) |
58 | return firstChild; |
59 | return firstChild->nextInFlowOrFloatingSibling(); |
60 | } |
61 | return nullptr; |
62 | } |
63 | |
64 | const Box* Container::lastInFlowChild() const |
65 | { |
66 | if (auto* lastChild = this->lastChild()) { |
67 | if (lastChild->isInFlow()) |
68 | return lastChild; |
69 | return lastChild->previousInFlowSibling(); |
70 | } |
71 | return nullptr; |
72 | } |
73 | |
74 | const Box* Container::lastInFlowOrFloatingChild() const |
75 | { |
76 | if (auto* lastChild = this->lastChild()) { |
77 | if (lastChild->isInFlow() || lastChild->isFloatingPositioned()) |
78 | return lastChild; |
79 | return lastChild->previousInFlowOrFloatingSibling(); |
80 | } |
81 | return nullptr; |
82 | } |
83 | |
84 | void Container::setFirstChild(Box& childBox) |
85 | { |
86 | m_firstChild = &childBox; |
87 | } |
88 | |
89 | void Container::setLastChild(Box& childBox) |
90 | { |
91 | m_lastChild = &childBox; |
92 | } |
93 | |
94 | void Container::addOutOfFlowDescendant(const Box& outOfFlowBox) |
95 | { |
96 | // Since we layout the out-of-flow boxes at the end of the formatting context layout, |
97 | // it's okay to store them at the formatting context root level -as opposed to the containing block level. |
98 | ASSERT(establishesFormattingContext()); |
99 | m_outOfFlowDescendants.append(makeWeakPtr(outOfFlowBox)); |
100 | } |
101 | |
102 | } |
103 | } |
104 | #endif |
105 | |