mirror of
https://github.com/RGBCube/serenity
synced 2025-07-10 05:17:34 +00:00
LibWeb: Improve computation of a layout node's containing block
In particular, we now compute the containing block of boxes with position:absolute and position:fixed (more) correctly.
This commit is contained in:
parent
762617a028
commit
7fcf61be35
3 changed files with 43 additions and 5 deletions
|
@ -29,7 +29,9 @@
|
|||
#include <LibWeb/DOM/Element.h>
|
||||
#include <LibWeb/Frame.h>
|
||||
#include <LibWeb/Layout/LayoutBlock.h>
|
||||
#include <LibWeb/Layout/LayoutDocument.h>
|
||||
#include <LibWeb/Layout/LayoutNode.h>
|
||||
#include <LibWeb/Layout/LayoutReplaced.h>
|
||||
|
||||
namespace Web {
|
||||
|
||||
|
@ -53,13 +55,36 @@ void LayoutNode::layout(LayoutMode layout_mode)
|
|||
});
|
||||
}
|
||||
|
||||
bool LayoutNode::can_contain_boxes_with_position_absolute() const
|
||||
{
|
||||
return style().position() != CSS::Position::Static || is_root();
|
||||
}
|
||||
|
||||
const LayoutBlock* LayoutNode::containing_block() const
|
||||
{
|
||||
for (auto* ancestor = parent(); ancestor; ancestor = ancestor->parent()) {
|
||||
if (is<LayoutBlock>(*ancestor))
|
||||
return to<LayoutBlock>(ancestor);
|
||||
if (is_text()) {
|
||||
auto* ancestor = parent();
|
||||
while (ancestor && ((ancestor->is_inline() && !is<LayoutReplaced>(*ancestor)) || !is<LayoutBlock>(*ancestor)))
|
||||
ancestor = ancestor->parent();
|
||||
return to<LayoutBlock>(ancestor);
|
||||
}
|
||||
return nullptr;
|
||||
|
||||
if (is_absolutely_positioned()) {
|
||||
auto* ancestor = parent();
|
||||
while (ancestor && !ancestor->can_contain_boxes_with_position_absolute())
|
||||
ancestor = ancestor->parent();
|
||||
while (ancestor && (!is<LayoutBlock>(ancestor) || ancestor->is_anonymous()))
|
||||
ancestor = ancestor->containing_block();
|
||||
return to<LayoutBlock>(ancestor);
|
||||
}
|
||||
|
||||
if (style().position() == CSS::Position::Fixed)
|
||||
return &root();
|
||||
|
||||
auto* ancestor = parent();
|
||||
while (ancestor && ((ancestor->is_inline() && !is<LayoutReplaced>(*ancestor)) || !is<LayoutBlock>(*ancestor)))
|
||||
ancestor = ancestor->parent();
|
||||
return to<LayoutBlock>(ancestor);
|
||||
}
|
||||
|
||||
void LayoutNode::render(RenderingContext& context)
|
||||
|
@ -155,4 +180,10 @@ Gfx::FloatPoint LayoutNode::box_type_agnostic_position() const
|
|||
return position;
|
||||
}
|
||||
|
||||
bool LayoutNode::is_absolutely_positioned() const
|
||||
{
|
||||
return style().position() == CSS::Position::Absolute;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue