Page.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. * Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibWeb/DOM/Document.h>
  7. #include <LibWeb/HTML/BrowsingContext.h>
  8. #include <LibWeb/Page/Page.h>
  9. namespace Web {
  10. Page::Page(PageClient& client)
  11. : m_client(client)
  12. {
  13. m_top_level_browsing_context = JS::make_handle(*HTML::BrowsingContext::create_a_new_top_level_browsing_context(*this));
  14. }
  15. Page::~Page() = default;
  16. HTML::BrowsingContext& Page::focused_context()
  17. {
  18. if (m_focused_context)
  19. return *m_focused_context;
  20. return top_level_browsing_context();
  21. }
  22. void Page::set_focused_browsing_context(Badge<EventHandler>, HTML::BrowsingContext& browsing_context)
  23. {
  24. m_focused_context = browsing_context.make_weak_ptr();
  25. }
  26. void Page::load(const AK::URL& url)
  27. {
  28. top_level_browsing_context().loader().load(url, FrameLoader::Type::Navigation);
  29. }
  30. void Page::load(LoadRequest& request)
  31. {
  32. top_level_browsing_context().loader().load(request, FrameLoader::Type::Navigation);
  33. }
  34. void Page::load_html(StringView html, const AK::URL& url)
  35. {
  36. top_level_browsing_context().loader().load_html(html, url);
  37. }
  38. Gfx::Palette Page::palette() const
  39. {
  40. return m_client.palette();
  41. }
  42. Gfx::IntRect Page::screen_rect() const
  43. {
  44. return m_client.screen_rect();
  45. }
  46. CSS::PreferredColorScheme Page::preferred_color_scheme() const
  47. {
  48. return m_client.preferred_color_scheme();
  49. }
  50. bool Page::handle_mousewheel(Gfx::IntPoint const& position, unsigned button, unsigned modifiers, int wheel_delta_x, int wheel_delta_y)
  51. {
  52. return top_level_browsing_context().event_handler().handle_mousewheel(position, button, modifiers, wheel_delta_x, wheel_delta_y);
  53. }
  54. bool Page::handle_mouseup(Gfx::IntPoint const& position, unsigned button, unsigned modifiers)
  55. {
  56. return top_level_browsing_context().event_handler().handle_mouseup(position, button, modifiers);
  57. }
  58. bool Page::handle_mousedown(Gfx::IntPoint const& position, unsigned button, unsigned modifiers)
  59. {
  60. return top_level_browsing_context().event_handler().handle_mousedown(position, button, modifiers);
  61. }
  62. bool Page::handle_mousemove(Gfx::IntPoint const& position, unsigned buttons, unsigned modifiers)
  63. {
  64. return top_level_browsing_context().event_handler().handle_mousemove(position, buttons, modifiers);
  65. }
  66. bool Page::handle_doubleclick(Gfx::IntPoint const& position, unsigned button, unsigned modifiers)
  67. {
  68. return top_level_browsing_context().event_handler().handle_doubleclick(position, button, modifiers);
  69. }
  70. bool Page::handle_keydown(KeyCode key, unsigned modifiers, u32 code_point)
  71. {
  72. return focused_context().event_handler().handle_keydown(key, modifiers, code_point);
  73. }
  74. bool Page::handle_keyup(KeyCode key, unsigned modifiers, u32 code_point)
  75. {
  76. return focused_context().event_handler().handle_keyup(key, modifiers, code_point);
  77. }
  78. HTML::BrowsingContext& Page::top_level_browsing_context()
  79. {
  80. return *m_top_level_browsing_context;
  81. }
  82. HTML::BrowsingContext const& Page::top_level_browsing_context() const
  83. {
  84. return *m_top_level_browsing_context;
  85. }
  86. }