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
|
|
|
|
2021-02-07 11:20:15 +01:00
|
|
|
HTMLObjectElement::HTMLObjectElement(DOM::Document& document, QualifiedName qualified_name)
|
|
|
|
: HTMLElement(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;
|
|
|
|
this->document().force_layout();
|
|
|
|
};
|
|
|
|
|
|
|
|
m_image_loader.on_fail = [this] {
|
|
|
|
m_should_show_fallback_content = true;
|
|
|
|
this->document().force_layout();
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2021-01-06 14:27:40 +01:00
|
|
|
RefPtr<Layout::Node> HTMLObjectElement::create_layout_node()
|
2020-06-13 22:24:49 +02:00
|
|
|
{
|
|
|
|
if (m_should_show_fallback_content)
|
2021-01-06 14:27:40 +01:00
|
|
|
return HTMLElement::create_layout_node();
|
2020-06-13 22:24:49 +02:00
|
|
|
|
2021-09-24 13:49:57 +02:00
|
|
|
auto style = document().style_computer().compute_style(*this);
|
2021-10-06 17:57:44 +02:00
|
|
|
if (style->display().is_none())
|
2020-06-13 22:24:49 +02:00
|
|
|
return nullptr;
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|