[ContentChangeObserver] Introduce observer subclasses to scope content change observing.
authorzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 28 Feb 2019 23:18:06 +0000 (23:18 +0000)
committerzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 28 Feb 2019 23:18:06 +0000 (23:18 +0000)
https://bugs.webkit.org/show_bug.cgi?id=195172
<rdar://problem/48479259>

Reviewed by Simon Fraser.

Let's scope start/stopObserving call pairs.

* dom/Document.cpp:
(WebCore::Document::updateStyleIfNeeded):
* page/DOMTimer.cpp:
(WebCore::DOMTimer::fired):
* page/ios/ContentChangeObserver.cpp:
(WebCore::ContentChangeObserver::StyleChangeObserver::StyleChangeObserver):
(WebCore::ContentChangeObserver::StyleChangeObserver::~StyleChangeObserver):
(WebCore::ContentChangeObserver::StyleRecalcObserver::StyleRecalcObserver):
(WebCore::ContentChangeObserver::StyleRecalcObserver::~StyleRecalcObserver):
(WebCore::ContentChangeObserver::DOMTimerObserver::DOMTimerObserver):
(WebCore::ContentChangeObserver::DOMTimerObserver::~DOMTimerObserver):
(WebCore::ContentChangeObserver::StyleChange::StyleChange): Deleted.
(WebCore::ContentChangeObserver::StyleChange::~StyleChange): Deleted.
* page/ios/ContentChangeObserver.h:
* rendering/updating/RenderTreeUpdater.cpp:
(WebCore::RenderTreeUpdater::updateElementRenderer):

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

Source/WebCore/ChangeLog
Source/WebCore/dom/Document.cpp
Source/WebCore/page/DOMTimer.cpp
Source/WebCore/page/ios/ContentChangeObserver.cpp
Source/WebCore/page/ios/ContentChangeObserver.h
Source/WebCore/rendering/updating/RenderTreeUpdater.cpp

index 2719de8..6c20267 100644 (file)
@@ -1,3 +1,30 @@
+2019-02-28  Zalan Bujtas  <zalan@apple.com>
+
+        [ContentChangeObserver] Introduce observer subclasses to scope content change observing.
+        https://bugs.webkit.org/show_bug.cgi?id=195172
+        <rdar://problem/48479259>
+
+        Reviewed by Simon Fraser.
+
+        Let's scope start/stopObserving call pairs.
+
+        * dom/Document.cpp:
+        (WebCore::Document::updateStyleIfNeeded):
+        * page/DOMTimer.cpp:
+        (WebCore::DOMTimer::fired):
+        * page/ios/ContentChangeObserver.cpp:
+        (WebCore::ContentChangeObserver::StyleChangeObserver::StyleChangeObserver):
+        (WebCore::ContentChangeObserver::StyleChangeObserver::~StyleChangeObserver):
+        (WebCore::ContentChangeObserver::StyleRecalcObserver::StyleRecalcObserver):
+        (WebCore::ContentChangeObserver::StyleRecalcObserver::~StyleRecalcObserver):
+        (WebCore::ContentChangeObserver::DOMTimerObserver::DOMTimerObserver):
+        (WebCore::ContentChangeObserver::DOMTimerObserver::~DOMTimerObserver):
+        (WebCore::ContentChangeObserver::StyleChange::StyleChange): Deleted.
+        (WebCore::ContentChangeObserver::StyleChange::~StyleChange): Deleted.
+        * page/ios/ContentChangeObserver.h:
+        * rendering/updating/RenderTreeUpdater.cpp:
+        (WebCore::RenderTreeUpdater::updateElementRenderer):
+
 2019-02-28  Antoine Quint  <graouts@apple.com>
 
         Enable the Pointer Events runtime flag by default
index 6600e4c..6b6f0ce 100644 (file)
@@ -2055,18 +2055,11 @@ bool Document::updateStyleIfNeeded()
     }
 
 #if PLATFORM(IOS_FAMILY)
-    if (auto* page = this->page())
-        page->contentChangeObserver().startObservingStyleResolve();
+    ContentChangeObserver::StyleRecalcScope observingScope(page());
 #endif
     // The early exit above for !needsStyleRecalc() is needed when updateWidgetPositions() is called in runOrScheduleAsynchronousTasks().
     RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(isSafeToUpdateStyleOrLayout(*this));
-
     resolveStyle();
-
-#if PLATFORM(IOS_FAMILY)
-    if (auto* page = this->page())
-        page->contentChangeObserver().stopObservingStyleResolve();
-#endif
     return true;
 }
 
index 7737e7c..c8a313d 100644 (file)
@@ -335,15 +335,9 @@ void DOMTimer::fired()
         nestedTimers->startTracking();
 
 #if PLATFORM(IOS_FAMILY)
-    Page* page = is<Document>(context) ? downcast<Document>(context).page() : nullptr;
-    if (page)
-        page->contentChangeObserver().startObservingDOMTimerExecute(*this);
+    ContentChangeObserver::DOMTimerScope observingScope(is<Document>(context) ? downcast<Document>(context).page() : nullptr, *this);
 #endif
     m_action->execute(context);
-#if PLATFORM(IOS_FAMILY)
-    if (page)
-        page->contentChangeObserver().stopObservingDOMTimerExecute(*this);
-#endif
 
     InspectorInstrumentation::didFireTimer(cookie);
 
index fcfa683..8aefdb1 100644 (file)
@@ -277,18 +277,21 @@ static Visibility elementImplicitVisibility(const Element& element)
     return Visibility::Visible;
 }
 
-ContentChangeObserver::StyleChange::StyleChange(const Element& element, ContentChangeObserver& contentChangeObserver)
-    : m_element(element)
-    , m_contentChangeObserver(contentChangeObserver)
-    , m_previousDisplay(element.renderStyle() ? element.renderStyle()->display() : DisplayType::None)
-    , m_previousVisibility(element.renderStyle() ? element.renderStyle()->visibility() : Visibility::Hidden)
-    , m_previousImplicitVisibility(contentChangeObserver.isObservingContentChanges() && contentChangeObserver.observedContentChange() != WKContentVisibilityChange ? elementImplicitVisibility(element) : Visibility::Visible)
-{
+ContentChangeObserver::StyleChangeScope::StyleChangeScope(Page* page, const Element& element)
+    : m_contentChangeObserver(page ? &page->contentChangeObserver() : nullptr)
+    , m_element(element)
+    , m_needsObserving(m_contentChangeObserver && m_contentChangeObserver->isObservingContentChanges() && m_contentChangeObserver->observedContentChange() != WKContentVisibilityChange)
+{
+    if (m_needsObserving) {
+        m_previousDisplay = element.renderStyle() ? element.renderStyle()->display() : DisplayType::None;
+        m_previousVisibility = element.renderStyle() ? element.renderStyle()->visibility() : Visibility::Hidden;
+        m_previousImplicitVisibility = elementImplicitVisibility(element);
+    }
 }
 
-ContentChangeObserver::StyleChange::~StyleChange()
+ContentChangeObserver::StyleChangeScope::~StyleChangeScope()
 {
-    if (!m_contentChangeObserver.isObservingContentChanges())
+    if (!m_needsObserving)
         return;
 
     auto* style = m_element.renderStyle();
@@ -308,8 +311,36 @@ ContentChangeObserver::StyleChange::~StyleChange()
     if ((m_previousDisplay == DisplayType::None && style->display() != DisplayType::None)
         || (m_previousVisibility == Visibility::Hidden && style->visibility() != Visibility::Hidden)
         || (m_previousImplicitVisibility == Visibility::Hidden && elementImplicitVisibility(m_element) == Visibility::Visible))
-        m_contentChangeObserver.setObservedContentChange(WKContentVisibilityChange);
+        m_contentChangeObserver->setObservedContentChange(WKContentVisibilityChange);
+}
+
+ContentChangeObserver::StyleRecalcScope::StyleRecalcScope(Page* page)
+    : m_contentChangeObserver(page ? &page->contentChangeObserver() : nullptr)
+{
+    if (m_contentChangeObserver)
+        m_contentChangeObserver->startObservingStyleResolve();
+}
+
+ContentChangeObserver::StyleRecalcScope::~StyleRecalcScope()
+{
+    if (m_contentChangeObserver)
+        m_contentChangeObserver->stopObservingStyleResolve();
 }
+
+ContentChangeObserver::DOMTimerScope::DOMTimerScope(Page* page, const DOMTimer& domTimer)
+    : m_contentChangeObserver(page ? &page->contentChangeObserver() : nullptr)
+    , m_domTimer(domTimer)
+{
+    if (m_contentChangeObserver)
+        m_contentChangeObserver->startObservingDOMTimerExecute(m_domTimer);
+}
+
+ContentChangeObserver::DOMTimerScope::~DOMTimerScope()
+{
+    if (m_contentChangeObserver)
+        m_contentChangeObserver->stopObservingDOMTimerExecute(m_domTimer);
+}
+
 }
 
 #endif // PLATFORM(IOS_FAMILY)
index fc87d83..8c486f4 100644 (file)
@@ -38,40 +38,58 @@ class ContentChangeObserver {
 public:
     ContentChangeObserver(Page&);
 
+    WEBCORE_EXPORT void startObservingContentChanges();
+    WEBCORE_EXPORT void stopObservingContentChanges();
+    WEBCORE_EXPORT WKContentChange observedContentChange();
+
     void didInstallDOMTimer(const DOMTimer&, Seconds timeout, bool singleShot);
     void removeDOMTimer(const DOMTimer&);
-    void startObservingDOMTimerExecute(const DOMTimer&);
-    void stopObservingDOMTimerExecute(const DOMTimer&);
 
     void didScheduleStyleRecalc();
-    void startObservingStyleResolve();
-    void stopObservingStyleResolve();
-
     void didSuspendActiveDOMObjects();
     void willDetachPage();
 
-    WEBCORE_EXPORT void startObservingContentChanges();
-    WEBCORE_EXPORT void stopObservingContentChanges();
-
-    WEBCORE_EXPORT WKContentChange observedContentChange();
-
-    class StyleChange {
+    class StyleChangeScope {
     public:
-        StyleChange(const Element&, ContentChangeObserver&);
-        ~StyleChange();
+        StyleChangeScope(Page*, const Element&);
+        ~StyleChangeScope();
 
     private:
+        ContentChangeObserver* m_contentChangeObserver { nullptr };
         const Element& m_element;
-        ContentChangeObserver& m_contentChangeObserver;
+        bool m_needsObserving { false };
         DisplayType m_previousDisplay;
         Visibility m_previousVisibility;
         Visibility m_previousImplicitVisibility;
     };
 
+    class StyleRecalcScope {
+    public:
+        StyleRecalcScope(Page*);
+        ~StyleRecalcScope();
+    private:
+        ContentChangeObserver* m_contentChangeObserver { nullptr };
+    };
+
+    class DOMTimerScope {
+    public:
+        DOMTimerScope(Page*, const DOMTimer&);
+        ~DOMTimerScope();
+    private:
+        ContentChangeObserver* m_contentChangeObserver { nullptr };
+        const DOMTimer& m_domTimer;
+    };
+
 private:
     void startObservingDOMTimerScheduling();
     void stopObservingDOMTimerScheduling();
 
+    void startObservingDOMTimerExecute(const DOMTimer&);
+    void stopObservingDOMTimerExecute(const DOMTimer&);
+
+    void startObservingStyleResolve();
+    void stopObservingStyleResolve();
+
     void addObservedDOMTimer(const DOMTimer&);
     bool isObservingDOMTimerScheduling();
     void removeObservedDOMTimer(const DOMTimer&);
index 9ef9f61..c5f4350 100644 (file)
@@ -293,7 +293,7 @@ void RenderTreeUpdater::updateRendererStyle(RenderElement& renderer, RenderStyle
 void RenderTreeUpdater::updateElementRenderer(Element& element, const Style::ElementUpdate& update)
 {
 #if PLATFORM(IOS_FAMILY)
-    ContentChangeObserver::StyleChange checkForStyleChange(element, m_document.page()->contentChangeObserver());
+    ContentChangeObserver::StyleChangeScope observingScope(m_document.page(), element);
 #endif
 
     bool shouldTearDownRenderers = update.change == Style::Detach && (element.renderer() || element.hasDisplayContents());