From a4bc7e2d96b54369e16f15ad9a2d893e9a6669ba Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 19 Feb 2022 16:42:02 +0100 Subject: [PATCH] LibWeb: Hack BFC to always remember to handle position:absolute elements Normally we don't layout position:absolute elements until after the parent formatting context has assigned dimensions to the current formatting context's root box. However, some of our parent contexts (especially FFC) don't do this reliably, which makes position:absolute children have 0x0 dimensions. Hack this for now by making ~BFC() pretend that the parent assigned dimensions if it hadn't done it already. --- .../Libraries/LibWeb/Layout/BlockFormattingContext.cpp | 10 +++++++++- .../Libraries/LibWeb/Layout/BlockFormattingContext.h | 2 ++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp index ad964baba3..43955c9454 100644 --- a/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2021, Andreas Kling + * Copyright (c) 2020-2022, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ @@ -25,6 +25,12 @@ BlockFormattingContext::BlockFormattingContext(BlockContainer& root, FormattingC BlockFormattingContext::~BlockFormattingContext() { + if (!m_was_notified_after_parent_dimensioned_my_root_box) { + // HACK: The parent formatting context never notified us after assigning dimensions to our root box. + // Pretend that it did anyway, to make sure absolutely positioned children get laid out. + // FIXME: Get rid of this hack once parent contexts behave properly. + parent_context_did_dimension_child_root_box(); + } } bool BlockFormattingContext::is_initial() const @@ -47,6 +53,8 @@ void BlockFormattingContext::run(Box&, LayoutMode layout_mode) void BlockFormattingContext::parent_context_did_dimension_child_root_box() { + m_was_notified_after_parent_dimensioned_my_root_box = true; + for (auto& box : m_absolutely_positioned_boxes) layout_absolutely_positioned_element(box); diff --git a/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.h b/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.h index b2d28c37b3..c9d7c18158 100644 --- a/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.h +++ b/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.h @@ -76,6 +76,8 @@ private: FloatSideData m_right_floats; Vector m_absolutely_positioned_boxes; + + bool m_was_notified_after_parent_dimensioned_my_root_box { false }; }; }