Changeset 252761 in webkit


Ignore:
Timestamp:
Nov 21, 2019 9:09:36 PM (4 years ago)
Author:
rniwa@webkit.org
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.
Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r252760 r252761  
     12019-11-21  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Scrolling to fragment shouldn't happen as a part of updating style
     4        https://bugs.webkit.org/show_bug.cgi?id=203982
     5
     6        Reviewed by Simon Fraser.
     7
     8        Made an existing test more robust.
     9
     10        * fast/parser/adoption-agency-unload-iframe-4.html: Made the iframe's data URL not cachable.
     11
    1122019-11-21  Myles C. Maxfield  <mmaxfield@apple.com>
    213
  • trunk/LayoutTests/fast/parser/adoption-agency-unload-iframe-4.html

    r212621 r252761  
    3838    doc.write(`<div><b><p><script>
    3939        parent.p = document.querySelector('p');
    40         document.write('<link rel="stylesheet" href="data:,a">');
     40        document.write('<link rel="stylesheet" href="data:,a${(new Date).toISOString() + Math.random()}">');
    4141        location.hash = 'target';
    4242    <\/script></b></p></div></body>`);
  • trunk/Source/WebCore/ChangeLog

    r252760 r252761  
     12019-11-21  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Scrolling to fragment shouldn't happen as a part of updating style
     4        https://bugs.webkit.org/show_bug.cgi?id=203982
     5
     6        Reviewed by Simon Fraser.
     7
     8        Don't scroll to the current URL's fragment at the end of resolveStyle. Instead, schedule a task
     9        to scroll to the current URL's fragment when all pending stylesheets have finished loading.
     10
     11        This patch also moves the code which sets a Document's m_gotoAnchorNeededAfterStylesheetsLoadflag
     12        from FrameView to FrameLoader as FrameView shouldn't be relying on the states of pending stylesheets.
     13
     14        * dom/Document.cpp:
     15        (WebCore::Document::resolveStyle): Removed the code to scroll to the current URL's fragment.
     16        (WebCore::Document::didRemoveAllPendingStylesheet): Added a code to schedule a task to scoll.
     17        * loader/FrameLoader.cpp:
     18        (WebCore::FrameLoader::scrollToFragmentWithParentBoundary): Moved the code to trigger the code
     19        in didRemoveAllPendingStylesheet from FrameView.
     20        * page/FrameView.cpp:
     21        (WebCore::FrameView::scrollToFragment):
     22        (WebCore::FrameView::scrollToFragmentInternal): Renamed from scrollToAnchor since this function sets
     23        the current anchor. Also removed the code which defers the scrolling based on pending stylesheets'
     24        states since such a code doesn't belong in FrameView.
     25        * page/FrameView.h:
     26
    1272019-11-21  Myles C. Maxfield  <mmaxfield@apple.com>
    228
  • trunk/Source/WebCore/dom/Document.cpp

    r252723 r252761  
    20022002    if (updatedCompositingLayers && !frameView.needsLayout())
    20032003        frameView.viewportContentsChanged();
    2004 
    2005     if (m_gotoAnchorNeededAfterStylesheetsLoad && !styleScope().hasPendingSheets())
    2006         frameView.scrollToFragment(m_url);
    20072004}
    20082005
     
    34733470    if (auto* parser = scriptableDocumentParser())
    34743471        parser->executeScriptsWaitingForStylesheetsSoon();
     3472
     3473    if (m_gotoAnchorNeededAfterStylesheetsLoad) {
     3474        // https://html.spec.whatwg.org/multipage/browsing-the-web.html#try-to-scroll-to-the-fragment
     3475        eventLoop().queueTask(TaskSource::Networking, [protectedThis = makeRef(*this), this] {
     3476            auto frameView = makeRefPtr(view());
     3477            if (!frameView)
     3478                return;
     3479            if (!haveStylesheetsLoaded()) {
     3480                m_gotoAnchorNeededAfterStylesheetsLoad = true;
     3481                return;
     3482            }
     3483            frameView->scrollToFragment(m_url);
     3484        });
     3485    }
    34753486}
    34763487
  • trunk/Source/WebCore/loader/FrameLoader.cpp

    r252641 r252761  
    32513251void FrameLoader::scrollToFragmentWithParentBoundary(const URL& url, bool isNewNavigation)
    32523252{
    3253     FrameView* view = m_frame.view();
    3254     if (!view)
    3255         return;
    3256 
    3257     if (isSameDocumentReload(isNewNavigation, m_loadType) || itemAllowsScrollRestoration(history().currentItem()))
    3258         view->scrollToFragment(url);
     3253    auto view = makeRefPtr(m_frame.view());
     3254    auto document = makeRefPtr(m_frame.document());
     3255    if (!view || !document)
     3256        return;
     3257
     3258    if (isSameDocumentReload(isNewNavigation, m_loadType) || itemAllowsScrollRestoration(history().currentItem())) {
     3259        // https://html.spec.whatwg.org/multipage/browsing-the-web.html#try-to-scroll-to-the-fragment
     3260        if (!document->haveStylesheetsLoaded())
     3261            document->setGotoAnchorNeededAfterStylesheetsLoad(true);
     3262        else
     3263            view->scrollToFragment(url);
     3264    }
     3265
    32593266}
    32603267
  • trunk/Source/WebCore/page/FrameView.cpp

    r252628 r252761  
    21702170{
    21712171    String fragmentIdentifier = url.fragmentIdentifier();
    2172     if (scrollToAnchor(fragmentIdentifier))
     2172    if (scrollToFragmentInternal(fragmentIdentifier))
    21732173        return true;
    21742174
    21752175    // Try again after decoding the ref, based on the document's encoding.
    21762176    if (TextResourceDecoder* decoder = frame().document()->decoder()) {
    2177         if (scrollToAnchor(decodeURLEscapeSequences(fragmentIdentifier, decoder->encoding())))
     2177        if (scrollToFragmentInternal(decodeURLEscapeSequences(fragmentIdentifier, decoder->encoding())))
    21782178            return true;
    21792179    }
     
    21832183}
    21842184
    2185 bool FrameView::scrollToAnchor(const String& fragmentIdentifier)
     2185bool FrameView::scrollToFragmentInternal(const String& fragmentIdentifier)
    21862186{
    21872187    LOG(Scrolling, "FrameView::scrollToAnchor %s", fragmentIdentifier.utf8().data());
     
    21932193    ASSERT(frame().document());
    21942194    auto& document = *frame().document();
    2195 
    2196     if (!document.haveStylesheetsLoaded()) {
    2197         document.setGotoAnchorNeededAfterStylesheetsLoad(true);
    2198         return false;
    2199     }
    2200 
    2201     document.setGotoAnchorNeededAfterStylesheetsLoad(false);
     2195    RELEASE_ASSERT(document.haveStylesheetsLoaded());
    22022196
    22032197    Element* anchorElement = document.findAnchor(fragmentIdentifier);
  • trunk/Source/WebCore/page/FrameView.h

    r252552 r252761  
    426426
    427427    bool scrollToFragment(const URL&);
    428     bool scrollToAnchor(const String&);
    429428    void maintainScrollPositionAtAnchor(ContainerNode*);
    430429    WEBCORE_EXPORT void scrollElementToRect(const Element&, const IntRect&);
     
    779778    void updateWidgetPositionsTimerFired();
    780779
     780    bool scrollToFragmentInternal(const String&);
    781781    void scrollToAnchor();
    782782    void scrollPositionChanged(const ScrollPosition& oldPosition, const ScrollPosition& newPosition);
Note: See TracChangeset for help on using the changeset viewer.