ProgressEvent.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. class ProgressEvent : public DOM::Event {
  12. public:
  13. using WrapperType = Bindings::ProgressEventWrapper;
  14. static NonnullRefPtr<ProgressEvent> create(const FlyString& event_name, u32 transmitted, u32 length)
  15. {
  16. return adopt_ref(*new ProgressEvent(event_name, transmitted, length));
  17. }
  18. virtual ~ProgressEvent() override { }
  19. bool length_computable() const { return m_length_computable; }
  20. u32 loaded() const { return m_loaded; }
  21. u32 total() const { return m_total; }
  22. protected:
  23. ProgressEvent(const FlyString& event_name, u32 transmitted, u32 length)
  24. : Event(event_name)
  25. , m_length_computable(length != 0)
  26. , m_loaded(transmitted)
  27. , m_total(length)
  28. {
  29. }
  30. bool m_length_computable { false };
  31. u32 m_loaded { 0 };
  32. u32 m_total { 0 };
  33. };
  34. }