EventHandler.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/Forward.h>
  8. #include <AK/NonnullOwnPtr.h>
  9. #include <AK/WeakPtr.h>
  10. #include <Kernel/API/KeyCode.h>
  11. #include <LibGUI/Forward.h>
  12. #include <LibGfx/Forward.h>
  13. #include <LibWeb/Forward.h>
  14. #include <LibWeb/Page/EditEventHandler.h>
  15. #include <LibWeb/PixelUnits.h>
  16. namespace Web {
  17. class EventHandler {
  18. public:
  19. explicit EventHandler(Badge<HTML::BrowsingContext>, HTML::BrowsingContext&);
  20. ~EventHandler();
  21. bool handle_mouseup(CSSPixelPoint, unsigned button, unsigned buttons, unsigned modifiers);
  22. bool handle_mousedown(CSSPixelPoint, unsigned button, unsigned buttons, unsigned modifiers);
  23. bool handle_mousemove(CSSPixelPoint, unsigned buttons, unsigned modifiers);
  24. bool handle_mousewheel(CSSPixelPoint, unsigned button, unsigned buttons, unsigned modifiers, int wheel_delta_x, int wheel_delta_y);
  25. bool handle_doubleclick(CSSPixelPoint, unsigned button, unsigned buttons, unsigned modifiers);
  26. bool handle_keydown(KeyCode, unsigned modifiers, u32 code_point);
  27. bool handle_keyup(KeyCode, unsigned modifiers, u32 code_point);
  28. void set_mouse_event_tracking_layout_node(Layout::Node*);
  29. void set_edit_event_handler(NonnullOwnPtr<EditEventHandler> value) { m_edit_event_handler = move(value); }
  30. private:
  31. bool focus_next_element();
  32. bool focus_previous_element();
  33. bool fire_keyboard_event(FlyString const& event_name, HTML::BrowsingContext& browsing_context, KeyCode key, unsigned modifiers, u32 code_point);
  34. CSSPixelPoint compute_mouse_event_client_offset(CSSPixelPoint event_page_position) const;
  35. CSSPixelPoint compute_mouse_event_page_offset(CSSPixelPoint event_client_offset) const;
  36. Layout::Viewport* layout_root();
  37. Layout::Viewport const* layout_root() const;
  38. Painting::PaintableBox* paint_root();
  39. Painting::PaintableBox const* paint_root() const;
  40. JS::NonnullGCPtr<HTML::BrowsingContext> m_browsing_context;
  41. bool m_in_mouse_selection { false };
  42. WeakPtr<Layout::Node> m_mouse_event_tracking_layout_node;
  43. NonnullOwnPtr<EditEventHandler> m_edit_event_handler;
  44. WeakPtr<DOM::EventTarget> m_mousedown_target;
  45. };
  46. }