From 51102254b5b14fcddbe51f0b79299241f09ee0e2 Mon Sep 17 00:00:00 2001 From: Shannon Booth Date: Wed, 15 Jan 2025 17:15:25 +1300 Subject: [PATCH] LibWeb/HTML: Scroll to the fragment before loading the document Otherwise nowhere ends up scrolling to the fragment specified by the fragment in document's URL. This fixes ladybird scrolling to the correct location in the document when navigating to a link that has a fragment, e.g: https://html.spec.whatwg.org/multipage/browsing-the-web.html#try-to-scroll-to-the-fragment As well as use of the :target selector. --- Libraries/LibWeb/HTML/Parser/HTMLParser.cpp | 3 ++ .../nodes/ParentNode-querySelector-All.txt | 12 +++---- .../wpt-import/url/data-uri-fragment.txt | 6 ++++ .../wpt-import/url/data-uri-fragment.html | 34 +++++++++++++++++++ 4 files changed, 49 insertions(+), 6 deletions(-) create mode 100644 Tests/LibWeb/Text/expected/wpt-import/url/data-uri-fragment.txt create mode 100644 Tests/LibWeb/Text/input/wpt-import/url/data-uri-fragment.html diff --git a/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp b/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp index be21f5b48e0..7b00353e93f 100644 --- a/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp +++ b/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp @@ -310,6 +310,9 @@ void HTMLParser::the_end(GC::Ref document, GC::Ptr pa (void)document->scripts_to_execute_when_parsing_has_finished().take_first(); } + // FIXME: Spec bug: https://github.com/whatwg/html/issues/10914 + document->scroll_to_the_fragment(); + // 6. Queue a global task on the DOM manipulation task source given the Document's relevant global object to run the following substeps: queue_global_task(HTML::Task::Source::DOMManipulation, *document, GC::create_function(heap, [document] { // 1. Set the Document's load timing info's DOM content loaded event start time to the current high resolution time given the Document's relevant global object. diff --git a/Tests/LibWeb/Text/expected/wpt-import/dom/nodes/ParentNode-querySelector-All.txt b/Tests/LibWeb/Text/expected/wpt-import/dom/nodes/ParentNode-querySelector-All.txt index 58b8a586545..aefda0483a4 100644 --- a/Tests/LibWeb/Text/expected/wpt-import/dom/nodes/ParentNode-querySelector-All.txt +++ b/Tests/LibWeb/Text/expected/wpt-import/dom/nodes/ParentNode-querySelector-All.txt @@ -2,8 +2,8 @@ Harness status: OK Found 1975 tests -1955 Pass -20 Fail +1959 Pass +16 Fail Pass Selectors-API Test Suite: HTML Pass Document supports querySelector Pass Document supports querySelectorAll @@ -601,8 +601,8 @@ Pass Document.querySelectorAll: :link and :visited pseudo-class selectors, match Pass Document.querySelector: :link and :visited pseudo-class selectors, matching a and area elements with href attributes: #pseudo-link :link, #pseudo-link :visited Pass Document.querySelectorAll: :link and :visited pseudo-class selectors, matching no elements: #head :link, #head :visited Pass Document.querySelector: :link and :visited pseudo-class selectors, matching no elements: #head :link, #head :visited -Fail Document.querySelectorAll: :target pseudo-class selector, matching the element referenced by the URL fragment identifier: :target -Fail Document.querySelector: :target pseudo-class selector, matching the element referenced by the URL fragment identifier: :target +Pass Document.querySelectorAll: :target pseudo-class selector, matching the element referenced by the URL fragment identifier: :target +Pass Document.querySelector: :target pseudo-class selector, matching the element referenced by the URL fragment identifier: :target Pass Document.querySelectorAll: :lang pseudo-class selector, matching inherited language: #pseudo-lang-div1:lang(en) Pass Document.querySelector: :lang pseudo-class selector, matching inherited language: #pseudo-lang-div1:lang(en) Pass Document.querySelectorAll: :lang pseudo-class selector, matching specified language with exact value: #pseudo-lang-div2:lang(fr) @@ -1893,8 +1893,8 @@ Pass In-document Element.querySelectorAll: :link and :visited pseudo-class selec Pass In-document Element.querySelector: :link and :visited pseudo-class selectors, not matching link elements with href attributes: #head :link, #head :visited Pass In-document Element.querySelectorAll: :link and :visited pseudo-class selectors, chained, mutually exclusive pseudo-classes match nothing: :link:visited Pass In-document Element.querySelector: :link and :visited pseudo-class selectors, chained, mutually exclusive pseudo-classes match nothing: :link:visited -Fail In-document Element.querySelectorAll: :target pseudo-class selector, matching the element referenced by the URL fragment identifier: :target -Fail In-document Element.querySelector: :target pseudo-class selector, matching the element referenced by the URL fragment identifier: :target +Pass In-document Element.querySelectorAll: :target pseudo-class selector, matching the element referenced by the URL fragment identifier: :target +Pass In-document Element.querySelector: :target pseudo-class selector, matching the element referenced by the URL fragment identifier: :target Pass In-document Element.querySelectorAll: :lang pseudo-class selector, matching inherited language: #pseudo-lang-div1:lang(en) Pass In-document Element.querySelector: :lang pseudo-class selector, matching inherited language: #pseudo-lang-div1:lang(en) Pass In-document Element.querySelectorAll: :lang pseudo-class selector, matching specified language with exact value: #pseudo-lang-div2:lang(fr) diff --git a/Tests/LibWeb/Text/expected/wpt-import/url/data-uri-fragment.txt b/Tests/LibWeb/Text/expected/wpt-import/url/data-uri-fragment.txt new file mode 100644 index 00000000000..495399b301f --- /dev/null +++ b/Tests/LibWeb/Text/expected/wpt-import/url/data-uri-fragment.txt @@ -0,0 +1,6 @@ +Harness status: OK + +Found 1 tests + +1 Pass +Pass Data URI parsing of fragments \ No newline at end of file diff --git a/Tests/LibWeb/Text/input/wpt-import/url/data-uri-fragment.html b/Tests/LibWeb/Text/input/wpt-import/url/data-uri-fragment.html new file mode 100644 index 00000000000..ac64f4dfd45 --- /dev/null +++ b/Tests/LibWeb/Text/input/wpt-import/url/data-uri-fragment.html @@ -0,0 +1,34 @@ + + +Data URI parsing of fragments + + + + + + + + +