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

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

Issue 2772503004: [LayoutNG] Add NGInlineBreakToken and back of NGInlineLayoutAlgorithm (Closed)
Patch Set: Resolved merge conflicts Created 3 years, 8 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef NGLineBuilder_h
6 #define NGLineBuilder_h
7
8 #include "core/CoreExport.h"
9 #include "core/layout/ng/geometry/ng_logical_offset.h"
10 #include "core/layout/ng/ng_constraint_space_builder.h"
11 #include "core/layout/ng/ng_fragment_builder.h"
12 #include "core/layout/ng/ng_line_height_metrics.h"
13 #include "platform/fonts/FontBaseline.h"
14 #include "platform/heap/Handle.h"
15 #include "wtf/Vector.h"
16
17 namespace blink {
18
19 class NGConstraintSpace;
20 class NGInlineNode;
21 class NGLayoutInlineItem;
22 class NGLineBoxFragmentBuilder;
23 class NGTextFragmentBuilder;
24
25 // NGLineBuilder creates the fragment tree for a line.
26 // NGLineBuilder manages the current line as a range, |start| and |end|.
27 // |end| can be extended multiple times before creating a line, usually until
28 // |!CanFitOnLine()|.
29 // |SetBreakOpportunity| can mark the last confirmed offset that can fit.
30 class CORE_EXPORT NGLineBuilder final {
31 STACK_ALLOCATED();
32
33 public:
34 NGLineBuilder(NGInlineNode*, NGConstraintSpace*);
35
36 const NGConstraintSpace& ConstraintSpace() const {
37 return *constraint_space_;
38 }
39
40 LayoutUnit MaxInlineSize() const { return max_inline_size_; }
41
42 // Returns if the current items fit on a line.
43 bool CanFitOnLine() const;
44
45 // Returns if there were any items.
46 bool HasItems() const;
47
48 // Set the start offset.
49 // Set the end as well, and therefore empties the current line.
50 void SetStart(unsigned index, unsigned offset);
51
52 // Set the end offset.
53 void SetEnd(unsigned end_offset);
54
55 // Set the end offset if caller knows the inline size since the current end.
56 void SetEnd(unsigned index,
57 unsigned end_offset,
58 LayoutUnit inline_size_since_current_end);
59
60 // Create a line up to the end offset.
61 // Then set the start to the end offset, and thus empty the current line.
62 void CreateLine();
63
64 // Returns if a break opportunity was set on the current line.
65 bool HasBreakOpportunity() const;
66
67 // Returns if there were items after the last break opportunity.
68 bool HasItemsAfterLastBreakOpportunity() const;
69
70 // Set the break opportunity at the current end offset.
71 void SetBreakOpportunity();
72
73 // Create a line up to the last break opportunity.
74 // Items after that are sent to the next line.
75 void CreateLineUpToLastBreakOpportunity();
76
77 // 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
79 // center/right alignment.
80 void SetStartOfHangables(unsigned offset);
81
82 // Create fragments for all lines created so far.
83 RefPtr<NGLayoutResult> CreateFragments();
84
85 // Copy fragment data of all lines created by this NGLineBuilder to
86 // LayoutBlockFlow.
87 // This must run after |CreateFragments()|, and after the fragments it created
88 // are placed.
89 void CopyFragmentDataToLayoutBlockFlow();
90
91 // Compute inline size of an NGLayoutInlineItem.
92 // Same as NGLayoutInlineItem::InlineSize(), except that this function can
93 // compute atomic inlines by performing layout.
94 LayoutUnit InlineSize(const NGLayoutInlineItem&);
95
96 private:
97 bool IsHorizontalWritingMode() const { return is_horizontal_writing_mode_; }
98
99 LayoutUnit InlineSize(const NGLayoutInlineItem&,
100 unsigned start_offset,
101 unsigned end_offset);
102 LayoutUnit InlineSizeFromLayout(const NGLayoutInlineItem&);
103 const NGLayoutResult* LayoutItem(const NGLayoutInlineItem&);
104
105 struct LineItemChunk {
106 unsigned index;
107 unsigned start_offset;
108 unsigned end_offset;
109 LayoutUnit inline_size;
110 };
111
112 void BidiReorder(Vector<LineItemChunk, 32>*);
113
114 // Lays out the inline float.
115 // List of actions:
116 // - tries to position the float right away if we have enough space.
117 // - 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
119 // be positioned after we're done with the current line.
120 void LayoutAndPositionFloat(LayoutUnit end_position, LayoutObject*);
121
122 void PlaceItems(const Vector<LineItemChunk, 32>&);
123 void AccumulateUsedFonts(const NGLayoutInlineItem&,
124 const LineItemChunk&,
125 NGLineBoxFragmentBuilder*);
126 LayoutUnit PlaceAtomicInline(const NGLayoutInlineItem&,
127 LayoutUnit estimated_baseline,
128 NGLineBoxFragmentBuilder*,
129 NGTextFragmentBuilder*);
130
131 // Finds the next layout opportunity for the next text fragment.
132 void FindNextLayoutOpportunity();
133
134 Persistent<NGInlineNode> inline_box_;
135 NGConstraintSpace* constraint_space_; // Not owned as STACK_ALLOCATED.
136 Vector<RefPtr<NGLayoutResult>, 32> layout_results_;
137 unsigned start_index_ = 0;
138 unsigned start_offset_ = 0;
139 unsigned last_index_ = 0;
140 unsigned end_offset_ = 0;
141 unsigned last_break_opportunity_index_ = 0;
142 unsigned last_break_opportunity_offset_ = 0;
143 LayoutUnit end_position_;
144 LayoutUnit last_break_opportunity_position_;
145 LayoutUnit content_size_;
146 LayoutUnit max_inline_size_;
147 NGFragmentBuilder container_builder_;
148 RefPtr<NGLayoutResult> container_layout_result_;
149 FontBaseline baseline_type_ = FontBaseline::AlphabeticBaseline;
150
151 NGLogicalOffset bfc_offset_;
152 NGLogicalRect current_opportunity_;
153
154 unsigned is_horizontal_writing_mode_ : 1;
155
156 NGConstraintSpaceBuilder space_builder_;
157 #if DCHECK_IS_ON()
158 unsigned is_bidi_reordered_ : 1;
159 #endif
160 };
161
162 } // namespace blink
163
164 #endif // NGLineBuilder_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698