Page.cpp 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 = HTML::BrowsingContext::create_a_new_browsing_context(*this, nullptr, nullptr);
  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. }