2022-03-09 23:53:41 +01:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
|
|
|
|
|
*
|
|
|
|
|
* 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>
|
2022-03-09 23:53:41 +01:00
|
|
|
|
|
|
|
|
namespace Web::Painting {
|
|
|
|
|
|
2022-12-06 20:27:44 +00:00
|
|
|
Paintable::DispatchEventOfSameName Paintable::handle_mousedown(Badge<EventHandler>, Gfx::IntPoint, 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-12-06 20:27:44 +00:00
|
|
|
Paintable::DispatchEventOfSameName Paintable::handle_mouseup(Badge<EventHandler>, Gfx::IntPoint, 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-12-06 20:27:44 +00:00
|
|
|
Paintable::DispatchEventOfSameName Paintable::handle_mousemove(Badge<EventHandler>, Gfx::IntPoint, 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-12-06 20:27:44 +00:00
|
|
|
bool Paintable::handle_mousewheel(Badge<EventHandler>, Gfx::IntPoint, unsigned, unsigned, int wheel_delta_x, int wheel_delta_y)
|
2022-03-10 22:46:35 +01:00
|
|
|
{
|
2022-03-12 00:35:49 +01:00
|
|
|
if (auto* containing_block = this->containing_block()) {
|
2022-03-10 22:46:35 +01:00
|
|
|
if (!containing_block->is_scrollable())
|
|
|
|
|
return false;
|
|
|
|
|
auto new_offset = containing_block->scroll_offset();
|
|
|
|
|
new_offset.translate_by(wheel_delta_x, wheel_delta_y);
|
|
|
|
|
// FIXME: This const_cast is gross.
|
|
|
|
|
// FIXME: Scroll offset shouldn't live in the layout tree.
|
|
|
|
|
const_cast<Layout::BlockContainer*>(containing_block)->set_scroll_offset(new_offset);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-06 20:57:07 +00:00
|
|
|
Optional<HitTestResult> Paintable::hit_test(Gfx::FloatPoint, 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
|
|
|
}
|
|
|
|
|
|
2022-04-08 15:19:02 +02:00
|
|
|
Paintable const* Paintable::first_child() const
|
|
|
|
|
{
|
|
|
|
|
auto* layout_child = m_layout_node.first_child();
|
|
|
|
|
for (; layout_child && !layout_child->paintable(); layout_child = layout_child->next_sibling())
|
|
|
|
|
;
|
|
|
|
|
return layout_child ? layout_child->paintable() : nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Paintable const* Paintable::next_sibling() const
|
|
|
|
|
{
|
|
|
|
|
auto* layout_node = m_layout_node.next_sibling();
|
|
|
|
|
for (; layout_node && !layout_node->paintable(); layout_node = layout_node->next_sibling())
|
|
|
|
|
;
|
|
|
|
|
return layout_node ? layout_node->paintable() : nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-03 19:08:07 +01:00
|
|
|
Paintable const* Paintable::last_child() const
|
|
|
|
|
{
|
|
|
|
|
auto* layout_child = m_layout_node.last_child();
|
|
|
|
|
for (; layout_child && !layout_child->paintable(); layout_child = layout_child->previous_sibling())
|
|
|
|
|
;
|
|
|
|
|
return layout_child ? layout_child->paintable() : nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Paintable const* Paintable::previous_sibling() const
|
|
|
|
|
{
|
|
|
|
|
auto* layout_node = m_layout_node.previous_sibling();
|
|
|
|
|
for (; layout_node && !layout_node->paintable(); layout_node = layout_node->previous_sibling())
|
|
|
|
|
;
|
|
|
|
|
return layout_node ? layout_node->paintable() : nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-09 23:53:41 +01:00
|
|
|
}
|