OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "core/layout/ng/ng_box.h" | 5 #include "core/layout/ng/ng_box.h" |
6 | 6 |
7 #include "core/layout/LayoutObject.h" | 7 #include "core/layout/LayoutObject.h" |
8 #include "core/layout/ng/layout_ng_block_flow.h" | 8 #include "core/layout/ng/layout_ng_block_flow.h" |
9 #include "core/layout/ng/ng_block_layout_algorithm.h" | 9 #include "core/layout/ng/ng_block_layout_algorithm.h" |
10 #include "core/layout/ng/ng_box_iterator.h" | 10 #include "core/layout/ng/ng_box_iterator.h" |
11 #include "core/layout/ng/ng_constraint_space.h" | 11 #include "core/layout/ng/ng_constraint_space.h" |
12 #include "core/layout/ng/ng_fragment.h" | 12 #include "core/layout/ng/ng_fragment.h" |
13 #include "core/layout/ng/ng_fragment_builder.h" | 13 #include "core/layout/ng/ng_fragment_builder.h" |
14 #include "core/layout/ng/ng_writing_mode.h" | 14 #include "core/layout/ng/ng_writing_mode.h" |
15 #include "core/layout/LayoutBlockFlow.h" | 15 #include "core/layout/LayoutBlockFlow.h" |
16 #include "core/layout/LayoutBox.h" | 16 #include "core/layout/LayoutBox.h" |
17 | 17 |
18 namespace blink { | 18 namespace blink { |
19 | 19 |
20 NGFragment* NGBox::layout(const NGConstraintSpace* constraint_space) { | 20 bool NGBox::Layout(const NGConstraintSpace* constraint_space, |
| 21 NGFragment** out) { |
21 // We can either use the new layout code to do the layout and then copy the | 22 // We can either use the new layout code to do the layout and then copy the |
22 // resulting size to the LayoutObject, or use the old layout code and | 23 // resulting size to the LayoutObject, or use the old layout code and |
23 // synthesize a fragment. | 24 // synthesize a fragment. |
24 NGFragment* fragment = nullptr; | 25 NGFragment* fragment = nullptr; |
25 if (canUseNewLayout()) { | 26 if (canUseNewLayout()) { |
26 NGBlockLayoutAlgorithm algorithm(style(), childIterator()); | 27 NGBlockLayoutAlgorithm algorithm(style(), childIterator()); |
27 | 28 |
28 // Change the coordinate system of the constraint space. | 29 // Change the coordinate system of the constraint space. |
29 NGConstraintSpace* child_constraint_space = new NGConstraintSpace( | 30 NGConstraintSpace* child_constraint_space = new NGConstraintSpace( |
30 FromPlatformWritingMode(style()->getWritingMode()), constraint_space); | 31 FromPlatformWritingMode(style()->getWritingMode()), constraint_space); |
31 | 32 |
32 fragment = algorithm.layout(child_constraint_space); | 33 if (!algorithm.Layout(child_constraint_space, &fragment)) |
| 34 return false; |
33 m_layoutBox->setLogicalWidth(fragment->InlineSize()); | 35 m_layoutBox->setLogicalWidth(fragment->InlineSize()); |
34 m_layoutBox->setLogicalHeight(fragment->BlockSize()); | 36 m_layoutBox->setLogicalHeight(fragment->BlockSize()); |
35 if (m_layoutBox->isLayoutBlock()) | 37 if (m_layoutBox->isLayoutBlock()) |
36 toLayoutBlock(m_layoutBox)->layoutPositionedObjects(true); | 38 toLayoutBlock(m_layoutBox)->layoutPositionedObjects(true); |
37 m_layoutBox->clearNeedsLayout(); | 39 m_layoutBox->clearNeedsLayout(); |
38 } else { | 40 } else { |
39 // TODO(layout-ng): If fixedSize is true, set the override width/height too | 41 // TODO(layout-ng): If fixedSize is true, set the override width/height too |
40 NGLogicalSize container_size = constraint_space->ContainerSize(); | 42 NGLogicalSize container_size = constraint_space->ContainerSize(); |
41 m_layoutBox->setOverrideContainingBlockContentLogicalWidth( | 43 m_layoutBox->setOverrideContainingBlockContentLogicalWidth( |
42 container_size.inline_size); | 44 container_size.inline_size); |
43 m_layoutBox->setOverrideContainingBlockContentLogicalHeight( | 45 m_layoutBox->setOverrideContainingBlockContentLogicalHeight( |
44 container_size.block_size); | 46 container_size.block_size); |
45 if (m_layoutBox->isLayoutNGBlockFlow() && m_layoutBox->needsLayout()) { | 47 if (m_layoutBox->isLayoutNGBlockFlow() && m_layoutBox->needsLayout()) { |
46 toLayoutNGBlockFlow(m_layoutBox)->LayoutBlockFlow::layoutBlock(true); | 48 toLayoutNGBlockFlow(m_layoutBox)->LayoutBlockFlow::layoutBlock(true); |
47 } else { | 49 } else { |
48 m_layoutBox->layoutIfNeeded(); | 50 m_layoutBox->layoutIfNeeded(); |
49 } | 51 } |
50 LayoutRect overflow = m_layoutBox->layoutOverflowRect(); | 52 LayoutRect overflow = m_layoutBox->layoutOverflowRect(); |
51 // TODO(layout-ng): This does not handle writing modes correctly (for | 53 // TODO(layout-ng): This does not handle writing modes correctly (for |
52 // overflow & the enums) | 54 // overflow & the enums) |
53 NGFragmentBuilder builder(NGFragmentBase::FragmentBox); | 55 NGFragmentBuilder builder(NGFragmentBase::FragmentBox); |
54 builder.SetInlineSize(m_layoutBox->logicalWidth()) | 56 builder.SetInlineSize(m_layoutBox->logicalWidth()) |
55 .SetBlockSize(m_layoutBox->logicalHeight()) | 57 .SetBlockSize(m_layoutBox->logicalHeight()) |
56 .SetInlineOverflow(overflow.width()) | 58 .SetInlineOverflow(overflow.width()) |
57 .SetBlockOverflow(overflow.height()); | 59 .SetBlockOverflow(overflow.height()); |
58 fragment = builder.ToFragment(); | 60 fragment = builder.ToFragment(); |
59 } | 61 } |
60 return fragment; | 62 *out = fragment; |
| 63 return true; |
61 } | 64 } |
62 | 65 |
63 const ComputedStyle* NGBox::style() const { | 66 const ComputedStyle* NGBox::style() const { |
64 return m_layoutBox->style(); | 67 return m_layoutBox->style(); |
65 } | 68 } |
66 | 69 |
67 NGBoxIterator NGBox::childIterator() { | 70 NGBoxIterator NGBox::childIterator() { |
68 return NGBoxIterator(firstChild()); | 71 return NGBoxIterator(firstChild()); |
69 } | 72 } |
70 | 73 |
(...skipping 11 matching lines...) Expand all Loading... |
82 } | 85 } |
83 | 86 |
84 bool NGBox::canUseNewLayout() { | 87 bool NGBox::canUseNewLayout() { |
85 if (!m_layoutBox) | 88 if (!m_layoutBox) |
86 return true; | 89 return true; |
87 if (m_layoutBox->isLayoutBlockFlow() && !m_layoutBox->childrenInline()) | 90 if (m_layoutBox->isLayoutBlockFlow() && !m_layoutBox->childrenInline()) |
88 return true; | 91 return true; |
89 return false; | 92 return false; |
90 } | 93 } |
91 } // namespace blink | 94 } // namespace blink |
OLD | NEW |