[ContentChangeObserver] Move observing logic from Document::updateStyleIfNeeded to...
authorzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 26 Feb 2019 18:28:42 +0000 (18:28 +0000)
committerzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 26 Feb 2019 18:28:42 +0000 (18:28 +0000)
https://bugs.webkit.org/show_bug.cgi?id=195032
<rdar://problem/48388063>

Reviewed by Tim Horton.

This might eventually turn into a regular start/stop content observing call.

* dom/Document.cpp:
(WebCore::Document::updateStyleIfNeeded):
* page/ios/ContentChangeObserver.h:
* page/ios/ContentChangeObserver.mm:
(WebCore::ContentChangeObserver::startObservingStyleResolve):
(WebCore::ContentChangeObserver::stopObservingStyleResolve):

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

Source/WebCore/ChangeLog
Source/WebCore/dom/Document.cpp
Source/WebCore/page/ios/ContentChangeObserver.h
Source/WebCore/page/ios/ContentChangeObserver.mm

index 502f8e8..f01b70b 100644 (file)
@@ -1,5 +1,22 @@
 2019-02-26  Zalan Bujtas  <zalan@apple.com>
 
+        [ContentChangeObserver] Move observing logic from Document::updateStyleIfNeeded to ContentChangeObserver
+        https://bugs.webkit.org/show_bug.cgi?id=195032
+        <rdar://problem/48388063>
+
+        Reviewed by Tim Horton.
+
+        This might eventually turn into a regular start/stop content observing call.
+
+        * dom/Document.cpp:
+        (WebCore::Document::updateStyleIfNeeded):
+        * page/ios/ContentChangeObserver.h:
+        * page/ios/ContentChangeObserver.mm:
+        (WebCore::ContentChangeObserver::startObservingStyleResolve):
+        (WebCore::ContentChangeObserver::stopObservingStyleResolve):
+
+2019-02-26  Zalan Bujtas  <zalan@apple.com>
+
         [ContentChangeObserver] Move CheckForVisibilityChange to ContentChangeObserver class
         https://bugs.webkit.org/show_bug.cgi?id=195035
         <rdar://problem/48389123>
index 9c38d7d..9f9edd3 100644 (file)
@@ -2050,16 +2050,8 @@ bool Document::updateStyleIfNeeded()
     }
 
 #if PLATFORM(IOS_FAMILY)
-    auto observingContentChange = false;
-    if (auto* page = this->page()) {
-        auto& contentChangeObserver = page->contentChangeObserver();
-        observingContentChange = contentChangeObserver.shouldObserveNextStyleRecalc();
-        if (observingContentChange) {
-            LOG_WITH_STREAM(ContentObservation, stream << "Document(" << this << ")::scheduleStyleRecalc: start observing content change.");
-            contentChangeObserver.setShouldObserveNextStyleRecalc(false);
-            contentChangeObserver.startObservingContentChanges();
-        }
-    }
+    if (auto* page = this->page())
+        page->contentChangeObserver().startObservingStyleResolve();
 #endif
     // The early exit above for !needsStyleRecalc() is needed when updateWidgetPositions() is called in runOrScheduleAsynchronousTasks().
     RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(isSafeToUpdateStyleOrLayout(*this));
@@ -2067,19 +2059,8 @@ bool Document::updateStyleIfNeeded()
     resolveStyle();
 
 #if PLATFORM(IOS_FAMILY)
-    if (observingContentChange && page()) {
-        LOG_WITH_STREAM(ContentObservation, stream << "Document(" << this << ")::scheduleStyleRecalc: stop observing content change.");
-        auto& contentChangeObserver = page()->contentChangeObserver();
-        contentChangeObserver.stopObservingContentChanges();
-
-        auto inDeterminedState = contentChangeObserver.observedContentChange() == WKContentVisibilityChange || !contentChangeObserver.countOfObservedDOMTimers();  
-        if (inDeterminedState) {
-            LOG_WITH_STREAM(ContentObservation, stream << "Document(" << this << ")::scheduleStyleRecalc: notify the pending synthetic click handler.");
-            page()->chrome().client().observedContentChange(*frame());
-        } else {
-            LOG_WITH_STREAM(ContentObservation, stream << "Document(" << this << ")::scheduleStyleRecalc: can't decided it yet.");
-        }
-    }
+    if (auto* page = this->page())
+        page->contentChangeObserver().stopObservingStyleResolve();
 #endif
     return true;
 }
index 92a7ad2..6db24b6 100644 (file)
@@ -43,6 +43,9 @@ public:
     void startObservingDOMTimerExecute(const DOMTimer&);
     void stopObservingDOMTimerExecute(const DOMTimer&);
 
+    void startObservingStyleResolve();
+    void stopObservingStyleResolve();
+
     WEBCORE_EXPORT void startObservingContentChanges();
     WEBCORE_EXPORT void stopObservingContentChanges();
 
index fb9d564..789a5aa 100644 (file)
@@ -86,6 +86,29 @@ void ContentChangeObserver::stopObservingDOMTimerExecute(const DOMTimer& timer)
     }
 }
 
+void ContentChangeObserver::startObservingStyleResolve()
+{
+    if (!shouldObserveNextStyleRecalc())
+        return;
+    LOG(ContentObservation, "startObservingStyleResolve: start observing style resolve.");
+    startObservingContentChanges();
+}
+
+void ContentChangeObserver::stopObservingStyleResolve()
+{
+    if (!shouldObserveNextStyleRecalc())
+        return;
+    LOG(ContentObservation, "stopObservingStyleResolve: stop observing style resolve");
+    setShouldObserveNextStyleRecalc(false);
+    auto inDeterminedState = observedContentChange() == WKContentVisibilityChange || !countOfObservedDOMTimers();
+    if (!inDeterminedState) {
+        LOG(ContentObservation, "stopObservingStyleResolve: can't decided it yet.");
+        return;
+    }
+    LOG(ContentObservation, "stopObservingStyleResolve: notify the pending synthetic click handler.");
+    m_page.chrome().client().observedContentChange(m_page.mainFrame());
+}
+
 void ContentChangeObserver::removeDOMTimer(const DOMTimer& timer)
 {
     if (!containsObservedDOMTimer(timer))