Branch: refs/heads/main Home: https://github.com/WebKit/WebKit Commit: 38771c35ceb476acc7d75e856add5df546ec8db3 https://github.com/WebKit/WebKit/commit/38771c35ceb476acc7d75e856add5df546ec8db3 Author: Wenson Hsieh <wenson_hs...@apple.com> Date: 2024-07-27 (Sat, 27 Jul 2024)
Changed paths: M Source/WebCore/page/ElementTargetingController.cpp M Source/WebCore/page/ElementTargetingController.h M Source/WebCore/page/LocalFrame.cpp M Source/WebCore/page/Page.cpp M Source/WebCore/page/Page.h M Tools/TestWebKitAPI/Tests/WebKitCocoa/ElementTargetingTests.mm Log Message: ----------- [Remote Inspection] numberOfVisibilityAdjustmentRects returns 0 after loading from back/forward cache https://bugs.webkit.org/show_bug.cgi?id=277187 rdar://132521358 Reviewed by Richard Robinson. `ElementTargetingController`'s set of `m_adjustedElements` is currently reset whenever a load is committed. This causes `numberOfVisibilityAdjustmentRects()` to always return 0 when the current document has been restored from the back/forward cache, since adjustment state persists on the DOM nodes in the new document, but `m_adjustedElements` is empty. To address this, we: 1. Keep track of a `WeakSet` of documents wherein we've previously applied adjustments. 2. Add plumbing to inform `ElementTargetingController` when the main document will change; if the new document is one where we've previously applied adjustments, then set a boolean flag, `m_shouldRecomputeAdjustedElements`, to indicate that we need to lazily compute `m_adjustedElements` if the client ever asks for the adjusted rect count. 3. If `m_shouldRecomputeAdjustedElements` is set and This design ensures that we do no additional work (i.e. the full tree traversal) in the following scenarios: (a) No element has ever been adjusted in the document we're loading. (b) The client never requests the adjustment rect count. * Source/WebCore/page/ElementTargetingController.cpp: (WebCore::ElementTargetingController::adjustVisibility): (WebCore::ElementTargetingController::adjustVisibilityInRepeatedlyTargetedRegions): (WebCore::ElementTargetingController::applyVisibilityAdjustmentFromSelectors): (WebCore::ElementTargetingController::didChangeMainDocument): (WebCore::ElementTargetingController::numberOfVisibilityAdjustmentRects): (WebCore::ElementTargetingController::recomputeAdjustedElementsIfNeeded): Collect the set of elements with active visibility adjustments, if necessary. See above for more details. (WebCore::ElementTargetingController::numberOfVisibilityAdjustmentRects const): Deleted. Make this non-const, now that it invokes `recomputeAdjustedElementsIfNeeded`. * Source/WebCore/page/ElementTargetingController.h: * Source/WebCore/page/LocalFrame.cpp: (WebCore::LocalFrame::setDocument): * Source/WebCore/page/Page.cpp: (WebCore::Page::didChangeMainDocument): Additionally plumb the new document through `didChangeMainDocument()`. Perhaps counterintuitively, `didChangeMainDocument` is invoked *before* the main frame's document has actually changed to the new value. * Source/WebCore/page/Page.h: * Tools/TestWebKitAPI/Tests/WebKitCocoa/ElementTargetingTests.mm: (TestWebKitAPI::TEST(ElementTargeting, CountVisibilityAdjustmentsAfterNavigatingBack)): Add a new API test to exercise the change. Canonical link: https://commits.webkit.org/281452@main To unsubscribe from these emails, change your notification settings at https://github.com/WebKit/WebKit/settings/notifications _______________________________________________ webkit-changes mailing list webkit-changes@lists.webkit.org https://lists.webkit.org/mailman/listinfo/webkit-changes