RESOLVED WONTFIX 64479
RenderObject::containingBlock is a const method but it returns a non-const object
https://bugs.webkit.org/show_bug.cgi?id=64479
Summary RenderObject::containingBlock is a const method but it returns a non-const ob...
Julien Chaffraix
Reported 2011-07-13 12:40:29 PDT
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
Ahmad Saleem
Comment 1 2023-05-07 04:06:53 PDT
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
Comment 2 2023-05-07 06:28:34 PDT
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.
zalan
Comment 3 2023-05-07 09:28:36 PDT
(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)
Note You need to log in before you can comment on or make changes to this bug.