Page.cpp 2.5 KB

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