mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-10-22 08:00:45 +00:00
Currently, ImageProvider::current_image_bitmap takes a Gfx::IntSize argument which determines the size of the returned bitmap. The default value of this argument is 0x0 which causes the function to return nullptr. This behavior is evidently unintuitive enough that it has lead to incorrect usage in multiple places. For example, the 2D canvas drawImage method will never actually draw anything because it calls current_image_bitmap with no arguments. And the naturalWidth and naturalHeight of an image will always return 0 (even after the image has loaded) for the same reason. To correct this and hopefully avoid similar issues in the future, ImageProvider::current_image_bitmap will be renamed to current_image_bitmap_sized, and the default value for the size argument will be removed. For consistency, a similar change will be made to SVGImageElement::default_image_bitmap. The existing current_image_bitmap function will no longer take a size argument. Instead it will always return a bitmap of the image's intrinsic size. This seems to be what most existing callers had already assumed was the function's behavior.
71 lines
2.4 KiB
C++
71 lines
2.4 KiB
C++
/*
|
|
* Copyright (c) 2024, Tim Ledbetter <tim.ledbetter@ladybird.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <LibGC/Ptr.h>
|
|
#include <LibWeb/Layout/ImageProvider.h>
|
|
#include <LibWeb/SVG/SVGAnimatedLength.h>
|
|
#include <LibWeb/SVG/SVGGraphicsElement.h>
|
|
|
|
namespace Web::SVG {
|
|
|
|
class SVGImageElement
|
|
: public SVGGraphicsElement
|
|
, public SVGURIReferenceMixin<SupportsXLinkHref::Yes>
|
|
, public Layout::ImageProvider {
|
|
WEB_PLATFORM_OBJECT(SVGImageElement, SVGGraphicsElement);
|
|
|
|
public:
|
|
virtual void attribute_changed(FlyString const& name, Optional<String> const& old_value, Optional<String> const& value, Optional<FlyString> const& namespace_) override;
|
|
|
|
GC::Ref<SVG::SVGAnimatedLength> x();
|
|
GC::Ref<SVG::SVGAnimatedLength> y();
|
|
GC::Ref<SVG::SVGAnimatedLength> width();
|
|
GC::Ref<SVG::SVGAnimatedLength> height();
|
|
|
|
Gfx::Rect<CSSPixels> bounding_box() const;
|
|
|
|
RefPtr<Gfx::ImmutableBitmap> default_image_bitmap_sized(Gfx::IntSize) const;
|
|
|
|
// ^Layout::ImageProvider
|
|
virtual bool is_image_available() const override;
|
|
virtual Optional<CSSPixels> intrinsic_width() const override;
|
|
virtual Optional<CSSPixels> intrinsic_height() const override;
|
|
virtual Optional<CSSPixelFraction> intrinsic_aspect_ratio() const override;
|
|
virtual RefPtr<Gfx::ImmutableBitmap> current_image_bitmap_sized(Gfx::IntSize) const override;
|
|
virtual void set_visible_in_viewport(bool) override { }
|
|
virtual GC::Ptr<DOM::Element const> to_html_element() const override { return *this; }
|
|
|
|
protected:
|
|
SVGImageElement(DOM::Document&, DOM::QualifiedName);
|
|
|
|
virtual void initialize(JS::Realm&) override;
|
|
virtual void visit_edges(Cell::Visitor&) override;
|
|
|
|
void process_the_url(Optional<String> const& href);
|
|
void fetch_the_document(URL::URL const& url);
|
|
|
|
private:
|
|
virtual GC::Ptr<Layout::Node> create_layout_node(GC::Ref<CSS::ComputedProperties>) override;
|
|
void animate();
|
|
|
|
GC::Ptr<SVG::SVGAnimatedLength> m_x;
|
|
GC::Ptr<SVG::SVGAnimatedLength> m_y;
|
|
GC::Ptr<SVG::SVGAnimatedLength> m_width;
|
|
GC::Ptr<SVG::SVGAnimatedLength> m_height;
|
|
|
|
RefPtr<Core::Timer> m_animation_timer;
|
|
size_t m_current_frame_index { 0 };
|
|
size_t m_loops_completed { 0 };
|
|
|
|
Optional<URL::URL> m_href;
|
|
|
|
GC::Ptr<HTML::SharedResourceRequest> m_resource_request;
|
|
Optional<DOM::DocumentLoadEventDelayer> m_load_event_delayer;
|
|
};
|
|
|
|
}
|