1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 13:48:12 +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:
Andreas Kling 2019-10-20 09:14:12 +02:00
parent 202dfbd6cd
commit c41bae3d54
8 changed files with 100 additions and 13 deletions

View file

@ -30,6 +30,11 @@ public:
LayoutBlock* next_sibling() { return to<LayoutBlock>(LayoutNode::next_sibling()); }
const LayoutBlock* next_sibling() const { return to<LayoutBlock>(LayoutNode::next_sibling()); }
template<typename Callback>
void for_each_fragment(Callback);
template<typename Callback>
void for_each_fragment(Callback) const;
private:
virtual bool is_block() const override { return true; }
@ -46,10 +51,20 @@ private:
};
template<typename Callback>
void LayoutNode::for_each_fragment_of_this(Callback callback)
void LayoutBlock::for_each_fragment(Callback callback)
{
auto& block = *containing_block();
for (auto& line_box : block.line_boxes()) {
for (auto& line_box : line_boxes()) {
for (auto& fragment : line_box.fragments()) {
if (callback(fragment) == IterationDecision::Break)
return;
}
}
}
template<typename Callback>
void LayoutBlock::for_each_fragment(Callback callback) const
{
for (auto& line_box : line_boxes()) {
for (auto& fragment : line_box.fragments()) {
if (callback(fragment) == IterationDecision::Break)
return;