Bug 1811311 - Part 3: Refactor `GetNaturalBaselineBOffset` to return `Maybe<nscoord>`. r=layout-reviewers,emilio

Changed from returning `bool` & taking an out parameter.

Differential Revision: https://phabricator.services.mozilla.com/D168998
This commit is contained in:
David Shin 2023-02-23 14:53:27 +00:00
Родитель e02d078c12
Коммит f5a42005e2
34 изменённых файлов: 225 добавлений и 260 удалений

Просмотреть файл

@ -85,23 +85,22 @@ LogicalSize nsCheckboxRadioFrame::ComputeAutoSize(
return size;
}
bool nsCheckboxRadioFrame::GetNaturalBaselineBOffset(
mozilla::WritingMode aWM, BaselineSharingGroup aBaselineGroup,
nscoord* aBaseline) const {
Maybe<nscoord> nsCheckboxRadioFrame::GetNaturalBaselineBOffset(
WritingMode aWM, BaselineSharingGroup aBaselineGroup) const {
NS_ASSERTION(!IsSubtreeDirty(), "frame must not be dirty");
if (aBaselineGroup == BaselineSharingGroup::Last) {
return false;
return Nothing{};
}
if (StyleDisplay()->IsBlockOutsideStyle()) {
return false;
return Nothing{};
}
// For appearance:none we use a standard CSS baseline, i.e. synthesized from
// our margin-box.
if (!StyleDisplay()->HasAppearance()) {
return false;
return Nothing{};
}
// This is for compatibility with Chrome, Safari and Edge (Dec 2016).
@ -110,10 +109,9 @@ bool nsCheckboxRadioFrame::GetNaturalBaselineBOffset(
// than the margin edge).
// For "inverted" lines (typically in writing-mode:vertical-lr), use the
// block-start end instead.
*aBaseline = aWM.IsLineInverted()
? GetLogicalUsedBorderAndPadding(aWM).BStart(aWM)
: BSize(aWM) - GetLogicalUsedBorderAndPadding(aWM).BEnd(aWM);
return true;
return Some(aWM.IsLineInverted()
? GetLogicalUsedBorderAndPadding(aWM).BStart(aWM)
: BSize(aWM) - GetLogicalUsedBorderAndPadding(aWM).BEnd(aWM));
}
void nsCheckboxRadioFrame::Reflow(nsPresContext* aPresContext,

Просмотреть файл

@ -61,9 +61,9 @@ class nsCheckboxRadioFrame final : public nsAtomicContainerFrame,
mozilla::WidgetGUIEvent* aEvent,
nsEventStatus* aEventStatus) override;
bool GetNaturalBaselineBOffset(mozilla::WritingMode aWM,
BaselineSharingGroup aBaselineGroup,
nscoord* aBaseline) const override;
Maybe<nscoord> GetNaturalBaselineBOffset(
mozilla::WritingMode aWM,
BaselineSharingGroup aBaselineGroup) const override;
/**
* Respond to the request to resize and/or reflow

Просмотреть файл

@ -64,11 +64,10 @@ nscoord nsDateTimeControlFrame::GetPrefISize(gfxContext* aRenderingContext) {
return result;
}
bool nsDateTimeControlFrame::GetNaturalBaselineBOffset(
WritingMode aWM, BaselineSharingGroup aBaselineGroup,
nscoord* aBaseline) const {
Maybe<nscoord> nsDateTimeControlFrame::GetNaturalBaselineBOffset(
WritingMode aWM, BaselineSharingGroup aBaselineGroup) const {
return nsTextControlFrame::GetSingleLineTextControlBaseline(
this, mFirstBaseline, aWM, aBaselineGroup, aBaseline);
this, mFirstBaseline, aWM, aBaselineGroup);
}
void nsDateTimeControlFrame::Reflow(nsPresContext* aPresContext,

Просмотреть файл

@ -61,9 +61,9 @@ class nsDateTimeControlFrame final : public nsContainerFrame {
const ReflowInput& aReflowInput,
nsReflowStatus& aStatus) override;
bool GetNaturalBaselineBOffset(mozilla::WritingMode aWM,
BaselineSharingGroup aBaselineGroup,
nscoord* aBaseline) const override;
Maybe<nscoord> GetNaturalBaselineBOffset(
mozilla::WritingMode aWM,
BaselineSharingGroup aBaselineGroup) const override;
nscoord mFirstBaseline = NS_INTRINSIC_ISIZE_UNKNOWN;
};

Просмотреть файл

@ -850,29 +850,27 @@ nscoord nsFieldSetFrame::SynthesizeFallbackBaseline(
return Baseline::SynthesizeBOffsetFromMarginBox(this, aWM, aBaselineGroup);
}
bool nsFieldSetFrame::GetNaturalBaselineBOffset(
WritingMode aWM, BaselineSharingGroup aBaselineGroup,
nscoord* aBaseline) const {
Maybe<nscoord> nsFieldSetFrame::GetNaturalBaselineBOffset(
WritingMode aWM, BaselineSharingGroup aBaselineGroup) const {
if (StyleDisplay()->IsContainLayout()) {
// If we are layout-contained, our child 'inner' should not
// affect how we calculate our baseline.
return false;
return Nothing{};
}
nsIFrame* inner = GetInner();
if (MOZ_UNLIKELY(!inner)) {
return false;
return Nothing{};
}
MOZ_ASSERT(!inner->GetWritingMode().IsOrthogonalTo(aWM));
if (!inner->GetNaturalBaselineBOffset(aWM, aBaselineGroup, aBaseline)) {
return false;
const auto result = inner->GetNaturalBaselineBOffset(aWM, aBaselineGroup);
if (!result) {
return Nothing{};
}
nscoord innerBStart = inner->BStart(aWM, GetSize());
if (aBaselineGroup == BaselineSharingGroup::First) {
*aBaseline += innerBStart;
} else {
*aBaseline += BSize(aWM) - (innerBStart + inner->BSize(aWM));
return Some(*result + innerBStart);
}
return true;
return Some(*result + BSize(aWM) - (innerBStart + inner->BSize(aWM)));
}
nsIScrollableFrame* nsFieldSetFrame::GetScrollTargetFrame() const {

Просмотреть файл

@ -40,9 +40,9 @@ class nsFieldSetFrame final : public nsContainerFrame {
mozilla::WritingMode aWM,
BaselineSharingGroup aBaselineGroup) const override;
BaselineSharingGroup GetDefaultBaselineSharingGroup() const override;
bool GetNaturalBaselineBOffset(mozilla::WritingMode aWM,
BaselineSharingGroup aBaselineGroup,
nscoord* aBaseline) const override;
Maybe<nscoord> GetNaturalBaselineBOffset(
mozilla::WritingMode aWM,
BaselineSharingGroup aBaselineGroup) const override;
virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder,
const nsDisplayListSet& aLists) override;

Просмотреть файл

@ -310,29 +310,27 @@ void nsHTMLButtonControlFrame::ReflowButtonContents(
aButtonDesiredSize.SetOverflowAreasToDesiredBounds();
}
bool nsHTMLButtonControlFrame::GetNaturalBaselineBOffset(
WritingMode aWM, BaselineSharingGroup aBaselineGroup,
nscoord* aBaseline) const {
Maybe<nscoord> nsHTMLButtonControlFrame::GetNaturalBaselineBOffset(
WritingMode aWM, BaselineSharingGroup aBaselineGroup) const {
if (StyleDisplay()->IsContainLayout()) {
return false;
return Nothing{};
}
nsIFrame* inner = mFrames.FirstChild();
if (MOZ_UNLIKELY(inner->GetWritingMode().IsOrthogonalTo(aWM))) {
return false;
}
if (!inner->GetNaturalBaselineBOffset(aWM, aBaselineGroup, aBaseline)) {
// <input type=color> has an empty block frame as inner frame
*aBaseline =
Baseline::SynthesizeBOffsetFromBorderBox(inner, aWM, aBaselineGroup);
return Nothing{};
}
auto result = inner->GetNaturalBaselineBOffset(aWM, aBaselineGroup)
.valueOrFrom([inner, aWM, aBaselineGroup]() {
return Baseline::SynthesizeBOffsetFromBorderBox(
inner, aWM, aBaselineGroup);
});
nscoord innerBStart = inner->BStart(aWM, GetSize());
if (aBaselineGroup == BaselineSharingGroup::First) {
*aBaseline += innerBStart;
} else {
*aBaseline += BSize(aWM) - (innerBStart + inner->BSize(aWM));
return Some(result + innerBStart);
}
return true;
return Some(result + BSize(aWM) - (innerBStart + inner->BSize(aWM)));
}
BaselineSharingGroup nsHTMLButtonControlFrame::GetDefaultBaselineSharingGroup()

Просмотреть файл

@ -38,9 +38,9 @@ class nsHTMLButtonControlFrame : public nsContainerFrame,
const ReflowInput& aReflowInput,
nsReflowStatus& aStatus) override;
bool GetNaturalBaselineBOffset(mozilla::WritingMode aWM,
BaselineSharingGroup aBaselineGroup,
nscoord* aBaseline) const override;
Maybe<nscoord> GetNaturalBaselineBOffset(
mozilla::WritingMode aWM,
BaselineSharingGroup aBaselineGroup) const override;
virtual nsresult HandleEvent(nsPresContext* aPresContext,
mozilla::WidgetGUIEvent* aEvent,

Просмотреть файл

@ -70,11 +70,10 @@ nsListControlFrame::nsListControlFrame(ComputedStyle* aStyle,
nsListControlFrame::~nsListControlFrame() = default;
bool nsListControlFrame::GetNaturalBaselineBOffset(
WritingMode aWM, BaselineSharingGroup aBaselineGroup,
nscoord* aBaseline) const {
Maybe<nscoord> nsListControlFrame::GetNaturalBaselineBOffset(
WritingMode aWM, BaselineSharingGroup aBaselineGroup) const {
// Unlike scroll frames which we inherit from, we don't export a baseline.
return false;
return Nothing{};
}
// for Bug 47302 (remove this comment later)
void nsListControlFrame::DestroyFrom(nsIFrame* aDestructRoot,

Просмотреть файл

@ -55,9 +55,9 @@ class nsListControlFrame final : public nsHTMLScrollFrame,
NS_DECL_QUERYFRAME
NS_DECL_FRAMEARENA_HELPERS(nsListControlFrame)
bool GetNaturalBaselineBOffset(mozilla::WritingMode aWM,
BaselineSharingGroup aBaselineGroup,
nscoord* aBaseline) const override;
Maybe<nscoord> GetNaturalBaselineBOffset(
mozilla::WritingMode aWM,
BaselineSharingGroup aBaselineGroup) const override;
// nsIFrame
nsresult HandleEvent(nsPresContext* aPresContext,

Просмотреть файл

@ -77,28 +77,27 @@ class nsTextControlFrame : public nsContainerFrame,
const ReflowInput& aReflowInput,
nsReflowStatus& aStatus) override;
bool GetNaturalBaselineBOffset(mozilla::WritingMode aWM,
BaselineSharingGroup aBaselineGroup,
nscoord* aBaseline) const override {
Maybe<nscoord> GetNaturalBaselineBOffset(
mozilla::WritingMode aWM,
BaselineSharingGroup aBaselineGroup) const override {
if (!IsSingleLineTextControl()) {
return false;
return Nothing{};
}
return GetSingleLineTextControlBaseline(this, mFirstBaseline, aWM,
aBaselineGroup, aBaseline);
aBaselineGroup);
}
static bool GetSingleLineTextControlBaseline(
static Maybe<nscoord> GetSingleLineTextControlBaseline(
const nsIFrame* aFrame, nscoord aFirstBaseline, mozilla::WritingMode aWM,
BaselineSharingGroup aBaselineGroup, nscoord* aBaseline) {
BaselineSharingGroup aBaselineGroup) {
if (aFrame->StyleDisplay()->IsContainLayout()) {
return false;
return Nothing{};
}
NS_ASSERTION(aFirstBaseline != NS_INTRINSIC_ISIZE_UNKNOWN,
"please call Reflow before asking for the baseline");
*aBaseline = aBaselineGroup == BaselineSharingGroup::First
? aFirstBaseline
: aFrame->BSize(aWM) - aFirstBaseline;
return true;
return mozilla::Some(aBaselineGroup == BaselineSharingGroup::First
? aFirstBaseline
: aFrame->BSize(aWM) - aFirstBaseline);
}
nsSize GetXULMinSize(nsBoxLayoutState&) override;

Просмотреть файл

@ -59,9 +59,8 @@ class BRFrame final : public nsIFrame {
nscoord GetMinISize(gfxContext* aRenderingContext) override;
nscoord GetPrefISize(gfxContext* aRenderingContext) override;
bool GetNaturalBaselineBOffset(WritingMode aWM,
BaselineSharingGroup aBaselineGroup,
nscoord* aBaseline) const override;
Maybe<nscoord> GetNaturalBaselineBOffset(
WritingMode aWM, BaselineSharingGroup aBaselineGroup) const override;
bool IsFrameOfType(uint32_t aFlags) const override {
return nsIFrame::IsFrameOfType(
@ -203,14 +202,12 @@ nscoord BRFrame::GetPrefISize(gfxContext* aRenderingContext) {
return result;
}
bool BRFrame::GetNaturalBaselineBOffset(WritingMode aWM,
BaselineSharingGroup aBaselineGroup,
nscoord* aBaseline) const {
Maybe<nscoord> BRFrame::GetNaturalBaselineBOffset(
WritingMode aWM, BaselineSharingGroup aBaselineGroup) const {
if (aBaselineGroup == BaselineSharingGroup::Last) {
return false;
return Nothing{};
}
*aBaseline = mAscent;
return true;
return Some(mAscent);
}
nsIFrame::ContentOffsets BRFrame::CalcContentOffsetsFromFramePoint(

Просмотреть файл

@ -604,21 +604,23 @@ nscoord nsBlockFrame::SynthesizeFallbackBaseline(
return Baseline::SynthesizeBOffsetFromMarginBox(this, aWM, aBaselineGroup);
}
bool nsBlockFrame::GetNaturalBaselineBOffset(
WritingMode aWM, BaselineSharingGroup aBaselineGroup,
nscoord* aBaseline) const {
Maybe<nscoord> nsBlockFrame::GetNaturalBaselineBOffset(
WritingMode aWM, BaselineSharingGroup aBaselineGroup) const {
if (StyleDisplay()->IsContainLayout()) {
return false;
return Nothing{};
}
if (aBaselineGroup == BaselineSharingGroup::First) {
return nsLayoutUtils::GetFirstLineBaseline(aWM, this, aBaseline);
nscoord result;
if (!nsLayoutUtils::GetFirstLineBaseline(aWM, this, &result)) {
return Nothing{};
}
return Some(result);
}
for (ConstReverseLineIterator line = LinesRBegin(), line_end = LinesREnd();
line != line_end; ++line) {
if (line->IsBlock()) {
nscoord offset;
nsIFrame* kid = line->mFirstChild;
if (aWM.IsOrthogonalTo(kid->GetWritingMode())) {
continue;
@ -628,26 +630,28 @@ bool nsBlockFrame::GetNaturalBaselineBOffset(
continue;
}
const auto kidBaselineGroup = kid->GetDefaultBaselineSharingGroup();
if (kid->GetNaturalBaselineBOffset(aWM, kidBaselineGroup, &offset)) {
if (kidBaselineGroup == BaselineSharingGroup::Last) {
offset = kid->BSize(aWM) - offset;
}
// Ignore relative positioning for baseline calculations.
const nsSize& sz = line->mContainerSize;
offset += kid->GetLogicalNormalPosition(aWM, sz).B(aWM);
*aBaseline = BSize(aWM) - offset;
return true;
const auto kidBaseline =
kid->GetNaturalBaselineBOffset(aWM, kidBaselineGroup);
if (!kidBaseline) {
continue;
}
auto result = *kidBaseline;
if (kidBaselineGroup == BaselineSharingGroup::Last) {
result = kid->BSize(aWM) - result;
}
// Ignore relative positioning for baseline calculations.
const nsSize& sz = line->mContainerSize;
result += kid->GetLogicalNormalPosition(aWM, sz).B(aWM);
return Some(BSize(aWM) - result);
} else {
// XXX Is this the right test? We have some bogus empty lines
// floating around, but IsEmpty is perhaps too weak.
if (line->BSize() != 0 || !line->IsEmpty()) {
*aBaseline = BSize(aWM) - (line->BStart() + line->GetLogicalAscent());
return true;
return Some(BSize(aWM) - (line->BStart() + line->GetLogicalAscent()));
}
}
}
return false;
return Nothing{};
}
nscoord nsBlockFrame::GetCaretBaseline() const {
@ -1565,14 +1569,13 @@ void nsBlockFrame::Reflow(nsPresContext* aPresContext, ReflowOutput& aMetrics,
LogicalRect bbox =
marker->GetLogicalRect(wm, reflowOutput.PhysicalSize());
const auto baselineGroup = BaselineSharingGroup::First;
nscoord markerBaseline;
if (MOZ_UNLIKELY(wm.IsOrthogonalTo(marker->GetWritingMode()) ||
!marker->GetNaturalBaselineBOffset(wm, baselineGroup,
&markerBaseline))) {
// ::marker has no baseline in this axis: align with its margin-box end.
markerBaseline =
bbox.BSize(wm) + marker->GetLogicalUsedMargin(wm).BEnd(wm);
Maybe<nscoord> result;
if (MOZ_LIKELY(!wm.IsOrthogonalTo(marker->GetWritingMode()))) {
result = marker->GetNaturalBaselineBOffset(wm, baselineGroup);
}
const auto markerBaseline = result.valueOrFrom([bbox, wm, marker]() {
return bbox.BSize(wm) + marker->GetLogicalUsedMargin(wm).BEnd(wm);
});
bbox.BStart(wm) = position.mBaseline - markerBaseline;
marker->SetRect(wm, bbox, reflowOutput.PhysicalSize());
}

Просмотреть файл

@ -132,9 +132,9 @@ class nsBlockFrame : public nsContainerFrame {
BaselineSharingGroup GetDefaultBaselineSharingGroup() const override {
return BaselineSharingGroup::Last;
}
bool GetNaturalBaselineBOffset(mozilla::WritingMode aWM,
BaselineSharingGroup aBaselineGroup,
nscoord* aBaseline) const override;
Maybe<nscoord> GetNaturalBaselineBOffset(
mozilla::WritingMode aWM,
BaselineSharingGroup aBaselineGroup) const override;
nscoord GetCaretBaseline() const override;
void DestroyFrom(nsIFrame* aDestructRoot,
PostDestroyData& aPostDestroyData) override;

Просмотреть файл

@ -425,14 +425,12 @@ void nsFirstLetterFrame::DrainOverflowFrames(nsPresContext* aPresContext) {
}
}
bool nsFirstLetterFrame::GetNaturalBaselineBOffset(
WritingMode aWM, BaselineSharingGroup aBaselineGroup,
nscoord* aBaseline) const {
Maybe<nscoord> nsFirstLetterFrame::GetNaturalBaselineBOffset(
WritingMode aWM, BaselineSharingGroup aBaselineGroup) const {
if (aBaselineGroup == BaselineSharingGroup::Last) {
return false;
return Nothing{};
}
*aBaseline = mBaseline;
return true;
return Some(mBaseline);
}
LogicalSides nsFirstLetterFrame::GetLogicalSkipSides() const {

Просмотреть файл

@ -60,9 +60,9 @@ class nsFirstLetterFrame final : public nsContainerFrame {
nsReflowStatus& aStatus) override;
virtual bool CanContinueTextRun() const override;
bool GetNaturalBaselineBOffset(mozilla::WritingMode aWM,
BaselineSharingGroup aBaselineGroup,
nscoord* aBaseline) const override;
Maybe<nscoord> GetNaturalBaselineBOffset(
mozilla::WritingMode aWM,
BaselineSharingGroup aBaselineGroup) const override;
virtual LogicalSides GetLogicalSkipSides() const override;
// override of nsFrame method

Просмотреть файл

@ -421,12 +421,12 @@ class nsFlexContainerFrame::FlexItem final {
// If the nsLayoutUtils getter fails, then ask the frame directly:
auto baselineGroup = aUseFirstBaseline ? BaselineSharingGroup::First
: BaselineSharingGroup::Last;
if (mFrame->GetNaturalBaselineBOffset(mWM, baselineGroup, &mAscent)) {
if (baselineGroup == BaselineSharingGroup::Last) {
// Offset for last baseline from `GetNaturalBaselineBOffset` originates
// from the frame's block end, so convert it back.
mAscent = mFrame->BSize(mWM) - mAscent;
}
if (auto baseline = mFrame->GetNaturalBaselineBOffset(mWM, baselineGroup)) {
// Offset for last baseline from `GetNaturalBaselineBOffset` originates
// from the frame's block end, so convert it back.
mAscent = baselineGroup == BaselineSharingGroup::First
? *baseline
: mFrame->BSize(mWM) - *baseline;
return mAscent;
}
@ -4632,6 +4632,17 @@ void nsFlexContainerFrame::Reflow(nsPresContext* aPresContext,
}
}
Maybe<nscoord> nsFlexContainerFrame::GetNaturalBaselineBOffset(
WritingMode aWM, BaselineSharingGroup aBaselineGroup) const {
if (StyleDisplay()->IsContainLayout() ||
HasAnyStateBits(NS_STATE_FLEX_SYNTHESIZE_BASELINE)) {
return Nothing{};
}
return Some(aBaselineGroup == BaselineSharingGroup::First
? mBaselineFromLastReflow
: mLastBaselineFromLastReflow);
}
void nsFlexContainerFrame::UnionInFlowChildOverflow(
OverflowAreas& aOverflowAreas) {
// The CSS Overflow spec [1] requires that a scrollable container's

Просмотреть файл

@ -165,18 +165,9 @@ class nsFlexContainerFrame final : public nsContainerFrame,
nsresult GetFrameName(nsAString& aResult) const override;
#endif
bool GetNaturalBaselineBOffset(mozilla::WritingMode aWM,
BaselineSharingGroup aBaselineGroup,
nscoord* aBaseline) const override {
if (StyleDisplay()->IsContainLayout() ||
HasAnyStateBits(NS_STATE_FLEX_SYNTHESIZE_BASELINE)) {
return false;
}
*aBaseline = aBaselineGroup == BaselineSharingGroup::First
? mBaselineFromLastReflow
: mLastBaselineFromLastReflow;
return true;
}
Maybe<nscoord> GetNaturalBaselineBOffset(
mozilla::WritingMode aWM,
BaselineSharingGroup aBaselineGroup) const override;
// Unions the child overflow from our in-flow children.
void UnionInFlowChildOverflow(mozilla::OverflowAreas&);

Просмотреть файл

@ -1347,9 +1347,8 @@ static void GetScrollableOverflowForPerspective(
}
}
bool nsHTMLScrollFrame::GetNaturalBaselineBOffset(
WritingMode aWM, BaselineSharingGroup aBaselineGroup,
nscoord* aBaseline) const {
Maybe<nscoord> nsHTMLScrollFrame::GetNaturalBaselineBOffset(
WritingMode aWM, BaselineSharingGroup aBaselineGroup) const {
// Block containers that are scrollable always have a first & last baselines
// that are synthesized from block-end margin edge.
// Note(dshin): This behaviour is really only relevant to `inline-block`
@ -1358,29 +1357,24 @@ bool nsHTMLScrollFrame::GetNaturalBaselineBOffset(
// calculations of its own.
// https://drafts.csswg.org/css-align/#baseline-export
if (mHelper.mScrolledFrame->IsBlockFrameOrSubclass()) {
*aBaseline = SynthesizeFallbackBaseline(aWM, aBaselineGroup);
return true;
return Some(SynthesizeFallbackBaseline(aWM, aBaselineGroup));
}
if (StyleDisplay()->IsContainLayout()) {
return false;
return Nothing{};
}
// OK, here's where we defer to our scrolled frame.
nscoord scrolledBaseline;
if (!mHelper.mScrolledFrame->GetNaturalBaselineBOffset(aWM, aBaselineGroup,
&scrolledBaseline)) {
return false;
}
// We have to add our border BStart thickness to whatever it returns, to
// produce an offset in our frame-rect's coordinate system. (We don't have to
// add padding, because the scrolled frame handles our padding.)
LogicalMargin border = GetLogicalUsedBorder(aWM);
const auto bSize = GetLogicalSize(aWM).BSize(aWM);
// Clamp the baseline to the border rect. See bug 1791069.
*aBaseline = std::clamp(border.BStart(aWM) + scrolledBaseline, 0, bSize);
return true;
return mHelper.mScrolledFrame->GetNaturalBaselineBOffset(aWM, aBaselineGroup)
.map([this, aWM](nscoord aBaseline) {
// We have to add our border BStart thickness to whatever it returns, to
// produce an offset in our frame-rect's coordinate system. (We don't
// have to add padding, because the scrolled frame handles our padding.)
LogicalMargin border = GetLogicalUsedBorder(aWM);
const auto bSize = GetLogicalSize(aWM).BSize(aWM);
// Clamp the baseline to the border rect. See bug 1791069.
return std::clamp(border.BStart(aWM) + aBaseline, 0, bSize);
});
}
void nsHTMLScrollFrame::AdjustForPerspective(nsRect& aScrollableOverflow) {

Просмотреть файл

@ -978,9 +978,9 @@ class nsHTMLScrollFrame : public nsContainerFrame,
return mHelper.ComputeCustomOverflow(aOverflowAreas);
}
bool GetNaturalBaselineBOffset(mozilla::WritingMode aWM,
BaselineSharingGroup aBaselineGroup,
nscoord* aBaseline) const override;
Maybe<nscoord> GetNaturalBaselineBOffset(
mozilla::WritingMode aWM,
BaselineSharingGroup aBaselineGroup) const override;
// Recomputes the scrollable overflow area we store in the helper to take
// children that are affected by perpsective set on the outer frame and scroll

Просмотреть файл

@ -5818,9 +5818,9 @@ void nsGridContainerFrame::Tracks::InitializeItemBaselines(
if (state & ItemState::eFirstBaseline) {
if (grid) {
if (isOrthogonal == isInlineAxis) {
grid->GetBBaseline(BaselineSharingGroup::First, &baseline);
baseline = grid->GetBBaseline(BaselineSharingGroup::First);
} else {
grid->GetIBaseline(BaselineSharingGroup::First, &baseline);
baseline = grid->GetIBaseline(BaselineSharingGroup::First);
}
}
if (grid || nsLayoutUtils::GetFirstLineBaseline(wm, child, &baseline)) {
@ -5839,9 +5839,9 @@ void nsGridContainerFrame::Tracks::InitializeItemBaselines(
} else {
if (grid) {
if (isOrthogonal == isInlineAxis) {
grid->GetBBaseline(BaselineSharingGroup::Last, &baseline);
baseline = grid->GetBBaseline(BaselineSharingGroup::Last);
} else {
grid->GetIBaseline(BaselineSharingGroup::Last, &baseline);
baseline = grid->GetIBaseline(BaselineSharingGroup::Last);
}
}
if (grid || nsLayoutUtils::GetLastLineBaseline(wm, child, &baseline)) {
@ -5982,9 +5982,9 @@ void nsGridContainerFrame::Tracks::InitializeItemBaselinesInMasonryAxis(
if (state & ItemState::eFirstBaseline) {
if (grid) {
if (isOrthogonal == isInlineAxis) {
grid->GetBBaseline(BaselineSharingGroup::First, &baseline);
baseline = grid->GetBBaseline(BaselineSharingGroup::First);
} else {
grid->GetIBaseline(BaselineSharingGroup::First, &baseline);
baseline = grid->GetIBaseline(BaselineSharingGroup::First);
}
}
if (grid || nsLayoutUtils::GetFirstLineBaseline(wm, child, &baseline)) {
@ -6013,9 +6013,9 @@ void nsGridContainerFrame::Tracks::InitializeItemBaselinesInMasonryAxis(
} else {
if (grid) {
if (isOrthogonal == isInlineAxis) {
grid->GetBBaseline(BaselineSharingGroup::Last, &baseline);
baseline = grid->GetBBaseline(BaselineSharingGroup::Last);
} else {
grid->GetIBaseline(BaselineSharingGroup::Last, &baseline);
baseline = grid->GetIBaseline(BaselineSharingGroup::Last);
}
}
if (grid || nsLayoutUtils::GetLastLineBaseline(wm, child, &baseline)) {
@ -9586,15 +9586,14 @@ nscoord nsGridContainerFrame::SynthesizeBaseline(
start = child->GetLogicalNormalPosition(aCBWM, aCBPhysicalSize).B(aCBWM);
size = child->BSize(aCBWM);
if (grid && aGridOrderItem.mIsInEdgeTrack) {
isOrthogonal ? grid->GetIBaseline(aGroup, &baseline)
: grid->GetBBaseline(aGroup, &baseline);
baseline = isOrthogonal ? grid->GetIBaseline(aGroup)
: grid->GetBBaseline(aGroup);
} else if (!isOrthogonal && aGridOrderItem.mIsInEdgeTrack) {
const bool result =
child->GetNaturalBaselineBOffset(childWM, aGroup, &baseline);
if (!result) {
baseline =
Baseline::SynthesizeBOffsetFromBorderBox(child, childWM, aGroup);
}
baseline = child->GetNaturalBaselineBOffset(childWM, aGroup)
.valueOrFrom([aGroup, child, childWM]() {
return Baseline::SynthesizeBOffsetFromBorderBox(
child, childWM, aGroup);
});
} else {
baseline = ::SynthesizeBaselineFromBorderBox(aGroup, childWM, size);
}
@ -9602,8 +9601,8 @@ nscoord nsGridContainerFrame::SynthesizeBaseline(
start = child->GetLogicalNormalPosition(aCBWM, aCBPhysicalSize).I(aCBWM);
size = child->ISize(aCBWM);
if (grid && aGridOrderItem.mIsInEdgeTrack) {
isOrthogonal ? grid->GetBBaseline(aGroup, &baseline)
: grid->GetIBaseline(aGroup, &baseline);
baseline = isOrthogonal ? grid->GetBBaseline(aGroup)
: grid->GetIBaseline(aGroup);
} else if (isOrthogonal && aGridOrderItem.mIsInEdgeTrack &&
GetBBaseline(aGroup, childWM, child, &baseline)) {
if (aGroup == BaselineSharingGroup::Last) {

Просмотреть файл

@ -130,14 +130,14 @@ class nsGridContainerFrame final : public nsContainerFrame,
void BuildDisplayList(nsDisplayListBuilder* aBuilder,
const nsDisplayListSet& aLists) override;
bool GetNaturalBaselineBOffset(mozilla::WritingMode aWM,
BaselineSharingGroup aBaselineGroup,
nscoord* aBaseline) const override {
Maybe<nscoord> GetNaturalBaselineBOffset(
mozilla::WritingMode aWM,
BaselineSharingGroup aBaselineGroup) const override {
if (StyleDisplay()->IsContainLayout() ||
HasAnyStateBits(NS_STATE_GRID_SYNTHESIZE_BASELINE)) {
return false;
return Nothing{};
}
return GetBBaseline(aBaselineGroup, aBaseline);
return mozilla::Some(GetBBaseline(aBaselineGroup));
}
#ifdef DEBUG_FRAME_DUMP
@ -367,15 +367,11 @@ class nsGridContainerFrame final : public nsContainerFrame,
nscoord IntrinsicISize(gfxContext* aRenderingContext,
mozilla::IntrinsicISizeType aConstraint);
bool GetBBaseline(BaselineSharingGroup aBaselineGroup,
nscoord* aResult) const {
*aResult = mBaseline[mozilla::eLogicalAxisBlock][aBaselineGroup];
return true;
nscoord GetBBaseline(BaselineSharingGroup aBaselineGroup) const {
return mBaseline[mozilla::eLogicalAxisBlock][aBaselineGroup];
}
bool GetIBaseline(BaselineSharingGroup aBaselineGroup,
nscoord* aResult) const {
*aResult = mBaseline[mozilla::eLogicalAxisInline][aBaselineGroup];
return true;
nscoord GetIBaseline(BaselineSharingGroup aBaselineGroup) const {
return mBaseline[mozilla::eLogicalAxisInline][aBaselineGroup];
}
/**

Просмотреть файл

@ -2130,12 +2130,13 @@ nscoord nsIFrame::GetLogicalBaseline(WritingMode aWM) const {
nscoord nsIFrame::GetLogicalBaseline(
WritingMode aWM, BaselineSharingGroup aBaselineGroup) const {
nscoord result;
if (!GetNaturalBaselineBOffset(aWM, aBaselineGroup, &result)) {
result = SynthesizeFallbackBaseline(aWM, aBaselineGroup);
}
const auto result =
GetNaturalBaselineBOffset(aWM, aBaselineGroup)
.valueOrFrom([this, aWM, aBaselineGroup]() {
return SynthesizeFallbackBaseline(aWM, aBaselineGroup);
});
if (aBaselineGroup == BaselineSharingGroup::Last) {
result = BSize(aWM) - result;
return BSize(aWM) - result;
}
return result;
}

Просмотреть файл

@ -1535,12 +1535,11 @@ class nsIFrame : public nsQueryFrame {
* @note The returned value is only valid when reflow is not needed.
* @note You should only call this on frames with a WM that's parallel to aWM.
* @param aWM the writing-mode of the alignment context.
* @param aBaseline the baseline offset, only valid if the method returns true
* @return the baseline offset, if one exists
*/
virtual bool GetNaturalBaselineBOffset(mozilla::WritingMode aWM,
BaselineSharingGroup aBaselineGroup,
nscoord* aBaseline) const {
return false;
virtual Maybe<nscoord> GetNaturalBaselineBOffset(
mozilla::WritingMode aWM, BaselineSharingGroup aBaselineGroup) const {
return Nothing{};
}
/**

Просмотреть файл

@ -841,14 +841,12 @@ LogicalSides nsInlineFrame::GetLogicalSkipSides() const {
return skip;
}
bool nsInlineFrame::GetNaturalBaselineBOffset(
WritingMode aWM, BaselineSharingGroup aBaselineGroup,
nscoord* aBaseline) const {
Maybe<nscoord> nsInlineFrame::GetNaturalBaselineBOffset(
WritingMode aWM, BaselineSharingGroup aBaselineGroup) const {
if (aBaselineGroup == BaselineSharingGroup::Last) {
return false;
return Nothing{};
}
*aBaseline = mBaseline;
return true;
return Some(mBaseline);
}
#ifdef ACCESSIBILITY

Просмотреть файл

@ -96,9 +96,9 @@ class nsInlineFrame : public nsContainerFrame {
virtual void PullOverflowsFromPrevInFlow() override;
bool GetNaturalBaselineBOffset(mozilla::WritingMode aWM,
BaselineSharingGroup aBaselineGroup,
nscoord* aBaseline) const override;
Maybe<nscoord> GetNaturalBaselineBOffset(
mozilla::WritingMode aWM,
BaselineSharingGroup aBaselineGroup) const override;
virtual bool DrainSelfOverflowList() override;
/**

Просмотреть файл

@ -261,14 +261,12 @@ nsIFrame::SizeComputationResult nsRubyBaseContainerFrame::ComputeSize(
AspectRatioUsage::None};
}
bool nsRubyBaseContainerFrame::GetNaturalBaselineBOffset(
WritingMode aWM, BaselineSharingGroup aBaselineGroup,
nscoord* aBaseline) const {
Maybe<nscoord> nsRubyBaseContainerFrame::GetNaturalBaselineBOffset(
WritingMode aWM, BaselineSharingGroup aBaselineGroup) const {
if (aBaselineGroup == BaselineSharingGroup::Last) {
return false;
return Nothing{};
}
*aBaseline = mBaseline;
return true;
return Some(mBaseline);
}
struct nsRubyBaseContainerFrame::RubyReflowInput {

Просмотреть файл

@ -46,9 +46,9 @@ class nsRubyBaseContainerFrame final : public nsContainerFrame {
const ReflowInput& aReflowInput,
nsReflowStatus& aStatus) override;
bool GetNaturalBaselineBOffset(mozilla::WritingMode aWM,
BaselineSharingGroup aBaselineGroup,
nscoord* aBaseline) const override;
Maybe<nscoord> GetNaturalBaselineBOffset(
mozilla::WritingMode aWM,
BaselineSharingGroup aBaselineGroup) const override;
#ifdef DEBUG_FRAME_DUMP
virtual nsresult GetFrameName(nsAString& aResult) const override;

Просмотреть файл

@ -10704,16 +10704,14 @@ bool nsTextFrame::IsAtEndOfLine() const {
return HasAnyStateBits(TEXT_END_OF_LINE);
}
bool nsTextFrame::GetNaturalBaselineBOffset(WritingMode aWM,
BaselineSharingGroup aBaselineGroup,
nscoord* aBaseline) const {
Maybe<nscoord> nsTextFrame::GetNaturalBaselineBOffset(
WritingMode aWM, BaselineSharingGroup aBaselineGroup) const {
if (aBaselineGroup == BaselineSharingGroup::Last) {
return false;
return Nothing{};
}
if (!aWM.IsOrthogonalTo(GetWritingMode())) {
*aBaseline = mAscent;
return true;
return Some(mAscent);
}
// When the text frame has a writing mode orthogonal to the desired
@ -10724,11 +10722,9 @@ bool nsTextFrame::GetNaturalBaselineBOffset(WritingMode aWM,
if (aWM.IsVerticalRL()) {
nscoord parentDescent = parent->GetSize().width - parentAscent;
nscoord descent = parentDescent - position.x;
*aBaseline = GetSize().width - descent;
} else {
*aBaseline = parentAscent - (aWM.IsVertical() ? position.x : position.y);
return Some(GetSize().width - descent);
}
return true;
return Some(parentAscent - (aWM.IsVertical() ? position.x : position.y));
}
bool nsTextFrame::HasAnyNoncollapsedCharacters() {

Просмотреть файл

@ -366,9 +366,9 @@ class nsTextFrame : public nsIFrame {
bool IsEmpty() final;
bool IsSelfEmpty() final { return IsEmpty(); }
bool GetNaturalBaselineBOffset(mozilla::WritingMode aWM,
BaselineSharingGroup aBaselineGroup,
nscoord* aBaseline) const override;
Maybe<nscoord> GetNaturalBaselineBOffset(
mozilla::WritingMode aWM,
BaselineSharingGroup aBaselineGroup) const override;
bool HasSignificantTerminalNewline() const final;

Просмотреть файл

@ -3521,11 +3521,10 @@ nscoord nsTableFrame::SynthesizeFallbackBaseline(
}
/* virtual */
bool nsTableFrame::GetNaturalBaselineBOffset(
WritingMode aWM, BaselineSharingGroup aBaselineGroup,
nscoord* aBaseline) const {
Maybe<nscoord> nsTableFrame::GetNaturalBaselineBOffset(
WritingMode aWM, BaselineSharingGroup aBaselineGroup) const {
if (StyleDisplay()->IsContainLayout()) {
return false;
return Nothing{};
}
RowGroupArray orderedRowGroups;
@ -3545,8 +3544,7 @@ bool nsTableFrame::GetNaturalBaselineBOffset(
nsTableRowGroupFrame* rgFrame = orderedRowGroups[rgIndex];
nsTableRowFrame* row = rgFrame->GetFirstRow();
if (row) {
*aBaseline = TableBaseline(rgFrame, row);
return true;
return Some(TableBaseline(rgFrame, row));
}
}
} else {
@ -3554,12 +3552,11 @@ bool nsTableFrame::GetNaturalBaselineBOffset(
nsTableRowGroupFrame* rgFrame = orderedRowGroups[rgIndex];
nsTableRowFrame* row = rgFrame->GetLastRow();
if (row) {
*aBaseline = BSize(aWM) - TableBaseline(rgFrame, row);
return true;
return Some(BSize(aWM) - TableBaseline(rgFrame, row));
}
}
}
return false;
return Nothing{};
}
/* ----- global methods ----- */

Просмотреть файл

@ -434,9 +434,9 @@ class nsTableFrame : public nsContainerFrame {
nscoord SynthesizeFallbackBaseline(
mozilla::WritingMode aWM,
BaselineSharingGroup aBaselineGroup) const override;
bool GetNaturalBaselineBOffset(mozilla::WritingMode aWM,
BaselineSharingGroup aBaselineGroup,
nscoord* aBaseline) const override;
Maybe<nscoord> GetNaturalBaselineBOffset(
mozilla::WritingMode aWM,
BaselineSharingGroup aBaselineGroup) const override;
/** return the row span of a cell, taking into account row span magic at the
* bottom of a table. The row span equals the number of rows spanned by aCell

Просмотреть файл

@ -37,9 +37,8 @@ nscoord nsTableWrapperFrame::SynthesizeFallbackBaseline(
return BSize(aWM) + marginBlockEnd;
}
bool nsTableWrapperFrame::GetNaturalBaselineBOffset(
WritingMode aWM, BaselineSharingGroup aBaselineGroup,
nscoord* aBaseline) const {
Maybe<nscoord> nsTableWrapperFrame::GetNaturalBaselineBOffset(
WritingMode aWM, BaselineSharingGroup aBaselineGroup) const {
// Baseline is determined by row
// (https://drafts.csswg.org/css-align-3/#baseline-export). If the row
// direction is going to be orthogonal to the parent's writing mode, the
@ -47,21 +46,18 @@ bool nsTableWrapperFrame::GetNaturalBaselineBOffset(
// instead.
if (StyleDisplay()->IsContainLayout() ||
GetWritingMode().IsOrthogonalTo(aWM)) {
return false;
return Nothing{};
}
auto* innerTable = InnerTableFrame();
nscoord offset;
if (innerTable->GetNaturalBaselineBOffset(aWM, aBaselineGroup, &offset)) {
auto bStart = innerTable->BStart(aWM, mRect.Size());
if (aBaselineGroup == BaselineSharingGroup::First) {
*aBaseline = offset + bStart;
} else {
auto bEnd = bStart + innerTable->BSize(aWM);
*aBaseline = BSize(aWM) - (bEnd - offset);
}
return true;
}
return false;
return innerTable->GetNaturalBaselineBOffset(aWM, aBaselineGroup)
.map([this, aWM, aBaselineGroup, innerTable](nscoord aBaseline) {
auto bStart = innerTable->BStart(aWM, mRect.Size());
if (aBaselineGroup == BaselineSharingGroup::First) {
return aBaseline + bStart;
}
auto bEnd = bStart + innerTable->BSize(aWM);
return BSize(aWM) - (bEnd - aBaseline);
});
}
nsTableWrapperFrame::nsTableWrapperFrame(ComputedStyle* aStyle,

Просмотреть файл

@ -67,9 +67,9 @@ class nsTableWrapperFrame : public nsContainerFrame {
nscoord SynthesizeFallbackBaseline(
mozilla::WritingMode aWM,
BaselineSharingGroup aBaselineGroup) const override;
bool GetNaturalBaselineBOffset(mozilla::WritingMode aWM,
BaselineSharingGroup aBaselineGroup,
nscoord* aBaseline) const override;
Maybe<nscoord> GetNaturalBaselineBOffset(
mozilla::WritingMode aWM,
BaselineSharingGroup aBaselineGroup) const override;
virtual nscoord GetMinISize(gfxContext* aRenderingContext) override;
virtual nscoord GetPrefISize(gfxContext* aRenderingContext) override;