PageView.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. * Copyright (c) 2018-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/URL.h>
  28. #include <LibGUI/ScrollableWidget.h>
  29. #include <LibWeb/DOM/Document.h>
  30. #include <LibWeb/Page.h>
  31. namespace Web {
  32. class PageView final
  33. : public GUI::ScrollableWidget
  34. , public PageClient {
  35. C_OBJECT(PageView);
  36. public:
  37. virtual ~PageView() override;
  38. // FIXME: Remove this once the new parser is ready.
  39. void set_use_old_parser(bool use_old_parser);
  40. void load_empty_document();
  41. Document* document();
  42. const Document* document() const;
  43. void set_document(Document*);
  44. const LayoutDocument* layout_root() const;
  45. LayoutDocument* layout_root();
  46. void reload();
  47. bool load(const URL&);
  48. void scroll_to_anchor(const StringView&);
  49. URL url() const;
  50. void set_should_show_line_box_borders(bool value) { m_should_show_line_box_borders = value; }
  51. Function<void(const String& href, const String& target, unsigned modifiers)> on_link_click;
  52. Function<void(const String& href, const Gfx::IntPoint& screen_position)> on_link_context_menu_request;
  53. Function<void(const String& href)> on_link_middle_click;
  54. Function<void(const String&)> on_link_hover;
  55. Function<void(const String&)> on_title_change;
  56. Function<void(const URL&)> on_load_start;
  57. Function<void(const Gfx::Bitmap&)> on_favicon_change;
  58. Function<void(const URL&)> on_url_drop;
  59. Function<void(Document*)> on_set_document;
  60. virtual bool accepts_focus() const override { return true; }
  61. private:
  62. PageView();
  63. Page& page() { return *m_page; }
  64. const Page& page() const { return *m_page; }
  65. virtual void resize_event(GUI::ResizeEvent&) override;
  66. virtual void paint_event(GUI::PaintEvent&) override;
  67. virtual void mousemove_event(GUI::MouseEvent&) override;
  68. virtual void mousedown_event(GUI::MouseEvent&) override;
  69. virtual void mouseup_event(GUI::MouseEvent&) override;
  70. virtual void keydown_event(GUI::KeyEvent&) override;
  71. virtual void drop_event(GUI::DropEvent&) override;
  72. virtual void did_scroll() override;
  73. // ^Web::PageClient
  74. virtual void page_did_change_title(const String&) override;
  75. virtual void page_did_set_document_in_main_frame(Document*) override;
  76. virtual void page_did_start_loading(const URL&) override;
  77. virtual void page_did_change_selection() override;
  78. virtual void page_did_request_cursor_change(GUI::StandardCursor) override;
  79. virtual void page_did_request_link_context_menu(const Gfx::IntPoint&, const String& href, const String& target, unsigned modifiers) override;
  80. virtual void page_did_click_link(const String& href, const String& target, unsigned modifiers) override;
  81. virtual void page_did_middle_click_link(const String& href, const String& target, unsigned modifiers) override;
  82. virtual void page_did_enter_tooltip_area(const Gfx::IntPoint&, const String&) override;
  83. virtual void page_did_leave_tooltip_area() override;
  84. virtual void page_did_hover_link(const URL&) override;
  85. virtual void page_did_unhover_link() override;
  86. virtual void page_did_request_scroll_to_anchor(const String& fragment) override;
  87. virtual void page_did_invalidate(const Gfx::IntRect&) override;
  88. virtual void page_did_change_favicon(const Gfx::Bitmap&) override;
  89. void layout_and_sync_size();
  90. bool m_should_show_line_box_borders { false };
  91. NonnullOwnPtr<Page> m_page;
  92. };
  93. }