| File: | Volumes/Data/worker/macOS-Safer-CPP-Checks-EWS/build/Source/WebCore/rendering/updating/RenderTreeBuilderList.cpp |
| Warning: | line 42, column 5 Member variable 'parent' in 'WebCore::LineBoxParentSearchResult' is a raw pointer to CheckedPtr capable type 'WebCore::RenderBlock'; member variables must be a CheckedPtr, CheckedRef, WeakRef, or WeakPtr |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
| 1 | /** |
| 2 | * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
| 3 | * (C) 1999 Antti Koivisto (koivisto@kde.org) |
| 4 | * Copyright (C) 2003-2025 Apple Inc. All rights reserved. |
| 5 | * Copyright (C) 2006 Andrew Wellington (proton@wiretapped.net) |
| 6 | * |
| 7 | * This library is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU Library General Public |
| 9 | * License as published by the Free Software Foundation; either |
| 10 | * version 2 of the License, or (at your option) any later version. |
| 11 | * |
| 12 | * This library is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * Library General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU Library General Public License |
| 18 | * along with this library; see the file COPYING.LIB. If not, write to |
| 19 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 20 | * Boston, MA 02110-1301, USA. |
| 21 | * |
| 22 | */ |
| 23 | |
| 24 | #include "config.h" |
| 25 | #include "RenderTreeBuilderList.h" |
| 26 | |
| 27 | #include "LegacyInlineIterator.h" |
| 28 | #include "LineInlineHeaders.h" |
| 29 | #include "RenderChildIterator.h" |
| 30 | #include "RenderListMarker.h" |
| 31 | #include "RenderMenuList.h" |
| 32 | #include "RenderMultiColumnFlow.h" |
| 33 | #include "RenderObjectStyle.h" |
| 34 | #include "RenderTable.h" |
| 35 | #include <wtf/TZoneMallocInlines.h> |
| 36 | |
| 37 | namespace WebCore { |
| 38 | |
| 39 | WTF_MAKE_TZONE_ALLOCATED_IMPL(RenderTreeBuilder::List)::bmalloc::api::HeapRef RenderTreeBuilder::List::s_heapRef; const TZoneSpecification RenderTreeBuilder::List::s_heapSpec = { & RenderTreeBuilder::List::s_heapRef, TZoneSpecification::encodeSize <RenderTreeBuilder::List>(), TZoneSpecification::encodeAlignment <RenderTreeBuilder::List>(), TZoneSpecification::encodeCategory <RenderTreeBuilder::List>(), ::bmalloc::api::compactAllocationMode <RenderTreeBuilder::List>(), TZoneSpecification::encodeDescriptor <RenderTreeBuilder::List>(), }; void* RenderTreeBuilder ::List::operatorNewSlow(size_t size) { if constexpr (::bmalloc ::api::compactAllocationMode<RenderTreeBuilder::List>() == CompactAllocationMode::Compact) return ::bmalloc::api::tzoneAllocateCompactSlow (size, s_heapSpec); return ::bmalloc::api::tzoneAllocateNonCompactSlow (size, s_heapSpec); } using __makeBtzoneMallocedInlineMacroSemicolonifier __attribute__((unused)) = int; |
| 40 | |
| 41 | struct LineBoxParentSearchResult { |
| 42 | RenderBlock* parent; |
Member variable 'parent' in 'WebCore::LineBoxParentSearchResult' is a raw pointer to CheckedPtr capable type 'WebCore::RenderBlock'; member variables must be a CheckedPtr, CheckedRef, WeakRef, or WeakPtr | |
| 43 | RenderBlock* fallbackParent; |
| 44 | bool failedDueToBlockification; |
| 45 | }; |
| 46 | |
| 47 | static LineBoxParentSearchResult findParentOfEmptyOrFirstLineBox(RenderBlock& blockContainer, const RenderListMarker& marker) |
| 48 | { |
| 49 | auto inQuirksMode = blockContainer.document().inQuirksMode(); |
| 50 | RenderBlock* fallbackParent = { }; |
| 51 | bool failedDueToBlockification = false; |
| 52 | |
| 53 | for (auto& child : childrenOfType<RenderObject>(blockContainer)) { |
| 54 | if (&child == &marker) |
| 55 | continue; |
| 56 | |
| 57 | if (child.isInline()) { |
| 58 | if (!is<RenderInline>(child) || !isEmptyInline(downcast<RenderInline>(child))) |
| 59 | return { &blockContainer, { }, false }; |
| 60 | fallbackParent = &blockContainer; |
| 61 | } |
| 62 | |
| 63 | if (child.isFloating() || child.isOutOfFlowPositioned() || is<RenderMenuList>(child)) |
| 64 | continue; |
| 65 | |
| 66 | if (auto* renderBox = dynamicDowncast<RenderBox>(child); renderBox && renderBox->isWritingModeRoot()) |
| 67 | break; |
| 68 | |
| 69 | if (is<RenderListItem>(blockContainer) && inQuirksMode && child.node() && isHTMLListElement(*child.node())) |
| 70 | break; |
| 71 | |
| 72 | if (!is<RenderBlock>(child) || is<RenderTable>(child)) { |
| 73 | if (!child.isInline() && child.style().originalDisplay().isInlineType()) |
| 74 | failedDueToBlockification = true; |
| 75 | break; |
| 76 | } |
| 77 | |
| 78 | auto& blockChild = downcast<RenderBlock>(child); |
| 79 | auto nestedResult = findParentOfEmptyOrFirstLineBox(blockChild, marker); |
| 80 | if (nestedResult.parent) |
| 81 | return { nestedResult.parent, { }, nestedResult.failedDueToBlockification }; |
| 82 | |
| 83 | failedDueToBlockification |= nestedResult.failedDueToBlockification; |
| 84 | if (!fallbackParent) { |
| 85 | if (nestedResult.fallbackParent) |
| 86 | fallbackParent = nestedResult.fallbackParent; |
| 87 | else if (auto* firstInFlowChild = blockChild.firstInFlowChild(); !firstInFlowChild || firstInFlowChild == &marker) |
| 88 | fallbackParent = &blockChild; |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | return { { }, fallbackParent, failedDueToBlockification }; |
| 93 | } |
| 94 | |
| 95 | struct MarkerParentSearchResult { |
| 96 | RenderBlock* parent; |
| 97 | bool failedDueToBlockification; |
| 98 | }; |
| 99 | |
| 100 | static MarkerParentSearchResult parentCandidateForMarker(RenderListItem& listItemRenderer, const RenderListMarker& marker) |
| 101 | { |
| 102 | if (marker.isInside()) { |
| 103 | if (auto* firstChild = dynamicDowncast<RenderBlock>(listItemRenderer.firstChild())) { |
| 104 | if (!firstChild->isAnonymous()) |
| 105 | return { &listItemRenderer, false }; |
| 106 | // We may have created this anonymous block for the marker itself. Let's keep it in there. |
| 107 | if (firstChild->firstChild() == &marker && !marker.nextSibling()) |
| 108 | return { firstChild, false }; |
| 109 | } |
| 110 | auto result = findParentOfEmptyOrFirstLineBox(listItemRenderer, marker); |
| 111 | return { result.parent, result.failedDueToBlockification }; |
| 112 | } |
| 113 | auto result = findParentOfEmptyOrFirstLineBox(listItemRenderer, marker); |
| 114 | return { result.parent ? result.parent : result.fallbackParent, result.failedDueToBlockification }; |
| 115 | } |
| 116 | |
| 117 | static RenderObject* firstNonMarkerChild(RenderBlock& parent) |
| 118 | { |
| 119 | RenderObject* child = parent.firstChild(); |
| 120 | while (is<RenderListMarker>(child)) |
| 121 | child = child->nextSibling(); |
| 122 | return child; |
| 123 | } |
| 124 | |
| 125 | RenderTreeBuilder::List::List(RenderTreeBuilder& builder) |
| 126 | : m_builder(builder) |
| 127 | { |
| 128 | } |
| 129 | |
| 130 | void RenderTreeBuilder::List::updateItemMarker(RenderListItem& listItemRenderer) |
| 131 | { |
| 132 | auto& style = listItemRenderer.style(); |
| 133 | |
| 134 | if (listItemRenderer.element() && listItemRenderer.element()->hasTagName(HTMLNames::fieldsetTag)) { |
| 135 | if (auto* marker = listItemRenderer.markerRenderer()) |
| 136 | m_builder.destroy(*marker); |
| 137 | return; |
| 138 | } |
| 139 | |
| 140 | if (RefPtr styleImage = style.listStyleImage().tryStyleImage(); style.listStyleType().isNone() && (!styleImage || styleImage->errorOccurred())) { |
| 141 | if (auto* marker = listItemRenderer.markerRenderer()) |
| 142 | m_builder.destroy(*marker); |
| 143 | return; |
| 144 | } |
| 145 | |
| 146 | auto newStyle = listItemRenderer.computeMarkerStyle(); |
| 147 | if (auto* markerRenderer = listItemRenderer.markerRenderer()) { |
| 148 | markerRenderer->setStyle(WTF::move(newStyle)); |
| 149 | auto* currentParent = markerRenderer->parent(); |
| 150 | if (!currentParent) { |
| 151 | ASSERT_NOT_REACHED()((void)0); |
| 152 | return; |
| 153 | } |
| 154 | |
| 155 | auto searchResult = parentCandidateForMarker(listItemRenderer, *markerRenderer); |
| 156 | if (!searchResult.parent) { |
| 157 | if (currentParent->isAnonymousBlock()) { |
| 158 | // For outside markers, if the search failed because a flex/grid container blockified a replaced |
| 159 | // child (e.g., <img>), we should collapse the anonymous block's height so it doesn't inflate the list item. |
| 160 | auto shouldCollapseAnonymousBlockParent = !markerRenderer->isInside() && searchResult.failedDueToBlockification; |
| 161 | markerRenderer->setShouldCollapseAnonymousBlockParent(shouldCollapseAnonymousBlockParent); |
| 162 | // If the marker is currently contained inside an anonymous box, we are the only item in that anonymous box |
| 163 | // since no line box parent was found. It's ok to just leave the marker where it is in this case. |
| 164 | return; |
| 165 | } |
| 166 | searchResult.parent = &listItemRenderer; |
| 167 | if (auto* multiColumnFlow = listItemRenderer.multiColumnFlow()) |
| 168 | searchResult.parent = multiColumnFlow; |
| 169 | } |
| 170 | |
| 171 | if (searchResult.parent == currentParent) |
| 172 | return; |
| 173 | |
| 174 | m_builder.attach(*searchResult.parent, m_builder.detach(*currentParent, *markerRenderer, WillBeDestroyed::No, RenderTreeBuilder::CanCollapseAnonymousBlock::No), firstNonMarkerChild(*searchResult.parent)); |
| 175 | // If current parent is an anonymous block that has lost all its children, destroy it. |
| 176 | if (currentParent->isAnonymousBlock() && !currentParent->firstChild() && !downcast<RenderBlock>(*currentParent).continuation()) |
| 177 | m_builder.destroy(*currentParent); |
| 178 | return; |
| 179 | } |
| 180 | |
| 181 | RenderPtr<RenderListMarker> newMarkerRenderer = WebCore::createRenderer<RenderListMarker>(listItemRenderer, WTF::move(newStyle)); |
| 182 | newMarkerRenderer->initializeStyle(); |
| 183 | listItemRenderer.setMarkerRenderer(*newMarkerRenderer); |
| 184 | auto searchResult = parentCandidateForMarker(listItemRenderer, *newMarkerRenderer); |
| 185 | if (!searchResult.parent) { |
| 186 | // For outside markers, if the search failed because a flex/grid container blockified a replaced |
| 187 | // child (e.g., <img>), we should collapse the anonymous block's height so it doesn't inflate the list item. |
| 188 | auto shouldCollapseAnonymousBlockParent = !newMarkerRenderer->isInside() && searchResult.failedDueToBlockification; |
| 189 | listItemRenderer.markerRenderer()->setShouldCollapseAnonymousBlockParent(shouldCollapseAnonymousBlockParent); |
| 190 | searchResult.parent = &listItemRenderer; |
| 191 | if (auto* multiColumnFlow = listItemRenderer.multiColumnFlow()) |
| 192 | searchResult.parent = multiColumnFlow; |
| 193 | } |
| 194 | m_builder.attach(*searchResult.parent, WTF::move(newMarkerRenderer), firstNonMarkerChild(*searchResult.parent)); |
| 195 | } |
| 196 | |
| 197 | } |