[ContentChangeObserver] Cleanup adjustObservedState
authorzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 8 Mar 2019 22:12:46 +0000 (22:12 +0000)
committerzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 8 Mar 2019 22:12:46 +0000 (22:12 +0000)
https://bugs.webkit.org/show_bug.cgi?id=195470
<rdar://problem/48717823>

Reviewed by Simon Fraser.

This is in preparation for introducing an observation window from touchStart -> mouseMoved.
1. Cancel pending activities (future timers, pending stylesheet recalcs) when visible content change is detected.
2. The fixed time window takes care of notifying the client -timers, style recalcs during the window should not signal themselves.
3. Reset m_isObservingPendingStyleRecalc at StartedStyleRecalc instead of EndedStyleRecalc.

* page/ios/ContentChangeObserver.cpp:
(WebCore::ContentChangeObserver::domTimerExecuteDidFinish):
(WebCore::ContentChangeObserver::styleRecalcDidStart):
(WebCore::ContentChangeObserver::styleRecalcDidFinish):
(WebCore::ContentChangeObserver::adjustObservedState):
* page/ios/ContentChangeObserver.h:
(WebCore::ContentChangeObserver::hasPendingActivity const):
(WebCore::ContentChangeObserver::isObservationTimeWindowActive const):

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

Source/WebCore/ChangeLog
Source/WebCore/page/ios/ContentChangeObserver.cpp
Source/WebCore/page/ios/ContentChangeObserver.h

index 2f97ec8..81c389d 100644 (file)
@@ -1,5 +1,27 @@
 2019-03-08  Zalan Bujtas  <zalan@apple.com>
 
+        [ContentChangeObserver] Cleanup adjustObservedState
+        https://bugs.webkit.org/show_bug.cgi?id=195470
+        <rdar://problem/48717823>
+
+        Reviewed by Simon Fraser.
+
+        This is in preparation for introducing an observation window from touchStart -> mouseMoved.
+        1. Cancel pending activities (future timers, pending stylesheet recalcs) when visible content change is detected.
+        2. The fixed time window takes care of notifying the client -timers, style recalcs during the window should not signal themselves.  
+        3. Reset m_isObservingPendingStyleRecalc at StartedStyleRecalc instead of EndedStyleRecalc. 
+
+        * page/ios/ContentChangeObserver.cpp:
+        (WebCore::ContentChangeObserver::domTimerExecuteDidFinish):
+        (WebCore::ContentChangeObserver::styleRecalcDidStart):
+        (WebCore::ContentChangeObserver::styleRecalcDidFinish):
+        (WebCore::ContentChangeObserver::adjustObservedState):
+        * page/ios/ContentChangeObserver.h:
+        (WebCore::ContentChangeObserver::hasPendingActivity const):
+        (WebCore::ContentChangeObserver::isObservationTimeWindowActive const):
+
+2019-03-08  Zalan Bujtas  <zalan@apple.com>
+
         [ContentChangeObserver] Add StartedDOMTimerExecution and StartedStyleRecalc
         https://bugs.webkit.org/show_bug.cgi?id=195463
         <rdar://problem/48714762>
index 72b8d6a..b1b1af0 100644 (file)
@@ -93,19 +93,18 @@ void ContentChangeObserver::domTimerExecuteDidStart(const DOMTimer& timer)
         return;
     LOG_WITH_STREAM(ContentObservation, stream << "startObservingDOMTimerExecute: start observing (" << &timer << ") timer callback.");
 
-    m_domTimerIsBeingExecuted = true;
+    m_observedDomTimerIsBeingExecuted = true;
     adjustObservedState(Event::StartedDOMTimerExecution);
 }
 
 void ContentChangeObserver::domTimerExecuteDidFinish(const DOMTimer& timer)
 {
-    if (!containsObservedDOMTimer(timer))
+    if (!m_observedDomTimerIsBeingExecuted)
         return;
     LOG_WITH_STREAM(ContentObservation, stream << "stopObservingDOMTimerExecute: stop observing (" << &timer << ") timer callback.");
 
-    m_domTimerIsBeingExecuted = false;
+    m_observedDomTimerIsBeingExecuted = false;
     unregisterDOMTimer(timer);
-    setShouldObserveNextStyleRecalc(m_document.hasPendingStyleRecalc());
     adjustObservedState(Event::EndedDOMTimerExecution);
 }
 
@@ -113,21 +112,19 @@ void ContentChangeObserver::styleRecalcDidStart()
 {
     if (!isWaitingForStyleRecalc())
         return;
-    if (hasVisibleChangeState())
-        return;
     LOG(ContentObservation, "startObservingStyleRecalc: start observing style recalc.");
 
-    m_styleRecalcIsBeingExecuted = true;
+    m_isInObservedStyleRecalc = true;
     adjustObservedState(Event::StartedStyleRecalc);
 }
 
 void ContentChangeObserver::styleRecalcDidFinish()
 {
-    if (!isWaitingForStyleRecalc())
+    if (!m_isInObservedStyleRecalc)
         return;
     LOG(ContentObservation, "stopObservingStyleRecalc: stop observing style recalc");
 
-    m_styleRecalcIsBeingExecuted = false;
+    m_isInObservedStyleRecalc = false;
     adjustObservedState(Event::EndedStyleRecalc);
 }
 
@@ -229,7 +226,11 @@ bool ContentChangeObserver::isNotifyContentChangeAllowed() const
 
 void ContentChangeObserver::adjustObservedState(Event event)
 {
-    auto notifyContentChangeIfNeeded = [&] {
+    auto adjustStateAndNotifyContentChangeIfNeeded = [&] {
+        // Demote to "no change" when there's no pending activity anymore.
+        if (observedContentChange() == WKContentIndeterminateChange && !hasPendingActivity())
+            setHasNoChangeState();
+
         if (!hasDeterminateState()) {
             LOG(ContentObservation, "notifyContentChangeIfNeeded: not in a determined state yet.");
             return;
@@ -248,6 +249,9 @@ void ContentChangeObserver::adjustObservedState(Event event)
         m_isMouseMovedPrecededByTouch = true;
         setShouldObserveDOMTimerScheduling(true);
         break;
+    case Event::EndedTouchStartEventDispatching:
+        setShouldObserveDOMTimerScheduling(false);
+        break;
     case Event::StartedMouseMovedEventDispatching:
         ASSERT(!m_document.hasPendingStyleRecalc());
         if (!m_isMouseMovedPrecededByTouch) {
@@ -257,33 +261,36 @@ void ContentChangeObserver::adjustObservedState(Event event)
         setShouldObserveDOMTimerScheduling(true);
         m_isMouseMovedPrecededByTouch = false;
         break;
-    case Event::StartedDOMTimerExecution:
-    case Event::StartedStyleRecalc:
-        ASSERT(observedContentChange() == WKContentIndeterminateChange);
-        break;
-    case Event::EndedTouchStartEventDispatching:
     case Event::EndedMouseMovedEventDispatching:
         setShouldObserveDOMTimerScheduling(false);
         break;
+    case Event::StartedStyleRecalc:
+        setShouldObserveNextStyleRecalc(false);
+        FALLTHROUGH;
+    case Event::StartedDOMTimerExecution:
+        ASSERT(isObservationTimeWindowActive() || observedContentChange() == WKContentIndeterminateChange);
+        break;
     case Event::InstalledDOMTimer:
     case Event::StartedFixedObservationTimeWindow:
-        // Expecting a timer fire. Promote to an indeterminate state.
         ASSERT(!hasVisibleChangeState());
         setHasIndeterminateState();
         break;
-    case Event::EndedStyleRecalc:
-        setShouldObserveNextStyleRecalc(false);
+    case Event::EndedDOMTimerExecution:
+        setShouldObserveNextStyleRecalc(m_document.hasPendingStyleRecalc());
         FALLTHROUGH;
+    case Event::EndedStyleRecalc:
     case Event::RemovedDOMTimer:
-    case Event::EndedDOMTimerExecution:
+        if (!isObservationTimeWindowActive())
+            adjustStateAndNotifyContentChangeIfNeeded();
+        break;
     case Event::EndedFixedObservationTimeWindow:
-        // Demote to "no change" when there's no pending activity anymore.
-        if (observedContentChange() == WKContentIndeterminateChange && !hasPendingActivity())
-            setHasNoChangeState();
-        notifyContentChangeIfNeeded();
+        adjustStateAndNotifyContentChangeIfNeeded();
         break;
     case Event::ContentVisibilityChanged:
         setHasVisibleChangeState();
+        // Remove pending activities. We don't need to observe them anymore.
+        setShouldObserveNextStyleRecalc(false);
+        clearObservedDOMTimers();
         break;
     }
 }
index 712603b..5234a9b 100644 (file)
@@ -119,7 +119,7 @@ private:
     void setShouldObserveNextStyleRecalc(bool);
     bool isWaitingForStyleRecalc() const { return m_isWaitingForStyleRecalc; }
 
-    bool isObservingContentChanges() const { return m_mouseMovedEventIsBeingDispatched || m_touchEventIsBeingDispatched || m_domTimerIsBeingExecuted || m_styleRecalcIsBeingExecuted || m_contentObservationTimer.isActive(); }
+    bool isObservingContentChanges() const { return m_mouseMovedEventIsBeingDispatched || m_touchEventIsBeingDispatched || m_observedDomTimerIsBeingExecuted || m_isInObservedStyleRecalc || m_contentObservationTimer.isActive(); }
 
     void cancelPendingActivities();
 
@@ -131,7 +131,8 @@ private:
     bool hasObservedDOMTimer() const { return !m_DOMTimerList.isEmpty(); }
     bool hasDeterminateState() const;
 
-    bool hasPendingActivity() const { return hasObservedDOMTimer() || m_document.hasPendingStyleRecalc() || m_contentObservationTimer.isActive(); }
+    bool hasPendingActivity() const { return hasObservedDOMTimer() || m_document.hasPendingStyleRecalc() || isObservationTimeWindowActive(); }
+    bool isObservationTimeWindowActive() const { return m_contentObservationTimer.isActive(); }
 #if !ASSERT_DISABLED
     bool isNotifyContentChangeAllowed() const;
 #endif
@@ -160,9 +161,9 @@ private:
     HashSet<const DOMTimer*> m_DOMTimerList;
     bool m_touchEventIsBeingDispatched { false };
     bool m_isWaitingForStyleRecalc { false };
-    bool m_styleRecalcIsBeingExecuted { false };
+    bool m_isInObservedStyleRecalc { false };
     bool m_isObservingDOMTimerScheduling { false };
-    bool m_domTimerIsBeingExecuted { false };
+    bool m_observedDomTimerIsBeingExecuted { false };
     bool m_isMouseMovedPrecededByTouch { false };
     bool m_mouseMovedEventIsBeingDispatched { false };
 };