mirror of
https://github.com/RGBCube/serenity
synced 2025-05-23 18:35:07 +00:00
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:
parent
202dfbd6cd
commit
c41bae3d54
8 changed files with 100 additions and 13 deletions
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue