OLD | NEW |
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 NGLineBuilder_h |
6 #define NGLineBuilder_h | 6 #define NGLineBuilder_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_opportunity_iterator.h" | 12 #include "core/layout/ng/ng_line_height_metrics.h" |
13 #include "core/layout/ng/ng_physical_fragment.h" | |
14 #include "platform/fonts/FontBaseline.h" | 13 #include "platform/fonts/FontBaseline.h" |
15 #include "platform/heap/Handle.h" | 14 #include "platform/heap/Handle.h" |
16 #include "wtf/Vector.h" | 15 #include "wtf/Vector.h" |
17 | 16 |
18 namespace blink { | 17 namespace blink { |
19 | 18 |
20 class ComputedStyle; | |
21 class FontMetrics; | |
22 class NGConstraintSpace; | 19 class NGConstraintSpace; |
23 class NGInlineNode; | 20 class NGInlineNode; |
24 class NGLayoutInlineItem; | 21 class NGLayoutInlineItem; |
| 22 class NGLineBoxFragmentBuilder; |
| 23 class NGTextFragmentBuilder; |
25 | 24 |
26 // NGLineBuilder creates the fragment tree for a line. | 25 // NGLineBuilder creates the fragment tree for a line. |
27 // NGLineBuilder manages the current line as a range, |start| and |end|. | 26 // NGLineBuilder manages the current line as a range, |start| and |end|. |
28 // |end| can be extended multiple times before creating a line, usually until | 27 // |end| can be extended multiple times before creating a line, usually until |
29 // |!CanFitOnLine()|. | 28 // |!CanFitOnLine()|. |
30 // |SetBreakOpportunity| can mark the last confirmed offset that can fit. | 29 // |SetBreakOpportunity| can mark the last confirmed offset that can fit. |
31 class CORE_EXPORT NGLineBuilder final { | 30 class CORE_EXPORT NGLineBuilder final { |
32 STACK_ALLOCATED(); | 31 STACK_ALLOCATED(); |
33 | 32 |
34 public: | 33 public: |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 void BidiReorder(Vector<LineItemChunk, 32>*); | 112 void BidiReorder(Vector<LineItemChunk, 32>*); |
114 | 113 |
115 // Lays out the inline float. | 114 // Lays out the inline float. |
116 // List of actions: | 115 // List of actions: |
117 // - tries to position the float right away if we have enough space. | 116 // - tries to position the float right away if we have enough space. |
118 // - updates the current_opportunity if we actually place the float. | 117 // - updates the current_opportunity if we actually place the float. |
119 // - if it's too wide then we add the float to the unpositioned list so it can | 118 // - if it's too wide then we add the float to the unpositioned list so it can |
120 // be positioned after we're done with the current line. | 119 // be positioned after we're done with the current line. |
121 void LayoutAndPositionFloat(LayoutUnit end_position, LayoutObject*); | 120 void LayoutAndPositionFloat(LayoutUnit end_position, LayoutObject*); |
122 | 121 |
123 // Represents block-direction metrics for an |NGLayoutInlineItem|. | |
124 struct InlineItemMetrics { | |
125 float ascent; | |
126 float descent; | |
127 float ascent_and_leading; | |
128 float descent_and_leading; | |
129 | |
130 // Use the leading from the 'line-height' property, or the font metrics of | |
131 // the primary font if 'line-height: normal'. | |
132 InlineItemMetrics(const ComputedStyle&, FontBaseline); | |
133 | |
134 // Use the leading from the font metrics. | |
135 InlineItemMetrics(const FontMetrics&, FontBaseline); | |
136 | |
137 private: | |
138 void Initialize(const FontMetrics&, FontBaseline, float line_height); | |
139 }; | |
140 | |
141 // LineBoxData is a set of data for a line box that are computed in early | |
142 // phases, such as in |CreateLine()|, and will be used in later phases. | |
143 // TODO(kojii): Not sure if all these data are needed in fragment tree. If | |
144 // they are, we can create a linebox fragment, store them there, and this | |
145 // isn't needed. For now, we're trying to minimize data in fragments. | |
146 struct LineBoxData { | |
147 unsigned fragment_end; | |
148 LayoutUnit inline_size; | |
149 LayoutUnit top_with_leading; | |
150 float max_ascent = 0; | |
151 float max_descent = 0; | |
152 float max_ascent_and_leading = 0; | |
153 float max_descent_and_leading = 0; | |
154 | |
155 // Include |InlineItemMetrics| into the metrics for this line box. | |
156 void UpdateMaxAscentAndDescent(const InlineItemMetrics&); | |
157 }; | |
158 | |
159 void PlaceItems(const Vector<LineItemChunk, 32>&); | 122 void PlaceItems(const Vector<LineItemChunk, 32>&); |
160 void AccumulateUsedFonts(const NGLayoutInlineItem&, | 123 void AccumulateUsedFonts(const NGLayoutInlineItem&, |
161 const LineItemChunk&, | 124 const LineItemChunk&, |
162 LineBoxData*); | 125 NGLineBoxFragmentBuilder*); |
163 LayoutUnit PlaceAtomicInline(const NGLayoutInlineItem&, | 126 LayoutUnit PlaceAtomicInline(const NGLayoutInlineItem&, |
164 LayoutUnit estimated_baseline, | 127 LayoutUnit estimated_baseline, |
165 LineBoxData*, | 128 NGLineBoxFragmentBuilder*, |
166 NGFragmentBuilder*); | 129 NGTextFragmentBuilder*); |
167 | 130 |
168 // Finds the next layout opportunity for the next text fragment. | 131 // Finds the next layout opportunity for the next text fragment. |
169 void FindNextLayoutOpportunity(); | 132 void FindNextLayoutOpportunity(); |
170 | 133 |
171 Persistent<NGInlineNode> inline_box_; | 134 Persistent<NGInlineNode> inline_box_; |
172 NGConstraintSpace* constraint_space_; // Not owned as STACK_ALLOCATED. | 135 NGConstraintSpace* constraint_space_; // Not owned as STACK_ALLOCATED. |
173 Vector<RefPtr<NGLayoutResult>, 32> layout_results_; | 136 Vector<RefPtr<NGLayoutResult>, 32> layout_results_; |
174 Vector<LineBoxData, 32> line_box_data_list_; | |
175 unsigned start_index_ = 0; | 137 unsigned start_index_ = 0; |
176 unsigned start_offset_ = 0; | 138 unsigned start_offset_ = 0; |
177 unsigned last_index_ = 0; | 139 unsigned last_index_ = 0; |
178 unsigned end_offset_ = 0; | 140 unsigned end_offset_ = 0; |
179 unsigned last_break_opportunity_index_ = 0; | 141 unsigned last_break_opportunity_index_ = 0; |
180 unsigned last_break_opportunity_offset_ = 0; | 142 unsigned last_break_opportunity_offset_ = 0; |
181 LayoutUnit end_position_; | 143 LayoutUnit end_position_; |
182 LayoutUnit last_break_opportunity_position_; | 144 LayoutUnit last_break_opportunity_position_; |
183 LayoutUnit content_size_; | 145 LayoutUnit content_size_; |
184 LayoutUnit max_inline_size_; | 146 LayoutUnit max_inline_size_; |
185 NGFragmentBuilder container_builder_; | 147 NGFragmentBuilder container_builder_; |
186 RefPtr<NGLayoutResult> container_layout_result_; | 148 RefPtr<NGLayoutResult> container_layout_result_; |
187 FontBaseline baseline_type_ = FontBaseline::AlphabeticBaseline; | 149 FontBaseline baseline_type_ = FontBaseline::AlphabeticBaseline; |
188 | 150 |
189 NGLogicalOffset bfc_offset_; | 151 NGLogicalOffset bfc_offset_; |
190 NGLogicalRect current_opportunity_; | 152 NGLogicalRect current_opportunity_; |
191 | 153 |
192 unsigned is_horizontal_writing_mode_ : 1; | 154 unsigned is_horizontal_writing_mode_ : 1; |
193 | 155 |
194 NGConstraintSpaceBuilder space_builder_; | 156 NGConstraintSpaceBuilder space_builder_; |
195 #if DCHECK_IS_ON() | 157 #if DCHECK_IS_ON() |
196 unsigned is_bidi_reordered_ : 1; | 158 unsigned is_bidi_reordered_ : 1; |
197 #endif | 159 #endif |
198 }; | 160 }; |
199 | 161 |
200 } // namespace blink | 162 } // namespace blink |
201 | 163 |
202 #endif // NGLineBuilder_h | 164 #endif // NGLineBuilder_h |
OLD | NEW |