HtmlView.h 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 scroll_to_anchor(const StringView&);
  46. URL url() const;
  47. void set_should_show_line_box_borders(bool value) { m_should_show_line_box_borders = value; }
  48. Function<void(const String&)> on_link_click;
  49. Function<void(const String&)> on_link_hover;
  50. Function<void(const String&)> on_title_change;
  51. Function<void(const URL&)> on_load_start;
  52. virtual bool accepts_focus() const override { return true; }
  53. protected:
  54. HtmlView();
  55. virtual void resize_event(GUI::ResizeEvent&) override;
  56. virtual void paint_event(GUI::PaintEvent&) override;
  57. virtual void mousemove_event(GUI::MouseEvent&) override;
  58. virtual void mousedown_event(GUI::MouseEvent&) override;
  59. virtual void mouseup_event(GUI::MouseEvent&) override;
  60. virtual void keydown_event(GUI::KeyEvent&) override;
  61. private:
  62. virtual void did_scroll() override;
  63. void layout_and_sync_size();
  64. void dump_selection(const char* event_name);
  65. Gfx::Point compute_mouse_event_offset(const Gfx::Point&, const LayoutNode&) const;
  66. RefPtr<Web::Frame> m_main_frame;
  67. bool m_should_show_line_box_borders { false };
  68. bool m_in_mouse_selection { false };
  69. };
  70. }