| 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/ng/ng_units.h" | 7 #include "core/layout/ng/ng_units.h" |
| 8 | 8 |
| 9 namespace blink { | 9 namespace blink { |
| 10 | 10 |
| 11 static inline NGLogicalSize LogicalSizeForWritingMode( | |
| 12 NGWritingMode writing_mode, | |
| 13 NGPhysicalConstraintSpace* physical_space) { | |
| 14 return writing_mode == HorizontalTopBottom | |
| 15 ? NGLogicalSize(physical_space->ContainerSize().width, | |
| 16 physical_space->ContainerSize().height) | |
| 17 : NGLogicalSize(physical_space->ContainerSize().height, | |
| 18 physical_space->ContainerSize().width); | |
| 19 } | |
| 20 | |
| 21 // TODO: This should set the size of the NGPhysicalConstraintSpace. Or we could | 11 // TODO: This should set the size of the NGPhysicalConstraintSpace. Or we could |
| 22 // remove it requiring that a NGConstraintSpace is created from a | 12 // remove it requiring that a NGConstraintSpace is created from a |
| 23 // NGPhysicalConstraintSpace. | 13 // NGPhysicalConstraintSpace. |
| 24 NGConstraintSpace::NGConstraintSpace(NGWritingMode writing_mode, | 14 NGConstraintSpace::NGConstraintSpace(NGWritingMode writing_mode, |
| 25 NGLogicalSize container_size) | 15 NGLogicalSize container_size) |
| 26 : physical_space_(new NGPhysicalConstraintSpace()), | 16 : physical_space_(new NGPhysicalConstraintSpace()), |
| 27 writing_mode_(writing_mode) { | 17 writing_mode_(writing_mode) { |
| 28 SetContainerSize(container_size); | 18 SetContainerSize(container_size); |
| 29 } | 19 } |
| 30 | 20 |
| 31 NGConstraintSpace::NGConstraintSpace(NGWritingMode writing_mode, | 21 NGConstraintSpace::NGConstraintSpace(NGWritingMode writing_mode, |
| 32 NGPhysicalConstraintSpace* physical_space) | 22 NGPhysicalConstraintSpace* physical_space) |
| 33 : physical_space_(physical_space), writing_mode_(writing_mode) { | 23 : physical_space_(physical_space), writing_mode_(writing_mode) { |
| 34 SetContainerSize(LogicalSizeForWritingMode(writing_mode, physical_space)); | |
| 35 } | 24 } |
| 36 | 25 |
| 37 NGConstraintSpace::NGConstraintSpace(const NGConstraintSpace& other, | 26 NGConstraintSpace::NGConstraintSpace(const NGConstraintSpace& other, |
| 38 NGLogicalSize container_size) | 27 NGLogicalSize container_size) |
| 39 : physical_space_(*other.physical_space_), | 28 : physical_space_(*other.physical_space_), |
| 40 writing_mode_(other.writing_mode_) { | 29 writing_mode_(other.writing_mode_) { |
| 41 SetContainerSize(container_size); | 30 SetContainerSize(container_size); |
| 42 } | 31 } |
| 43 | 32 |
| 44 NGLogicalSize NGConstraintSpace::ContainerSize() const { | 33 NGLogicalSize NGConstraintSpace::ContainerSize() const { |
| 45 return LogicalSizeForWritingMode(WritingMode(), physical_space_); | 34 return physical_space_->container_size_.ConvertToLogical( |
| 35 static_cast<NGWritingMode>(writing_mode_)); |
| 46 } | 36 } |
| 47 | 37 |
| 48 bool NGConstraintSpace::InlineTriggersScrollbar() const { | 38 bool NGConstraintSpace::InlineTriggersScrollbar() const { |
| 49 return writing_mode_ == HorizontalTopBottom | 39 return writing_mode_ == HorizontalTopBottom |
| 50 ? physical_space_->width_direction_triggers_scrollbar_ | 40 ? physical_space_->width_direction_triggers_scrollbar_ |
| 51 : physical_space_->height_direction_triggers_scrollbar_; | 41 : physical_space_->height_direction_triggers_scrollbar_; |
| 52 } | 42 } |
| 53 | 43 |
| 54 bool NGConstraintSpace::BlockTriggersScrollbar() const { | 44 bool NGConstraintSpace::BlockTriggersScrollbar() const { |
| 55 return writing_mode_ == HorizontalTopBottom | 45 return writing_mode_ == HorizontalTopBottom |
| (...skipping 23 matching lines...) Expand all Loading... |
| 79 } | 69 } |
| 80 | 70 |
| 81 NGLayoutOpportunityIterator NGConstraintSpace::LayoutOpportunities( | 71 NGLayoutOpportunityIterator NGConstraintSpace::LayoutOpportunities( |
| 82 unsigned clear, | 72 unsigned clear, |
| 83 bool for_inline_or_bfc) { | 73 bool for_inline_or_bfc) { |
| 84 NGLayoutOpportunityIterator iterator(this, clear, for_inline_or_bfc); | 74 NGLayoutOpportunityIterator iterator(this, clear, for_inline_or_bfc); |
| 85 return iterator; | 75 return iterator; |
| 86 } | 76 } |
| 87 | 77 |
| 88 void NGConstraintSpace::SetContainerSize(NGLogicalSize container_size) { | 78 void NGConstraintSpace::SetContainerSize(NGLogicalSize container_size) { |
| 89 if (writing_mode_ == HorizontalTopBottom) { | 79 physical_space_->container_size_ = container_size.ConvertToPhysical( |
| 90 physical_space_->container_size_.width = container_size.inline_size; | 80 static_cast<NGWritingMode>(writing_mode_)); |
| 91 physical_space_->container_size_.height = container_size.block_size; | |
| 92 } else { | |
| 93 physical_space_->container_size_.width = container_size.block_size; | |
| 94 physical_space_->container_size_.height = container_size.inline_size; | |
| 95 } | |
| 96 } | 81 } |
| 97 | 82 |
| 98 void NGConstraintSpace::SetOverflowTriggersScrollbar(bool inline_triggers, | 83 void NGConstraintSpace::SetOverflowTriggersScrollbar(bool inline_triggers, |
| 99 bool block_triggers) { | 84 bool block_triggers) { |
| 100 if (writing_mode_ == HorizontalTopBottom) { | 85 if (writing_mode_ == HorizontalTopBottom) { |
| 101 physical_space_->width_direction_triggers_scrollbar_ = inline_triggers; | 86 physical_space_->width_direction_triggers_scrollbar_ = inline_triggers; |
| 102 physical_space_->height_direction_triggers_scrollbar_ = block_triggers; | 87 physical_space_->height_direction_triggers_scrollbar_ = block_triggers; |
| 103 } else { | 88 } else { |
| 104 physical_space_->width_direction_triggers_scrollbar_ = block_triggers; | 89 physical_space_->width_direction_triggers_scrollbar_ = block_triggers; |
| 105 physical_space_->height_direction_triggers_scrollbar_ = inline_triggers; | 90 physical_space_->height_direction_triggers_scrollbar_ = inline_triggers; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 132 | 117 |
| 133 NGConstraintSpace* NGLayoutOpportunityIterator::Next() { | 118 NGConstraintSpace* NGLayoutOpportunityIterator::Next() { |
| 134 auto* exclusions = constraint_space_->PhysicalSpace()->Exclusions(); | 119 auto* exclusions = constraint_space_->PhysicalSpace()->Exclusions(); |
| 135 if (!exclusions->head()) | 120 if (!exclusions->head()) |
| 136 return new NGConstraintSpace(constraint_space_->WritingMode(), | 121 return new NGConstraintSpace(constraint_space_->WritingMode(), |
| 137 constraint_space_->PhysicalSpace()); | 122 constraint_space_->PhysicalSpace()); |
| 138 return nullptr; | 123 return nullptr; |
| 139 } | 124 } |
| 140 | 125 |
| 141 } // namespace blink | 126 } // namespace blink |
| OLD | NEW |