summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/HTML/BrowsingContext.cpp
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2022-09-26 11:08:42 +0200
committerAndreas Kling <kling@serenityos.org>2022-09-29 18:33:41 +0200
commitfdc9dc572969df21baa9267ecf50ec2607c05372 (patch)
treee52c852e75384cbaed99974bacc0600a1b3253fb /Userland/Libraries/LibWeb/HTML/BrowsingContext.cpp
parentf161e20e5782464010290a6d417e6a1e14e6412b (diff)
downloadserenity-fdc9dc572969df21baa9267ecf50ec2607c05372.zip
LibWeb: Don't force layout when scrolling to non-existent anchor
If we're asked to scroll to an anchor element that's not actually in the document, we don't need to perform a layout.
Diffstat (limited to 'Userland/Libraries/LibWeb/HTML/BrowsingContext.cpp')
-rw-r--r--Userland/Libraries/LibWeb/HTML/BrowsingContext.cpp14
1 files changed, 9 insertions, 5 deletions
diff --git a/Userland/Libraries/LibWeb/HTML/BrowsingContext.cpp b/Userland/Libraries/LibWeb/HTML/BrowsingContext.cpp
index 18cbdbdcfd..e90f88cae1 100644
--- a/Userland/Libraries/LibWeb/HTML/BrowsingContext.cpp
+++ b/Userland/Libraries/LibWeb/HTML/BrowsingContext.cpp
@@ -392,12 +392,13 @@ void BrowsingContext::scroll_to(Gfx::IntPoint const& position)
void BrowsingContext::scroll_to_anchor(String const& fragment)
{
- if (!active_document())
+ JS::GCPtr<DOM::Document> document = active_document();
+ if (!document)
return;
- auto element = active_document()->get_element_by_id(fragment);
+ auto element = document->get_element_by_id(fragment);
if (!element) {
- auto candidates = active_document()->get_elements_by_name(fragment);
+ auto candidates = document->get_elements_by_name(fragment);
for (auto& candidate : candidates->collect_matching_elements()) {
if (is<HTML::HTMLAnchorElement>(*candidate)) {
element = &verify_cast<HTML::HTMLAnchorElement>(*candidate);
@@ -406,9 +407,12 @@ void BrowsingContext::scroll_to_anchor(String const& fragment)
}
}
- active_document()->force_layout();
+ if (!element)
+ return;
+
+ document->force_layout();
- if (!element || !element->layout_node())
+ if (!element->layout_node())
return;
auto& layout_node = *element->layout_node();