| 
									
										
										
										
											2023-07-21 11:59:49 +02:00
										 |  |  |  | /*
 | 
					
						
							|  |  |  |  |  * Copyright (c) 2023, Andreas Kling <kling@serenityos.org> | 
					
						
							|  |  |  |  |  * | 
					
						
							|  |  |  |  |  * SPDX-License-Identifier: BSD-2-Clause | 
					
						
							|  |  |  |  |  */ | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | #include <LibJS/Runtime/VM.h>
 | 
					
						
							|  |  |  |  | #include <LibWeb/Bindings/InternalsPrototype.h>
 | 
					
						
							|  |  |  |  | #include <LibWeb/Bindings/Intrinsics.h>
 | 
					
						
							| 
									
										
										
										
											2023-08-08 22:44:52 +02:00
										 |  |  |  | #include <LibWeb/DOM/Document.h>
 | 
					
						
							|  |  |  |  | #include <LibWeb/HTML/BrowsingContext.h>
 | 
					
						
							|  |  |  |  | #include <LibWeb/HTML/Window.h>
 | 
					
						
							| 
									
										
										
										
											2023-07-21 11:59:49 +02:00
										 |  |  |  | #include <LibWeb/Internals/Internals.h>
 | 
					
						
							| 
									
										
										
										
											2023-09-19 19:16:50 +02:00
										 |  |  |  | #include <LibWeb/Page/Page.h>
 | 
					
						
							| 
									
										
										
										
											2023-08-08 22:44:52 +02:00
										 |  |  |  | #include <LibWeb/Painting/PaintableBox.h>
 | 
					
						
							| 
									
										
										
										
											2023-07-21 11:59:49 +02:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | namespace Web::Internals { | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | Internals::Internals(JS::Realm& realm) | 
					
						
							|  |  |  |  |     : Bindings::PlatformObject(realm) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | Internals::~Internals() = default; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-07 08:41:28 +02:00
										 |  |  |  | void Internals::initialize(JS::Realm& realm) | 
					
						
							| 
									
										
										
										
											2023-07-21 11:59:49 +02:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2023-08-07 08:41:28 +02:00
										 |  |  |  |     Base::initialize(realm); | 
					
						
							| 
									
										
										
										
											2023-07-21 11:59:49 +02:00
										 |  |  |  |     Object::set_prototype(&Bindings::ensure_web_prototype<Bindings::InternalsPrototype>(realm, "Internals")); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-14 19:17:32 +02:00
										 |  |  |  | void Internals::signal_text_test_is_done() | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |     if (auto* page = global_object().browsing_context()->page()) { | 
					
						
							|  |  |  |  |         page->client().page_did_finish_text_test(); | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-21 11:59:49 +02:00
										 |  |  |  | void Internals::gc() | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |     vm().heap().collect_garbage(); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-08 22:44:52 +02:00
										 |  |  |  | JS::Object* Internals::hit_test(double x, double y) | 
					
						
							|  |  |  |  | { | 
					
						
							| 
									
										
										
										
											2023-09-04 15:33:08 +02:00
										 |  |  |  |     auto* active_document = global_object().browsing_context()->top_level_browsing_context()->active_document(); | 
					
						
							| 
									
										
										
										
											2023-08-08 22:44:52 +02:00
										 |  |  |  |     // NOTE: Force a layout update just before hit testing. This is because the current layout tree, which is required
 | 
					
						
							|  |  |  |  |     //       for stacking context traversal, might not exist if this call occurs between the tear_down_layout_tree()
 | 
					
						
							|  |  |  |  |     //       and update_layout() calls
 | 
					
						
							|  |  |  |  |     active_document->update_layout(); | 
					
						
							|  |  |  |  |     auto result = active_document->paintable_box()->hit_test({ x, y }, Painting::HitTestType::Exact); | 
					
						
							|  |  |  |  |     if (result.has_value()) { | 
					
						
							|  |  |  |  |         auto hit_tеsting_result = JS::Object::create(realm(), nullptr); | 
					
						
							|  |  |  |  |         hit_tеsting_result->define_direct_property("node", result->dom_node(), JS::default_attributes); | 
					
						
							|  |  |  |  |         hit_tеsting_result->define_direct_property("indexInNode", JS::Value(result->index_in_node), JS::default_attributes); | 
					
						
							|  |  |  |  |         return hit_tеsting_result; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |     return nullptr; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-21 11:59:49 +02:00
										 |  |  |  | } |