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

Side by Side Diff: third_party/WebKit/Source/core/layout/ng/inline/ng_line_breaker.cc

Issue 2954953002: [LayoutNG] Abort a layout once the BFC offset is resolved. (Closed)
Patch Set: rebase. Created 3 years, 5 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 #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
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 353 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 constraint_space_->BfcOffset().inline_offset, margins, node, 432 constraint_space_->BfcOffset().inline_offset, margins, node,
430 /* break_token */ nullptr); 433 /* break_token */ nullptr);
431 434
432 LayoutUnit inline_size = ComputeInlineSizeForUnpositionedFloat( 435 LayoutUnit inline_size = ComputeInlineSizeForUnpositionedFloat(
433 constraint_space_, unpositioned_float.Get()); 436 constraint_space_, unpositioned_float.Get());
434 437
435 // We can only determine if our float will fit if we have an available_width 438 // We can only determine if our float will fit if we have an available_width
436 // I.e. we may not have come across any text yet, in order to be able to 439 // I.e. we may not have come across any text yet, in order to be able to
437 // resolve the BFC position. 440 // resolve the BFC position.
438 bool float_does_not_fit = 441 bool float_does_not_fit =
439 !HasAvailableWidth() || 442 (!constraint_space_->FloatsBfcOffset() ||
440 position_ + inline_size + margins.InlineSum() > AvailableWidth(); 443 container_builder_->BfcOffset()) &&
444 (!HasAvailableWidth() ||
445 position_ + inline_size + margins.InlineSum() > AvailableWidth());
441 446
442 // Check if we already have a pending float. That's because a float cannot be 447 // Check if we already have a pending float. That's because a float cannot be
443 // higher than any block or floated box generated before. 448 // higher than any block or floated box generated before.
444 if (!container_builder_->UnpositionedFloats().IsEmpty() || 449 if (!unpositioned_floats_->IsEmpty() || float_does_not_fit) {
445 float_does_not_fit) { 450 unpositioned_floats_->push_back(std::move(unpositioned_float));
446 container_builder_->AddUnpositionedFloat(unpositioned_float);
447 } else { 451 } else {
448 NGLogicalOffset container_bfc_offset = 452 NGLogicalOffset container_bfc_offset =
449 container_builder_->BfcOffset().value(); 453 container_builder_->BfcOffset()
454 ? container_builder_->BfcOffset().value()
455 : constraint_space_->FloatsBfcOffset().value();
450 LayoutUnit origin_block_offset = 456 LayoutUnit origin_block_offset =
451 container_bfc_offset.block_offset + content_offset_.block_offset; 457 container_bfc_offset.block_offset + content_offset_.block_offset;
452 458
453 container_builder_->AddPositionedFloat( 459 container_builder_->AddPositionedFloat(
454 PositionFloat(origin_block_offset, container_bfc_offset.block_offset, 460 PositionFloat(origin_block_offset, container_bfc_offset.block_offset,
455 unpositioned_float.Get(), constraint_space_)); 461 unpositioned_float.Get(), constraint_space_));
456 462
457 // We need to recalculate the available_width as the float probably 463 // We need to recalculate the available_width as the float probably
458 // consumed space on the line. 464 // consumed space on the line.
459 UpdateAvailableWidth(); 465 if (container_builder_->BfcOffset())
466 UpdateAvailableWidth();
460 } 467 }
461 468
462 // Floats are already positioned in the container_builder. 469 // Floats are already positioned in the container_builder.
463 item_results->pop_back(); 470 item_results->pop_back();
464 MoveToNextOf(item); 471 MoveToNextOf(item);
465 } 472 }
466 473
467 void NGLineBreaker::HandleOpenTag(const NGInlineItem& item, 474 void NGLineBreaker::HandleOpenTag(const NGInlineItem& item,
468 NGInlineItemResult* item_result) { 475 NGInlineItemResult* item_result) {
469 DCHECK(item.Style()); 476 DCHECK(item.Style());
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
668 } 675 }
669 676
670 RefPtr<NGInlineBreakToken> NGLineBreaker::CreateBreakToken() const { 677 RefPtr<NGInlineBreakToken> NGLineBreaker::CreateBreakToken() const {
671 const Vector<NGInlineItem>& items = node_.Items(); 678 const Vector<NGInlineItem>& items = node_.Items();
672 if (item_index_ >= items.size()) 679 if (item_index_ >= items.size())
673 return nullptr; 680 return nullptr;
674 return NGInlineBreakToken::Create(node_, item_index_, offset_); 681 return NGInlineBreakToken::Create(node_, item_index_, offset_);
675 } 682 }
676 683
677 } // namespace blink 684 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698