simon.fraser@apple.com | 6576a4b | 2014-01-02 19:41:45 +0000 | [diff] [blame] | 1 | /* |
bfulgham@apple.com | 355e666 | 2015-04-30 00:29:05 +0000 | [diff] [blame] | 2 | * Copyright (C) 2014-2015 Apple Inc. All rights reserved. |
simon.fraser@apple.com | 6576a4b | 2014-01-02 19:41:45 +0000 | [diff] [blame] | 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. AND ITS CONTRIBUTORS ``AS IS'' |
| 14 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
| 15 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS |
| 17 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 18 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 19 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 20 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 21 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 22 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
| 23 | * THE POSSIBILITY OF SUCH DAMAGE. |
| 24 | */ |
| 25 | |
| 26 | #include "config.h" |
| 27 | |
| 28 | #if ENABLE(ASYNC_SCROLLING) |
| 29 | #include "AsyncScrollingCoordinator.h" |
| 30 | |
cdumez@apple.com | b7bae2c | 2016-06-17 15:43:14 +0000 | [diff] [blame] | 31 | #include "Document.h" |
enrica@apple.com | fd21a09 | 2014-07-22 23:28:37 +0000 | [diff] [blame] | 32 | #include "EditorClient.h" |
simon.fraser@apple.com | 6576a4b | 2014-01-02 19:41:45 +0000 | [diff] [blame] | 33 | #include "Frame.h" |
| 34 | #include "FrameView.h" |
| 35 | #include "GraphicsLayer.h" |
bfulgham@apple.com | 06c9628 | 2015-05-02 00:39:37 +0000 | [diff] [blame] | 36 | #include "Logging.h" |
simon.fraser@apple.com | 6576a4b | 2014-01-02 19:41:45 +0000 | [diff] [blame] | 37 | #include "MainFrame.h" |
| 38 | #include "Page.h" |
bfulgham@apple.com | 355e666 | 2015-04-30 00:29:05 +0000 | [diff] [blame] | 39 | #include "ScrollAnimator.h" |
simon.fraser@apple.com | 6576a4b | 2014-01-02 19:41:45 +0000 | [diff] [blame] | 40 | #include "ScrollingConstraints.h" |
| 41 | #include "ScrollingStateFixedNode.h" |
simon.fraser@apple.com | 79ad80a | 2014-05-19 20:23:10 +0000 | [diff] [blame] | 42 | #include "ScrollingStateFrameScrollingNode.h" |
| 43 | #include "ScrollingStateOverflowScrollingNode.h" |
simon.fraser@apple.com | 6576a4b | 2014-01-02 19:41:45 +0000 | [diff] [blame] | 44 | #include "ScrollingStateStickyNode.h" |
| 45 | #include "ScrollingStateTree.h" |
simon.fraser@apple.com | eee0f0c | 2016-11-09 23:41:14 +0000 | [diff] [blame] | 46 | #include "Settings.h" |
simon.fraser@apple.com | a98439e | 2016-11-13 03:24:27 +0000 | [diff] [blame] | 47 | #include "TextStream.h" |
bfulgham@apple.com | 355e666 | 2015-04-30 00:29:05 +0000 | [diff] [blame] | 48 | #include "WheelEventTestTrigger.h" |
simon.fraser@apple.com | 6576a4b | 2014-01-02 19:41:45 +0000 | [diff] [blame] | 49 | |
| 50 | namespace WebCore { |
| 51 | |
| 52 | AsyncScrollingCoordinator::AsyncScrollingCoordinator(Page* page) |
| 53 | : ScrollingCoordinator(page) |
andersca@apple.com | 574a745 | 2014-11-21 20:10:13 +0000 | [diff] [blame] | 54 | , m_updateNodeScrollPositionTimer(*this, &AsyncScrollingCoordinator::updateScrollPositionAfterAsyncScrollTimerFired) |
weinig@apple.com | 2663f8f | 2014-12-31 20:01:02 +0000 | [diff] [blame] | 55 | , m_scrollingStateTree(std::make_unique<ScrollingStateTree>(this)) |
simon.fraser@apple.com | 6576a4b | 2014-01-02 19:41:45 +0000 | [diff] [blame] | 56 | { |
| 57 | } |
| 58 | |
| 59 | AsyncScrollingCoordinator::~AsyncScrollingCoordinator() |
| 60 | { |
| 61 | } |
| 62 | |
simon.fraser@apple.com | e5d6ecb | 2014-01-04 03:55:23 +0000 | [diff] [blame] | 63 | void AsyncScrollingCoordinator::scrollingStateTreePropertiesChanged() |
| 64 | { |
| 65 | scheduleTreeStateCommit(); |
| 66 | } |
| 67 | |
wenson_hsieh@apple.com | 70bbd21 | 2015-09-29 22:56:20 +0000 | [diff] [blame] | 68 | static inline void setStateScrollingNodeSnapOffsetsAsFloat(ScrollingStateScrollingNode& node, ScrollEventAxis axis, const Vector<LayoutUnit>* snapOffsets, float deviceScaleFactor) |
commit-queue@webkit.org | 4ad6b20 | 2014-08-15 21:09:13 +0000 | [diff] [blame] | 69 | { |
| 70 | // FIXME: Incorporate current page scale factor in snapping to device pixel. Perhaps we should just convert to float here and let UI process do the pixel snapping? |
| 71 | Vector<float> snapOffsetsAsFloat; |
wenson_hsieh@apple.com | 70bbd21 | 2015-09-29 22:56:20 +0000 | [diff] [blame] | 72 | if (snapOffsets) { |
| 73 | snapOffsetsAsFloat.reserveInitialCapacity(snapOffsets->size()); |
| 74 | for (auto& offset : *snapOffsets) |
| 75 | snapOffsetsAsFloat.uncheckedAppend(roundToDevicePixel(offset, deviceScaleFactor, false)); |
| 76 | } |
commit-queue@webkit.org | 4ad6b20 | 2014-08-15 21:09:13 +0000 | [diff] [blame] | 77 | if (axis == ScrollEventAxis::Horizontal) |
| 78 | node.setHorizontalSnapOffsets(snapOffsetsAsFloat); |
| 79 | else |
| 80 | node.setVerticalSnapOffsets(snapOffsetsAsFloat); |
| 81 | } |
| 82 | |
benjamin@webkit.org | 1ad546c | 2016-06-11 01:18:37 +0000 | [diff] [blame] | 83 | void AsyncScrollingCoordinator::setEventTrackingRegionsDirty() |
simon.fraser@apple.com | 7904959 | 2015-04-04 22:39:29 +0000 | [diff] [blame] | 84 | { |
benjamin@webkit.org | 1ad546c | 2016-06-11 01:18:37 +0000 | [diff] [blame] | 85 | m_eventTrackingRegionsDirty = true; |
simon.fraser@apple.com | 7904959 | 2015-04-04 22:39:29 +0000 | [diff] [blame] | 86 | // We have to schedule a commit, but the computed non-fast region may not have actually changed. |
| 87 | scheduleTreeStateCommit(); |
| 88 | } |
| 89 | |
| 90 | void AsyncScrollingCoordinator::willCommitTree() |
| 91 | { |
benjamin@webkit.org | 1ad546c | 2016-06-11 01:18:37 +0000 | [diff] [blame] | 92 | updateEventTrackingRegions(); |
simon.fraser@apple.com | 7904959 | 2015-04-04 22:39:29 +0000 | [diff] [blame] | 93 | } |
| 94 | |
benjamin@webkit.org | 1ad546c | 2016-06-11 01:18:37 +0000 | [diff] [blame] | 95 | void AsyncScrollingCoordinator::updateEventTrackingRegions() |
simon.fraser@apple.com | 7904959 | 2015-04-04 22:39:29 +0000 | [diff] [blame] | 96 | { |
benjamin@webkit.org | 1ad546c | 2016-06-11 01:18:37 +0000 | [diff] [blame] | 97 | if (!m_eventTrackingRegionsDirty) |
simon.fraser@apple.com | 7904959 | 2015-04-04 22:39:29 +0000 | [diff] [blame] | 98 | return; |
| 99 | |
simon.fraser@apple.com | 8c341c4 | 2015-04-10 05:21:14 +0000 | [diff] [blame] | 100 | if (!m_scrollingStateTree->rootStateNode()) |
| 101 | return; |
| 102 | |
benjamin@webkit.org | 1ad546c | 2016-06-11 01:18:37 +0000 | [diff] [blame] | 103 | m_scrollingStateTree->rootStateNode()->setEventTrackingRegions(absoluteEventTrackingRegions()); |
| 104 | m_eventTrackingRegionsDirty = false; |
simon.fraser@apple.com | 7904959 | 2015-04-04 22:39:29 +0000 | [diff] [blame] | 105 | } |
| 106 | |
simon.fraser@apple.com | 9960e2c | 2015-03-30 04:13:45 +0000 | [diff] [blame] | 107 | void AsyncScrollingCoordinator::frameViewLayoutUpdated(FrameView& frameView) |
simon.fraser@apple.com | 6576a4b | 2014-01-02 19:41:45 +0000 | [diff] [blame] | 108 | { |
| 109 | ASSERT(isMainThread()); |
| 110 | ASSERT(m_page); |
| 111 | |
| 112 | // If there isn't a root node yet, don't do anything. We'll be called again after creating one. |
| 113 | if (!m_scrollingStateTree->rootStateNode()) |
| 114 | return; |
| 115 | |
| 116 | // Compute the region of the page that we can't do fast scrolling for. This currently includes |
| 117 | // all scrollable areas, such as subframes, overflow divs and list boxes. We need to do this even if the |
| 118 | // frame view whose layout was updated is not the main frame. |
simon.fraser@apple.com | 6576a4b | 2014-01-02 19:41:45 +0000 | [diff] [blame] | 119 | // In the future, we may want to have the ability to set non-fast scrolling regions for more than |
| 120 | // just the root node. But right now, this concept only applies to the root. |
benjamin@webkit.org | 1ad546c | 2016-06-11 01:18:37 +0000 | [diff] [blame] | 121 | m_scrollingStateTree->rootStateNode()->setEventTrackingRegions(absoluteEventTrackingRegions()); |
| 122 | m_eventTrackingRegionsDirty = false; |
simon.fraser@apple.com | 6576a4b | 2014-01-02 19:41:45 +0000 | [diff] [blame] | 123 | |
| 124 | if (!coordinatesScrollingForFrameView(frameView)) |
| 125 | return; |
| 126 | |
simon.fraser@apple.com | 9960e2c | 2015-03-30 04:13:45 +0000 | [diff] [blame] | 127 | ScrollingStateFrameScrollingNode* node = downcast<ScrollingStateFrameScrollingNode>(m_scrollingStateTree->stateNodeForID(frameView.scrollLayerID())); |
simon.fraser@apple.com | 6576a4b | 2014-01-02 19:41:45 +0000 | [diff] [blame] | 128 | if (!node) |
| 129 | return; |
| 130 | |
simon.fraser@apple.com | 9960e2c | 2015-03-30 04:13:45 +0000 | [diff] [blame] | 131 | Scrollbar* verticalScrollbar = frameView.verticalScrollbar(); |
| 132 | Scrollbar* horizontalScrollbar = frameView.horizontalScrollbar(); |
mmaxfield@apple.com | 9c7b0c4 | 2016-03-13 03:58:41 +0000 | [diff] [blame] | 133 | node->setScrollerImpsFromScrollbars(verticalScrollbar, horizontalScrollbar); |
simon.fraser@apple.com | 79ad80a | 2014-05-19 20:23:10 +0000 | [diff] [blame] | 134 | |
simon.fraser@apple.com | 9960e2c | 2015-03-30 04:13:45 +0000 | [diff] [blame] | 135 | node->setFrameScaleFactor(frameView.frame().frameScaleFactor()); |
| 136 | node->setHeaderHeight(frameView.headerHeight()); |
| 137 | node->setFooterHeight(frameView.footerHeight()); |
| 138 | node->setTopContentInset(frameView.topContentInset()); |
simon.fraser@apple.com | 6576a4b | 2014-01-02 19:41:45 +0000 | [diff] [blame] | 139 | |
simon.fraser@apple.com | eee0f0c | 2016-11-09 23:41:14 +0000 | [diff] [blame] | 140 | node->setVisualViewportEnabled(visualViewportEnabled()); |
| 141 | node->setLayoutViewport(frameView.layoutViewportRect()); |
| 142 | node->setMinLayoutViewportOrigin(frameView.minStableLayoutViewportOrigin()); |
| 143 | node->setMaxLayoutViewportOrigin(frameView.maxStableLayoutViewportOrigin()); |
| 144 | |
simon.fraser@apple.com | 9960e2c | 2015-03-30 04:13:45 +0000 | [diff] [blame] | 145 | node->setScrollOrigin(frameView.scrollOrigin()); |
| 146 | node->setScrollableAreaSize(frameView.visibleContentRect().size()); |
| 147 | node->setTotalContentsSize(frameView.totalContentsSize()); |
| 148 | node->setReachableContentsSize(frameView.totalContentsSize()); |
simon.fraser@apple.com | bf9a5d8 | 2015-04-30 23:44:49 +0000 | [diff] [blame] | 149 | node->setFixedElementsLayoutRelativeToFrame(frameView.fixedElementsLayoutRelativeToFrame()); |
simon.fraser@apple.com | 6576a4b | 2014-01-02 19:41:45 +0000 | [diff] [blame] | 150 | |
commit-queue@webkit.org | 4ad6b20 | 2014-08-15 21:09:13 +0000 | [diff] [blame] | 151 | #if ENABLE(CSS_SCROLL_SNAP) |
simon.fraser@apple.com | 9960e2c | 2015-03-30 04:13:45 +0000 | [diff] [blame] | 152 | frameView.updateSnapOffsets(); |
wenson_hsieh@apple.com | 70bbd21 | 2015-09-29 22:56:20 +0000 | [diff] [blame] | 153 | updateScrollSnapPropertiesWithFrameView(frameView); |
commit-queue@webkit.org | 4ad6b20 | 2014-08-15 21:09:13 +0000 | [diff] [blame] | 154 | #endif |
| 155 | |
bfulgham@apple.com | 06c9628 | 2015-05-02 00:39:37 +0000 | [diff] [blame] | 156 | #if PLATFORM(COCOA) |
| 157 | Page* page = frameView.frame().page(); |
| 158 | if (page && page->expectsWheelEventTriggers()) { |
| 159 | LOG(WheelEventTestTriggers, " AsyncScrollingCoordinator::frameViewLayoutUpdated: Expects wheel event test trigger=%d", page->expectsWheelEventTriggers()); |
| 160 | node->setExpectsWheelEventTestTrigger(page->expectsWheelEventTriggers()); |
| 161 | } |
| 162 | #endif |
| 163 | |
simon.fraser@apple.com | 6576a4b | 2014-01-02 19:41:45 +0000 | [diff] [blame] | 164 | ScrollableAreaParameters scrollParameters; |
simon.fraser@apple.com | 9960e2c | 2015-03-30 04:13:45 +0000 | [diff] [blame] | 165 | scrollParameters.horizontalScrollElasticity = frameView.horizontalScrollElasticity(); |
| 166 | scrollParameters.verticalScrollElasticity = frameView.verticalScrollElasticity(); |
simon.fraser@apple.com | 6576a4b | 2014-01-02 19:41:45 +0000 | [diff] [blame] | 167 | scrollParameters.hasEnabledHorizontalScrollbar = horizontalScrollbar && horizontalScrollbar->enabled(); |
| 168 | scrollParameters.hasEnabledVerticalScrollbar = verticalScrollbar && verticalScrollbar->enabled(); |
simon.fraser@apple.com | 9960e2c | 2015-03-30 04:13:45 +0000 | [diff] [blame] | 169 | scrollParameters.horizontalScrollbarMode = frameView.horizontalScrollbarMode(); |
| 170 | scrollParameters.verticalScrollbarMode = frameView.verticalScrollbarMode(); |
simon.fraser@apple.com | 6576a4b | 2014-01-02 19:41:45 +0000 | [diff] [blame] | 171 | |
| 172 | node->setScrollableAreaParameters(scrollParameters); |
simon.fraser@apple.com | 6576a4b | 2014-01-02 19:41:45 +0000 | [diff] [blame] | 173 | } |
| 174 | |
benjamin@webkit.org | 1ad546c | 2016-06-11 01:18:37 +0000 | [diff] [blame] | 175 | void AsyncScrollingCoordinator::frameViewEventTrackingRegionsChanged(FrameView&) |
simon.fraser@apple.com | 734cb1b | 2014-02-06 06:55:20 +0000 | [diff] [blame] | 176 | { |
| 177 | if (!m_scrollingStateTree->rootStateNode()) |
| 178 | return; |
| 179 | |
benjamin@webkit.org | 1ad546c | 2016-06-11 01:18:37 +0000 | [diff] [blame] | 180 | setEventTrackingRegionsDirty(); |
simon.fraser@apple.com | 734cb1b | 2014-02-06 06:55:20 +0000 | [diff] [blame] | 181 | } |
| 182 | |
simon.fraser@apple.com | 9960e2c | 2015-03-30 04:13:45 +0000 | [diff] [blame] | 183 | void AsyncScrollingCoordinator::frameViewRootLayerDidChange(FrameView& frameView) |
simon.fraser@apple.com | 6576a4b | 2014-01-02 19:41:45 +0000 | [diff] [blame] | 184 | { |
| 185 | ASSERT(isMainThread()); |
| 186 | ASSERT(m_page); |
| 187 | |
| 188 | if (!coordinatesScrollingForFrameView(frameView)) |
| 189 | return; |
simon.fraser@apple.com | d475c7f | 2014-05-09 02:26:22 +0000 | [diff] [blame] | 190 | |
| 191 | // FIXME: In some navigation scenarios, the FrameView has no RenderView or that RenderView has not been composited. |
| 192 | // This needs cleaning up: https://bugs.webkit.org/show_bug.cgi?id=132724 |
simon.fraser@apple.com | 9960e2c | 2015-03-30 04:13:45 +0000 | [diff] [blame] | 193 | if (!frameView.scrollLayerID()) |
simon.fraser@apple.com | d475c7f | 2014-05-09 02:26:22 +0000 | [diff] [blame] | 194 | return; |
| 195 | |
simon.fraser@apple.com | 6576a4b | 2014-01-02 19:41:45 +0000 | [diff] [blame] | 196 | // If the root layer does not have a ScrollingStateNode, then we should create one. |
| 197 | ensureRootStateNodeForFrameView(frameView); |
| 198 | ASSERT(m_scrollingStateTree->rootStateNode()); |
| 199 | |
| 200 | ScrollingCoordinator::frameViewRootLayerDidChange(frameView); |
| 201 | |
simon.fraser@apple.com | 9960e2c | 2015-03-30 04:13:45 +0000 | [diff] [blame] | 202 | ScrollingStateFrameScrollingNode* node = downcast<ScrollingStateFrameScrollingNode>(m_scrollingStateTree->stateNodeForID(frameView.scrollLayerID())); |
simon.fraser@apple.com | bb2165c | 2014-02-14 19:13:54 +0000 | [diff] [blame] | 203 | node->setLayer(scrollLayerForFrameView(frameView)); |
simon.fraser@apple.com | 7080ea8 | 2014-05-20 19:13:14 +0000 | [diff] [blame] | 204 | node->setScrolledContentsLayer(rootContentLayerForFrameView(frameView)); |
simon.fraser@apple.com | bb2165c | 2014-02-14 19:13:54 +0000 | [diff] [blame] | 205 | node->setCounterScrollingLayer(counterScrollingLayerForFrameView(frameView)); |
bdakin@apple.com | e2e03fb | 2014-05-04 20:40:40 +0000 | [diff] [blame] | 206 | node->setInsetClipLayer(insetClipLayerForFrameView(frameView)); |
bdakin@apple.com | ae3d31b | 2014-05-12 23:21:51 +0000 | [diff] [blame] | 207 | node->setContentShadowLayer(contentShadowLayerForFrameView(frameView)); |
simon.fraser@apple.com | bb2165c | 2014-02-14 19:13:54 +0000 | [diff] [blame] | 208 | node->setHeaderLayer(headerLayerForFrameView(frameView)); |
| 209 | node->setFooterLayer(footerLayerForFrameView(frameView)); |
simon.fraser@apple.com | 9960e2c | 2015-03-30 04:13:45 +0000 | [diff] [blame] | 210 | node->setScrollBehaviorForFixedElements(frameView.scrollBehaviorForFixedElements()); |
simon.fraser@apple.com | 6576a4b | 2014-01-02 19:41:45 +0000 | [diff] [blame] | 211 | } |
| 212 | |
simon.fraser@apple.com | 9960e2c | 2015-03-30 04:13:45 +0000 | [diff] [blame] | 213 | bool AsyncScrollingCoordinator::requestScrollPositionUpdate(FrameView& frameView, const IntPoint& scrollPosition) |
simon.fraser@apple.com | 6576a4b | 2014-01-02 19:41:45 +0000 | [diff] [blame] | 214 | { |
| 215 | ASSERT(isMainThread()); |
| 216 | ASSERT(m_page); |
| 217 | |
| 218 | if (!coordinatesScrollingForFrameView(frameView)) |
| 219 | return false; |
| 220 | |
simon.fraser@apple.com | 9960e2c | 2015-03-30 04:13:45 +0000 | [diff] [blame] | 221 | bool isProgrammaticScroll = frameView.inProgrammaticScroll(); |
cdumez@apple.com | fd6ef2a | 2016-09-12 19:50:50 +0000 | [diff] [blame] | 222 | if (isProgrammaticScroll || frameView.frame().document()->pageCacheState() != Document::NotInPageCache) |
utatane.tea@gmail.com | 4392696 | 2016-11-27 06:08:16 +0000 | [diff] [blame^] | 223 | updateScrollPositionAfterAsyncScroll(frameView.scrollLayerID(), scrollPosition, std::nullopt, isProgrammaticScroll, ScrollingLayerPositionAction::Set); |
simon.fraser@apple.com | 6576a4b | 2014-01-02 19:41:45 +0000 | [diff] [blame] | 224 | |
| 225 | // If this frame view's document is being put into the page cache, we don't want to update our |
| 226 | // main frame scroll position. Just let the FrameView think that we did. |
cdumez@apple.com | fd6ef2a | 2016-09-12 19:50:50 +0000 | [diff] [blame] | 227 | if (frameView.frame().document()->pageCacheState() != Document::NotInPageCache) |
simon.fraser@apple.com | 6576a4b | 2014-01-02 19:41:45 +0000 | [diff] [blame] | 228 | return true; |
| 229 | |
simon.fraser@apple.com | 9960e2c | 2015-03-30 04:13:45 +0000 | [diff] [blame] | 230 | ScrollingStateScrollingNode* stateNode = downcast<ScrollingStateScrollingNode>(m_scrollingStateTree->stateNodeForID(frameView.scrollLayerID())); |
simon.fraser@apple.com | 6576a4b | 2014-01-02 19:41:45 +0000 | [diff] [blame] | 231 | if (!stateNode) |
| 232 | return false; |
| 233 | |
simon.fraser@apple.com | 61d3e78 | 2014-12-06 01:25:21 +0000 | [diff] [blame] | 234 | stateNode->setRequestedScrollPosition(scrollPosition, isProgrammaticScroll); |
simon.fraser@apple.com | 6576a4b | 2014-01-02 19:41:45 +0000 | [diff] [blame] | 235 | return true; |
| 236 | } |
| 237 | |
utatane.tea@gmail.com | 4392696 | 2016-11-27 06:08:16 +0000 | [diff] [blame^] | 238 | void AsyncScrollingCoordinator::scheduleUpdateScrollPositionAfterAsyncScroll(ScrollingNodeID nodeID, const FloatPoint& scrollPosition, const std::optional<FloatPoint>& layoutViewportOrigin, bool programmaticScroll, ScrollingLayerPositionAction scrollingLayerPositionAction) |
simon.fraser@apple.com | 7ad60ba | 2014-01-25 00:04:18 +0000 | [diff] [blame] | 239 | { |
simon.fraser@apple.com | eee0f0c | 2016-11-09 23:41:14 +0000 | [diff] [blame] | 240 | ScheduledScrollUpdate scrollUpdate(nodeID, scrollPosition, layoutViewportOrigin, programmaticScroll, scrollingLayerPositionAction); |
simon.fraser@apple.com | 7ad60ba | 2014-01-25 00:04:18 +0000 | [diff] [blame] | 241 | |
simon.fraser@apple.com | 61d3e78 | 2014-12-06 01:25:21 +0000 | [diff] [blame] | 242 | // For programmatic scrolls, requestScrollPositionUpdate() has already called updateScrollPositionAfterAsyncScroll(). |
| 243 | if (programmaticScroll) |
| 244 | return; |
| 245 | |
simon.fraser@apple.com | 7ad60ba | 2014-01-25 00:04:18 +0000 | [diff] [blame] | 246 | if (m_updateNodeScrollPositionTimer.isActive()) { |
| 247 | if (m_scheduledScrollUpdate.matchesUpdateType(scrollUpdate)) { |
| 248 | m_scheduledScrollUpdate.scrollPosition = scrollPosition; |
| 249 | return; |
| 250 | } |
| 251 | |
simon.fraser@apple.com | 2c30b1b | 2014-04-28 17:28:11 +0000 | [diff] [blame] | 252 | // If the parameters don't match what was previously scheduled, dispatch immediately. |
simon.fraser@apple.com | 7ad60ba | 2014-01-25 00:04:18 +0000 | [diff] [blame] | 253 | m_updateNodeScrollPositionTimer.stop(); |
simon.fraser@apple.com | eee0f0c | 2016-11-09 23:41:14 +0000 | [diff] [blame] | 254 | updateScrollPositionAfterAsyncScroll(m_scheduledScrollUpdate.nodeID, m_scheduledScrollUpdate.scrollPosition, m_scheduledScrollUpdate.layoutViewportOrigin, m_scheduledScrollUpdate.isProgrammaticScroll, m_scheduledScrollUpdate.updateLayerPositionAction); |
| 255 | updateScrollPositionAfterAsyncScroll(nodeID, scrollPosition, layoutViewportOrigin, programmaticScroll, scrollingLayerPositionAction); |
simon.fraser@apple.com | 7ad60ba | 2014-01-25 00:04:18 +0000 | [diff] [blame] | 256 | return; |
| 257 | } |
| 258 | |
| 259 | m_scheduledScrollUpdate = scrollUpdate; |
| 260 | m_updateNodeScrollPositionTimer.startOneShot(0); |
| 261 | } |
| 262 | |
andersca@apple.com | 574a745 | 2014-11-21 20:10:13 +0000 | [diff] [blame] | 263 | void AsyncScrollingCoordinator::updateScrollPositionAfterAsyncScrollTimerFired() |
simon.fraser@apple.com | 7ad60ba | 2014-01-25 00:04:18 +0000 | [diff] [blame] | 264 | { |
simon.fraser@apple.com | eee0f0c | 2016-11-09 23:41:14 +0000 | [diff] [blame] | 265 | updateScrollPositionAfterAsyncScroll(m_scheduledScrollUpdate.nodeID, m_scheduledScrollUpdate.scrollPosition, m_scheduledScrollUpdate.layoutViewportOrigin, m_scheduledScrollUpdate.isProgrammaticScroll, m_scheduledScrollUpdate.updateLayerPositionAction); |
simon.fraser@apple.com | 7ad60ba | 2014-01-25 00:04:18 +0000 | [diff] [blame] | 266 | } |
| 267 | |
simon.fraser@apple.com | c423908 | 2014-06-10 00:37:06 +0000 | [diff] [blame] | 268 | FrameView* AsyncScrollingCoordinator::frameViewForScrollingNode(ScrollingNodeID scrollingNodeID) const |
| 269 | { |
simon.fraser@apple.com | 8bbf869 | 2014-06-12 22:24:13 +0000 | [diff] [blame] | 270 | if (!m_scrollingStateTree->rootStateNode()) |
| 271 | return nullptr; |
| 272 | |
simon.fraser@apple.com | c423908 | 2014-06-10 00:37:06 +0000 | [diff] [blame] | 273 | if (scrollingNodeID == m_scrollingStateTree->rootStateNode()->scrollingNodeID()) |
| 274 | return m_page->mainFrame().view(); |
| 275 | |
| 276 | ScrollingStateNode* stateNode = m_scrollingStateTree->stateNodeForID(scrollingNodeID); |
| 277 | if (!stateNode) |
| 278 | return nullptr; |
| 279 | |
| 280 | // Find the enclosing frame scrolling node. |
| 281 | ScrollingStateNode* parentNode = stateNode; |
| 282 | while (parentNode && parentNode->nodeType() != FrameScrollingNode) |
| 283 | parentNode = parentNode->parent(); |
| 284 | |
| 285 | if (!parentNode) |
| 286 | return nullptr; |
| 287 | |
| 288 | // Walk the frame tree to find the matching FrameView. This is not ideal, but avoids back pointers to FrameViews |
| 289 | // from ScrollingTreeStateNodes. |
| 290 | for (Frame* frame = &m_page->mainFrame(); frame; frame = frame->tree().traverseNext()) { |
| 291 | if (FrameView* view = frame->view()) { |
| 292 | if (view->scrollLayerID() == parentNode->scrollingNodeID()) |
| 293 | return view; |
| 294 | } |
| 295 | } |
| 296 | |
| 297 | return nullptr; |
| 298 | } |
| 299 | |
utatane.tea@gmail.com | 4392696 | 2016-11-27 06:08:16 +0000 | [diff] [blame^] | 300 | void AsyncScrollingCoordinator::updateScrollPositionAfterAsyncScroll(ScrollingNodeID scrollingNodeID, const FloatPoint& scrollPosition, std::optional<FloatPoint> layoutViewportOrigin, bool programmaticScroll, ScrollingLayerPositionAction scrollingLayerPositionAction) |
simon.fraser@apple.com | 7ad60ba | 2014-01-25 00:04:18 +0000 | [diff] [blame] | 301 | { |
| 302 | ASSERT(isMainThread()); |
| 303 | |
| 304 | if (!m_page) |
| 305 | return; |
| 306 | |
simon.fraser@apple.com | 9960e2c | 2015-03-30 04:13:45 +0000 | [diff] [blame] | 307 | FrameView* frameViewPtr = frameViewForScrollingNode(scrollingNodeID); |
| 308 | if (!frameViewPtr) |
simon.fraser@apple.com | 7ad60ba | 2014-01-25 00:04:18 +0000 | [diff] [blame] | 309 | return; |
| 310 | |
simon.fraser@apple.com | 0e87c83 | 2016-11-19 19:34:18 +0000 | [diff] [blame] | 311 | LOG_WITH_STREAM(Scrolling, stream << "AsyncScrollingCoordinator::updateScrollPositionAfterAsyncScroll node " << scrollingNodeID << " scrollPosition " << scrollPosition << " action " << scrollingLayerPositionAction); |
simon.fraser@apple.com | a98439e | 2016-11-13 03:24:27 +0000 | [diff] [blame] | 312 | |
simon.fraser@apple.com | 9960e2c | 2015-03-30 04:13:45 +0000 | [diff] [blame] | 313 | FrameView& frameView = *frameViewPtr; |
simon.fraser@apple.com | 543255a | 2014-03-31 21:23:27 +0000 | [diff] [blame] | 314 | |
simon.fraser@apple.com | 9960e2c | 2015-03-30 04:13:45 +0000 | [diff] [blame] | 315 | if (scrollingNodeID == frameView.scrollLayerID()) { |
simon.fraser@apple.com | 0e87c83 | 2016-11-19 19:34:18 +0000 | [diff] [blame] | 316 | reconcileScrollingState(frameView, scrollPosition, layoutViewportOrigin, programmaticScroll, true, scrollingLayerPositionAction); |
simon.fraser@apple.com | 543255a | 2014-03-31 21:23:27 +0000 | [diff] [blame] | 317 | |
bfulgham@apple.com | 355e666 | 2015-04-30 00:29:05 +0000 | [diff] [blame] | 318 | #if PLATFORM(COCOA) |
| 319 | if (m_page->expectsWheelEventTriggers()) { |
| 320 | frameView.scrollAnimator().setWheelEventTestTrigger(m_page->testTrigger()); |
| 321 | if (const auto& trigger = m_page->testTrigger()) |
bfulgham@apple.com | 06c9628 | 2015-05-02 00:39:37 +0000 | [diff] [blame] | 322 | trigger->removeTestDeferralForReason(reinterpret_cast<WheelEventTestTrigger::ScrollableAreaIdentifier>(scrollingNodeID), WheelEventTestTrigger::ScrollingThreadSyncNeeded); |
bfulgham@apple.com | 355e666 | 2015-04-30 00:29:05 +0000 | [diff] [blame] | 323 | } |
| 324 | #endif |
| 325 | |
simon.fraser@apple.com | 543255a | 2014-03-31 21:23:27 +0000 | [diff] [blame] | 326 | return; |
simon.fraser@apple.com | 7ad60ba | 2014-01-25 00:04:18 +0000 | [diff] [blame] | 327 | } |
simon.fraser@apple.com | 543255a | 2014-03-31 21:23:27 +0000 | [diff] [blame] | 328 | |
| 329 | // Overflow-scroll area. |
simon.fraser@apple.com | 9960e2c | 2015-03-30 04:13:45 +0000 | [diff] [blame] | 330 | if (ScrollableArea* scrollableArea = frameView.scrollableAreaForScrollLayerID(scrollingNodeID)) { |
simon.fraser@apple.com | 0e87c83 | 2016-11-19 19:34:18 +0000 | [diff] [blame] | 331 | scrollableArea->setIsUserScroll(scrollingLayerPositionAction == ScrollingLayerPositionAction::Sync); |
simon.fraser@apple.com | 543255a | 2014-03-31 21:23:27 +0000 | [diff] [blame] | 332 | scrollableArea->scrollToOffsetWithoutAnimation(scrollPosition); |
simon.fraser@apple.com | c1a4d46 | 2014-05-06 01:10:30 +0000 | [diff] [blame] | 333 | scrollableArea->setIsUserScroll(false); |
simon.fraser@apple.com | 0e87c83 | 2016-11-19 19:34:18 +0000 | [diff] [blame] | 334 | if (scrollingLayerPositionAction == ScrollingLayerPositionAction::Set) |
akling@apple.com | 26f8fc8 | 2015-01-16 21:33:01 +0000 | [diff] [blame] | 335 | m_page->editorClient().overflowScrollPositionChanged(); |
bfulgham@apple.com | 355e666 | 2015-04-30 00:29:05 +0000 | [diff] [blame] | 336 | |
| 337 | #if PLATFORM(COCOA) |
| 338 | if (m_page->expectsWheelEventTriggers()) { |
| 339 | frameView.scrollAnimator().setWheelEventTestTrigger(m_page->testTrigger()); |
| 340 | if (const auto& trigger = m_page->testTrigger()) |
bfulgham@apple.com | 06c9628 | 2015-05-02 00:39:37 +0000 | [diff] [blame] | 341 | trigger->removeTestDeferralForReason(reinterpret_cast<WheelEventTestTrigger::ScrollableAreaIdentifier>(scrollingNodeID), WheelEventTestTrigger::ScrollingThreadSyncNeeded); |
bfulgham@apple.com | 355e666 | 2015-04-30 00:29:05 +0000 | [diff] [blame] | 342 | } |
| 343 | #endif |
simon.fraser@apple.com | c1a4d46 | 2014-05-06 01:10:30 +0000 | [diff] [blame] | 344 | } |
simon.fraser@apple.com | 7ad60ba | 2014-01-25 00:04:18 +0000 | [diff] [blame] | 345 | } |
| 346 | |
simon.fraser@apple.com | 0e87c83 | 2016-11-19 19:34:18 +0000 | [diff] [blame] | 347 | void AsyncScrollingCoordinator::reconcileScrollingState(FrameView& frameView, const FloatPoint& scrollPosition, const LayoutViewportOriginOrOverrideRect& layoutViewportOriginOrOverrideRect, bool programmaticScroll, bool inStableState, ScrollingLayerPositionAction scrollingLayerPositionAction) |
simon.fraser@apple.com | a98439e | 2016-11-13 03:24:27 +0000 | [diff] [blame] | 348 | { |
| 349 | bool oldProgrammaticScroll = frameView.inProgrammaticScroll(); |
| 350 | frameView.setInProgrammaticScroll(programmaticScroll); |
| 351 | |
utatane.tea@gmail.com | 4392696 | 2016-11-27 06:08:16 +0000 | [diff] [blame^] | 352 | std::optional<FloatRect> layoutViewportRect; |
simon.fraser@apple.com | 0e87c83 | 2016-11-19 19:34:18 +0000 | [diff] [blame] | 353 | |
simon.fraser@apple.com | a98439e | 2016-11-13 03:24:27 +0000 | [diff] [blame] | 354 | WTF::switchOn(layoutViewportOriginOrOverrideRect, |
utatane.tea@gmail.com | 4392696 | 2016-11-27 06:08:16 +0000 | [diff] [blame^] | 355 | [&frameView](std::optional<FloatPoint> origin) { |
simon.fraser@apple.com | a98439e | 2016-11-13 03:24:27 +0000 | [diff] [blame] | 356 | if (origin) |
simon.fraser@apple.com | 7fded23 | 2016-11-15 21:06:06 +0000 | [diff] [blame] | 357 | frameView.setBaseLayoutViewportOrigin(LayoutPoint(origin.value()), FrameView::TriggerLayoutOrNot::No); |
utatane.tea@gmail.com | 4392696 | 2016-11-27 06:08:16 +0000 | [diff] [blame^] | 358 | }, [&frameView, &layoutViewportRect, inStableState, visualViewportEnabled = visualViewportEnabled()](std::optional<FloatRect> overrideRect) { |
simon.fraser@apple.com | 0e87c83 | 2016-11-19 19:34:18 +0000 | [diff] [blame] | 359 | layoutViewportRect = overrideRect; |
| 360 | if (overrideRect && inStableState) { |
| 361 | if (visualViewportEnabled) |
| 362 | frameView.setLayoutViewportOverrideRect(LayoutRect(overrideRect.value())); |
simon.fraser@apple.com | a98439e | 2016-11-13 03:24:27 +0000 | [diff] [blame] | 363 | #if PLATFORM(IOS) |
simon.fraser@apple.com | 0e87c83 | 2016-11-19 19:34:18 +0000 | [diff] [blame] | 364 | else |
| 365 | frameView.setCustomFixedPositionLayoutRect(enclosingIntRect(overrideRect.value())); |
simon.fraser@apple.com | a98439e | 2016-11-13 03:24:27 +0000 | [diff] [blame] | 366 | #endif |
simon.fraser@apple.com | 0e87c83 | 2016-11-19 19:34:18 +0000 | [diff] [blame] | 367 | } |
simon.fraser@apple.com | a98439e | 2016-11-13 03:24:27 +0000 | [diff] [blame] | 368 | } |
| 369 | ); |
| 370 | |
| 371 | frameView.setConstrainsScrollingToContentEdge(false); |
| 372 | frameView.notifyScrollPositionChanged(roundedIntPoint(scrollPosition)); |
| 373 | frameView.setConstrainsScrollingToContentEdge(true); |
| 374 | frameView.setInProgrammaticScroll(oldProgrammaticScroll); |
| 375 | |
simon.fraser@apple.com | 0e87c83 | 2016-11-19 19:34:18 +0000 | [diff] [blame] | 376 | if (!programmaticScroll && scrollingLayerPositionAction != ScrollingLayerPositionAction::Set) { |
| 377 | if (inStableState) |
| 378 | reconcileViewportConstrainedLayerPositions(frameView.rectForFixedPositionLayout(), scrollingLayerPositionAction); |
| 379 | else if (layoutViewportRect) |
| 380 | reconcileViewportConstrainedLayerPositions(LayoutRect(layoutViewportRect.value()), scrollingLayerPositionAction); |
| 381 | } |
simon.fraser@apple.com | a98439e | 2016-11-13 03:24:27 +0000 | [diff] [blame] | 382 | |
| 383 | GraphicsLayer* scrollLayer = scrollLayerForFrameView(frameView); |
| 384 | if (!scrollLayer) |
| 385 | return; |
| 386 | |
| 387 | GraphicsLayer* counterScrollingLayer = counterScrollingLayerForFrameView(frameView); |
| 388 | GraphicsLayer* insetClipLayer = insetClipLayerForFrameView(frameView); |
| 389 | GraphicsLayer* contentShadowLayer = contentShadowLayerForFrameView(frameView); |
| 390 | GraphicsLayer* scrolledContentsLayer = rootContentLayerForFrameView(frameView); |
| 391 | GraphicsLayer* headerLayer = headerLayerForFrameView(frameView); |
| 392 | GraphicsLayer* footerLayer = footerLayerForFrameView(frameView); |
| 393 | |
| 394 | ASSERT(frameView.scrollPosition() == roundedIntPoint(scrollPosition)); |
simon.fraser@apple.com | 7fded23 | 2016-11-15 21:06:06 +0000 | [diff] [blame] | 395 | LayoutPoint scrollPositionForFixed = frameView.scrollPositionForFixedPosition(); |
simon.fraser@apple.com | a98439e | 2016-11-13 03:24:27 +0000 | [diff] [blame] | 396 | float topContentInset = frameView.topContentInset(); |
| 397 | |
| 398 | FloatPoint positionForInsetClipLayer; |
| 399 | if (insetClipLayer) |
| 400 | positionForInsetClipLayer = FloatPoint(insetClipLayer->position().x(), FrameView::yPositionForInsetClipLayer(scrollPosition, topContentInset)); |
| 401 | FloatPoint positionForContentsLayer = frameView.positionForRootContentLayer(); |
| 402 | |
| 403 | FloatPoint positionForHeaderLayer = FloatPoint(scrollPositionForFixed.x(), FrameView::yPositionForHeaderLayer(scrollPosition, topContentInset)); |
| 404 | FloatPoint positionForFooterLayer = FloatPoint(scrollPositionForFixed.x(), |
| 405 | FrameView::yPositionForFooterLayer(scrollPosition, topContentInset, frameView.totalContentsSize().height(), frameView.footerHeight())); |
| 406 | |
simon.fraser@apple.com | 0e87c83 | 2016-11-19 19:34:18 +0000 | [diff] [blame] | 407 | if (programmaticScroll || scrollingLayerPositionAction == ScrollingLayerPositionAction::Set) { |
simon.fraser@apple.com | a98439e | 2016-11-13 03:24:27 +0000 | [diff] [blame] | 408 | scrollLayer->setPosition(-frameView.scrollPosition()); |
| 409 | if (counterScrollingLayer) |
| 410 | counterScrollingLayer->setPosition(scrollPositionForFixed); |
| 411 | if (insetClipLayer) |
| 412 | insetClipLayer->setPosition(positionForInsetClipLayer); |
| 413 | if (contentShadowLayer) |
| 414 | contentShadowLayer->setPosition(positionForContentsLayer); |
| 415 | if (scrolledContentsLayer) |
| 416 | scrolledContentsLayer->setPosition(positionForContentsLayer); |
| 417 | if (headerLayer) |
| 418 | headerLayer->setPosition(positionForHeaderLayer); |
| 419 | if (footerLayer) |
| 420 | footerLayer->setPosition(positionForFooterLayer); |
| 421 | } else { |
| 422 | scrollLayer->syncPosition(-frameView.scrollPosition()); |
| 423 | if (counterScrollingLayer) |
| 424 | counterScrollingLayer->syncPosition(scrollPositionForFixed); |
| 425 | if (insetClipLayer) |
| 426 | insetClipLayer->syncPosition(positionForInsetClipLayer); |
| 427 | if (contentShadowLayer) |
| 428 | contentShadowLayer->syncPosition(positionForContentsLayer); |
| 429 | if (scrolledContentsLayer) |
| 430 | scrolledContentsLayer->syncPosition(positionForContentsLayer); |
| 431 | if (headerLayer) |
| 432 | headerLayer->syncPosition(positionForHeaderLayer); |
| 433 | if (footerLayer) |
| 434 | footerLayer->syncPosition(positionForFooterLayer); |
| 435 | } |
| 436 | } |
| 437 | |
simon.fraser@apple.com | 9960e2c | 2015-03-30 04:13:45 +0000 | [diff] [blame] | 438 | void AsyncScrollingCoordinator::scrollableAreaScrollbarLayerDidChange(ScrollableArea& scrollableArea, ScrollbarOrientation orientation) |
simon.fraser@apple.com | 6576a4b | 2014-01-02 19:41:45 +0000 | [diff] [blame] | 439 | { |
| 440 | ASSERT(isMainThread()); |
| 441 | ASSERT(m_page); |
| 442 | |
simon.fraser@apple.com | 9960e2c | 2015-03-30 04:13:45 +0000 | [diff] [blame] | 443 | if (&scrollableArea != static_cast<ScrollableArea*>(m_page->mainFrame().view())) |
simon.fraser@apple.com | 6576a4b | 2014-01-02 19:41:45 +0000 | [diff] [blame] | 444 | return; |
| 445 | |
| 446 | if (orientation == VerticalScrollbar) |
simon.fraser@apple.com | 9960e2c | 2015-03-30 04:13:45 +0000 | [diff] [blame] | 447 | scrollableArea.verticalScrollbarLayerDidChange(); |
simon.fraser@apple.com | 6576a4b | 2014-01-02 19:41:45 +0000 | [diff] [blame] | 448 | else |
simon.fraser@apple.com | 9960e2c | 2015-03-30 04:13:45 +0000 | [diff] [blame] | 449 | scrollableArea.horizontalScrollbarLayerDidChange(); |
simon.fraser@apple.com | 6576a4b | 2014-01-02 19:41:45 +0000 | [diff] [blame] | 450 | } |
| 451 | |
| 452 | ScrollingNodeID AsyncScrollingCoordinator::attachToStateTree(ScrollingNodeType nodeType, ScrollingNodeID newNodeID, ScrollingNodeID parentID) |
| 453 | { |
| 454 | return m_scrollingStateTree->attachNode(nodeType, newNodeID, parentID); |
| 455 | } |
| 456 | |
| 457 | void AsyncScrollingCoordinator::detachFromStateTree(ScrollingNodeID nodeID) |
| 458 | { |
| 459 | m_scrollingStateTree->detachNode(nodeID); |
| 460 | } |
| 461 | |
| 462 | void AsyncScrollingCoordinator::clearStateTree() |
| 463 | { |
| 464 | m_scrollingStateTree->clear(); |
| 465 | } |
| 466 | |
simon.fraser@apple.com | 0e87c83 | 2016-11-19 19:34:18 +0000 | [diff] [blame] | 467 | void AsyncScrollingCoordinator::reconcileViewportConstrainedLayerPositions(const LayoutRect& viewportRect, ScrollingLayerPositionAction action) |
simon.fraser@apple.com | 6576a4b | 2014-01-02 19:41:45 +0000 | [diff] [blame] | 468 | { |
| 469 | if (!m_scrollingStateTree->rootStateNode()) |
| 470 | return; |
| 471 | |
simon.fraser@apple.com | 2f1f181 | 2014-06-18 21:43:30 +0000 | [diff] [blame] | 472 | auto children = m_scrollingStateTree->rootStateNode()->children(); |
simon.fraser@apple.com | 6576a4b | 2014-01-02 19:41:45 +0000 | [diff] [blame] | 473 | if (!children) |
| 474 | return; |
| 475 | |
simon.fraser@apple.com | 0e87c83 | 2016-11-19 19:34:18 +0000 | [diff] [blame] | 476 | LOG_WITH_STREAM(Scrolling, stream << "AsyncScrollingCoordinator::reconcileViewportConstrainedLayerPositions for viewport rect " << viewportRect); |
simon.fraser@apple.com | a98439e | 2016-11-13 03:24:27 +0000 | [diff] [blame] | 477 | |
simon.fraser@apple.com | 6576a4b | 2014-01-02 19:41:45 +0000 | [diff] [blame] | 478 | // FIXME: We'll have to traverse deeper into the tree at some point. |
simon.fraser@apple.com | c423908 | 2014-06-10 00:37:06 +0000 | [diff] [blame] | 479 | for (auto& child : *children) |
simon.fraser@apple.com | 0e87c83 | 2016-11-19 19:34:18 +0000 | [diff] [blame] | 480 | child->reconcileLayerPositionForViewportRect(viewportRect, action); |
simon.fraser@apple.com | 6576a4b | 2014-01-02 19:41:45 +0000 | [diff] [blame] | 481 | } |
| 482 | |
simon.fraser@apple.com | 9960e2c | 2015-03-30 04:13:45 +0000 | [diff] [blame] | 483 | void AsyncScrollingCoordinator::ensureRootStateNodeForFrameView(FrameView& frameView) |
simon.fraser@apple.com | 6576a4b | 2014-01-02 19:41:45 +0000 | [diff] [blame] | 484 | { |
simon.fraser@apple.com | 9960e2c | 2015-03-30 04:13:45 +0000 | [diff] [blame] | 485 | ASSERT(frameView.scrollLayerID()); |
| 486 | attachToStateTree(FrameScrollingNode, frameView.scrollLayerID(), 0); |
simon.fraser@apple.com | 6576a4b | 2014-01-02 19:41:45 +0000 | [diff] [blame] | 487 | } |
| 488 | |
simon.fraser@apple.com | 7080ea8 | 2014-05-20 19:13:14 +0000 | [diff] [blame] | 489 | void AsyncScrollingCoordinator::updateFrameScrollingNode(ScrollingNodeID nodeID, GraphicsLayer* layer, GraphicsLayer* scrolledContentsLayer, GraphicsLayer* counterScrollingLayer, GraphicsLayer* insetClipLayer, const ScrollingGeometry* scrollingGeometry) |
simon.fraser@apple.com | 6576a4b | 2014-01-02 19:41:45 +0000 | [diff] [blame] | 490 | { |
cdumez@apple.com | 2cd7a21 | 2014-10-06 05:14:36 +0000 | [diff] [blame] | 491 | ScrollingStateFrameScrollingNode* node = downcast<ScrollingStateFrameScrollingNode>(m_scrollingStateTree->stateNodeForID(nodeID)); |
simon.fraser@apple.com | 6576a4b | 2014-01-02 19:41:45 +0000 | [diff] [blame] | 492 | ASSERT(node); |
| 493 | if (!node) |
| 494 | return; |
| 495 | |
simon.fraser@apple.com | bb2165c | 2014-02-14 19:13:54 +0000 | [diff] [blame] | 496 | node->setLayer(layer); |
bdakin@apple.com | e2e03fb | 2014-05-04 20:40:40 +0000 | [diff] [blame] | 497 | node->setInsetClipLayer(insetClipLayer); |
simon.fraser@apple.com | 7080ea8 | 2014-05-20 19:13:14 +0000 | [diff] [blame] | 498 | node->setScrolledContentsLayer(scrolledContentsLayer); |
simon.fraser@apple.com | 6576a4b | 2014-01-02 19:41:45 +0000 | [diff] [blame] | 499 | node->setCounterScrollingLayer(counterScrollingLayer); |
simon.fraser@apple.com | e2fcc42 | 2014-03-27 02:15:48 +0000 | [diff] [blame] | 500 | |
simon.fraser@apple.com | 6cced98 | 2014-03-27 06:50:40 +0000 | [diff] [blame] | 501 | if (scrollingGeometry) { |
| 502 | node->setScrollOrigin(scrollingGeometry->scrollOrigin); |
| 503 | node->setScrollPosition(scrollingGeometry->scrollPosition); |
| 504 | node->setTotalContentsSize(scrollingGeometry->contentSize); |
simon.fraser@apple.com | c9dc900 | 2014-06-27 18:28:39 +0000 | [diff] [blame] | 505 | node->setReachableContentsSize(scrollingGeometry->reachableContentSize); |
simon.fraser@apple.com | 79ad80a | 2014-05-19 20:23:10 +0000 | [diff] [blame] | 506 | node->setScrollableAreaSize(scrollingGeometry->scrollableAreaSize); |
| 507 | } |
| 508 | } |
| 509 | |
| 510 | void AsyncScrollingCoordinator::updateOverflowScrollingNode(ScrollingNodeID nodeID, GraphicsLayer* layer, GraphicsLayer* scrolledContentsLayer, const ScrollingGeometry* scrollingGeometry) |
| 511 | { |
cdumez@apple.com | 2cd7a21 | 2014-10-06 05:14:36 +0000 | [diff] [blame] | 512 | ScrollingStateOverflowScrollingNode* node = downcast<ScrollingStateOverflowScrollingNode>(m_scrollingStateTree->stateNodeForID(nodeID)); |
simon.fraser@apple.com | 79ad80a | 2014-05-19 20:23:10 +0000 | [diff] [blame] | 513 | ASSERT(node); |
| 514 | if (!node) |
| 515 | return; |
| 516 | |
| 517 | node->setLayer(layer); |
| 518 | node->setScrolledContentsLayer(scrolledContentsLayer); |
| 519 | |
| 520 | if (scrollingGeometry) { |
| 521 | node->setScrollOrigin(scrollingGeometry->scrollOrigin); |
| 522 | node->setScrollPosition(scrollingGeometry->scrollPosition); |
| 523 | node->setTotalContentsSize(scrollingGeometry->contentSize); |
simon.fraser@apple.com | c9dc900 | 2014-06-27 18:28:39 +0000 | [diff] [blame] | 524 | node->setReachableContentsSize(scrollingGeometry->reachableContentSize); |
simon.fraser@apple.com | 79ad80a | 2014-05-19 20:23:10 +0000 | [diff] [blame] | 525 | node->setScrollableAreaSize(scrollingGeometry->scrollableAreaSize); |
commit-queue@webkit.org | 4ad6b20 | 2014-08-15 21:09:13 +0000 | [diff] [blame] | 526 | #if ENABLE(CSS_SCROLL_SNAP) |
wenson_hsieh@apple.com | 70bbd21 | 2015-09-29 22:56:20 +0000 | [diff] [blame] | 527 | setStateScrollingNodeSnapOffsetsAsFloat(*node, ScrollEventAxis::Horizontal, &scrollingGeometry->horizontalSnapOffsets, m_page->deviceScaleFactor()); |
| 528 | setStateScrollingNodeSnapOffsetsAsFloat(*node, ScrollEventAxis::Vertical, &scrollingGeometry->verticalSnapOffsets, m_page->deviceScaleFactor()); |
bfulgham@apple.com | b10296b | 2015-06-19 19:24:59 +0000 | [diff] [blame] | 529 | node->setCurrentHorizontalSnapPointIndex(scrollingGeometry->currentHorizontalSnapPointIndex); |
| 530 | node->setCurrentVerticalSnapPointIndex(scrollingGeometry->currentVerticalSnapPointIndex); |
commit-queue@webkit.org | 4ad6b20 | 2014-08-15 21:09:13 +0000 | [diff] [blame] | 531 | #endif |
simon.fraser@apple.com | 6cced98 | 2014-03-27 06:50:40 +0000 | [diff] [blame] | 532 | } |
simon.fraser@apple.com | 6576a4b | 2014-01-02 19:41:45 +0000 | [diff] [blame] | 533 | } |
| 534 | |
| 535 | void AsyncScrollingCoordinator::updateViewportConstrainedNode(ScrollingNodeID nodeID, const ViewportConstraints& constraints, GraphicsLayer* graphicsLayer) |
| 536 | { |
| 537 | ASSERT(supportsFixedPositionLayers()); |
| 538 | |
| 539 | ScrollingStateNode* node = m_scrollingStateTree->stateNodeForID(nodeID); |
| 540 | if (!node) |
| 541 | return; |
| 542 | |
| 543 | switch (constraints.constraintType()) { |
| 544 | case ViewportConstraints::FixedPositionConstraint: { |
cdumez@apple.com | 2cd7a21 | 2014-10-06 05:14:36 +0000 | [diff] [blame] | 545 | ScrollingStateFixedNode& fixedNode = downcast<ScrollingStateFixedNode>(*node); |
| 546 | fixedNode.setLayer(graphicsLayer); |
| 547 | fixedNode.updateConstraints((const FixedPositionViewportConstraints&)constraints); |
simon.fraser@apple.com | 6576a4b | 2014-01-02 19:41:45 +0000 | [diff] [blame] | 548 | break; |
| 549 | } |
| 550 | case ViewportConstraints::StickyPositionConstraint: { |
cdumez@apple.com | 2cd7a21 | 2014-10-06 05:14:36 +0000 | [diff] [blame] | 551 | ScrollingStateStickyNode& stickyNode = downcast<ScrollingStateStickyNode>(*node); |
| 552 | stickyNode.setLayer(graphicsLayer); |
| 553 | stickyNode.updateConstraints((const StickyPositionViewportConstraints&)constraints); |
simon.fraser@apple.com | 6576a4b | 2014-01-02 19:41:45 +0000 | [diff] [blame] | 554 | break; |
| 555 | } |
| 556 | } |
simon.fraser@apple.com | 6576a4b | 2014-01-02 19:41:45 +0000 | [diff] [blame] | 557 | } |
| 558 | |
simon.fraser@apple.com | 6576a4b | 2014-01-02 19:41:45 +0000 | [diff] [blame] | 559 | void AsyncScrollingCoordinator::setSynchronousScrollingReasons(SynchronousScrollingReasons reasons) |
| 560 | { |
| 561 | if (!m_scrollingStateTree->rootStateNode()) |
| 562 | return; |
| 563 | |
| 564 | // The FrameView's GraphicsLayer is likely to be out-of-synch with the PlatformLayer |
| 565 | // at this point. So we'll update it before we switch back to main thread scrolling |
| 566 | // in order to avoid layer positioning bugs. |
| 567 | if (reasons) |
| 568 | updateMainFrameScrollLayerPosition(); |
| 569 | m_scrollingStateTree->rootStateNode()->setSynchronousScrollingReasons(reasons); |
simon.fraser@apple.com | 6576a4b | 2014-01-02 19:41:45 +0000 | [diff] [blame] | 570 | } |
| 571 | |
| 572 | void AsyncScrollingCoordinator::updateMainFrameScrollLayerPosition() |
| 573 | { |
| 574 | ASSERT(isMainThread()); |
| 575 | |
| 576 | if (!m_page) |
| 577 | return; |
| 578 | |
| 579 | FrameView* frameView = m_page->mainFrame().view(); |
| 580 | if (!frameView) |
| 581 | return; |
| 582 | |
simon.fraser@apple.com | 9960e2c | 2015-03-30 04:13:45 +0000 | [diff] [blame] | 583 | if (GraphicsLayer* scrollLayer = scrollLayerForFrameView(*frameView)) |
simon.fraser@apple.com | 6576a4b | 2014-01-02 19:41:45 +0000 | [diff] [blame] | 584 | scrollLayer->setPosition(-frameView->scrollPosition()); |
| 585 | } |
| 586 | |
simon.fraser@apple.com | 6576a4b | 2014-01-02 19:41:45 +0000 | [diff] [blame] | 587 | bool AsyncScrollingCoordinator::isRubberBandInProgress() const |
| 588 | { |
| 589 | return scrollingTree()->isRubberBandInProgress(); |
| 590 | } |
| 591 | |
| 592 | void AsyncScrollingCoordinator::setScrollPinningBehavior(ScrollPinningBehavior pinning) |
| 593 | { |
| 594 | scrollingTree()->setScrollPinningBehavior(pinning); |
| 595 | } |
| 596 | |
simon.fraser@apple.com | eee0f0c | 2016-11-09 23:41:14 +0000 | [diff] [blame] | 597 | bool AsyncScrollingCoordinator::visualViewportEnabled() const |
| 598 | { |
| 599 | return m_page->mainFrame().settings().visualViewportEnabled(); |
| 600 | } |
| 601 | |
simon.fraser@apple.com | 6576a4b | 2014-01-02 19:41:45 +0000 | [diff] [blame] | 602 | String AsyncScrollingCoordinator::scrollingStateTreeAsText() const |
| 603 | { |
simon.fraser@apple.com | 7904959 | 2015-04-04 22:39:29 +0000 | [diff] [blame] | 604 | if (m_scrollingStateTree->rootStateNode()) { |
benjamin@webkit.org | 1ad546c | 2016-06-11 01:18:37 +0000 | [diff] [blame] | 605 | if (m_eventTrackingRegionsDirty) |
| 606 | m_scrollingStateTree->rootStateNode()->setEventTrackingRegions(absoluteEventTrackingRegions()); |
simon.fraser@apple.com | 6576a4b | 2014-01-02 19:41:45 +0000 | [diff] [blame] | 607 | return m_scrollingStateTree->rootStateNode()->scrollingStateTreeAsText(); |
simon.fraser@apple.com | 7904959 | 2015-04-04 22:39:29 +0000 | [diff] [blame] | 608 | } |
simon.fraser@apple.com | 6576a4b | 2014-01-02 19:41:45 +0000 | [diff] [blame] | 609 | |
| 610 | return String(); |
| 611 | } |
| 612 | |
bfulgham@apple.com | 06c9628 | 2015-05-02 00:39:37 +0000 | [diff] [blame] | 613 | #if PLATFORM(COCOA) |
bfulgham@apple.com | b2287ea | 2015-05-12 01:12:01 +0000 | [diff] [blame] | 614 | void AsyncScrollingCoordinator::setActiveScrollSnapIndices(ScrollingNodeID scrollingNodeID, unsigned horizontalIndex, unsigned verticalIndex) |
| 615 | { |
| 616 | ASSERT(isMainThread()); |
| 617 | |
| 618 | if (!m_page) |
| 619 | return; |
| 620 | |
| 621 | FrameView* frameView = frameViewForScrollingNode(scrollingNodeID); |
| 622 | if (!frameView) |
| 623 | return; |
| 624 | |
| 625 | if (scrollingNodeID == frameView->scrollLayerID()) { |
| 626 | frameView->setCurrentHorizontalSnapPointIndex(horizontalIndex); |
| 627 | frameView->setCurrentVerticalSnapPointIndex(verticalIndex); |
| 628 | return; |
| 629 | } |
| 630 | |
| 631 | // Overflow-scroll area. |
| 632 | if (ScrollableArea* scrollableArea = frameView->scrollableAreaForScrollLayerID(scrollingNodeID)) { |
| 633 | scrollableArea->setCurrentHorizontalSnapPointIndex(horizontalIndex); |
| 634 | scrollableArea->setCurrentVerticalSnapPointIndex(verticalIndex); |
| 635 | } |
| 636 | } |
| 637 | |
bfulgham@apple.com | 06c9628 | 2015-05-02 00:39:37 +0000 | [diff] [blame] | 638 | void AsyncScrollingCoordinator::deferTestsForReason(WheelEventTestTrigger::ScrollableAreaIdentifier identifier, WheelEventTestTrigger::DeferTestTriggerReason reason) const |
| 639 | { |
bfulgham@apple.com | b2287ea | 2015-05-12 01:12:01 +0000 | [diff] [blame] | 640 | ASSERT(isMainThread()); |
bfulgham@apple.com | 06c9628 | 2015-05-02 00:39:37 +0000 | [diff] [blame] | 641 | if (!m_page || !m_page->expectsWheelEventTriggers()) |
| 642 | return; |
| 643 | |
| 644 | if (const auto& trigger = m_page->testTrigger()) { |
| 645 | LOG(WheelEventTestTriggers, " (!) AsyncScrollingCoordinator::deferTestsForReason: Deferring %p for reason %d.", identifier, reason); |
| 646 | trigger->deferTestsForReason(identifier, reason); |
| 647 | } |
| 648 | } |
| 649 | |
| 650 | void AsyncScrollingCoordinator::removeTestDeferralForReason(WheelEventTestTrigger::ScrollableAreaIdentifier identifier, WheelEventTestTrigger::DeferTestTriggerReason reason) const |
| 651 | { |
bfulgham@apple.com | b2287ea | 2015-05-12 01:12:01 +0000 | [diff] [blame] | 652 | ASSERT(isMainThread()); |
bfulgham@apple.com | 06c9628 | 2015-05-02 00:39:37 +0000 | [diff] [blame] | 653 | if (!m_page || !m_page->expectsWheelEventTriggers()) |
| 654 | return; |
| 655 | |
| 656 | if (const auto& trigger = m_page->testTrigger()) { |
| 657 | LOG(WheelEventTestTriggers, " (!) AsyncScrollingCoordinator::removeTestDeferralForReason: Deferring %p for reason %d.", identifier, reason); |
| 658 | trigger->removeTestDeferralForReason(identifier, reason); |
| 659 | } |
| 660 | } |
| 661 | #endif |
| 662 | |
bfulgham@apple.com | f5a9fff | 2015-05-19 21:58:30 +0000 | [diff] [blame] | 663 | #if ENABLE(CSS_SCROLL_SNAP) |
| 664 | bool AsyncScrollingCoordinator::isScrollSnapInProgress() const |
| 665 | { |
| 666 | return scrollingTree()->isScrollSnapInProgress(); |
| 667 | } |
wenson_hsieh@apple.com | 70bbd21 | 2015-09-29 22:56:20 +0000 | [diff] [blame] | 668 | |
| 669 | void AsyncScrollingCoordinator::updateScrollSnapPropertiesWithFrameView(const FrameView& frameView) |
| 670 | { |
| 671 | if (auto node = downcast<ScrollingStateFrameScrollingNode>(m_scrollingStateTree->stateNodeForID(frameView.scrollLayerID()))) { |
| 672 | setStateScrollingNodeSnapOffsetsAsFloat(*node, ScrollEventAxis::Horizontal, frameView.horizontalSnapOffsets(), m_page->deviceScaleFactor()); |
| 673 | setStateScrollingNodeSnapOffsetsAsFloat(*node, ScrollEventAxis::Vertical, frameView.verticalSnapOffsets(), m_page->deviceScaleFactor()); |
| 674 | node->setCurrentHorizontalSnapPointIndex(frameView.currentHorizontalSnapPointIndex()); |
| 675 | node->setCurrentVerticalSnapPointIndex(frameView.currentVerticalSnapPointIndex()); |
| 676 | } |
| 677 | } |
bfulgham@apple.com | f5a9fff | 2015-05-19 21:58:30 +0000 | [diff] [blame] | 678 | #endif |
| 679 | |
simon.fraser@apple.com | 6576a4b | 2014-01-02 19:41:45 +0000 | [diff] [blame] | 680 | } // namespace WebCore |
| 681 | |
| 682 | #endif // ENABLE(ASYNC_SCROLLING) |