Paintable.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. }