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

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

Issue 2847823002: Make leading OOF objects to be handled by block layout in LayoutNG (Closed)
Patch Set: fix NGBlockNodeForTest 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 #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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 : NGLayoutAlgorithm(inline_node, space, break_token), 59 : NGLayoutAlgorithm(inline_node, space, break_token),
60 is_horizontal_writing_mode_( 60 is_horizontal_writing_mode_(
61 blink::IsHorizontalWritingMode(space->WritingMode())), 61 blink::IsHorizontalWritingMode(space->WritingMode())),
62 disallow_first_line_rules_(false), 62 disallow_first_line_rules_(false),
63 space_builder_(space) 63 space_builder_(space)
64 #if DCHECK_IS_ON() 64 #if DCHECK_IS_ON()
65 , 65 ,
66 is_bidi_reordered_(false) 66 is_bidi_reordered_(false)
67 #endif 67 #endif
68 { 68 {
69 container_builder_.MutableUnpositionedFloats() = space->UnpositionedFloats();
70
71 // TODO(crbug.com/716930): We may be an empty LayoutInline due to splitting.
72 // Only resolve our BFC offset if we know that we are non-empty as we may
73 // need to pass through our margin strut.
74 if (!inline_node->Items().IsEmpty()) {
75 NGLogicalOffset bfc_offset = ConstraintSpace().BfcOffset();
76 bfc_offset.block_offset += ConstraintSpace().MarginStrut().Sum();
77 MaybeUpdateFragmentBfcOffset(ConstraintSpace(), bfc_offset,
78 &container_builder_);
79 PositionPendingFloats(bfc_offset.block_offset, &container_builder_,
80 MutableConstraintSpace());
81 }
82
69 if (!is_horizontal_writing_mode_) 83 if (!is_horizontal_writing_mode_)
70 baseline_type_ = FontBaseline::kIdeographicBaseline; 84 baseline_type_ = FontBaseline::kIdeographicBaseline;
71 if (break_token) 85 if (break_token)
72 Initialize(break_token->ItemIndex(), break_token->TextOffset()); 86 Initialize(break_token->ItemIndex(), break_token->TextOffset());
73 else 87 else
74 Initialize(0, 0); 88 Initialize(0, 0);
75 container_builder_.MutableUnpositionedFloats() = space->UnpositionedFloats();
76 } 89 }
77 90
78 bool NGInlineLayoutAlgorithm::IsFirstLine() const { 91 bool NGInlineLayoutAlgorithm::IsFirstLine() const {
79 return !disallow_first_line_rules_ && container_builder_.Children().IsEmpty(); 92 return !disallow_first_line_rules_ && container_builder_.Children().IsEmpty();
80 } 93 }
81 94
82 const ComputedStyle& NGInlineLayoutAlgorithm::FirstLineStyle() const { 95 const ComputedStyle& NGInlineLayoutAlgorithm::FirstLineStyle() const {
83 return Node()->GetLayoutObject()->FirstLineStyleRef(); 96 return Node()->GetLayoutObject()->FirstLineStyleRef();
84 } 97 }
85 98
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 249
237 bool NGInlineLayoutAlgorithm::CreateLine() { 250 bool NGInlineLayoutAlgorithm::CreateLine() {
238 if (HasItemsAfterLastBreakOpportunity()) 251 if (HasItemsAfterLastBreakOpportunity())
239 SetBreakOpportunity(); 252 SetBreakOpportunity();
240 return CreateLineUpToLastBreakOpportunity(); 253 return CreateLineUpToLastBreakOpportunity();
241 } 254 }
242 255
243 bool NGInlineLayoutAlgorithm::CreateLineUpToLastBreakOpportunity() { 256 bool NGInlineLayoutAlgorithm::CreateLineUpToLastBreakOpportunity() {
244 const Vector<NGInlineItem>& items = Node()->Items(); 257 const Vector<NGInlineItem>& items = Node()->Items();
245 258
246 // TODO(crbug.com/716930): We may be an empty LayoutInline due to splitting.
247 // Only resolve our BFC offset if we know that we are non-empty as we may
248 // need to pass through our margin strut.
249 if (!items.IsEmpty()) {
250 NGLogicalOffset bfc_offset = ConstraintSpace().BfcOffset();
251 bfc_offset.block_offset += ConstraintSpace().MarginStrut().Sum();
252 MaybeUpdateFragmentBfcOffset(ConstraintSpace(), bfc_offset,
253 &container_builder_);
254 PositionPendingFloats(bfc_offset.block_offset, &container_builder_,
255 MutableConstraintSpace());
256 }
257
258 // Create a list of LineItemChunk from |start| and |last_break_opportunity|. 259 // Create a list of LineItemChunk from |start| and |last_break_opportunity|.
259 // TODO(kojii): Consider refactoring LineItemChunk once NGLineBuilder's public 260 // TODO(kojii): Consider refactoring LineItemChunk once NGLineBuilder's public
260 // API is more finalized. It does not fit well with the current API. 261 // API is more finalized. It does not fit well with the current API.
261 Vector<LineItemChunk, 32> line_item_chunks; 262 Vector<LineItemChunk, 32> line_item_chunks;
262 unsigned start_offset = start_offset_; 263 unsigned start_offset = start_offset_;
263 for (unsigned i = start_index_; i <= last_break_opportunity_index_; i++) { 264 for (unsigned i = start_index_; i <= last_break_opportunity_index_; i++) {
264 const NGInlineItem& item = items[i]; 265 const NGInlineItem& item = items[i];
265 unsigned end_offset = 266 unsigned end_offset =
266 std::min(item.EndOffset(), last_break_opportunity_offset_); 267 std::min(item.EndOffset(), last_break_opportunity_offset_);
267 line_item_chunks.push_back( 268 line_item_chunks.push_back(
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
544 state->metrics.Unite(metrics); 545 state->metrics.Unite(metrics);
545 546
546 // TODO(kojii): Figure out what to do with OOF in NGLayoutResult. 547 // TODO(kojii): Figure out what to do with OOF in NGLayoutResult.
547 // Floats are ok because atomic inlines are BFC? 548 // Floats are ok because atomic inlines are BFC?
548 549
549 return -metrics.ascent; 550 return -metrics.ascent;
550 } 551 }
551 552
552 void NGInlineLayoutAlgorithm::FindNextLayoutOpportunity() { 553 void NGInlineLayoutAlgorithm::FindNextLayoutOpportunity() {
553 NGLogicalOffset iter_offset = ConstraintSpace().BfcOffset(); 554 NGLogicalOffset iter_offset = ConstraintSpace().BfcOffset();
555 if (container_builder_.BfcOffset())
556 iter_offset = ContainerBfcOffset();
554 iter_offset.block_offset += content_size_; 557 iter_offset.block_offset += content_size_;
555 auto* iter = MutableConstraintSpace()->LayoutOpportunityIterator(iter_offset); 558 auto* iter = MutableConstraintSpace()->LayoutOpportunityIterator(iter_offset);
556 NGLayoutOpportunity opportunity = iter->Next(); 559 NGLayoutOpportunity opportunity = iter->Next();
557 if (!opportunity.IsEmpty()) 560 if (!opportunity.IsEmpty())
558 current_opportunity_ = opportunity; 561 current_opportunity_ = opportunity;
559 } 562 }
560 563
561 RefPtr<NGLayoutResult> NGInlineLayoutAlgorithm::Layout() { 564 RefPtr<NGLayoutResult> NGInlineLayoutAlgorithm::Layout() {
562 // TODO(koji): The relationship of NGInlineLayoutAlgorithm and NGLineBreaker 565 // TODO(koji): The relationship of NGInlineLayoutAlgorithm and NGLineBreaker
563 // should be inverted. 566 // should be inverted.
(...skipping 30 matching lines...) Expand all
594 597
595 // max-content is the width without any line wrapping. 598 // max-content is the width without any line wrapping.
596 // TODO(kojii): Implement hard breaks (<br> etc.) to break. 599 // TODO(kojii): Implement hard breaks (<br> etc.) to break.
597 for (const auto& item : Node()->Items()) 600 for (const auto& item : Node()->Items())
598 sizes.max_content += InlineSize(item); 601 sizes.max_content += InlineSize(item);
599 602
600 return sizes; 603 return sizes;
601 } 604 }
602 605
603 } // namespace blink 606 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698