From 268492413afbf17e4e198e73549ace9f090cb953 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Fri, 14 Jul 2023 10:02:19 +0200 Subject: [PATCH] LibWeb: Add Paintable::stacking_context_rooted_here() This is a convenience helper that lets you get the stacking context rooted at a given paintable, without checking that the paintable is a box first. --- Userland/Libraries/LibWeb/Painting/Paintable.cpp | 10 +++++++++- Userland/Libraries/LibWeb/Painting/Paintable.h | 2 ++ Userland/Libraries/LibWeb/Painting/StackingContext.cpp | 2 +- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibWeb/Painting/Paintable.cpp b/Userland/Libraries/LibWeb/Painting/Paintable.cpp index 24839e0bba..3abbe3a304 100644 --- a/Userland/Libraries/LibWeb/Painting/Paintable.cpp +++ b/Userland/Libraries/LibWeb/Painting/Paintable.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Andreas Kling + * Copyright (c) 2022-2023, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ @@ -7,6 +7,7 @@ #include #include #include +#include namespace Web::Painting { @@ -86,4 +87,11 @@ Paintable const* Paintable::previous_sibling() const return layout_node ? layout_node->paintable() : nullptr; } +StackingContext const* Paintable::stacking_context_rooted_here() const +{ + if (!layout_node().is_box()) + return nullptr; + return static_cast(*this).stacking_context(); +} + } diff --git a/Userland/Libraries/LibWeb/Painting/Paintable.h b/Userland/Libraries/LibWeb/Painting/Paintable.h index 4b6c57f19b..8dd79305a5 100644 --- a/Userland/Libraries/LibWeb/Painting/Paintable.h +++ b/Userland/Libraries/LibWeb/Painting/Paintable.h @@ -134,6 +134,8 @@ public: template bool fast_is() const = delete; + StackingContext const* stacking_context_rooted_here() const; + protected: explicit Paintable(Layout::Node const& layout_node) : m_layout_node(layout_node) diff --git a/Userland/Libraries/LibWeb/Painting/StackingContext.cpp b/Userland/Libraries/LibWeb/Painting/StackingContext.cpp index b591195c09..245c593721 100644 --- a/Userland/Libraries/LibWeb/Painting/StackingContext.cpp +++ b/Userland/Libraries/LibWeb/Painting/StackingContext.cpp @@ -444,7 +444,7 @@ Gfx::FloatPoint StackingContext::compute_transform_origin() const template static TraversalDecision for_each_in_inclusive_subtree_of_type_within_same_stacking_context_in_reverse(Paintable const& paintable, Callback callback) { - if (is(paintable) && static_cast(paintable).stacking_context()) { + if (paintable.stacking_context_rooted_here()) { // Note: Include the stacking context (so we can hit test it), but don't recurse into it. if (auto decision = callback(static_cast(paintable)); decision != TraversalDecision::Continue) return decision;