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

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

Issue 2845493002: [LayoutNG] Fix empty inlines to influence the used line height (Closed)
Patch Set: Mark failure in a test in CSS2/normal-flow 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 376 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 PositionFloat(floating_object.Get(), MutableConstraintSpace()); 387 PositionFloat(floating_object.Get(), MutableConstraintSpace());
388 container_builder_.MutablePositionedFloats().push_back(floating_object); 388 container_builder_.MutablePositionedFloats().push_back(floating_object);
389 FindNextLayoutOpportunity(); 389 FindNextLayoutOpportunity();
390 } 390 }
391 } 391 }
392 392
393 bool NGInlineLayoutAlgorithm::PlaceItems( 393 bool NGInlineLayoutAlgorithm::PlaceItems(
394 const Vector<LineItemChunk, 32>& line_item_chunks) { 394 const Vector<LineItemChunk, 32>& line_item_chunks) {
395 const Vector<NGInlineItem>& items = Node()->Items(); 395 const Vector<NGInlineItem>& items = Node()->Items();
396 396
397 // Use a "strut" (a zero-width inline box with the element's font and
398 // line height properties) as the initial metrics for the line box.
399 // https://drafts.csswg.org/css2/visudet.html#strut
400 const ComputedStyle& line_style = LineStyle(); 397 const ComputedStyle& line_style = LineStyle();
401 NGLineHeightMetrics line_metrics(line_style, baseline_type_); 398 NGLineHeightMetrics line_metrics(line_style, baseline_type_);
402 NGLineHeightMetrics line_metrics_with_leading = line_metrics; 399 NGLineHeightMetrics line_metrics_with_leading = line_metrics;
403 line_metrics_with_leading.AddLeading(line_style.ComputedLineHeightAsFixed()); 400 line_metrics_with_leading.AddLeading(line_style.ComputedLineHeightAsFixed());
404 NGLineBoxFragmentBuilder line_box(Node(), line_metrics_with_leading); 401 NGLineBoxFragmentBuilder line_box(Node());
405 402
406 // Compute heights of all inline items by placing the dominant baseline at 0. 403 // Compute heights of all inline items by placing the dominant baseline at 0.
407 // The baseline is adjusted after the height of the line box is computed. 404 // The baseline is adjusted after the height of the line box is computed.
408 NGTextFragmentBuilder text_builder(Node()); 405 NGTextFragmentBuilder text_builder(Node());
409 NGInlineBoxState* box = box_states_.OnBeginPlaceItems(&LineStyle()); 406 NGInlineBoxState* box =
407 box_states_.OnBeginPlaceItems(&LineStyle(), baseline_type_);
410 LayoutUnit inline_size; 408 LayoutUnit inline_size;
411 for (const auto& line_item_chunk : line_item_chunks) { 409 for (const auto& line_item_chunk : line_item_chunks) {
412 const NGInlineItem& item = items[line_item_chunk.index]; 410 const NGInlineItem& item = items[line_item_chunk.index];
413 LayoutUnit line_top; 411 LayoutUnit line_top;
414 if (item.Type() == NGInlineItem::kText) { 412 if (item.Type() == NGInlineItem::kText) {
415 DCHECK(item.GetLayoutObject()->IsText()); 413 DCHECK(item.GetLayoutObject()->IsText());
416 if (box->text_metrics.IsEmpty()) 414 DCHECK(!box->text_metrics.IsEmpty());
417 box->ComputeTextMetrics(item, baseline_type_);
418 line_top = box->text_top; 415 line_top = box->text_top;
419 text_builder.SetSize( 416 text_builder.SetSize(
420 {line_item_chunk.inline_size, box->text_metrics.LineHeight()}); 417 {line_item_chunk.inline_size, box->text_metrics.LineHeight()});
421 // Take all used fonts into account if 'line-height: normal'. 418 // Take all used fonts into account if 'line-height: normal'.
422 if (box->include_used_fonts) 419 if (box->include_used_fonts) {
423 AccumulateUsedFonts(item, line_item_chunk, &line_box); 420 box->AccumulateUsedFonts(item, line_item_chunk.start_offset,
421 line_item_chunk.end_offset, baseline_type_);
422 }
424 } else if (item.Type() == NGInlineItem::kOpenTag) { 423 } else if (item.Type() == NGInlineItem::kOpenTag) {
425 box = box_states_.OnOpenTag(item, &line_box, &text_builder); 424 box = box_states_.OnOpenTag(item, &line_box, &text_builder);
425 // Compute text metrics for all inline boxes since even empty inlines
426 // influence the line height.
427 // https://drafts.csswg.org/css2/visudet.html#line-height
428 // TODO(kojii): Review if atomic inline level should have open/close.
429 if (!item.GetLayoutObject()->IsAtomicInlineLevel())
430 box->ComputeTextMetrics(*item.Style(), baseline_type_);
426 continue; 431 continue;
427 } else if (item.Type() == NGInlineItem::kCloseTag) { 432 } else if (item.Type() == NGInlineItem::kCloseTag) {
428 box = box_states_.OnCloseTag(item, &line_box, box); 433 box = box_states_.OnCloseTag(item, &line_box, box);
429 continue; 434 continue;
430 } else if (item.Type() == NGInlineItem::kAtomicInline) { 435 } else if (item.Type() == NGInlineItem::kAtomicInline) {
431 line_top = PlaceAtomicInline(item, &line_box, box, &text_builder); 436 line_top = PlaceAtomicInline(item, &line_box, box, &text_builder);
432 } else if (item.Type() == NGInlineItem::kOutOfFlowPositioned) { 437 } else if (item.Type() == NGInlineItem::kOutOfFlowPositioned) {
433 // TODO(layout-dev): Report the correct static position for the out of 438 // TODO(layout-dev): Report the correct static position for the out of
434 // flow descendant. We can't do this here yet as it doesn't know the 439 // flow descendant. We can't do this here yet as it doesn't know the
435 // size of the line box. 440 // size of the line box.
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 } 489 }
485 490
486 // TODO(kojii): Implement flipped line (vertical-lr). In this case, line_top 491 // TODO(kojii): Implement flipped line (vertical-lr). In this case, line_top
487 // and block_start do not match. 492 // and block_start do not match.
488 493
489 // Up until this point, children are placed so that the dominant baseline is 494 // Up until this point, children are placed so that the dominant baseline is
490 // at 0. Move them to the final baseline position, and set the logical top of 495 // at 0. Move them to the final baseline position, and set the logical top of
491 // the line box to the line top. 496 // the line box to the line top.
492 line_box.MoveChildrenInBlockDirection(baseline); 497 line_box.MoveChildrenInBlockDirection(baseline);
493 line_box.SetInlineSize(inline_size); 498 line_box.SetInlineSize(inline_size);
494 container_builder_.AddChild(line_box.ToLineBoxFragment(), 499 container_builder_.AddChild(
495 {LayoutUnit(), baseline - line_metrics.ascent}); 500 line_box.ToLineBoxFragment(),
501 {LayoutUnit(), baseline + box_states_.LineBoxState().text_top});
496 502
497 max_inline_size_ = std::max(max_inline_size_, inline_size); 503 max_inline_size_ = std::max(max_inline_size_, inline_size);
498 content_size_ = line_bottom; 504 content_size_ = line_bottom;
499 return true; 505 return true;
500 } 506 }
501 507
502 void NGInlineLayoutAlgorithm::AccumulateUsedFonts(
503 const NGInlineItem& item,
504 const LineItemChunk& line_item_chunk,
505 NGLineBoxFragmentBuilder* line_box) {
506 HashSet<const SimpleFontData*> fallback_fonts;
507 item.GetFallbackFonts(&fallback_fonts, line_item_chunk.start_offset,
508 line_item_chunk.end_offset);
509 for (const auto& fallback_font : fallback_fonts) {
510 NGLineHeightMetrics metrics(fallback_font->GetFontMetrics(),
511 baseline_type_);
512 metrics.AddLeading(fallback_font->GetFontMetrics().FixedLineSpacing());
513 line_box->UniteMetrics(metrics);
514 }
515 }
516
517 LayoutUnit NGInlineLayoutAlgorithm::PlaceAtomicInline( 508 LayoutUnit NGInlineLayoutAlgorithm::PlaceAtomicInline(
518 const NGInlineItem& item, 509 const NGInlineItem& item,
519 NGLineBoxFragmentBuilder* line_box, 510 NGLineBoxFragmentBuilder* line_box,
520 NGInlineBoxState* state, 511 NGInlineBoxState* state,
521 NGTextFragmentBuilder* text_builder) { 512 NGTextFragmentBuilder* text_builder) {
522 NGBoxFragment fragment( 513 NGBoxFragment fragment(
523 ConstraintSpace().WritingMode(), 514 ConstraintSpace().WritingMode(),
524 ToNGPhysicalBoxFragment(LayoutItem(item)->PhysicalFragment().Get())); 515 ToNGPhysicalBoxFragment(LayoutItem(item)->PhysicalFragment().Get()));
525 // TODO(kojii): Margin and border in block progression not implemented yet. 516 // TODO(kojii): Margin and border in block progression not implemented yet.
526 LayoutUnit block_size = fragment.BlockSize(); 517 LayoutUnit block_size = fragment.BlockSize();
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
585 576
586 // max-content is the width without any line wrapping. 577 // max-content is the width without any line wrapping.
587 // TODO(kojii): Implement hard breaks (<br> etc.) to break. 578 // TODO(kojii): Implement hard breaks (<br> etc.) to break.
588 for (const auto& item : Node()->Items()) 579 for (const auto& item : Node()->Items())
589 sizes.max_content += InlineSize(item); 580 sizes.max_content += InlineSize(item);
590 581
591 return sizes; 582 return sizes;
592 } 583 }
593 584
594 } // namespace blink 585 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698