Screen.cpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * Copyright (c) 2021-2022, Linus Groh <linusg@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibGfx/Rect.h>
  7. #include <LibWeb/Bindings/Intrinsics.h>
  8. #include <LibWeb/Bindings/ScreenPrototype.h>
  9. #include <LibWeb/CSS/Screen.h>
  10. #include <LibWeb/CSS/ScreenOrientation.h>
  11. #include <LibWeb/DOM/Document.h>
  12. #include <LibWeb/Page/Page.h>
  13. namespace Web::CSS {
  14. JS_DEFINE_ALLOCATOR(Screen);
  15. JS::NonnullGCPtr<Screen> Screen::create(HTML::Window& window)
  16. {
  17. return window.heap().allocate<Screen>(window.realm(), window);
  18. }
  19. Screen::Screen(HTML::Window& window)
  20. : DOM::EventTarget(window.realm())
  21. , m_window(window)
  22. {
  23. }
  24. void Screen::initialize(JS::Realm& realm)
  25. {
  26. Base::initialize(realm);
  27. WEB_SET_PROTOTYPE_FOR_INTERFACE(Screen);
  28. }
  29. void Screen::visit_edges(Cell::Visitor& visitor)
  30. {
  31. Base::visit_edges(visitor);
  32. visitor.visit(m_window);
  33. visitor.visit(m_orientation);
  34. }
  35. Gfx::IntRect Screen::screen_rect() const
  36. {
  37. auto screen_rect_in_css_pixels = window().page().web_exposed_screen_area();
  38. return {
  39. screen_rect_in_css_pixels.x().to_int(),
  40. screen_rect_in_css_pixels.y().to_int(),
  41. screen_rect_in_css_pixels.width().to_int(),
  42. screen_rect_in_css_pixels.height().to_int()
  43. };
  44. }
  45. JS::NonnullGCPtr<ScreenOrientation> Screen::orientation()
  46. {
  47. if (!m_orientation)
  48. m_orientation = ScreenOrientation::create(realm());
  49. return *m_orientation;
  50. }
  51. // https://w3c.github.io/window-management/#dom-screen-isextended
  52. bool Screen::is_extended() const
  53. {
  54. dbgln("FIXME: Unimplemented Screen::is_extended");
  55. return false;
  56. }
  57. // https://w3c.github.io/window-management/#dom-screen-onchange
  58. void Screen::set_onchange(JS::GCPtr<WebIDL::CallbackType> event_handler)
  59. {
  60. set_event_handler_attribute(HTML::EventNames::change, event_handler);
  61. }
  62. // https://w3c.github.io/window-management/#dom-screen-onchange
  63. JS::GCPtr<WebIDL::CallbackType> Screen::onchange()
  64. {
  65. return event_handler_attribute(HTML::EventNames::change);
  66. }
  67. }