[ContentChangeObserver] Send content change notification through adjustObservedState
authorzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 5 Mar 2019 21:52:41 +0000 (21:52 +0000)
committerzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 5 Mar 2019 21:52:41 +0000 (21:52 +0000)
https://bugs.webkit.org/show_bug.cgi?id=195328
<rdar://problem/48601143>

Reviewed by Simon Fraser.

Have a dedicated place for the notification logic.

* page/ios/ContentChangeObserver.cpp:
(WebCore::ContentChangeObserver::stopDurationBasedContentObservation):
(WebCore::ContentChangeObserver::didInstallDOMTimer):
(WebCore::ContentChangeObserver::didRemoveDOMTimer):
(WebCore::ContentChangeObserver::domTimerExecuteDidFinish):
(WebCore::ContentChangeObserver::styleRecalcDidFinish):
(WebCore::ContentChangeObserver::mouseMovedDidStart):
(WebCore::ContentChangeObserver::adjustObservedState):
(WebCore::ContentChangeObserver::registerDOMTimer): Deleted.
(WebCore::ContentChangeObserver::unregisterDOMTimer): Deleted.
(WebCore::ContentChangeObserver::notifyContentChangeIfNeeded): Deleted.
* page/ios/ContentChangeObserver.h:
(WebCore::ContentChangeObserver::registerDOMTimer):
(WebCore::ContentChangeObserver::unregisterDOMTimer):

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

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

index 8ef10b2..edbf5e4 100644 (file)
@@ -1,3 +1,28 @@
+2019-03-05  Zalan Bujtas  <zalan@apple.com>
+
+        [ContentChangeObserver] Send content change notification through adjustObservedState
+        https://bugs.webkit.org/show_bug.cgi?id=195328
+        <rdar://problem/48601143>
+
+        Reviewed by Simon Fraser.
+
+        Have a dedicated place for the notification logic.
+
+        * page/ios/ContentChangeObserver.cpp:
+        (WebCore::ContentChangeObserver::stopDurationBasedContentObservation):
+        (WebCore::ContentChangeObserver::didInstallDOMTimer):
+        (WebCore::ContentChangeObserver::didRemoveDOMTimer):
+        (WebCore::ContentChangeObserver::domTimerExecuteDidFinish):
+        (WebCore::ContentChangeObserver::styleRecalcDidFinish):
+        (WebCore::ContentChangeObserver::mouseMovedDidStart):
+        (WebCore::ContentChangeObserver::adjustObservedState):
+        (WebCore::ContentChangeObserver::registerDOMTimer): Deleted.
+        (WebCore::ContentChangeObserver::unregisterDOMTimer): Deleted.
+        (WebCore::ContentChangeObserver::notifyContentChangeIfNeeded): Deleted.
+        * page/ios/ContentChangeObserver.h:
+        (WebCore::ContentChangeObserver::registerDOMTimer):
+        (WebCore::ContentChangeObserver::unregisterDOMTimer):
+
 2019-03-05  Youenn Fablet  <youenn@apple.com>
 
         MockLibWebRTCPeerConnection is leaking some session description
index 8b1cfe2..87e888a 100644 (file)
@@ -54,6 +54,7 @@ void ContentChangeObserver::didInstallDOMTimer(const DOMTimer& timer, Seconds ti
     LOG_WITH_STREAM(ContentObservation, stream << "didInstallDOMTimer: register this timer: (" << &timer << ") and observe when it fires.");
 
     registerDOMTimer(timer);
+    adjustObservedState(Event::InstalledDOMTimer);
 }
 
 void ContentChangeObserver::didRemoveDOMTimer(const DOMTimer& timer)
@@ -63,7 +64,7 @@ void ContentChangeObserver::didRemoveDOMTimer(const DOMTimer& timer)
     LOG_WITH_STREAM(ContentObservation, stream << "removeDOMTimer: remove registered timer (" << &timer << ")");
 
     unregisterDOMTimer(timer);
-    notifyContentChangeIfNeeded();
+    adjustObservedState(Event::RemovedDOMTimer);
 }
 
 void ContentChangeObserver::domTimerExecuteDidStart(const DOMTimer& timer)
@@ -84,7 +85,7 @@ void ContentChangeObserver::domTimerExecuteDidFinish(const DOMTimer& timer)
     m_domTimerisBeingExecuted = false;
     unregisterDOMTimer(timer);
     setShouldObserveNextStyleRecalc(m_document.hasPendingStyleRecalc());
-    notifyContentChangeIfNeeded();
+    adjustObservedState(Event::EndedDOMTimerExecution);
 }
 
 void ContentChangeObserver::styleRecalcDidStart()
@@ -107,7 +108,6 @@ void ContentChangeObserver::styleRecalcDidFinish()
     m_styleRecalcIsBeingExecuted = false;
     setShouldObserveNextStyleRecalc(false);
     adjustObservedState(Event::StyleRecalcFinished);
-    notifyContentChangeIfNeeded();
 }
 
 void ContentChangeObserver::clearTimersAndReportContentChange()
@@ -143,7 +143,7 @@ void ContentChangeObserver::mouseMovedDidStart()
     ASSERT(!m_document.hasPendingStyleRecalc());
     clearObservedDOMTimers();
     setShouldObserveDOMTimerScheduling(true);
-    adjustObservedState(Event::ContentObservationStarted);
+    adjustObservedState(Event::StartedMouseMovedEventDispatching);
 }
 
 void ContentChangeObserver::mouseMovedDidFinish()
@@ -156,18 +156,6 @@ WKContentChange ContentChangeObserver::observedContentChange() const
     return WKObservedContentChange();
 }
 
-void ContentChangeObserver::registerDOMTimer(const DOMTimer& timer)
-{
-    m_DOMTimerList.add(&timer);
-    adjustObservedState(Event::InstalledDOMTimer);
-}
-
-void ContentChangeObserver::unregisterDOMTimer(const DOMTimer& timer)
-{
-    m_DOMTimerList.remove(&timer);
-    adjustObservedState(Event::RemovedDOMTimer);
-}
-
 void ContentChangeObserver::setShouldObserveNextStyleRecalc(bool shouldObserve)
 {
     if (shouldObserve)
@@ -179,13 +167,24 @@ bool ContentChangeObserver::hasDeterminateState() const
 {
     if (hasVisibleChangeState())
         return true;
-    return observedContentChange() == WKContentNoChange && !hasObservedDOMTimer() && !m_document.hasPendingStyleRecalc();
+    return observedContentChange() == WKContentNoChange && !hasPendingActivity();
 }
 
 void ContentChangeObserver::adjustObservedState(Event event)
 {
+    auto notifyContentChangeIfNeeded = [&] {
+        if (!hasDeterminateState()) {
+            LOG(ContentObservation, "notifyContentChangeIfNeeded: not in a determined state yet.");
+            return;
+        }
+        LOG_WITH_STREAM(ContentObservation, stream << "notifyContentChangeIfNeeded: sending observedContentChange ->" << observedContentChange());
+        ASSERT(m_document.page());
+        ASSERT(m_document.frame());
+        m_document.page()->chrome().client().observedContentChange(*m_document.frame());
+    };
+
     switch (event) {
-    case Event::ContentObservationStarted:
+    case Event::StartedMouseMovedEventDispatching:
         setHasNoChangeState();
         break;
     case Event::InstalledDOMTimer:
@@ -195,9 +194,11 @@ void ContentChangeObserver::adjustObservedState(Event event)
         break;
     case Event::RemovedDOMTimer:
     case Event::StyleRecalcFinished:
+    case Event::EndedDOMTimerExecution:
         // Demote to "no change" when there's no pending activity anymore.
-        if (observedContentChange() == WKContentIndeterminateChange && !hasObservedDOMTimer() && !m_document.hasPendingStyleRecalc())
+        if (observedContentChange() == WKContentIndeterminateChange && !hasPendingActivity())
             setHasNoChangeState();
+        notifyContentChangeIfNeeded();
         break;
     case Event::ContentVisibilityChanged:
         setHasVisibleChangeState();
@@ -205,19 +206,6 @@ void ContentChangeObserver::adjustObservedState(Event event)
     }
 }
 
-void ContentChangeObserver::notifyContentChangeIfNeeded()
-{
-    if (!hasDeterminateState()) {
-        LOG(ContentObservation, "notifyContentChangeIfNeeded: not in a determined state yet.");
-        return;
-    }
-    LOG_WITH_STREAM(ContentObservation, stream << "notifyContentChangeIfNeeded: sending observedContentChange ->" << observedContentChange());
-    ASSERT(m_document.page());
-    ASSERT(m_document.frame());
-    m_document.page()->chrome().client().observedContentChange(*m_document.frame());
-}
-
-
 static Visibility elementImplicitVisibility(const Element& element)
 {
     auto* renderer = element.renderer();
index 23d1250..0e01ea1 100644 (file)
@@ -93,8 +93,8 @@ private:
     bool isObservingDOMTimerScheduling() const { return m_isObservingDOMTimerScheduling; }
     void domTimerExecuteDidStart(const DOMTimer&);
     void domTimerExecuteDidFinish(const DOMTimer&);
-    void registerDOMTimer(const DOMTimer&);
-    void unregisterDOMTimer(const DOMTimer&);
+    void registerDOMTimer(const DOMTimer& timer) { m_DOMTimerList.add(&timer); }
+    void unregisterDOMTimer(const DOMTimer& timer) { m_DOMTimerList.remove(&timer); }
     bool containsObservedDOMTimer(const DOMTimer& timer) const { return m_DOMTimerList.contains(&timer); }
 
     void styleRecalcDidStart();
@@ -115,12 +115,13 @@ private:
     bool hasObservedDOMTimer() const { return !m_DOMTimerList.isEmpty(); }
     bool hasDeterminateState() const;
 
-    void notifyContentChangeIfNeeded();
+    bool hasPendingActivity() const { return hasObservedDOMTimer() || m_document.hasPendingStyleRecalc(); }
 
     enum class Event {
-        ContentObservationStarted,
+        StartedMouseMovedEventDispatching,
         InstalledDOMTimer,
         RemovedDOMTimer,
+        EndedDOMTimerExecution,
         StyleRecalcFinished,
         ContentVisibilityChanged
     };