mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 11:22:45 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			35 lines
		
	
	
	
		
			990 B
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			35 lines
		
	
	
	
		
			990 B
		
	
	
	
		
			C++
		
	
	
	
	
	
| #include <AK/URL.h>
 | |
| #include <LibCore/CFile.h>
 | |
| #include <LibHTML/DOM/Document.h>
 | |
| #include <LibHTML/DOM/HTMLLinkElement.h>
 | |
| #include <LibHTML/Parser/CSSParser.h>
 | |
| #include <LibHTML/ResourceLoader.h>
 | |
| 
 | |
| HTMLLinkElement::HTMLLinkElement(Document& document, const String& tag_name)
 | |
|     : HTMLElement(document, tag_name)
 | |
| {
 | |
| }
 | |
| 
 | |
| HTMLLinkElement::~HTMLLinkElement()
 | |
| {
 | |
| }
 | |
| 
 | |
| void HTMLLinkElement::inserted_into(Node&)
 | |
| {
 | |
|     if (rel() == "stylesheet") {
 | |
|         URL url = document().complete_url(href());
 | |
|         ResourceLoader::the().load(url, [&](auto data) {
 | |
|             if (data.is_null()) {
 | |
|                 dbg() << "HTMLLinkElement: Failed to load stylesheet: " << href();
 | |
|                 return;
 | |
|             }
 | |
|             auto sheet = parse_css(data);
 | |
|             if (!sheet) {
 | |
|                 dbg() << "HTMLLinkElement: Failed to parse stylesheet: " << href();
 | |
|                 return;
 | |
|             }
 | |
|             document().add_sheet(*sheet);
 | |
|             document().update_style();
 | |
|         });
 | |
|     }
 | |
| }
 | 
