diff options
author | Idan Horowitz <idan.horowitz@gmail.com> | 2021-10-01 18:55:24 +0300 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-10-01 20:14:45 +0200 |
commit | 4d71f226730ad5d1a6ea9779b17a64e26c06488a (patch) | |
tree | 1df24dc6bcb7e7f0eb48a3ceaeb275283448402c /Userland | |
parent | 1e8ba0d9d362dffb8e781d0a45155623c8bc2cea (diff) | |
download | serenity-4d71f226730ad5d1a6ea9779b17a64e26c06488a.zip |
LibWeb: Add the missing ProgressEvent IDL constructor
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Libraries/LibWeb/XHR/ProgressEvent.h | 24 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/XHR/ProgressEvent.idl | 8 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp | 6 |
3 files changed, 30 insertions, 8 deletions
diff --git a/Userland/Libraries/LibWeb/XHR/ProgressEvent.h b/Userland/Libraries/LibWeb/XHR/ProgressEvent.h index 7cd2ca49d1..a969864e01 100644 --- a/Userland/Libraries/LibWeb/XHR/ProgressEvent.h +++ b/Userland/Libraries/LibWeb/XHR/ProgressEvent.h @@ -13,13 +13,23 @@ namespace Web::XHR { // FIXME: All the "u32"s should be "u64"s, however LibJS doesn't currently support constructing values with u64, // and the IDL parser doesn't properly parse "unsigned long long". +struct ProgressEventInit : public DOM::EventInit { + bool length_computable { false }; + u32 loaded { 0 }; + u32 total { 0 }; +}; + class ProgressEvent : public DOM::Event { public: using WrapperType = Bindings::ProgressEventWrapper; - static NonnullRefPtr<ProgressEvent> create(const FlyString& event_name, u32 transmitted, u32 length) + static NonnullRefPtr<ProgressEvent> create(FlyString const& event_name, ProgressEventInit const& event_init) + { + return adopt_ref(*new ProgressEvent(event_name, event_init)); + } + static NonnullRefPtr<ProgressEvent> create_with_global_object(Bindings::WindowObject&, FlyString const& event_name, ProgressEventInit const& event_init) { - return adopt_ref(*new ProgressEvent(event_name, transmitted, length)); + return ProgressEvent::create(event_name, event_init); } virtual ~ProgressEvent() override { } @@ -29,11 +39,11 @@ public: u32 total() const { return m_total; } protected: - ProgressEvent(const FlyString& event_name, u32 transmitted, u32 length) - : Event(event_name) - , m_length_computable(length != 0) - , m_loaded(transmitted) - , m_total(length) + ProgressEvent(FlyString const& event_name, ProgressEventInit const& event_init) + : Event(event_name, event_init) + , m_length_computable(event_init.length_computable) + , m_loaded(event_init.loaded) + , m_total(event_init.total) { } diff --git a/Userland/Libraries/LibWeb/XHR/ProgressEvent.idl b/Userland/Libraries/LibWeb/XHR/ProgressEvent.idl index 64e9805ef2..c92731e934 100644 --- a/Userland/Libraries/LibWeb/XHR/ProgressEvent.idl +++ b/Userland/Libraries/LibWeb/XHR/ProgressEvent.idl @@ -1,7 +1,15 @@ +#import <DOM/Event.idl> + interface ProgressEvent : Event { + constructor(DOMString type, optional ProgressEventInit eventInitDict = {}); readonly attribute boolean lengthComputable; readonly attribute unsigned long loaded; readonly attribute unsigned long total; +}; +dictionary ProgressEventInit : EventInit { + boolean lengthComputable = false; + unsigned long loaded = 0; + unsigned long total = 0; }; diff --git a/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp b/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp index 73258099aa..d778e7338a 100644 --- a/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp +++ b/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp @@ -45,7 +45,11 @@ void XMLHttpRequest::set_ready_state(ReadyState ready_state) void XMLHttpRequest::fire_progress_event(const String& event_name, u64 transmitted, u64 length) { - dispatch_event(ProgressEvent::create(event_name, transmitted, length)); + ProgressEventInit event_init {}; + event_init.length_computable = true; + event_init.loaded = transmitted; + event_init.total = length; + dispatch_event(ProgressEvent::create(event_name, event_init)); } String XMLHttpRequest::response_text() const |