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 |
26 NGBox::NGBox(LayoutObject* layout_object) | 19 NGBox::NGBox(LayoutObject* layout_object) |
27 : layout_box_(toLayoutBox(layout_object)) { | 20 : layout_box_(toLayoutBox(layout_object)) { |
28 DCHECK(layout_box_); | 21 DCHECK(layout_box_); |
29 } | 22 } |
30 | 23 |
31 NGBox::NGBox(ComputedStyle* style) : layout_box_(nullptr), style_(style) { | 24 NGBox::NGBox(ComputedStyle* style) : layout_box_(nullptr), style_(style) { |
32 DCHECK(style_); | 25 DCHECK(style_); |
33 } | 26 } |
34 | 27 |
35 bool NGBox::Layout(const NGConstraintSpace* constraint_space, | 28 bool NGBox::Layout(const NGConstraintSpace* constraint_space, |
36 NGFragment** out) { | 29 NGFragment** out) { |
37 if (layout_box_ && layout_box_->isOutOfFlowPositioned()) | 30 if (layout_box_ && layout_box_->isOutOfFlowPositioned()) |
38 layout_box_->containingBlock()->insertPositionedObject(layout_box_); | 31 layout_box_->containingBlock()->insertPositionedObject(layout_box_); |
39 // We can either use the new layout code to do the layout and then copy the | 32 // We can either use the new layout code to do the layout and then copy the |
40 // resulting size to the LayoutObject, or use the old layout code and | 33 // resulting size to the LayoutObject, or use the old layout code and |
41 // synthesize a fragment. | 34 // synthesize a fragment. |
42 if (CanUseNewLayout()) { | 35 if (CanUseNewLayout()) { |
43 if (!algorithm_) | 36 if (!algorithm_) |
44 algorithm_ = new NGBlockLayoutAlgorithm(Style(), FirstChild()); | 37 algorithm_ = new NGBlockLayoutAlgorithm(Style(), FirstChild()); |
45 // Change the coordinate system of the constraint space. | 38 // Change the coordinate system of the constraint space. |
46 NGConstraintSpace* child_constraint_space = new NGConstraintSpace( | 39 NGConstraintSpace* child_constraint_space = new NGConstraintSpace( |
47 FromPlatformWritingMode(Style()->getWritingMode()), | 40 FromPlatformWritingMode(Style()->getWritingMode()), |
48 FromPlatformDirection(Style()->direction()), constraint_space); | 41 FromPlatformDirection(Style()->direction()), constraint_space); |
49 child_constraint_space->SetIsNewFormattingContext( | |
50 IsNewFormattingContext(layout_box_)); | |
51 | 42 |
52 NGPhysicalFragment* fragment = nullptr; | 43 NGPhysicalFragment* fragment = nullptr; |
53 if (!algorithm_->Layout(child_constraint_space, &fragment)) | 44 if (!algorithm_->Layout(child_constraint_space, &fragment)) |
54 return false; | 45 return false; |
55 fragment_ = fragment; | 46 fragment_ = fragment; |
56 | 47 |
57 if (layout_box_) { | 48 if (layout_box_) { |
58 CopyFragmentDataToLayoutBox(*constraint_space); | 49 CopyFragmentDataToLayoutBox(*constraint_space); |
59 } | 50 } |
60 } else { | 51 } else { |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 .SetBlockSize(layout_box_->logicalHeight()) | 170 .SetBlockSize(layout_box_->logicalHeight()) |
180 .SetDirection(FromPlatformDirection(layout_box_->styleRef().direction())) | 171 .SetDirection(FromPlatformDirection(layout_box_->styleRef().direction())) |
181 .SetWritingMode( | 172 .SetWritingMode( |
182 FromPlatformWritingMode(layout_box_->styleRef().getWritingMode())) | 173 FromPlatformWritingMode(layout_box_->styleRef().getWritingMode())) |
183 .SetInlineOverflow(overflow.width()) | 174 .SetInlineOverflow(overflow.width()) |
184 .SetBlockOverflow(overflow.height()); | 175 .SetBlockOverflow(overflow.height()); |
185 return builder.ToFragment(); | 176 return builder.ToFragment(); |
186 } | 177 } |
187 | 178 |
188 } // namespace blink | 179 } // namespace blink |
OLD | NEW |