2022-03-10 16:46:44 +01:00
|
|
|
/*
|
2024-10-04 13:19:50 +02:00
|
|
|
* Copyright (c) 2022, Andreas Kling <andreas@ladybird.org>
|
2022-03-10 16:46:44 +01:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
2022-03-10 22:38:08 +01:00
|
|
|
#include <LibWeb/HTML/BrowsingContext.h>
|
|
|
|
#include <LibWeb/Layout/Label.h>
|
2022-03-14 23:05:55 +00:00
|
|
|
#include <LibWeb/Layout/LabelableNode.h>
|
2022-03-10 22:38:08 +01:00
|
|
|
#include <LibWeb/Page/EventHandler.h>
|
2022-03-10 16:46:44 +01:00
|
|
|
#include <LibWeb/Painting/TextPaintable.h>
|
|
|
|
|
|
|
|
namespace Web::Painting {
|
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
GC_DEFINE_ALLOCATOR(TextPaintable);
|
2024-04-06 10:16:04 -07:00
|
|
|
|
2025-07-25 09:34:41 -04:00
|
|
|
GC::Ref<TextPaintable> TextPaintable::create(Layout::TextNode const& layout_node, Utf16String text_for_rendering)
|
2022-03-10 16:46:44 +01:00
|
|
|
{
|
2025-07-25 09:34:41 -04:00
|
|
|
return layout_node.heap().allocate<TextPaintable>(layout_node, move(text_for_rendering));
|
2022-03-10 16:46:44 +01:00
|
|
|
}
|
|
|
|
|
2025-07-25 09:34:41 -04:00
|
|
|
TextPaintable::TextPaintable(Layout::TextNode const& layout_node, Utf16String text_for_rendering)
|
2022-03-10 16:46:44 +01:00
|
|
|
: Paintable(layout_node)
|
2025-07-25 09:34:41 -04:00
|
|
|
, m_text_for_rendering(move(text_for_rendering))
|
2022-03-10 16:46:44 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-03-10 22:46:35 +01:00
|
|
|
bool TextPaintable::wants_mouse_events() const
|
|
|
|
{
|
|
|
|
return layout_node().first_ancestor_of_type<Layout::Label>();
|
|
|
|
}
|
|
|
|
|
2022-11-02 17:35:53 +00:00
|
|
|
TextPaintable::DispatchEventOfSameName TextPaintable::handle_mousedown(Badge<EventHandler>, CSSPixelPoint position, unsigned button, unsigned)
|
2022-03-10 22:46:35 +01:00
|
|
|
{
|
|
|
|
auto* label = layout_node().first_ancestor_of_type<Layout::Label>();
|
|
|
|
if (!label)
|
2022-03-14 23:05:55 +00:00
|
|
|
return DispatchEventOfSameName::No;
|
2022-03-10 22:46:35 +01:00
|
|
|
const_cast<Layout::Label*>(label)->handle_mousedown_on_label({}, position, button);
|
2025-01-31 11:12:20 +01:00
|
|
|
navigable()->event_handler().set_mouse_event_tracking_paintable(this);
|
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
|
|
|
TextPaintable::DispatchEventOfSameName TextPaintable::handle_mouseup(Badge<EventHandler>, CSSPixelPoint position, unsigned button, unsigned)
|
2022-03-10 22:46:35 +01:00
|
|
|
{
|
|
|
|
auto* label = layout_node().first_ancestor_of_type<Layout::Label>();
|
|
|
|
if (!label)
|
2022-03-14 23:05:55 +00:00
|
|
|
return DispatchEventOfSameName::No;
|
2022-03-10 22:46:35 +01:00
|
|
|
|
|
|
|
const_cast<Layout::Label*>(label)->handle_mouseup_on_label({}, position, button);
|
2025-01-31 11:12:20 +01:00
|
|
|
navigable()->event_handler().set_mouse_event_tracking_paintable(nullptr);
|
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
|
|
|
TextPaintable::DispatchEventOfSameName TextPaintable::handle_mousemove(Badge<EventHandler>, CSSPixelPoint position, unsigned button, unsigned)
|
2022-03-10 22:46:35 +01:00
|
|
|
{
|
|
|
|
auto* label = layout_node().first_ancestor_of_type<Layout::Label>();
|
|
|
|
if (!label)
|
2022-03-14 23:05:55 +00:00
|
|
|
return DispatchEventOfSameName::No;
|
2022-03-10 22:46:35 +01:00
|
|
|
const_cast<Layout::Label*>(label)->handle_mousemove_on_label({}, position, button);
|
2022-03-14 23:05:55 +00:00
|
|
|
return DispatchEventOfSameName::Yes;
|
2022-03-10 22:46:35 +01:00
|
|
|
}
|
|
|
|
|
2022-03-10 16:46:44 +01:00
|
|
|
}
|