mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 04:22:45 +00:00 
			
		
		
		
	 c718ba5947
			
		
	
	
		c718ba5947
		
	
	
	
	
		
			
			Both of these are supposed to be set when the CSSRule is created. The spec is silent on setting it when a CSSRule is added to a parent. So, this is a bit ad-hoc. The parent rule gets set whenever a rule is added to a new parent. The parent stylesheet gets set whenever the rule or one of its ancestors is added to a different stylesheet. There may be some nuance there that I'm missing, but I'm sure we'll find out quickly once we have WPT running!
		
			
				
	
	
		
			58 lines
		
	
	
	
		
			1.3 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			58 lines
		
	
	
	
		
			1.3 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
| /*
 | |
|  * Copyright (c) 2021, the SerenityOS developers.
 | |
|  *
 | |
|  * SPDX-License-Identifier: BSD-2-Clause
 | |
|  */
 | |
| 
 | |
| #pragma once
 | |
| 
 | |
| #include <AK/RefCounted.h>
 | |
| #include <AK/String.h>
 | |
| #include <AK/Weakable.h>
 | |
| #include <LibWeb/Bindings/Wrappable.h>
 | |
| #include <LibWeb/CSS/CSSStyleDeclaration.h>
 | |
| #include <LibWeb/CSS/Selector.h>
 | |
| 
 | |
| namespace Web::CSS {
 | |
| 
 | |
| class CSSRule
 | |
|     : public RefCounted<CSSRule>
 | |
|     , public Bindings::Wrappable
 | |
|     , public Weakable<CSSRule> {
 | |
| public:
 | |
|     using WrapperType = Bindings::CSSRuleWrapper;
 | |
| 
 | |
|     virtual ~CSSRule() = default;
 | |
| 
 | |
|     // https://drafts.csswg.org/cssom/#dom-cssrule-type
 | |
|     enum class Type : u16 {
 | |
|         Style = 1,
 | |
|         Import = 3,
 | |
|         Media = 4,
 | |
|         FontFace = 5,
 | |
|         Supports = 12,
 | |
|     };
 | |
| 
 | |
|     virtual StringView class_name() const = 0;
 | |
|     virtual Type type() const = 0;
 | |
| 
 | |
|     String css_text() const;
 | |
|     void set_css_text(StringView);
 | |
| 
 | |
|     CSSRule* parent_rule() { return m_parent_rule; }
 | |
|     void set_parent_rule(CSSRule*);
 | |
| 
 | |
|     CSSStyleSheet* parent_style_sheet() { return m_parent_style_sheet; }
 | |
|     virtual void set_parent_style_sheet(CSSStyleSheet*);
 | |
| 
 | |
|     template<typename T>
 | |
|     bool fast_is() const = delete;
 | |
| 
 | |
| protected:
 | |
|     virtual String serialized() const = 0;
 | |
| 
 | |
|     WeakPtr<CSSRule> m_parent_rule;
 | |
|     WeakPtr<CSSStyleSheet> m_parent_style_sheet;
 | |
| };
 | |
| 
 | |
| }
 |