Paintable.cpp 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibWeb/DOM/Document.h>
  7. #include <LibWeb/Layout/BlockContainer.h>
  8. #include <LibWeb/Painting/Paintable.h>
  9. namespace Web::Painting {
  10. void Paintable::visit_edges(Cell::Visitor& visitor)
  11. {
  12. Base::visit_edges(visitor);
  13. visitor.visit(m_layout_node);
  14. if (m_containing_block.has_value())
  15. visitor.visit(m_containing_block.value());
  16. }
  17. Paintable::DispatchEventOfSameName Paintable::handle_mousedown(Badge<EventHandler>, CSSPixelPoint, unsigned, unsigned)
  18. {
  19. return DispatchEventOfSameName::Yes;
  20. }
  21. Paintable::DispatchEventOfSameName Paintable::handle_mouseup(Badge<EventHandler>, CSSPixelPoint, unsigned, unsigned)
  22. {
  23. return DispatchEventOfSameName::Yes;
  24. }
  25. Paintable::DispatchEventOfSameName Paintable::handle_mousemove(Badge<EventHandler>, CSSPixelPoint, unsigned, unsigned)
  26. {
  27. return DispatchEventOfSameName::Yes;
  28. }
  29. bool Paintable::handle_mousewheel(Badge<EventHandler>, CSSPixelPoint, unsigned, unsigned, int wheel_delta_x, int wheel_delta_y)
  30. {
  31. if (auto const* containing_block = this->containing_block()) {
  32. if (!containing_block->is_scrollable())
  33. return false;
  34. auto new_offset = containing_block->scroll_offset();
  35. new_offset.translate_by(wheel_delta_x, wheel_delta_y);
  36. // FIXME: This const_cast is gross.
  37. // FIXME: Scroll offset shouldn't live in the layout tree.
  38. const_cast<Layout::Box*>(containing_block)->set_scroll_offset(new_offset);
  39. return true;
  40. }
  41. return false;
  42. }
  43. Optional<HitTestResult> Paintable::hit_test(CSSPixelPoint, HitTestType) const
  44. {
  45. return {};
  46. }
  47. Paintable const* Paintable::first_child() const
  48. {
  49. auto const* layout_child = m_layout_node->first_child();
  50. for (; layout_child && !layout_child->paintable(); layout_child = layout_child->next_sibling())
  51. ;
  52. return layout_child ? layout_child->paintable() : nullptr;
  53. }
  54. Paintable const* Paintable::next_sibling() const
  55. {
  56. auto const* layout_node = m_layout_node->next_sibling();
  57. for (; layout_node && !layout_node->paintable(); layout_node = layout_node->next_sibling())
  58. ;
  59. return layout_node ? layout_node->paintable() : nullptr;
  60. }
  61. Paintable const* Paintable::last_child() const
  62. {
  63. auto const* layout_child = m_layout_node->last_child();
  64. for (; layout_child && !layout_child->paintable(); layout_child = layout_child->previous_sibling())
  65. ;
  66. return layout_child ? layout_child->paintable() : nullptr;
  67. }
  68. Paintable const* Paintable::previous_sibling() const
  69. {
  70. auto const* layout_node = m_layout_node->previous_sibling();
  71. for (; layout_node && !layout_node->paintable(); layout_node = layout_node->previous_sibling())
  72. ;
  73. return layout_node ? layout_node->paintable() : nullptr;
  74. }
  75. }