ScreenOrientation.cpp 2.0 KB

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