Bug 1906792 Part 1 - Let nsLeafFrame and subclasses override GetIntrinsicSize(). r=layout-reviewers,emilio

`nsIFrame` already provides `GetIntrinsicSize()` for subclasses to override.
Therefore, `nsLeafFrame` doesn't need to introduce another version for its
subclasses.

This patch (hopefully) shouldn't change the behavior.

Differential Revision: https://phabricator.services.mozilla.com/D215998
This commit is contained in:
Ting-Yu Lin 2024-07-09 18:49:32 +00:00
parent d99f46a3b3
commit 18707dab6b
9 changed files with 23 additions and 67 deletions

View File

@ -108,8 +108,6 @@ class nsHTMLFramesetBorderFrame final : public nsLeafFrame {
nsHTMLFramesetBorderFrame(ComputedStyle*, nsPresContext*, int32_t aWidth,
bool aVertical, bool aVisible);
virtual ~nsHTMLFramesetBorderFrame();
virtual nscoord GetIntrinsicISize() override;
virtual nscoord GetIntrinsicBSize() override;
// the prev and next neighbors are indexes into the row (for a horizontal
// border) or col (for a vertical border) of nsHTMLFramesetFrames or
@ -150,8 +148,6 @@ class nsHTMLFramesetBlankFrame final : public nsLeafFrame {
: nsLeafFrame(aStyle, aPresContext, kClassID) {}
virtual ~nsHTMLFramesetBlankFrame();
virtual nscoord GetIntrinsicISize() override;
virtual nscoord GetIntrinsicBSize() override;
friend class nsHTMLFramesetFrame;
friend class nsHTMLFrameset;
@ -1290,16 +1286,6 @@ nsHTMLFramesetBorderFrame::~nsHTMLFramesetBorderFrame() {
NS_IMPL_FRAMEARENA_HELPERS(nsHTMLFramesetBorderFrame)
nscoord nsHTMLFramesetBorderFrame::GetIntrinsicISize() {
// No intrinsic width
return 0;
}
nscoord nsHTMLFramesetBorderFrame::GetIntrinsicBSize() {
// No intrinsic height
return 0;
}
void nsHTMLFramesetBorderFrame::SetVisibility(bool aVisibility) {
mVisibility = aVisibility;
}
@ -1480,16 +1466,6 @@ nsHTMLFramesetBlankFrame::~nsHTMLFramesetBlankFrame() {
// printf("nsHTMLFramesetBlankFrame destructor %p \n", this);
}
nscoord nsHTMLFramesetBlankFrame::GetIntrinsicISize() {
// No intrinsic width
return 0;
}
nscoord nsHTMLFramesetBlankFrame::GetIntrinsicBSize() {
// No intrinsic height
return 0;
}
void nsHTMLFramesetBlankFrame::Reflow(nsPresContext* aPresContext,
ReflowOutput& aDesiredSize,
const ReflowInput& aReflowInput,

View File

@ -6240,7 +6240,8 @@ nsIFrame::IntrinsicSizeOffsetData nsIFrame::IntrinsicBSizeOffsets(
/* virtual */
IntrinsicSize nsIFrame::GetIntrinsicSize() {
return IntrinsicSize(); // default is width/height set to eStyleUnit_None
// Defaults to no intrinsic size.
return IntrinsicSize();
}
AspectRatio nsIFrame::GetAspectRatio() const {

View File

@ -24,12 +24,12 @@ void nsLeafFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
/* virtual */
nscoord nsLeafFrame::GetMinISize(gfxContext* aRenderingContext) {
return GetIntrinsicISize();
return GetIntrinsicSize().ISize(GetWritingMode()).valueOr(0);
}
/* virtual */
nscoord nsLeafFrame::GetPrefISize(gfxContext* aRenderingContext) {
return GetIntrinsicISize();
return GetIntrinsicSize().ISize(GetWritingMode()).valueOr(0);
}
/* virtual */
@ -39,15 +39,12 @@ LogicalSize nsLeafFrame::ComputeAutoSize(
const LogicalSize& aBorderPadding, const StyleSizeOverrides& aSizeOverrides,
ComputeSizeFlags aFlags) {
const WritingMode wm = GetWritingMode();
LogicalSize result(wm, GetIntrinsicISize(), GetIntrinsicBSize());
IntrinsicSize intrinsicSize = GetIntrinsicSize();
LogicalSize result(wm, intrinsicSize.ISize(wm).valueOr(0),
intrinsicSize.BSize(wm).valueOr(0));
return result.ConvertTo(aWM, wm);
}
nscoord nsLeafFrame::GetIntrinsicBSize() {
MOZ_ASSERT_UNREACHABLE("Someone didn't override Reflow or ComputeAutoSize");
return 0;
}
void nsLeafFrame::SizeToAvailSize(const ReflowInput& aReflowInput,
ReflowOutput& aDesiredSize) {
aDesiredSize.SetSize(aReflowInput.GetWritingMode(),

View File

@ -28,14 +28,13 @@ class nsLeafFrame : public nsIFrame {
const nsDisplayListSet& aLists) override;
/**
* Both GetMinISize and GetPrefISize will return whatever GetIntrinsicISize
* returns.
* Both GetMinISize and GetPrefISize will return our intrinsic inline size.
*/
virtual nscoord GetMinISize(gfxContext* aRenderingContext) override;
virtual nscoord GetPrefISize(gfxContext* aRenderingContext) override;
/**
* Our auto size is just intrinsic width and intrinsic height.
* Our auto size is just the intrinsic size.
*/
mozilla::LogicalSize ComputeAutoSize(
gfxContext* aRenderingContext, mozilla::WritingMode aWM,
@ -58,22 +57,6 @@ class nsLeafFrame : public nsIFrame {
virtual ~nsLeafFrame();
/**
* Return the intrinsic isize of the frame's content area. Note that this
* should not include borders or padding and should not depend on the applied
* styles.
*/
virtual nscoord GetIntrinsicISize() = 0;
/**
* Return the intrinsic bsize of the frame's content area. This should not
* include border or padding. This will only matter if the specified bsize
* is auto. Note that subclasses must either implement this or override
* Reflow and ComputeAutoSize; the default Reflow and ComputeAutoSize impls
* call this method.
*/
virtual nscoord GetIntrinsicBSize();
/**
* Set aDesiredSize to be the available size
*/

View File

@ -1003,12 +1003,13 @@ nsPageBreakFrame::nsPageBreakFrame(ComputedStyle* aStyle,
nsPageBreakFrame::~nsPageBreakFrame() = default;
nscoord nsPageBreakFrame::GetIntrinsicISize() {
return nsPresContext::CSSPixelsToAppUnits(1);
IntrinsicSize nsPageBreakFrame::GetIntrinsicSize() {
IntrinsicSize intrinsicSize;
intrinsicSize.ISize(GetWritingMode())
.emplace(nsPresContext::CSSPixelsToAppUnits(1));
return intrinsicSize;
}
nscoord nsPageBreakFrame::GetIntrinsicBSize() { return 0; }
void nsPageBreakFrame::Reflow(nsPresContext* aPresContext,
ReflowOutput& aReflowOutput,
const ReflowInput& aReflowInput,
@ -1041,7 +1042,7 @@ void nsPageBreakFrame::Reflow(nsPresContext* aPresContext,
}
}
}
LogicalSize finalSize(wm, GetIntrinsicISize(), bSize);
LogicalSize finalSize(wm, *GetIntrinsicSize().ISize(wm), bSize);
// round the height down to the nearest pixel
// XXX(mats) why???
finalSize.BSize(wm) -=

View File

@ -162,9 +162,7 @@ class nsPageBreakFrame final : public nsLeafFrame {
nsresult GetFrameName(nsAString& aResult) const override;
#endif
protected:
nscoord GetIntrinsicISize() override;
nscoord GetIntrinsicBSize() override;
mozilla::IntrinsicSize GetIntrinsicSize() override;
friend nsIFrame* NS_NewPageBreakFrame(mozilla::PresShell* aPresShell,
ComputedStyle* aStyle);

View File

@ -22,10 +22,6 @@ class SimpleXULLeafFrame : public nsLeafFrame {
public:
NS_DECL_FRAMEARENA_HELPERS(SimpleXULLeafFrame)
// TODO: Look at appearance instead maybe?
nscoord GetIntrinsicISize() override { return 0; }
nscoord GetIntrinsicBSize() override { return 0; }
void Reflow(nsPresContext* aPresContext, ReflowOutput& aDesiredSize,
const ReflowInput& aReflowInput,
nsReflowStatus& aStatus) override;

View File

@ -389,8 +389,12 @@ void nsTreeBodyFrame::ManageReflowCallback() {
mHorzWidth = horzWidth;
}
nscoord nsTreeBodyFrame::GetIntrinsicBSize() {
return mHasFixedRowCount ? mRowHeight * mPageLength : 0;
IntrinsicSize nsTreeBodyFrame::GetIntrinsicSize() {
IntrinsicSize intrinsicSize;
if (mHasFixedRowCount) {
intrinsicSize.BSize(GetWritingMode()).emplace(mRowHeight * mPageLength);
}
return intrinsicSize;
}
void nsTreeBodyFrame::DidReflow(nsPresContext* aPresContext,

View File

@ -60,7 +60,7 @@ class nsTreeBodyFrame final : public mozilla::SimpleXULLeafFrame,
explicit nsTreeBodyFrame(ComputedStyle* aStyle, nsPresContext* aPresContext);
~nsTreeBodyFrame();
nscoord GetIntrinsicBSize() override;
mozilla::IntrinsicSize GetIntrinsicSize() override;
NS_DECL_QUERYFRAME
NS_DECL_FRAMEARENA_HELPERS(nsTreeBodyFrame)