mirror of
				https://github.com/LadybirdBrowser/ladybird.git
				synced 2025-10-29 20:30:58 +00:00 
			
		
		
		
	 6f433c8656
			
		
	
	
		6f433c8656
		
	
	
	
	
		
			
			This is a monster patch that turns all EventTargets into GC-allocated PlatformObjects. Their C++ wrapper classes are removed, and the LibJS garbage collector is now responsible for their lifetimes. There's a fair amount of hacks and band-aids in this patch, and we'll have a lot of cleanup to do after this.
		
			
				
	
	
		
			60 lines
		
	
	
	
		
			1.7 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			60 lines
		
	
	
	
		
			1.7 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
| /*
 | |
|  * Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org>
 | |
|  *
 | |
|  * SPDX-License-Identifier: BSD-2-Clause
 | |
|  */
 | |
| 
 | |
| #include <LibWeb/Bindings/CSSSupportsRulePrototype.h>
 | |
| #include <LibWeb/CSS/CSSSupportsRule.h>
 | |
| #include <LibWeb/CSS/Parser/Parser.h>
 | |
| #include <LibWeb/HTML/Window.h>
 | |
| 
 | |
| namespace Web::CSS {
 | |
| 
 | |
| CSSSupportsRule* CSSSupportsRule::create(HTML::Window& window_object, NonnullRefPtr<Supports>&& supports, CSSRuleList& rules)
 | |
| {
 | |
|     return window_object.heap().allocate<CSSSupportsRule>(window_object.realm(), window_object, move(supports), rules);
 | |
| }
 | |
| 
 | |
| CSSSupportsRule::CSSSupportsRule(HTML::Window& window_object, NonnullRefPtr<Supports>&& supports, CSSRuleList& rules)
 | |
|     : CSSConditionRule(window_object, rules)
 | |
|     , m_supports(move(supports))
 | |
| {
 | |
|     set_prototype(&window_object.ensure_web_prototype<Bindings::CSSSupportsRulePrototype>("CSSSupportsRule"));
 | |
| }
 | |
| 
 | |
| String CSSSupportsRule::condition_text() const
 | |
| {
 | |
|     return m_supports->to_string();
 | |
| }
 | |
| 
 | |
| void CSSSupportsRule::set_condition_text(String text)
 | |
| {
 | |
|     if (auto new_supports = parse_css_supports({}, text))
 | |
|         m_supports = new_supports.release_nonnull();
 | |
| }
 | |
| 
 | |
| // https://www.w3.org/TR/cssom-1/#serialize-a-css-rule
 | |
| String CSSSupportsRule::serialized() const
 | |
| {
 | |
|     // Note: The spec doesn't cover this yet, so I'm roughly following the spec for the @media rule.
 | |
|     // It should be pretty close!
 | |
| 
 | |
|     StringBuilder builder;
 | |
| 
 | |
|     builder.append("@supports "sv);
 | |
|     builder.append(condition_text());
 | |
|     builder.append(" {\n"sv);
 | |
|     for (size_t i = 0; i < css_rules().length(); i++) {
 | |
|         auto rule = css_rules().item(i);
 | |
|         if (i != 0)
 | |
|             builder.append("\n"sv);
 | |
|         builder.append("  "sv);
 | |
|         builder.append(rule->css_text());
 | |
|     }
 | |
|     builder.append("\n}"sv);
 | |
| 
 | |
|     return builder.to_string();
 | |
| }
 | |
| 
 | |
| }
 |