ViewImplementation.cpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * Copyright (c) 2023, Linus Groh <linusg@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <AK/Error.h>
  7. #include <AK/String.h>
  8. #include <LibWebView/ViewImplementation.h>
  9. namespace WebView {
  10. WebContentClient& ViewImplementation::client()
  11. {
  12. VERIFY(m_client_state.client);
  13. return *m_client_state.client;
  14. }
  15. WebContentClient const& ViewImplementation::client() const
  16. {
  17. VERIFY(m_client_state.client);
  18. return *m_client_state.client;
  19. }
  20. void ViewImplementation::zoom_in()
  21. {
  22. if (m_zoom_level >= ZOOM_MAX_LEVEL)
  23. return;
  24. m_zoom_level += ZOOM_STEP;
  25. update_zoom();
  26. }
  27. void ViewImplementation::zoom_out()
  28. {
  29. if (m_zoom_level <= ZOOM_MIN_LEVEL)
  30. return;
  31. m_zoom_level -= ZOOM_STEP;
  32. update_zoom();
  33. }
  34. void ViewImplementation::reset_zoom()
  35. {
  36. m_zoom_level = 1.0f;
  37. update_zoom();
  38. }
  39. void ViewImplementation::get_source()
  40. {
  41. client().async_get_source();
  42. }
  43. void ViewImplementation::inspect_dom_tree()
  44. {
  45. client().async_inspect_dom_tree();
  46. }
  47. void ViewImplementation::inspect_accessibility_tree()
  48. {
  49. client().async_inspect_accessibility_tree();
  50. }
  51. ErrorOr<ViewImplementation::DOMNodeProperties> ViewImplementation::inspect_dom_node(i32 node_id, Optional<Web::CSS::Selector::PseudoElement> pseudo_element)
  52. {
  53. auto response = client().inspect_dom_node(node_id, pseudo_element);
  54. if (!response.has_style())
  55. return Error::from_string_view("Inspected node returned no style"sv);
  56. return DOMNodeProperties {
  57. .computed_style_json = TRY(String::from_deprecated_string(response.take_computed_style())),
  58. .resolved_style_json = TRY(String::from_deprecated_string(response.take_resolved_style())),
  59. .custom_properties_json = TRY(String::from_deprecated_string(response.take_custom_properties())),
  60. .node_box_sizing_json = TRY(String::from_deprecated_string(response.take_node_box_sizing())),
  61. };
  62. }
  63. void ViewImplementation::clear_inspected_dom_node()
  64. {
  65. client().inspect_dom_node(0, {});
  66. }
  67. i32 ViewImplementation::get_hovered_node_id()
  68. {
  69. return client().get_hovered_node_id();
  70. }
  71. }