From 411bbfc5cc41023d044c374c0d2d6b12547cfa1b Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 16 Mar 2024 13:26:00 +0100 Subject: [PATCH] LibWeb: Add fast_is for UIEvents::MouseEvent --- Userland/Libraries/LibWeb/DOM/Event.h | 5 +++++ Userland/Libraries/LibWeb/HTML/HTMLImageElement.cpp | 8 +++++++- Userland/Libraries/LibWeb/UIEvents/MouseEvent.h | 9 +++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibWeb/DOM/Event.h b/Userland/Libraries/LibWeb/DOM/Event.h index eeb9784c4fd911d..f9cc2f74e612d27 100644 --- a/Userland/Libraries/LibWeb/DOM/Event.h +++ b/Userland/Libraries/LibWeb/DOM/Event.h @@ -144,6 +144,11 @@ class Event : public Bindings::PlatformObject { Vector> composed_path() const; + template + bool fast_is() const = delete; + + virtual bool is_mouse_event() const { return false; } + protected: void initialize_event(String const&, bool, bool); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLImageElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLImageElement.cpp index ac1215e92c9804a..2b2723de317ae4f 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLImageElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLImageElement.cpp @@ -838,7 +838,13 @@ void HTMLImageElement::handle_failed_fetch() void HTMLImageElement::restart_the_animation() { m_current_frame_index = 0; - m_animation_timer->start(); + + auto image_data = m_current_request->image_data(); + if (image_data && image_data->frame_count() > 1) { + m_animation_timer->start(); + } else { + m_animation_timer->stop(); + } } // https://html.spec.whatwg.org/multipage/images.html#update-the-source-set diff --git a/Userland/Libraries/LibWeb/UIEvents/MouseEvent.h b/Userland/Libraries/LibWeb/UIEvents/MouseEvent.h index a27d85ffe201ee4..69b8d0852908f4c 100644 --- a/Userland/Libraries/LibWeb/UIEvents/MouseEvent.h +++ b/Userland/Libraries/LibWeb/UIEvents/MouseEvent.h @@ -71,6 +71,8 @@ class MouseEvent : public UIEvent { virtual void initialize(JS::Realm&) override; private: + virtual bool is_mouse_event() const override { return true; } + void set_event_characteristics(); double m_screen_x { 0 }; @@ -102,3 +104,10 @@ class MouseEvent : public UIEvent { }; } + +namespace Web::DOM { + +template<> +inline bool Event::fast_is() const { return is_mouse_event(); } + +}