1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 07:17:35 +00:00

LibWeb: Implement "out-of-flow" property of Layout Box

In some situations, a layout box should not participate in the standard
layout process, for example when set to `position: absolute`.
This commit is contained in:
Sam Atkins 2021-09-15 12:19:42 +01:00 committed by Andreas Kling
parent e80396e044
commit 2844f89a83
4 changed files with 30 additions and 0 deletions

View file

@ -1,5 +1,6 @@
/*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -12,6 +13,7 @@
#include <LibWeb/HTML/HTMLHtmlElement.h>
#include <LibWeb/Layout/BlockBox.h>
#include <LibWeb/Layout/Box.h>
#include <LibWeb/Layout/FormattingContext.h>
#include <LibWeb/Page/BrowsingContext.h>
#include <LibWeb/Painting/BorderPainting.h>
@ -317,6 +319,29 @@ Box::BorderRadiusData Box::normalized_border_radius_data()
return { (int)top_left_radius, (int)top_right_radius, (int)bottom_right_radius, (int)bottom_left_radius };
}
// https://www.w3.org/TR/css-display-3/#out-of-flow
bool Box::is_out_of_flow(FormattingContext const& formatting_context) const
{
// A box is out of flow if either:
// 1. It is floated (which requires that floating is not inhibited).
if (!formatting_context.inhibits_floating() && computed_values().float_() != CSS::Float::None)
return true;
// 2. It is "absolutely positioned".
switch (computed_values().position()) {
case CSS::Position::Absolute:
case CSS::Position::Fixed:
return true;
case CSS::Position::Static:
case CSS::Position::Relative:
case CSS::Position::Sticky:
break;
}
return false;
}
HitTestResult Box::hit_test(const Gfx::IntPoint& position, HitTestType type) const
{
// FIXME: It would be nice if we could confidently skip over hit testing

View file

@ -97,6 +97,8 @@ public:
float absolute_y() const { return absolute_rect().y(); }
Gfx::FloatPoint absolute_position() const { return absolute_rect().location(); }
bool is_out_of_flow(FormattingContext const&) const;
virtual HitTestResult hit_test(const Gfx::IntPoint&, HitTestType) const override;
virtual void set_needs_display() override;

View file

@ -15,6 +15,8 @@ public:
FlexFormattingContext(Box& containing_block, FormattingContext* parent);
~FlexFormattingContext();
virtual bool inhibits_floating() const override { return true; }
virtual void run(Box&, LayoutMode) override;
};

View file

@ -21,6 +21,7 @@ public:
const FormattingContext* parent() const { return m_parent; }
virtual bool is_block_formatting_context() const { return false; }
virtual bool inhibits_floating() const { return false; }
static bool creates_block_formatting_context(const Box&);