| 
									
										
										
										
											2020-01-18 09:38:21 +01:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> | 
					
						
							|  |  |  |  * All rights reserved. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Redistribution and use in source and binary forms, with or without | 
					
						
							|  |  |  |  * modification, are permitted provided that the following conditions are met: | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * 1. Redistributions of source code must retain the above copyright notice, this | 
					
						
							|  |  |  |  *    list of conditions and the following disclaimer. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * 2. Redistributions in binary form must reproduce the above copyright notice, | 
					
						
							|  |  |  |  *    this list of conditions and the following disclaimer in the documentation | 
					
						
							|  |  |  |  *    and/or other materials provided with the distribution. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | 
					
						
							|  |  |  |  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 
					
						
							|  |  |  |  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 
					
						
							|  |  |  |  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | 
					
						
							|  |  |  |  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 
					
						
							|  |  |  |  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | 
					
						
							|  |  |  |  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | 
					
						
							|  |  |  |  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | 
					
						
							|  |  |  |  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 
					
						
							|  |  |  |  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-25 12:44:22 +03:00
										 |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-05 10:16:27 +02:00
										 |  |  | #include <AK/URL.h>
 | 
					
						
							| 
									
										
										
										
											2019-09-25 12:44:22 +03:00
										 |  |  | #include <LibGUI/GScrollableWidget.h>
 | 
					
						
							|  |  |  | #include <LibHTML/DOM/Document.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-04 15:50:04 +02:00
										 |  |  | class Frame; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-25 12:44:22 +03:00
										 |  |  | class HtmlView : public GScrollableWidget { | 
					
						
							|  |  |  |     C_OBJECT(HtmlView) | 
					
						
							|  |  |  | public: | 
					
						
							| 
									
										
										
										
											2019-10-04 15:50:04 +02:00
										 |  |  |     virtual ~HtmlView() override; | 
					
						
							| 
									
										
										
										
											2019-09-25 12:44:22 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-20 10:36:14 +02:00
										 |  |  |     Document* document(); | 
					
						
							|  |  |  |     const Document* document() const; | 
					
						
							| 
									
										
										
										
											2019-09-25 12:44:22 +03:00
										 |  |  |     void set_document(Document*); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-13 12:34:25 +02:00
										 |  |  |     const LayoutDocument* layout_root() const; | 
					
						
							|  |  |  |     LayoutDocument* layout_root(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-04 15:50:04 +02:00
										 |  |  |     Frame& main_frame() { return *m_main_frame; } | 
					
						
							|  |  |  |     const Frame& main_frame() const { return *m_main_frame; } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-05 10:16:27 +02:00
										 |  |  |     void reload(); | 
					
						
							|  |  |  |     void load(const URL&); | 
					
						
							| 
									
										
										
										
											2019-10-20 09:14:12 +02:00
										 |  |  |     void scroll_to_anchor(const StringView&); | 
					
						
							| 
									
										
										
										
											2019-10-05 10:16:27 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     URL url() const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-12 15:02:53 +02:00
										 |  |  |     void set_should_show_line_box_borders(bool value) { m_should_show_line_box_borders = value; } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-29 12:04:02 +02:00
										 |  |  |     Function<void(const String&)> on_link_click; | 
					
						
							| 
									
										
										
										
											2019-10-19 21:21:29 +02:00
										 |  |  |     Function<void(const String&)> on_link_hover; | 
					
						
							| 
									
										
										
										
											2019-09-29 16:24:57 +02:00
										 |  |  |     Function<void(const String&)> on_title_change; | 
					
						
							| 
									
										
										
										
											2019-10-05 10:16:27 +02:00
										 |  |  |     Function<void(const URL&)> on_load_start; | 
					
						
							| 
									
										
										
										
											2019-09-29 12:04:02 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-17 21:36:22 +02:00
										 |  |  |     virtual bool accepts_focus() const override { return true; } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-25 12:44:22 +03:00
										 |  |  | protected: | 
					
						
							|  |  |  |     HtmlView(GWidget* parent = nullptr); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     virtual void resize_event(GResizeEvent&) override; | 
					
						
							|  |  |  |     virtual void paint_event(GPaintEvent&) override; | 
					
						
							| 
									
										
										
										
											2019-09-28 23:02:22 +02:00
										 |  |  |     virtual void mousemove_event(GMouseEvent&) override; | 
					
						
							| 
									
										
										
										
											2019-09-29 12:04:02 +02:00
										 |  |  |     virtual void mousedown_event(GMouseEvent&) override; | 
					
						
							| 
									
										
										
										
											2019-11-05 22:13:26 +01:00
										 |  |  |     virtual void mouseup_event(GMouseEvent&) override; | 
					
						
							| 
									
										
										
										
											2019-10-17 21:36:22 +02:00
										 |  |  |     virtual void keydown_event(GKeyEvent&) override; | 
					
						
							| 
									
										
										
										
											2019-09-25 12:44:22 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							| 
									
										
										
										
											2019-12-18 20:54:23 +01:00
										 |  |  |     virtual void did_scroll() override; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-25 12:44:22 +03:00
										 |  |  |     void layout_and_sync_size(); | 
					
						
							| 
									
										
										
										
											2019-11-05 22:13:26 +01:00
										 |  |  |     void dump_selection(const char* event_name); | 
					
						
							| 
									
										
										
										
											2019-09-25 12:44:22 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-04 15:50:04 +02:00
										 |  |  |     RefPtr<Frame> m_main_frame; | 
					
						
							| 
									
										
										
										
											2019-10-12 15:02:53 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     bool m_should_show_line_box_borders { false }; | 
					
						
							| 
									
										
										
										
											2019-11-05 22:13:26 +01:00
										 |  |  |     bool m_in_mouse_selection { false }; | 
					
						
							| 
									
										
										
										
											2019-09-25 12:44:22 +03:00
										 |  |  | }; |