mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 17:52:45 +00:00 
			
		
		
		
	LibWeb: Implement details_notification_task_steps for <details>
				
					
				
			This commit is contained in:
		
							parent
							
								
									8773122f6b
								
							
						
					
					
						commit
						fd360ba171
					
				
					 3 changed files with 44 additions and 2 deletions
				
			
		|  | @ -89,11 +89,11 @@ public: | ||||||
|     bool has_attributes() const; |     bool has_attributes() const; | ||||||
|     DeprecatedString attribute(DeprecatedFlyString const& name) const { return get_attribute(name); } |     DeprecatedString attribute(DeprecatedFlyString const& name) const { return get_attribute(name); } | ||||||
|     DeprecatedString get_attribute(DeprecatedFlyString const& name) const; |     DeprecatedString get_attribute(DeprecatedFlyString const& name) const; | ||||||
|     WebIDL::ExceptionOr<void> set_attribute(DeprecatedFlyString const& name, DeprecatedString const& value); |     virtual WebIDL::ExceptionOr<void> set_attribute(DeprecatedFlyString const& name, DeprecatedString const& value); | ||||||
|     WebIDL::ExceptionOr<void> set_attribute_ns(DeprecatedFlyString const& namespace_, DeprecatedFlyString const& qualified_name, DeprecatedString const& value); |     WebIDL::ExceptionOr<void> set_attribute_ns(DeprecatedFlyString const& namespace_, DeprecatedFlyString const& qualified_name, DeprecatedString const& value); | ||||||
|     WebIDL::ExceptionOr<JS::GCPtr<Attr>> set_attribute_node(Attr&); |     WebIDL::ExceptionOr<JS::GCPtr<Attr>> set_attribute_node(Attr&); | ||||||
|     WebIDL::ExceptionOr<JS::GCPtr<Attr>> set_attribute_node_ns(Attr&); |     WebIDL::ExceptionOr<JS::GCPtr<Attr>> set_attribute_node_ns(Attr&); | ||||||
|     void remove_attribute(DeprecatedFlyString const& name); |     virtual void remove_attribute(DeprecatedFlyString const& name); | ||||||
|     WebIDL::ExceptionOr<bool> toggle_attribute(DeprecatedFlyString const& name, Optional<bool> force); |     WebIDL::ExceptionOr<bool> toggle_attribute(DeprecatedFlyString const& name, Optional<bool> force); | ||||||
|     size_t attribute_list_size() const; |     size_t attribute_list_size() const; | ||||||
|     NamedNodeMap const* attributes() const { return m_attributes.ptr(); } |     NamedNodeMap const* attributes() const { return m_attributes.ptr(); } | ||||||
|  |  | ||||||
|  | @ -5,7 +5,9 @@ | ||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| #include <LibWeb/Bindings/Intrinsics.h> | #include <LibWeb/Bindings/Intrinsics.h> | ||||||
|  | #include <LibWeb/DOM/Event.h> | ||||||
| #include <LibWeb/HTML/HTMLDetailsElement.h> | #include <LibWeb/HTML/HTMLDetailsElement.h> | ||||||
|  | #include <LibWeb/HTML/HTMLSummaryElement.h> | ||||||
| 
 | 
 | ||||||
| namespace Web::HTML { | namespace Web::HTML { | ||||||
| 
 | 
 | ||||||
|  | @ -16,6 +18,40 @@ HTMLDetailsElement::HTMLDetailsElement(DOM::Document& document, DOM::QualifiedNa | ||||||
| 
 | 
 | ||||||
| HTMLDetailsElement::~HTMLDetailsElement() = default; | HTMLDetailsElement::~HTMLDetailsElement() = default; | ||||||
| 
 | 
 | ||||||
|  | WebIDL::ExceptionOr<void> HTMLDetailsElement::set_attribute(DeprecatedFlyString const& name, DeprecatedString const& value) | ||||||
|  | { | ||||||
|  |     auto result = HTMLElement::set_attribute(name, value); | ||||||
|  |     if (result.is_exception()) | ||||||
|  |         return result.exception(); | ||||||
|  | 
 | ||||||
|  |     if (name == HTML::AttributeNames::open) | ||||||
|  |         run_details_notification_task_steps(); | ||||||
|  | 
 | ||||||
|  |     return result; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void HTMLDetailsElement::remove_attribute(DeprecatedFlyString const& name) | ||||||
|  | { | ||||||
|  |     HTMLElement::remove_attribute(name); | ||||||
|  | 
 | ||||||
|  |     if (name == HTML::AttributeNames::open) | ||||||
|  |         run_details_notification_task_steps(); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | // https://html.spec.whatwg.org/multipage/interactive-elements.html#the-details-element:details-notification-task-steps
 | ||||||
|  | void HTMLDetailsElement::run_details_notification_task_steps() | ||||||
|  | { | ||||||
|  |     // Whenever the open attribute is added to or removed from a details element,
 | ||||||
|  |     // the user agent must queue an element task on the DOM manipulation task source given then details element that runs the following steps,
 | ||||||
|  |     // which are known as the details notification task steps, for this details element:
 | ||||||
|  |     queue_an_element_task(HTML::Task::Source::DOMManipulation, [this] { | ||||||
|  |         // 1. FIXME: If another task has been queued to run the details notification task steps for this details element, then return.
 | ||||||
|  | 
 | ||||||
|  |         // 2. Fire an event named toggle at the details element.
 | ||||||
|  |         dispatch_event(Web::DOM::Event::create(realm(), HTML::EventNames::toggle).release_value_but_fixme_should_propagate_errors()); | ||||||
|  |     }); | ||||||
|  | } | ||||||
|  | 
 | ||||||
| JS::ThrowCompletionOr<void> HTMLDetailsElement::initialize(JS::Realm& realm) | JS::ThrowCompletionOr<void> HTMLDetailsElement::initialize(JS::Realm& realm) | ||||||
| { | { | ||||||
|     MUST_OR_THROW_OOM(Base::initialize(realm)); |     MUST_OR_THROW_OOM(Base::initialize(realm)); | ||||||
|  |  | ||||||
|  | @ -20,6 +20,12 @@ public: | ||||||
|     // https://www.w3.org/TR/html-aria/#el-details
 |     // https://www.w3.org/TR/html-aria/#el-details
 | ||||||
|     virtual Optional<ARIA::Role> default_role() const override { return ARIA::Role::group; }; |     virtual Optional<ARIA::Role> default_role() const override { return ARIA::Role::group; }; | ||||||
| 
 | 
 | ||||||
|  |     // ^Element
 | ||||||
|  |     WebIDL::ExceptionOr<void> set_attribute(DeprecatedFlyString const& name, DeprecatedString const& value) override; | ||||||
|  |     void remove_attribute(DeprecatedFlyString const& name) override; | ||||||
|  | 
 | ||||||
|  |     void run_details_notification_task_steps(); | ||||||
|  | 
 | ||||||
| private: | private: | ||||||
|     HTMLDetailsElement(DOM::Document&, DOM::QualifiedName); |     HTMLDetailsElement(DOM::Document&, DOM::QualifiedName); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 stelar7
						stelar7