mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 21:28:14 +00:00
LibWeb: Generalize ImageBox and ImagePaintable for any ImageProvider
They currently assume the DOM node is an HTMLImageElement with respect to handling the alt attribute. The HTMLInputElement will require the same behavior.
This commit is contained in:
parent
c4295edc81
commit
45a47cb32b
10 changed files with 45 additions and 8 deletions
|
@ -8,6 +8,7 @@
|
|||
#include <LibWeb/HTML/DecodedImageData.h>
|
||||
#include <LibWeb/HTML/ImageRequest.h>
|
||||
#include <LibWeb/Layout/ImageBox.h>
|
||||
#include <LibWeb/Layout/ImageProvider.h>
|
||||
#include <LibWeb/Painting/ImagePaintable.h>
|
||||
#include <LibWeb/Platform/FontPlugin.h>
|
||||
|
||||
|
@ -28,9 +29,9 @@ void ImageBox::prepare_for_replaced_layout()
|
|||
set_natural_aspect_ratio(m_image_provider.intrinsic_aspect_ratio());
|
||||
|
||||
if (renders_as_alt_text()) {
|
||||
auto& image_element = verify_cast<HTML::HTMLImageElement>(dom_node());
|
||||
auto const& element = verify_cast<HTML::HTMLElement>(dom_node());
|
||||
auto& font = Platform::FontPlugin::the().default_font();
|
||||
auto alt = image_element.alt();
|
||||
auto alt = element.get_attribute_value(HTML::AttributeNames::alt);
|
||||
|
||||
CSSPixels alt_text_width = 0;
|
||||
if (!m_cached_alt_text_width.has_value())
|
||||
|
@ -46,15 +47,15 @@ void ImageBox::prepare_for_replaced_layout()
|
|||
}
|
||||
}
|
||||
|
||||
void ImageBox::dom_node_did_update_alt_text(Badge<HTML::HTMLImageElement>)
|
||||
void ImageBox::dom_node_did_update_alt_text(Badge<ImageProvider>)
|
||||
{
|
||||
m_cached_alt_text_width = {};
|
||||
}
|
||||
|
||||
bool ImageBox::renders_as_alt_text() const
|
||||
{
|
||||
if (is<HTML::HTMLImageElement>(dom_node()))
|
||||
return !static_cast<HTML::HTMLImageElement const&>(dom_node()).current_request().is_available();
|
||||
if (auto const* image_provider = dynamic_cast<ImageProvider const*>(&dom_node()))
|
||||
return !image_provider->is_image_available();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue