mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 19:22:45 +00:00 
			
		
		
		
	 b98a2be96b
			
		
	
	
		b98a2be96b
		
	
	
	
	
		
			
			Normally, assigning to e.g document.body.onload will forward to window.onload. However, in a detached DOM tree, there is no associated window, so we have nowhere to forward to, making this a no-op. The bulk of this change is making Document::window() return a nullable pointer, as documents created by DOMParser or DOMImplementation do not have an associated window object, and so must be able to return null from here.
		
			
				
	
	
		
			68 lines
		
	
	
	
		
			3.1 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			68 lines
		
	
	
	
		
			3.1 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
| /*
 | ||
|  * Copyright (c) 2024, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
 | ||
|  *
 | ||
|  * SPDX-License-Identifier: BSD-2-Clause
 | ||
|  */
 | ||
| 
 | ||
| #include <LibJS/Heap/Heap.h>
 | ||
| #include <LibWeb/Bindings/ResizeObserverSizePrototype.h>
 | ||
| #include <LibWeb/HTML/Window.h>
 | ||
| #include <LibWeb/Painting/PaintableBox.h>
 | ||
| #include <LibWeb/ResizeObserver/ResizeObserverSize.h>
 | ||
| 
 | ||
| namespace Web::ResizeObserver {
 | ||
| 
 | ||
| JS_DEFINE_ALLOCATOR(ResizeObserverSize);
 | ||
| 
 | ||
| void ResizeObserverSize::initialize(JS::Realm& realm)
 | ||
| {
 | ||
|     Base::initialize(realm);
 | ||
|     set_prototype(&Bindings::ensure_web_prototype<Bindings::ResizeObserverSizePrototype>(realm, "ResizeObserverSize"_fly_string));
 | ||
| }
 | ||
| 
 | ||
| // https://drafts.csswg.org/resize-observer-1/#calculate-box-size
 | ||
| JS::NonnullGCPtr<ResizeObserverSize> ResizeObserverSize::calculate_box_size(JS::Realm& realm, DOM::Element& target, Bindings::ResizeObserverBoxOptions observed_box)
 | ||
| {
 | ||
|     // 1. Let computedSize be a new ResizeObserverSize object.
 | ||
|     auto computed_size = realm.heap().allocate<ResizeObserverSize>(realm, realm);
 | ||
| 
 | ||
|     // FIXME: 2. If target is an SVGGraphicsElement that does not have an associated CSS layout box:
 | ||
|     // Otherwise:
 | ||
|     if (target.paintable_box()) {
 | ||
|         auto const& paintable_box = *target.paintable_box();
 | ||
|         switch (observed_box) {
 | ||
|         case Bindings::ResizeObserverBoxOptions::BorderBox:
 | ||
|             // 1. Set computedSize’s inlineSize attribute to target’s border area inline length.
 | ||
|             computed_size->set_inline_size(paintable_box.border_box_width().to_double());
 | ||
|             // 2. Set computedSize’s blockSize attribute to target’s border area block length.
 | ||
|             computed_size->set_block_size(paintable_box.border_box_height().to_double());
 | ||
|             break;
 | ||
|         case Bindings::ResizeObserverBoxOptions::ContentBox:
 | ||
|             // 1. Set computedSize’s inlineSize attribute to target’s content area inline length.
 | ||
|             computed_size->set_inline_size(paintable_box.content_width().to_double());
 | ||
|             // 2. Set computedSize’s blockSize attribute to target’s content area block length.
 | ||
|             computed_size->set_block_size(paintable_box.content_height().to_double());
 | ||
|             break;
 | ||
|         case Bindings::ResizeObserverBoxOptions::DevicePixelContentBox: {
 | ||
|             auto device_pixel_ratio = target.document().window()->device_pixel_ratio();
 | ||
|             // 1. Set computedSize’s inlineSize attribute to target’s content area inline length, in integral device pixels.
 | ||
|             computed_size->set_inline_size(paintable_box.border_box_width().to_double() * device_pixel_ratio);
 | ||
|             // 2. Set computedSize’s blockSize attribute to target’s content area block length, in integral device pixels.
 | ||
|             computed_size->set_block_size(paintable_box.border_box_height().to_double() * device_pixel_ratio);
 | ||
|             break;
 | ||
|         }
 | ||
|         default:
 | ||
|             VERIFY_NOT_REACHED();
 | ||
|         }
 | ||
|     }
 | ||
| 
 | ||
|     // 3. Return computedSize.s
 | ||
|     return computed_size;
 | ||
| }
 | ||
| 
 | ||
| bool ResizeObserverSize::equals(ResizeObserverSize const& other) const
 | ||
| {
 | ||
|     return m_inline_size == other.m_inline_size && m_block_size == other.m_block_size;
 | ||
| }
 | ||
| 
 | ||
| }
 |