mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 09:57:34 +00:00
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.
This commit is contained in:
parent
2138c164c9
commit
268492413a
3 changed files with 12 additions and 2 deletions
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
|
* Copyright (c) 2022-2023, Andreas Kling <kling@serenityos.org>
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
@ -7,6 +7,7 @@
|
||||||
#include <LibWeb/DOM/Document.h>
|
#include <LibWeb/DOM/Document.h>
|
||||||
#include <LibWeb/Layout/BlockContainer.h>
|
#include <LibWeb/Layout/BlockContainer.h>
|
||||||
#include <LibWeb/Painting/Paintable.h>
|
#include <LibWeb/Painting/Paintable.h>
|
||||||
|
#include <LibWeb/Painting/PaintableBox.h>
|
||||||
|
|
||||||
namespace Web::Painting {
|
namespace Web::Painting {
|
||||||
|
|
||||||
|
@ -86,4 +87,11 @@ Paintable const* Paintable::previous_sibling() const
|
||||||
return layout_node ? layout_node->paintable() : nullptr;
|
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<PaintableBox const&>(*this).stacking_context();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -134,6 +134,8 @@ public:
|
||||||
template<typename T>
|
template<typename T>
|
||||||
bool fast_is() const = delete;
|
bool fast_is() const = delete;
|
||||||
|
|
||||||
|
StackingContext const* stacking_context_rooted_here() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
explicit Paintable(Layout::Node const& layout_node)
|
explicit Paintable(Layout::Node const& layout_node)
|
||||||
: m_layout_node(layout_node)
|
: m_layout_node(layout_node)
|
||||||
|
|
|
@ -444,7 +444,7 @@ Gfx::FloatPoint StackingContext::compute_transform_origin() const
|
||||||
template<typename U, typename Callback>
|
template<typename U, typename Callback>
|
||||||
static TraversalDecision for_each_in_inclusive_subtree_of_type_within_same_stacking_context_in_reverse(Paintable const& paintable, Callback callback)
|
static TraversalDecision for_each_in_inclusive_subtree_of_type_within_same_stacking_context_in_reverse(Paintable const& paintable, Callback callback)
|
||||||
{
|
{
|
||||||
if (is<PaintableBox>(paintable) && static_cast<PaintableBox const&>(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.
|
// Note: Include the stacking context (so we can hit test it), but don't recurse into it.
|
||||||
if (auto decision = callback(static_cast<U const&>(paintable)); decision != TraversalDecision::Continue)
|
if (auto decision = callback(static_cast<U const&>(paintable)); decision != TraversalDecision::Continue)
|
||||||
return decision;
|
return decision;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue