Skip to content

Commit

Permalink
Use more smart pointers in RenderView
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=261479

Reviewed by Alan Baradlay.

* Source/WebCore/page/scrolling/ScrollSnapOffsetsInfo.cpp:
(WebCore::updateSnapOffsetsForScrollableArea):
* Source/WebCore/rendering/RenderView.cpp:
(WebCore::RenderView::scheduleLazyRepaint):
(WebCore::RenderView::unscheduleLazyRepaint):
(WebCore::RenderView::lazyRepaintTimerFired):
(WebCore::RenderView::registerForVisibleInViewportCallback):
(WebCore::RenderView::unregisterForVisibleInViewportCallback):
(WebCore::RenderView::updateVisibleViewportRect):
(WebCore::RenderView::addRendererWithPausedImageAnimations):
(WebCore::RenderView::removeRendererWithPausedImageAnimations):
(WebCore::RenderView::resumePausedImageAnimationsIfNeeded):
(WebCore::RenderView::registerBoxWithScrollSnapPositions):
(WebCore::RenderView::unregisterBoxWithScrollSnapPositions):
* Source/WebCore/rendering/RenderView.h:

Canonical link: https://commits.webkit.org/267929@main
  • Loading branch information
cdumez committed Sep 13, 2023
1 parent d65ae5e commit a173bc8
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 46 deletions.
22 changes: 11 additions & 11 deletions Source/WebCore/page/scrolling/ScrollSnapOffsetsInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ void updateSnapOffsetsForScrollableArea(ScrollableArea& scrollableArea, const Re
{
auto scrollSnapType = scrollingElementStyle.scrollSnapType();
const auto& boxesWithScrollSnapPositions = scrollingElementBox.view().boxesWithScrollSnapPositions();
if (scrollSnapType.strictness == ScrollSnapStrictness::None || boxesWithScrollSnapPositions.isEmpty()) {
if (scrollSnapType.strictness == ScrollSnapStrictness::None || boxesWithScrollSnapPositions.isEmptyIgnoringNullReferences()) {
scrollableArea.clearSnapOffsets();
return;
}
Expand Down Expand Up @@ -346,34 +346,34 @@ void updateSnapOffsetsForScrollableArea(ScrollableArea& scrollableArea, const Re
// The bounds of the scrolling container's snap port, where the top left of the scrolling container's border box is the origin.
auto scrollSnapPort = computeScrollSnapPortOrAreaRect(viewportRectInBorderBoxCoordinates, scrollingElementStyle.scrollPadding(), InsetOrOutset::Inset);
LOG_WITH_STREAM(ScrollSnap, stream << "Computing scroll snap offsets for " << scrollableArea << " in snap port " << scrollSnapPort);
for (auto* child : boxesWithScrollSnapPositions) {
if (child->enclosingScrollableContainerForSnapping() != &scrollingElementBox)
for (auto& child : boxesWithScrollSnapPositions) {
if (child.enclosingScrollableContainerForSnapping() != &scrollingElementBox)
continue;

// The bounds of the child element's snap area, where the top left of the scrolling container's border box is the origin.
// The snap area is the bounding box of the child element's border box, after applying transformations.
OptionSet<MapCoordinatesMode> options = { UseTransforms, IgnoreStickyOffsets };
auto scrollSnapArea = LayoutRect(child->localToContainerQuad(FloatQuad(child->borderBoundingBox()), &scrollingElementBox, options).boundingBox());
auto scrollSnapArea = LayoutRect(child.localToContainerQuad(FloatQuad(child.borderBoundingBox()), &scrollingElementBox, options).boundingBox());

// localToContainerQuad will transform the scroll snap area by the scroll position, except in the case that this position is
// coming from a ScrollView. We want the transformed area, but without scroll position taken into account.
if (!scrollableArea.isScrollView())
scrollSnapArea.moveBy(scrollPosition);

scrollSnapArea = computeScrollSnapPortOrAreaRect(scrollSnapArea, child->style().scrollMargin(), InsetOrOutset::Outset);
scrollSnapArea = computeScrollSnapPortOrAreaRect(scrollSnapArea, child.style().scrollMargin(), InsetOrOutset::Outset);
LOG_WITH_STREAM(ScrollSnap, stream << " Considering scroll snap target area " << scrollSnapArea);
auto alignment = child->style().scrollSnapAlign();
auto stop = child->style().scrollSnapStop();
auto alignment = child.style().scrollSnapAlign();
auto stop = child.style().scrollSnapStop();

// From https://drafts.csswg.org/css-scroll-snap-1/#scroll-snap-align:
// "Start and end alignments are resolved with respect to the writing mode of the snap container unless the
// scroll snap area is larger than the snapport, in which case they are resolved with respect to the writing
// mode of the box itself."
bool areaXAxisFlipped = scrollerXAxisFlipped;
bool areaYAxisFlipped = scrollerYAxisFlipped;
bool areaHasVerticalWritingMode = isVerticalWritingMode(child->style().writingMode());
bool areaHasVerticalWritingMode = isVerticalWritingMode(child.style().writingMode());
if ((areaHasVerticalWritingMode && scrollSnapArea.height() > scrollSnapPort.height()) || (!areaHasVerticalWritingMode && scrollSnapArea.width() > scrollSnapPort.width()))
std::tie(areaXAxisFlipped, areaYAxisFlipped) = axesFlippedForWritingModeAndDirection(child->style().writingMode(), child->style().direction());
std::tie(areaXAxisFlipped, areaYAxisFlipped) = axesFlippedForWritingModeAndDirection(child.style().writingMode(), child.style().direction());

ScrollSnapAxisAlignType xAlign = scrollerHasVerticalWritingMode ? alignment.blockAlign : alignment.inlineAlign;
ScrollSnapAxisAlignType yAlign = scrollerHasVerticalWritingMode ? alignment.inlineAlign : alignment.blockAlign;
Expand All @@ -387,8 +387,8 @@ void updateSnapOffsetsForScrollableArea(ScrollableArea& scrollableArea, const Re
LayoutRect scrollSnapAreaAsOffsets(scrollableArea.scrollOffsetFromPosition(roundedIntPoint(snapAreaOriginRelativeToBorderEdge)), scrollSnapArea.size());
snapAreas.append(scrollSnapAreaAsOffsets);

auto isFocused = child->element() ? focusedElement == child->element() : false;
auto identifier = child->element() ? child->element()->identifier() : ObjectIdentifier<ElementIdentifierType>(0);
auto isFocused = child.element() ? focusedElement == child.element() : false;
auto identifier = child.element() ? child.element()->identifier() : ObjectIdentifier<ElementIdentifierType>(0);
snapAreasIDs.append(identifier);
if (snapsHorizontally) {
auto absoluteScrollXPosition = computeScrollSnapAlignOffset(scrollSnapArea.x(), scrollSnapArea.maxX(), xAlign, areaXAxisFlipped) - computeScrollSnapAlignOffset(scrollSnapPort.x(), scrollSnapPort.maxX(), xAlign, areaXAxisFlipped);
Expand Down
60 changes: 30 additions & 30 deletions Source/WebCore/rendering/RenderView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ void RenderView::scheduleLazyRepaint(RenderBox& renderer)
if (renderer.renderBoxNeedsLazyRepaint())
return;
renderer.setRenderBoxNeedsLazyRepaint(true);
m_renderersNeedingLazyRepaint.add(&renderer);
m_renderersNeedingLazyRepaint.add(renderer);
if (!m_lazyRepaintTimer.isActive())
m_lazyRepaintTimer.startOneShot(0_s);
}
Expand All @@ -136,16 +136,16 @@ void RenderView::unscheduleLazyRepaint(RenderBox& renderer)
if (!renderer.renderBoxNeedsLazyRepaint())
return;
renderer.setRenderBoxNeedsLazyRepaint(false);
m_renderersNeedingLazyRepaint.remove(&renderer);
if (m_renderersNeedingLazyRepaint.isEmpty())
m_renderersNeedingLazyRepaint.remove(renderer);
if (m_renderersNeedingLazyRepaint.isEmptyIgnoringNullReferences())
m_lazyRepaintTimer.stop();
}

void RenderView::lazyRepaintTimerFired()
{
for (auto& renderer : m_renderersNeedingLazyRepaint) {
renderer->repaint();
renderer->setRenderBoxNeedsLazyRepaint(false);
renderer.repaint();
renderer.setRenderBoxNeedsLazyRepaint(false);
}
m_renderersNeedingLazyRepaint.clear();
}
Expand Down Expand Up @@ -854,52 +854,52 @@ ImageQualityController& RenderView::imageQualityController()

void RenderView::registerForVisibleInViewportCallback(RenderElement& renderer)
{
ASSERT(!m_visibleInViewportRenderers.contains(&renderer));
m_visibleInViewportRenderers.add(&renderer);
ASSERT(!m_visibleInViewportRenderers.contains(renderer));
m_visibleInViewportRenderers.add(renderer);
}

void RenderView::unregisterForVisibleInViewportCallback(RenderElement& renderer)
{
ASSERT(m_visibleInViewportRenderers.contains(&renderer));
m_visibleInViewportRenderers.remove(&renderer);
ASSERT(m_visibleInViewportRenderers.contains(renderer));
m_visibleInViewportRenderers.remove(renderer);
}

void RenderView::updateVisibleViewportRect(const IntRect& visibleRect)
{
resumePausedImageAnimationsIfNeeded(visibleRect);

for (auto* renderer : m_visibleInViewportRenderers) {
auto state = visibleRect.intersects(enclosingIntRect(renderer->absoluteClippedOverflowRectForRepaint())) ? VisibleInViewportState::Yes : VisibleInViewportState::No;
renderer->setVisibleInViewportState(state);
for (auto& renderer : m_visibleInViewportRenderers) {
auto state = visibleRect.intersects(enclosingIntRect(renderer.absoluteClippedOverflowRectForRepaint())) ? VisibleInViewportState::Yes : VisibleInViewportState::No;
renderer.setVisibleInViewportState(state);
}
}

void RenderView::addRendererWithPausedImageAnimations(RenderElement& renderer, CachedImage& image)
{
ASSERT(!renderer.hasPausedImageAnimations() || m_renderersWithPausedImageAnimation.contains(&renderer));
ASSERT(!renderer.hasPausedImageAnimations() || m_renderersWithPausedImageAnimation.contains(renderer));

renderer.setHasPausedImageAnimations(true);
auto& images = m_renderersWithPausedImageAnimation.ensure(&renderer, [] {
return Vector<CachedImage*>();
auto& images = m_renderersWithPausedImageAnimation.ensure(renderer, [] {
return Vector<WeakPtr<CachedImage>>();
}).iterator->value;
if (!images.contains(&image))
images.append(&image);
images.append(image);
}

void RenderView::removeRendererWithPausedImageAnimations(RenderElement& renderer)
{
ASSERT(renderer.hasPausedImageAnimations());
ASSERT(m_renderersWithPausedImageAnimation.contains(&renderer));
ASSERT(m_renderersWithPausedImageAnimation.contains(renderer));

renderer.setHasPausedImageAnimations(false);
m_renderersWithPausedImageAnimation.remove(&renderer);
m_renderersWithPausedImageAnimation.remove(renderer);
}

void RenderView::removeRendererWithPausedImageAnimations(RenderElement& renderer, CachedImage& image)
{
ASSERT(renderer.hasPausedImageAnimations());

auto it = m_renderersWithPausedImageAnimation.find(&renderer);
auto it = m_renderersWithPausedImageAnimation.find(renderer);
ASSERT(it != m_renderersWithPausedImageAnimation.end());

auto& images = it->value;
Expand All @@ -914,24 +914,24 @@ void RenderView::removeRendererWithPausedImageAnimations(RenderElement& renderer

void RenderView::resumePausedImageAnimationsIfNeeded(const IntRect& visibleRect)
{
Vector<std::pair<RenderElement*, CachedImage*>, 10> toRemove;
for (auto& it : m_renderersWithPausedImageAnimation) {
auto* renderer = it.key;
for (auto* image : it.value) {
if (renderer->repaintForPausedImageAnimationsIfNeeded(visibleRect, *image))
toRemove.append(std::make_pair(renderer, image));
Vector<std::pair<WeakPtr<RenderElement>, WeakPtr<CachedImage>>, 10> toRemove;
for (auto it : m_renderersWithPausedImageAnimation) {
auto& renderer = it.key;
for (auto& image : it.value) {
if (renderer.repaintForPausedImageAnimationsIfNeeded(visibleRect, *image))
toRemove.append({ renderer, image });
}
}
for (auto& pair : toRemove)
removeRendererWithPausedImageAnimations(*pair.first, *pair.second);

Vector<SVGSVGElement*> svgSvgElementsToRemove;
Vector<Ref<SVGSVGElement>> svgSvgElementsToRemove;
m_SVGSVGElementsWithPausedImageAnimation.forEach([&] (WeakPtr<SVGSVGElement, WeakPtrImplWithEventTargetData> svgSvgElement) {
if (svgSvgElement && svgSvgElement->resumePausedAnimationsIfNeeded(visibleRect))
svgSvgElementsToRemove.append(svgSvgElement.get());
svgSvgElementsToRemove.append(*svgSvgElement);
});
for (auto& svgSvgElement : svgSvgElementsToRemove)
m_SVGSVGElementsWithPausedImageAnimation.remove(*svgSvgElement);
m_SVGSVGElementsWithPausedImageAnimation.remove(svgSvgElement.get());
}

#if ENABLE(ACCESSIBILITY_ANIMATION_CONTROL)
Expand Down Expand Up @@ -1092,12 +1092,12 @@ RenderLayer* RenderView::takeStyleChangeLayerTreeMutationRoot()

void RenderView::registerBoxWithScrollSnapPositions(const RenderBox& box)
{
m_boxesWithScrollSnapPositions.add(&box);
m_boxesWithScrollSnapPositions.add(box);
}

void RenderView::unregisterBoxWithScrollSnapPositions(const RenderBox& box)
{
m_boxesWithScrollSnapPositions.remove(&box);
m_boxesWithScrollSnapPositions.remove(box);
}

void RenderView::registerContainerQueryBox(const RenderBox& box)
Expand Down
10 changes: 5 additions & 5 deletions Source/WebCore/rendering/RenderView.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ class RenderView final : public RenderBlockFlow {

void registerBoxWithScrollSnapPositions(const RenderBox&);
void unregisterBoxWithScrollSnapPositions(const RenderBox&);
const HashSet<const RenderBox*>& boxesWithScrollSnapPositions() { return m_boxesWithScrollSnapPositions; }
const WeakHashSet<const RenderBox>& boxesWithScrollSnapPositions() { return m_boxesWithScrollSnapPositions; }

void registerContainerQueryBox(const RenderBox&);
void unregisterContainerQueryBox(const RenderBox&);
Expand Down Expand Up @@ -261,7 +261,7 @@ class RenderView final : public RenderBlockFlow {
void lazyRepaintTimerFired();

Timer m_lazyRepaintTimer;
HashSet<RenderBox*> m_renderersNeedingLazyRepaint;
WeakHashSet<RenderBox> m_renderersNeedingLazyRepaint;

std::unique_ptr<ImageQualityController> m_imageQualityController;
std::optional<LayoutSize> m_pageLogicalSize;
Expand All @@ -278,11 +278,11 @@ class RenderView final : public RenderBlockFlow {
bool m_needsRepaintHackAfterCompositingLayerUpdateForDebugOverlaysOnly { false };
bool m_needsEventRegionUpdateForNonCompositedFrame { false };

HashMap<RenderElement*, Vector<CachedImage*>> m_renderersWithPausedImageAnimation;
WeakHashMap<RenderElement, Vector<WeakPtr<CachedImage>>> m_renderersWithPausedImageAnimation;
WeakHashSet<SVGSVGElement, WeakPtrImplWithEventTargetData> m_SVGSVGElementsWithPausedImageAnimation;
HashSet<RenderElement*> m_visibleInViewportRenderers;
WeakHashSet<RenderElement> m_visibleInViewportRenderers;

HashSet<const RenderBox*> m_boxesWithScrollSnapPositions;
WeakHashSet<const RenderBox> m_boxesWithScrollSnapPositions;
WeakHashSet<const RenderBox> m_containerQueryBoxes;
};

Expand Down

0 comments on commit a173bc8

Please sign in to comment.