LibHTML+Browser: Support scrolling to anchor with <a href="#foo">

This patch implements basic support for <a href="#foo"> fragment links.

To figure out where we actually want to scroll to, we have to do
something different based on the layout node's box type. So if it's a
regular LayoutBox we can just use the LayoutBox::position().

However, if it's an inline layout node, we use the position of the
first line box fragment in the containing block contributed by this
layout node or one of its descendants.
This commit is contained in:
Andreas Kling 2019-10-20 09:14:12 +02:00
commit c41bae3d54
Notes: sideshowbarker 2024-07-19 11:37:23 +09:00
8 changed files with 100 additions and 13 deletions

View file

@ -79,10 +79,30 @@ void LayoutNode::set_needs_display()
auto* frame = document().frame();
ASSERT(frame);
for_each_fragment_of_this([&](auto& fragment) {
if (&fragment.layout_node() == this || is_ancestor_of(fragment.layout_node())) {
const_cast<Frame*>(frame)->set_needs_display(fragment.rect());
}
return IterationDecision::Continue;
});
if (auto* block = containing_block()) {
block->for_each_fragment([&](auto& fragment) {
if (&fragment.layout_node() == this || is_ancestor_of(fragment.layout_node())) {
const_cast<Frame*>(frame)->set_needs_display(fragment.rect());
}
return IterationDecision::Continue;
});
}
}
Point LayoutNode::box_type_agnostic_position() const
{
if (is_box())
return to<LayoutBox>(*this).position();
ASSERT(is_inline());
Point position;
if (auto* block = containing_block()) {
block->for_each_fragment([&](auto& fragment) {
if (&fragment.layout_node() == this || is_ancestor_of(fragment.layout_node())) {
position = fragment.rect().location();
return IterationDecision::Break;
}
return IterationDecision::Continue;
});
}
return position;
}