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

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

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

Powered by Google App Engine
This is Rietveld 408576698