2022-03-09 23:53:41 +01:00
|
|
|
/*
|
2023-07-14 10:02:19 +02:00
|
|
|
* Copyright (c) 2022-2023, Andreas Kling <kling@serenityos.org>
|
2022-03-09 23:53:41 +01:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
*/
|
|
|
|
|
|
2022-03-10 14:02:25 +01:00
|
|
|
#include <LibWeb/DOM/Document.h>
|
2022-03-09 23:53:41 +01:00
|
|
|
#include <LibWeb/Layout/BlockContainer.h>
|
2022-03-10 11:26:01 +01:00
|
|
|
#include <LibWeb/Painting/Paintable.h>
|
2023-07-14 10:02:19 +02:00
|
|
|
#include <LibWeb/Painting/PaintableBox.h>
|
2022-03-09 23:53:41 +01:00
|
|
|
|
|
|
|
|
namespace Web::Painting {
|
|
|
|
|
|
2023-08-18 13:21:38 +02:00
|
|
|
Paintable::Paintable(Layout::Node const& layout_node)
|
|
|
|
|
: m_layout_node(layout_node)
|
|
|
|
|
, m_browsing_context(const_cast<HTML::BrowsingContext&>(layout_node.browsing_context()))
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-11 12:51:49 +01:00
|
|
|
void Paintable::visit_edges(Cell::Visitor& visitor)
|
|
|
|
|
{
|
|
|
|
|
Base::visit_edges(visitor);
|
2023-08-28 18:38:06 +02:00
|
|
|
TreeNode::visit_edges(visitor);
|
2023-08-18 13:01:45 +02:00
|
|
|
visitor.visit(m_dom_node);
|
2023-01-11 12:51:49 +01:00
|
|
|
visitor.visit(m_layout_node);
|
2023-08-18 13:21:38 +02:00
|
|
|
visitor.visit(m_browsing_context);
|
2023-01-11 14:36:27 +01:00
|
|
|
if (m_containing_block.has_value())
|
|
|
|
|
visitor.visit(m_containing_block.value());
|
2023-01-11 12:51:49 +01:00
|
|
|
}
|
|
|
|
|
|
2023-08-21 17:07:53 +02:00
|
|
|
bool Paintable::is_positioned() const
|
|
|
|
|
{
|
|
|
|
|
if (layout_node().is_grid_item() && computed_values().z_index().has_value()) {
|
|
|
|
|
// https://www.w3.org/TR/css-grid-2/#z-order
|
|
|
|
|
// grid items with z_index should behave as if position were "relative"
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return computed_values().position() != CSS::Position::Static;
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-18 13:01:45 +02:00
|
|
|
void Paintable::set_dom_node(JS::GCPtr<DOM::Node> dom_node)
|
|
|
|
|
{
|
|
|
|
|
m_dom_node = dom_node;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
JS::GCPtr<DOM::Node> Paintable::dom_node()
|
|
|
|
|
{
|
|
|
|
|
return m_dom_node;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
JS::GCPtr<DOM::Node const> Paintable::dom_node() const
|
|
|
|
|
{
|
|
|
|
|
return m_dom_node;
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-18 13:21:38 +02:00
|
|
|
HTML::BrowsingContext const& Paintable::browsing_context() const
|
|
|
|
|
{
|
|
|
|
|
return m_browsing_context;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HTML::BrowsingContext& Paintable::browsing_context()
|
|
|
|
|
{
|
|
|
|
|
return m_browsing_context;
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-02 17:35:53 +00:00
|
|
|
Paintable::DispatchEventOfSameName Paintable::handle_mousedown(Badge<EventHandler>, CSSPixelPoint, unsigned, unsigned)
|
2022-03-10 22:46:35 +01:00
|
|
|
{
|
2022-03-14 23:05:55 +00:00
|
|
|
return DispatchEventOfSameName::Yes;
|
2022-03-10 22:46:35 +01:00
|
|
|
}
|
|
|
|
|
|
2022-11-02 17:35:53 +00:00
|
|
|
Paintable::DispatchEventOfSameName Paintable::handle_mouseup(Badge<EventHandler>, CSSPixelPoint, unsigned, unsigned)
|
2022-03-10 22:46:35 +01:00
|
|
|
{
|
2022-03-14 23:05:55 +00:00
|
|
|
return DispatchEventOfSameName::Yes;
|
2022-03-10 22:46:35 +01:00
|
|
|
}
|
|
|
|
|
|
2022-11-02 17:35:53 +00:00
|
|
|
Paintable::DispatchEventOfSameName Paintable::handle_mousemove(Badge<EventHandler>, CSSPixelPoint, unsigned, unsigned)
|
2022-03-10 22:46:35 +01:00
|
|
|
{
|
2022-03-14 23:05:55 +00:00
|
|
|
return DispatchEventOfSameName::Yes;
|
2022-03-10 22:46:35 +01:00
|
|
|
}
|
|
|
|
|
|
2023-08-06 14:28:23 +02:00
|
|
|
bool Paintable::handle_mousewheel(Badge<EventHandler>, CSSPixelPoint, unsigned, unsigned, int, int)
|
2022-03-10 22:46:35 +01:00
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-02 17:35:53 +00:00
|
|
|
Optional<HitTestResult> Paintable::hit_test(CSSPixelPoint, HitTestType) const
|
2022-03-11 00:03:28 +01:00
|
|
|
{
|
2022-03-18 22:17:42 +01:00
|
|
|
return {};
|
2022-03-11 00:03:28 +01:00
|
|
|
}
|
|
|
|
|
|
2023-07-14 10:02:19 +02:00
|
|
|
StackingContext const* Paintable::stacking_context_rooted_here() const
|
|
|
|
|
{
|
2023-08-18 13:47:52 +02:00
|
|
|
if (!is<PaintableBox>(*this))
|
2023-07-14 10:02:19 +02:00
|
|
|
return nullptr;
|
|
|
|
|
return static_cast<PaintableBox const&>(*this).stacking_context();
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-09 23:53:41 +01:00
|
|
|
}
|