| 
									
										
										
										
											2021-04-04 00:14:39 +02:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2022-12-14 17:40:33 +00:00
										 |  |  |  * Copyright (c) 2021-2022, Linus Groh <linusg@serenityos.org> | 
					
						
							| 
									
										
										
										
											2021-04-04 00:14:39 +02:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2021-04-22 01:24:48 -07:00
										 |  |  |  * SPDX-License-Identifier: BSD-2-Clause | 
					
						
							| 
									
										
										
										
											2021-04-04 00:14:39 +02:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <LibGfx/Rect.h>
 | 
					
						
							| 
									
										
										
										
											2022-09-24 16:34:04 -06:00
										 |  |  | #include <LibWeb/Bindings/Intrinsics.h>
 | 
					
						
							|  |  |  | #include <LibWeb/Bindings/ScreenPrototype.h>
 | 
					
						
							| 
									
										
										
										
											2021-04-04 00:14:39 +02:00
										 |  |  | #include <LibWeb/CSS/Screen.h>
 | 
					
						
							| 
									
										
										
										
											2024-04-02 22:44:05 +02:00
										 |  |  | #include <LibWeb/CSS/ScreenOrientation.h>
 | 
					
						
							| 
									
										
										
										
											2021-04-04 00:14:39 +02:00
										 |  |  | #include <LibWeb/DOM/Document.h>
 | 
					
						
							|  |  |  | #include <LibWeb/Page/Page.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace Web::CSS { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-19 19:47:52 +01:00
										 |  |  | JS_DEFINE_ALLOCATOR(Screen); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-13 13:05:26 +02:00
										 |  |  | JS::NonnullGCPtr<Screen> Screen::create(HTML::Window& window) | 
					
						
							| 
									
										
										
										
											2022-08-31 18:52:54 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2023-08-13 13:05:26 +02:00
										 |  |  |     return window.heap().allocate<Screen>(window.realm(), window); | 
					
						
							| 
									
										
										
										
											2022-08-31 18:52:54 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-07 23:08:26 +01:00
										 |  |  | Screen::Screen(HTML::Window& window) | 
					
						
							| 
									
										
										
										
											2024-04-05 18:15:43 +02:00
										 |  |  |     : DOM::EventTarget(window.realm()) | 
					
						
							| 
									
										
										
										
											2022-08-31 18:52:54 +02:00
										 |  |  |     , m_window(window) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2023-01-10 06:28:20 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-07 08:41:28 +02:00
										 |  |  | void Screen::initialize(JS::Realm& realm) | 
					
						
							| 
									
										
										
										
											2023-01-10 06:28:20 -05:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2023-08-07 08:41:28 +02:00
										 |  |  |     Base::initialize(realm); | 
					
						
							| 
									
										
										
										
											2024-03-16 13:13:08 +01:00
										 |  |  |     WEB_SET_PROTOTYPE_FOR_INTERFACE(Screen); | 
					
						
							| 
									
										
										
										
											2022-08-31 18:52:54 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void Screen::visit_edges(Cell::Visitor& visitor) | 
					
						
							| 
									
										
										
										
											2021-04-04 00:14:39 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2022-08-31 18:52:54 +02:00
										 |  |  |     Base::visit_edges(visitor); | 
					
						
							| 
									
										
										
										
											2023-11-19 16:18:00 +13:00
										 |  |  |     visitor.visit(m_window); | 
					
						
							| 
									
										
										
										
											2024-04-02 22:44:05 +02:00
										 |  |  |     visitor.visit(m_orientation); | 
					
						
							| 
									
										
										
										
											2021-04-04 00:14:39 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Gfx::IntRect Screen::screen_rect() const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2023-12-15 20:33:16 +01:00
										 |  |  |     auto screen_rect_in_css_pixels = window().page().web_exposed_screen_area(); | 
					
						
							| 
									
										
										
										
											2022-11-25 17:07:19 +00:00
										 |  |  |     return { | 
					
						
							| 
									
										
										
										
											2023-06-12 21:37:35 +03:00
										 |  |  |         screen_rect_in_css_pixels.x().to_int(), | 
					
						
							|  |  |  |         screen_rect_in_css_pixels.y().to_int(), | 
					
						
							|  |  |  |         screen_rect_in_css_pixels.width().to_int(), | 
					
						
							|  |  |  |         screen_rect_in_css_pixels.height().to_int() | 
					
						
							| 
									
										
										
										
											2022-11-25 17:07:19 +00:00
										 |  |  |     }; | 
					
						
							| 
									
										
										
										
											2021-04-04 00:14:39 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-02 22:44:05 +02:00
										 |  |  | JS::NonnullGCPtr<ScreenOrientation> Screen::orientation() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (!m_orientation) | 
					
						
							|  |  |  |         m_orientation = ScreenOrientation::create(realm()); | 
					
						
							|  |  |  |     return *m_orientation; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-05 18:15:43 +02:00
										 |  |  | // https://w3c.github.io/window-management/#dom-screen-isextended
 | 
					
						
							|  |  |  | bool Screen::is_extended() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     dbgln("FIXME: Unimplemented Screen::is_extended"); | 
					
						
							|  |  |  |     return false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // https://w3c.github.io/window-management/#dom-screen-onchange
 | 
					
						
							|  |  |  | void Screen::set_onchange(JS::GCPtr<WebIDL::CallbackType> event_handler) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     set_event_handler_attribute(HTML::EventNames::change, event_handler); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // https://w3c.github.io/window-management/#dom-screen-onchange
 | 
					
						
							|  |  |  | JS::GCPtr<WebIDL::CallbackType> Screen::onchange() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return event_handler_attribute(HTML::EventNames::change); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-04 00:14:39 +02:00
										 |  |  | } |