ScreenOrientation.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. * Copyright (c) 2024, Shannon Booth <shannon@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibWeb/Bindings/Intrinsics.h>
  7. #include <LibWeb/CSS/ScreenOrientation.h>
  8. #include <LibWeb/HTML/EventNames.h>
  9. namespace Web::CSS {
  10. JS_DEFINE_ALLOCATOR(ScreenOrientation);
  11. ScreenOrientation::ScreenOrientation(JS::Realm& realm)
  12. : DOM::EventTarget(realm)
  13. {
  14. }
  15. void ScreenOrientation::initialize(JS::Realm& realm)
  16. {
  17. Base::initialize(realm);
  18. WEB_SET_PROTOTYPE_FOR_INTERFACE(ScreenOrientation);
  19. }
  20. JS::NonnullGCPtr<ScreenOrientation> ScreenOrientation::create(JS::Realm& realm)
  21. {
  22. return realm.heap().allocate<ScreenOrientation>(realm, realm);
  23. }
  24. // https://w3c.github.io/screen-orientation/#lock-method
  25. WebIDL::ExceptionOr<JS::NonnullGCPtr<JS::Promise>> ScreenOrientation::lock(Bindings::OrientationLockType)
  26. {
  27. return WebIDL::NotSupportedError::create(realm(), "FIXME: ScreenOrientation::lock() is not implemented"_fly_string);
  28. }
  29. // https://w3c.github.io/screen-orientation/#unlock-method
  30. void ScreenOrientation::unlock()
  31. {
  32. dbgln("FIXME: Stubbed ScreenOrientation::unlock()");
  33. }
  34. // https://w3c.github.io/screen-orientation/#type-attribute
  35. Bindings::OrientationType ScreenOrientation::type() const
  36. {
  37. dbgln("FIXME: Stubbed ScreenOrientation::type()");
  38. return Bindings::OrientationType::LandscapePrimary;
  39. }
  40. // https://w3c.github.io/screen-orientation/#angle-attribute
  41. WebIDL::UnsignedShort ScreenOrientation::angle() const
  42. {
  43. dbgln("FIXME: Stubbed ScreenOrientation::angle()");
  44. return 0;
  45. }
  46. // https://w3c.github.io/screen-orientation/#onchange-event-handler-attribute
  47. void ScreenOrientation::set_onchange(JS::GCPtr<WebIDL::CallbackType> event_handler)
  48. {
  49. set_event_handler_attribute(HTML::EventNames::change, event_handler);
  50. }
  51. // https://w3c.github.io/screen-orientation/#onchange-event-handler-attribute
  52. JS::GCPtr<WebIDL::CallbackType> ScreenOrientation::onchange()
  53. {
  54. return event_handler_attribute(HTML::EventNames::change);
  55. }
  56. }