Skip to content

Commit

Permalink
LibWeb: Add fast_is<T> for UIEvents::MouseEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
awesomekling committed Mar 16, 2024
1 parent bfbc08e commit 411bbfc
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
5 changes: 5 additions & 0 deletions Userland/Libraries/LibWeb/DOM/Event.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@ class Event : public Bindings::PlatformObject {

Vector<JS::Handle<EventTarget>> composed_path() const;

template<typename T>
bool fast_is() const = delete;

virtual bool is_mouse_event() const { return false; }

protected:
void initialize_event(String const&, bool, bool);

Expand Down
8 changes: 7 additions & 1 deletion Userland/Libraries/LibWeb/HTML/HTMLImageElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions Userland/Libraries/LibWeb/UIEvents/MouseEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down Expand Up @@ -102,3 +104,10 @@ class MouseEvent : public UIEvent {
};

}

namespace Web::DOM {

template<>
inline bool Event::fast_is<UIEvents::MouseEvent>() const { return is_mouse_event(); }

}

0 comments on commit 411bbfc

Please sign in to comment.