Bug 64479
| Summary: | RenderObject::containingBlock is a const method but it returns a non-const object | ||
|---|---|---|---|
| Product: | WebKit | Reporter: | Julien Chaffraix <jchaffraix> |
| Component: | Layout and Rendering | Assignee: | Nobody <webkit-unassigned> |
| Status: | RESOLVED WONTFIX | ||
| Severity: | Enhancement | CC: | ahmad.saleem792, darin, simon.fraser, zalan |
| Priority: | P4 | ||
| Version: | 528+ (Nightly build) | ||
| Hardware: | All | ||
| OS: | All | ||
Julien Chaffraix
See https://bugs.webkit.org/show_bug.cgi?id=64318#c2
This leads to ugly code like the following:
RenderBlock* RenderView::containingBlock() const
{
return const_cast<RenderView*>(this);
}
Also it is a violation of const-ness.
| Attachments | ||
|---|---|---|
| Add attachment proposed patch, testcase, etc. |
Ahmad Saleem
https://searchfox.org/wubkat/source/Source/WebCore/rendering/RenderObject.cpp#727
^ Anything else needed here?
RenderBlock* RenderObject::containingBlock() const
{
if (is<RenderText>(*this))
return containingBlockForPositionType(PositionType::Static, *this);
auto containingBlockForRenderer = [](const auto& renderer) -> RenderBlock* {
if (isInTopLayerOrBackdrop(renderer.style(), renderer.element()))
return &renderer.view();
return containingBlockForPositionType(renderer.style().position(), renderer);
};
if (!parent() && is<RenderScrollbarPart>(*this)) {
if (auto* scrollbarPart = downcast<RenderScrollbarPart>(*this).rendererOwningScrollbar())
return containingBlockForRenderer(*scrollbarPart);
return nullptr;
}
return containingBlockForRenderer(downcast<RenderElement>(*this));
}
Darin Adler
I am not sure this should be changed. The exact meaning of const for pointers into a tree and tree traversal is unclear to me and I definitely don’t want to create two of each tree traversal function. Many, many other functions like Node::parent and Node::document also work this way. I don’t agree with the premise of this bug report.
alan
(In reply to Darin Adler from comment #2)
> I am not sure this should be changed. The exact meaning of const for
> pointers into a tree and tree traversal is unclear to me and I definitely
> don’t want to create two of each tree traversal function. Many, many other
> functions like Node::parent and Node::document also work this way. I don’t
> agree with the premise of this bug report.
I agree. I don't think we should change this. (Though in LFC we managed to achieve const correctness but we did it by turning the layout tree (render tree) immutable as a whole)