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" |
11 #include "core/layout/ng/ng_direction.h" | 11 #include "core/layout/ng/ng_direction.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_length_utils.h" | 14 #include "core/layout/ng/ng_length_utils.h" |
15 #include "core/layout/ng/ng_writing_mode.h" | 15 #include "core/layout/ng/ng_writing_mode.h" |
16 | 16 |
17 namespace blink { | 17 namespace blink { |
| 18 namespace { |
| 19 // TODO(layout-ng): Add m_isNewFc flag to ComputedStyle and set it from |
| 20 // StyleResolver instead of getting it calculated by createsNewFormattingContext |
| 21 bool IsNewFormattingContext(const LayoutBox* layout_box) { |
| 22 return layout_box && toLayoutBlock(layout_box)->createsNewFormattingContext(); |
| 23 } |
| 24 } // namespace |
| 25 |
18 NGBox::NGBox(LayoutObject* layout_object) | 26 NGBox::NGBox(LayoutObject* layout_object) |
19 : layout_box_(toLayoutBox(layout_object)) { | 27 : layout_box_(toLayoutBox(layout_object)) { |
20 DCHECK(layout_box_); | 28 DCHECK(layout_box_); |
21 } | 29 } |
22 | 30 |
23 NGBox::NGBox(ComputedStyle* style) : layout_box_(nullptr), style_(style) { | 31 NGBox::NGBox(ComputedStyle* style) : layout_box_(nullptr), style_(style) { |
24 DCHECK(style_); | 32 DCHECK(style_); |
25 } | 33 } |
26 | 34 |
27 bool NGBox::Layout(const NGConstraintSpace* constraint_space, | 35 bool NGBox::Layout(const NGConstraintSpace* constraint_space, |
28 NGFragment** out) { | 36 NGFragment** out) { |
29 if (layout_box_ && layout_box_->isOutOfFlowPositioned()) | 37 if (layout_box_ && layout_box_->isOutOfFlowPositioned()) |
30 layout_box_->containingBlock()->insertPositionedObject(layout_box_); | 38 layout_box_->containingBlock()->insertPositionedObject(layout_box_); |
31 // We can either use the new layout code to do the layout and then copy the | 39 // We can either use the new layout code to do the layout and then copy the |
32 // resulting size to the LayoutObject, or use the old layout code and | 40 // resulting size to the LayoutObject, or use the old layout code and |
33 // synthesize a fragment. | 41 // synthesize a fragment. |
34 if (CanUseNewLayout()) { | 42 if (CanUseNewLayout()) { |
35 if (!algorithm_) | 43 if (!algorithm_) |
36 algorithm_ = new NGBlockLayoutAlgorithm(Style(), FirstChild()); | 44 algorithm_ = new NGBlockLayoutAlgorithm(Style(), FirstChild()); |
37 // Change the coordinate system of the constraint space. | 45 // Change the coordinate system of the constraint space. |
38 NGConstraintSpace* child_constraint_space = new NGConstraintSpace( | 46 NGConstraintSpace* child_constraint_space = new NGConstraintSpace( |
39 FromPlatformWritingMode(Style()->getWritingMode()), | 47 FromPlatformWritingMode(Style()->getWritingMode()), |
40 FromPlatformDirection(Style()->direction()), constraint_space); | 48 FromPlatformDirection(Style()->direction()), constraint_space); |
| 49 child_constraint_space->SetIsNewFormattingContext( |
| 50 IsNewFormattingContext(layout_box_)); |
41 | 51 |
42 NGPhysicalFragment* fragment = nullptr; | 52 NGPhysicalFragment* fragment = nullptr; |
43 if (!algorithm_->Layout(child_constraint_space, &fragment)) | 53 if (!algorithm_->Layout(child_constraint_space, &fragment)) |
44 return false; | 54 return false; |
45 fragment_ = fragment; | 55 fragment_ = fragment; |
46 | 56 |
47 if (layout_box_) { | 57 if (layout_box_) { |
48 layout_box_->setWidth(fragment_->Width()); | 58 layout_box_->setWidth(fragment_->Width()); |
49 layout_box_->setHeight(fragment_->Height()); | 59 layout_box_->setHeight(fragment_->Height()); |
50 NGBoxStrut border_and_padding = | 60 NGBoxStrut border_and_padding = |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 | 159 |
150 bool NGBox::CanUseNewLayout() { | 160 bool NGBox::CanUseNewLayout() { |
151 if (!layout_box_) | 161 if (!layout_box_) |
152 return true; | 162 return true; |
153 if (!layout_box_->isLayoutBlockFlow()) | 163 if (!layout_box_->isLayoutBlockFlow()) |
154 return false; | 164 return false; |
155 const LayoutBlockFlow* block_flow = toLayoutBlockFlow(layout_box_); | 165 const LayoutBlockFlow* block_flow = toLayoutBlockFlow(layout_box_); |
156 return !block_flow->childrenInline() || !block_flow->firstChild(); | 166 return !block_flow->childrenInline() || !block_flow->firstChild(); |
157 } | 167 } |
158 } // namespace blink | 168 } // namespace blink |
OLD | NEW |