Page.cpp 2.2 KB

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