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

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

Issue 2525033002: Deprecate NGPhysicalConstraintSpace (Closed)
Patch Set: Set the correct exclusion list for each child 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 }
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_; }
81 void SetOffset(const NGLogicalOffset& offset) { offset_ = offset; } 73 void SetOffset(const NGLogicalOffset& offset) { offset_ = offset; }
ikilpatrick 2016/11/29 00:10:27 .nit? (up to you) TODO: remove.
Gleb Lanbin 2016/12/01 20:41:53 Done.
82 74
83 // Whether the current constraint space is for the newly established 75 // Whether the current constraint space is for the newly established
84 // Formatting Context. 76 // Formatting Context.
85 bool IsNewFormattingContext() const; 77 bool IsNewFormattingContext() const { return is_new_fc_; }
86 78
87 // Whether exceeding the AvailableSize() triggers the presence of a scrollbar 79 // Whether exceeding the AvailableSize() triggers the presence of a scrollbar
88 // for the indicated direction. 80 // for the indicated direction.
89 // If exceeded the current layout should be aborted and invoked again with a 81 // If exceeded the current layout should be aborted and invoked again with a
90 // constraint space modified to reserve space for a scrollbar. 82 // constraint space modified to reserve space for a scrollbar.
91 bool InlineTriggersScrollbar() const; 83 bool IsInlineDirectionTriggersScrollbar() const {
92 bool BlockTriggersScrollbar() const; 84 return is_inline_direction_triggers_scrollbar_;
85 }
86
87 bool IsBlockDirectionTriggersScrollbar() const {
88 return is_block_direction_triggers_scrollbar_;
89 }
93 90
94 // Some layout modes “stretch” their children to a fixed size (e.g. flex, 91 // 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 92 // grid). These flags represented whether a layout needs to produce a
96 // fragment that satisfies a fixed constraint in the inline and block 93 // fragment that satisfies a fixed constraint in the inline and block
97 // direction respectively. 94 // direction respectively.
98 bool FixedInlineSize() const; 95 bool IsFixedSizeInline() const { return is_fixed_size_inline_; }
99 bool FixedBlockSize() const; 96
97 bool IsFixedSizeBlock() const { return is_fixed_size_block_; }
100 98
101 // If specified a layout should produce a Fragment which fragments at the 99 // If specified a layout should produce a Fragment which fragments at the
102 // blockSize if possible. 100 // blockSize if possible.
103 NGFragmentationType BlockFragmentationType() const; 101 NGFragmentationType BlockFragmentationType() const;
104 102
105 // Modifies constraint space to account for a placed fragment. Depending on 103 // 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 104 // the shape of the fragment this will either modify the inline or block
107 // size, or add an exclusion. 105 // size, or add an exclusion.
108 void Subtract(const NGFragment*); 106 void Subtract(const NGFragment*);
109 107
110 NGLayoutOpportunityIterator* LayoutOpportunities( 108 NGLayoutOpportunityIterator* LayoutOpportunities(
111 unsigned clear = NGClearNone, 109 unsigned clear = NGClearNone,
112 bool for_inline_or_bfc = false); 110 bool for_inline_or_bfc = false);
113 111
114 DEFINE_INLINE_VIRTUAL_TRACE() { visitor->trace(physical_space_); } 112 DEFINE_INLINE_VIRTUAL_TRACE() {}
115 113
116 NGConstraintSpace* ChildSpace(const ComputedStyle* style) const; 114 NGConstraintSpace* ChildSpace(const ComputedStyle* style) const;
117
118 String ToString() const; 115 String ToString() const;
119 116
120 private: 117 private:
121 Member<NGPhysicalConstraintSpace> physical_space_; 118 friend class NGConstraintSpaceBuilder;
119 // Default constructor.
120 NGConstraintSpace(NGWritingMode,
121 TextDirection,
122 NGLogicalSize available_size,
123 NGLogicalSize percentage_resolution_size,
124 bool is_fixed_size_inline,
125 bool is_fixed_size_block,
126 bool is_inline_direction_triggers_scrollbar,
127 bool is_block_direction_triggers_scrollbar,
128 NGFragmentationType block_direction_fragmentation_type,
129 bool is_new_fc,
130 const std::shared_ptr<NGExclusions>& exclusions_);
131
132 NGLogicalSize available_size_;
133 NGLogicalSize percentage_resolution_size_;
134
135 unsigned is_fixed_size_inline_ : 1;
136 unsigned is_fixed_size_block_ : 1;
137
138 unsigned is_inline_direction_triggers_scrollbar_ : 1;
139 unsigned is_block_direction_triggers_scrollbar_ : 1;
140
141 unsigned block_direction_fragmentation_type_ : 2;
142
143 // Whether the current constraint space is for the newly established
144 // formatting Context
145 unsigned is_new_fc_ : 1;
146
122 NGLogicalOffset offset_; 147 NGLogicalOffset offset_;
123 unsigned writing_mode_ : 3; 148 unsigned writing_mode_ : 3;
124 unsigned direction_ : 1; 149 unsigned direction_ : 1;
150
151 const std::shared_ptr<NGExclusions> exclusions_;
125 }; 152 };
126 153
127 inline std::ostream& operator<<(std::ostream& stream, 154 inline std::ostream& operator<<(std::ostream& stream,
128 const NGConstraintSpace& value) { 155 const NGConstraintSpace& value) {
129 return stream << value.ToString(); 156 return stream << value.ToString();
130 } 157 }
131 158
132 } // namespace blink 159 } // namespace blink
133 160
134 #endif // NGConstraintSpace_h 161 #endif // NGConstraintSpace_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698