EventHandler.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 <LibJS/Heap/GCPtr.h>
  14. #include <LibWeb/Forward.h>
  15. #include <LibWeb/Page/EditEventHandler.h>
  16. #include <LibWeb/PixelUnits.h>
  17. namespace Web {
  18. class EventHandler {
  19. public:
  20. explicit EventHandler(Badge<HTML::BrowsingContext>, HTML::BrowsingContext&);
  21. ~EventHandler();
  22. bool handle_mouseup(CSSPixelPoint, unsigned button, unsigned buttons, unsigned modifiers);
  23. bool handle_mousedown(CSSPixelPoint, unsigned button, unsigned buttons, unsigned modifiers);
  24. bool handle_mousemove(CSSPixelPoint, unsigned buttons, unsigned modifiers);
  25. bool handle_mousewheel(CSSPixelPoint, unsigned button, unsigned buttons, unsigned modifiers, int wheel_delta_x, int wheel_delta_y);
  26. bool handle_doubleclick(CSSPixelPoint, unsigned button, unsigned buttons, unsigned modifiers);
  27. bool handle_keydown(KeyCode, unsigned modifiers, u32 code_point);
  28. bool handle_keyup(KeyCode, unsigned modifiers, u32 code_point);
  29. void set_mouse_event_tracking_layout_node(Layout::Node*);
  30. void set_edit_event_handler(NonnullOwnPtr<EditEventHandler> value) { m_edit_event_handler = move(value); }
  31. private:
  32. bool focus_next_element();
  33. bool focus_previous_element();
  34. bool fire_keyboard_event(FlyString const& event_name, HTML::BrowsingContext& browsing_context, KeyCode key, unsigned modifiers, u32 code_point);
  35. CSSPixelPoint compute_mouse_event_client_offset(CSSPixelPoint event_page_position) const;
  36. CSSPixelPoint compute_mouse_event_page_offset(CSSPixelPoint event_client_offset) const;
  37. struct Target {
  38. JS::GCPtr<Painting::Paintable> paintable;
  39. Optional<int> index_in_node;
  40. };
  41. Optional<Target> target_for_mouse_position(CSSPixelPoint position);
  42. Layout::Viewport* layout_root();
  43. Layout::Viewport const* layout_root() const;
  44. Painting::PaintableBox* paint_root();
  45. Painting::PaintableBox const* paint_root() const;
  46. JS::NonnullGCPtr<HTML::BrowsingContext> m_browsing_context;
  47. bool m_in_mouse_selection { false };
  48. WeakPtr<Layout::Node> m_mouse_event_tracking_layout_node;
  49. NonnullOwnPtr<EditEventHandler> m_edit_event_handler;
  50. WeakPtr<DOM::EventTarget> m_mousedown_target;
  51. };
  52. }