Page.h 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright notice, this
  9. * list of conditions and the following disclaimer.
  10. *
  11. * 2. Redistributions in binary form must reproduce the above copyright notice,
  12. * this list of conditions and the following disclaimer in the documentation
  13. * and/or other materials provided with the distribution.
  14. *
  15. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  16. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  17. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  18. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  19. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  20. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  21. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  22. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  23. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  24. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. */
  26. #pragma once
  27. #include <AK/Noncopyable.h>
  28. #include <AK/OwnPtr.h>
  29. #include <AK/RefPtr.h>
  30. #include <LibGUI/Window.h>
  31. #include <LibGfx/Forward.h>
  32. #include <LibGfx/Palette.h>
  33. #include <LibWeb/Forward.h>
  34. namespace Web {
  35. class PageClient;
  36. class Page {
  37. AK_MAKE_NONCOPYABLE(Page);
  38. AK_MAKE_NONMOVABLE(Page);
  39. public:
  40. explicit Page(PageClient&);
  41. ~Page();
  42. PageClient& client() { return m_client; }
  43. const PageClient& client() const { return m_client; }
  44. Web::Frame& main_frame() { return *m_main_frame; }
  45. const Web::Frame& main_frame() const { return *m_main_frame; }
  46. void load(const URL&);
  47. bool handle_mouseup(const Gfx::IntPoint&, unsigned button, unsigned modifiers);
  48. bool handle_mousedown(const Gfx::IntPoint&, unsigned button, unsigned modifiers);
  49. bool handle_mousemove(const Gfx::IntPoint&, unsigned buttons, unsigned modifiers);
  50. Gfx::Palette palette() const;
  51. private:
  52. PageClient& m_client;
  53. RefPtr<Frame> m_main_frame;
  54. };
  55. class PageClient {
  56. public:
  57. virtual void page_did_set_document_in_main_frame(Document*) { }
  58. virtual void page_did_change_title(const String&) { }
  59. virtual void page_did_start_loading(const URL&) { }
  60. virtual void page_did_change_selection() { }
  61. virtual void page_did_request_cursor_change(GUI::StandardCursor) { }
  62. virtual void page_did_request_link_context_menu(const Gfx::IntPoint&, [[maybe_unused]] const String& href, [[maybe_unused]] const String& target, [[maybe_unused]] unsigned modifiers) { }
  63. virtual void page_did_click_link([[maybe_unused]] const String& href, [[maybe_unused]] const String& target, [[maybe_unused]] unsigned modifiers) { }
  64. virtual void page_did_middle_click_link([[maybe_unused]] const String& href, [[maybe_unused]] const String& target, [[maybe_unused]] unsigned modifiers) { }
  65. virtual void page_did_enter_tooltip_area(const Gfx::IntPoint&, const String&) { }
  66. virtual void page_did_leave_tooltip_area() { }
  67. virtual void page_did_hover_link(const URL&) { }
  68. virtual void page_did_unhover_link() { }
  69. virtual void page_did_request_scroll_to_anchor([[maybe_unused]] const String& fragment) { }
  70. virtual void page_did_invalidate(const Gfx::IntRect&) { }
  71. virtual void page_did_change_favicon(const Gfx::Bitmap&) { }
  72. };
  73. }