InProcessWebView.h 4.8 KB

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