Page.cpp 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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()
  15. {
  16. }
  17. HTML::BrowsingContext& Page::focused_context()
  18. {
  19. if (m_focused_context)
  20. return *m_focused_context;
  21. return top_level_browsing_context();
  22. }
  23. void Page::set_focused_browsing_context(Badge<EventHandler>, HTML::BrowsingContext& browsing_context)
  24. {
  25. m_focused_context = browsing_context.make_weak_ptr();
  26. }
  27. void Page::load(const AK::URL& url)
  28. {
  29. top_level_browsing_context().loader().load(url, FrameLoader::Type::Navigation);
  30. }
  31. void Page::load(LoadRequest& request)
  32. {
  33. top_level_browsing_context().loader().load(request, FrameLoader::Type::Navigation);
  34. }
  35. void Page::load_html(StringView html, const AK::URL& url)
  36. {
  37. top_level_browsing_context().loader().load_html(html, url);
  38. }
  39. Gfx::Palette Page::palette() const
  40. {
  41. return m_client.palette();
  42. }
  43. Gfx::IntRect Page::screen_rect() const
  44. {
  45. return m_client.screen_rect();
  46. }
  47. CSS::PreferredColorScheme Page::preferred_color_scheme() const
  48. {
  49. return m_client.preferred_color_scheme();
  50. }
  51. bool Page::handle_mousewheel(const Gfx::IntPoint& position, unsigned button, unsigned modifiers, int wheel_delta)
  52. {
  53. return top_level_browsing_context().event_handler().handle_mousewheel(position, button, modifiers, wheel_delta);
  54. }
  55. bool Page::handle_mouseup(const Gfx::IntPoint& position, unsigned button, unsigned modifiers)
  56. {
  57. return top_level_browsing_context().event_handler().handle_mouseup(position, button, modifiers);
  58. }
  59. bool Page::handle_mousedown(const Gfx::IntPoint& position, unsigned button, unsigned modifiers)
  60. {
  61. return top_level_browsing_context().event_handler().handle_mousedown(position, button, modifiers);
  62. }
  63. bool Page::handle_mousemove(const Gfx::IntPoint& position, unsigned buttons, unsigned modifiers)
  64. {
  65. return top_level_browsing_context().event_handler().handle_mousemove(position, buttons, modifiers);
  66. }
  67. bool Page::handle_keydown(KeyCode key, unsigned modifiers, u32 code_point)
  68. {
  69. return focused_context().event_handler().handle_keydown(key, modifiers, code_point);
  70. }
  71. bool Page::handle_keyup(KeyCode key, unsigned modifiers, u32 code_point)
  72. {
  73. return focused_context().event_handler().handle_keyup(key, modifiers, code_point);
  74. }
  75. }