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 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 } | 297 } |
298 | 298 |
299 if (line_box.Children().IsEmpty()) { | 299 if (line_box.Children().IsEmpty()) { |
300 return true; // The line was empty. | 300 return true; // The line was empty. |
301 } | 301 } |
302 | 302 |
303 box_states_.OnEndPlaceItems(&line_box, baseline_type_, position); | 303 box_states_.OnEndPlaceItems(&line_box, baseline_type_, position); |
304 | 304 |
305 // The baselines are always placed at pixel boundaries. Not doing so results | 305 // The baselines are always placed at pixel boundaries. Not doing so results |
306 // in incorrect layout of text decorations, most notably underlines. | 306 // in incorrect layout of text decorations, most notably underlines. |
307 LayoutUnit baseline = content_size_ + line_box.Metrics().ascent + | 307 LayoutUnit baseline = content_size_ + line_box.Metrics().ascent; |
308 border_and_padding_.block_start; | |
309 baseline = LayoutUnit(baseline.Round()); | 308 baseline = LayoutUnit(baseline.Round()); |
310 | 309 |
311 // Check if the line fits into the constraint space in block direction. | 310 // Check if the line fits into the constraint space in block direction. |
312 LayoutUnit line_bottom = baseline + line_box.Metrics().descent; | 311 LayoutUnit line_bottom = baseline + line_box.Metrics().descent; |
313 | 312 |
314 if (!container_builder_.Children().IsEmpty() && | 313 if (!container_builder_.Children().IsEmpty() && |
315 ConstraintSpace().AvailableSize().block_size != NGSizeIndefinite && | 314 ConstraintSpace().AvailableSize().block_size != NGSizeIndefinite && |
316 line_bottom > ConstraintSpace().AvailableSize().block_size) { | 315 line_bottom > ConstraintSpace().AvailableSize().block_size) { |
317 return false; | 316 return false; |
318 } | 317 } |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
405 {border_and_padding_.inline_start, border_and_padding_.block_start}; | 404 {border_and_padding_.inline_start, border_and_padding_.block_start}; |
406 } | 405 } |
407 iter_offset.block_offset += content_size_; | 406 iter_offset.block_offset += content_size_; |
408 auto* iter = MutableConstraintSpace()->LayoutOpportunityIterator(iter_offset); | 407 auto* iter = MutableConstraintSpace()->LayoutOpportunityIterator(iter_offset); |
409 NGLayoutOpportunity opportunity = iter->Next(); | 408 NGLayoutOpportunity opportunity = iter->Next(); |
410 if (!opportunity.IsEmpty()) | 409 if (!opportunity.IsEmpty()) |
411 current_opportunity_ = opportunity; | 410 current_opportunity_ = opportunity; |
412 } | 411 } |
413 | 412 |
414 RefPtr<NGLayoutResult> NGInlineLayoutAlgorithm::Layout() { | 413 RefPtr<NGLayoutResult> NGInlineLayoutAlgorithm::Layout() { |
| 414 // If we are resuming from a break token our start border and padding is |
| 415 // within a previous fragment. |
| 416 content_size_ = BreakToken() ? LayoutUnit() : border_and_padding_.block_start; |
| 417 |
415 NGLineBreaker line_breaker(Node(), constraint_space_, BreakToken()); | 418 NGLineBreaker line_breaker(Node(), constraint_space_, BreakToken()); |
416 NGInlineItemResults item_results; | 419 NGInlineItemResults item_results; |
417 while (true) { | 420 while (true) { |
418 line_breaker.NextLine(&item_results, this); | 421 line_breaker.NextLine(&item_results, this); |
419 if (item_results.IsEmpty()) | 422 if (item_results.IsEmpty()) |
420 break; | 423 break; |
421 CreateLine(&item_results, line_breaker.CreateBreakToken()); | 424 CreateLine(&item_results, line_breaker.CreateBreakToken()); |
422 item_results.clear(); | 425 item_results.clear(); |
423 } | 426 } |
424 | 427 |
425 // TODO(crbug.com/716930): Avoid calculating border/padding twice. | 428 // TODO(crbug.com/716930): Avoid calculating border/padding twice. |
426 if (!Node()->Items().IsEmpty()) | 429 if (!BreakToken()) |
427 content_size_ -= border_and_padding_.block_start; | 430 content_size_ -= border_and_padding_.block_start; |
428 | 431 |
429 // TODO(kojii): Check if the line box width should be content or available. | 432 // TODO(kojii): Check if the line box width should be content or available. |
430 NGLogicalSize size(max_inline_size_, content_size_); | 433 NGLogicalSize size(max_inline_size_, content_size_); |
431 container_builder_.SetSize(size).SetOverflowSize(size); | 434 container_builder_.SetSize(size).SetOverflowSize(size); |
432 | 435 |
433 // TODO(crbug.com/716930): We may be an empty LayoutInline due to splitting. | 436 // TODO(crbug.com/716930): We may be an empty LayoutInline due to splitting. |
434 // Margin struts shouldn't need to be passed through like this once we've | 437 // Margin struts shouldn't need to be passed through like this once we've |
435 // removed LayoutInline splitting. | 438 // removed LayoutInline splitting. |
436 if (!container_builder_.BfcOffset()) { | 439 if (!container_builder_.BfcOffset()) { |
437 container_builder_.SetEndMarginStrut(ConstraintSpace().MarginStrut()); | 440 container_builder_.SetEndMarginStrut(ConstraintSpace().MarginStrut()); |
438 } | 441 } |
439 | 442 |
440 return container_builder_.ToBoxFragment(); | 443 return container_builder_.ToBoxFragment(); |
441 } | 444 } |
442 | 445 |
443 } // namespace blink | 446 } // namespace blink |
OLD | NEW |