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_constraint_space.h" | 5 #include "core/layout/ng/ng_constraint_space.h" |
6 | 6 |
7 #include "core/layout/LayoutBlock.h" | 7 #include "core/layout/LayoutBlock.h" |
8 #include "core/layout/LayoutView.h" | 8 #include "core/layout/LayoutView.h" |
9 #include "core/layout/ng/ng_layout_opportunity_iterator.h" | 9 #include "core/layout/ng/ng_layout_opportunity_iterator.h" |
10 #include "core/layout/ng/ng_units.h" | 10 #include "core/layout/ng/ng_units.h" |
11 | 11 |
12 namespace blink { | 12 namespace blink { |
13 | 13 |
14 NGConstraintSpace::NGConstraintSpace(NGWritingMode writing_mode, | 14 NGConstraintSpace::NGConstraintSpace(NGWritingMode writing_mode, |
15 NGDirection direction, | 15 NGDirection direction, |
16 NGLogicalSize container_size) | 16 NGLogicalSize container_size) |
17 : physical_space_(new NGPhysicalConstraintSpace( | 17 : physical_space_(new NGPhysicalConstraintSpace( |
18 container_size.ConvertToPhysical(writing_mode))), | 18 container_size.ConvertToPhysical(writing_mode))), |
19 size_(container_size), | 19 size_(container_size), |
20 writing_mode_(writing_mode), | 20 writing_mode_(writing_mode), |
21 direction_(direction), | 21 direction_(direction) {} |
22 is_new_fc_(false) {} | |
23 | 22 |
24 NGConstraintSpace::NGConstraintSpace(NGWritingMode writing_mode, | 23 NGConstraintSpace::NGConstraintSpace(NGWritingMode writing_mode, |
25 NGDirection direction, | 24 NGDirection direction, |
26 NGPhysicalConstraintSpace* physical_space) | 25 NGPhysicalConstraintSpace* physical_space) |
27 : physical_space_(physical_space), | 26 : physical_space_(physical_space), |
28 size_(physical_space->ContainerSize().ConvertToLogical(writing_mode)), | 27 size_(physical_space->ContainerSize().ConvertToLogical(writing_mode)), |
29 writing_mode_(writing_mode), | 28 writing_mode_(writing_mode), |
30 direction_(direction), | 29 direction_(direction) {} |
31 is_new_fc_(false) {} | |
32 | 30 |
33 NGConstraintSpace::NGConstraintSpace(NGWritingMode writing_mode, | 31 NGConstraintSpace::NGConstraintSpace(NGWritingMode writing_mode, |
34 NGDirection direction, | 32 NGDirection direction, |
35 const NGConstraintSpace* constraint_space) | 33 const NGConstraintSpace* constraint_space) |
36 : physical_space_(constraint_space->PhysicalSpace()), | 34 : physical_space_(constraint_space->PhysicalSpace()), |
37 offset_(constraint_space->Offset()), | 35 offset_(constraint_space->Offset()), |
38 size_(constraint_space->Size()), | 36 size_(constraint_space->Size()), |
39 writing_mode_(writing_mode), | 37 writing_mode_(writing_mode), |
40 direction_(direction), | 38 direction_(direction) {} |
41 is_new_fc_(false) {} | |
42 | 39 |
43 NGConstraintSpace::NGConstraintSpace(const NGConstraintSpace& other, | 40 NGConstraintSpace::NGConstraintSpace(const NGConstraintSpace& other, |
44 NGLogicalOffset offset, | 41 NGLogicalOffset offset, |
45 NGLogicalSize size) | 42 NGLogicalSize size) |
46 : physical_space_(other.PhysicalSpace()), | 43 : physical_space_(other.PhysicalSpace()), |
47 offset_(offset), | 44 offset_(offset), |
48 size_(size), | 45 size_(size), |
49 writing_mode_(other.WritingMode()), | 46 writing_mode_(other.WritingMode()), |
50 direction_(other.Direction()), | 47 direction_(other.Direction()) {} |
51 is_new_fc_(false) {} | |
52 | 48 |
53 NGConstraintSpace::NGConstraintSpace(NGWritingMode writing_mode, | 49 NGConstraintSpace::NGConstraintSpace(NGWritingMode writing_mode, |
54 NGDirection direction, | 50 NGDirection direction, |
55 const NGConstraintSpace& other, | 51 const NGConstraintSpace& other, |
56 NGLogicalSize size) | 52 NGLogicalSize size) |
57 : size_(size), | 53 : size_(size), writing_mode_(writing_mode), direction_(direction) { |
58 writing_mode_(writing_mode), | |
59 direction_(direction), | |
60 is_new_fc_(false) { | |
61 physical_space_ = | 54 physical_space_ = |
62 new NGPhysicalConstraintSpace(size.ConvertToPhysical(writing_mode)); | 55 new NGPhysicalConstraintSpace(size.ConvertToPhysical(writing_mode)); |
63 for (const auto& exclusion : other.PhysicalSpace()->Exclusions()) { | 56 for (const auto& exclusion : other.PhysicalSpace()->Exclusions()) { |
64 physical_space_->AddExclusion(exclusion); | 57 physical_space_->AddExclusion(exclusion); |
65 } | 58 } |
66 } | 59 } |
67 | 60 |
68 NGConstraintSpace* NGConstraintSpace::CreateFromLayoutObject( | 61 NGConstraintSpace* NGConstraintSpace::CreateFromLayoutObject( |
69 const LayoutBox& box) { | 62 const LayoutBox& box) { |
70 bool fixed_inline = false, fixed_block = false; | 63 bool fixed_inline = false, fixed_block = false, is_new_fc = false; |
71 // XXX for orthogonal writing mode this is not right | 64 // XXX for orthogonal writing mode this is not right |
72 LayoutUnit container_logical_width = | 65 LayoutUnit container_logical_width = |
73 std::max(LayoutUnit(), box.containingBlockLogicalWidthForContent()); | 66 std::max(LayoutUnit(), box.containingBlockLogicalWidthForContent()); |
74 LayoutUnit container_logical_height; | 67 LayoutUnit container_logical_height; |
75 if (!box.parent()) { | 68 if (!box.parent()) { |
76 container_logical_height = box.view()->viewLogicalHeightForPercentages(); | 69 container_logical_height = box.view()->viewLogicalHeightForPercentages(); |
77 } else if (box.containingBlock()) { | 70 } else if (box.containingBlock()) { |
78 container_logical_height = | 71 container_logical_height = |
79 box.containingBlock()->availableLogicalHeightForPercentageComputation(); | 72 box.containingBlock()->availableLogicalHeightForPercentageComputation(); |
80 } | 73 } |
81 // When we have an override size, the container_logical_{width,height} will be | 74 // When we have an override size, the container_logical_{width,height} will be |
82 // used as the final size of the box, so it has to include border and | 75 // used as the final size of the box, so it has to include border and |
83 // padding. | 76 // padding. |
84 if (box.hasOverrideLogicalContentWidth()) { | 77 if (box.hasOverrideLogicalContentWidth()) { |
85 container_logical_width = | 78 container_logical_width = |
86 box.borderAndPaddingLogicalWidth() + box.overrideLogicalContentWidth(); | 79 box.borderAndPaddingLogicalWidth() + box.overrideLogicalContentWidth(); |
87 fixed_inline = true; | 80 fixed_inline = true; |
88 } | 81 } |
89 if (box.hasOverrideLogicalContentHeight()) { | 82 if (box.hasOverrideLogicalContentHeight()) { |
90 container_logical_height = box.borderAndPaddingLogicalHeight() + | 83 container_logical_height = box.borderAndPaddingLogicalHeight() + |
91 box.overrideLogicalContentHeight(); | 84 box.overrideLogicalContentHeight(); |
92 fixed_block = true; | 85 fixed_block = true; |
93 } | 86 } |
94 | 87 |
| 88 if (box.isLayoutBlock() && toLayoutBlock(box).createsNewFormattingContext()) |
| 89 is_new_fc = true; |
| 90 |
95 NGConstraintSpace* derived_constraint_space = new NGConstraintSpace( | 91 NGConstraintSpace* derived_constraint_space = new NGConstraintSpace( |
96 FromPlatformWritingMode(box.styleRef().getWritingMode()), | 92 FromPlatformWritingMode(box.styleRef().getWritingMode()), |
97 FromPlatformDirection(box.styleRef().direction()), | 93 FromPlatformDirection(box.styleRef().direction()), |
98 NGLogicalSize(container_logical_width, container_logical_height)); | 94 NGLogicalSize(container_logical_width, container_logical_height)); |
99 derived_constraint_space->SetOverflowTriggersScrollbar( | 95 derived_constraint_space->SetOverflowTriggersScrollbar( |
100 box.styleRef().overflowInlineDirection() == OverflowAuto, | 96 box.styleRef().overflowInlineDirection() == OverflowAuto, |
101 box.styleRef().overflowBlockDirection() == OverflowAuto); | 97 box.styleRef().overflowBlockDirection() == OverflowAuto); |
102 derived_constraint_space->SetFixedSize(fixed_inline, fixed_block); | 98 derived_constraint_space->SetFixedSize(fixed_inline, fixed_block); |
| 99 derived_constraint_space->SetIsNewFormattingContext(is_new_fc); |
| 100 |
103 return derived_constraint_space; | 101 return derived_constraint_space; |
104 } | 102 } |
105 | 103 |
106 NGLogicalSize NGConstraintSpace::ContainerSize() const { | 104 NGLogicalSize NGConstraintSpace::ContainerSize() const { |
107 return physical_space_->container_size_.ConvertToLogical( | 105 return physical_space_->container_size_.ConvertToLogical( |
108 static_cast<NGWritingMode>(writing_mode_)); | 106 static_cast<NGWritingMode>(writing_mode_)); |
109 } | 107 } |
110 | 108 |
| 109 bool NGConstraintSpace::IsNewFormattingContext() const { |
| 110 return physical_space_->is_new_fc_; |
| 111 } |
| 112 |
111 bool NGConstraintSpace::InlineTriggersScrollbar() const { | 113 bool NGConstraintSpace::InlineTriggersScrollbar() const { |
112 return writing_mode_ == HorizontalTopBottom | 114 return writing_mode_ == HorizontalTopBottom |
113 ? physical_space_->width_direction_triggers_scrollbar_ | 115 ? physical_space_->width_direction_triggers_scrollbar_ |
114 : physical_space_->height_direction_triggers_scrollbar_; | 116 : physical_space_->height_direction_triggers_scrollbar_; |
115 } | 117 } |
116 | 118 |
117 bool NGConstraintSpace::BlockTriggersScrollbar() const { | 119 bool NGConstraintSpace::BlockTriggersScrollbar() const { |
118 return writing_mode_ == HorizontalTopBottom | 120 return writing_mode_ == HorizontalTopBottom |
119 ? physical_space_->height_direction_triggers_scrollbar_ | 121 ? physical_space_->height_direction_triggers_scrollbar_ |
120 : physical_space_->width_direction_triggers_scrollbar_; | 122 : physical_space_->width_direction_triggers_scrollbar_; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 FragmentNone); | 179 FragmentNone); |
178 physical_space_->height_direction_fragmentation_type_ = type; | 180 physical_space_->height_direction_fragmentation_type_ = type; |
179 } else { | 181 } else { |
180 DCHECK_EQ(static_cast<NGFragmentationType>( | 182 DCHECK_EQ(static_cast<NGFragmentationType>( |
181 physical_space_->height_direction_fragmentation_type_), | 183 physical_space_->height_direction_fragmentation_type_), |
182 FragmentNone); | 184 FragmentNone); |
183 physical_space_->width_direction_triggers_scrollbar_ = type; | 185 physical_space_->width_direction_triggers_scrollbar_ = type; |
184 } | 186 } |
185 } | 187 } |
186 | 188 |
| 189 void NGConstraintSpace::SetIsNewFormattingContext(bool is_new_fc) { |
| 190 physical_space_->is_new_fc_ = is_new_fc; |
| 191 } |
| 192 |
187 String NGConstraintSpace::ToString() const { | 193 String NGConstraintSpace::ToString() const { |
188 return String::format("%s,%s %sx%s", | 194 return String::format("%s,%s %sx%s", |
189 offset_.inline_offset.toString().ascii().data(), | 195 offset_.inline_offset.toString().ascii().data(), |
190 offset_.block_offset.toString().ascii().data(), | 196 offset_.block_offset.toString().ascii().data(), |
191 size_.inline_size.toString().ascii().data(), | 197 size_.inline_size.toString().ascii().data(), |
192 size_.block_size.toString().ascii().data()); | 198 size_.block_size.toString().ascii().data()); |
193 } | 199 } |
194 | 200 |
195 } // namespace blink | 201 } // namespace blink |
OLD | NEW |