| 
									
										
										
										
											2020-01-18 09:38:21 +01:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2024-10-04 13:19:50 +02:00
										 |  |  |  * Copyright (c) 2018-2021, Andreas Kling <andreas@ladybird.org> | 
					
						
							| 
									
										
										
										
											2021-02-21 18:44:17 +02:00
										 |  |  |  * Copyright (c) 2021, the SerenityOS developers. | 
					
						
							| 
									
										
										
										
											2024-06-22 11:12:44 +01:00
										 |  |  |  * Copyright (c) 2024, Jamie Mansfield <jmansfield@cadixdev.org> | 
					
						
							| 
									
										
										
										
											2020-01-18 09:38:21 +01:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2021-04-22 01:24:48 -07:00
										 |  |  |  * SPDX-License-Identifier: BSD-2-Clause | 
					
						
							| 
									
										
										
										
											2020-01-18 09:38:21 +01:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-27 12:09:58 +12:00
										 |  |  | #include <LibWeb/Bindings/HTMLStyleElementPrototype.h>
 | 
					
						
							| 
									
										
										
										
											2020-07-28 19:20:11 +02:00
										 |  |  | #include <LibWeb/HTML/HTMLStyleElement.h>
 | 
					
						
							| 
									
										
										
										
											2019-09-29 17:43:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-28 18:20:36 +02:00
										 |  |  | namespace Web::HTML { | 
					
						
							| 
									
										
										
										
											2020-03-07 10:27:02 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-15 04:01:23 +13:00
										 |  |  | GC_DEFINE_ALLOCATOR(HTMLStyleElement); | 
					
						
							| 
									
										
										
										
											2023-11-19 19:47:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-18 21:00:52 +01:00
										 |  |  | HTMLStyleElement::HTMLStyleElement(DOM::Document& document, DOM::QualifiedName qualified_name) | 
					
						
							| 
									
										
										
										
											2021-02-07 11:20:15 +01:00
										 |  |  |     : HTMLElement(document, move(qualified_name)) | 
					
						
							| 
									
										
										
										
											2019-09-29 17:43:30 +02:00
										 |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-14 13:21:51 -06:00
										 |  |  | HTMLStyleElement::~HTMLStyleElement() = default; | 
					
						
							| 
									
										
										
										
											2019-09-29 17:43:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-07 08:41:28 +02:00
										 |  |  | void HTMLStyleElement::initialize(JS::Realm& realm) | 
					
						
							| 
									
										
										
										
											2023-01-10 06:28:20 -05:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2023-08-07 08:41:28 +02:00
										 |  |  |     Base::initialize(realm); | 
					
						
							| 
									
										
										
										
											2024-03-16 13:13:08 +01:00
										 |  |  |     WEB_SET_PROTOTYPE_FOR_INTERFACE(HTMLStyleElement); | 
					
						
							| 
									
										
										
										
											2023-01-10 06:28:20 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-28 13:42:07 +02:00
										 |  |  | void HTMLStyleElement::visit_edges(Cell::Visitor& visitor) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     Base::visit_edges(visitor); | 
					
						
							| 
									
										
										
										
											2024-09-21 07:47:37 +02:00
										 |  |  |     m_style_element_utils.visit_edges(visitor); | 
					
						
							| 
									
										
										
										
											2022-08-28 13:42:07 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-03 23:06:09 +02:00
										 |  |  | void HTMLStyleElement::children_changed() | 
					
						
							| 
									
										
										
										
											2019-09-29 17:43:30 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2023-06-08 16:07:12 +01:00
										 |  |  |     m_style_element_utils.update_a_style_block(*this); | 
					
						
							|  |  |  |     Base::children_changed(); | 
					
						
							| 
									
										
										
										
											2019-09-29 17:43:30 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-25 22:05:42 +01:00
										 |  |  | void HTMLStyleElement::inserted() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2023-06-08 16:07:12 +01:00
										 |  |  |     m_style_element_utils.update_a_style_block(*this); | 
					
						
							|  |  |  |     Base::inserted(); | 
					
						
							| 
									
										
										
										
											2022-02-25 22:05:42 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-06 17:58:20 +01:00
										 |  |  | void HTMLStyleElement::removed_from(Node* old_parent) | 
					
						
							| 
									
										
										
										
											2019-09-29 17:43:30 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-09-21 08:11:49 +02:00
										 |  |  |     m_style_element_utils.update_a_style_block(*this); | 
					
						
							| 
									
										
										
										
											2023-06-08 16:07:12 +01:00
										 |  |  |     Base::removed_from(old_parent); | 
					
						
							| 
									
										
										
										
											2022-08-07 13:14:54 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-22 11:12:44 +01:00
										 |  |  | // https://html.spec.whatwg.org/multipage/semantics.html#dom-style-disabled
 | 
					
						
							|  |  |  | bool HTMLStyleElement::disabled() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     // 1. If this does not have an associated CSS style sheet, return false.
 | 
					
						
							|  |  |  |     if (!sheet()) | 
					
						
							|  |  |  |         return false; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // 2. If this's associated CSS style sheet's disabled flag is set, return true.
 | 
					
						
							|  |  |  |     if (sheet()->disabled()) | 
					
						
							|  |  |  |         return true; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // 3. Return false.
 | 
					
						
							|  |  |  |     return false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // https://html.spec.whatwg.org/multipage/semantics.html#dom-style-disabled
 | 
					
						
							|  |  |  | void HTMLStyleElement::set_disabled(bool disabled) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     // 1. If this does not have an associated CSS style sheet, return.
 | 
					
						
							|  |  |  |     if (!sheet()) | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // 2. If the given value is true, set this's associated CSS style sheet's disabled flag.
 | 
					
						
							|  |  |  |     //    Otherwise, unset this's associated CSS style sheet's disabled flag.
 | 
					
						
							|  |  |  |     sheet()->set_disabled(disabled); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-07 13:14:54 +02:00
										 |  |  | // https://www.w3.org/TR/cssom/#dom-linkstyle-sheet
 | 
					
						
							|  |  |  | CSS::CSSStyleSheet* HTMLStyleElement::sheet() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     // The sheet attribute must return the associated CSS style sheet for the node or null if there is no associated CSS style sheet.
 | 
					
						
							| 
									
										
										
										
											2023-06-08 16:07:12 +01:00
										 |  |  |     return m_style_element_utils.sheet(); | 
					
						
							| 
									
										
										
										
											2021-09-29 23:46:16 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-15 19:38:39 +01:00
										 |  |  | // https://www.w3.org/TR/cssom/#dom-linkstyle-sheet
 | 
					
						
							| 
									
										
										
										
											2022-08-07 13:14:54 +02:00
										 |  |  | CSS::CSSStyleSheet const* HTMLStyleElement::sheet() const | 
					
						
							| 
									
										
										
										
											2021-10-01 00:13:56 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     // The sheet attribute must return the associated CSS style sheet for the node or null if there is no associated CSS style sheet.
 | 
					
						
							| 
									
										
										
										
											2023-06-08 16:07:12 +01:00
										 |  |  |     return m_style_element_utils.sheet(); | 
					
						
							| 
									
										
										
										
											2021-10-01 00:13:56 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-07 10:27:02 +01:00
										 |  |  | } |