Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(420)

Side by Side Diff: third_party/WebKit/Source/core/layout/ng/ng_constraint_space.h

Issue 2525033002: Deprecate NGPhysicalConstraintSpace (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 NGClearNone = 0,
26 NGClearFloatLeft = 1,
27 NGClearFloatRight = 2,
28 NGClearFragment = 4
29 };
30
31 enum NGFragmentationType {
32 FragmentNone,
33 FragmentPage,
34 FragmentColumn,
35 FragmentRegion
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 }
66
67 void SetPercentageResolutionSize(
68 const NGLogicalSize& percentage_resolution_size) {
69 percentage_resolution_size_ = percentage_resolution_size;
70 }
74 71
75 // The available space size. 72 // The available space size.
76 // See: https://drafts.csswg.org/css-sizing/#available 73 // See: https://drafts.csswg.org/css-sizing/#available
77 NGLogicalSize AvailableSize() const; 74 NGLogicalSize AvailableSize() const { return available_size_; }
75
76 void SetAvailableSize(const NGLogicalSize& size) { available_size_ = size; }
78 77
79 // Offset relative to the root constraint space. 78 // Offset relative to the root constraint space.
80 NGLogicalOffset Offset() const { return offset_; } 79 NGLogicalOffset Offset() const { return offset_; }
81 void SetOffset(const NGLogicalOffset& offset) { offset_ = offset; } 80 void SetOffset(const NGLogicalOffset& offset) { offset_ = offset; }
82 81
83 // Whether the current constraint space is for the newly established 82 // Whether the current constraint space is for the newly established
84 // Formatting Context. 83 // Formatting Context.
85 bool IsNewFormattingContext() const; 84 bool IsNewFormattingContext() const { return is_new_fc_; }
86 85
87 // Whether exceeding the AvailableSize() triggers the presence of a scrollbar 86 // Whether exceeding the AvailableSize() triggers the presence of a scrollbar
88 // for the indicated direction. 87 // for the indicated direction.
89 // If exceeded the current layout should be aborted and invoked again with a 88 // If exceeded the current layout should be aborted and invoked again with a
90 // constraint space modified to reserve space for a scrollbar. 89 // constraint space modified to reserve space for a scrollbar.
91 bool InlineTriggersScrollbar() const; 90 bool IsInlineDirectionTriggersScrollbar() const {
92 bool BlockTriggersScrollbar() const; 91 return is_inline_direction_triggers_scrollbar_;
92 }
93
94 bool SetIsInlineDirectionTriggersScrollbar(
ikilpatrick 2016/11/23 17:40:38 we don't need the setters any more?
Gleb Lanbin 2016/11/23 18:59:50 Done.
95 bool is_inline_direction_triggers_scrollbar) {
96 return is_inline_direction_triggers_scrollbar_ =
97 is_inline_direction_triggers_scrollbar;
98 }
99
100 bool IsBlockDirectionTriggersScrollbar() const {
101 return is_block_direction_triggers_scrollbar_;
102 }
103
104 bool SetIsBlockDirectionTriggersScrollbar(
105 bool is_block_direction_triggers_scrollbar) {
106 return is_block_direction_triggers_scrollbar_ =
107 is_block_direction_triggers_scrollbar;
108 }
93 109
94 // Some layout modes “stretch” their children to a fixed size (e.g. flex, 110 // 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 111 // grid). These flags represented whether a layout needs to produce a
96 // fragment that satisfies a fixed constraint in the inline and block 112 // fragment that satisfies a fixed constraint in the inline and block
97 // direction respectively. 113 // direction respectively.
98 bool FixedInlineSize() const; 114 bool IsFixedSizeInline() const { return is_fixed_size_inline_; }
99 bool FixedBlockSize() const; 115
116 void SetIsFixedSizeInline(bool is_fixed_size_inline) {
117 is_fixed_size_inline_ = is_fixed_size_inline;
118 }
119
120 bool IsFixedSizeBlock() const { return is_fixed_size_block_; }
121
122 void SetIsFixedSizeBlock(bool is_fixed_size_block) {
123 is_fixed_size_block_ = is_fixed_size_block;
124 }
100 125
101 // If specified a layout should produce a Fragment which fragments at the 126 // If specified a layout should produce a Fragment which fragments at the
102 // blockSize if possible. 127 // blockSize if possible.
103 NGFragmentationType BlockFragmentationType() const; 128 NGFragmentationType BlockFragmentationType() const;
104 129
105 // Modifies constraint space to account for a placed fragment. Depending on 130 // 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 131 // the shape of the fragment this will either modify the inline or block
107 // size, or add an exclusion. 132 // size, or add an exclusion.
108 void Subtract(const NGFragment*); 133 void Subtract(const NGFragment*);
109 134
110 NGLayoutOpportunityIterator* LayoutOpportunities( 135 NGLayoutOpportunityIterator* LayoutOpportunities(
111 unsigned clear = NGClearNone, 136 unsigned clear = NGClearNone,
112 bool for_inline_or_bfc = false); 137 bool for_inline_or_bfc = false);
113 138
114 DEFINE_INLINE_VIRTUAL_TRACE() { visitor->trace(physical_space_); } 139 DEFINE_INLINE_VIRTUAL_TRACE() {}
115 140
116 NGConstraintSpace* ChildSpace(const ComputedStyle* style) const; 141 NGConstraintSpace* ChildSpace(const ComputedStyle* style) const;
ikilpatrick 2016/11/23 17:40:38 I assume this method is going away, add todo?
Gleb Lanbin 2016/11/23 18:59:50 is it? I'm not aware about this. Can you provide a
117
118 String ToString() const; 142 String ToString() const;
119 143
120 private: 144 private:
121 Member<NGPhysicalConstraintSpace> physical_space_; 145 friend class NGConstraintSpaceBuilder;
146 // Default constructor.
147 NGConstraintSpace(NGWritingMode,
148 TextDirection,
149 NGLogicalSize available_size,
150 NGLogicalSize percentage_resolution_size,
151 bool is_fixed_size_inline,
152 bool is_fixed_size_block,
153 bool is_inline_direction_triggers_scrollbar,
154 bool is_block_direction_triggers_scrollbar,
155 NGFragmentationType block_direction_fragmentation_type,
156 bool is_new_fc,
157 const std::shared_ptr<NGExclusions>& exclusions_);
158
159 NGLogicalSize available_size_;
160 NGLogicalSize percentage_resolution_size_;
161
162 unsigned is_fixed_size_inline_ : 1;
163 unsigned is_fixed_size_block_ : 1;
164
165 unsigned is_inline_direction_triggers_scrollbar_ : 1;
166 unsigned is_block_direction_triggers_scrollbar_ : 1;
167
168 unsigned block_direction_fragmentation_type_ : 2;
169
170 // Whether the current constraint space is for the newly established
171 // formatting Context
172 unsigned is_new_fc_ : 1;
173
122 NGLogicalOffset offset_; 174 NGLogicalOffset offset_;
123 unsigned writing_mode_ : 3; 175 unsigned writing_mode_ : 3;
124 unsigned direction_ : 1; 176 unsigned direction_ : 1;
177
178 const std::shared_ptr<NGExclusions> exclusions_;
125 }; 179 };
126 180
127 inline std::ostream& operator<<(std::ostream& stream, 181 inline std::ostream& operator<<(std::ostream& stream,
128 const NGConstraintSpace& value) { 182 const NGConstraintSpace& value) {
129 return stream << value.ToString(); 183 return stream << value.ToString();
130 } 184 }
131 185
132 } // namespace blink 186 } // namespace blink
133 187
134 #endif // NGConstraintSpace_h 188 #endif // NGConstraintSpace_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698