Title: [242190] trunk/Source/WebCore
Revision
242190
Author
[email protected]
Date
2019-02-27 20:39:22 -0800 (Wed, 27 Feb 2019)

Log Message

[ContentChangeObserver] Move WKSetObservedContentChange logic to ContentChangeObserver class.
https://bugs.webkit.org/show_bug.cgi?id=195128
<rdar://problem/48456752>

Reviewed by Simon Fraser.

Move the final bits over to ContentChangeObserver and delete WKContentObservationInternal.h.

* WebCore.xcodeproj/project.pbxproj:
* page/ios/ContentChangeObserver.mm:
(WebCore::ContentChangeObserver::setObservedContentChange):
* platform/ios/wak/WKContentObservation.cpp:
(WKSetObservedContentChange):
* platform/ios/wak/WKContentObservation.h:
* platform/ios/wak/WKContentObservationInternal.h: Removed.

Modified Paths

Added Paths

Removed Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (242189 => 242190)


--- trunk/Source/WebCore/ChangeLog	2019-02-28 04:35:25 UTC (rev 242189)
+++ trunk/Source/WebCore/ChangeLog	2019-02-28 04:39:22 UTC (rev 242190)
@@ -1,3 +1,21 @@
+2019-02-27  Zalan Bujtas  <[email protected]>
+
+        [ContentChangeObserver] Move WKSetObservedContentChange logic to ContentChangeObserver class.
+        https://bugs.webkit.org/show_bug.cgi?id=195128
+        <rdar://problem/48456752>
+
+        Reviewed by Simon Fraser.
+
+        Move the final bits over to ContentChangeObserver and delete WKContentObservationInternal.h.
+
+        * WebCore.xcodeproj/project.pbxproj:
+        * page/ios/ContentChangeObserver.mm:
+        (WebCore::ContentChangeObserver::setObservedContentChange):
+        * platform/ios/wak/WKContentObservation.cpp:
+        (WKSetObservedContentChange):
+        * platform/ios/wak/WKContentObservation.h:
+        * platform/ios/wak/WKContentObservationInternal.h: Removed.
+
 2019-02-27  Simon Fraser  <[email protected]>
 
         Roll out r242014; it caused crashes in compositing logging (webkit.org/b/195141)

Modified: trunk/Source/WebCore/SourcesCocoa.txt (242189 => 242190)


--- trunk/Source/WebCore/SourcesCocoa.txt	2019-02-28 04:35:25 UTC (rev 242189)
+++ trunk/Source/WebCore/SourcesCocoa.txt	2019-02-28 04:39:22 UTC (rev 242190)
@@ -131,7 +131,7 @@
 page/cocoa/ResourceUsageThreadCocoa.mm
 page/cocoa/SettingsBaseCocoa.mm
 
-page/ios/ContentChangeObserver.mm
+page/ios/ContentChangeObserver.cpp
 page/ios/EventHandlerIOS.mm
 page/ios/FrameIOS.mm
 page/ios/WebEventRegion.mm

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (242189 => 242190)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2019-02-28 04:35:25 UTC (rev 242189)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2019-02-28 04:39:22 UTC (rev 242190)
@@ -4923,7 +4923,6 @@
 		EBF5121C1696496C0056BD25 /* JSTypeConversions.cpp in Sources */ = {isa = PBXBuildFile; fileRef = EBF5121A1696496C0056BD25 /* JSTypeConversions.cpp */; };
 		EBF5121D1696496C0056BD25 /* JSTypeConversions.h in Headers */ = {isa = PBXBuildFile; fileRef = EBF5121B1696496C0056BD25 /* JSTypeConversions.h */; };
 		ECA680C71E67724500731D20 /* StringUtilities.h in Headers */ = {isa = PBXBuildFile; fileRef = ECA680C61E67724500731D20 /* StringUtilities.h */; settings = {ATTRIBUTES = (Private, ); }; };
-		ECCDB8811E4B8C5900A1AEA6 /* WKContentObservationInternal.h in Headers */ = {isa = PBXBuildFile; fileRef = ECCDB8801E4B8C5900A1AEA6 /* WKContentObservationInternal.h */; };
 		ED2BA83C09A24B91006C0AC4 /* DocumentMarker.h in Headers */ = {isa = PBXBuildFile; fileRef = ED2BA83B09A24B91006C0AC4 /* DocumentMarker.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		EDE3A5000C7A430600956A37 /* ColorMac.h in Headers */ = {isa = PBXBuildFile; fileRef = EDE3A4FF0C7A430600956A37 /* ColorMac.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		EDEC98030AED7E170059137F /* WebCorePrefix.h in Headers */ = {isa = PBXBuildFile; fileRef = EDEC98020AED7E170059137F /* WebCorePrefix.h */; };
@@ -9245,7 +9244,7 @@
 		6FE7CFA02177EEF1005B1573 /* InlineItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InlineItem.h; sourceTree = "<group>"; };
 		6FE7CFA32177EF10005B1573 /* LayoutLineBreakBox.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LayoutLineBreakBox.h; sourceTree = "<group>"; };
 		6FE7CFA52177F069005B1573 /* LayoutLineBreakBox.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LayoutLineBreakBox.cpp; sourceTree = "<group>"; };
-		6FE9F09222211035004C5082 /* ContentChangeObserver.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ContentChangeObserver.mm; sourceTree = "<group>"; };
+		6FE9F09222211035004C5082 /* ContentChangeObserver.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ContentChangeObserver.cpp; sourceTree = "<group>"; };
 		6FFDC43E212EFF1600A9CA91 /* FloatAvoider.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FloatAvoider.cpp; sourceTree = "<group>"; };
 		6FFDC440212EFF1600A9CA91 /* FloatAvoider.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FloatAvoider.h; sourceTree = "<group>"; };
 		709A01FD1E3D0BCC006B0D4C /* ModuleFetchFailureKind.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ModuleFetchFailureKind.h; sourceTree = "<group>"; };
@@ -15136,7 +15135,6 @@
 		EBF5121B1696496C0056BD25 /* JSTypeConversions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSTypeConversions.h; sourceTree = "<group>"; };
 		ECA680C61E67724500731D20 /* StringUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StringUtilities.h; sourceTree = "<group>"; };
 		ECA680C81E67730B00731D20 /* StringUtilities.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = StringUtilities.mm; sourceTree = "<group>"; };
-		ECCDB8801E4B8C5900A1AEA6 /* WKContentObservationInternal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKContentObservationInternal.h; sourceTree = "<group>"; };
 		ED2BA83B09A24B91006C0AC4 /* DocumentMarker.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DocumentMarker.h; sourceTree = "<group>"; };
 		ED501DC50B249F2900AE18D9 /* EditorMac.mm */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.objcpp; path = EditorMac.mm; sourceTree = "<group>"; };
 		EDE3A4FF0C7A430600956A37 /* ColorMac.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ColorMac.h; sourceTree = "<group>"; };
@@ -16591,8 +16589,8 @@
 		18A6CD6F0D8F2025001DC3CE /* ios */ = {
 			isa = PBXGroup;
 			children = (
+				6FE9F09222211035004C5082 /* ContentChangeObserver.cpp */,
 				6FB5E212221F2447003989CF /* ContentChangeObserver.h */,
-				6FE9F09222211035004C5082 /* ContentChangeObserver.mm */,
 				FE6938B51045D67E008EABB6 /* EventHandlerIOS.mm */,
 				FED13D3B0CEA936A00D89466 /* FrameIOS.mm */,
 				225A16B30D5C11E900090295 /* WebEventRegion.h */,
@@ -22308,7 +22306,6 @@
 				A14832A1187F508700DA63A6 /* WebCoreThreadSystemInterface.h */,
 				A14832A2187F508700DA63A6 /* WKContentObservation.cpp */,
 				A14832A3187F508700DA63A6 /* WKContentObservation.h */,
-				ECCDB8801E4B8C5900A1AEA6 /* WKContentObservationInternal.h */,
 				A14832A4187F508700DA63A6 /* WKGraphics.h */,
 				A14832A5187F508700DA63A6 /* WKGraphics.mm */,
 				A14832A6187F508700DA63A6 /* WKTypes.h */,
@@ -32382,7 +32379,6 @@
 				E1E1BF00115FF6FB006F52CA /* WindowsKeyboardCodes.h in Headers */,
 				501BAAA913950E2C00F7ACEB /* WindRule.h in Headers */,
 				A14832BE187F64CC00DA63A6 /* WKContentObservation.h in Headers */,
-				ECCDB8811E4B8C5900A1AEA6 /* WKContentObservationInternal.h in Headers */,
 				A14832BF187F652C00DA63A6 /* WKGraphics.h in Headers */,
 				A14832C1187F657A00DA63A6 /* WKTypes.h in Headers */,
 				A14832C3187F65DF00DA63A6 /* WKUtilities.h in Headers */,

Copied: trunk/Source/WebCore/page/ios/ContentChangeObserver.cpp (from rev 242189, trunk/Source/WebCore/page/ios/ContentChangeObserver.mm) (0 => 242190)


--- trunk/Source/WebCore/page/ios/ContentChangeObserver.cpp	                        (rev 0)
+++ trunk/Source/WebCore/page/ios/ContentChangeObserver.cpp	2019-02-28 04:39:22 UTC (rev 242190)
@@ -0,0 +1,310 @@
+/*
+ * Copyright (C) 2019 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "ContentChangeObserver.h"
+
+#if PLATFORM(IOS_FAMILY)
+#include "Chrome.h"
+#include "ChromeClient.h"
+#include "DOMTimer.h"
+#include "Logging.h"
+#include "NodeRenderStyle.h"
+#include "Page.h"
+
+namespace WebCore {
+
+ContentChangeObserver::ContentChangeObserver(Page& page)
+    : m_page(page)
+{
+}
+
+void ContentChangeObserver::didInstallDOMTimer(const DOMTimer& timer, Seconds timeout, bool singleShot)
+{
+    if (!m_page.mainFrame().document())
+        return;
+    if (m_page.mainFrame().document()->activeDOMObjectsAreSuspended())
+        return;
+    if (timeout > 250_ms || !singleShot)
+        return;
+    if (!isObservingDOMTimerScheduling())
+        return;
+    setObservedContentChange(WKContentIndeterminateChange);
+    addObservedDOMTimer(timer);
+    LOG_WITH_STREAM(ContentObservation, stream << "didInstallDOMTimer: register this timer: (" << &timer << ") and observe when it fires.");
+}
+
+void ContentChangeObserver::startObservingDOMTimerExecute(const DOMTimer& timer)
+{
+    if (!containsObservedDOMTimer(timer))
+        return;
+    LOG_WITH_STREAM(ContentObservation, stream << "startObservingDOMTimerExecute: start observing (" << &timer << ") timer callback.");
+    startObservingStyleRecalcScheduling();
+    m_observingContentChanges = true;
+}
+
+void ContentChangeObserver::stopObservingDOMTimerExecute(const DOMTimer& timer)
+{
+    if (!containsObservedDOMTimer(timer))
+        return;
+    removeObservedDOMTimer(timer);
+    stopObservingStyleRecalcScheduling();
+    stopObservingContentChanges();
+    auto observedContentChange = this->observedContentChange();
+    // Check if the timer callback triggered either a sync or async style update.
+    auto inDeterminedState = observedContentChange == WKContentVisibilityChange || (!countOfObservedDOMTimers() && observedContentChange == WKContentNoChange);  
+
+    LOG_WITH_STREAM(ContentObservation, stream << "stopObservingDOMTimerExecute: stop observing (" << &timer << ") timer callback.");
+    if (inDeterminedState) {
+        LOG_WITH_STREAM(ContentObservation, stream << "stopObservingDOMTimerExecute: (" << &timer << ") in determined state.");
+        m_page.chrome().client().observedContentChange(m_page.mainFrame());
+    } else if (observedContentChange == WKContentIndeterminateChange) {
+        // An async style recalc has been scheduled. Let's observe it.
+        LOG_WITH_STREAM(ContentObservation, stream << "stopObservingDOMTimerExecute: (" << &timer << ") wait until next style recalc fires.");
+        setShouldObserveNextStyleRecalc(true);
+    }
+}
+
+void ContentChangeObserver::didScheduleStyleRecalc()
+{
+    if (!isObservingStyleRecalcScheduling())
+        return;
+    LOG(ContentObservation, "didScheduleStyleRecalc: register this style recalc schedule and observe when it fires.");
+    setObservedContentChange(WKContentIndeterminateChange);
+}
+
+void ContentChangeObserver::startObservingStyleResolve()
+{
+    if (!shouldObserveNextStyleRecalc())
+        return;
+    LOG(ContentObservation, "startObservingStyleResolve: start observing style resolve.");
+    m_observingContentChanges = true;
+}
+
+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))
+        return;
+    removeObservedDOMTimer(timer);
+    LOG_WITH_STREAM(ContentObservation, stream << "removeDOMTimer: remove registered timer (" << &timer << ")");
+    if (countOfObservedDOMTimers())
+        return;
+    m_page.chrome().client().observedContentChange(m_page.mainFrame());
+}
+
+void ContentChangeObserver::clearTimersAndReportContentChange()
+{
+    if (!countOfObservedDOMTimers())
+        return;
+    LOG(ContentObservation, "clearTimersAndReportContentChange: remove registered timers and report content change.");
+    clearObservedDOMTimers();
+    m_page.chrome().client().observedContentChange(m_page.mainFrame());
+}
+
+void ContentChangeObserver::didSuspendActiveDOMObjects()
+{
+    clearTimersAndReportContentChange();
+}
+
+void ContentChangeObserver::willDetachPage()
+{
+    clearTimersAndReportContentChange();
+}
+
+void ContentChangeObserver::startObservingContentChanges()
+{
+    startObservingDOMTimerScheduling();
+    setObservedContentChange(WKContentNoChange);
+    m_observingContentChanges = true;
+}
+
+void ContentChangeObserver::stopObservingContentChanges()
+{
+    stopObservingDOMTimerScheduling();
+    m_observingContentChanges = false;
+}
+
+bool ContentChangeObserver::isObservingContentChanges()
+{
+    return m_observingContentChanges;
+}
+
+void ContentChangeObserver::startObservingDOMTimerScheduling()
+{
+    m_observingDOMTimerScheduling = true;
+    clearObservedDOMTimers();
+}
+
+void ContentChangeObserver::stopObservingDOMTimerScheduling()
+{
+    m_observingDOMTimerScheduling = false;
+}
+
+bool ContentChangeObserver::isObservingDOMTimerScheduling()
+{
+    return m_observingDOMTimerScheduling;
+}
+
+void ContentChangeObserver::startObservingStyleRecalcScheduling()
+{
+    m_observingStyleRecalcScheduling = true;
+}
+
+void ContentChangeObserver::stopObservingStyleRecalcScheduling()
+{
+    m_observingStyleRecalcScheduling = false;
+}
+
+bool ContentChangeObserver::isObservingStyleRecalcScheduling()
+{
+    return m_observingStyleRecalcScheduling;
+}
+
+void ContentChangeObserver::setShouldObserveNextStyleRecalc(bool observe)
+{
+    m_observingNextStyleRecalc = observe;
+}
+
+bool ContentChangeObserver::shouldObserveNextStyleRecalc()
+{
+    return m_observingNextStyleRecalc;
+}
+
+WKContentChange ContentChangeObserver::observedContentChange()
+{
+    return WKObservedContentChange();
+}
+
+unsigned ContentChangeObserver::countOfObservedDOMTimers()
+{
+    return m_DOMTimerList.size();
+}
+
+void ContentChangeObserver::clearObservedDOMTimers()
+{
+    m_DOMTimerList.clear();
+}
+
+void ContentChangeObserver::setObservedContentChange(WKContentChange change)
+{
+    if (observedContentChange() == WKContentVisibilityChange)
+        return;
+    WKSetObservedContentChange(change);
+}
+
+bool ContentChangeObserver::containsObservedDOMTimer(const DOMTimer& timer)
+{
+    return m_DOMTimerList.contains(&timer);
+}
+
+void ContentChangeObserver::addObservedDOMTimer(const DOMTimer& timer)
+{
+    ASSERT(isObservingDOMTimerScheduling());
+    if (observedContentChange() == WKContentVisibilityChange)
+        return;
+    m_DOMTimerList.add(&timer);
+}
+
+void ContentChangeObserver::removeObservedDOMTimer(const DOMTimer& timer)
+{
+    m_DOMTimerList.remove(&timer);
+    // Force reset the content change flag when the last observed content modifier is removed. We should not be in indeterminate state anymore.
+    if (!countOfObservedDOMTimers() && observedContentChange() == WKContentIndeterminateChange)
+        setObservedContentChange(WKContentNoChange);
+}
+
+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)

Deleted: trunk/Source/WebCore/page/ios/ContentChangeObserver.mm (242189 => 242190)


--- trunk/Source/WebCore/page/ios/ContentChangeObserver.mm	2019-02-28 04:35:25 UTC (rev 242189)
+++ trunk/Source/WebCore/page/ios/ContentChangeObserver.mm	2019-02-28 04:39:22 UTC (rev 242190)
@@ -1,308 +0,0 @@
-/*
- * Copyright (C) 2019 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1.  Redistributions of source code must retain the above copyright
- *     notice, this list of conditions and the following disclaimer.
- * 2.  Redistributions in binary form must reproduce the above copyright
- *     notice, this list of conditions and the following disclaimer in the
- *     documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#import "config.h"
-#import "ContentChangeObserver.h"
-
-#if PLATFORM(IOS_FAMILY)
-#import "Chrome.h"
-#import "ChromeClient.h"
-#import "DOMTimer.h"
-#import "Logging.h"
-#import "Page.h"
-#import "WKContentObservationInternal.h"
-
-namespace WebCore {
-
-ContentChangeObserver::ContentChangeObserver(Page& page)
-    : m_page(page)
-{
-}
-
-void ContentChangeObserver::didInstallDOMTimer(const DOMTimer& timer, Seconds timeout, bool singleShot)
-{
-    if (!m_page.mainFrame().document())
-        return;
-    if (m_page.mainFrame().document()->activeDOMObjectsAreSuspended())
-        return;
-    if (timeout > 250_ms || !singleShot)
-        return;
-    if (!isObservingDOMTimerScheduling())
-        return;
-    setObservedContentChange(WKContentIndeterminateChange);
-    addObservedDOMTimer(timer);
-    LOG_WITH_STREAM(ContentObservation, stream << "didInstallDOMTimer: register this timer: (" << &timer << ") and observe when it fires.");
-}
-
-void ContentChangeObserver::startObservingDOMTimerExecute(const DOMTimer& timer)
-{
-    if (!containsObservedDOMTimer(timer))
-        return;
-    LOG_WITH_STREAM(ContentObservation, stream << "startObservingDOMTimerExecute: start observing (" << &timer << ") timer callback.");
-    startObservingStyleRecalcScheduling();
-    m_observingContentChanges = true;
-}
-
-void ContentChangeObserver::stopObservingDOMTimerExecute(const DOMTimer& timer)
-{
-    if (!containsObservedDOMTimer(timer))
-        return;
-    removeObservedDOMTimer(timer);
-    stopObservingStyleRecalcScheduling();
-    stopObservingContentChanges();
-    auto observedContentChange = this->observedContentChange();
-    // Check if the timer callback triggered either a sync or async style update.
-    auto inDeterminedState = observedContentChange == WKContentVisibilityChange || (!countOfObservedDOMTimers() && observedContentChange == WKContentNoChange);  
-
-    LOG_WITH_STREAM(ContentObservation, stream << "stopObservingDOMTimerExecute: stop observing (" << &timer << ") timer callback.");
-    if (inDeterminedState) {
-        LOG_WITH_STREAM(ContentObservation, stream << "stopObservingDOMTimerExecute: (" << &timer << ") in determined state.");
-        m_page.chrome().client().observedContentChange(m_page.mainFrame());
-    } else if (observedContentChange == WKContentIndeterminateChange) {
-        // An async style recalc has been scheduled. Let's observe it.
-        LOG_WITH_STREAM(ContentObservation, stream << "stopObservingDOMTimerExecute: (" << &timer << ") wait until next style recalc fires.");
-        setShouldObserveNextStyleRecalc(true);
-    }
-}
-
-void ContentChangeObserver::didScheduleStyleRecalc()
-{
-    if (!isObservingStyleRecalcScheduling())
-        return;
-    LOG(ContentObservation, "didScheduleStyleRecalc: register this style recalc schedule and observe when it fires.");
-    setObservedContentChange(WKContentIndeterminateChange);
-}
-
-void ContentChangeObserver::startObservingStyleResolve()
-{
-    if (!shouldObserveNextStyleRecalc())
-        return;
-    LOG(ContentObservation, "startObservingStyleResolve: start observing style resolve.");
-    m_observingContentChanges = true;
-}
-
-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))
-        return;
-    removeObservedDOMTimer(timer);
-    LOG_WITH_STREAM(ContentObservation, stream << "removeDOMTimer: remove registered timer (" << &timer << ")");
-    if (countOfObservedDOMTimers())
-        return;
-    m_page.chrome().client().observedContentChange(m_page.mainFrame());
-}
-
-void ContentChangeObserver::clearTimersAndReportContentChange()
-{
-    if (!countOfObservedDOMTimers())
-        return;
-    LOG(ContentObservation, "clearTimersAndReportContentChange: remove registered timers and report content change.");
-    clearObservedDOMTimers();
-    m_page.chrome().client().observedContentChange(m_page.mainFrame());
-}
-
-void ContentChangeObserver::didSuspendActiveDOMObjects()
-{
-    clearTimersAndReportContentChange();
-}
-
-void ContentChangeObserver::willDetachPage()
-{
-    clearTimersAndReportContentChange();
-}
-
-void ContentChangeObserver::startObservingContentChanges()
-{
-    startObservingDOMTimerScheduling();
-    setObservedContentChange(WKContentNoChange);
-    m_observingContentChanges = true;
-}
-
-void ContentChangeObserver::stopObservingContentChanges()
-{
-    stopObservingDOMTimerScheduling();
-    m_observingContentChanges = false;
-}
-
-bool ContentChangeObserver::isObservingContentChanges()
-{
-    return m_observingContentChanges;
-}
-
-void ContentChangeObserver::startObservingDOMTimerScheduling()
-{
-    m_observingDOMTimerScheduling = true;
-    clearObservedDOMTimers();
-}
-
-void ContentChangeObserver::stopObservingDOMTimerScheduling()
-{
-    m_observingDOMTimerScheduling = false;
-}
-
-bool ContentChangeObserver::isObservingDOMTimerScheduling()
-{
-    return m_observingDOMTimerScheduling;
-}
-
-void ContentChangeObserver::startObservingStyleRecalcScheduling()
-{
-    m_observingStyleRecalcScheduling = true;
-}
-
-void ContentChangeObserver::stopObservingStyleRecalcScheduling()
-{
-    m_observingStyleRecalcScheduling = false;
-}
-
-bool ContentChangeObserver::isObservingStyleRecalcScheduling()
-{
-    return m_observingStyleRecalcScheduling;
-}
-
-void ContentChangeObserver::setShouldObserveNextStyleRecalc(bool observe)
-{
-    m_observingNextStyleRecalc = observe;
-}
-
-bool ContentChangeObserver::shouldObserveNextStyleRecalc()
-{
-    return m_observingNextStyleRecalc;
-}
-
-WKContentChange ContentChangeObserver::observedContentChange()
-{
-    return WKObservedContentChange();
-}
-
-unsigned ContentChangeObserver::countOfObservedDOMTimers()
-{
-    return m_DOMTimerList.size();
-}
-
-void ContentChangeObserver::clearObservedDOMTimers()
-{
-    m_DOMTimerList.clear();
-}
-
-void ContentChangeObserver::setObservedContentChange(WKContentChange change)
-{
-    WKSetObservedContentChange(change);
-}
-
-bool ContentChangeObserver::containsObservedDOMTimer(const DOMTimer& timer)
-{
-    return m_DOMTimerList.contains(&timer);
-}
-
-void ContentChangeObserver::addObservedDOMTimer(const DOMTimer& timer)
-{
-    ASSERT(isObservingDOMTimerScheduling());
-    if (observedContentChange() == WKContentVisibilityChange)
-        return;
-    m_DOMTimerList.add(&timer);
-}
-
-void ContentChangeObserver::removeObservedDOMTimer(const DOMTimer& timer)
-{
-    m_DOMTimerList.remove(&timer);
-    // Force reset the content change flag when the last observed content modifier is removed. We should not be in indeterminate state anymore.
-    if (!countOfObservedDOMTimers() && observedContentChange() == WKContentIndeterminateChange)
-        setObservedContentChange(WKContentNoChange);
-}
-
-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)

Modified: trunk/Source/WebCore/platform/ios/wak/WKContentObservation.cpp (242189 => 242190)


--- trunk/Source/WebCore/platform/ios/wak/WKContentObservation.cpp	2019-02-28 04:35:25 UTC (rev 242189)
+++ trunk/Source/WebCore/platform/ios/wak/WKContentObservation.cpp	2019-02-28 04:39:22 UTC (rev 242190)
@@ -25,15 +25,9 @@
 
 #include "config.h"
 #include "WKContentObservation.h"
-#include "WKContentObservationInternal.h"
 
 #if PLATFORM(IOS_FAMILY)
 
-#include "JSDOMBinding.h"
-#include "WebCoreThread.h"
-#include <wtf/HashMap.h>
-#include <wtf/NeverDestroyed.h>
-
 WKContentChange _WKContentChange = WKContentNoChange;
 
 WKContentChange WKObservedContentChange(void)
@@ -43,15 +37,7 @@
 
 void WKSetObservedContentChange(WKContentChange change)
 {
-    // We've already have a definite answer.
-    if (_WKContentChange == WKContentVisibilityChange)
-        return;
-
-    if (change == WKContentVisibilityChange || change == WKContentIndeterminateChange) {
-        _WKContentChange = change;
-        return;
-    }
-    ASSERT_NOT_REACHED();
+    _WKContentChange = change;
 }
 
 #endif // PLATFORM(IOS_FAMILY)

Modified: trunk/Source/WebCore/platform/ios/wak/WKContentObservation.h (242189 => 242190)


--- trunk/Source/WebCore/platform/ios/wak/WKContentObservation.h	2019-02-28 04:35:25 UTC (rev 242189)
+++ trunk/Source/WebCore/platform/ios/wak/WKContentObservation.h	2019-02-28 04:39:22 UTC (rev 242190)
@@ -40,6 +40,7 @@
 }   WKContentChange;
 
 WEBCORE_EXPORT WKContentChange WKObservedContentChange(void);
+WEBCORE_EXPORT void WKSetObservedContentChange(WKContentChange);
 
 #ifdef __cplusplus
 }

Deleted: trunk/Source/WebCore/platform/ios/wak/WKContentObservationInternal.h (242189 => 242190)


--- trunk/Source/WebCore/platform/ios/wak/WKContentObservationInternal.h	2019-02-28 04:35:25 UTC (rev 242189)
+++ trunk/Source/WebCore/platform/ios/wak/WKContentObservationInternal.h	2019-02-28 04:39:22 UTC (rev 242190)
@@ -1,45 +0,0 @@
-/*
- * Copyright (C) 2017 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef WKContentObservationInternal_h
-#define WKContentObservationInternal_h
-
-#if TARGET_OS_IPHONE
-
-#import "WKContentObservation.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-void WKSetObservedContentChange(WKContentChange);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif // TARGET_OS_IPHONE
-
-#endif // WKContentObservationInternal_h
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to