
When style is invalidated (for example when an external stylesheet finishes loading) we delete the whole layout tree and build a new one. This is necessary since the new style information may result in a different layout tree. When layout is invalidated (window resized, image dimensions learned, etc..) we keep the existing layout tree but run the layout algorithm once again. There's obviously lots of room for improvement here. :^)
35 lines
994 B
C++
35 lines
994 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().invalidate_style();
|
|
});
|
|
}
|
|
}
|