diff --git a/Userland/Libraries/LibWeb/Layout/Box.cpp b/Userland/Libraries/LibWeb/Layout/Box.cpp index e56b4fd60c..99717c3a56 100644 --- a/Userland/Libraries/LibWeb/Layout/Box.cpp +++ b/Userland/Libraries/LibWeb/Layout/Box.cpp @@ -1,5 +1,6 @@ /* * Copyright (c) 2018-2020, Andreas Kling + * Copyright (c) 2021, Sam Atkins * * SPDX-License-Identifier: BSD-2-Clause */ @@ -12,6 +13,7 @@ #include #include #include +#include #include #include @@ -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 diff --git a/Userland/Libraries/LibWeb/Layout/Box.h b/Userland/Libraries/LibWeb/Layout/Box.h index 26060e1c2b..003ddafbe4 100644 --- a/Userland/Libraries/LibWeb/Layout/Box.h +++ b/Userland/Libraries/LibWeb/Layout/Box.h @@ -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; diff --git a/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.h b/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.h index a3a28398d8..680a3db6d8 100644 --- a/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.h +++ b/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.h @@ -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; }; diff --git a/Userland/Libraries/LibWeb/Layout/FormattingContext.h b/Userland/Libraries/LibWeb/Layout/FormattingContext.h index e67799000f..c4e30c4ad7 100644 --- a/Userland/Libraries/LibWeb/Layout/FormattingContext.h +++ b/Userland/Libraries/LibWeb/Layout/FormattingContext.h @@ -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&);