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