2019-10-07 19:06:47 +02:00
|
|
|
#include <AK/URL.h>
|
|
|
|
#include <LibCore/CFile.h>
|
|
|
|
#include <LibHTML/DOM/Document.h>
|
|
|
|
#include <LibHTML/DOM/HTMLLinkElement.h>
|
|
|
|
#include <LibHTML/Parser/CSSParser.h>
|
2019-10-09 07:37:25 +02:00
|
|
|
#include <LibHTML/ResourceLoader.h>
|
2019-10-07 19:06:47 +02:00
|
|
|
|
|
|
|
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());
|
2019-10-09 07:37:25 +02:00
|
|
|
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);
|
2019-10-13 12:49:43 +02:00
|
|
|
document().invalidate_style();
|
2019-10-09 07:37:25 +02:00
|
|
|
});
|
2019-10-07 19:06:47 +02:00
|
|
|
}
|
|
|
|
}
|