| File: | Volumes/Data/worker/Apple-iOS-26-Safer-CPP-Checks-EWS/build/Source/WebCore/rendering/RenderScrollbarPart.cpp |
| Warning: | line 155, column 55 Call argument for 'this' parameter is unchecked and unsafe |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
| 1 | /* |
| 2 | * Copyright (C) 2008-2025 Apple Inc. All rights reserved. |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions |
| 6 | * are met: |
| 7 | * 1. Redistributions of source code must retain the above copyright |
| 8 | * notice, this list of conditions and the following disclaimer. |
| 9 | * 2. Redistributions in binary form must reproduce the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer in the |
| 11 | * documentation and/or other materials provided with the distribution. |
| 12 | * |
| 13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
| 14 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
| 17 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 18 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 19 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 20 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 21 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 | */ |
| 25 | |
| 26 | #include "config.h" |
| 27 | #include "RenderScrollbarPart.h" |
| 28 | |
| 29 | #include "PaintInfo.h" |
| 30 | #include "RenderBoxInlines.h" |
| 31 | #include "RenderBoxModelObjectInlines.h" |
| 32 | #include "RenderScrollbar.h" |
| 33 | #include "RenderScrollbarTheme.h" |
| 34 | #include "RenderStyle+GettersInlines.h" |
| 35 | #include "RenderView.h" |
| 36 | #include <wtf/StackStats.h> |
| 37 | #include <wtf/TZoneMallocInlines.h> |
| 38 | |
| 39 | namespace WebCore { |
| 40 | |
| 41 | WTF_MAKE_TZONE_ALLOCATED_IMPL(RenderScrollbarPart)::bmalloc::api::HeapRef RenderScrollbarPart::s_heapRef; const TZoneSpecification RenderScrollbarPart::s_heapSpec = { & RenderScrollbarPart::s_heapRef, TZoneSpecification::encodeSize <RenderScrollbarPart>(), TZoneSpecification::encodeAlignment <RenderScrollbarPart>(), TZoneSpecification::encodeCategory <RenderScrollbarPart>(), ::bmalloc::api::compactAllocationMode <RenderScrollbarPart>(), TZoneSpecification::encodeDescriptor <RenderScrollbarPart>(), }; void* RenderScrollbarPart:: operatorNewSlow(size_t size) { if constexpr (::bmalloc::api:: compactAllocationMode<RenderScrollbarPart>() == CompactAllocationMode ::Compact) return ::bmalloc::api::tzoneAllocateCompactSlow(size , s_heapSpec); return ::bmalloc::api::tzoneAllocateNonCompactSlow (size, s_heapSpec); } using __makeBtzoneMallocedInlineMacroSemicolonifier __attribute__((unused)) = int; |
| 42 | |
| 43 | RenderScrollbarPart::RenderScrollbarPart(Document& document, RenderStyle&& style, RenderScrollbar* scrollbar, ScrollbarPart part) |
| 44 | : RenderBlock(Type::ScrollbarPart, document, WTF::move(style), { }) |
| 45 | , m_scrollbar(scrollbar) |
| 46 | , m_part(part) |
| 47 | { |
| 48 | ASSERT(isRenderScrollbarPart())((void)0); |
| 49 | } |
| 50 | |
| 51 | RenderScrollbarPart::~RenderScrollbarPart() = default; |
| 52 | |
| 53 | void RenderScrollbarPart::layout() |
| 54 | { |
| 55 | StackStats::LayoutCheckPoint layoutCheckPoint; |
| 56 | setLocation(LayoutPoint()); // We don't worry about positioning ourselves. We're just determining our minimum width/height. |
| 57 | if (m_scrollbar->orientation() == ScrollbarOrientation::Horizontal) |
| 58 | layoutHorizontalPart(); |
| 59 | else |
| 60 | layoutVerticalPart(); |
| 61 | |
| 62 | clearNeedsLayout(); |
| 63 | } |
| 64 | |
| 65 | void RenderScrollbarPart::layoutHorizontalPart() |
| 66 | { |
| 67 | if (m_part == ScrollbarBGPart) { |
| 68 | setWidth(m_scrollbar->width()); |
| 69 | computeScrollbarHeight(); |
| 70 | } else { |
| 71 | computeScrollbarWidth(); |
| 72 | setHeight(m_scrollbar->height()); |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | void RenderScrollbarPart::layoutVerticalPart() |
| 77 | { |
| 78 | if (m_part == ScrollbarBGPart) { |
| 79 | computeScrollbarWidth(); |
| 80 | setHeight(m_scrollbar->height()); |
| 81 | } else { |
| 82 | setWidth(m_scrollbar->width()); |
| 83 | computeScrollbarHeight(); |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | static int calcScrollbarThicknessUsing(const Style::PreferredSize& preferredSize, Style::ZoomFactor zoomFactor) |
| 88 | { |
| 89 | if (preferredSize.isFixed()) |
| 90 | return Style::evaluateMinimum<LayoutUnit>(preferredSize, 0_lu, zoomFactor); |
| 91 | return ScrollbarTheme::theme().scrollbarThickness(); |
| 92 | } |
| 93 | |
| 94 | static int calcScrollbarThicknessUsing(const Style::MinimumSize& minimumSize, Style::ZoomFactor zoomFactor) |
| 95 | { |
| 96 | if (minimumSize.isFixed() || minimumSize.isAuto()) |
| 97 | return Style::evaluateMinimum<LayoutUnit>(minimumSize, 0_lu, zoomFactor); |
| 98 | return ScrollbarTheme::theme().scrollbarThickness(); |
| 99 | } |
| 100 | |
| 101 | static int calcScrollbarThicknessUsing(const Style::MaximumSize& maximumSize, Style::ZoomFactor zoomFactor) |
| 102 | { |
| 103 | if (maximumSize.isFixed()) |
| 104 | return Style::evaluateMinimum<LayoutUnit>(maximumSize, 0_lu, zoomFactor); |
| 105 | return ScrollbarTheme::theme().scrollbarThickness(); |
| 106 | } |
| 107 | |
| 108 | void RenderScrollbarPart::computeScrollbarWidth() |
| 109 | { |
| 110 | if (!m_scrollbar->owningRenderer()) |
| 111 | return; |
| 112 | auto zoomFactor = style().usedZoomForLength(); |
| 113 | auto width = calcScrollbarThicknessUsing(style().width(), zoomFactor); |
| 114 | auto minWidth = calcScrollbarThicknessUsing(style().minWidth(), zoomFactor); |
| 115 | auto maxWidth = style().maxWidth().isNone() ? width : calcScrollbarThicknessUsing(style().maxWidth(), zoomFactor); |
| 116 | setWidth(std::max(minWidth, std::min(maxWidth, width))); |
| 117 | |
| 118 | // Buttons and track pieces can all have margins along the axis of the scrollbar. |
| 119 | m_marginBox.setLeft(Style::evaluateMinimum<LayoutUnit>(style().marginLeft(), 0_lu, style().usedZoomForLength())); |
| 120 | m_marginBox.setRight(Style::evaluateMinimum<LayoutUnit>(style().marginRight(), 0_lu, style().usedZoomForLength())); |
| 121 | } |
| 122 | |
| 123 | void RenderScrollbarPart::computeScrollbarHeight() |
| 124 | { |
| 125 | if (!m_scrollbar->owningRenderer()) |
| 126 | return; |
| 127 | auto zoomFactor = style().usedZoomForLength(); |
| 128 | auto height = calcScrollbarThicknessUsing(style().height(), zoomFactor); |
| 129 | auto minHeight = calcScrollbarThicknessUsing(style().minHeight(), zoomFactor); |
| 130 | auto maxHeight = style().maxHeight().isNone() ? height : calcScrollbarThicknessUsing(style().maxHeight(), zoomFactor); |
| 131 | setHeight(std::max(minHeight, std::min(maxHeight, height))); |
| 132 | |
| 133 | // Buttons and track pieces can all have margins along the axis of the scrollbar. |
| 134 | m_marginBox.setTop(Style::evaluateMinimum<LayoutUnit>(style().marginTop(), 0_lu, style().usedZoomForLength())); |
| 135 | m_marginBox.setBottom(Style::evaluateMinimum<LayoutUnit>(style().marginBottom(), 0_lu, style().usedZoomForLength())); |
| 136 | } |
| 137 | |
| 138 | void RenderScrollbarPart::styleDidChange(Style::Difference diff, const RenderStyle* oldStyle) |
| 139 | { |
| 140 | RenderBlock::styleDidChange(diff, oldStyle); |
| 141 | setInline(false); |
| 142 | clearPositionedState(); |
| 143 | setFloating(false); |
| 144 | setHasNonVisibleOverflow(false); |
| 145 | if (oldStyle && m_scrollbar && m_part != NoPart && diff >= Style::DifferenceResult::Repaint) |
| 146 | m_scrollbar->theme().invalidatePart(*m_scrollbar, m_part); |
| 147 | } |
| 148 | |
| 149 | void RenderScrollbarPart::imageChanged(WrappedImagePtr image, const IntRect* rect) |
| 150 | { |
| 151 | if (m_scrollbar && m_part != NoPart) |
| 152 | m_scrollbar->theme().invalidatePart(*m_scrollbar, m_part); |
| 153 | else { |
| 154 | if (view().frameView().isFrameViewScrollCorner(*this)) { |
| 155 | view().frameView().invalidateScrollCorner(view().frameView().scrollCornerRect()); |
Call argument for 'this' parameter is unchecked and unsafe | |
| 156 | return; |
| 157 | } |
| 158 | |
| 159 | RenderBlock::imageChanged(image, rect); |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | void RenderScrollbarPart::paintIntoRect(GraphicsContext& graphicsContext, const LayoutPoint& paintOffset, const LayoutRect& rect) |
| 164 | { |
| 165 | // Make sure our dimensions match the rect. |
| 166 | setLocation(rect.location() - toLayoutSize(paintOffset)); |
| 167 | setWidth(rect.width()); |
| 168 | setHeight(rect.height()); |
| 169 | |
| 170 | if (graphicsContext.paintingDisabled() || style().opacity().isTransparent()) |
| 171 | return; |
| 172 | |
| 173 | // We don't use RenderLayers for scrollbar parts, so we need to handle opacity here. |
| 174 | // Opacity for ScrollbarBGPart is handled by RenderScrollbarTheme::willPaintScrollbar(). |
| 175 | bool needsTransparencyLayer = m_part != ScrollbarBGPart && !style().opacity().isOpaque(); |
| 176 | if (needsTransparencyLayer) { |
| 177 | graphicsContext.save(); |
| 178 | graphicsContext.clip(rect); |
| 179 | graphicsContext.beginTransparencyLayer(style().opacity().value.value); |
| 180 | } |
| 181 | |
| 182 | // Now do the paint. |
| 183 | PaintInfo paintInfo(graphicsContext, snappedIntRect(rect), PaintPhase::BlockBackground, PaintBehavior::Normal); |
| 184 | paint(paintInfo, paintOffset); |
| 185 | paintInfo.phase = PaintPhase::ChildBlockBackgrounds; |
| 186 | paint(paintInfo, paintOffset); |
| 187 | paintInfo.phase = PaintPhase::Float; |
| 188 | paint(paintInfo, paintOffset); |
| 189 | paintInfo.phase = PaintPhase::Foreground; |
| 190 | paint(paintInfo, paintOffset); |
| 191 | paintInfo.phase = PaintPhase::Outline; |
| 192 | paint(paintInfo, paintOffset); |
| 193 | |
| 194 | if (needsTransparencyLayer) { |
| 195 | graphicsContext.endTransparencyLayer(); |
| 196 | graphicsContext.restore(); |
| 197 | } |
| 198 | } |
| 199 | |
| 200 | RenderBox* RenderScrollbarPart::rendererOwningScrollbar() const |
| 201 | { |
| 202 | if (!m_scrollbar) |
| 203 | return nullptr; |
| 204 | return m_scrollbar->owningRenderer(); |
| 205 | } |
| 206 | |
| 207 | } |