Move "inProgrammaticScroll" down to ScrollableArea
authorsimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 4 Apr 2019 21:10:29 +0000 (21:10 +0000)
committersimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 4 Apr 2019 21:10:29 +0000 (21:10 +0000)
https://bugs.webkit.org/show_bug.cgi?id=196614

Reviewed by Zalan Bujtas.

A future patch will need to update "inProgrammaticScroll" on RenderLayers, so push
inProgrammaticScroll() down to ScrollableArea.

ScrollableArea already has "isScrolledProgrammatically", which I rename to "scrollShouldClearLatchedState"
to reduce confusion. It might be possible to remove this in future with some refactoring.

Sadly we can no longer use SetForScope<> in FrameView after this change so add some manual save/restore code.

* dom/Element.cpp:
(WebCore::Element::setScrollLeft):
(WebCore::Element::setScrollTop):
* page/EventHandler.cpp:
(WebCore::EventHandler::completeWidgetWheelEvent):
(WebCore::EventHandler::handleWheelEvent):
* page/FrameView.cpp:
(WebCore::FrameView::setFrameRect):
(WebCore::FrameView::topContentInsetDidChange):
(WebCore::FrameView::updateLayoutViewport):
(WebCore::FrameView::setScrollPosition):
(WebCore::FrameView::setWasScrolledByUser):
* page/FrameView.h:
* platform/ScrollView.h:
(WebCore::ScrollView::inProgrammaticScroll const): Deleted.
* platform/ScrollableArea.cpp:
(WebCore::ScrollableArea::ScrollableArea):
* platform/ScrollableArea.h:
(WebCore::ScrollableArea::inProgrammaticScroll const):
(WebCore::ScrollableArea::setInProgrammaticScroll):
(WebCore::ScrollableArea::scrollShouldClearLatchedState const):
(WebCore::ScrollableArea::setScrollShouldClearLatchedState):
(WebCore::ScrollableArea::isScrolledProgrammatically const): Deleted.
(WebCore::ScrollableArea::setScrolledProgrammatically): Deleted.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@243905 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/dom/Element.cpp
Source/WebCore/page/EventHandler.cpp
Source/WebCore/page/FrameView.cpp
Source/WebCore/page/FrameView.h
Source/WebCore/platform/ScrollView.h
Source/WebCore/platform/ScrollableArea.cpp
Source/WebCore/platform/ScrollableArea.h

index d66d731..4cc53b1 100644 (file)
@@ -1,3 +1,43 @@
+2019-04-04  Simon Fraser  <simon.fraser@apple.com>
+
+        Move "inProgrammaticScroll" down to ScrollableArea
+        https://bugs.webkit.org/show_bug.cgi?id=196614
+
+        Reviewed by Zalan Bujtas.
+
+        A future patch will need to update "inProgrammaticScroll" on RenderLayers, so push
+        inProgrammaticScroll() down to ScrollableArea.
+
+        ScrollableArea already has "isScrolledProgrammatically", which I rename to "scrollShouldClearLatchedState"
+        to reduce confusion. It might be possible to remove this in future with some refactoring.
+
+        Sadly we can no longer use SetForScope<> in FrameView after this change so add some manual save/restore code.
+
+        * dom/Element.cpp:
+        (WebCore::Element::setScrollLeft):
+        (WebCore::Element::setScrollTop):
+        * page/EventHandler.cpp:
+        (WebCore::EventHandler::completeWidgetWheelEvent):
+        (WebCore::EventHandler::handleWheelEvent):
+        * page/FrameView.cpp:
+        (WebCore::FrameView::setFrameRect):
+        (WebCore::FrameView::topContentInsetDidChange):
+        (WebCore::FrameView::updateLayoutViewport):
+        (WebCore::FrameView::setScrollPosition):
+        (WebCore::FrameView::setWasScrolledByUser):
+        * page/FrameView.h:
+        * platform/ScrollView.h:
+        (WebCore::ScrollView::inProgrammaticScroll const): Deleted.
+        * platform/ScrollableArea.cpp:
+        (WebCore::ScrollableArea::ScrollableArea):
+        * platform/ScrollableArea.h:
+        (WebCore::ScrollableArea::inProgrammaticScroll const):
+        (WebCore::ScrollableArea::setInProgrammaticScroll):
+        (WebCore::ScrollableArea::scrollShouldClearLatchedState const):
+        (WebCore::ScrollableArea::setScrollShouldClearLatchedState):
+        (WebCore::ScrollableArea::isScrolledProgrammatically const): Deleted.
+        (WebCore::ScrollableArea::setScrolledProgrammatically): Deleted.
+
 2019-04-04  Sihui Liu  <sihui_liu@apple.com>
 
         Leak of UniqueIDBDatabase in network process running layout tests
index 79f086c..a423625 100644 (file)
@@ -1140,7 +1140,7 @@ void Element::setScrollLeft(int newLeft)
     if (auto* renderer = renderBox()) {
         renderer->setScrollLeft(static_cast<int>(newLeft * renderer->style().effectiveZoom()), ScrollType::Programmatic);
         if (auto* scrollableArea = renderer->layer())
-            scrollableArea->setScrolledProgrammatically(true);
+            scrollableArea->setScrollShouldClearLatchedState(true);
     }
 }
 
@@ -1157,7 +1157,7 @@ void Element::setScrollTop(int newTop)
     if (auto* renderer = renderBox()) {
         renderer->setScrollTop(static_cast<int>(newTop * renderer->style().effectiveZoom()), ScrollType::Programmatic);
         if (auto* scrollableArea = renderer->layer())
-            scrollableArea->setScrolledProgrammatically(true);
+            scrollableArea->setScrollShouldClearLatchedState(true);
     }
 }
 
index 9339236..369e381 100644 (file)
@@ -2749,7 +2749,7 @@ bool EventHandler::completeWidgetWheelEvent(const PlatformWheelEvent& event, con
         return false;
     
     if (scrollableArea)
-        scrollableArea->setScrolledProgrammatically(false);
+        scrollableArea->setScrollShouldClearLatchedState(false);
 
     platformNotifyIfEndGesture(event, scrollableArea);
 
@@ -2812,10 +2812,10 @@ bool EventHandler::handleWheelEvent(const PlatformWheelEvent& event)
 
         if (!element->dispatchWheelEvent(adjustedEvent)) {
             m_isHandlingWheelEvent = false;
-            if (scrollableArea && scrollableArea->isScrolledProgrammatically()) {
+            if (scrollableArea && scrollableArea->scrollShouldClearLatchedState()) {
                 // Web developer is controlling scrolling, so don't attempt to latch.
                 clearLatchedState();
-                scrollableArea->setScrolledProgrammatically(false);
+                scrollableArea->setScrollShouldClearLatchedState(false);
             }
 
             platformNotifyIfEndGesture(adjustedEvent, scrollableArea);
@@ -2824,7 +2824,7 @@ bool EventHandler::handleWheelEvent(const PlatformWheelEvent& event)
     }
 
     if (scrollableArea)
-        scrollableArea->setScrolledProgrammatically(false);
+        scrollableArea->setScrollShouldClearLatchedState(false);
 
     bool handledEvent = platformCompleteWheelEvent(adjustedEvent, scrollableContainer.get(), scrollableArea);
     platformNotifyIfEndGesture(adjustedEvent, scrollableArea);
index 11159ee..c08c64b 100644 (file)
@@ -460,7 +460,8 @@ void FrameView::setFrameRect(const IntRect& newRect)
     if (newRect == oldRect)
         return;
     // Every scroll that happens as the result of frame size change is programmatic.
-    SetForScope<bool> changeInProgrammaticScroll(m_inProgrammaticScroll, true);
+    bool wasInProgrammaticScroll = inProgrammaticScroll();
+    setInProgrammaticScroll(true);
     ScrollView::setFrameRect(newRect);
 
     updateScrollableAreaSet();
@@ -474,6 +475,7 @@ void FrameView::setFrameRect(const IntRect& newRect)
         frame().page()->pageOverlayController().didChangeViewSize();
 
     viewportContentsChanged();
+    setInProgrammaticScroll(wasInProgrammaticScroll);
 }
 
 bool FrameView::scheduleAnimation()
@@ -1090,13 +1092,16 @@ void FrameView::topContentInsetDidChange(float newTopContentInset)
     
     layoutContext().layout();
     // Every scroll that happens as the result of content inset change is programmatic.
-    SetForScope<bool> changeInProgrammaticScroll(m_inProgrammaticScroll, true);
+    bool wasInProgrammaticScroll = inProgrammaticScroll();
+    setInProgrammaticScroll(true);
     updateScrollbars(scrollPosition());
     if (renderView->usesCompositing())
         renderView->compositor().frameViewDidChangeSize();
 
     if (TiledBacking* tiledBacking = this->tiledBacking())
         tiledBacking->setTopContentInset(newTopContentInset);
+
+    setInProgrammaticScroll(wasInProgrammaticScroll);
 }
 
 void FrameView::topContentDirectionDidChange()
@@ -1670,7 +1675,7 @@ void FrameView::updateLayoutViewport()
     LOG_WITH_STREAM(Scrolling, stream << "stable origins: min: " << minStableLayoutViewportOrigin() << " max: "<< maxStableLayoutViewportOrigin());
     
     if (m_layoutViewportOverrideRect) {
-        if (m_inProgrammaticScroll) {
+        if (inProgrammaticScroll()) {
             LOG_WITH_STREAM(Scrolling, stream << "computing new override layout viewport because of programmatic scrolling");
             LayoutPoint newOrigin = computeLayoutViewportOrigin(visualViewportRect(), minStableLayoutViewportOrigin(), maxStableLayoutViewportOrigin(), layoutViewport, StickToDocumentBounds);
             setLayoutViewportOverrideRect(LayoutRect(newOrigin, m_layoutViewportOverrideRect.value().size()));
@@ -2274,7 +2279,9 @@ void FrameView::setScrollPosition(const ScrollPosition& scrollPosition)
 {
     LOG_WITH_STREAM(Scrolling, stream << "FrameView::setScrollPosition " << scrollPosition << " , clearing anchor");
 
-    SetForScope<bool> changeInProgrammaticScroll(m_inProgrammaticScroll, true);
+    bool wasInProgrammaticScroll = inProgrammaticScroll();
+    setInProgrammaticScroll(true);
+
     m_maintainScrollPositionAnchor = nullptr;
     m_shouldScrollToFocusedElement = false;
     m_delayedScrollToFocusedElementTimer.stop();
@@ -2282,6 +2289,8 @@ void FrameView::setScrollPosition(const ScrollPosition& scrollPosition)
     if (page && page->expectsWheelEventTriggers())
         scrollAnimator().setWheelEventTestTrigger(page->testTrigger());
     ScrollView::setScrollPosition(scrollPosition);
+
+    setInProgrammaticScroll(wasInProgrammaticScroll);
 }
 
 void FrameView::resetScrollAnchor()
@@ -4100,7 +4109,7 @@ void FrameView::setWasScrolledByUser(bool wasScrolledByUser)
 
     m_shouldScrollToFocusedElement = false;
     m_delayedScrollToFocusedElementTimer.stop();
-    if (m_inProgrammaticScroll)
+    if (inProgrammaticScroll())
         return;
     m_maintainScrollPositionAnchor = nullptr;
     if (m_wasScrolledByUser == wasScrolledByUser)
index c3f8843..55f2a67 100644 (file)
@@ -555,9 +555,6 @@ public:
     const Pagination& pagination() const;
     void setPagination(const Pagination&);
     
-    bool inProgrammaticScroll() const final { return m_inProgrammaticScroll; }
-    void setInProgrammaticScroll(bool programmaticScroll) { m_inProgrammaticScroll = programmaticScroll; }
-
 #if ENABLE(CSS_DEVICE_ADAPTATION)
     IntSize initialViewportSize() const { return m_initialViewportSize; }
     void setInitialViewportSize(const IntSize& size) { m_initialViewportSize = size; }
@@ -923,7 +920,6 @@ private:
 
     bool m_isTrackingRepaints { false }; // Used for testing.
     bool m_wasScrolledByUser { false };
-    bool m_inProgrammaticScroll { false };
     bool m_shouldScrollToFocusedElement { false };
 
     bool m_isPainting { false };
index 87bca2d..8eb4683 100644 (file)
@@ -196,8 +196,6 @@ public:
     LegacyTileCache* legacyTileCache();
 #endif
 
-    virtual bool inProgrammaticScroll() const { return false; }
-
     // Size available for view contents, including content inset areas. Not affected by zooming.
     IntSize sizeForVisibleContent(VisibleContentRectIncludesScrollbars = ExcludeScrollbars) const;
     // FIXME: remove this. It's only used for the incorrectly behaving ScrollView::unobscuredContentRectInternal().
index e95f23a..7459cde 100644 (file)
@@ -66,7 +66,8 @@ ScrollableArea::ScrollableArea()
     , m_horizontalScrollElasticity(ScrollElasticityNone)
     , m_scrollbarOverlayStyle(ScrollbarOverlayStyleDefault)
     , m_scrollOriginChanged(false)
-    , m_scrolledProgrammatically(false)
+    , m_inProgrammaticScroll(false)
+    , m_scrollShouldClearLatchedState(false)
 {
 }
 
index 2136139..f0a00b6 100644 (file)
@@ -228,8 +228,11 @@ public:
     WEBCORE_EXPORT virtual bool scrolledToLeft() const;
     WEBCORE_EXPORT virtual bool scrolledToRight() const;
 
-    bool isScrolledProgrammatically() const { return m_scrolledProgrammatically; }
-    void setScrolledProgrammatically(bool state) { m_scrolledProgrammatically = state; }
+    bool inProgrammaticScroll() const { return m_inProgrammaticScroll; }
+    void setInProgrammaticScroll(bool inProgrammaticScroll) { m_inProgrammaticScroll = inProgrammaticScroll; }
+
+    bool scrollShouldClearLatchedState() const { return m_scrollShouldClearLatchedState; }
+    void setScrollShouldClearLatchedState(bool shouldClear) { m_scrollShouldClearLatchedState = shouldClear; }
 
     enum VisibleContentRectIncludesScrollbars { ExcludeScrollbars, IncludeScrollbars };
     enum VisibleContentRectBehavior {
@@ -391,7 +394,8 @@ private:
     unsigned m_scrollbarOverlayStyle : 2; // ScrollbarOverlayStyle
 
     unsigned m_scrollOriginChanged : 1;
-    unsigned m_scrolledProgrammatically : 1;
+    unsigned m_inProgrammaticScroll : 1;
+    unsigned m_scrollShouldClearLatchedState : 1;
 };
 
 } // namespace WebCore