Serenity Operating System
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
28#include <AK/URL.h>
29#include <LibGUI/ScrollableWidget.h>
30#include <LibHTML/DOM/Document.h>
31
32class Frame;
33
34class HtmlView : public GUI::ScrollableWidget {
35 C_OBJECT(HtmlView)
36public:
37 virtual ~HtmlView() override;
38
39 Document* document();
40 const Document* document() const;
41 void set_document(Document*);
42
43 const LayoutDocument* layout_root() const;
44 LayoutDocument* layout_root();
45
46 ::Frame& main_frame() { return *m_main_frame; }
47 const ::Frame& main_frame() const { return *m_main_frame; }
48
49 void reload();
50 void load(const URL&);
51 void scroll_to_anchor(const StringView&);
52
53 URL url() const;
54
55 void set_should_show_line_box_borders(bool value) { m_should_show_line_box_borders = value; }
56
57 Function<void(const String&)> on_link_click;
58 Function<void(const String&)> on_link_hover;
59 Function<void(const String&)> on_title_change;
60 Function<void(const URL&)> on_load_start;
61
62 virtual bool accepts_focus() const override { return true; }
63
64protected:
65 HtmlView();
66
67 virtual void resize_event(GUI::ResizeEvent&) override;
68 virtual void paint_event(GUI::PaintEvent&) override;
69 virtual void mousemove_event(GUI::MouseEvent&) override;
70 virtual void mousedown_event(GUI::MouseEvent&) override;
71 virtual void mouseup_event(GUI::MouseEvent&) override;
72 virtual void keydown_event(GUI::KeyEvent&) override;
73
74private:
75 virtual void did_scroll() override;
76
77 void layout_and_sync_size();
78 void dump_selection(const char* event_name);
79
80 RefPtr<::Frame> m_main_frame;
81
82 bool m_should_show_line_box_borders { false };
83 bool m_in_mouse_selection { false };
84};