| 
									
										
										
										
											2020-01-18 09:38:21 +01:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2021-02-09 21:23:50 +01:00
										 |  |  |  * Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org> | 
					
						
							| 
									
										
										
										
											2020-01-18 09:38:21 +01:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2021-04-22 01:24:48 -07:00
										 |  |  |  * SPDX-License-Identifier: BSD-2-Clause | 
					
						
							| 
									
										
										
										
											2020-01-18 09:38:21 +01:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-04 15:50:04 +02:00
										 |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-09 21:25:29 +02:00
										 |  |  | #include <AK/Function.h>
 | 
					
						
							| 
									
										
										
										
											2019-10-04 15:50:04 +02:00
										 |  |  | #include <AK/Noncopyable.h>
 | 
					
						
							|  |  |  | #include <AK/RefPtr.h>
 | 
					
						
							| 
									
										
										
										
											2019-11-25 21:19:03 +01:00
										 |  |  | #include <AK/WeakPtr.h>
 | 
					
						
							| 
									
										
										
										
											2020-08-02 11:52:35 +02:00
										 |  |  | #include <LibCore/Timer.h>
 | 
					
						
							| 
									
										
										
										
											2020-06-06 13:02:44 +02:00
										 |  |  | #include <LibGfx/Bitmap.h>
 | 
					
						
							| 
									
										
										
										
											2020-02-06 12:04:00 +01:00
										 |  |  | #include <LibGfx/Rect.h>
 | 
					
						
							|  |  |  | #include <LibGfx/Size.h>
 | 
					
						
							| 
									
										
										
										
											2020-08-02 11:52:35 +02:00
										 |  |  | #include <LibWeb/DOM/Position.h>
 | 
					
						
							| 
									
										
										
										
											2020-06-06 13:02:44 +02:00
										 |  |  | #include <LibWeb/Loader/FrameLoader.h>
 | 
					
						
							| 
									
										
										
										
											2020-07-28 19:27:41 +02:00
										 |  |  | #include <LibWeb/Page/EventHandler.h>
 | 
					
						
							| 
									
										
										
										
											2020-03-07 10:32:51 +01:00
										 |  |  | #include <LibWeb/TreeNode.h>
 | 
					
						
							| 
									
										
										
										
											2019-10-04 15:50:04 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-07 10:27:02 +01:00
										 |  |  | namespace Web { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-19 09:42:20 +02:00
										 |  |  | class Frame : public TreeNode<Frame> { | 
					
						
							| 
									
										
										
										
											2019-10-04 15:50:04 +02:00
										 |  |  | public: | 
					
						
							| 
									
										
										
										
											2021-04-23 16:46:57 +02:00
										 |  |  |     static NonnullRefPtr<Frame> create_subframe(DOM::Element& host_element, Frame& main_frame) { return adopt_ref(*new Frame(host_element, main_frame)); } | 
					
						
							|  |  |  |     static NonnullRefPtr<Frame> create(Page& page) { return adopt_ref(*new Frame(page)); } | 
					
						
							| 
									
										
										
										
											2019-10-04 15:50:04 +02:00
										 |  |  |     ~Frame(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-30 12:25:33 +01:00
										 |  |  |     class ViewportClient { | 
					
						
							|  |  |  |     public: | 
					
						
							|  |  |  |         virtual ~ViewportClient() { } | 
					
						
							|  |  |  |         virtual void frame_did_set_viewport_rect(const Gfx::IntRect&) = 0; | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |     void register_viewport_client(ViewportClient&); | 
					
						
							|  |  |  |     void unregister_viewport_client(ViewportClient&); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-06 16:33:04 +02:00
										 |  |  |     bool is_main_frame() const { return this == &m_main_frame; } | 
					
						
							| 
									
										
										
										
											2020-08-14 11:33:20 +02:00
										 |  |  |     bool is_focused_frame() const; | 
					
						
							| 
									
										
										
										
											2020-06-06 16:33:04 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-26 19:37:56 +02:00
										 |  |  |     const DOM::Document* document() const { return m_document; } | 
					
						
							|  |  |  |     DOM::Document* document() { return m_document; } | 
					
						
							| 
									
										
										
										
											2019-10-04 15:50:04 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-26 19:37:56 +02:00
										 |  |  |     void set_document(DOM::Document*); | 
					
						
							| 
									
										
										
										
											2019-10-04 15:50:04 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-12 18:23:05 +01:00
										 |  |  |     Page* page() { return m_page; } | 
					
						
							|  |  |  |     const Page* page() const { return m_page; } | 
					
						
							| 
									
										
										
										
											2019-11-25 21:19:03 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-10 10:57:59 +02:00
										 |  |  |     const Gfx::IntSize& size() const { return m_size; } | 
					
						
							|  |  |  |     void set_size(const Gfx::IntSize&); | 
					
						
							| 
									
										
										
										
											2019-10-04 15:50:04 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-10 10:57:59 +02:00
										 |  |  |     void set_needs_display(const Gfx::IntRect&); | 
					
						
							| 
									
										
										
										
											2020-06-06 13:02:44 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-02 23:40:57 +01:00
										 |  |  |     void set_viewport_scroll_offset(const Gfx::IntPoint&); | 
					
						
							|  |  |  |     Gfx::IntRect viewport_rect() const { return { m_viewport_scroll_offset, m_size }; } | 
					
						
							| 
									
										
										
										
											2021-02-09 22:40:16 +01:00
										 |  |  |     void set_viewport_rect(const Gfx::IntRect&); | 
					
						
							| 
									
										
										
										
											2019-12-18 20:54:23 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-06 13:02:44 +02:00
										 |  |  |     FrameLoader& loader() { return m_loader; } | 
					
						
							|  |  |  |     const FrameLoader& loader() const { return m_loader; } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-07 14:40:38 +02:00
										 |  |  |     EventHandler& event_handler() { return m_event_handler; } | 
					
						
							|  |  |  |     const EventHandler& event_handler() const { return m_event_handler; } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-06 13:02:44 +02:00
										 |  |  |     void scroll_to_anchor(const String&); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-06 15:08:36 +02:00
										 |  |  |     Frame& main_frame() { return m_main_frame; } | 
					
						
							|  |  |  |     const Frame& main_frame() const { return m_main_frame; } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-26 19:37:56 +02:00
										 |  |  |     DOM::Element* host_element() { return m_host_element; } | 
					
						
							|  |  |  |     const DOM::Element* host_element() const { return m_host_element; } | 
					
						
							| 
									
										
										
										
											2020-06-06 15:08:36 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-10 10:57:59 +02:00
										 |  |  |     Gfx::IntPoint to_main_frame_position(const Gfx::IntPoint&); | 
					
						
							|  |  |  |     Gfx::IntRect to_main_frame_rect(const Gfx::IntRect&); | 
					
						
							| 
									
										
										
										
											2020-06-08 20:31:49 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-02 11:52:35 +02:00
										 |  |  |     const DOM::Position& cursor_position() const { return m_cursor_position; } | 
					
						
							| 
									
										
										
										
											2021-02-09 21:23:50 +01:00
										 |  |  |     void set_cursor_position(DOM::Position); | 
					
						
							| 
									
										
										
										
											2021-05-18 22:01:12 +02:00
										 |  |  |     bool increment_cursor_position_offset(); | 
					
						
							|  |  |  |     bool decrement_cursor_position_offset(); | 
					
						
							| 
									
										
										
										
											2020-08-02 11:52:35 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     bool cursor_blink_state() const { return m_cursor_blink_state; } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-06 19:21:59 +02:00
										 |  |  |     String selected_text() const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-04 20:48:27 +01:00
										 |  |  |     void did_edit(Badge<EditEventHandler>); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-19 14:30:08 +02:00
										 |  |  |     void register_frame_nesting(URL const&); | 
					
						
							|  |  |  |     bool is_frame_nesting_allowed(URL const&) const; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     void set_frame_nesting_levels(const HashMap<URL, size_t> frame_nesting_levels) { m_frame_nesting_levels = move(frame_nesting_levels); }; | 
					
						
							|  |  |  |     HashMap<URL, size_t> const& frame_nesting_levels() const { return m_frame_nesting_levels; } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-04 15:50:04 +02:00
										 |  |  | private: | 
					
						
							| 
									
										
										
										
											2020-07-26 19:37:56 +02:00
										 |  |  |     explicit Frame(DOM::Element& host_element, Frame& main_frame); | 
					
						
							| 
									
										
										
										
											2020-06-08 20:31:49 +02:00
										 |  |  |     explicit Frame(Page&); | 
					
						
							| 
									
										
										
										
											2019-10-04 15:50:04 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-09 21:23:50 +01:00
										 |  |  |     void reset_cursor_blink_cycle(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-02 11:52:35 +02:00
										 |  |  |     void setup(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-12 18:23:05 +01:00
										 |  |  |     WeakPtr<Page> m_page; | 
					
						
							| 
									
										
										
										
											2020-06-06 15:08:36 +02:00
										 |  |  |     Frame& m_main_frame; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-06 13:02:44 +02:00
										 |  |  |     FrameLoader m_loader; | 
					
						
							| 
									
										
										
										
											2020-06-07 14:40:38 +02:00
										 |  |  |     EventHandler m_event_handler; | 
					
						
							| 
									
										
										
										
											2020-06-06 13:02:44 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-26 19:37:56 +02:00
										 |  |  |     WeakPtr<DOM::Element> m_host_element; | 
					
						
							|  |  |  |     RefPtr<DOM::Document> m_document; | 
					
						
							| 
									
										
										
										
											2020-06-10 10:57:59 +02:00
										 |  |  |     Gfx::IntSize m_size; | 
					
						
							| 
									
										
										
										
											2020-12-02 23:40:57 +01:00
										 |  |  |     Gfx::IntPoint m_viewport_scroll_offset; | 
					
						
							| 
									
										
										
										
											2020-08-02 11:52:35 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     DOM::Position m_cursor_position; | 
					
						
							|  |  |  |     RefPtr<Core::Timer> m_cursor_blink_timer; | 
					
						
							|  |  |  |     bool m_cursor_blink_state { false }; | 
					
						
							| 
									
										
										
										
											2021-01-30 12:25:33 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     HashTable<ViewportClient*> m_viewport_clients; | 
					
						
							| 
									
										
										
										
											2021-04-19 14:30:08 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     HashMap<URL, size_t> m_frame_nesting_levels; | 
					
						
							| 
									
										
										
										
											2019-10-04 15:50:04 +02:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2020-03-07 10:27:02 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | } |