mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 04:27:44 +00:00
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.
This commit is contained in:
parent
f161e20e57
commit
fdc9dc5729
1 changed files with 9 additions and 5 deletions
|
@ -392,12 +392,13 @@ void BrowsingContext::scroll_to(Gfx::IntPoint const& position)
|
||||||
|
|
||||||
void BrowsingContext::scroll_to_anchor(String const& fragment)
|
void BrowsingContext::scroll_to_anchor(String const& fragment)
|
||||||
{
|
{
|
||||||
if (!active_document())
|
JS::GCPtr<DOM::Document> document = active_document();
|
||||||
|
if (!document)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
auto element = active_document()->get_element_by_id(fragment);
|
auto element = document->get_element_by_id(fragment);
|
||||||
if (!element) {
|
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()) {
|
for (auto& candidate : candidates->collect_matching_elements()) {
|
||||||
if (is<HTML::HTMLAnchorElement>(*candidate)) {
|
if (is<HTML::HTMLAnchorElement>(*candidate)) {
|
||||||
element = &verify_cast<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;
|
||||||
|
|
||||||
if (!element || !element->layout_node())
|
document->force_layout();
|
||||||
|
|
||||||
|
if (!element->layout_node())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
auto& layout_node = *element->layout_node();
|
auto& layout_node = *element->layout_node();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue