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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 , | 69 , |
70 is_bidi_reordered_(false) | 70 is_bidi_reordered_(false) |
71 #endif | 71 #endif |
72 { | 72 { |
73 if (!is_horizontal_writing_mode_) | 73 if (!is_horizontal_writing_mode_) |
74 baseline_type_ = FontBaseline::kIdeographicBaseline; | 74 baseline_type_ = FontBaseline::kIdeographicBaseline; |
75 if (break_token) | 75 if (break_token) |
76 Initialize(break_token->ItemIndex(), break_token->TextOffset()); | 76 Initialize(break_token->ItemIndex(), break_token->TextOffset()); |
77 else | 77 else |
78 Initialize(0, 0); | 78 Initialize(0, 0); |
79 | |
80 // BFC offset is known for inline fragments. | |
81 MaybeUpdateFragmentBfcOffset(ConstraintSpace(), ConstraintSpace().BfcOffset(), | |
82 &container_builder_); | |
83 } | 79 } |
84 | 80 |
85 bool NGInlineLayoutAlgorithm::IsFirstLine() const { | 81 bool NGInlineLayoutAlgorithm::IsFirstLine() const { |
86 return !disallow_first_line_rules_ && container_builder_.Children().IsEmpty(); | 82 return !disallow_first_line_rules_ && container_builder_.Children().IsEmpty(); |
87 } | 83 } |
88 | 84 |
89 const ComputedStyle& NGInlineLayoutAlgorithm::FirstLineStyle() const { | 85 const ComputedStyle& NGInlineLayoutAlgorithm::FirstLineStyle() const { |
90 return Node()->GetLayoutObject()->FirstLineStyleRef(); | 86 return Node()->GetLayoutObject()->FirstLineStyleRef(); |
91 } | 87 } |
92 | 88 |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 | 239 |
244 bool NGInlineLayoutAlgorithm::CreateLine() { | 240 bool NGInlineLayoutAlgorithm::CreateLine() { |
245 if (HasItemsAfterLastBreakOpportunity()) | 241 if (HasItemsAfterLastBreakOpportunity()) |
246 SetBreakOpportunity(); | 242 SetBreakOpportunity(); |
247 return CreateLineUpToLastBreakOpportunity(); | 243 return CreateLineUpToLastBreakOpportunity(); |
248 } | 244 } |
249 | 245 |
250 bool NGInlineLayoutAlgorithm::CreateLineUpToLastBreakOpportunity() { | 246 bool NGInlineLayoutAlgorithm::CreateLineUpToLastBreakOpportunity() { |
251 const Vector<NGInlineItem>& items = Node()->Items(); | 247 const Vector<NGInlineItem>& items = Node()->Items(); |
252 | 248 |
| 249 // TODO(crbug.com/716930): We may be an empty LayoutInline due to splitting. |
| 250 // Only resolve our BFC offset if we know that we are non-empty as we may |
| 251 // need to pass through our margin strut. |
| 252 if (!items.IsEmpty()) { |
| 253 NGLogicalOffset bfc_offset = ConstraintSpace().BfcOffset(); |
| 254 bfc_offset.block_offset += ConstraintSpace().MarginStrut().Sum(); |
| 255 MaybeUpdateFragmentBfcOffset(ConstraintSpace(), bfc_offset, |
| 256 &container_builder_); |
| 257 } |
| 258 |
253 // Create a list of LineItemChunk from |start| and |last_break_opportunity|. | 259 // Create a list of LineItemChunk from |start| and |last_break_opportunity|. |
254 // TODO(kojii): Consider refactoring LineItemChunk once NGLineBuilder's public | 260 // TODO(kojii): Consider refactoring LineItemChunk once NGLineBuilder's public |
255 // 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. |
256 Vector<LineItemChunk, 32> line_item_chunks; | 262 Vector<LineItemChunk, 32> line_item_chunks; |
257 unsigned start_offset = start_offset_; | 263 unsigned start_offset = start_offset_; |
258 for (unsigned i = start_index_; i <= last_break_opportunity_index_; i++) { | 264 for (unsigned i = start_index_; i <= last_break_opportunity_index_; i++) { |
259 const NGInlineItem& item = items[i]; | 265 const NGInlineItem& item = items[i]; |
260 unsigned end_offset = | 266 unsigned end_offset = |
261 std::min(item.EndOffset(), last_break_opportunity_offset_); | 267 std::min(item.EndOffset(), last_break_opportunity_offset_); |
262 line_item_chunks.push_back( | 268 line_item_chunks.push_back( |
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
564 // TODO(eae): Does this need the LayoutText::LocaleForLineBreakIterator | 570 // TODO(eae): Does this need the LayoutText::LocaleForLineBreakIterator |
565 // logic to switch the locale based on breaking mode? | 571 // logic to switch the locale based on breaking mode? |
566 NGLineBreaker line_breaker(Node()->Style().Locale()); | 572 NGLineBreaker line_breaker(Node()->Style().Locale()); |
567 line_breaker.BreakLines(this, Node()->Text(), start_offset_); | 573 line_breaker.BreakLines(this, Node()->Text(), start_offset_); |
568 } | 574 } |
569 | 575 |
570 // TODO(kojii): Check if the line box width should be content or available. | 576 // TODO(kojii): Check if the line box width should be content or available. |
571 NGLogicalSize size(max_inline_size_, content_size_); | 577 NGLogicalSize size(max_inline_size_, content_size_); |
572 container_builder_.SetSize(size).SetOverflowSize(size); | 578 container_builder_.SetSize(size).SetOverflowSize(size); |
573 | 579 |
| 580 // TODO(crbug.com/716930): We may be an empty LayoutInline due to splitting. |
| 581 // Margin struts shouldn't need to be passed through like this once we've |
| 582 // removed LayoutInline splitting. |
| 583 if (!container_builder_.BfcOffset()) { |
| 584 container_builder_.SetEndMarginStrut(ConstraintSpace().MarginStrut()); |
| 585 } |
| 586 |
574 return container_builder_.ToBoxFragment(); | 587 return container_builder_.ToBoxFragment(); |
575 } | 588 } |
576 | 589 |
577 MinMaxContentSize NGInlineLayoutAlgorithm::ComputeMinMaxContentSizeByLayout() { | 590 MinMaxContentSize NGInlineLayoutAlgorithm::ComputeMinMaxContentSizeByLayout() { |
578 DCHECK_EQ(ConstraintSpace().AvailableSize().inline_size, LayoutUnit()); | 591 DCHECK_EQ(ConstraintSpace().AvailableSize().inline_size, LayoutUnit()); |
579 DCHECK_EQ(ConstraintSpace().AvailableSize().block_size, NGSizeIndefinite); | 592 DCHECK_EQ(ConstraintSpace().AvailableSize().block_size, NGSizeIndefinite); |
580 if (!Node()->Text().IsEmpty()) { | 593 if (!Node()->Text().IsEmpty()) { |
581 NGLineBreaker line_breaker(Node()->Style().Locale()); | 594 NGLineBreaker line_breaker(Node()->Style().Locale()); |
582 line_breaker.BreakLines(this, Node()->Text(), start_offset_); | 595 line_breaker.BreakLines(this, Node()->Text(), start_offset_); |
583 } | 596 } |
584 MinMaxContentSize sizes; | 597 MinMaxContentSize sizes; |
585 sizes.min_content = MaxInlineSize(); | 598 sizes.min_content = MaxInlineSize(); |
586 | 599 |
587 // max-content is the width without any line wrapping. | 600 // max-content is the width without any line wrapping. |
588 // TODO(kojii): Implement hard breaks (<br> etc.) to break. | 601 // TODO(kojii): Implement hard breaks (<br> etc.) to break. |
589 for (const auto& item : Node()->Items()) | 602 for (const auto& item : Node()->Items()) |
590 sizes.max_content += InlineSize(item); | 603 sizes.max_content += InlineSize(item); |
591 | 604 |
592 return sizes; | 605 return sizes; |
593 } | 606 } |
594 | 607 |
595 } // namespace blink | 608 } // namespace blink |
OLD | NEW |