[webkit-changes] [WebKit/WebKit] 13f0d2: Avoid forced layouts because of scrollTo(0, 0) if t...
Simon Fraser
noreply at github.com
Tue Dec 12 10:41:57 PST 2023
Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: 13f0d241c7f2d817c79ec142f33b54b35597b42b
https://github.com/WebKit/WebKit/commit/13f0d241c7f2d817c79ec142f33b54b35597b42b
Author: Simon Fraser <simon.fraser at apple.com>
Date: 2023-12-12 (Tue, 12 Dec 2023)
Changed paths:
M Source/WebCore/dom/Element.cpp
M Source/WebCore/dom/Element.h
M Source/WebCore/dom/ElementRareData.h
M Source/WebCore/dom/EventTarget.h
M Source/WebCore/platform/ScrollTypes.cpp
M Source/WebCore/platform/ScrollTypes.h
M Source/WebCore/rendering/RenderLayerScrollableArea.cpp
Log Message:
-----------
Avoid forced layouts because of scrollTo(0,0) if the element hasn't scrolled
https://bugs.webkit.org/show_bug.cgi?id=262012
rdar://115732977
Reviewed by Ryosuke Niwa.
We force a layout in `Element::scrollTo()` to ensure that style is up-to-date for checking
`document().scrollingElement()`, and to layout so that scrollHeight etc is computed.
But we can avoid this layout if the scrollTo() is to 0,0, and if this element's scroll
position was already 0,0. Do this by updating `Element::savedLayerScrollPosition()` on
every scroll (instead of just when a RenderLayer is torn down), and check this, and some
other conditions, before short-circuiting the scrollTo.
We have to store a bit in EventTargetFlags to say if this element has ever had a smooth scroll because
`scrollTo(0, 500, { behavior: smooth})` immediately followed by scrollTo(0, 0)` needs
to not short-circuit in order to cancel the animated scroll (tested by
imported/w3c/web-platform-tests/css/cssom-view/scroll-behavior-element.html).
* Source/WebCore/dom/Element.cpp:
(WebCore::Element::scrollTo):
(WebCore::Element::setScrollLeft):
(WebCore::Element::setScrollTop):
(WebCore::Element::removedFromAncestor):
(WebCore::Element::setSavedLayerScrollPositionSlow):
* Source/WebCore/dom/Element.h:
(WebCore::Element::hasEverHadSmoothScroll const):
(WebCore::Element::setHasEverHadSmoothScroll):
(WebCore::Element::setSavedLayerScrollPosition):
* Source/WebCore/dom/ElementRareData.h:
(WebCore::ElementRareData::savedLayerScrollPosition const):
(WebCore::ElementRareData::setSavedLayerScrollPosition):
* Source/WebCore/dom/EventTarget.h:
* Source/WebCore/platform/ScrollTypes.cpp:
(WebCore::operator<<):
* Source/WebCore/platform/ScrollTypes.h:
* Source/WebCore/rendering/RenderLayerScrollableArea.cpp:
(WebCore::RenderLayerScrollableArea::clear):
(WebCore::RenderLayerScrollableArea::restoreScrollPosition):
(WebCore::RenderLayerScrollableArea::scrollTo):
Canonical link: https://commits.webkit.org/271943@main
More information about the webkit-changes
mailing list