HtmlView.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. namespace Web {
  31. class Frame;
  32. class HtmlView : public GUI::ScrollableWidget {
  33. C_OBJECT(HtmlView)
  34. public:
  35. virtual ~HtmlView() override;
  36. Document* document();
  37. const Document* document() const;
  38. void set_document(Document*);
  39. const LayoutDocument* layout_root() const;
  40. LayoutDocument* layout_root();
  41. Web::Frame& main_frame() { return *m_main_frame; }
  42. const Web::Frame& main_frame() const { return *m_main_frame; }
  43. void reload();
  44. void load(const URL&);
  45. void load_error_page(const URL&, const String& error);
  46. void scroll_to_anchor(const StringView&);
  47. URL url() const;
  48. void set_should_show_line_box_borders(bool value) { m_should_show_line_box_borders = value; }
  49. Function<void(const String& href, const String& target, unsigned modifiers)> on_link_click;
  50. Function<void(const String& href, const Gfx::Point& screen_position)> on_link_context_menu_request;
  51. Function<void(const String& href)> on_link_middle_click;
  52. Function<void(const String&)> on_link_hover;
  53. Function<void(const String&)> on_title_change;
  54. Function<void(const URL&)> on_load_start;
  55. Function<void(const Gfx::Bitmap&)> on_favicon_change;
  56. Function<void(const URL&)> on_url_drop;
  57. virtual bool accepts_focus() const override { return true; }
  58. protected:
  59. HtmlView();
  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 keydown_event(GUI::KeyEvent&) override;
  66. virtual void drop_event(GUI::DropEvent&) override;
  67. private:
  68. virtual void did_scroll() override;
  69. void run_javascript_url(const String& url);
  70. void layout_and_sync_size();
  71. void dump_selection(const char* event_name);
  72. Gfx::Point compute_mouse_event_offset(const Gfx::Point&, const LayoutNode&) const;
  73. RefPtr<Web::Frame> m_main_frame;
  74. bool m_should_show_line_box_borders { false };
  75. bool m_in_mouse_selection { false };
  76. };
  77. }