2020-06-13 22:24:49 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-06-13 22:24:49 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <LibGfx/Bitmap.h>
|
2021-09-24 13:49:57 +02:00
|
|
|
#include <LibWeb/CSS/StyleComputer.h>
|
2020-06-13 22:24:49 +02:00
|
|
|
#include <LibWeb/DOM/Document.h>
|
|
|
|
#include <LibWeb/DOM/Event.h>
|
2020-07-26 15:08:16 +02:00
|
|
|
#include <LibWeb/HTML/HTMLObjectElement.h>
|
2020-11-22 15:53:01 +01:00
|
|
|
#include <LibWeb/Layout/ImageBox.h>
|
2020-06-13 22:24:49 +02:00
|
|
|
#include <LibWeb/Loader/ResourceLoader.h>
|
|
|
|
|
2020-07-28 18:20:36 +02:00
|
|
|
namespace Web::HTML {
|
2020-06-13 22:24:49 +02:00
|
|
|
|
2022-02-18 21:00:52 +01:00
|
|
|
HTMLObjectElement::HTMLObjectElement(DOM::Document& document, DOM::QualifiedName qualified_name)
|
2021-10-14 16:18:49 +01:00
|
|
|
: FormAssociatedElement(document, move(qualified_name))
|
2021-04-14 10:39:12 -04:00
|
|
|
, m_image_loader(*this)
|
2020-06-13 22:24:49 +02:00
|
|
|
{
|
|
|
|
m_image_loader.on_load = [this] {
|
|
|
|
m_should_show_fallback_content = false;
|
2021-10-18 10:37:44 +02:00
|
|
|
set_needs_style_update(true);
|
2022-03-16 23:12:18 +01:00
|
|
|
this->document().set_needs_layout();
|
2022-03-16 00:11:39 +00:00
|
|
|
// FIXME: This should be done by the HTML^Wdocument parser.
|
|
|
|
dispatch_event(DOM::Event::create(HTML::EventNames::load));
|
2020-06-13 22:24:49 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
m_image_loader.on_fail = [this] {
|
|
|
|
m_should_show_fallback_content = true;
|
2021-10-18 10:37:44 +02:00
|
|
|
set_needs_style_update(true);
|
2022-03-16 23:12:18 +01:00
|
|
|
this->document().set_needs_layout();
|
2022-03-16 00:11:39 +00:00
|
|
|
// FIXME: This should be done by the HTML^Wdocument parser.
|
|
|
|
dispatch_event(DOM::Event::create(HTML::EventNames::load));
|
2020-06-13 22:24:49 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
HTMLObjectElement::~HTMLObjectElement()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void HTMLObjectElement::parse_attribute(const FlyString& name, const String& value)
|
|
|
|
{
|
|
|
|
HTMLElement::parse_attribute(name, value);
|
|
|
|
|
|
|
|
if (name == HTML::AttributeNames::data)
|
2021-09-09 18:08:56 +02:00
|
|
|
m_image_loader.load(document().parse_url(value));
|
2020-06-13 22:24:49 +02:00
|
|
|
}
|
|
|
|
|
2022-02-05 13:17:01 +01:00
|
|
|
RefPtr<Layout::Node> HTMLObjectElement::create_layout_node(NonnullRefPtr<CSS::StyleProperties> style)
|
2020-06-13 22:24:49 +02:00
|
|
|
{
|
|
|
|
if (m_should_show_fallback_content)
|
2022-02-05 13:17:01 +01:00
|
|
|
return HTMLElement::create_layout_node(move(style));
|
2020-06-23 13:42:38 +02:00
|
|
|
if (m_image_loader.has_image())
|
2021-04-23 16:46:57 +02:00
|
|
|
return adopt_ref(*new Layout::ImageBox(document(), *this, move(style), m_image_loader));
|
2020-06-13 22:24:49 +02:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|