| 
									
										
										
										
											2020-04-01 18:53:28 +02:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2022-02-08 19:38:29 +01:00
										 |  |  |  * Copyright (c) 2020-2022, Andreas Kling <kling@serenityos.org> | 
					
						
							| 
									
										
										
										
											2020-04-01 18:53:28 +02:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2021-04-22 01:24:48 -07:00
										 |  |  |  * SPDX-License-Identifier: BSD-2-Clause | 
					
						
							| 
									
										
										
										
											2020-04-01 18:53:28 +02:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <AK/Badge.h>
 | 
					
						
							| 
									
										
										
										
											2020-06-27 18:30:29 +02:00
										 |  |  | #include <AK/IDAllocator.h>
 | 
					
						
							| 
									
										
										
										
											2020-04-01 18:53:28 +02:00
										 |  |  | #include <AK/RefCounted.h>
 | 
					
						
							|  |  |  | #include <AK/RefPtr.h>
 | 
					
						
							| 
									
										
										
										
											2022-03-24 16:09:09 -04:00
										 |  |  | #include <AK/Weakable.h>
 | 
					
						
							| 
									
										
										
										
											2020-04-01 18:53:28 +02:00
										 |  |  | #include <LibWeb/Bindings/WindowObject.h>
 | 
					
						
							|  |  |  | #include <LibWeb/Bindings/Wrappable.h>
 | 
					
						
							| 
									
										
										
										
											2021-09-12 17:10:27 +01:00
										 |  |  | #include <LibWeb/CSS/MediaQueryList.h>
 | 
					
						
							| 
									
										
										
										
											2021-04-04 00:14:39 +02:00
										 |  |  | #include <LibWeb/CSS/Screen.h>
 | 
					
						
							| 
									
										
										
										
											2022-03-05 00:13:13 +01:00
										 |  |  | #include <LibWeb/DOM/Document.h>
 | 
					
						
							| 
									
										
										
										
											2020-11-21 18:32:39 +00:00
										 |  |  | #include <LibWeb/DOM/Event.h>
 | 
					
						
							| 
									
										
										
										
											2020-10-18 13:43:44 +02:00
										 |  |  | #include <LibWeb/DOM/EventTarget.h>
 | 
					
						
							| 
									
										
										
										
											2022-03-05 00:13:13 +01:00
										 |  |  | #include <LibWeb/HTML/BrowsingContext.h>
 | 
					
						
							| 
									
										
										
										
											2021-09-22 16:39:15 +02:00
										 |  |  | #include <LibWeb/HTML/GlobalEventHandlers.h>
 | 
					
						
							| 
									
										
										
										
											2020-04-01 18:53:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-07 23:08:26 +01:00
										 |  |  | namespace Web::HTML { | 
					
						
							| 
									
										
										
										
											2020-04-01 18:53:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-13 02:03:06 +02:00
										 |  |  | class RequestAnimationFrameCallback; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-18 13:43:44 +02:00
										 |  |  | class Window final | 
					
						
							|  |  |  |     : public RefCounted<Window> | 
					
						
							| 
									
										
										
										
											2022-03-24 16:09:09 -04:00
										 |  |  |     , public Weakable<Window> | 
					
						
							| 
									
										
										
										
											2022-03-07 23:08:26 +01:00
										 |  |  |     , public DOM::EventTarget | 
					
						
							| 
									
										
										
										
											2021-09-22 16:39:15 +02:00
										 |  |  |     , public HTML::GlobalEventHandlers { | 
					
						
							| 
									
										
										
										
											2020-04-01 18:53:28 +02:00
										 |  |  | public: | 
					
						
							| 
									
										
										
										
											2022-03-07 23:08:26 +01:00
										 |  |  |     static NonnullRefPtr<Window> create_with_document(DOM::Document&); | 
					
						
							| 
									
										
										
										
											2020-04-01 18:53:28 +02:00
										 |  |  |     ~Window(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-18 13:43:44 +02:00
										 |  |  |     using RefCounted::ref; | 
					
						
							|  |  |  |     using RefCounted::unref; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     virtual void ref_event_target() override { RefCounted::ref(); } | 
					
						
							|  |  |  |     virtual void unref_event_target() override { RefCounted::unref(); } | 
					
						
							| 
									
										
										
										
											2022-03-07 23:08:26 +01:00
										 |  |  |     virtual bool dispatch_event(NonnullRefPtr<DOM::Event>) override; | 
					
						
							| 
									
										
										
										
											2021-01-18 12:15:02 +01:00
										 |  |  |     virtual JS::Object* create_wrapper(JS::GlobalObject&) override; | 
					
						
							| 
									
										
										
										
											2020-10-18 13:43:44 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-09 13:45:03 +02:00
										 |  |  |     Page* page(); | 
					
						
							|  |  |  |     Page const* page() const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-05 00:13:13 +01:00
										 |  |  |     // https://html.spec.whatwg.org/multipage/window-object.html#concept-document-window
 | 
					
						
							| 
									
										
										
										
											2022-03-07 23:08:26 +01:00
										 |  |  |     DOM::Document const& associated_document() const { return *m_associated_document; } | 
					
						
							|  |  |  |     DOM::Document& associated_document() { return *m_associated_document; } | 
					
						
							| 
									
										
										
										
											2020-04-01 18:53:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-05 00:13:13 +01:00
										 |  |  |     // https://html.spec.whatwg.org/multipage/window-object.html#window-bc
 | 
					
						
							|  |  |  |     HTML::BrowsingContext const* browsing_context() const { return m_associated_document->browsing_context(); } | 
					
						
							|  |  |  |     HTML::BrowsingContext* browsing_context() { return m_associated_document->browsing_context(); } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-09 13:50:06 +02:00
										 |  |  |     void alert(String const&); | 
					
						
							|  |  |  |     bool confirm(String const&); | 
					
						
							|  |  |  |     String prompt(String const&, String const&); | 
					
						
							| 
									
										
										
										
											2021-10-14 18:03:08 +01:00
										 |  |  |     i32 request_animation_frame(NonnullOwnPtr<Bindings::CallbackType> js_callback); | 
					
						
							| 
									
										
										
										
											2020-04-01 18:53:28 +02:00
										 |  |  |     void cancel_animation_frame(i32); | 
					
						
							| 
									
										
										
										
											2020-06-27 18:30:29 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-04 10:41:12 -05:00
										 |  |  |     i32 set_timeout(Bindings::TimerHandler handler, i32 timeout, JS::MarkedVector<JS::Value> arguments); | 
					
						
							|  |  |  |     i32 set_interval(Bindings::TimerHandler handler, i32 timeout, JS::MarkedVector<JS::Value> arguments); | 
					
						
							| 
									
										
										
										
											2020-06-27 18:30:29 +02:00
										 |  |  |     void clear_timeout(i32); | 
					
						
							|  |  |  |     void clear_interval(i32); | 
					
						
							| 
									
										
										
										
											2020-04-01 18:53:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-14 18:03:08 +01:00
										 |  |  |     void queue_microtask(NonnullOwnPtr<Bindings::CallbackType> callback); | 
					
						
							| 
									
										
										
										
											2021-09-26 14:36:20 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-16 17:22:01 +01:00
										 |  |  |     int inner_width() const; | 
					
						
							|  |  |  |     int inner_height() const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-13 00:33:23 +03:00
										 |  |  |     void did_set_location_href(Badge<Bindings::LocationObject>, AK::URL const& new_href); | 
					
						
							| 
									
										
										
										
											2020-05-18 22:05:13 +02:00
										 |  |  |     void did_call_location_reload(Badge<Bindings::LocationObject>); | 
					
						
							| 
									
										
										
										
											2021-10-03 23:31:52 +02:00
										 |  |  |     void did_call_location_replace(Badge<Bindings::LocationObject>, String url); | 
					
						
							| 
									
										
										
										
											2020-05-18 21:52:50 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-20 17:45:27 +02:00
										 |  |  |     Bindings::WindowObject* wrapper() { return m_wrapper; } | 
					
						
							| 
									
										
										
										
											2021-09-09 13:50:06 +02:00
										 |  |  |     Bindings::WindowObject const* wrapper() const { return m_wrapper; } | 
					
						
							| 
									
										
										
										
											2020-06-20 17:45:27 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     void set_wrapper(Badge<Bindings::WindowObject>, Bindings::WindowObject&); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-07 23:54:56 +01:00
										 |  |  |     void deallocate_timer_id(Badge<Timer>, i32); | 
					
						
							| 
									
										
										
										
											2020-06-27 18:30:29 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-29 18:19:18 +02:00
										 |  |  |     HighResolutionTime::Performance& performance() { return *m_performance; } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-30 20:02:55 +03:00
										 |  |  |     Crypto::Crypto& crypto() { return *m_crypto; } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-04 00:14:39 +02:00
										 |  |  |     CSS::Screen& screen() { return *m_screen; } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-07 23:08:26 +01:00
										 |  |  |     DOM::Event const* current_event() const { return m_current_event; } | 
					
						
							|  |  |  |     void set_current_event(DOM::Event* event) { m_current_event = event; } | 
					
						
							| 
									
										
										
										
											2020-11-21 18:32:39 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-11 00:33:30 +02:00
										 |  |  |     NonnullRefPtr<CSS::CSSStyleDeclaration> get_computed_style(DOM::Element&) const; | 
					
						
							| 
									
										
										
										
											2021-09-12 17:10:27 +01:00
										 |  |  |     NonnullRefPtr<CSS::MediaQueryList> match_media(String); | 
					
						
							| 
									
										
										
										
											2022-03-08 16:51:33 +00:00
										 |  |  |     Optional<CSS::MediaFeatureValue> query_media_feature(CSS::MediaFeatureID) const; | 
					
						
							| 
									
										
										
										
											2021-09-11 00:33:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-24 21:49:31 +02:00
										 |  |  |     float scroll_x() const; | 
					
						
							|  |  |  |     float scroll_y() const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-01 19:05:28 +03:00
										 |  |  |     void fire_a_page_transition_event(FlyString const& event_name, bool persisted); | 
					
						
							| 
									
										
										
										
											2021-09-26 12:39:27 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-27 16:34:06 +02:00
										 |  |  |     float device_pixel_ratio() const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-29 00:15:26 +02:00
										 |  |  |     int screen_x() const; | 
					
						
							|  |  |  |     int screen_y() const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-10 19:12:32 +02:00
										 |  |  |     Selection::Selection* get_selection(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-08 19:38:29 +01:00
										 |  |  |     RefPtr<HTML::Storage> local_storage(); | 
					
						
							| 
									
										
										
										
											2022-03-08 04:39:44 +13:00
										 |  |  |     RefPtr<HTML::Storage> session_storage(); | 
					
						
							| 
									
										
										
										
											2022-02-08 19:38:29 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-26 15:55:45 +01:00
										 |  |  |     Window* parent(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-26 17:21:40 +01:00
										 |  |  |     DOM::ExceptionOr<void> post_message(JS::Value, String const& target_origin); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-16 17:15:11 +01:00
										 |  |  |     String name() const; | 
					
						
							|  |  |  |     void set_name(String const&); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-01 18:53:28 +02:00
										 |  |  | private: | 
					
						
							| 
									
										
										
										
											2022-03-07 23:08:26 +01:00
										 |  |  |     explicit Window(DOM::Document&); | 
					
						
							| 
									
										
										
										
											2020-04-01 18:53:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-22 16:39:15 +02:00
										 |  |  |     // ^HTML::GlobalEventHandlers
 | 
					
						
							|  |  |  |     virtual DOM::EventTarget& global_event_handlers_to_event_target() override { return *this; } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-04 10:41:12 -05:00
										 |  |  |     enum class Repeat { | 
					
						
							|  |  |  |         Yes, | 
					
						
							|  |  |  |         No, | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |     i32 run_timer_initialization_steps(Bindings::TimerHandler handler, i32 timeout, JS::MarkedVector<JS::Value> arguments, Repeat repeat, Optional<i32> previous_id = {}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-09 13:55:31 +02:00
										 |  |  |     // https://html.spec.whatwg.org/multipage/window-object.html#concept-document-window
 | 
					
						
							| 
									
										
										
										
											2022-03-07 23:08:26 +01:00
										 |  |  |     WeakPtr<DOM::Document> m_associated_document; | 
					
						
							| 
									
										
										
										
											2021-09-09 13:55:31 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-20 17:45:27 +02:00
										 |  |  |     WeakPtr<Bindings::WindowObject> m_wrapper; | 
					
						
							| 
									
										
										
										
											2020-06-27 18:30:29 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     IDAllocator m_timer_id_allocator; | 
					
						
							| 
									
										
										
										
											2022-03-07 23:54:56 +01:00
										 |  |  |     HashMap<int, NonnullRefPtr<Timer>> m_timers; | 
					
						
							| 
									
										
										
										
											2020-09-29 18:19:18 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     NonnullOwnPtr<HighResolutionTime::Performance> m_performance; | 
					
						
							| 
									
										
										
										
											2021-09-30 20:02:55 +03:00
										 |  |  |     NonnullRefPtr<Crypto::Crypto> m_crypto; | 
					
						
							| 
									
										
										
										
											2021-12-09 15:47:48 +01:00
										 |  |  |     NonnullOwnPtr<CSS::Screen> m_screen; | 
					
						
							| 
									
										
										
										
											2022-03-07 23:08:26 +01:00
										 |  |  |     RefPtr<DOM::Event> m_current_event; | 
					
						
							| 
									
										
										
										
											2021-09-13 02:03:06 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     HashMap<i32, NonnullRefPtr<RequestAnimationFrameCallback>> m_request_animation_frame_callbacks; | 
					
						
							| 
									
										
										
										
											2020-04-01 18:53:28 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-03 16:28:14 +02:00
										 |  |  | void run_animation_frame_callbacks(DOM::Document&, double now); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-01 18:53:28 +02:00
										 |  |  | } |