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