InProcessWebView.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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/Desktop.h>
  29. #include <LibGUI/ScrollableWidget.h>
  30. #include <LibWeb/DOM/Document.h>
  31. #include <LibWeb/Page/Page.h>
  32. #include <LibWeb/WebViewHooks.h>
  33. namespace Web {
  34. class InProcessWebView final
  35. : public GUI::ScrollableWidget
  36. , public WebViewHooks
  37. , public PageClient {
  38. C_OBJECT(InProcessWebView);
  39. public:
  40. virtual ~InProcessWebView() override;
  41. void load_html(const StringView&, const URL&);
  42. void load_empty_document();
  43. DOM::Document* document();
  44. const DOM::Document* document() const;
  45. void set_document(DOM::Document*);
  46. const Layout::InitialContainingBlockBox* layout_root() const;
  47. Layout::InitialContainingBlockBox* layout_root();
  48. void reload();
  49. bool load(const URL&);
  50. URL url() const;
  51. void set_should_show_line_box_borders(bool value) { m_should_show_line_box_borders = value; }
  52. GUI::Action& select_all_action() { return *m_select_all_action; }
  53. GUI::Action& copy_action() { return *m_copy_action; }
  54. String selected_text() const;
  55. void select_all();
  56. private:
  57. InProcessWebView();
  58. Page& page() { return *m_page; }
  59. const Page& page() const { return *m_page; }
  60. virtual void resize_event(GUI::ResizeEvent&) override;
  61. virtual void paint_event(GUI::PaintEvent&) override;
  62. virtual void mousemove_event(GUI::MouseEvent&) override;
  63. virtual void mousedown_event(GUI::MouseEvent&) override;
  64. virtual void mouseup_event(GUI::MouseEvent&) override;
  65. virtual void mousewheel_event(GUI::MouseEvent&) override;
  66. virtual void keydown_event(GUI::KeyEvent&) override;
  67. virtual void drop_event(GUI::DropEvent&) override;
  68. virtual void did_scroll() override;
  69. // ^Web::PageClient
  70. virtual bool is_multi_process() const override { return false; }
  71. virtual Gfx::Palette palette() const override { return GUI::ScrollableWidget::palette(); }
  72. virtual Gfx::IntRect screen_rect() const override { return GUI::Desktop::the().rect(); }
  73. virtual void page_did_change_title(const String&) override;
  74. virtual void page_did_set_document_in_main_frame(DOM::Document*) override;
  75. virtual void page_did_start_loading(const URL&) override;
  76. virtual void page_did_finish_loading(const URL&) override;
  77. virtual void page_did_change_selection() override;
  78. virtual void page_did_request_cursor_change(Gfx::StandardCursor) override;
  79. virtual void page_did_request_context_menu(const Gfx::IntPoint&) override;
  80. virtual void page_did_request_link_context_menu(const Gfx::IntPoint&, const URL&, const String& target, unsigned modifiers) override;
  81. virtual void page_did_request_image_context_menu(const Gfx::IntPoint&, const URL&, const String& target, unsigned modifiers, const Gfx::Bitmap*) override;
  82. virtual void page_did_click_link(const URL&, const String& target, unsigned modifiers) override;
  83. virtual void page_did_middle_click_link(const URL&, const String& target, unsigned modifiers) override;
  84. virtual void page_did_enter_tooltip_area(const Gfx::IntPoint&, const String&) override;
  85. virtual void page_did_leave_tooltip_area() override;
  86. virtual void page_did_hover_link(const URL&) override;
  87. virtual void page_did_unhover_link() override;
  88. virtual void page_did_invalidate(const Gfx::IntRect&) override;
  89. virtual void page_did_change_favicon(const Gfx::Bitmap&) override;
  90. virtual void page_did_layout() override;
  91. virtual void page_did_request_scroll_into_view(const Gfx::IntRect&) override;
  92. virtual void page_did_request_alert(const String&) override;
  93. virtual bool page_did_request_confirm(const String&) override;
  94. virtual String page_did_request_prompt(const String&, const String&) override;
  95. virtual String page_did_request_cookie(const URL&) override;
  96. virtual void page_did_set_cookie(const URL&, const String&) override;
  97. void layout_and_sync_size();
  98. bool m_should_show_line_box_borders { false };
  99. NonnullOwnPtr<Page> m_page;
  100. RefPtr<GUI::Action> m_copy_action;
  101. RefPtr<GUI::Action> m_select_all_action;
  102. };
  103. }