mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 12:32:43 +00:00 
			
		
		
		
	LibWeb: Implement IntersectionObserver "intersection roots" per spec
In particular, get the implicit root correctly for intersection observers that don't have an explicit root specified. This makes it possible to load the Terminal app on https://puter.com/
This commit is contained in:
		
							parent
							
								
									8586897928
								
							
						
					
					
						commit
						8addfc14af
					
				
					 3 changed files with 27 additions and 3 deletions
				
			
		|  | @ -0,0 +1 @@ | ||||||
|  |     PASS if we didn't crash! | ||||||
|  | @ -0,0 +1,17 @@ | ||||||
|  | <body> | ||||||
|  | <iframe></iframe> | ||||||
|  | <script src="../include.js"></script> | ||||||
|  | <script> | ||||||
|  |     asyncTest(done => { | ||||||
|  |         let iframe = document.querySelector("iframe"); | ||||||
|  |         iframe.src = | ||||||
|  |             "data:text/html," + | ||||||
|  |             encodeURI("<script>new IntersectionObserver(function() { }, { })<" + "/script>"); | ||||||
|  |         iframe.onload = function () { | ||||||
|  |             iframe.remove(); | ||||||
|  |             done(); | ||||||
|  |             println("PASS if we didn't crash!"); | ||||||
|  |         }; | ||||||
|  |     }); | ||||||
|  | </script> | ||||||
|  | </body> | ||||||
|  | @ -11,6 +11,7 @@ | ||||||
| #include <LibWeb/HTML/TraversableNavigable.h> | #include <LibWeb/HTML/TraversableNavigable.h> | ||||||
| #include <LibWeb/HTML/Window.h> | #include <LibWeb/HTML/Window.h> | ||||||
| #include <LibWeb/IntersectionObserver/IntersectionObserver.h> | #include <LibWeb/IntersectionObserver/IntersectionObserver.h> | ||||||
|  | #include <LibWeb/Page/Page.h> | ||||||
| 
 | 
 | ||||||
| namespace Web::IntersectionObserver { | namespace Web::IntersectionObserver { | ||||||
| 
 | 
 | ||||||
|  | @ -156,11 +157,16 @@ Variant<JS::Handle<DOM::Element>, JS::Handle<DOM::Document>, Empty> Intersection | ||||||
|     return m_root.value(); |     return m_root.value(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | // https://www.w3.org/TR/intersection-observer/#intersectionobserver-intersection-root
 | ||||||
| Variant<JS::Handle<DOM::Element>, JS::Handle<DOM::Document>> IntersectionObserver::intersection_root() const | Variant<JS::Handle<DOM::Element>, JS::Handle<DOM::Document>> IntersectionObserver::intersection_root() const | ||||||
| { | { | ||||||
|     if (!m_root.has_value()) |     // The intersection root for an IntersectionObserver is the value of its root attribute
 | ||||||
|         return JS::make_handle(global_object().navigable()->traversable_navigable()->active_document()); |     // if the attribute is non-null;
 | ||||||
|     return m_root.value(); |     if (m_root.has_value()) | ||||||
|  |         return m_root.value(); | ||||||
|  | 
 | ||||||
|  |     // otherwise, it is the top-level browsing context’s document node, referred to as the implicit root.
 | ||||||
|  |     return JS::make_handle(global_object().page().top_level_browsing_context().active_document()); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // https://www.w3.org/TR/intersection-observer/#intersectionobserver-root-intersection-rectangle
 | // https://www.w3.org/TR/intersection-observer/#intersectionobserver-root-intersection-rectangle
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Andreas Kling
						Andreas Kling