Paintable.cpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. Paintable::DispatchEventOfSameName Paintable::handle_mousedown(Badge<EventHandler>, Gfx::IntPoint const&, unsigned, unsigned)
  11. {
  12. return DispatchEventOfSameName::Yes;
  13. }
  14. Paintable::DispatchEventOfSameName Paintable::handle_mouseup(Badge<EventHandler>, Gfx::IntPoint const&, unsigned, unsigned)
  15. {
  16. return DispatchEventOfSameName::Yes;
  17. }
  18. Paintable::DispatchEventOfSameName Paintable::handle_mousemove(Badge<EventHandler>, Gfx::IntPoint const&, unsigned, unsigned)
  19. {
  20. return DispatchEventOfSameName::Yes;
  21. }
  22. bool Paintable::handle_mousewheel(Badge<EventHandler>, Gfx::IntPoint const&, unsigned, unsigned, int wheel_delta_x, int wheel_delta_y)
  23. {
  24. if (auto* containing_block = this->containing_block()) {
  25. if (!containing_block->is_scrollable())
  26. return false;
  27. auto new_offset = containing_block->scroll_offset();
  28. new_offset.translate_by(wheel_delta_x, wheel_delta_y);
  29. // FIXME: This const_cast is gross.
  30. // FIXME: Scroll offset shouldn't live in the layout tree.
  31. const_cast<Layout::BlockContainer*>(containing_block)->set_scroll_offset(new_offset);
  32. return true;
  33. }
  34. return false;
  35. }
  36. Optional<HitTestResult> Paintable::hit_test(Gfx::FloatPoint const&, HitTestType) const
  37. {
  38. return {};
  39. }
  40. Paintable const* Paintable::first_child() const
  41. {
  42. auto* layout_child = m_layout_node.first_child();
  43. for (; layout_child && !layout_child->paintable(); layout_child = layout_child->next_sibling())
  44. ;
  45. return layout_child ? layout_child->paintable() : nullptr;
  46. }
  47. Paintable const* Paintable::next_sibling() const
  48. {
  49. auto* layout_node = m_layout_node.next_sibling();
  50. for (; layout_node && !layout_node->paintable(); layout_node = layout_node->next_sibling())
  51. ;
  52. return layout_node ? layout_node->paintable() : nullptr;
  53. }
  54. }