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/LayoutBlockFlow.h" | 7 #include "core/layout/LayoutBlockFlow.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_constraint_space.h" | 10 #include "core/layout/ng/ng_constraint_space.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 FromPlatformDirection(Style()->direction()), constraint_space); | 48 FromPlatformDirection(Style()->direction()), constraint_space); |
49 child_constraint_space->SetIsNewFormattingContext( | 49 child_constraint_space->SetIsNewFormattingContext( |
50 IsNewFormattingContext(layout_box_)); | 50 IsNewFormattingContext(layout_box_)); |
51 | 51 |
52 NGPhysicalFragment* fragment = nullptr; | 52 NGPhysicalFragment* fragment = nullptr; |
53 if (!algorithm_->Layout(child_constraint_space, &fragment)) | 53 if (!algorithm_->Layout(child_constraint_space, &fragment)) |
54 return false; | 54 return false; |
55 fragment_ = fragment; | 55 fragment_ = fragment; |
56 | 56 |
57 if (layout_box_) { | 57 if (layout_box_) { |
58 layout_box_->setWidth(fragment_->Width()); | 58 CopyFragmentDataToLayoutBox(*constraint_space); |
59 layout_box_->setHeight(fragment_->Height()); | |
60 NGBoxStrut border_and_padding = | |
61 computeBorders(*Style()) + | |
62 computePadding(*constraint_space, *Style()); | |
63 LayoutUnit intrinsic_logical_height = | |
64 layout_box_->style()->isHorizontalWritingMode() | |
65 ? fragment_->HeightOverflow() | |
66 : fragment_->WidthOverflow(); | |
67 intrinsic_logical_height -= border_and_padding.BlockSum(); | |
68 layout_box_->setIntrinsicContentLogicalHeight(intrinsic_logical_height); | |
69 | |
70 // Ensure the position of the children are copied across to the | |
71 // LayoutObject tree. | |
72 for (NGBox* box = FirstChild(); box; box = box->NextSibling()) { | |
73 if (box->fragment_) | |
74 box->PositionUpdated(); | |
75 } | |
76 | |
77 if (layout_box_->isLayoutBlock()) | |
78 toLayoutBlock(layout_box_)->layoutPositionedObjects(true); | |
79 layout_box_->clearNeedsLayout(); | |
80 if (layout_box_->isLayoutBlockFlow()) { | |
81 toLayoutBlockFlow(layout_box_)->updateIsSelfCollapsing(); | |
82 } | |
83 } | 59 } |
84 } else { | 60 } else { |
85 DCHECK(layout_box_); | 61 DCHECK(layout_box_); |
86 // TODO(layout-ng): If fixedSize is true, set the override width/height too | 62 fragment_ = RunOldLayout(*constraint_space); |
87 NGLogicalSize container_size = constraint_space->ContainerSize(); | |
88 layout_box_->setOverrideContainingBlockContentLogicalWidth( | |
89 container_size.inline_size); | |
90 layout_box_->setOverrideContainingBlockContentLogicalHeight( | |
91 container_size.block_size); | |
92 if (layout_box_->isLayoutNGBlockFlow() && layout_box_->needsLayout()) { | |
93 toLayoutNGBlockFlow(layout_box_)->LayoutBlockFlow::layoutBlock(true); | |
94 } else { | |
95 layout_box_->forceLayout(); | |
96 } | |
97 LayoutRect overflow = layout_box_->layoutOverflowRect(); | |
98 // TODO(layout-ng): This does not handle writing modes correctly (for | |
99 // overflow) | |
100 NGFragmentBuilder builder(NGPhysicalFragmentBase::FragmentBox); | |
101 builder.SetInlineSize(layout_box_->logicalWidth()) | |
102 .SetBlockSize(layout_box_->logicalHeight()) | |
103 .SetDirection( | |
104 FromPlatformDirection(layout_box_->styleRef().direction())) | |
105 .SetWritingMode( | |
106 FromPlatformWritingMode(layout_box_->styleRef().getWritingMode())) | |
107 .SetInlineOverflow(overflow.width()) | |
108 .SetBlockOverflow(overflow.height()); | |
109 fragment_ = builder.ToFragment(); | |
110 } | 63 } |
111 *out = new NGFragment(constraint_space->WritingMode(), | 64 *out = new NGFragment(constraint_space->WritingMode(), |
112 FromPlatformDirection(Style()->direction()), | 65 FromPlatformDirection(Style()->direction()), |
113 fragment_.get()); | 66 fragment_.get()); |
114 // Reset algorithm for future use | 67 // Reset algorithm for future use |
115 algorithm_ = nullptr; | 68 algorithm_ = nullptr; |
116 return true; | 69 return true; |
117 } | 70 } |
118 | 71 |
119 const ComputedStyle* NGBox::Style() const { | 72 const ComputedStyle* NGBox::Style() const { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 } | 111 } |
159 | 112 |
160 bool NGBox::CanUseNewLayout() { | 113 bool NGBox::CanUseNewLayout() { |
161 if (!layout_box_) | 114 if (!layout_box_) |
162 return true; | 115 return true; |
163 if (!layout_box_->isLayoutBlockFlow()) | 116 if (!layout_box_->isLayoutBlockFlow()) |
164 return false; | 117 return false; |
165 const LayoutBlockFlow* block_flow = toLayoutBlockFlow(layout_box_); | 118 const LayoutBlockFlow* block_flow = toLayoutBlockFlow(layout_box_); |
166 return !block_flow->childrenInline() || !block_flow->firstChild(); | 119 return !block_flow->childrenInline() || !block_flow->firstChild(); |
167 } | 120 } |
| 121 |
| 122 void NGBox::CopyFragmentDataToLayoutBox( |
| 123 const NGConstraintSpace& constraint_space) { |
| 124 DCHECK(layout_box_); |
| 125 layout_box_->setWidth(fragment_->Width()); |
| 126 layout_box_->setHeight(fragment_->Height()); |
| 127 NGBoxStrut border_and_padding = |
| 128 computeBorders(*Style()) + computePadding(constraint_space, *Style()); |
| 129 LayoutUnit intrinsic_logical_height = |
| 130 layout_box_->style()->isHorizontalWritingMode() |
| 131 ? fragment_->HeightOverflow() |
| 132 : fragment_->WidthOverflow(); |
| 133 intrinsic_logical_height -= border_and_padding.BlockSum(); |
| 134 layout_box_->setIntrinsicContentLogicalHeight(intrinsic_logical_height); |
| 135 |
| 136 // Ensure the position of the children are copied across to the |
| 137 // LayoutObject tree. |
| 138 for (NGBox* box = FirstChild(); box; box = box->NextSibling()) { |
| 139 if (box->fragment_) |
| 140 box->PositionUpdated(); |
| 141 } |
| 142 |
| 143 if (layout_box_->isLayoutBlock()) |
| 144 toLayoutBlock(layout_box_)->layoutPositionedObjects(true); |
| 145 layout_box_->clearNeedsLayout(); |
| 146 if (layout_box_->isLayoutBlockFlow()) { |
| 147 toLayoutBlockFlow(layout_box_)->updateIsSelfCollapsing(); |
| 148 } |
| 149 } |
| 150 |
| 151 NGPhysicalFragment* NGBox::RunOldLayout( |
| 152 const NGConstraintSpace& constraint_space) { |
| 153 // TODO(layout-ng): If fixedSize is true, set the override width/height too |
| 154 NGLogicalSize container_size = constraint_space.ContainerSize(); |
| 155 layout_box_->setOverrideContainingBlockContentLogicalWidth( |
| 156 container_size.inline_size); |
| 157 layout_box_->setOverrideContainingBlockContentLogicalHeight( |
| 158 container_size.block_size); |
| 159 if (layout_box_->isLayoutNGBlockFlow() && layout_box_->needsLayout()) { |
| 160 toLayoutNGBlockFlow(layout_box_)->LayoutBlockFlow::layoutBlock(true); |
| 161 } else { |
| 162 layout_box_->forceLayout(); |
| 163 } |
| 164 LayoutRect overflow = layout_box_->layoutOverflowRect(); |
| 165 // TODO(layout-ng): This does not handle writing modes correctly (for |
| 166 // overflow) |
| 167 NGFragmentBuilder builder(NGPhysicalFragmentBase::FragmentBox); |
| 168 builder.SetInlineSize(layout_box_->logicalWidth()) |
| 169 .SetBlockSize(layout_box_->logicalHeight()) |
| 170 .SetDirection(FromPlatformDirection(layout_box_->styleRef().direction())) |
| 171 .SetWritingMode( |
| 172 FromPlatformWritingMode(layout_box_->styleRef().getWritingMode())) |
| 173 .SetInlineOverflow(overflow.width()) |
| 174 .SetBlockOverflow(overflow.height()); |
| 175 return builder.ToFragment(); |
| 176 } |
| 177 |
168 } // namespace blink | 178 } // namespace blink |
OLD | NEW |