InspectorClient.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <AK/Function.h>
  7. #include <AK/JsonValue.h>
  8. #include <AK/StringView.h>
  9. #include <LibGfx/Point.h>
  10. #include <LibWebView/ViewImplementation.h>
  11. #pragma once
  12. namespace WebView {
  13. class InspectorClient {
  14. public:
  15. InspectorClient(ViewImplementation& content_web_view, ViewImplementation& inspector_web_view);
  16. ~InspectorClient();
  17. void inspect();
  18. void reset();
  19. void select_hovered_node();
  20. void select_default_node();
  21. void clear_selection();
  22. void context_menu_edit_dom_node();
  23. void context_menu_copy_dom_node();
  24. void context_menu_screenshot_dom_node();
  25. void context_menu_create_child_element();
  26. void context_menu_create_child_text_node();
  27. void context_menu_clone_dom_node();
  28. void context_menu_remove_dom_node();
  29. void context_menu_add_dom_node_attribute();
  30. void context_menu_remove_dom_node_attribute();
  31. void context_menu_copy_dom_node_attribute_value();
  32. Function<void(Gfx::IntPoint)> on_requested_dom_node_text_context_menu;
  33. Function<void(Gfx::IntPoint, String const&)> on_requested_dom_node_tag_context_menu;
  34. Function<void(Gfx::IntPoint, String const&, Attribute const&)> on_requested_dom_node_attribute_context_menu;
  35. private:
  36. void load_inspector();
  37. String generate_dom_tree(JsonObject const&);
  38. String generate_accessibility_tree(JsonObject const&);
  39. void select_node(i32 node_id);
  40. void request_console_messages();
  41. void handle_console_message(i32 message_index);
  42. void handle_console_messages(i32 start_index, ReadonlySpan<DeprecatedString> message_types, ReadonlySpan<DeprecatedString> messages);
  43. void append_console_source(StringView);
  44. void append_console_message(StringView);
  45. void append_console_warning(StringView);
  46. void append_console_output(StringView);
  47. void clear_console_output();
  48. void begin_console_group(StringView label, bool start_expanded);
  49. void end_console_group();
  50. ViewImplementation& m_content_web_view;
  51. ViewImplementation& m_inspector_web_view;
  52. Optional<i32> m_body_node_id;
  53. Optional<i32> m_pending_selection;
  54. bool m_dom_tree_loaded { false };
  55. struct ContextMenuData {
  56. i32 dom_node_id { 0 };
  57. Optional<String> tag;
  58. Optional<Attribute> attribute;
  59. };
  60. Optional<ContextMenuData> m_context_menu_data;
  61. i32 m_highest_notified_message_index { -1 };
  62. i32 m_highest_received_message_index { -1 };
  63. bool m_waiting_for_messages { false };
  64. };
  65. }