Paintable.cpp 3.0 KB

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