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

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

Issue 2772503004: [LayoutNG] Add NGInlineBreakToken and back of NGInlineLayoutAlgorithm (Closed)
Patch Set: Rename Created 3 years, 9 months 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 NGLineBuilder_h 5 #ifndef NGInlineLayoutAlgorithm_h
6 #define NGLineBuilder_h 6 #define NGInlineLayoutAlgorithm_h
7 7
8 #include "core/CoreExport.h" 8 #include "core/CoreExport.h"
9 #include "core/layout/ng/geometry/ng_logical_offset.h" 9 #include "core/layout/ng/geometry/ng_logical_offset.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_fragment_builder.h" 11 #include "core/layout/ng/ng_fragment_builder.h"
12 #include "core/layout/ng/ng_layout_algorithm.h"
12 #include "core/layout/ng/ng_line_height_metrics.h" 13 #include "core/layout/ng/ng_line_height_metrics.h"
13 #include "platform/fonts/FontBaseline.h" 14 #include "platform/fonts/FontBaseline.h"
14 #include "platform/heap/Handle.h" 15 #include "platform/heap/Handle.h"
15 #include "wtf/Vector.h" 16 #include "wtf/Vector.h"
16 17
17 namespace blink { 18 namespace blink {
18 19
19 class NGConstraintSpace; 20 class NGConstraintSpace;
21 class NGInlineBreakToken;
20 class NGInlineNode; 22 class NGInlineNode;
21 class NGLayoutInlineItem; 23 class NGLayoutInlineItem;
22 class NGLineBoxFragmentBuilder; 24 class NGLineBoxFragmentBuilder;
23 class NGTextFragmentBuilder; 25 class NGTextFragmentBuilder;
24 26
25 // NGLineBuilder creates the fragment tree for a line. 27 // A class for inline layout (e.g. a <span> with no special style).
26 // NGLineBuilder manages the current line as a range, |start| and |end|. 28 //
27 // |end| can be extended multiple times before creating a line, usually until 29 // Uses NGLineBreaker to find break opportunities, and let it call back to
28 // |!CanFitOnLine()|. 30 // construct linebox fragments and its wrapper box fragment.
29 // |SetBreakOpportunity| can mark the last confirmed offset that can fit. 31 //
30 class CORE_EXPORT NGLineBuilder final { 32 // From a line breaker, this class manages the current line as a range, |start|
31 STACK_ALLOCATED(); 33 // and |end|. |end| can be extended multiple times before creating a line,
32 34 // usually until |!CanFitOnLine()|. |SetBreakOpportunity| can mark the last
35 // confirmed offset that can fit.
36 class CORE_EXPORT NGInlineLayoutAlgorithm final : public NGLayoutAlgorithm {
33 public: 37 public:
34 NGLineBuilder(NGInlineNode*, NGConstraintSpace*); 38 NGInlineLayoutAlgorithm(NGInlineNode*,
39 NGConstraintSpace*,
40 NGInlineBreakToken* = nullptr);
35 41
36 const NGConstraintSpace& ConstraintSpace() const { 42 const NGConstraintSpace& ConstraintSpace() const {
37 return *constraint_space_; 43 return *constraint_space_;
38 } 44 }
39 45
40 LayoutUnit MaxInlineSize() const { return max_inline_size_; } 46 LayoutUnit MaxInlineSize() const { return max_inline_size_; }
41 47
42 // Returns if the current items fit on a line. 48 // Returns if the current items fit on a line.
43 bool CanFitOnLine() const; 49 bool CanFitOnLine() const;
44 50
45 // Returns if there were any items. 51 // Returns if there were any items.
46 bool HasItems() const; 52 bool HasItems() const;
47 53
48 // Set the start offset. 54 // Set the start and the end to the specified offset.
49 // Set the end as well, and therefore empties the current line. 55 // This Empties the current line.
ikilpatrick 2017/03/24 20:58:05 This empties the current line. (no E cap)
50 void SetStart(unsigned index, unsigned offset); 56 void Initialize(unsigned index, unsigned offset);
ikilpatrick 2017/03/24 20:58:05 can this be private?
51 57
52 // Set the end offset. 58 // Set the end offset.
53 void SetEnd(unsigned end_offset); 59 void SetEnd(unsigned end_offset);
54 60
55 // Set the end offset if caller knows the inline size since the current end. 61 // Set the end offset if caller knows the inline size since the current end.
56 void SetEnd(unsigned index, 62 void SetEnd(unsigned index,
57 unsigned end_offset, 63 unsigned end_offset,
58 LayoutUnit inline_size_since_current_end); 64 LayoutUnit inline_size_since_current_end);
59 65
60 // Create a line up to the end offset. 66 // Create a line up to the end offset.
61 // Then set the start to the end offset, and thus empty the current line. 67 // Then set the start to the end offset, and thus empty the current line.
62 void CreateLine(); 68 // @return false if the line does not fit in the constraint space in block
69 // direction.
70 bool CreateLine();
63 71
64 // Returns if a break opportunity was set on the current line. 72 // Returns if a break opportunity was set on the current line.
65 bool HasBreakOpportunity() const; 73 bool HasBreakOpportunity() const;
66 74
67 // Returns if there were items after the last break opportunity. 75 // Returns if there were items after the last break opportunity.
68 bool HasItemsAfterLastBreakOpportunity() const; 76 bool HasItemsAfterLastBreakOpportunity() const;
69 77
70 // Set the break opportunity at the current end offset. 78 // Set the break opportunity at the current end offset.
71 void SetBreakOpportunity(); 79 void SetBreakOpportunity();
72 80
73 // Create a line up to the last break opportunity. 81 // Create a line up to the last break opportunity.
74 // Items after that are sent to the next line. 82 // Items after that are sent to the next line.
75 void CreateLineUpToLastBreakOpportunity(); 83 // @return false if the line does not fit in the constraint space in block
84 // direction.
ikilpatrick 2017/03/24 20:58:05 do we indent text here?
85 bool CreateLineUpToLastBreakOpportunity();
76 86
77 // Set the start offset of hangables; e.g., spaces or hanging punctuations. 87 // Set the start offset of hangables; e.g., spaces or hanging punctuations.
78 // Hangable characters can go beyond the right margin, and are ignored for 88 // Hangable characters can go beyond the right margin, and are ignored for
79 // center/right alignment. 89 // center/right alignment.
80 void SetStartOfHangables(unsigned offset); 90 void SetStartOfHangables(unsigned offset);
81 91
82 // Create fragments for all lines created so far. 92 // Create fragments for all lines created so far.
83 RefPtr<NGLayoutResult> CreateFragments(); 93 RefPtr<NGLayoutResult> CreateFragments();
84 94
85 // Copy fragment data of all lines created by this NGLineBuilder to 95 RefPtr<NGLayoutResult> Layout() override;
86 // LayoutBlockFlow. 96
87 // This must run after |CreateFragments()|, and after the fragments it created 97 // Compute MinMaxContentSize by performing layout.
88 // are placed. 98 // Unlike NGLayoutAlgorithm::ComputeMinMaxContentSize(), this function runs
89 void CopyFragmentDataToLayoutBlockFlow(); 99 // part of layout operations and modifies the state of |this|.
100 MinMaxContentSize ComputeMinMaxContentSizeByLayout();
101
102 // Copy fragment data of all lines to LayoutBlockFlow.
ikilpatrick 2017/03/24 20:58:05 add TODO move to NGInlineNode?
103 void CopyFragmentDataToLayoutBlockFlow(NGLayoutResult*);
90 104
91 // Compute inline size of an NGLayoutInlineItem. 105 // Compute inline size of an NGLayoutInlineItem.
92 // Same as NGLayoutInlineItem::InlineSize(), except that this function can 106 // Same as NGLayoutInlineItem::InlineSize(), except that this function can
93 // compute atomic inlines by performing layout. 107 // compute atomic inlines by performing layout.
94 LayoutUnit InlineSize(const NGLayoutInlineItem&); 108 LayoutUnit InlineSize(const NGLayoutInlineItem&);
95 109
96 private: 110 private:
97 bool IsHorizontalWritingMode() const { return is_horizontal_writing_mode_; } 111 bool IsHorizontalWritingMode() const { return is_horizontal_writing_mode_; }
98 112
99 LayoutUnit InlineSize(const NGLayoutInlineItem&, 113 LayoutUnit InlineSize(const NGLayoutInlineItem&,
(...skipping 12 matching lines...) Expand all
112 void BidiReorder(Vector<LineItemChunk, 32>*); 126 void BidiReorder(Vector<LineItemChunk, 32>*);
113 127
114 // Lays out the inline float. 128 // Lays out the inline float.
115 // List of actions: 129 // List of actions:
116 // - tries to position the float right away if we have enough space. 130 // - tries to position the float right away if we have enough space.
117 // - updates the current_opportunity if we actually place the float. 131 // - updates the current_opportunity if we actually place the float.
118 // - if it's too wide then we add the float to the unpositioned list so it can 132 // - if it's too wide then we add the float to the unpositioned list so it can
119 // be positioned after we're done with the current line. 133 // be positioned after we're done with the current line.
120 void LayoutAndPositionFloat(LayoutUnit end_position, LayoutObject*); 134 void LayoutAndPositionFloat(LayoutUnit end_position, LayoutObject*);
121 135
122 void PlaceItems(const Vector<LineItemChunk, 32>&); 136 bool PlaceItems(const Vector<LineItemChunk, 32>&);
123 void AccumulateUsedFonts(const NGLayoutInlineItem&, 137 void AccumulateUsedFonts(const NGLayoutInlineItem&,
124 const LineItemChunk&, 138 const LineItemChunk&,
125 NGLineBoxFragmentBuilder*); 139 NGLineBoxFragmentBuilder*);
126 LayoutUnit PlaceAtomicInline(const NGLayoutInlineItem&, 140 LayoutUnit PlaceAtomicInline(const NGLayoutInlineItem&,
127 LayoutUnit estimated_baseline, 141 LayoutUnit estimated_baseline,
128 NGLineBoxFragmentBuilder*, 142 NGLineBoxFragmentBuilder*,
129 NGTextFragmentBuilder*); 143 NGTextFragmentBuilder*);
130 144
131 // Finds the next layout opportunity for the next text fragment. 145 // Finds the next layout opportunity for the next text fragment.
132 void FindNextLayoutOpportunity(); 146 void FindNextLayoutOpportunity();
133 147
134 Persistent<NGInlineNode> inline_box_; 148 Persistent<NGInlineNode> inline_box_;
135 NGConstraintSpace* constraint_space_; // Not owned as STACK_ALLOCATED. 149 NGConstraintSpace* constraint_space_; // Not owned as STACK_ALLOCATED.
136 Vector<RefPtr<NGLayoutResult>, 32> layout_results_; 150 Vector<RefPtr<NGLayoutResult>, 32> layout_results_;
137 unsigned start_index_ = 0; 151 unsigned start_index_ = 0;
138 unsigned start_offset_ = 0; 152 unsigned start_offset_ = 0;
139 unsigned last_index_ = 0; 153 unsigned last_index_ = 0;
140 unsigned end_offset_ = 0; 154 unsigned end_offset_ = 0;
141 unsigned last_break_opportunity_index_ = 0; 155 unsigned last_break_opportunity_index_ = 0;
142 unsigned last_break_opportunity_offset_ = 0; 156 unsigned last_break_opportunity_offset_ = 0;
143 LayoutUnit end_position_; 157 LayoutUnit end_position_;
144 LayoutUnit last_break_opportunity_position_; 158 LayoutUnit last_break_opportunity_position_;
145 LayoutUnit content_size_; 159 LayoutUnit content_size_;
146 LayoutUnit max_inline_size_; 160 LayoutUnit max_inline_size_;
147 NGFragmentBuilder container_builder_; 161 NGFragmentBuilder container_builder_;
148 RefPtr<NGLayoutResult> container_layout_result_;
149 FontBaseline baseline_type_ = FontBaseline::AlphabeticBaseline; 162 FontBaseline baseline_type_ = FontBaseline::AlphabeticBaseline;
150 163
151 NGLogicalOffset bfc_offset_; 164 NGLogicalOffset bfc_offset_;
152 NGLogicalRect current_opportunity_; 165 NGLogicalRect current_opportunity_;
153 166
154 unsigned is_horizontal_writing_mode_ : 1; 167 unsigned is_horizontal_writing_mode_ : 1;
155 168
156 NGConstraintSpaceBuilder space_builder_; 169 NGConstraintSpaceBuilder space_builder_;
157 #if DCHECK_IS_ON() 170 #if DCHECK_IS_ON()
158 unsigned is_bidi_reordered_ : 1; 171 unsigned is_bidi_reordered_ : 1;
159 #endif 172 #endif
160 }; 173 };
161 174
162 } // namespace blink 175 } // namespace blink
163 176
164 #endif // NGLineBuilder_h 177 #endif // NGInlineLayoutAlgorithm_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698