[ContentChangeObserver] Move CheckForVisibilityChange to ContentChangeObserver class
authorzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 26 Feb 2019 18:20:33 +0000 (18:20 +0000)
committerzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 26 Feb 2019 18:20:33 +0000 (18:20 +0000)
https://bugs.webkit.org/show_bug.cgi?id=195035
<rdar://problem/48389123>

Reviewed by Tim Horton.

Visibility checking logic belongs to ContentChangeObserver.

* page/ios/ContentChangeObserver.h:
* page/ios/ContentChangeObserver.mm:
(WebCore::elementImplicitVisibility):
(WebCore::ContentChangeObserver::StyleChange::StyleChange):
(WebCore::ContentChangeObserver::StyleChange::~StyleChange):
* rendering/updating/RenderTreeUpdater.cpp:
(WebCore::RenderTreeUpdater::updateElementRenderer):
(WebCore::elementImplicitVisibility): Deleted.
(WebCore::CheckForVisibilityChange::CheckForVisibilityChange): Deleted.
(WebCore::CheckForVisibilityChange::~CheckForVisibilityChange): Deleted.

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

Source/WebCore/ChangeLog
Source/WebCore/page/ios/ContentChangeObserver.h
Source/WebCore/page/ios/ContentChangeObserver.mm
Source/WebCore/rendering/updating/RenderTreeUpdater.cpp

index 1f6bf23..502f8e8 100644 (file)
@@ -1,3 +1,24 @@
+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>
+
+        Reviewed by Tim Horton.
+
+        Visibility checking logic belongs to ContentChangeObserver.
+
+        * page/ios/ContentChangeObserver.h:
+        * page/ios/ContentChangeObserver.mm:
+        (WebCore::elementImplicitVisibility):
+        (WebCore::ContentChangeObserver::StyleChange::StyleChange):
+        (WebCore::ContentChangeObserver::StyleChange::~StyleChange):
+        * rendering/updating/RenderTreeUpdater.cpp:
+        (WebCore::RenderTreeUpdater::updateElementRenderer):
+        (WebCore::elementImplicitVisibility): Deleted.
+        (WebCore::CheckForVisibilityChange::CheckForVisibilityChange): Deleted.
+        (WebCore::CheckForVisibilityChange::~CheckForVisibilityChange): Deleted.
+
 2019-02-26  Philippe Normand  <pnormand@igalia.com>
 
         [EGL] Runtime support for RGB565 pixel layout
index 6fbe075..92a7ad2 100644 (file)
@@ -45,7 +45,6 @@ public:
 
     WEBCORE_EXPORT void startObservingContentChanges();
     WEBCORE_EXPORT void stopObservingContentChanges();
-    bool isObservingContentChanges();
 
     WEBCORE_EXPORT void startObservingDOMTimerScheduling();
     WEBCORE_EXPORT void stopObservingDOMTimerScheduling();
@@ -61,6 +60,19 @@ public:
     WEBCORE_EXPORT unsigned countOfObservedDOMTimers();
     WEBCORE_EXPORT void clearObservedDOMTimers();
 
+    class StyleChange {
+    public:
+        StyleChange(const Element&, ContentChangeObserver&);
+        ~StyleChange();
+
+    private:
+        const Element& m_element;
+        ContentChangeObserver& m_contentChangeObserver;
+        DisplayType m_previousDisplay;
+        Visibility m_previousVisibility;
+        Visibility m_previousImplicitVisibility;
+    };
+
 private:
     void addObservedDOMTimer(const DOMTimer&);
     bool isObservingDOMTimerScheduling();
@@ -70,6 +82,8 @@ private:
     void startObservingStyleRecalcScheduling();
     void stopObservingStyleRecalcScheduling();
 
+    bool isObservingContentChanges();
+
     Page& m_page;
 };
 
index 375ebca..fb9d564 100644 (file)
@@ -187,6 +187,62 @@ void ContentChangeObserver::removeObservedDOMTimer(const DOMTimer& timer)
     WebThreadRemoveObservedDOMTimer(const_cast<DOMTimer*>(&timer));
 }
 
+static Visibility elementImplicitVisibility(const Element& element)
+{
+    auto* renderer = element.renderer();
+    if (!renderer)
+        return Visibility::Visible;
+
+    auto& style = renderer->style();
+
+    auto width = style.width();
+    auto height = style.height();
+    if ((width.isFixed() && width.value() <= 0) || (height.isFixed() && height.value() <= 0))
+        return Visibility::Hidden;
+
+    auto top = style.top();
+    auto left = style.left();
+    if (left.isFixed() && width.isFixed() && -left.value() >= width.value())
+        return Visibility::Hidden;
+
+    if (top.isFixed() && height.isFixed() && -top.value() >= height.value())
+        return Visibility::Hidden;
+    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::StyleChange::~StyleChange()
+{
+    if (!m_contentChangeObserver.isObservingContentChanges())
+        return;
+
+    auto* style = m_element.renderStyle();
+    auto qualifiesForVisibilityCheck = [&] {
+        if (!style)
+            return false;
+        if (m_element.isInUserAgentShadowTree())
+            return false;
+        if (!const_cast<Element&>(m_element).willRespondToMouseClickEvents())
+            return false;
+        return true;
+    };
+
+    if (!qualifiesForVisibilityCheck())
+        return;
+
+    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);
+}
 }
 
 #endif // PLATFORM(IOS_FAMILY)
index 8505f5d..9ef9f61 100644 (file)
 
 namespace WebCore {
 
-#if PLATFORM(IOS_FAMILY)
-class CheckForVisibilityChange {
-public:
-    CheckForVisibilityChange(const Element&, Page*);
-    ~CheckForVisibilityChange();
-
-private:
-    const Element& m_element;
-    Page* m_page { nullptr };
-    DisplayType m_previousDisplay;
-    Visibility m_previousVisibility;
-    Visibility m_previousImplicitVisibility;
-};
-#endif // PLATFORM(IOS_FAMILY)
-
 RenderTreeUpdater::Parent::Parent(ContainerNode& root)
     : element(is<Document>(root) ? nullptr : downcast<Element>(&root))
     , renderTreePosition(RenderTreePosition(*root.renderer()))
@@ -308,7 +293,7 @@ void RenderTreeUpdater::updateRendererStyle(RenderElement& renderer, RenderStyle
 void RenderTreeUpdater::updateElementRenderer(Element& element, const Style::ElementUpdate& update)
 {
 #if PLATFORM(IOS_FAMILY)
-    CheckForVisibilityChange checkForVisibilityChange(element, m_document.page());
+    ContentChangeObserver::StyleChange checkForStyleChange(element, m_document.page()->contentChangeObserver());
 #endif
 
     bool shouldTearDownRenderers = update.change == Style::Detach && (element.renderer() || element.hasDisplayContents());
@@ -643,66 +628,4 @@ RenderView& RenderTreeUpdater::renderView()
     return *m_document.renderView();
 }
 
-#if PLATFORM(IOS_FAMILY)
-static Visibility elementImplicitVisibility(const Element& element)
-{
-    auto* renderer = element.renderer();
-    if (!renderer)
-        return Visibility::Visible;
-
-    auto& style = renderer->style();
-
-    auto width = style.width();
-    auto height = style.height();
-    if ((width.isFixed() && width.value() <= 0) || (height.isFixed() && height.value() <= 0))
-        return Visibility::Hidden;
-
-    auto top = style.top();
-    auto left = style.left();
-    if (left.isFixed() && width.isFixed() && -left.value() >= width.value())
-        return Visibility::Hidden;
-
-    if (top.isFixed() && height.isFixed() && -top.value() >= height.value())
-        return Visibility::Hidden;
-    return Visibility::Visible;
-}
-
-CheckForVisibilityChange::CheckForVisibilityChange(const Element& element, Page* page)
-    : m_element(element)
-    , m_page(page)
-    , m_previousDisplay(element.renderStyle() ? element.renderStyle()->display() : DisplayType::None)
-    , m_previousVisibility(element.renderStyle() ? element.renderStyle()->visibility() : Visibility::Hidden)
-    , m_previousImplicitVisibility(page && page->contentChangeObserver().isObservingContentChanges() && page->contentChangeObserver().observedContentChange() != WKContentVisibilityChange ? elementImplicitVisibility(element) : Visibility::Visible)
-{
-}
-
-CheckForVisibilityChange::~CheckForVisibilityChange()
-{
-    if (!m_page)
-        return;
-
-    auto& contentChangeObserver = m_page->contentChangeObserver();
-    if (!contentChangeObserver.isObservingContentChanges())
-        return;
-
-    auto* style = m_element.renderStyle();
-
-    auto qualifiesForVisibilityCheck = [&] {
-        if (!style)
-            return false;
-        if (m_element.isInUserAgentShadowTree())
-            return false;
-        if (!const_cast<Element&>(m_element).willRespondToMouseClickEvents())
-            return false;
-        return true;
-    };
-
-    if (!qualifiesForVisibilityCheck())
-        return;
-    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))
-        contentChangeObserver.setObservedContentChange(WKContentVisibilityChange);
-}
-#endif
-
 }