TextPaintable.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. * Copyright (c) 2022, Andreas Kling <andreas@ladybird.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibWeb/HTML/BrowsingContext.h>
  7. #include <LibWeb/Layout/Label.h>
  8. #include <LibWeb/Layout/LabelableNode.h>
  9. #include <LibWeb/Page/EventHandler.h>
  10. #include <LibWeb/Painting/TextPaintable.h>
  11. namespace Web::Painting {
  12. GC_DEFINE_ALLOCATOR(TextPaintable);
  13. GC::Ref<TextPaintable> TextPaintable::create(Layout::TextNode const& layout_node, String const& text_for_rendering)
  14. {
  15. return layout_node.heap().allocate<TextPaintable>(layout_node, text_for_rendering);
  16. }
  17. TextPaintable::TextPaintable(Layout::TextNode const& layout_node, String const& text_for_rendering)
  18. : Paintable(layout_node)
  19. , m_text_for_rendering(text_for_rendering)
  20. {
  21. }
  22. bool TextPaintable::wants_mouse_events() const
  23. {
  24. return layout_node().first_ancestor_of_type<Layout::Label>();
  25. }
  26. TextPaintable::DispatchEventOfSameName TextPaintable::handle_mousedown(Badge<EventHandler>, CSSPixelPoint position, unsigned button, unsigned)
  27. {
  28. auto* label = layout_node().first_ancestor_of_type<Layout::Label>();
  29. if (!label)
  30. return DispatchEventOfSameName::No;
  31. const_cast<Layout::Label*>(label)->handle_mousedown_on_label({}, position, button);
  32. const_cast<HTML::Navigable&>(*navigable()).event_handler().set_mouse_event_tracking_paintable(this);
  33. return DispatchEventOfSameName::Yes;
  34. }
  35. TextPaintable::DispatchEventOfSameName TextPaintable::handle_mouseup(Badge<EventHandler>, CSSPixelPoint position, unsigned button, unsigned)
  36. {
  37. auto* label = layout_node().first_ancestor_of_type<Layout::Label>();
  38. if (!label)
  39. return DispatchEventOfSameName::No;
  40. const_cast<Layout::Label*>(label)->handle_mouseup_on_label({}, position, button);
  41. const_cast<HTML::Navigable&>(*navigable()).event_handler().set_mouse_event_tracking_paintable(nullptr);
  42. return DispatchEventOfSameName::Yes;
  43. }
  44. TextPaintable::DispatchEventOfSameName TextPaintable::handle_mousemove(Badge<EventHandler>, CSSPixelPoint position, unsigned button, unsigned)
  45. {
  46. auto* label = layout_node().first_ancestor_of_type<Layout::Label>();
  47. if (!label)
  48. return DispatchEventOfSameName::No;
  49. const_cast<Layout::Label*>(label)->handle_mousemove_on_label({}, position, button);
  50. return DispatchEventOfSameName::Yes;
  51. }
  52. }