HtmlView.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. // FIXME: Remove this once the new parser is ready.
  37. void set_use_new_parser(bool use_new_parser) { m_use_new_parser = use_new_parser; }
  38. Document* document();
  39. const Document* document() const;
  40. void set_document(Document*);
  41. const LayoutDocument* layout_root() const;
  42. LayoutDocument* layout_root();
  43. Web::Frame& main_frame() { return *m_main_frame; }
  44. const Web::Frame& main_frame() const { return *m_main_frame; }
  45. void reload();
  46. void load(const URL&);
  47. void load_error_page(const URL&, const String& error);
  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::Point& 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. protected:
  62. HtmlView();
  63. virtual void resize_event(GUI::ResizeEvent&) override;
  64. virtual void paint_event(GUI::PaintEvent&) override;
  65. virtual void mousemove_event(GUI::MouseEvent&) override;
  66. virtual void mousedown_event(GUI::MouseEvent&) override;
  67. virtual void mouseup_event(GUI::MouseEvent&) override;
  68. virtual void keydown_event(GUI::KeyEvent&) override;
  69. virtual void drop_event(GUI::DropEvent&) override;
  70. private:
  71. virtual void did_scroll() override;
  72. RefPtr<Document> create_document_from_mime_type(const ByteBuffer& data, const URL& url, const String& mime_type, const String& encoding);
  73. void run_javascript_url(const String& url);
  74. void layout_and_sync_size();
  75. void dump_selection(const char* event_name);
  76. Gfx::Point compute_mouse_event_offset(const Gfx::Point&, const LayoutNode&) const;
  77. RefPtr<Web::Frame> m_main_frame;
  78. bool m_should_show_line_box_borders { false };
  79. bool m_in_mouse_selection { false };
  80. bool m_use_new_parser { false };
  81. };
  82. }