ProgressEvent.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. * Copyright (c) 2021, the SerenityOS developers.
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <LibWeb/DOM/Event.h>
  8. namespace Web::XHR {
  9. // FIXME: All the "u32"s should be "u64"s, however LibJS doesn't currently support constructing values with u64,
  10. // and the IDL parser doesn't properly parse "unsigned long long".
  11. struct ProgressEventInit : public DOM::EventInit {
  12. bool length_computable { false };
  13. u32 loaded { 0 };
  14. u32 total { 0 };
  15. };
  16. class ProgressEvent : public DOM::Event {
  17. public:
  18. using WrapperType = Bindings::ProgressEventWrapper;
  19. static NonnullRefPtr<ProgressEvent> create(FlyString const& event_name, ProgressEventInit const& event_init)
  20. {
  21. return adopt_ref(*new ProgressEvent(event_name, event_init));
  22. }
  23. static NonnullRefPtr<ProgressEvent> create_with_global_object(Bindings::WindowObject&, FlyString const& event_name, ProgressEventInit const& event_init)
  24. {
  25. return ProgressEvent::create(event_name, event_init);
  26. }
  27. virtual ~ProgressEvent() override = default;
  28. bool length_computable() const { return m_length_computable; }
  29. u32 loaded() const { return m_loaded; }
  30. u32 total() const { return m_total; }
  31. protected:
  32. ProgressEvent(FlyString const& event_name, ProgressEventInit const& event_init)
  33. : Event(event_name, event_init)
  34. , m_length_computable(event_init.length_computable)
  35. , m_loaded(event_init.loaded)
  36. , m_total(event_init.total)
  37. {
  38. }
  39. bool m_length_computable { false };
  40. u32 m_loaded { 0 };
  41. u32 m_total { 0 };
  42. };
  43. }