Skip to content

Commit

Permalink
[Cleanup] Remove RenderBoxModelObject::overridingContainingBlockConte…
Browse files Browse the repository at this point in the history
…ntWidth&co virtual functions

https://bugs.webkit.org/show_bug.cgi?id=273945

Reviewed by Simon Fraser.

There's no real functionality overriding here.

* Source/WebCore/rendering/RenderBox.h:
* Source/WebCore/rendering/RenderBoxModelObject.cpp:
(WebCore::RenderBoxModelObject::relativePositionOffset const):
* Source/WebCore/rendering/RenderBoxModelObject.h:
(WebCore::RenderBoxModelObject::overridingContainingBlockContentWidth const): Deleted.
(WebCore::RenderBoxModelObject::overridingContainingBlockContentHeight const): Deleted.
(WebCore::RenderBoxModelObject::hasOverridingContainingBlockContentWidth const): Deleted.
(WebCore::RenderBoxModelObject::hasOverridingContainingBlockContentHeight const): Deleted.

Canonical link: https://commits.webkit.org/278596@main
  • Loading branch information
alanbaradlay committed May 10, 2024
1 parent 17208d8 commit e2ab34f
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 35 deletions.
8 changes: 4 additions & 4 deletions Source/WebCore/rendering/RenderBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -291,10 +291,10 @@ class RenderBox : public RenderBoxModelObject {
inline LayoutUnit overridingContentLogicalWidth(LayoutUnit overridingLogicalWidth) const;
inline LayoutUnit overridingContentLogicalHeight(LayoutUnit overridingLogicalHeight) const;

std::optional<LayoutUnit> overridingContainingBlockContentWidth() const override;
std::optional<LayoutUnit> overridingContainingBlockContentHeight() const override;
bool hasOverridingContainingBlockContentWidth() const override;
bool hasOverridingContainingBlockContentHeight() const override;
std::optional<LayoutUnit> overridingContainingBlockContentWidth() const;
std::optional<LayoutUnit> overridingContainingBlockContentHeight() const;
bool hasOverridingContainingBlockContentWidth() const;
bool hasOverridingContainingBlockContentHeight() const;
std::optional<LayoutUnit> overridingContainingBlockContentLogicalWidth() const;
std::optional<LayoutUnit> overridingContainingBlockContentLogicalHeight() const;
bool hasOverridingContainingBlockContentLogicalWidth() const;
Expand Down
64 changes: 38 additions & 26 deletions Source/WebCore/rendering/RenderBoxModelObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,23 +385,35 @@ LayoutSize RenderBoxModelObject::relativePositionOffset() const
// where all values are either auto or fixed.

LayoutSize offset = accumulateInFlowPositionOffsets(this);
auto& style = this->style();
if (!containingBlock()) {
ASSERT_NOT_REACHED();
return { };
}
auto& containingBlock = *(this->containingBlock());

// Objects that shrink to avoid floats normally use available line width when computing containing block width. However
// in the case of relative positioning using percentages, we can't do this. The offset should always be resolved using the
// available width of the containing block. Therefore we don't use containingBlockLogicalWidthForContent() here, but instead explicitly
// call availableWidth on our containing block.
// However for grid items the containing block is the grid area, so offsets should be resolved against that:
// https://drafts.csswg.org/css-grid/#grid-item-sizing
if (!style().left().isAuto() || !style().right().isAuto()) {
LayoutUnit availableWidth = hasOverridingContainingBlockContentWidth()
? valueOrDefault(overridingContainingBlockContentWidth()) : containingBlock()->availableWidth();
if (!style().left().isAuto()) {
if (!style().right().isAuto() && !containingBlock()->style().isLeftToRightDirection())
offset.setWidth(-valueForLength(style().right(), !style().right().isFixed() ? availableWidth : 0_lu));
auto& left = style.left();
auto& right = style.right();
if (!left.isAuto() || !right.isAuto()) {
auto availableWidth = [&] {
auto* renderBox = dynamicDowncast<RenderBox>(*this);
if (!renderBox)
return containingBlock.availableWidth();
return renderBox->hasOverridingContainingBlockContentWidth() ? renderBox->overridingContainingBlockContentWidth().value_or(0_lu) : containingBlock.availableWidth();
};
if (!left.isAuto()) {
if (!right.isAuto() && !containingBlock.style().isLeftToRightDirection())
offset.setWidth(-valueForLength(right, availableWidth()));
else
offset.expand(valueForLength(style().left(), !style().left().isFixed() ? availableWidth : 0_lu), 0_lu);
} else if (!style().right().isAuto())
offset.expand(-valueForLength(style().right(), !style().right().isFixed() ? availableWidth : 0_lu), 0_lu);
offset.expand(valueForLength(left, availableWidth()), 0_lu);
} else if (!right.isAuto())
offset.expand(-valueForLength(right, availableWidth()), 0_lu);
}

// If the containing block of a relatively positioned element does not
Expand All @@ -412,28 +424,28 @@ LayoutSize RenderBoxModelObject::relativePositionOffset() const
// See <https://bugs.webkit.org/show_bug.cgi?id=26396>.
// Another exception is a grid item, as the containing block is the grid area:
// https://drafts.csswg.org/css-grid/#grid-item-sizing
if (!style().top().isAuto()
&& (!style().top().isPercentOrCalculated()
|| !containingBlock()->hasAutoHeightOrContainingBlockWithAutoHeight()
|| containingBlock()->stretchesToViewport()
|| hasOverridingContainingBlockContentHeight())) {
auto& top = style.top();
auto& bottom = style.bottom();
if (top.isAuto() && bottom.isAuto())
return offset;

auto hasOverridingContainingBlockContentHeight = [&] {
auto* renderBox = dynamicDowncast<RenderBox>(*this);
return renderBox && renderBox->hasOverridingContainingBlockContentHeight();
}();
auto containingBlockHasDefiniteHeight = !containingBlock.hasAutoHeightOrContainingBlockWithAutoHeight() || containingBlock.stretchesToViewport() || hasOverridingContainingBlockContentHeight;
auto containingBlockContentHeight = [&] {
return hasOverridingContainingBlockContentHeight ? downcast<RenderBox>(*this).overridingContainingBlockContentHeight().value_or(0_lu) : containingBlock.availableHeight();
};
if (!top.isAuto() && (!top.isPercentOrCalculated() || containingBlockHasDefiniteHeight)) {
// FIXME: The computation of the available height is repeated later for "bottom".
// We could refactor this and move it to some common code for both ifs, however moving it outside of the ifs
// is not possible as it'd cause performance regressions.
offset.expand(0_lu, valueForLength(style().top(), !style().top().isFixed()
? (hasOverridingContainingBlockContentHeight() ? overridingContainingBlockContentHeight().value_or(0_lu) : containingBlock()->availableHeight())
: LayoutUnit()));
} else if (!style().bottom().isAuto()
&& (!style().bottom().isPercentOrCalculated()
|| !containingBlock()->hasAutoHeightOrContainingBlockWithAutoHeight()
|| containingBlock()->stretchesToViewport()
|| hasOverridingContainingBlockContentHeight())) {
offset.expand(0_lu, valueForLength(top, containingBlockContentHeight()));
} else if (!bottom.isAuto() && (!bottom.isPercentOrCalculated() || containingBlockHasDefiniteHeight)) {
// FIXME: Check comment above for "top", it applies here too.
offset.expand(0_lu, -valueForLength(style().bottom(), !style().bottom().isFixed()
? (hasOverridingContainingBlockContentHeight() ? overridingContainingBlockContentHeight().value_or(0_lu) : containingBlock()->availableHeight())
: LayoutUnit()));
offset.expand(0_lu, -valueForLength(bottom, containingBlockContentHeight()));
}

return offset;
}

Expand Down
5 changes: 0 additions & 5 deletions Source/WebCore/rendering/RenderBoxModelObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,11 +209,6 @@ class RenderBoxModelObject : public RenderLayerModelObject {

bool hasRunningAcceleratedAnimations() const;

virtual std::optional<LayoutUnit> overridingContainingBlockContentWidth() const { ASSERT_NOT_REACHED(); return -1_lu; }
virtual std::optional<LayoutUnit> overridingContainingBlockContentHeight() const { ASSERT_NOT_REACHED(); return -1_lu; }
virtual bool hasOverridingContainingBlockContentWidth() const { return false; }
virtual bool hasOverridingContainingBlockContentHeight() const { return false; }

void applyTransform(TransformationMatrix&, const RenderStyle&, const FloatRect& boundingBox, OptionSet<RenderStyle::TransformOperationOption>) const override;

protected:
Expand Down

0 comments on commit e2ab34f

Please sign in to comment.