| 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_(container_size.ConvertToPhysical(writing_mode)), |
| 18 container_size.ConvertToPhysical(writing_mode))), | |
| 19 size_(container_size), | 18 size_(container_size), |
| 20 writing_mode_(writing_mode), | 19 writing_mode_(writing_mode), |
| 21 direction_(direction) {} | 20 direction_(direction) {} |
| 22 | 21 |
| 23 NGConstraintSpace::NGConstraintSpace(NGWritingMode writing_mode, | 22 NGConstraintSpace::NGConstraintSpace(NGWritingMode writing_mode, |
| 24 NGDirection direction, | 23 NGDirection direction, |
| 25 NGPhysicalConstraintSpace* physical_space) | 24 NGPhysicalConstraintSpace* physical_space) |
| 26 : physical_space_(physical_space), | 25 : physical_space_(*physical_space), |
| 27 size_(physical_space->ContainerSize().ConvertToLogical(writing_mode)), | 26 size_(physical_space->ContainerSize().ConvertToLogical(writing_mode)), |
| 28 writing_mode_(writing_mode), | 27 writing_mode_(writing_mode), |
| 29 direction_(direction) {} | 28 direction_(direction) {} |
| 30 | 29 |
| 31 NGConstraintSpace::NGConstraintSpace(NGWritingMode writing_mode, | 30 NGConstraintSpace::NGConstraintSpace(NGWritingMode writing_mode, |
| 32 NGDirection direction, | 31 NGDirection direction, |
| 33 const NGConstraintSpace* constraint_space) | 32 const NGConstraintSpace* constraint_space) |
| 34 : physical_space_(constraint_space->PhysicalSpace()), | 33 : physical_space_(constraint_space->PhysicalSpace()), |
| 35 offset_(constraint_space->Offset()), | 34 offset_(constraint_space->Offset()), |
| 36 size_(constraint_space->Size()), | 35 size_(constraint_space->Size()), |
| 37 writing_mode_(writing_mode), | 36 writing_mode_(writing_mode), |
| 38 direction_(direction) {} | 37 direction_(direction) {} |
| 39 | 38 |
| 40 NGConstraintSpace::NGConstraintSpace(const NGConstraintSpace& other, | 39 NGConstraintSpace::NGConstraintSpace(const NGConstraintSpace& other, |
| 41 NGLogicalOffset offset, | 40 NGLogicalOffset offset, |
| 42 NGLogicalSize size) | 41 NGLogicalSize size) |
| 43 : physical_space_(other.PhysicalSpace()), | 42 : physical_space_(other.PhysicalSpace()), |
| 44 offset_(offset), | 43 offset_(offset), |
| 45 size_(size), | 44 size_(size), |
| 46 writing_mode_(other.WritingMode()), | 45 writing_mode_(other.WritingMode()), |
| 47 direction_(other.Direction()) {} | 46 direction_(other.Direction()) {} |
| 48 | 47 |
| 49 NGConstraintSpace::NGConstraintSpace(NGWritingMode writing_mode, | 48 NGConstraintSpace::NGConstraintSpace(NGWritingMode writing_mode, |
| 50 NGDirection direction, | 49 NGDirection direction, |
| 51 const NGConstraintSpace& other, | 50 const NGConstraintSpace& other, |
| 52 NGLogicalSize size) | 51 NGLogicalSize size) |
| 53 : size_(size), writing_mode_(writing_mode), direction_(direction) { | 52 : physical_space_(size.ConvertToPhysical(writing_mode)), |
| 54 physical_space_ = | 53 size_(size), |
| 55 new NGPhysicalConstraintSpace(size.ConvertToPhysical(writing_mode)); | 54 writing_mode_(writing_mode), |
| 56 for (const NGExclusion& exclusion : other.PhysicalSpace()->Exclusions()) { | 55 direction_(direction) { |
| 57 physical_space_->AddExclusion(exclusion); | 56 for (const NGExclusion& exclusion : other.PhysicalSpace().Exclusions()) { |
| 57 physical_space_.AddExclusion(exclusion); |
| 58 } | 58 } |
| 59 } | 59 } |
| 60 | 60 |
| 61 NGConstraintSpace* NGConstraintSpace::CreateFromLayoutObject( | 61 NGConstraintSpace* NGConstraintSpace::CreateFromLayoutObject( |
| 62 const LayoutBox& box) { | 62 const LayoutBox& box) { |
| 63 bool fixed_inline = false, fixed_block = false; | 63 bool fixed_inline = false, fixed_block = false; |
| 64 // XXX for orthogonal writing mode this is not right | 64 // XXX for orthogonal writing mode this is not right |
| 65 LayoutUnit container_logical_width = | 65 LayoutUnit container_logical_width = |
| 66 std::max(LayoutUnit(), box.containingBlockLogicalWidthForContent()); | 66 std::max(LayoutUnit(), box.containingBlockLogicalWidthForContent()); |
| 67 LayoutUnit container_logical_height; | 67 LayoutUnit container_logical_height; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 90 FromPlatformDirection(box.styleRef().direction()), | 90 FromPlatformDirection(box.styleRef().direction()), |
| 91 NGLogicalSize(container_logical_width, container_logical_height)); | 91 NGLogicalSize(container_logical_width, container_logical_height)); |
| 92 derived_constraint_space->SetOverflowTriggersScrollbar( | 92 derived_constraint_space->SetOverflowTriggersScrollbar( |
| 93 box.styleRef().overflowInlineDirection() == OverflowAuto, | 93 box.styleRef().overflowInlineDirection() == OverflowAuto, |
| 94 box.styleRef().overflowBlockDirection() == OverflowAuto); | 94 box.styleRef().overflowBlockDirection() == OverflowAuto); |
| 95 derived_constraint_space->SetFixedSize(fixed_inline, fixed_block); | 95 derived_constraint_space->SetFixedSize(fixed_inline, fixed_block); |
| 96 return derived_constraint_space; | 96 return derived_constraint_space; |
| 97 } | 97 } |
| 98 | 98 |
| 99 NGLogicalSize NGConstraintSpace::ContainerSize() const { | 99 NGLogicalSize NGConstraintSpace::ContainerSize() const { |
| 100 return physical_space_->container_size_.ConvertToLogical( | 100 return physical_space_.container_size_.ConvertToLogical( |
| 101 static_cast<NGWritingMode>(writing_mode_)); | 101 static_cast<NGWritingMode>(writing_mode_)); |
| 102 } | 102 } |
| 103 | 103 |
| 104 bool NGConstraintSpace::InlineTriggersScrollbar() const { | 104 bool NGConstraintSpace::InlineTriggersScrollbar() const { |
| 105 return writing_mode_ == HorizontalTopBottom | 105 return writing_mode_ == HorizontalTopBottom |
| 106 ? physical_space_->width_direction_triggers_scrollbar_ | 106 ? physical_space_.width_direction_triggers_scrollbar_ |
| 107 : physical_space_->height_direction_triggers_scrollbar_; | 107 : physical_space_.height_direction_triggers_scrollbar_; |
| 108 } | 108 } |
| 109 | 109 |
| 110 bool NGConstraintSpace::BlockTriggersScrollbar() const { | 110 bool NGConstraintSpace::BlockTriggersScrollbar() const { |
| 111 return writing_mode_ == HorizontalTopBottom | 111 return writing_mode_ == HorizontalTopBottom |
| 112 ? physical_space_->height_direction_triggers_scrollbar_ | 112 ? physical_space_.height_direction_triggers_scrollbar_ |
| 113 : physical_space_->width_direction_triggers_scrollbar_; | 113 : physical_space_.width_direction_triggers_scrollbar_; |
| 114 } | 114 } |
| 115 | 115 |
| 116 bool NGConstraintSpace::FixedInlineSize() const { | 116 bool NGConstraintSpace::FixedInlineSize() const { |
| 117 return writing_mode_ == HorizontalTopBottom ? physical_space_->fixed_width_ | 117 return writing_mode_ == HorizontalTopBottom ? physical_space_.fixed_width_ |
| 118 : physical_space_->fixed_height_; | 118 : physical_space_.fixed_height_; |
| 119 } | 119 } |
| 120 | 120 |
| 121 bool NGConstraintSpace::FixedBlockSize() const { | 121 bool NGConstraintSpace::FixedBlockSize() const { |
| 122 return writing_mode_ == HorizontalTopBottom ? physical_space_->fixed_height_ | 122 return writing_mode_ == HorizontalTopBottom ? physical_space_.fixed_height_ |
| 123 : physical_space_->fixed_width_; | 123 : physical_space_.fixed_width_; |
| 124 } | 124 } |
| 125 | 125 |
| 126 NGFragmentationType NGConstraintSpace::BlockFragmentationType() const { | 126 NGFragmentationType NGConstraintSpace::BlockFragmentationType() const { |
| 127 return static_cast<NGFragmentationType>( | 127 return static_cast<NGFragmentationType>( |
| 128 writing_mode_ == HorizontalTopBottom | 128 writing_mode_ == HorizontalTopBottom |
| 129 ? physical_space_->height_direction_fragmentation_type_ | 129 ? physical_space_.height_direction_fragmentation_type_ |
| 130 : physical_space_->width_direction_fragmentation_type_); | 130 : physical_space_.width_direction_fragmentation_type_); |
| 131 } | 131 } |
| 132 | 132 |
| 133 void NGConstraintSpace::Subtract(const NGFragment*) { | 133 void NGConstraintSpace::Subtract(const NGFragment*) { |
| 134 // TODO(layout-ng): Implement. | 134 // TODO(layout-ng): Implement. |
| 135 } | 135 } |
| 136 | 136 |
| 137 NGLayoutOpportunityIterator* NGConstraintSpace::LayoutOpportunities( | 137 NGLayoutOpportunityIterator* NGConstraintSpace::LayoutOpportunities( |
| 138 unsigned clear, | 138 unsigned clear, |
| 139 bool for_inline_or_bfc) { | 139 bool for_inline_or_bfc) { |
| 140 NGLayoutOpportunityIterator* iterator = | 140 NGLayoutOpportunityIterator* iterator = |
| 141 new NGLayoutOpportunityIterator(this, clear, for_inline_or_bfc); | 141 new NGLayoutOpportunityIterator(this, clear, for_inline_or_bfc); |
| 142 return iterator; | 142 return iterator; |
| 143 } | 143 } |
| 144 | 144 |
| 145 void NGConstraintSpace::SetOverflowTriggersScrollbar(bool inline_triggers, | 145 void NGConstraintSpace::SetOverflowTriggersScrollbar(bool inline_triggers, |
| 146 bool block_triggers) { | 146 bool block_triggers) { |
| 147 if (writing_mode_ == HorizontalTopBottom) { | 147 if (writing_mode_ == HorizontalTopBottom) { |
| 148 physical_space_->width_direction_triggers_scrollbar_ = inline_triggers; | 148 physical_space_.width_direction_triggers_scrollbar_ = inline_triggers; |
| 149 physical_space_->height_direction_triggers_scrollbar_ = block_triggers; | 149 physical_space_.height_direction_triggers_scrollbar_ = block_triggers; |
| 150 } else { | 150 } else { |
| 151 physical_space_->width_direction_triggers_scrollbar_ = block_triggers; | 151 physical_space_.width_direction_triggers_scrollbar_ = block_triggers; |
| 152 physical_space_->height_direction_triggers_scrollbar_ = inline_triggers; | 152 physical_space_.height_direction_triggers_scrollbar_ = inline_triggers; |
| 153 } | 153 } |
| 154 } | 154 } |
| 155 | 155 |
| 156 void NGConstraintSpace::SetFixedSize(bool inline_fixed, bool block_fixed) { | 156 void NGConstraintSpace::SetFixedSize(bool inline_fixed, bool block_fixed) { |
| 157 if (writing_mode_ == HorizontalTopBottom) { | 157 if (writing_mode_ == HorizontalTopBottom) { |
| 158 physical_space_->fixed_width_ = inline_fixed; | 158 physical_space_.fixed_width_ = inline_fixed; |
| 159 physical_space_->fixed_height_ = block_fixed; | 159 physical_space_.fixed_height_ = block_fixed; |
| 160 } else { | 160 } else { |
| 161 physical_space_->fixed_width_ = block_fixed; | 161 physical_space_.fixed_width_ = block_fixed; |
| 162 physical_space_->fixed_height_ = inline_fixed; | 162 physical_space_.fixed_height_ = inline_fixed; |
| 163 } | 163 } |
| 164 } | 164 } |
| 165 | 165 |
| 166 void NGConstraintSpace::SetFragmentationType(NGFragmentationType type) { | 166 void NGConstraintSpace::SetFragmentationType(NGFragmentationType type) { |
| 167 if (writing_mode_ == HorizontalTopBottom) { | 167 if (writing_mode_ == HorizontalTopBottom) { |
| 168 DCHECK_EQ(static_cast<NGFragmentationType>( | 168 DCHECK_EQ(static_cast<NGFragmentationType>( |
| 169 physical_space_->width_direction_fragmentation_type_), | 169 physical_space_.width_direction_fragmentation_type_), |
| 170 FragmentNone); | 170 FragmentNone); |
| 171 physical_space_->height_direction_fragmentation_type_ = type; | 171 physical_space_.height_direction_fragmentation_type_ = type; |
| 172 } else { | 172 } else { |
| 173 DCHECK_EQ(static_cast<NGFragmentationType>( | 173 DCHECK_EQ(static_cast<NGFragmentationType>( |
| 174 physical_space_->height_direction_fragmentation_type_), | 174 physical_space_.height_direction_fragmentation_type_), |
| 175 FragmentNone); | 175 FragmentNone); |
| 176 physical_space_->width_direction_triggers_scrollbar_ = type; | 176 physical_space_.width_direction_triggers_scrollbar_ = type; |
| 177 } | 177 } |
| 178 } | 178 } |
| 179 | 179 |
| 180 String NGConstraintSpace::ToString() const { | 180 String NGConstraintSpace::ToString() const { |
| 181 return String::format("%s,%s %sx%s", | 181 return String::format("%s,%s %sx%s", |
| 182 offset_.inline_offset.toString().ascii().data(), | 182 offset_.inline_offset.toString().ascii().data(), |
| 183 offset_.block_offset.toString().ascii().data(), | 183 offset_.block_offset.toString().ascii().data(), |
| 184 size_.inline_size.toString().ascii().data(), | 184 size_.inline_size.toString().ascii().data(), |
| 185 size_.block_size.toString().ascii().data()); | 185 size_.block_size.toString().ascii().data()); |
| 186 } | 186 } |
| 187 | 187 |
| 188 } // namespace blink | 188 } // namespace blink |
| OLD | NEW |