PerformanceEventTiming.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * Copyright (c) 2024, Noah Bright <noah.bright.1@gmail.com>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <LibWeb/Bindings/Intrinsics.h>
  8. #include <LibWeb/DOM/Node.h>
  9. #include <LibWeb/PerformanceTimeline/PerformanceEntry.h>
  10. namespace Web::EventTiming {
  11. // https://www.w3.org/TR/event-timing/#sec-performance-event-timing
  12. class PerformanceEventTiming final : public PerformanceTimeline::PerformanceEntry {
  13. WEB_PLATFORM_OBJECT(PerformanceEventTiming, PerformanceTimeline::PerformanceEntry);
  14. JS_DECLARE_ALLOCATOR(PerformanceEventTiming);
  15. public:
  16. virtual ~PerformanceEventTiming();
  17. HighResolutionTime::DOMHighResTimeStamp processing_start() const;
  18. HighResolutionTime::DOMHighResTimeStamp processing_end() const;
  19. bool cancelable() const;
  20. JS::ThrowCompletionOr<JS::GCPtr<DOM::Node>> target();
  21. unsigned long long interaction_id();
  22. // from the registry:
  23. // https://w3c.github.io/timing-entrytypes-registry/#dfn-availablefromtimeline
  24. static PerformanceTimeline::AvailableFromTimeline available_from_timeline();
  25. // https://w3c.github.io/timing-entrytypes-registry/#dfn-maxbuffersize
  26. static Optional<u64> max_buffer_size();
  27. // https://w3c.github.io/timing-entrytypes-registry/#dfn-should-add-entry
  28. virtual PerformanceTimeline::ShouldAddEntry should_add_entry(Optional<PerformanceTimeline::PerformanceObserverInit const&> = {}) const override;
  29. virtual FlyString const& entry_type() const override;
  30. private:
  31. PerformanceEventTiming(JS::Realm& realm, String const& name, HighResolutionTime::DOMHighResTimeStamp start_time, HighResolutionTime::DOMHighResTimeStamp duration,
  32. DOM::Event const& event, HighResolutionTime::DOMHighResTimeStamp processing_start, unsigned long long interaction_id);
  33. // m_entry_type defined here for both "event"s and "first-input"s
  34. // this is the only PerformanceEntry that has two event types it could represent
  35. // That complicates implementing the registry functions if they remain static
  36. FlyString m_entry_type;
  37. JS::GCPtr<DOM::EventTarget> m_event_target;
  38. HighResolutionTime::DOMHighResTimeStamp m_start_time;
  39. HighResolutionTime::DOMHighResTimeStamp m_processing_start;
  40. bool m_cancelable;
  41. unsigned long long m_interaction_id;
  42. static WebIDL::ExceptionOr<JS::NonnullGCPtr<PerformanceEventTiming>> construct_impl(DOM::Event const&, HighResolutionTime::DOMHighResTimeStamp, unsigned long long);
  43. virtual void initialize(JS::Realm&) override;
  44. PerformanceTimeline::ShouldAddEntry should_add_performance_event_timing() const;
  45. virtual void visit_edges(JS::Cell::Visitor&) override;
  46. // FIXME: remaining algorithms described in this spec:
  47. // https://www.w3.org/TR/event-timing/#sec-increasing-interaction-count
  48. // https://www.w3.org/TR/event-timing/#sec-computing-interactionid
  49. // https://www.w3.org/TR/event-timing/#sec-fin-event-timing
  50. // https://www.w3.org/TR/event-timing/#sec-dispatch-pending
  51. };
  52. }