Title: [252761] trunk
Revision
252761
Author
[email protected]
Date
2019-11-21 21:09:36 -0800 (Thu, 21 Nov 2019)

Log Message

Scrolling to fragment shouldn't happen as a part of updating style
https://bugs.webkit.org/show_bug.cgi?id=203982

Reviewed by Simon Fraser.

Source/WebCore:

Don't scroll to the current URL's fragment at the end of resolveStyle. Instead, schedule a task
to scroll to the current URL's fragment when all pending stylesheets have finished loading.

This patch also moves the code which sets a Document's m_gotoAnchorNeededAfterStylesheetsLoadflag
from FrameView to FrameLoader as FrameView shouldn't be relying on the states of pending stylesheets.

* dom/Document.cpp:
(WebCore::Document::resolveStyle): Removed the code to scroll to the current URL's fragment.
(WebCore::Document::didRemoveAllPendingStylesheet): Added a code to schedule a task to scoll.
* loader/FrameLoader.cpp:
(WebCore::FrameLoader::scrollToFragmentWithParentBoundary): Moved the code to trigger the code
in didRemoveAllPendingStylesheet from FrameView.
* page/FrameView.cpp:
(WebCore::FrameView::scrollToFragment):
(WebCore::FrameView::scrollToFragmentInternal): Renamed from scrollToAnchor since this function sets
the current anchor. Also removed the code which defers the scrolling based on pending stylesheets'
states since such a code doesn't belong in FrameView.
* page/FrameView.h:

LayoutTests:

Made an existing test more robust.

* fast/parser/adoption-agency-unload-iframe-4.html: Made the iframe's data URL not cachable.

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (252760 => 252761)


--- trunk/LayoutTests/ChangeLog	2019-11-22 03:56:06 UTC (rev 252760)
+++ trunk/LayoutTests/ChangeLog	2019-11-22 05:09:36 UTC (rev 252761)
@@ -1,3 +1,14 @@
+2019-11-21  Ryosuke Niwa  <[email protected]>
+
+        Scrolling to fragment shouldn't happen as a part of updating style
+        https://bugs.webkit.org/show_bug.cgi?id=203982
+
+        Reviewed by Simon Fraser.
+
+        Made an existing test more robust.
+
+        * fast/parser/adoption-agency-unload-iframe-4.html: Made the iframe's data URL not cachable.
+
 2019-11-21  Myles C. Maxfield  <[email protected]>
 
         Remove font-variant @font-face descriptor

Modified: trunk/LayoutTests/fast/parser/adoption-agency-unload-iframe-4.html (252760 => 252761)


--- trunk/LayoutTests/fast/parser/adoption-agency-unload-iframe-4.html	2019-11-22 03:56:06 UTC (rev 252760)
+++ trunk/LayoutTests/fast/parser/adoption-agency-unload-iframe-4.html	2019-11-22 05:09:36 UTC (rev 252761)
@@ -37,7 +37,7 @@
 
     doc.write(`<div><b><p><script>
         parent.p = document.querySelector('p');
-        document.write('<link rel="stylesheet" href=""
+        document.write('<link rel="stylesheet" href="" Date).toISOString() + Math.random()}">');
         location.hash = 'target';
     <\/script></b></p></div></body>`);
 });

Modified: trunk/Source/WebCore/ChangeLog (252760 => 252761)


--- trunk/Source/WebCore/ChangeLog	2019-11-22 03:56:06 UTC (rev 252760)
+++ trunk/Source/WebCore/ChangeLog	2019-11-22 05:09:36 UTC (rev 252761)
@@ -1,3 +1,29 @@
+2019-11-21  Ryosuke Niwa  <[email protected]>
+
+        Scrolling to fragment shouldn't happen as a part of updating style
+        https://bugs.webkit.org/show_bug.cgi?id=203982
+
+        Reviewed by Simon Fraser.
+
+        Don't scroll to the current URL's fragment at the end of resolveStyle. Instead, schedule a task
+        to scroll to the current URL's fragment when all pending stylesheets have finished loading.
+
+        This patch also moves the code which sets a Document's m_gotoAnchorNeededAfterStylesheetsLoadflag
+        from FrameView to FrameLoader as FrameView shouldn't be relying on the states of pending stylesheets.
+
+        * dom/Document.cpp:
+        (WebCore::Document::resolveStyle): Removed the code to scroll to the current URL's fragment.
+        (WebCore::Document::didRemoveAllPendingStylesheet): Added a code to schedule a task to scoll.
+        * loader/FrameLoader.cpp:
+        (WebCore::FrameLoader::scrollToFragmentWithParentBoundary): Moved the code to trigger the code
+        in didRemoveAllPendingStylesheet from FrameView.
+        * page/FrameView.cpp:
+        (WebCore::FrameView::scrollToFragment):
+        (WebCore::FrameView::scrollToFragmentInternal): Renamed from scrollToAnchor since this function sets
+        the current anchor. Also removed the code which defers the scrolling based on pending stylesheets'
+        states since such a code doesn't belong in FrameView.
+        * page/FrameView.h:
+
 2019-11-21  Myles C. Maxfield  <[email protected]>
 
         Remove font-variant @font-face descriptor

Modified: trunk/Source/WebCore/dom/Document.cpp (252760 => 252761)


--- trunk/Source/WebCore/dom/Document.cpp	2019-11-22 03:56:06 UTC (rev 252760)
+++ trunk/Source/WebCore/dom/Document.cpp	2019-11-22 05:09:36 UTC (rev 252761)
@@ -2001,9 +2001,6 @@
     // check if they need to be resumed after layout.
     if (updatedCompositingLayers && !frameView.needsLayout())
         frameView.viewportContentsChanged();
-
-    if (m_gotoAnchorNeededAfterStylesheetsLoad && !styleScope().hasPendingSheets())
-        frameView.scrollToFragment(m_url);
 }
 
 void Document::updateTextRenderer(Text& text, unsigned offsetOfReplacedText, unsigned lengthOfReplacedText)
@@ -3472,6 +3469,20 @@
 {
     if (auto* parser = scriptableDocumentParser())
         parser->executeScriptsWaitingForStylesheetsSoon();
+
+    if (m_gotoAnchorNeededAfterStylesheetsLoad) {
+        // https://html.spec.whatwg.org/multipage/browsing-the-web.html#try-to-scroll-to-the-fragment
+        eventLoop().queueTask(TaskSource::Networking, [protectedThis = makeRef(*this), this] {
+            auto frameView = makeRefPtr(view());
+            if (!frameView)
+                return;
+            if (!haveStylesheetsLoaded()) {
+                m_gotoAnchorNeededAfterStylesheetsLoad = true;
+                return;
+            }
+            frameView->scrollToFragment(m_url);
+        });
+    }
 }
 
 bool Document::usesStyleBasedEditability() const

Modified: trunk/Source/WebCore/loader/FrameLoader.cpp (252760 => 252761)


--- trunk/Source/WebCore/loader/FrameLoader.cpp	2019-11-22 03:56:06 UTC (rev 252760)
+++ trunk/Source/WebCore/loader/FrameLoader.cpp	2019-11-22 05:09:36 UTC (rev 252761)
@@ -3250,12 +3250,19 @@
 
 void FrameLoader::scrollToFragmentWithParentBoundary(const URL& url, bool isNewNavigation)
 {
-    FrameView* view = m_frame.view();
-    if (!view)
+    auto view = makeRefPtr(m_frame.view());
+    auto document = makeRefPtr(m_frame.document());
+    if (!view || !document)
         return;
 
-    if (isSameDocumentReload(isNewNavigation, m_loadType) || itemAllowsScrollRestoration(history().currentItem()))
-        view->scrollToFragment(url);
+    if (isSameDocumentReload(isNewNavigation, m_loadType) || itemAllowsScrollRestoration(history().currentItem())) {
+        // https://html.spec.whatwg.org/multipage/browsing-the-web.html#try-to-scroll-to-the-fragment
+        if (!document->haveStylesheetsLoaded())
+            document->setGotoAnchorNeededAfterStylesheetsLoad(true);
+        else
+            view->scrollToFragment(url);
+    }
+
 }
 
 bool FrameLoader::shouldClose()

Modified: trunk/Source/WebCore/page/FrameView.cpp (252760 => 252761)


--- trunk/Source/WebCore/page/FrameView.cpp	2019-11-22 03:56:06 UTC (rev 252760)
+++ trunk/Source/WebCore/page/FrameView.cpp	2019-11-22 05:09:36 UTC (rev 252761)
@@ -2169,12 +2169,12 @@
 bool FrameView::scrollToFragment(const URL& url)
 {
     String fragmentIdentifier = url.fragmentIdentifier();
-    if (scrollToAnchor(fragmentIdentifier))
+    if (scrollToFragmentInternal(fragmentIdentifier))
         return true;
 
     // Try again after decoding the ref, based on the document's encoding.
     if (TextResourceDecoder* decoder = frame().document()->decoder()) {
-        if (scrollToAnchor(decodeURLEscapeSequences(fragmentIdentifier, decoder->encoding())))
+        if (scrollToFragmentInternal(decodeURLEscapeSequences(fragmentIdentifier, decoder->encoding())))
             return true;
     }
 
@@ -2182,7 +2182,7 @@
     return false;
 }
 
-bool FrameView::scrollToAnchor(const String& fragmentIdentifier)
+bool FrameView::scrollToFragmentInternal(const String& fragmentIdentifier)
 {
     LOG(Scrolling, "FrameView::scrollToAnchor %s", fragmentIdentifier.utf8().data());
 
@@ -2192,14 +2192,8 @@
 
     ASSERT(frame().document());
     auto& document = *frame().document();
+    RELEASE_ASSERT(document.haveStylesheetsLoaded());
 
-    if (!document.haveStylesheetsLoaded()) {
-        document.setGotoAnchorNeededAfterStylesheetsLoad(true);
-        return false;
-    }
-
-    document.setGotoAnchorNeededAfterStylesheetsLoad(false);
-
     Element* anchorElement = document.findAnchor(fragmentIdentifier);
 
     LOG(Scrolling, " anchorElement is %p", anchorElement);

Modified: trunk/Source/WebCore/page/FrameView.h (252760 => 252761)


--- trunk/Source/WebCore/page/FrameView.h	2019-11-22 03:56:06 UTC (rev 252760)
+++ trunk/Source/WebCore/page/FrameView.h	2019-11-22 05:09:36 UTC (rev 252761)
@@ -425,7 +425,6 @@
     WEBCORE_EXPORT void adjustPageHeightDeprecated(float* newBottom, float oldTop, float oldBottom, float bottomLimit);
 
     bool scrollToFragment(const URL&);
-    bool scrollToAnchor(const String&);
     void maintainScrollPositionAtAnchor(ContainerNode*);
     WEBCORE_EXPORT void scrollElementToRect(const Element&, const IntRect&);
 
@@ -778,6 +777,7 @@
 
     void updateWidgetPositionsTimerFired();
 
+    bool scrollToFragmentInternal(const String&);
     void scrollToAnchor();
     void scrollPositionChanged(const ScrollPosition& oldPosition, const ScrollPosition& newPosition);
     void scrollableAreaSetChanged();
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to