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 #include "core/layout/ng/inline/ng_inline_layout_algorithm.h" | 5 #include "core/layout/ng/inline/ng_inline_layout_algorithm.h" |
6 | 6 |
7 #include "core/layout/ng/inline/ng_bidi_paragraph.h" | 7 #include "core/layout/ng/inline/ng_bidi_paragraph.h" |
8 #include "core/layout/ng/inline/ng_inline_break_token.h" | 8 #include "core/layout/ng/inline/ng_inline_break_token.h" |
9 #include "core/layout/ng/inline/ng_inline_node.h" | 9 #include "core/layout/ng/inline/ng_inline_node.h" |
10 #include "core/layout/ng/inline/ng_line_box_fragment.h" | 10 #include "core/layout/ng/inline/ng_line_box_fragment.h" |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
241 // Up until this point, children are placed so that the dominant baseline is | 241 // Up until this point, children are placed so that the dominant baseline is |
242 // at 0. Move them to the final baseline position, and set the logical top of | 242 // at 0. Move them to the final baseline position, and set the logical top of |
243 // the line box to the line top. | 243 // the line box to the line top. |
244 line_box.MoveChildrenInBlockDirection(baseline); | 244 line_box.MoveChildrenInBlockDirection(baseline); |
245 | 245 |
246 NGLayoutOpportunity line_opp = FindLayoutOpportunityForLine(); | 246 NGLayoutOpportunity line_opp = FindLayoutOpportunityForLine(); |
247 | 247 |
248 LayoutUnit inline_size = position; | 248 LayoutUnit inline_size = position; |
249 NGLogicalOffset offset(LogicalLeftOffset(line_opp), | 249 NGLogicalOffset offset(LogicalLeftOffset(line_opp), |
250 baseline - box_states_.LineBoxState().metrics.ascent); | 250 baseline - box_states_.LineBoxState().metrics.ascent); |
251 ApplyTextAlign(line_style, line_style.GetTextAlign(line_info->IsLastLine()), | 251 ApplyTextAlign(line_style.GetTextAlign(line_info->IsLastLine()), |
252 &offset.inline_offset, inline_size, line_opp.InlineSize()); | 252 &offset.inline_offset, inline_size, line_opp.InlineSize()); |
253 | 253 |
254 line_box.SetInlineSize(inline_size); | 254 line_box.SetInlineSize(inline_size); |
255 container_builder_.AddChild(line_box.ToLineBoxFragment(), offset); | 255 container_builder_.AddChild(line_box.ToLineBoxFragment(), offset); |
256 | 256 |
257 max_inline_size_ = std::max(max_inline_size_, inline_size); | 257 max_inline_size_ = std::max(max_inline_size_, inline_size); |
258 content_size_ = ComputeContentSize(*line_info, line_bottom); | 258 content_size_ = ComputeContentSize(*line_info, line_bottom); |
259 | 259 |
260 return true; | 260 return true; |
261 } | 261 } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
304 text_builder->SetSize({fragment.InlineSize(), block_size}); | 304 text_builder->SetSize({fragment.InlineSize(), block_size}); |
305 LayoutUnit line_top = item_result->margins.block_start - metrics.ascent; | 305 LayoutUnit line_top = item_result->margins.block_start - metrics.ascent; |
306 RefPtr<NGPhysicalTextFragment> text_fragment = text_builder->ToTextFragment( | 306 RefPtr<NGPhysicalTextFragment> text_fragment = text_builder->ToTextFragment( |
307 item_result->item_index, item_result->start_offset, | 307 item_result->item_index, item_result->start_offset, |
308 item_result->end_offset); | 308 item_result->end_offset); |
309 line_box->AddChild(std::move(text_fragment), {position, line_top}); | 309 line_box->AddChild(std::move(text_fragment), {position, line_top}); |
310 | 310 |
311 return box_states_.OnCloseTag(item, line_box, box, baseline_type_); | 311 return box_states_.OnCloseTag(item, line_box, box, baseline_type_); |
312 } | 312 } |
313 | 313 |
314 void NGInlineLayoutAlgorithm::ApplyTextAlign(const ComputedStyle& line_style, | 314 void NGInlineLayoutAlgorithm::ApplyTextAlign(ETextAlign text_align, |
315 ETextAlign text_align, | |
316 LayoutUnit* line_left, | 315 LayoutUnit* line_left, |
317 LayoutUnit inline_size, | 316 LayoutUnit inline_size, |
318 LayoutUnit available_width) { | 317 LayoutUnit available_width) { |
319 switch (text_align) { | 318 bool is_base_ltr = IsLtr(Node().BaseDirection()); |
320 case ETextAlign::kRight: | 319 // TODO(kojii): Investigate handling trailing spaces. |
eae
2017/06/20 17:54:41
You might want to clarify that this is only for wh
| |
321 case ETextAlign::kWebkitRight: | 320 // Refer to LayoutBlockFlow::UpdateLogicalWidthForAlignment(). |
322 // Wide lines spill out of the block based off direction. | 321 while (true) { |
323 // So even if text-align is right, if direction is LTR, wide lines should | 322 switch (text_align) { |
324 // overflow out of the right side of the block. | 323 case ETextAlign::kLeft: |
325 // TODO(kojii): Investigate how to handle trailing spaces. | 324 case ETextAlign::kWebkitLeft: |
326 if (inline_size < available_width || !line_style.IsLeftToRightDirection()) | 325 // The direction of the block should determine what happens with wide |
327 *line_left += available_width - inline_size; | 326 // lines. In particular with RTL blocks, wide lines should still spill |
328 break; | 327 // out to the left. |
329 default: | 328 if (!is_base_ltr && inline_size > available_width) |
330 // TODO(layout-dev): Implement. | 329 *line_left -= inline_size - available_width; |
331 // Refer to LayoutBlockFlow::UpdateLogicalWidthForAlignment(). | 330 return; |
332 break; | 331 case ETextAlign::kRight: |
332 case ETextAlign::kWebkitRight: | |
333 // Wide lines spill out of the block based off direction. | |
334 // So even if text-align is right, if direction is LTR, wide lines | |
335 // should overflow out of the right side of the block. | |
336 if (inline_size < available_width || !is_base_ltr) | |
337 *line_left += available_width - inline_size; | |
338 return; | |
339 case ETextAlign::kCenter: | |
340 case ETextAlign::kWebkitCenter: | |
341 if (is_base_ltr) { | |
342 *line_left += | |
eae
2017/06/20 17:54:41
Much easier to follow now, thank you!
| |
343 std::max((available_width - inline_size) / 2, LayoutUnit()); | |
344 } else if (inline_size <= available_width) { | |
345 *line_left += (available_width - inline_size) / 2; | |
346 } else { | |
347 // In RTL, wide lines should spill out to the left, same as kRight. | |
348 *line_left += available_width - inline_size; | |
349 } | |
350 return; | |
351 case ETextAlign::kStart: | |
352 text_align = is_base_ltr ? ETextAlign::kLeft : ETextAlign::kRight; | |
353 continue; | |
354 case ETextAlign::kEnd: | |
355 text_align = is_base_ltr ? ETextAlign::kRight : ETextAlign::kLeft; | |
356 continue; | |
357 case ETextAlign::kJustify: | |
358 // TODO(kojii): Implement. | |
359 return; | |
360 } | |
361 NOTREACHED(); | |
362 return; | |
333 } | 363 } |
334 } | 364 } |
335 | 365 |
336 LayoutUnit NGInlineLayoutAlgorithm::ComputeContentSize( | 366 LayoutUnit NGInlineLayoutAlgorithm::ComputeContentSize( |
337 const NGLineInfo& line_info, | 367 const NGLineInfo& line_info, |
338 LayoutUnit line_bottom) { | 368 LayoutUnit line_bottom) { |
339 LayoutUnit content_size = line_bottom; | 369 LayoutUnit content_size = line_bottom; |
340 | 370 |
341 const Vector<NGInlineItem>& items = Node().Items(); | 371 const Vector<NGInlineItem>& items = Node().Items(); |
342 const NGInlineItemResults& line_items = line_info.Results(); | 372 const NGInlineItemResults& line_items = line_info.Results(); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
405 // Margin struts shouldn't need to be passed through like this once we've | 435 // Margin struts shouldn't need to be passed through like this once we've |
406 // removed LayoutInline splitting. | 436 // removed LayoutInline splitting. |
407 if (!container_builder_.BfcOffset()) { | 437 if (!container_builder_.BfcOffset()) { |
408 container_builder_.SetEndMarginStrut(ConstraintSpace().MarginStrut()); | 438 container_builder_.SetEndMarginStrut(ConstraintSpace().MarginStrut()); |
409 } | 439 } |
410 | 440 |
411 return container_builder_.ToBoxFragment(); | 441 return container_builder_.ToBoxFragment(); |
412 } | 442 } |
413 | 443 |
414 } // namespace blink | 444 } // namespace blink |
OLD | NEW |