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_line_breaker.h" | 5 #include "core/layout/ng/inline/ng_line_breaker.h" |
6 | 6 |
7 #include "core/layout/ng/inline/ng_inline_break_token.h" | 7 #include "core/layout/ng/inline/ng_inline_break_token.h" |
8 #include "core/layout/ng/inline/ng_inline_layout_algorithm.h" | 8 #include "core/layout/ng/inline/ng_inline_layout_algorithm.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_text_fragment.h" | 10 #include "core/layout/ng/inline/ng_text_fragment.h" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 return std::make_pair(next_break, next_inline_size); | 49 return std::make_pair(next_break, next_inline_size); |
50 offset = next_break; | 50 offset = next_break; |
51 inline_size = next_inline_size; | 51 inline_size = next_inline_size; |
52 has_break_opportunities = true; | 52 has_break_opportunities = true; |
53 } | 53 } |
54 } | 54 } |
55 #endif | 55 #endif |
56 | 56 |
57 } // namespace | 57 } // namespace |
58 | 58 |
59 NGLineBreaker::NGLineBreaker(NGInlineNode node, | 59 NGLineBreaker::NGLineBreaker( |
60 NGConstraintSpace* space, | 60 NGInlineNode node, |
61 NGFragmentBuilder* container_builder, | 61 NGConstraintSpace* space, |
62 const NGInlineBreakToken* break_token) | 62 NGFragmentBuilder* container_builder, |
| 63 Vector<RefPtr<NGUnpositionedFloat>>* unpositioned_floats, |
| 64 const NGInlineBreakToken* break_token) |
63 : node_(node), | 65 : node_(node), |
64 constraint_space_(space), | 66 constraint_space_(space), |
65 container_builder_(container_builder), | 67 container_builder_(container_builder), |
| 68 unpositioned_floats_(unpositioned_floats), |
66 item_index_(0), | 69 item_index_(0), |
67 offset_(0), | 70 offset_(0), |
68 break_iterator_(node.Text()), | 71 break_iterator_(node.Text()), |
69 shaper_(node.Text().Characters16(), node.Text().length()), | 72 shaper_(node.Text().Characters16(), node.Text().length()), |
70 spacing_(node.Text()), | 73 spacing_(node.Text()), |
71 auto_wrap_(false), | 74 auto_wrap_(false), |
72 should_create_line_box_(false), | 75 should_create_line_box_(false), |
73 is_after_forced_break_(false) { | 76 is_after_forced_break_(false) { |
74 if (break_token) { | 77 if (break_token) { |
75 item_index_ = break_token->ItemIndex(); | 78 item_index_ = break_token->ItemIndex(); |
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
416 constraint_space_->BfcOffset().inline_offset, margins, node, | 419 constraint_space_->BfcOffset().inline_offset, margins, node, |
417 /* break_token */ nullptr); | 420 /* break_token */ nullptr); |
418 | 421 |
419 LayoutUnit inline_size = ComputeInlineSizeForUnpositionedFloat( | 422 LayoutUnit inline_size = ComputeInlineSizeForUnpositionedFloat( |
420 constraint_space_, unpositioned_float.Get()); | 423 constraint_space_, unpositioned_float.Get()); |
421 | 424 |
422 // We can only determine if our float will fit if we have an available_width | 425 // We can only determine if our float will fit if we have an available_width |
423 // I.e. we may not have come across any text yet, in order to be able to | 426 // I.e. we may not have come across any text yet, in order to be able to |
424 // resolve the BFC position. | 427 // resolve the BFC position. |
425 bool float_does_not_fit = | 428 bool float_does_not_fit = |
426 !HasAvailableWidth() || | 429 (!constraint_space_->FloatsBfcOffset() || |
427 position_ + inline_size + margins.InlineSum() > AvailableWidth(); | 430 container_builder_->BfcOffset()) && |
| 431 (!HasAvailableWidth() || |
| 432 position_ + inline_size + margins.InlineSum() > AvailableWidth()); |
428 | 433 |
429 // Check if we already have a pending float. That's because a float cannot be | 434 // Check if we already have a pending float. That's because a float cannot be |
430 // higher than any block or floated box generated before. | 435 // higher than any block or floated box generated before. |
431 if (!container_builder_->UnpositionedFloats().IsEmpty() || | 436 if (!unpositioned_floats_->IsEmpty() || float_does_not_fit) { |
432 float_does_not_fit) { | 437 unpositioned_floats_->push_back(std::move(unpositioned_float)); |
433 container_builder_->AddUnpositionedFloat(unpositioned_float); | |
434 } else { | 438 } else { |
435 NGLogicalOffset container_bfc_offset = | 439 NGLogicalOffset container_bfc_offset = |
436 container_builder_->BfcOffset().value(); | 440 container_builder_->BfcOffset() |
| 441 ? container_builder_->BfcOffset().value() |
| 442 : constraint_space_->FloatsBfcOffset().value(); |
437 LayoutUnit origin_block_offset = | 443 LayoutUnit origin_block_offset = |
438 container_bfc_offset.block_offset + content_offset_.block_offset; | 444 container_bfc_offset.block_offset + content_offset_.block_offset; |
439 | 445 |
440 container_builder_->AddPositionedFloat( | 446 container_builder_->AddPositionedFloat( |
441 PositionFloat(origin_block_offset, container_bfc_offset.block_offset, | 447 PositionFloat(origin_block_offset, container_bfc_offset.block_offset, |
442 unpositioned_float.Get(), constraint_space_)); | 448 unpositioned_float.Get(), constraint_space_)); |
443 | 449 |
444 // We need to recalculate the available_width as the float probably | 450 // We need to recalculate the available_width as the float probably |
445 // consumed space on the line. | 451 // consumed space on the line. |
446 UpdateAvailableWidth(); | 452 if (container_builder_->BfcOffset()) |
| 453 UpdateAvailableWidth(); |
447 } | 454 } |
448 | 455 |
449 // Floats are already positioned in the container_builder. | 456 // Floats are already positioned in the container_builder. |
450 item_results->pop_back(); | 457 item_results->pop_back(); |
451 MoveToNextOf(item); | 458 MoveToNextOf(item); |
452 } | 459 } |
453 | 460 |
454 void NGLineBreaker::HandleOpenTag(const NGInlineItem& item, | 461 void NGLineBreaker::HandleOpenTag(const NGInlineItem& item, |
455 NGInlineItemResult* item_result) { | 462 NGInlineItemResult* item_result) { |
456 DCHECK(item.Style()); | 463 DCHECK(item.Style()); |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
655 } | 662 } |
656 | 663 |
657 RefPtr<NGInlineBreakToken> NGLineBreaker::CreateBreakToken() const { | 664 RefPtr<NGInlineBreakToken> NGLineBreaker::CreateBreakToken() const { |
658 const Vector<NGInlineItem>& items = node_.Items(); | 665 const Vector<NGInlineItem>& items = node_.Items(); |
659 if (item_index_ >= items.size()) | 666 if (item_index_ >= items.size()) |
660 return nullptr; | 667 return nullptr; |
661 return NGInlineBreakToken::Create(node_, item_index_, offset_); | 668 return NGInlineBreakToken::Create(node_, item_index_, offset_); |
662 } | 669 } |
663 | 670 |
664 } // namespace blink | 671 } // namespace blink |
OLD | NEW |