| 
									
										
										
										
											2020-11-21 18:32:39 +00:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Copyright (c) 2020, the SerenityOS developers. | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2021-04-22 01:24:48 -07:00
										 |  |  |  * SPDX-License-Identifier: BSD-2-Clause | 
					
						
							| 
									
										
										
										
											2020-11-21 18:32:39 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <AK/Assertions.h>
 | 
					
						
							|  |  |  | #include <AK/TypeCasts.h>
 | 
					
						
							|  |  |  | #include <LibWeb/DOM/Event.h>
 | 
					
						
							|  |  |  | #include <LibWeb/DOM/Node.h>
 | 
					
						
							|  |  |  | #include <LibWeb/DOM/ShadowRoot.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace Web::DOM { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void Event::append_to_path(EventTarget& invocation_target, RefPtr<EventTarget> shadow_adjusted_target, RefPtr<EventTarget> related_target, TouchTargetList& touch_targets, bool slot_in_closed_tree) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     bool invocation_target_in_shadow_tree = false; | 
					
						
							|  |  |  |     bool root_of_closed_tree = false; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (is<Node>(invocation_target)) { | 
					
						
							|  |  |  |         auto& invocation_target_node = downcast<Node>(invocation_target); | 
					
						
							| 
									
										
										
										
											2021-01-01 18:12:33 +01:00
										 |  |  |         if (is<ShadowRoot>(invocation_target_node.root())) | 
					
						
							| 
									
										
										
										
											2020-11-21 18:32:39 +00:00
										 |  |  |             invocation_target_in_shadow_tree = true; | 
					
						
							|  |  |  |         if (is<ShadowRoot>(invocation_target_node)) { | 
					
						
							|  |  |  |             auto& invocation_target_shadow_root = downcast<ShadowRoot>(invocation_target_node); | 
					
						
							|  |  |  |             root_of_closed_tree = invocation_target_shadow_root.closed(); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     m_path.append({ invocation_target, invocation_target_in_shadow_tree, shadow_adjusted_target, related_target, touch_targets, root_of_closed_tree, slot_in_closed_tree, m_path.size() }); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void Event::set_cancelled_flag() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (m_cancelable && !m_in_passive_listener) | 
					
						
							|  |  |  |         m_cancelled = true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-10 20:11:04 +01:00
										 |  |  | // https://dom.spec.whatwg.org/#concept-event-initialize
 | 
					
						
							|  |  |  | void Event::initialize(const String& type, bool bubbles, bool cancelable) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     m_initialized = true; | 
					
						
							|  |  |  |     m_stop_propagation = false; | 
					
						
							|  |  |  |     m_stop_immediate_propagation = false; | 
					
						
							|  |  |  |     m_cancelled = false; | 
					
						
							|  |  |  |     m_is_trusted = false; | 
					
						
							|  |  |  |     m_target = nullptr; | 
					
						
							|  |  |  |     m_type = type; | 
					
						
							|  |  |  |     m_bubbles = bubbles; | 
					
						
							|  |  |  |     m_cancelable = cancelable; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // https://dom.spec.whatwg.org/#dom-event-initevent
 | 
					
						
							|  |  |  | void Event::init_event(const String& type, bool bubbles, bool cancelable) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (m_dispatch) | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     initialize(type, bubbles, cancelable); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-21 18:32:39 +00:00
										 |  |  | } |