@@ -603,54 +603,76 @@ nscoord nsBlockFrame::SynthesizeFallbackBaseline(
603
603
return Baseline::SynthesizeBOffsetFromMarginBox(this, aWM, aBaselineGroup);
604
604
}
605
605
606
+ template <typename LineIteratorType>
607
+ Maybe<nscoord> nsBlockFrame::GetBaselineBOffset(
608
+ LineIteratorType aStart, LineIteratorType aEnd, WritingMode aWM,
609
+ BaselineSharingGroup aBaselineGroup,
610
+ BaselineExportContext aExportContext) const {
611
+ MOZ_ASSERT((std::is_same_v<LineIteratorType, ConstLineIterator> &&
612
+ aBaselineGroup == BaselineSharingGroup::First) ||
613
+ (std::is_same_v<LineIteratorType, ConstReverseLineIterator> &&
614
+ aBaselineGroup == BaselineSharingGroup::Last),
615
+ "Iterator direction must match baseline sharing group.");
616
+ for (auto line = aStart; line != aEnd; ++line) {
617
+ if (!line->IsBlock()) {
618
+ // XXX Is this the right test? We have some bogus empty lines
619
+ // floating around, but IsEmpty is perhaps too weak.
620
+ if (line->BSize() != 0 || !line->IsEmpty()) {
621
+ const auto ascent = line->BStart() + line->GetLogicalAscent();
622
+ if (aBaselineGroup == BaselineSharingGroup::Last) {
623
+ return Some(BSize(aWM) - ascent);
624
+ }
625
+ return Some(ascent);
626
+ }
627
+ continue;
628
+ }
629
+ nsIFrame* kid = line->mFirstChild;
630
+ if (aWM.IsOrthogonalTo(kid->GetWritingMode())) {
631
+ continue;
632
+ }
633
+ if (aExportContext == BaselineExportContext::LineLayout &&
634
+ kid->IsTableWrapperFrame()) {
635
+ // `<table>` in inline-block context does not export any baseline.
636
+ continue;
637
+ }
638
+ const auto kidBaselineGroup =
639
+ aExportContext == BaselineExportContext::LineLayout
640
+ ? kid->GetDefaultBaselineSharingGroup()
641
+ : aBaselineGroup;
642
+ const auto kidBaseline =
643
+ kid->GetNaturalBaselineBOffset(aWM, kidBaselineGroup, aExportContext);
644
+ if (!kidBaseline) {
645
+ continue;
646
+ }
647
+ auto result = *kidBaseline;
648
+ if (kidBaselineGroup == BaselineSharingGroup::Last) {
649
+ result = kid->BSize(aWM) - result;
650
+ }
651
+ // Ignore relative positioning for baseline calculations.
652
+ const nsSize& sz = line->mContainerSize;
653
+ result += kid->GetLogicalNormalPosition(aWM, sz).B(aWM);
654
+ if (aBaselineGroup == BaselineSharingGroup::Last) {
655
+ return Some(BSize(aWM) - result);
656
+ }
657
+ return Some(result);
658
+ }
659
+ return Nothing{};
660
+ }
661
+
606
662
Maybe<nscoord> nsBlockFrame::GetNaturalBaselineBOffset(
607
- WritingMode aWM, BaselineSharingGroup aBaselineGroup) const {
663
+ WritingMode aWM, BaselineSharingGroup aBaselineGroup,
664
+ BaselineExportContext aExportContext) const {
608
665
if (StyleDisplay()->IsContainLayout()) {
609
666
return Nothing{};
610
667
}
611
668
612
669
if (aBaselineGroup == BaselineSharingGroup::First) {
613
- nscoord result;
614
- if (!nsLayoutUtils::GetFirstLineBaseline(aWM, this, &result)) {
615
- return Nothing{};
616
- }
617
- return Some(result);
670
+ return GetBaselineBOffset(LinesBegin(), LinesEnd(), aWM, aBaselineGroup,
671
+ aExportContext);
618
672
}
619
673
620
- for (ConstReverseLineIterator line = LinesRBegin(), line_end = LinesREnd();
621
- line != line_end; ++line) {
622
- if (line->IsBlock()) {
623
- nsIFrame* kid = line->mFirstChild;
624
- if (aWM.IsOrthogonalTo(kid->GetWritingMode())) {
625
- continue;
626
- }
627
- if (kid->IsTableWrapperFrame()) {
628
- // `<table>` in block display context does not export any baseline.
629
- continue;
630
- }
631
- const auto kidBaselineGroup = kid->GetDefaultBaselineSharingGroup();
632
- const auto kidBaseline =
633
- kid->GetNaturalBaselineBOffset(aWM, kidBaselineGroup);
634
- if (!kidBaseline) {
635
- continue;
636
- }
637
- auto result = *kidBaseline;
638
- if (kidBaselineGroup == BaselineSharingGroup::Last) {
639
- result = kid->BSize(aWM) - result;
640
- }
641
- // Ignore relative positioning for baseline calculations.
642
- const nsSize& sz = line->mContainerSize;
643
- result += kid->GetLogicalNormalPosition(aWM, sz).B(aWM);
644
- return Some(BSize(aWM) - result);
645
- } else {
646
- // XXX Is this the right test? We have some bogus empty lines
647
- // floating around, but IsEmpty is perhaps too weak.
648
- if (line->BSize() != 0 || !line->IsEmpty()) {
649
- return Some(BSize(aWM) - (line->BStart() + line->GetLogicalAscent()));
650
- }
651
- }
652
- }
653
- return Nothing{};
674
+ return GetBaselineBOffset(LinesRBegin(), LinesREnd(), aWM, aBaselineGroup,
675
+ aExportContext);
654
676
}
655
677
656
678
nscoord nsBlockFrame::GetCaretBaseline() const {
@@ -1570,7 +1592,8 @@ void nsBlockFrame::Reflow(nsPresContext* aPresContext, ReflowOutput& aMetrics,
1570
1592
const auto baselineGroup = BaselineSharingGroup::First;
1571
1593
Maybe<nscoord> result;
1572
1594
if (MOZ_LIKELY(!wm.IsOrthogonalTo(marker->GetWritingMode()))) {
1573
- result = marker->GetNaturalBaselineBOffset(wm, baselineGroup);
1595
+ result = marker->GetNaturalBaselineBOffset(
1596
+ wm, baselineGroup, BaselineExportContext::LineLayout);
1574
1597
}
1575
1598
const auto markerBaseline = result.valueOrFrom([bbox, wm, marker]() {
1576
1599
return bbox.BSize(wm) + marker->GetLogicalUsedMargin(wm).BEnd(wm);
0 commit comments