ProgressEvent.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * Copyright (c) 2021, the SerenityOS developers.
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright notice, this
  9. * list of conditions and the following disclaimer.
  10. *
  11. * 2. Redistributions in binary form must reproduce the above copyright notice,
  12. * this list of conditions and the following disclaimer in the documentation
  13. * and/or other materials provided with the distribution.
  14. *
  15. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  16. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  17. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  18. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  19. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  20. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  21. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  22. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  23. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  24. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. */
  26. #pragma once
  27. #include <LibWeb/DOM/Event.h>
  28. namespace Web::XHR {
  29. // FIXME: All the "u32"s should be "u64"s, however LibJS doesn't currently support constructing values with u64,
  30. // and the IDL parser doesn't properly parse "unsigned long long".
  31. class ProgressEvent : public DOM::Event {
  32. public:
  33. using WrapperType = Bindings::ProgressEventWrapper;
  34. static NonnullRefPtr<ProgressEvent> create(const FlyString& event_name, u32 transmitted, u32 length)
  35. {
  36. return adopt(*new ProgressEvent(event_name, transmitted, length));
  37. }
  38. virtual ~ProgressEvent() override { }
  39. bool length_computable() const { return m_length_computable; }
  40. u32 loaded() const { return m_loaded; }
  41. u32 total() const { return m_total; }
  42. protected:
  43. ProgressEvent(const FlyString& event_name, u32 transmitted, u32 length)
  44. : Event(event_name)
  45. , m_length_computable(length != 0)
  46. , m_loaded(transmitted)
  47. , m_total(length)
  48. {
  49. }
  50. bool m_length_computable { false };
  51. u32 m_loaded { 0 };
  52. u32 m_total { 0 };
  53. };
  54. }