| 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 #ifndef NGConstraintSpace_h | 5 #ifndef NGConstraintSpace_h |
| 6 #define NGConstraintSpace_h | 6 #define NGConstraintSpace_h |
| 7 | 7 |
| 8 #include "core/CoreExport.h" | 8 #include "core/CoreExport.h" |
| 9 #include "core/layout/ng/ng_macros.h" | 9 #include "core/layout/ng/ng_macros.h" |
| 10 #include "core/layout/ng/ng_physical_constraint_space.h" | 10 #include "core/layout/ng/ng_units.h" |
| 11 #include "core/layout/ng/ng_writing_mode.h" | 11 #include "core/layout/ng/ng_writing_mode.h" |
| 12 #include "platform/heap/Handle.h" | 12 #include "platform/heap/Handle.h" |
| 13 #include "wtf/text/WTFString.h" | 13 #include "wtf/text/WTFString.h" |
| 14 #include "wtf/Vector.h" | 14 #include "wtf/Vector.h" |
| 15 | 15 |
| 16 namespace blink { | 16 namespace blink { |
| 17 | 17 |
| 18 class ComputedStyle; | 18 class ComputedStyle; |
| 19 class LayoutBox; | 19 class LayoutBox; |
| 20 class NGFragment; | 20 class NGFragment; |
| 21 class NGLayoutOpportunityIterator; | 21 class NGLayoutOpportunityIterator; |
| 22 | 22 |
| 23 // TODO(glebl@): unused, delete. |
| 24 enum NGExclusionType { |
| 25 kNGClearNone = 0, |
| 26 kNGClearFloatLeft = 1, |
| 27 kNGClearFloatRight = 2, |
| 28 kNGClearFragment = 4 |
| 29 }; |
| 30 |
| 31 enum NGFragmentationType { |
| 32 kFragmentNone, |
| 33 kFragmentPage, |
| 34 kFragmentColumn, |
| 35 kFragmentRegion |
| 36 }; |
| 37 |
| 23 // The NGConstraintSpace represents a set of constraints and available space | 38 // The NGConstraintSpace represents a set of constraints and available space |
| 24 // which a layout algorithm may produce a NGFragment within. It is a view on | 39 // which a layout algorithm may produce a NGFragment within. |
| 25 // top of a NGPhysicalConstraintSpace and provides accessor methods in the | |
| 26 // logical coordinate system defined by the writing mode given. | |
| 27 class CORE_EXPORT NGConstraintSpace final | 40 class CORE_EXPORT NGConstraintSpace final |
| 28 : public GarbageCollected<NGConstraintSpace> { | 41 : public GarbageCollectedFinalized<NGConstraintSpace> { |
| 29 public: | 42 public: |
| 30 // Constructs a constraint space based on an existing backing | |
| 31 // NGPhysicalConstraintSpace. Sets this constraint space's size to the | |
| 32 // physical constraint space's available size, converted to logical | |
| 33 // coordinates. | |
| 34 NGConstraintSpace(NGWritingMode, TextDirection, NGPhysicalConstraintSpace*); | |
| 35 | |
| 36 // This should live on NGBlockNode or another layout bridge and probably take | 43 // This should live on NGBlockNode or another layout bridge and probably take |
| 37 // a root | 44 // a root NGConstraintSpace. |
| 38 // NGConstraintSpace or a NGPhysicalConstraintSpace. | |
| 39 static NGConstraintSpace* CreateFromLayoutObject(const LayoutBox&); | 45 static NGConstraintSpace* CreateFromLayoutObject(const LayoutBox&); |
| 40 | 46 |
| 41 // Mutable Getters. | 47 const std::shared_ptr<NGExclusions>& Exclusions() const { |
| 42 // TODO(layout-dev): remove const constraint from MutablePhysicalSpace method | 48 return exclusions_; |
| 43 NGPhysicalConstraintSpace* MutablePhysicalSpace() const { | |
| 44 return physical_space_; | |
| 45 } | |
| 46 | |
| 47 // Read-only Getters. | |
| 48 const NGPhysicalConstraintSpace* PhysicalSpace() const { | |
| 49 return physical_space_; | |
| 50 } | |
| 51 | |
| 52 const Vector<std::unique_ptr<const NGExclusion>>& Exclusions() const { | |
| 53 WRITING_MODE_IGNORED( | |
| 54 "Exclusions are stored directly in physical constraint space."); | |
| 55 return PhysicalSpace()->Exclusions(); | |
| 56 } | 49 } |
| 57 | 50 |
| 58 TextDirection Direction() const { | 51 TextDirection Direction() const { |
| 59 return static_cast<TextDirection>(direction_); | 52 return static_cast<TextDirection>(direction_); |
| 60 } | 53 } |
| 61 | 54 |
| 62 NGWritingMode WritingMode() const { | 55 NGWritingMode WritingMode() const { |
| 63 return static_cast<NGWritingMode>(writing_mode_); | 56 return static_cast<NGWritingMode>(writing_mode_); |
| 64 } | 57 } |
| 65 | 58 |
| 66 // Adds the exclusion in the physical constraint space. | 59 void AddExclusion(const NGExclusion& exclusion); |
| 67 void AddExclusion(const NGExclusion& exclusion) const; | |
| 68 const NGExclusion* LastLeftFloatExclusion() const; | |
| 69 const NGExclusion* LastRightFloatExclusion() const; | |
| 70 | 60 |
| 71 // The size to use for percentage resolution. | 61 // The size to use for percentage resolution. |
| 72 // See: https://drafts.csswg.org/css-sizing/#percentage-sizing | 62 // See: https://drafts.csswg.org/css-sizing/#percentage-sizing |
| 73 NGLogicalSize PercentageResolutionSize() const; | 63 NGLogicalSize PercentageResolutionSize() const { |
| 64 return percentage_resolution_size_; |
| 65 } |
| 74 | 66 |
| 75 // The available space size. | 67 // The available space size. |
| 76 // See: https://drafts.csswg.org/css-sizing/#available | 68 // See: https://drafts.csswg.org/css-sizing/#available |
| 77 NGLogicalSize AvailableSize() const; | 69 NGLogicalSize AvailableSize() const { return available_size_; } |
| 78 | 70 |
| 79 // Offset relative to the root constraint space. | 71 // Offset relative to the root constraint space. |
| 80 NGLogicalOffset Offset() const { return offset_; } | 72 NGLogicalOffset Offset() const { return offset_; } |
| 73 // TODO(layout-ng): Set offset via NGConstraintSpacebuilder. |
| 81 void SetOffset(const NGLogicalOffset& offset) { offset_ = offset; } | 74 void SetOffset(const NGLogicalOffset& offset) { offset_ = offset; } |
| 82 | 75 |
| 83 // Whether the current constraint space is for the newly established | 76 // Whether the current constraint space is for the newly established |
| 84 // Formatting Context. | 77 // Formatting Context. |
| 85 bool IsNewFormattingContext() const; | 78 bool IsNewFormattingContext() const { return is_new_fc_; } |
| 86 | 79 |
| 87 // Whether exceeding the AvailableSize() triggers the presence of a scrollbar | 80 // Whether exceeding the AvailableSize() triggers the presence of a scrollbar |
| 88 // for the indicated direction. | 81 // for the indicated direction. |
| 89 // If exceeded the current layout should be aborted and invoked again with a | 82 // If exceeded the current layout should be aborted and invoked again with a |
| 90 // constraint space modified to reserve space for a scrollbar. | 83 // constraint space modified to reserve space for a scrollbar. |
| 91 bool InlineTriggersScrollbar() const; | 84 bool IsInlineDirectionTriggersScrollbar() const { |
| 92 bool BlockTriggersScrollbar() const; | 85 return is_inline_direction_triggers_scrollbar_; |
| 86 } |
| 87 |
| 88 bool IsBlockDirectionTriggersScrollbar() const { |
| 89 return is_block_direction_triggers_scrollbar_; |
| 90 } |
| 93 | 91 |
| 94 // Some layout modes “stretch” their children to a fixed size (e.g. flex, | 92 // Some layout modes “stretch” their children to a fixed size (e.g. flex, |
| 95 // grid). These flags represented whether a layout needs to produce a | 93 // grid). These flags represented whether a layout needs to produce a |
| 96 // fragment that satisfies a fixed constraint in the inline and block | 94 // fragment that satisfies a fixed constraint in the inline and block |
| 97 // direction respectively. | 95 // direction respectively. |
| 98 bool FixedInlineSize() const; | 96 bool IsFixedSizeInline() const { return is_fixed_size_inline_; } |
| 99 bool FixedBlockSize() const; | 97 |
| 98 bool IsFixedSizeBlock() const { return is_fixed_size_block_; } |
| 100 | 99 |
| 101 // If specified a layout should produce a Fragment which fragments at the | 100 // If specified a layout should produce a Fragment which fragments at the |
| 102 // blockSize if possible. | 101 // blockSize if possible. |
| 103 NGFragmentationType BlockFragmentationType() const; | 102 NGFragmentationType BlockFragmentationType() const; |
| 104 | 103 |
| 105 // Modifies constraint space to account for a placed fragment. Depending on | 104 // Modifies constraint space to account for a placed fragment. Depending on |
| 106 // the shape of the fragment this will either modify the inline or block | 105 // the shape of the fragment this will either modify the inline or block |
| 107 // size, or add an exclusion. | 106 // size, or add an exclusion. |
| 108 void Subtract(const NGFragment*); | 107 void Subtract(const NGFragment*); |
| 109 | 108 |
| 110 NGLayoutOpportunityIterator* LayoutOpportunities( | 109 NGLayoutOpportunityIterator* LayoutOpportunities( |
| 111 unsigned clear = kNGClearNone, | 110 unsigned clear = kNGClearNone, |
| 112 bool for_inline_or_bfc = false); | 111 bool for_inline_or_bfc = false); |
| 113 | 112 |
| 114 DEFINE_INLINE_VIRTUAL_TRACE() { visitor->trace(physical_space_); } | 113 DEFINE_INLINE_VIRTUAL_TRACE() {} |
| 115 | 114 |
| 116 NGConstraintSpace* ChildSpace(const ComputedStyle* style) const; | 115 NGConstraintSpace* ChildSpace(const ComputedStyle* style) const; |
| 117 | |
| 118 String ToString() const; | 116 String ToString() const; |
| 119 | 117 |
| 120 private: | 118 private: |
| 121 Member<NGPhysicalConstraintSpace> physical_space_; | 119 friend class NGConstraintSpaceBuilder; |
| 120 // Default constructor. |
| 121 NGConstraintSpace(NGWritingMode, |
| 122 TextDirection, |
| 123 NGLogicalSize available_size, |
| 124 NGLogicalSize percentage_resolution_size, |
| 125 bool is_fixed_size_inline, |
| 126 bool is_fixed_size_block, |
| 127 bool is_inline_direction_triggers_scrollbar, |
| 128 bool is_block_direction_triggers_scrollbar, |
| 129 NGFragmentationType block_direction_fragmentation_type, |
| 130 bool is_new_fc, |
| 131 const std::shared_ptr<NGExclusions>& exclusions_); |
| 132 |
| 133 NGLogicalSize available_size_; |
| 134 NGLogicalSize percentage_resolution_size_; |
| 135 |
| 136 unsigned is_fixed_size_inline_ : 1; |
| 137 unsigned is_fixed_size_block_ : 1; |
| 138 |
| 139 unsigned is_inline_direction_triggers_scrollbar_ : 1; |
| 140 unsigned is_block_direction_triggers_scrollbar_ : 1; |
| 141 |
| 142 unsigned block_direction_fragmentation_type_ : 2; |
| 143 |
| 144 // Whether the current constraint space is for the newly established |
| 145 // formatting Context |
| 146 unsigned is_new_fc_ : 1; |
| 147 |
| 122 NGLogicalOffset offset_; | 148 NGLogicalOffset offset_; |
| 123 unsigned writing_mode_ : 3; | 149 unsigned writing_mode_ : 3; |
| 124 unsigned direction_ : 1; | 150 unsigned direction_ : 1; |
| 151 |
| 152 const std::shared_ptr<NGExclusions> exclusions_; |
| 125 }; | 153 }; |
| 126 | 154 |
| 127 inline std::ostream& operator<<(std::ostream& stream, | 155 inline std::ostream& operator<<(std::ostream& stream, |
| 128 const NGConstraintSpace& value) { | 156 const NGConstraintSpace& value) { |
| 129 return stream << value.ToString(); | 157 return stream << value.ToString(); |
| 130 } | 158 } |
| 131 | 159 |
| 132 } // namespace blink | 160 } // namespace blink |
| 133 | 161 |
| 134 #endif // NGConstraintSpace_h | 162 #endif // NGConstraintSpace_h |
| OLD | NEW |