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

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: 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.
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. 54 // Set the end offset.
53 void SetEnd(unsigned end_offset); 55 void SetEnd(unsigned end_offset);
54 56
55 // Set the end offset if caller knows the inline size since the current end. 57 // Set the end offset if caller knows the inline size since the current end.
56 void SetEnd(unsigned index, 58 void SetEnd(unsigned index,
57 unsigned end_offset, 59 unsigned end_offset,
58 LayoutUnit inline_size_since_current_end); 60 LayoutUnit inline_size_since_current_end);
59 61
60 // Create a line up to the end offset. 62 // Create a line up to the end offset.
61 // Then set the start to the end offset, and thus empty the current line. 63 // Then set the start to the end offset, and thus empty the current line.
62 void CreateLine(); 64 // @return false if the line does not fit in the constraint space in block
65 // direction.
ikilpatrick 2017/03/27 09:19:59 +indent.
66 bool CreateLine();
63 67
64 // Returns if a break opportunity was set on the current line. 68 // Returns if a break opportunity was set on the current line.
65 bool HasBreakOpportunity() const; 69 bool HasBreakOpportunity() const;
66 70
67 // Returns if there were items after the last break opportunity. 71 // Returns if there were items after the last break opportunity.
68 bool HasItemsAfterLastBreakOpportunity() const; 72 bool HasItemsAfterLastBreakOpportunity() const;
69 73
70 // Set the break opportunity at the current end offset. 74 // Set the break opportunity at the current end offset.
71 void SetBreakOpportunity(); 75 void SetBreakOpportunity();
72 76
73 // Create a line up to the last break opportunity. 77 // Create a line up to the last break opportunity.
74 // Items after that are sent to the next line. 78 // Items after that are sent to the next line.
75 void CreateLineUpToLastBreakOpportunity(); 79 // @return false if the line does not fit in the constraint space in block
80 // direction.
81 bool CreateLineUpToLastBreakOpportunity();
76 82
77 // Set the start offset of hangables; e.g., spaces or hanging punctuations. 83 // 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 84 // Hangable characters can go beyond the right margin, and are ignored for
79 // center/right alignment. 85 // center/right alignment.
80 void SetStartOfHangables(unsigned offset); 86 void SetStartOfHangables(unsigned offset);
81 87
82 // Create fragments for all lines created so far. 88 RefPtr<NGLayoutResult> Layout() override;
83 RefPtr<NGLayoutResult> CreateFragments();
84 89
85 // Copy fragment data of all lines created by this NGLineBuilder to 90 // Compute MinMaxContentSize by performing layout.
86 // LayoutBlockFlow. 91 // Unlike NGLayoutAlgorithm::ComputeMinMaxContentSize(), this function runs
87 // This must run after |CreateFragments()|, and after the fragments it created 92 // part of layout operations and modifies the state of |this|.
88 // are placed. 93 MinMaxContentSize ComputeMinMaxContentSizeByLayout();
89 void CopyFragmentDataToLayoutBlockFlow(); 94
95 // Copy fragment data of all lines to LayoutBlockFlow.
96 // TODO(kojii): Move to NGInlineNode (or remove when paint is implemented.)
97 void CopyFragmentDataToLayoutBlockFlow(NGLayoutResult*);
90 98
91 // Compute inline size of an NGLayoutInlineItem. 99 // Compute inline size of an NGLayoutInlineItem.
92 // Same as NGLayoutInlineItem::InlineSize(), except that this function can 100 // Same as NGLayoutInlineItem::InlineSize(), except that this function can
93 // compute atomic inlines by performing layout. 101 // compute atomic inlines by performing layout.
94 LayoutUnit InlineSize(const NGLayoutInlineItem&); 102 LayoutUnit InlineSize(const NGLayoutInlineItem&);
95 103
96 private: 104 private:
97 bool IsHorizontalWritingMode() const { return is_horizontal_writing_mode_; } 105 bool IsHorizontalWritingMode() const { return is_horizontal_writing_mode_; }
98 106
107 // Set the start and the end to the specified offset.
108 // This empties the current line.
109 void Initialize(unsigned index, unsigned offset);
110
99 LayoutUnit InlineSize(const NGLayoutInlineItem&, 111 LayoutUnit InlineSize(const NGLayoutInlineItem&,
100 unsigned start_offset, 112 unsigned start_offset,
101 unsigned end_offset); 113 unsigned end_offset);
102 LayoutUnit InlineSizeFromLayout(const NGLayoutInlineItem&); 114 LayoutUnit InlineSizeFromLayout(const NGLayoutInlineItem&);
103 const NGLayoutResult* LayoutItem(const NGLayoutInlineItem&); 115 const NGLayoutResult* LayoutItem(const NGLayoutInlineItem&);
104 116
105 struct LineItemChunk { 117 struct LineItemChunk {
106 unsigned index; 118 unsigned index;
107 unsigned start_offset; 119 unsigned start_offset;
108 unsigned end_offset; 120 unsigned end_offset;
109 LayoutUnit inline_size; 121 LayoutUnit inline_size;
110 }; 122 };
111 123
112 void BidiReorder(Vector<LineItemChunk, 32>*); 124 void BidiReorder(Vector<LineItemChunk, 32>*);
113 125
114 // Lays out the inline float. 126 // Lays out the inline float.
115 // List of actions: 127 // List of actions:
116 // - tries to position the float right away if we have enough space. 128 // - tries to position the float right away if we have enough space.
117 // - updates the current_opportunity if we actually place the float. 129 // - 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 130 // - 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. 131 // be positioned after we're done with the current line.
120 void LayoutAndPositionFloat(LayoutUnit end_position, LayoutObject*); 132 void LayoutAndPositionFloat(LayoutUnit end_position, LayoutObject*);
121 133
122 void PlaceItems(const Vector<LineItemChunk, 32>&); 134 bool PlaceItems(const Vector<LineItemChunk, 32>&);
123 void AccumulateUsedFonts(const NGLayoutInlineItem&, 135 void AccumulateUsedFonts(const NGLayoutInlineItem&,
124 const LineItemChunk&, 136 const LineItemChunk&,
125 NGLineBoxFragmentBuilder*); 137 NGLineBoxFragmentBuilder*);
126 LayoutUnit PlaceAtomicInline(const NGLayoutInlineItem&, 138 LayoutUnit PlaceAtomicInline(const NGLayoutInlineItem&,
127 LayoutUnit estimated_baseline, 139 LayoutUnit estimated_baseline,
128 NGLineBoxFragmentBuilder*, 140 NGLineBoxFragmentBuilder*,
129 NGTextFragmentBuilder*); 141 NGTextFragmentBuilder*);
130 142
131 // Finds the next layout opportunity for the next text fragment. 143 // Finds the next layout opportunity for the next text fragment.
132 void FindNextLayoutOpportunity(); 144 void FindNextLayoutOpportunity();
133 145
134 Persistent<NGInlineNode> inline_box_; 146 Persistent<NGInlineNode> inline_box_;
135 NGConstraintSpace* constraint_space_; // Not owned as STACK_ALLOCATED. 147 NGConstraintSpace* constraint_space_; // Not owned as STACK_ALLOCATED.
136 Vector<RefPtr<NGLayoutResult>, 32> layout_results_; 148 Vector<RefPtr<NGLayoutResult>, 32> layout_results_;
137 unsigned start_index_ = 0; 149 unsigned start_index_ = 0;
138 unsigned start_offset_ = 0; 150 unsigned start_offset_ = 0;
139 unsigned last_index_ = 0; 151 unsigned last_index_ = 0;
140 unsigned end_offset_ = 0; 152 unsigned end_offset_ = 0;
141 unsigned last_break_opportunity_index_ = 0; 153 unsigned last_break_opportunity_index_ = 0;
142 unsigned last_break_opportunity_offset_ = 0; 154 unsigned last_break_opportunity_offset_ = 0;
143 LayoutUnit end_position_; 155 LayoutUnit end_position_;
144 LayoutUnit last_break_opportunity_position_; 156 LayoutUnit last_break_opportunity_position_;
145 LayoutUnit content_size_; 157 LayoutUnit content_size_;
146 LayoutUnit max_inline_size_; 158 LayoutUnit max_inline_size_;
147 NGFragmentBuilder container_builder_; 159 NGFragmentBuilder container_builder_;
148 RefPtr<NGLayoutResult> container_layout_result_;
149 FontBaseline baseline_type_ = FontBaseline::AlphabeticBaseline; 160 FontBaseline baseline_type_ = FontBaseline::AlphabeticBaseline;
150 161
151 NGLogicalOffset bfc_offset_; 162 NGLogicalOffset bfc_offset_;
152 NGLogicalRect current_opportunity_; 163 NGLogicalRect current_opportunity_;
153 164
154 unsigned is_horizontal_writing_mode_ : 1; 165 unsigned is_horizontal_writing_mode_ : 1;
155 166
156 NGConstraintSpaceBuilder space_builder_; 167 NGConstraintSpaceBuilder space_builder_;
157 #if DCHECK_IS_ON() 168 #if DCHECK_IS_ON()
158 unsigned is_bidi_reordered_ : 1; 169 unsigned is_bidi_reordered_ : 1;
159 #endif 170 #endif
160 }; 171 };
161 172
162 } // namespace blink 173 } // namespace blink
163 174
164 #endif // NGLineBuilder_h 175 #endif // NGInlineLayoutAlgorithm_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698