| 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_constraint_space.h" | 9 #include "core/layout/ng/ng_constraint_space.h" |
| 10 #include "core/layout/ng/ng_constraint_space_builder.h" | 10 #include "core/layout/ng/ng_constraint_space_builder.h" |
| 11 #include "core/layout/ng/ng_layout_opportunity_iterator.h" | 11 #include "core/layout/ng/ng_layout_opportunity_iterator.h" |
| 12 #include "core/layout/ng/ng_units.h" | 12 #include "core/layout/ng/ng_units.h" |
| 13 | 13 |
| 14 namespace blink { | 14 namespace blink { |
| 15 | 15 |
| 16 NGConstraintSpace::NGConstraintSpace(NGWritingMode writing_mode, | 16 NGConstraintSpace::NGConstraintSpace( |
| 17 TextDirection direction, | 17 NGWritingMode writing_mode, |
| 18 NGPhysicalConstraintSpace* physical_space) | 18 TextDirection direction, |
| 19 : physical_space_(physical_space), | 19 NGLogicalSize available_size, |
| 20 NGLogicalSize percentage_resolution_size, |
| 21 bool is_fixed_size_inline, |
| 22 bool is_fixed_size_block, |
| 23 bool is_inline_direction_triggers_scrollbar, |
| 24 bool is_block_direction_triggers_scrollbar, |
| 25 NGFragmentationType block_direction_fragmentation_type, |
| 26 bool is_new_fc, |
| 27 const std::shared_ptr<NGExclusions>& exclusions_) |
| 28 : available_size_(available_size), |
| 29 percentage_resolution_size_(percentage_resolution_size), |
| 30 is_fixed_size_inline_(is_fixed_size_inline), |
| 31 is_fixed_size_block_(is_fixed_size_block), |
| 32 is_inline_direction_triggers_scrollbar_( |
| 33 is_inline_direction_triggers_scrollbar), |
| 34 is_block_direction_triggers_scrollbar_( |
| 35 is_block_direction_triggers_scrollbar), |
| 36 block_direction_fragmentation_type_(block_direction_fragmentation_type), |
| 37 is_new_fc_(is_new_fc), |
| 20 writing_mode_(writing_mode), | 38 writing_mode_(writing_mode), |
| 21 direction_(direction) {} | 39 direction_(direction), |
| 40 exclusions_(exclusions_) {} |
| 22 | 41 |
| 23 NGConstraintSpace* NGConstraintSpace::CreateFromLayoutObject( | 42 NGConstraintSpace* NGConstraintSpace::CreateFromLayoutObject( |
| 24 const LayoutBox& box) { | 43 const LayoutBox& box) { |
| 25 bool fixed_inline = false, fixed_block = false; | 44 bool fixed_inline = false, fixed_block = false; |
| 26 // XXX for orthogonal writing mode this is not right | 45 // XXX for orthogonal writing mode this is not right |
| 27 LayoutUnit available_logical_width = | 46 LayoutUnit available_logical_width = |
| 28 std::max(LayoutUnit(), box.containingBlockLogicalWidthForContent()); | 47 std::max(LayoutUnit(), box.containingBlockLogicalWidthForContent()); |
| 29 LayoutUnit available_logical_height; | 48 LayoutUnit available_logical_height; |
| 30 if (!box.parent()) { | 49 if (!box.parent()) { |
| 31 available_logical_height = box.view()->viewLogicalHeightForPercentages(); | 50 available_logical_height = box.view()->viewLogicalHeightForPercentages(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 43 } | 62 } |
| 44 if (box.hasOverrideLogicalContentHeight()) { | 63 if (box.hasOverrideLogicalContentHeight()) { |
| 45 available_logical_height = box.borderAndPaddingLogicalHeight() + | 64 available_logical_height = box.borderAndPaddingLogicalHeight() + |
| 46 box.overrideLogicalContentHeight(); | 65 box.overrideLogicalContentHeight(); |
| 47 fixed_block = true; | 66 fixed_block = true; |
| 48 } | 67 } |
| 49 | 68 |
| 50 bool is_new_fc = | 69 bool is_new_fc = |
| 51 box.isLayoutBlock() && toLayoutBlock(box).createsNewFormattingContext(); | 70 box.isLayoutBlock() && toLayoutBlock(box).createsNewFormattingContext(); |
| 52 | 71 |
| 53 NGConstraintSpaceBuilder builder( | 72 NGLogicalSize size = {available_logical_width, available_logical_height}; |
| 54 FromPlatformWritingMode(box.styleRef().getWritingMode())); | 73 auto writing_mode = FromPlatformWritingMode(box.styleRef().getWritingMode()); |
| 55 builder | 74 return NGConstraintSpaceBuilder(writing_mode) |
| 56 .SetAvailableSize( | 75 .SetAvailableSize(size) |
| 57 NGLogicalSize(available_logical_width, available_logical_height)) | 76 .SetPercentageResolutionSize(size) |
| 58 .SetPercentageResolutionSize( | |
| 59 NGLogicalSize(available_logical_width, available_logical_height)) | |
| 60 .SetIsInlineDirectionTriggersScrollbar( | 77 .SetIsInlineDirectionTriggersScrollbar( |
| 61 box.styleRef().overflowInlineDirection() == OverflowAuto) | 78 box.styleRef().overflowInlineDirection() == OverflowAuto) |
| 62 .SetIsBlockDirectionTriggersScrollbar( | 79 .SetIsBlockDirectionTriggersScrollbar( |
| 63 box.styleRef().overflowBlockDirection() == OverflowAuto) | 80 box.styleRef().overflowBlockDirection() == OverflowAuto) |
| 64 .SetIsFixedSizeInline(fixed_inline) | 81 .SetIsFixedSizeInline(fixed_inline) |
| 65 .SetIsFixedSizeBlock(fixed_block) | 82 .SetIsFixedSizeBlock(fixed_block) |
| 66 .SetIsNewFormattingContext(is_new_fc); | 83 .SetIsNewFormattingContext(is_new_fc) |
| 67 | 84 .SetTextDirection(box.styleRef().direction()) |
| 68 return new NGConstraintSpace( | 85 .ToConstraintSpace(); |
| 69 FromPlatformWritingMode(box.styleRef().getWritingMode()), | |
| 70 box.styleRef().direction(), builder.ToConstraintSpace()); | |
| 71 } | 86 } |
| 72 | 87 |
| 73 void NGConstraintSpace::AddExclusion(const NGExclusion& exclusion) const { | 88 void NGConstraintSpace::AddExclusion(const NGExclusion& exclusion) { |
| 74 WRITING_MODE_IGNORED( | 89 exclusions_->Add(exclusion); |
| 75 "Exclusions are stored directly in physical constraint space."); | |
| 76 MutablePhysicalSpace()->AddExclusion(exclusion); | |
| 77 } | |
| 78 | |
| 79 const NGExclusion* NGConstraintSpace::LastLeftFloatExclusion() const { | |
| 80 WRITING_MODE_IGNORED( | |
| 81 "Exclusions are stored directly in physical constraint space."); | |
| 82 return PhysicalSpace()->LastLeftFloatExclusion(); | |
| 83 } | |
| 84 | |
| 85 const NGExclusion* NGConstraintSpace::LastRightFloatExclusion() const { | |
| 86 WRITING_MODE_IGNORED( | |
| 87 "Exclusions are stored directly in physical constraint space."); | |
| 88 return PhysicalSpace()->LastRightFloatExclusion(); | |
| 89 } | |
| 90 | |
| 91 NGLogicalSize NGConstraintSpace::PercentageResolutionSize() const { | |
| 92 return physical_space_->percentage_resolution_size_.ConvertToLogical( | |
| 93 static_cast<NGWritingMode>(writing_mode_)); | |
| 94 } | |
| 95 | |
| 96 NGLogicalSize NGConstraintSpace::AvailableSize() const { | |
| 97 return physical_space_->available_size_.ConvertToLogical( | |
| 98 static_cast<NGWritingMode>(writing_mode_)); | |
| 99 } | |
| 100 | |
| 101 bool NGConstraintSpace::IsNewFormattingContext() const { | |
| 102 return physical_space_->is_new_fc_; | |
| 103 } | |
| 104 | |
| 105 bool NGConstraintSpace::InlineTriggersScrollbar() const { | |
| 106 return writing_mode_ == kHorizontalTopBottom | |
| 107 ? physical_space_->width_direction_triggers_scrollbar_ | |
| 108 : physical_space_->height_direction_triggers_scrollbar_; | |
| 109 } | |
| 110 | |
| 111 bool NGConstraintSpace::BlockTriggersScrollbar() const { | |
| 112 return writing_mode_ == kHorizontalTopBottom | |
| 113 ? physical_space_->height_direction_triggers_scrollbar_ | |
| 114 : physical_space_->width_direction_triggers_scrollbar_; | |
| 115 } | |
| 116 | |
| 117 bool NGConstraintSpace::FixedInlineSize() const { | |
| 118 return writing_mode_ == kHorizontalTopBottom ? physical_space_->fixed_width_ | |
| 119 : physical_space_->fixed_height_; | |
| 120 } | |
| 121 | |
| 122 bool NGConstraintSpace::FixedBlockSize() const { | |
| 123 return writing_mode_ == kHorizontalTopBottom ? physical_space_->fixed_height_ | |
| 124 : physical_space_->fixed_width_; | |
| 125 } | 90 } |
| 126 | 91 |
| 127 NGFragmentationType NGConstraintSpace::BlockFragmentationType() const { | 92 NGFragmentationType NGConstraintSpace::BlockFragmentationType() const { |
| 128 return static_cast<NGFragmentationType>( | 93 return static_cast<NGFragmentationType>(block_direction_fragmentation_type_); |
| 129 writing_mode_ == kHorizontalTopBottom | |
| 130 ? physical_space_->height_direction_fragmentation_type_ | |
| 131 : physical_space_->width_direction_fragmentation_type_); | |
| 132 } | 94 } |
| 133 | 95 |
| 134 void NGConstraintSpace::Subtract(const NGFragment*) { | 96 void NGConstraintSpace::Subtract(const NGFragment*) { |
| 135 // TODO(layout-ng): Implement. | 97 // TODO(layout-ng): Implement. |
| 136 } | 98 } |
| 137 | 99 |
| 138 NGLayoutOpportunityIterator* NGConstraintSpace::LayoutOpportunities( | 100 NGLayoutOpportunityIterator* NGConstraintSpace::LayoutOpportunities( |
| 139 unsigned clear, | 101 unsigned clear, |
| 140 bool for_inline_or_bfc) { | 102 bool for_inline_or_bfc) { |
| 141 NGLayoutOpportunityIterator* iterator = new NGLayoutOpportunityIterator(this); | 103 NGLayoutOpportunityIterator* iterator = new NGLayoutOpportunityIterator(this); |
| 142 return iterator; | 104 return iterator; |
| 143 } | 105 } |
| 144 | 106 |
| 145 NGConstraintSpace* NGConstraintSpace::ChildSpace( | 107 NGConstraintSpace* NGConstraintSpace::ChildSpace( |
| 146 const ComputedStyle* style) const { | 108 const ComputedStyle* style) const { |
| 147 return new NGConstraintSpace(FromPlatformWritingMode(style->getWritingMode()), | 109 return NGConstraintSpaceBuilder(this) |
| 148 style->direction(), MutablePhysicalSpace()); | 110 .SetWritingMode(FromPlatformWritingMode(style->getWritingMode())) |
| 111 .SetTextDirection(style->direction()) |
| 112 .ToConstraintSpace(); |
| 149 } | 113 } |
| 150 | 114 |
| 151 String NGConstraintSpace::ToString() const { | 115 String NGConstraintSpace::ToString() const { |
| 152 return String::format("%s,%s %sx%s", | 116 return String::format("%s,%s %sx%s", |
| 153 offset_.inline_offset.toString().ascii().data(), | 117 offset_.inline_offset.toString().ascii().data(), |
| 154 offset_.block_offset.toString().ascii().data(), | 118 offset_.block_offset.toString().ascii().data(), |
| 155 AvailableSize().inline_size.toString().ascii().data(), | 119 AvailableSize().inline_size.toString().ascii().data(), |
| 156 AvailableSize().block_size.toString().ascii().data()); | 120 AvailableSize().block_size.toString().ascii().data()); |
| 157 } | 121 } |
| 158 | 122 |
| 159 } // namespace blink | 123 } // namespace blink |
| OLD | NEW |